Search in sources :

Example 1 with StickerDrawable

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();
}
Also used : ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) FeatherDrawable(com.aviary.android.feather.library.graphics.drawable.FeatherDrawable) StickerDrawable(com.aviary.android.feather.library.graphics.drawable.StickerDrawable)

Example 2 with StickerDrawable

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);
}
Also used : ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) RectF(android.graphics.RectF) Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView) Paint(android.graphics.Paint) Point(android.graphics.Point) StickerDrawable(com.aviary.android.feather.library.graphics.drawable.StickerDrawable)

Example 3 with StickerDrawable

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");
        }
    }
}
Also used : InternalPlugin(com.aviary.android.feather.library.plugins.PluginManager.InternalPlugin) InputStream(java.io.InputStream) StickerFilter(com.aviary.android.feather.library.filters.StickerFilter) ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) StickerDrawable(com.aviary.android.feather.library.graphics.drawable.StickerDrawable)

Aggregations

StickerDrawable (com.aviary.android.feather.library.graphics.drawable.StickerDrawable)3 ImageViewDrawableOverlay (com.aviary.android.feather.widget.ImageViewDrawableOverlay)2 ApplicationInfo (android.content.pm.ApplicationInfo)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 Matrix (android.graphics.Matrix)1 Paint (android.graphics.Paint)1 Point (android.graphics.Point)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 StickerFilter (com.aviary.android.feather.library.filters.StickerFilter)1 FeatherDrawable (com.aviary.android.feather.library.graphics.drawable.FeatherDrawable)1 InternalPlugin (com.aviary.android.feather.library.plugins.PluginManager.InternalPlugin)1 DrawableHighlightView (com.aviary.android.feather.widget.DrawableHighlightView)1 InputStream (java.io.InputStream)1