use of com.aviary.android.feather.library.graphics.drawable.StickerDrawable in project mobile-android by photo.
the class StickersPanel method onClearCurrent.
/**
* Removes the current active sticker.
*
* @param hv
* - the {@link DrawableHighlightView} of the active sticker
* @param removed
* - current sticker is removed
*/
private void onClearCurrent(DrawableHighlightView hv, boolean removed) {
mLogger.info("onClearCurrent. hv=" + hv + ", removed=" + removed);
if (mCurrentFilter != null) {
mCurrentFilter = null;
}
if (null != hv) {
FeatherDrawable content = hv.getContent();
if (removed) {
if (content instanceof StickerDrawable) {
String name = ((StickerDrawable) content).getStickerName();
String packname = ((StickerDrawable) content).getPackLabel();
Tracker.recordTag(name + ": Cancelled");
Tracker.recordTag(packname + ": Cancelled");
}
}
}
hv.setOnDeleteClickListener(null);
((ImageViewDrawableOverlay) mImageView).removeHightlightView(hv);
((ImageViewDrawableOverlay) mImageView).invalidate();
}
use of com.aviary.android.feather.library.graphics.drawable.StickerDrawable in project mobile-android by photo.
the class StickersPanel method onApplyCurrent.
/**
* Flatten the current sticker within the preview bitmap. No more changes will be possible on this sticker.
*/
private void onApplyCurrent() {
mLogger.info("onApplyCurrent");
if (!stickersOnScreen())
return;
final DrawableHighlightView hv = ((ImageViewDrawableOverlay) mImageView).getHighlightViewAt(0);
if (hv != null) {
final StickerDrawable stickerDrawable = ((StickerDrawable) hv.getContent());
RectF cropRect = hv.getCropRectF();
Rect rect = new Rect((int) cropRect.left, (int) cropRect.top, (int) cropRect.right, (int) cropRect.bottom);
Matrix rotateMatrix = hv.getCropRotationMatrix();
Matrix matrix = new Matrix(mImageView.getImageMatrix());
if (!matrix.invert(matrix)) {
}
int saveCount = mCanvas.save(Canvas.MATRIX_SAVE_FLAG);
mCanvas.concat(rotateMatrix);
stickerDrawable.setDropShadow(false);
hv.getContent().setBounds(rect);
hv.getContent().draw(mCanvas);
mCanvas.restoreToCount(saveCount);
mImageView.invalidate();
if (mCurrentFilter != null) {
final int w = mBitmap.getWidth();
final int h = mBitmap.getHeight();
mCurrentFilter.setTopLeft(cropRect.left / w, cropRect.top / h);
mCurrentFilter.setBottomRight(cropRect.right / w, cropRect.bottom / h);
mCurrentFilter.setRotation(Math.toRadians(hv.getRotation()));
int dw = stickerDrawable.getBitmapWidth();
int dh = stickerDrawable.getBitmapHeight();
float scalew = cropRect.width() / dw;
float scaleh = cropRect.height() / dh;
mCurrentFilter.setCenter(cropRect.centerX() / w, cropRect.centerY() / h);
mCurrentFilter.setScale(scalew, scaleh);
mActionList.add(mCurrentFilter.getActions().get(0));
Tracker.recordTag(stickerDrawable.getPackLabel() + ": Applied");
mCurrentFilter = null;
}
}
onClearCurrent(false);
onPreviewChanged(mPreview, false);
}
use of com.aviary.android.feather.library.graphics.drawable.StickerDrawable in project mobile-android by photo.
the class StickersPanel method addSticker.
/**
* Add a new sticker to the canvas.
*
* @param drawable
* - the drawable name
*/
private void addSticker(String drawable, RectF position) {
if (mPlugin == null || !(mPlugin instanceof InternalPlugin)) {
return;
}
final InternalPlugin plugin = (InternalPlugin) mPlugin;
onApplyCurrent();
final boolean rotateAndResize = true;
InputStream stream = null;
try {
stream = plugin.getStickerStream(drawable, StickerType.Small);
} catch (Exception e) {
e.printStackTrace();
onGenericError("Failed to load the selected sticker");
return;
}
if (stream != null) {
StickerDrawable d = new StickerDrawable(plugin.getResources(), stream, drawable, plugin.getLabel(FeatherIntent.PluginType.TYPE_STICKER).toString());
d.setAntiAlias(true);
IOUtils.closeSilently(stream);
// adding the required action
ApplicationInfo info = PackageManagerUtils.getApplicationInfo(getContext().getBaseContext(), mPlugin.getPackageName());
if (info != null) {
String sourceDir = plugin.getSourceDir(PluginType.TYPE_STICKER);
if (null == sourceDir) {
sourceDir = "";
mLogger.error("Cannot find the source dir");
}
mCurrentFilter = new StickerFilter(sourceDir, drawable);
mCurrentFilter.setSize(d.getBitmapWidth(), d.getBitmapHeight());
mCurrentFilter.setExternal(0);
Tracker.recordTag(drawable + ": Selected");
addSticker(d, rotateAndResize, position);
} else {
onGenericError("Sorry I'm not able to load the selected sticker");
}
}
}
Aggregations