Search in sources :

Example 1 with StickerFilter

use of com.aviary.android.feather.library.filters.StickerFilter 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

ApplicationInfo (android.content.pm.ApplicationInfo)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 StickerFilter (com.aviary.android.feather.library.filters.StickerFilter)1 StickerDrawable (com.aviary.android.feather.library.graphics.drawable.StickerDrawable)1 InternalPlugin (com.aviary.android.feather.library.plugins.PluginManager.InternalPlugin)1 InputStream (java.io.InputStream)1