Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 10923b30 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Removing shadow and badging from the icon which is shown in the menu

These are added as soon as the icon is added to the workspace

Bug: 28980830
Change-Id: I725d2ee8994324f09d9ecf7bbbb0090a7ceb5769
parent 2f88ef34
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -348,7 +348,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {

        public ShortcutInfo getShortcutInfo() {
            if (activityInfo != null) {
                return ShortcutInfo.fromActivityInfo(activityInfo, mContext);
                return new ShortcutInfo(activityInfo, mContext);
            } else {
                return LauncherAppState.getInstance().getModel().infoFromShortcutIntent(mContext, data);
            }
+17 −2
Original line number Diff line number Diff line
@@ -1957,8 +1957,7 @@ public class LauncherModel extends BroadcastReceiver
                                        }
                                    }
                                    incrementPinnedShortcutCount(key, shouldPin);
                                    info = ShortcutInfo.fromDeepShortcutInfo(
                                            pinnedShortcut, context);
                                    info = new ShortcutInfo(pinnedShortcut, context);
                                } else { // item type == ITEM_TYPE_SHORTCUT
                                    info = getShortcutInfo(c, context, titleIndex, cursorIconInfo);

@@ -3291,6 +3290,22 @@ public class LauncherModel extends BroadcastReceiver
        }
    }

    /**
     * Repopulates the shortcut info, possibly updating any icon already on the workspace.
     */
    public void updateShortcutInfo(final ShortcutInfoCompat fullDetail, final ShortcutInfo info) {
        enqueueItemUpdatedTask(new Runnable() {
            @Override
            public void run() {
                info.updateFromDeepShortcutInfo(
                        fullDetail, LauncherAppState.getInstance().getContext());
                ArrayList<ShortcutInfo> update = new ArrayList<ShortcutInfo>();
                update.add(info);
                bindUpdatedShortcuts(update, fullDetail.getUserHandle());
            }
        });
    }

    private class ShortcutsChangedTask implements Runnable {
        private String mPackageName;
        private List<ShortcutInfoCompat> mShortcuts;
+33 −38
Original line number Diff line number Diff line
@@ -162,19 +162,17 @@ public class ShortcutInfo extends ItemInfo {
        this.user = user;
    }

    public ShortcutInfo(Context context, ShortcutInfo info) {
    public ShortcutInfo(ShortcutInfo info) {
        super(info);
        title = Utilities.trim(info.title);
        title = info.title;
        intent = new Intent(info.intent);
        if (info.iconResource != null) {
            iconResource = new Intent.ShortcutIconResource();
            iconResource.packageName = info.iconResource.packageName;
            iconResource.resourceName = info.iconResource.resourceName;
        }
        iconResource = info.iconResource;
        mIcon = info.mIcon; // TODO: should make a copy here.  maybe we don't need this ctor at all
        flags = info.flags;
        user = info.user;
        status = info.status;
        mInstallProgress = info.mInstallProgress;
        isDisabled = info.isDisabled;
        usingFallbackIcon = info.usingFallbackIcon;
    }

    /** TODO: Remove this.  It's only called by ApplicationInfo.makeShortcut. */
@@ -186,6 +184,28 @@ public class ShortcutInfo extends ItemInfo {
        isDisabled = info.isDisabled;
    }

    public ShortcutInfo(LauncherActivityInfoCompat info, Context context) {
        user = info.getUser();
        title = Utilities.trim(info.getLabel());
        contentDescription = UserManagerCompat.getInstance(context)
                .getBadgedLabelForUser(info.getLabel(), info.getUser());
        intent = AppInfo.makeLaunchIntent(context, info, info.getUser());
        itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
        flags = AppInfo.initFlags(info);
    }

    /**
     * Creates a {@link ShortcutInfo} from a {@link ShortcutInfoCompat}.
     */
    @TargetApi(Build.VERSION_CODES.N)
    public ShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) {
        user = shortcutInfo.getUserHandle();
        itemType = LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
        intent = shortcutInfo.makeIntent(context);
        flags = 0;
        updateFromDeepShortcutInfo(shortcutInfo, context);
    }

    public void setIcon(Bitmap b) {
        mIcon = b;
    }
@@ -265,33 +285,6 @@ public class ShortcutInfo extends ItemInfo {
        return usingLowResIcon && container >= 0 && rank >= FolderIcon.NUM_ITEMS_IN_PREVIEW;
    }

    public static ShortcutInfo fromActivityInfo(LauncherActivityInfoCompat info, Context context) {
        final ShortcutInfo shortcut = new ShortcutInfo();
        shortcut.user = info.getUser();
        shortcut.title = Utilities.trim(info.getLabel());
        shortcut.contentDescription = UserManagerCompat.getInstance(context)
                .getBadgedLabelForUser(info.getLabel(), info.getUser());
        shortcut.intent = AppInfo.makeLaunchIntent(context, info, info.getUser());
        shortcut.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
        shortcut.flags = AppInfo.initFlags(info);
        return shortcut;
    }

    /**
     * Creates a {@link ShortcutInfo} from a {@link ShortcutInfoCompat}. Pardon the overloaded name.
     */
    @TargetApi(Build.VERSION_CODES.N)
    public static ShortcutInfo fromDeepShortcutInfo(ShortcutInfoCompat shortcutInfo,
            Context context) {
        ShortcutInfo si = new ShortcutInfo();
        si.user = shortcutInfo.getUserHandle();
        si.itemType = LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
        si.intent = shortcutInfo.makeIntent(context);
        si.flags = 0;
        si.updateFromDeepShortcutInfo(shortcutInfo, context);
        return si;
    }

    public void updateFromDeepShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) {
        title = shortcutInfo.getShortLabel();

@@ -306,11 +299,14 @@ public class ShortcutInfo extends ItemInfo {
        Drawable unbadgedIcon = launcherAppState.getShortcutManager()
                .getShortcutIconDrawable(shortcutInfo,
                        launcherAppState.getInvariantDeviceProfile().fillResIconDpi);
        Bitmap icon = unbadgedIcon == null ? null
                : Utilities.createBadgedIconBitmapWithShadow(unbadgedIcon, user, context);
        Bitmap icon = unbadgedIcon == null ? null : getBadgedIcon(unbadgedIcon, context);
        setIcon(icon != null ? icon : launcherAppState.getIconCache().getDefaultIcon(user));
    }

    protected Bitmap getBadgedIcon(Drawable unbadgedIcon, Context context) {
        return Utilities.createBadgedIconBitmapWithShadow(unbadgedIcon, user, context);
    }

    /** Returns the ShortcutInfo id associated with the deep shortcut. */
    public String getDeepShortcutId() {
        return itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT ?
@@ -322,4 +318,3 @@ public class ShortcutInfo extends ItemInfo {
        return isDisabled != 0;
    }
}
+13 −6
Original line number Diff line number Diff line
@@ -264,18 +264,25 @@ public final class Utilities {
    }

    /**
     * Same as {@link #createBadgedIconBitmap} but adds a shadow before badging the icon
     * Creates a normalized bitmap suitable for the all apps view. The bitmap is also visually
     * normalized with other icons and has enough spacing to add shadow.
     */
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static Bitmap createBadgedIconBitmapWithShadow(
            Drawable icon, UserHandleCompat user, Context context) {
    public static Bitmap createScaledBitmapWithoutShadow(Drawable icon, Context context) {
        RectF iconBounds = new RectF();
        float scale = FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION ?
                1 : IconNormalizer.getInstance().getScale(icon, iconBounds);
        scale = Math.min(scale, ShadowGenerator.getScaleForBounds(iconBounds));
        return createIconBitmap(icon, context, scale);
    }

        Bitmap bitmap = createIconBitmap(icon, context, scale);
        bitmap = ShadowGenerator.getInstance().recreateIcon(bitmap);
    /**
     * Same as {@link #createBadgedIconBitmap} but adds a shadow before badging the icon
     */
    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public static Bitmap createBadgedIconBitmapWithShadow(
            Drawable icon, UserHandleCompat user, Context context) {
        Bitmap bitmap = ShadowGenerator.getInstance().recreateIcon(
                createScaledBitmapWithoutShadow(icon, context));
        if (Utilities.ATLEAST_LOLLIPOP && user != null
                && !UserHandleCompat.myUserHandle().equals(user)) {
            BitmapDrawable drawable = new FixedSizeBitmapDrawable(bitmap);
+11 −11
Original line number Diff line number Diff line
@@ -2301,11 +2301,19 @@ public class Workspace extends PagedView
    }

    public void beginDragShared(View child, DragSource source, boolean accessible) {
        beginDragShared(child, new Point(), source, accessible, new DragPreviewProvider(child));
        Object dragObject = child.getTag();
        if (!(dragObject instanceof ItemInfo)) {
            String msg = "Drag started with a view that has no tag set. This "
                    + "will cause a crash (issue 11627249) down the line. "
                    + "View: " + child + "  tag: " + child.getTag();
            throw new IllegalStateException(msg);
        }
        beginDragShared(child, new Point(), source, accessible,
                (ItemInfo) dragObject, new DragPreviewProvider(child));
    }

    public void beginDragShared(View child, Point relativeTouchPos, DragSource source,
                                boolean accessible, DragPreviewProvider previewProvider) {
            boolean accessible, ItemInfo dragObject, DragPreviewProvider previewProvider) {
        child.clearFocus();
        child.setPressed(false);

@@ -2362,20 +2370,12 @@ public class Workspace extends PagedView
            icon.clearPressedBackground();
        }

        Object dragObject = child.getTag();
        if (!(dragObject instanceof ItemInfo)) {
            String msg = "Drag started with a view that has no tag set. This "
                    + "will cause a crash (issue 11627249) down the line. "
                    + "View: " + child + "  tag: " + child.getTag();
            throw new IllegalStateException(msg);
        }

        if (child.getParent() instanceof ShortcutAndWidgetContainer) {
            mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent();
        }

        DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source,
                (ItemInfo) dragObject, DragController.DRAG_ACTION_MOVE, dragVisualizeOffset,
                dragObject, DragController.DRAG_ACTION_MOVE, dragVisualizeOffset,
                dragRect, scale, accessible);
        dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor());

Loading