Search in sources :

Example 11 with ShortcutConfigActivityInfo

use of com.android.launcher3.compat.ShortcutConfigActivityInfo in project android_packages_apps_Launcher3 by crdroidandroid.

the class Utilities method loadFullDrawableWithoutTheme.

private static Drawable loadFullDrawableWithoutTheme(Launcher launcher, ItemInfo info, int width, int height, Object[] outObj) {
    LauncherAppState appState = LauncherAppState.getInstance(launcher);
    if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
        LauncherActivityInfo activityInfo = launcher.getSystemService(LauncherApps.class).resolveActivity(info.getIntent(), info.user);
        outObj[0] = activityInfo;
        return activityInfo == null ? null : LauncherAppState.getInstance(launcher).getIconProvider().getIcon(activityInfo, launcher.getDeviceProfile().inv.fillResIconDpi);
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        if (info instanceof PendingAddShortcutInfo) {
            ShortcutConfigActivityInfo activityInfo = ((PendingAddShortcutInfo) info).activityInfo;
            outObj[0] = activityInfo;
            return activityInfo.getFullResIcon(appState.getIconCache());
        }
        List<ShortcutInfo> si = ShortcutKey.fromItemInfo(info).buildRequest(launcher).query(ShortcutRequest.ALL);
        if (si.isEmpty()) {
            return null;
        } else {
            outObj[0] = si.get(0);
            return ShortcutCachingLogic.getIcon(launcher, si.get(0), appState.getInvariantDeviceProfile().fillResIconDpi);
        }
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        FolderAdaptiveIcon icon = FolderAdaptiveIcon.createFolderAdaptiveIcon(launcher, info.id, new Point(width, height));
        if (icon == null) {
            return null;
        }
        outObj[0] = icon;
        return icon;
    } else {
        return null;
    }
}
Also used : FolderAdaptiveIcon(com.android.launcher3.dragndrop.FolderAdaptiveIcon) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) ShortcutConfigActivityInfo(com.android.launcher3.pm.ShortcutConfigActivityInfo) LauncherApps(android.content.pm.LauncherApps) List(java.util.List) Point(android.graphics.Point)

Example 12 with ShortcutConfigActivityInfo

use of com.android.launcher3.compat.ShortcutConfigActivityInfo in project Neo-Launcher by NeoApplications.

the class WidgetPreviewLoader method generateShortcutPreview.

private Bitmap generateShortcutPreview(BaseActivity launcher, ShortcutConfigActivityInfo info, int maxWidth, int maxHeight, Bitmap preview) {
    int iconSize = launcher.getDeviceProfile().allAppsIconSizePx;
    int padding = launcher.getResources().getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);
    int size = iconSize + 2 * padding;
    if (maxHeight < size || maxWidth < size) {
        throw new RuntimeException("Max size is too small for preview");
    }
    final Canvas c = new Canvas();
    if (preview == null || preview.getWidth() < size || preview.getHeight() < size) {
        preview = Bitmap.createBitmap(size, size, Config.ARGB_8888);
        c.setBitmap(preview);
    } else {
        if (preview.getWidth() > size || preview.getHeight() > size) {
            preview.reconfigure(size, size, preview.getConfig());
        }
        // Reusing bitmap. Clear it.
        c.setBitmap(preview);
        c.drawColor(0, PorterDuff.Mode.CLEAR);
    }
    RectF boxRect = drawBoxWithShadow(c, size, size);
    LauncherIcons li = LauncherIcons.obtain(mContext);
    Bitmap icon = li.createBadgedIconBitmap(mutateOnMainThread(info.getFullResIcon(mIconCache)), Process.myUserHandle(), 0).icon;
    li.recycle();
    Rect src = new Rect(0, 0, icon.getWidth(), icon.getHeight());
    boxRect.set(0, 0, iconSize, iconSize);
    boxRect.offset(padding, padding);
    c.drawBitmap(icon, src, boxRect, new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
    c.setBitmap(null);
    return preview;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) LauncherIcons(com.android.launcher3.icons.LauncherIcons) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 13 with ShortcutConfigActivityInfo

use of com.android.launcher3.compat.ShortcutConfigActivityInfo in project android_packages_apps_Trebuchet by LineageOS.

the class WidgetPreviewLoader method generateShortcutPreview.

private Bitmap generateShortcutPreview(BaseActivity launcher, ShortcutConfigActivityInfo info, int maxWidth, int maxHeight, Bitmap preview) {
    int iconSize = launcher.getDeviceProfile().allAppsIconSizePx;
    int padding = launcher.getResources().getDimensionPixelSize(R.dimen.widget_preview_shortcut_padding);
    int size = iconSize + 2 * padding;
    if (maxHeight < size || maxWidth < size) {
        throw new RuntimeException("Max size is too small for preview");
    }
    final Canvas c = new Canvas();
    if (preview == null || preview.getWidth() < size || preview.getHeight() < size) {
        preview = Bitmap.createBitmap(size, size, Config.ARGB_8888);
        c.setBitmap(preview);
    } else {
        if (preview.getWidth() > size || preview.getHeight() > size) {
            preview.reconfigure(size, size, preview.getConfig());
        }
        // Reusing bitmap. Clear it.
        c.setBitmap(preview);
        c.drawColor(0, PorterDuff.Mode.CLEAR);
    }
    RectF boxRect = drawBoxWithShadow(c, size, size);
    LauncherIcons li = LauncherIcons.obtain(mContext);
    Bitmap icon = li.createBadgedIconBitmap(mutateOnMainThread(info.getFullResIcon(mIconCache)), Process.myUserHandle(), 0).icon;
    li.recycle();
    Rect src = new Rect(0, 0, icon.getWidth(), icon.getHeight());
    boxRect.set(0, 0, iconSize, iconSize);
    boxRect.offset(padding, padding);
    c.drawBitmap(icon, src, boxRect, new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
    c.setBitmap(null);
    return preview;
}
Also used : RectF(android.graphics.RectF) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) LauncherIcons(com.android.launcher3.icons.LauncherIcons) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 14 with ShortcutConfigActivityInfo

use of com.android.launcher3.compat.ShortcutConfigActivityInfo in project android_packages_apps_Trebuchet by LineageOS.

the class Utilities method getFullDrawable.

/**
 * Returns the full drawable for info without any flattening or pre-processing.
 *
 * @param outObj this is set to the internal data associated with {@param info},
 *               eg {@link LauncherActivityInfo} or {@link ShortcutInfo}.
 */
public static Drawable getFullDrawable(Launcher launcher, ItemInfo info, int width, int height, Object[] outObj) {
    LauncherAppState appState = LauncherAppState.getInstance(launcher);
    if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
        LauncherActivityInfo activityInfo = launcher.getSystemService(LauncherApps.class).resolveActivity(info.getIntent(), info.user);
        outObj[0] = activityInfo;
        return activityInfo == null ? null : new IconProvider(launcher).getIconForUI(activityInfo, launcher.getDeviceProfile().inv.fillResIconDpi);
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
        if (info instanceof PendingAddShortcutInfo) {
            ShortcutConfigActivityInfo activityInfo = ((PendingAddShortcutInfo) info).activityInfo;
            outObj[0] = activityInfo;
            return activityInfo.getFullResIcon(appState.getIconCache());
        }
        if (info.getIntent() == null || info.getIntent().getPackage() == null)
            return null;
        List<ShortcutInfo> si = ShortcutKey.fromItemInfo(info).buildRequest(launcher).query(ShortcutRequest.ALL);
        if (si.isEmpty()) {
            return null;
        } else {
            outObj[0] = si.get(0);
            return ShortcutCachingLogic.getIcon(launcher, si.get(0), appState.getInvariantDeviceProfile().fillResIconDpi);
        }
    } else if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
        FolderAdaptiveIcon icon = FolderAdaptiveIcon.createFolderAdaptiveIcon(launcher, info.id, new Point(width, height));
        if (icon == null) {
            return null;
        }
        outObj[0] = icon;
        return icon;
    } else {
        return null;
    }
}
Also used : FolderAdaptiveIcon(com.android.launcher3.dragndrop.FolderAdaptiveIcon) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) PendingAddShortcutInfo(com.android.launcher3.widget.PendingAddShortcutInfo) ShortcutConfigActivityInfo(com.android.launcher3.pm.ShortcutConfigActivityInfo) LauncherApps(android.content.pm.LauncherApps) List(java.util.List) Point(android.graphics.Point) IconProvider(com.android.launcher3.icons.IconProvider)

Example 15 with ShortcutConfigActivityInfo

use of com.android.launcher3.compat.ShortcutConfigActivityInfo in project android_packages_apps_Launcher3 by AOSPA.

the class WidgetsModel method update.

/**
 * @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise
 *                    only widgets and shortcuts associated with the package/user are.
 */
public List<ComponentWithLabelAndIcon> update(LauncherAppState app, @Nullable PackageUserKey packageUser) {
    Preconditions.assertWorkerThread();
    Context context = app.getContext();
    final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
    List<ComponentWithLabelAndIcon> updatedItems = new ArrayList<>();
    try {
        InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
        PackageManager pm = app.getContext().getPackageManager();
        // Widgets
        WidgetManagerHelper widgetManager = new WidgetManagerHelper(context);
        for (AppWidgetProviderInfo widgetInfo : widgetManager.getAllProviders(packageUser)) {
            LauncherAppWidgetProviderInfo launcherWidgetInfo = LauncherAppWidgetProviderInfo.fromProviderInfo(context, widgetInfo);
            widgetsAndShortcuts.add(new WidgetItem(launcherWidgetInfo, idp, app.getIconCache()));
            updatedItems.add(launcherWidgetInfo);
        }
        // Shortcuts
        for (ShortcutConfigActivityInfo info : queryList(context, packageUser)) {
            widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm));
            updatedItems.add(info);
        }
        setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
    } catch (Exception e) {
        if (!FeatureFlags.IS_STUDIO_BUILD && Utilities.isBinderSizeError(e)) {
        // the returned value may be incomplete and will not be refreshed until the next
        // time Launcher starts.
        // TODO: after figuring out a repro step, introduce a dirty bit to check when
        // onResume is called to refresh the widget provider list.
        } else {
            throw e;
        }
    }
    return updatedItems;
}
Also used : Context(android.content.Context) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) InvariantDeviceProfile(com.android.launcher3.InvariantDeviceProfile) ArrayList(java.util.ArrayList) PackageManager(android.content.pm.PackageManager) ComponentWithLabelAndIcon(com.android.launcher3.icons.ComponentWithLabelAndIcon) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) LauncherAppWidgetProviderInfo(com.android.launcher3.widget.LauncherAppWidgetProviderInfo) ShortcutConfigActivityInfo(com.android.launcher3.pm.ShortcutConfigActivityInfo) WidgetManagerHelper(com.android.launcher3.widget.WidgetManagerHelper)

Aggregations

ShortcutConfigActivityInfo (com.android.launcher3.pm.ShortcutConfigActivityInfo)10 ArrayList (java.util.ArrayList)9 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)7 PackageManager (android.content.pm.PackageManager)7 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)6 Context (android.content.Context)6 Paint (android.graphics.Paint)6 Point (android.graphics.Point)6 InvariantDeviceProfile (com.android.launcher3.InvariantDeviceProfile)6 FolderAdaptiveIcon (com.android.launcher3.dragndrop.FolderAdaptiveIcon)6 FastBitmapDrawable (com.android.launcher3.icons.FastBitmapDrawable)6 LauncherIcons (com.android.launcher3.icons.LauncherIcons)6 PendingAddShortcutInfo (com.android.launcher3.widget.PendingAddShortcutInfo)6 List (java.util.List)6 LauncherApps (android.content.pm.LauncherApps)5 ComponentWithLabelAndIcon (com.android.launcher3.icons.ComponentWithLabelAndIcon)5 WidgetManagerHelper (com.android.launcher3.widget.WidgetManagerHelper)5 Drawable (android.graphics.drawable.Drawable)4 LauncherAppWidgetProviderInfo (com.android.launcher3.widget.LauncherAppWidgetProviderInfo)4 Canvas (android.graphics.Canvas)3