@@ -0,0 +1,3134 @@
+/*%0A * Copyright (C) 2013 Andrew Neal%0A */%0A%0Apackage com.battlelancer.seriesguide.util;%0A%0Aimport android.app.Activity;%0Aimport android.content.Intent;%0Aimport android.graphics.Bitmap;%0Aimport android.graphics.Canvas;%0Aimport android.graphics.Paint;%0A%0Aimport com.battlelancer.seriesguide.ui.OverviewActivity;%0Aimport com.battlelancer.seriesguide.ui.OverviewFragment;%0A%0A/**%0A * @author Andrew Neal (andrew@seeingpixels.org)%0A */%0Apublic final class ShortcutUtils %7B%0A%0A    /** %7B@link Intent%7D action used to create the shortcut */%0A    private static final String ACTION_INSTALL_SHORTCUT = %22com.android.launcher.action.INSTALL_SHORTCUT%22;%0A%0A    /** Shortcut icon size */%0A    private static final int ICON_SIZE = 128;%0A%0A    /* This class is never initialized */%0A    private ShortcutUtils() %7B%0A    %7D%0A%0A    /**%0A     * Used to add a shortcut to the Launcher app%0A     * %0A     * @param activity The %7B@link Activity%7D to use%0A     * @param name The name to give the shortcut%0A     * @param path The path to the cached image%0A     * @param id The id of the show%0A     */%0A    public static void createShortcut(Activity activity, String name, String path, int id) %7B%0A        // The shortcut icon%0A        Bitmap icon = ImageProvider.getInstance(activity).getImage(path, false);%0A%0A        // Intent used when the icon is touched%0A        final Intent shortcutIntent = new Intent(activity, OverviewActivity.class);%0A        shortcutIntent.putExtra(OverviewFragment.InitBundle.SHOW_TVDBID, id);%0A        shortcutIntent.setAction(Intent.ACTION_MAIN);%0A        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);%0A%0A        // Intent that actually creates the shortcut%0A        final Intent intent = new Intent();%0A        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);%0A        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);%0A        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, resizeAndCropCenter(icon, ICON_SIZE));%0A        intent.setAction(ACTION_INSTALL_SHORTCUT);%0A        activity.sendBroadcast(intent);%0A    %7D%0A%0A    /**%0A     * Used to create launcher shortcut icons%0A     * %0A     * @param bitmap The bitmap to resize%0A     * @param size The new size of the bitmap%0A     * @return A new bitmap that has been resized and center cropped%0A     */%0A    public static Bitmap resizeAndCropCenter(Bitmap bitmap, int size) %7B%0A        final int w = bitmap.getWidth();%0A        final int h = bitmap.getHeight();%0A        if (w == size && h == size) %7B%0A            return bitmap;%0A        %7D%0A%0A        // Scale the image so that the shorter side equals to the target;%0A        // the longer side will be center-cropped%0A        final float scale = (float) size / Math.min(w, h);%0A        final float width = (size - Math.round(scale * w)) / 2f;%0A        final float height = (size - Math.round(scale * h)) / 2f;%0A%0A        final Bitmap target = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);%0A        final Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG %7C Paint.DITHER_FLAG);%0A        final Canvas canvas = new Canvas(target);%0A        canvas.translate(width, height);%0A        canvas.scale(scale, scale);%0A        canvas.drawBitmap(bitmap, 0, 0, paint);%0A        return target;%0A    %7D%0A%0A%7D%0A

Add ShorcutUtils