}
return si;
} else if (shortcutInfo != null) {
- return new ShortcutInfo(shortcutInfo, mContext);
+ ShortcutInfo si = new ShortcutInfo(shortcutInfo, mContext);
+ si.iconBitmap = LauncherIcons.createShortcutIcon(shortcutInfo, mContext);
+ return si;
} else if (providerInfo != null) {
LauncherAppWidgetProviderInfo info = LauncherAppWidgetProviderInfo
.fromProviderInfo(mContext, providerInfo);
import com.android.launcher3.dynamicui.ExtractionUtils;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
+import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.logging.FileLog;
import com.android.launcher3.model.AddWorkspaceItemsTask;
import com.android.launcher3.model.BgDataModel;
continue;
}
info = new ShortcutInfo(pinnedShortcut, context);
+ info.iconBitmap = LauncherIcons
+ .createShortcutIcon(pinnedShortcut, context);
intent = info.intent;
} else {
// Create a shortcut info in disabled mode for now.
}
}
+ public void updateAndBindShortcutInfo(final ShortcutInfo si, final ShortcutInfoCompat info) {
+ updateAndBindShortcutInfo(new Provider<ShortcutInfo>() {
+ @Override
+ public ShortcutInfo get() {
+ si.updateFromDeepShortcutInfo(info, mApp.getContext());
+ si.iconBitmap = LauncherIcons.createShortcutIcon(info, mApp.getContext());
+ return si;
+ }
+ });
+ }
+
/**
* Utility method to update a shortcut on the background thread.
*/
package com.android.launcher3;
import android.annotation.TargetApi;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.graphics.Bitmap;
-import android.graphics.drawable.Drawable;
import android.os.Build;
-import android.os.Process;
-import android.os.UserHandle;
import android.text.TextUtils;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.compat.UserManagerCompat;
-import com.android.launcher3.graphics.LauncherIcons;
-import com.android.launcher3.model.PackageItemInfo;
-import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.util.ContentWriter;
isDisabled |= FLAG_DISABLED_BY_PUBLISHER;
}
disabledMessage = shortcutInfo.getDisabledMessage();
-
- // TODO: Use cache for this
- LauncherAppState launcherAppState = LauncherAppState.getInstance(context);
- Drawable unbadgedDrawable = DeepShortcutManager.getInstance(context)
- .getShortcutIconDrawable(shortcutInfo,
- launcherAppState.getInvariantDeviceProfile().fillResIconDpi);
-
- IconCache cache = launcherAppState.getIconCache();
- Bitmap unbadgedBitmap = unbadgedDrawable == null
- ? cache.getDefaultIcon(Process.myUserHandle())
- : LauncherIcons.createScaledBitmapWithoutShadow(unbadgedDrawable, context);
- iconBitmap = getBadgedIcon(unbadgedBitmap, shortcutInfo, cache, context);
- }
-
- protected Bitmap getBadgedIcon(Bitmap unbadgedBitmap, ShortcutInfoCompat shortcutInfo,
- IconCache cache, Context context) {
- unbadgedBitmap = LauncherIcons.addShadowToIcon(unbadgedBitmap, context);
-
- final Bitmap badgeBitmap;
- ComponentName cn = shortcutInfo.getActivity();
- if (cn != null) {
- // Get the app info for the source activity.
- AppInfo appInfo = new AppInfo();
- appInfo.user = user;
- appInfo.componentName = cn;
- appInfo.intent = new Intent(Intent.ACTION_MAIN)
- .addCategory(Intent.CATEGORY_LAUNCHER)
- .setComponent(cn);
- cache.getTitleAndIcon(appInfo, false);
- badgeBitmap = appInfo.iconBitmap;
- } else {
- PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage());
- cache.getTitleAndIconForApp(pkgInfo, false);
- badgeBitmap = pkgInfo.iconBitmap;
- }
- return LauncherIcons.badgeWithBitmap(unbadgedBitmap, badgeBitmap, context);
}
/** Returns the ShortcutInfo id associated with the deep shortcut. */
package com.android.launcher3.graphics;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
import android.content.Intent.ShortcutIconResource;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Process;
import android.os.UserHandle;
+import com.android.launcher3.AppInfo;
+import com.android.launcher3.IconCache;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.config.ProviderConfig;
+import com.android.launcher3.model.PackageItemInfo;
+import com.android.launcher3.shortcuts.DeepShortcutManager;
+import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import java.lang.reflect.Method;
}
}
+ public static Bitmap createShortcutIcon(ShortcutInfoCompat shortcutInfo, Context context) {
+ return createShortcutIcon(shortcutInfo, context, true /* badged */);
+ }
+
+ public static Bitmap createShortcutIcon(ShortcutInfoCompat shortcutInfo, Context context,
+ boolean badged) {
+ LauncherAppState app = LauncherAppState.getInstance(context);
+ Drawable unbadgedDrawable = DeepShortcutManager.getInstance(context)
+ .getShortcutIconDrawable(shortcutInfo,
+ app.getInvariantDeviceProfile().fillResIconDpi);
+ IconCache cache = app.getIconCache();
+ Bitmap unbadgedBitmap = unbadgedDrawable == null
+ ? cache.getDefaultIcon(Process.myUserHandle())
+ : LauncherIcons.createScaledBitmapWithoutShadow(unbadgedDrawable, context);
+
+ if (!badged) {
+ return unbadgedBitmap;
+ }
+ unbadgedBitmap = LauncherIcons.addShadowToIcon(unbadgedBitmap, context);
+
+ final Bitmap badgeBitmap;
+ ComponentName cn = shortcutInfo.getActivity();
+ if (cn != null) {
+ // Get the app info for the source activity.
+ AppInfo appInfo = new AppInfo();
+ appInfo.user = shortcutInfo.getUserHandle();
+ appInfo.componentName = cn;
+ appInfo.intent = new Intent(Intent.ACTION_MAIN)
+ .addCategory(Intent.CATEGORY_LAUNCHER)
+ .setComponent(cn);
+ cache.getTitleAndIcon(appInfo, false);
+ badgeBitmap = appInfo.iconBitmap;
+ } else {
+ PackageItemInfo pkgInfo = new PackageItemInfo(shortcutInfo.getPackage());
+ cache.getTitleAndIconForApp(pkgInfo, false);
+ badgeBitmap = pkgInfo.iconBitmap;
+ }
+ return badgeWithBitmap(unbadgedBitmap, badgeBitmap, context);
+ }
+
/**
* An extension of {@link BitmapDrawable} which returns the bitmap pixel size as intrinsic size.
* This allows the badging to be done based on the action bitmap size rather than
import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.ShortcutInfo;
+import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.util.MultiHashMap;
}
for (ShortcutInfo shortcutInfo : shortcutInfos) {
shortcutInfo.updateFromDeepShortcutInfo(fullDetails, context);
+ shortcutInfo.iconBitmap =
+ LauncherIcons.createShortcutIcon(fullDetails, context);
updatedShortcutInfos.add(shortcutInfo);
}
}
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.compat.UserManagerCompat;
+import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
import com.android.launcher3.shortcuts.ShortcutKey;
}
si.isDisabled &= ~ShortcutInfo.FLAG_DISABLED_LOCKED_USER;
si.updateFromDeepShortcutInfo(shortcut, context);
+ si.iconBitmap = LauncherIcons.createShortcutIcon(shortcut, context);
} else {
si.isDisabled |= ShortcutInfo.FLAG_DISABLED_LOCKED_USER;
}
import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
import com.android.launcher3.Utilities;
-import com.android.launcher3.shortcuts.DeepShortcutsContainer.UnbadgedShortcutInfo;
import com.android.launcher3.util.PillRevealOutlineProvider;
import com.android.launcher3.util.PillWidthRevealOutlineProvider;
-import com.android.launcher3.util.Provider;
/**
* A {@link android.widget.FrameLayout} that contains a {@link DeepShortcutView}.
private View mIconView;
private float mOpenAnimationProgress;
- private UnbadgedShortcutInfo mInfo;
+ private ShortcutInfo mInfo;
+ private ShortcutInfoCompat mDetail;
public DeepShortcutView(Context context) {
this(context, null, 0);
}
/** package private **/
- void applyShortcutInfo(UnbadgedShortcutInfo info, DeepShortcutsContainer container) {
+ void applyShortcutInfo(ShortcutInfo info, ShortcutInfoCompat detail,
+ DeepShortcutsContainer container) {
mInfo = info;
+ mDetail = detail;
mBubbleText.applyFromShortcutInfo(info);
mIconView.setBackground(mBubbleText.getIcon());
// Use the long label as long as it exists and fits.
- CharSequence longLabel = info.mDetail.getLongLabel();
+ CharSequence longLabel = mDetail.getLongLabel();
int availableWidth = mBubbleText.getWidth() - mBubbleText.getTotalPaddingLeft()
- mBubbleText.getTotalPaddingRight();
boolean usingLongLabel = !TextUtils.isEmpty(longLabel)
&& mBubbleText.getPaint().measureText(longLabel.toString()) <= availableWidth;
- mBubbleText.setText(usingLongLabel ? longLabel : info.mDetail.getShortLabel());
+ mBubbleText.setText(usingLongLabel ? longLabel : mDetail.getShortLabel());
// TODO: Add the click handler to this view directly and not the child view.
mBubbleText.setOnClickListener(Launcher.getLauncher(getContext()));
final ShortcutInfo badged = new ShortcutInfo(mInfo);
// Queue an update task on the worker thread. This ensures that the badged
// shortcut eventually gets its icon updated.
- Launcher.getLauncher(getContext()).getModel().updateAndBindShortcutInfo(
- new Provider<ShortcutInfo>() {
- @Override
- public ShortcutInfo get() {
- badged.updateFromDeepShortcutInfo(mInfo.mDetail, getContext());
- return badged;
- }
- });
+ Launcher.getLauncher(getContext()).getModel()
+ .updateAndBindShortcutInfo(badged, mDetail);
return badged;
}
import android.content.ComponentName;
import android.content.Context;
import android.content.res.Resources;
-import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.PointF;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.DragSource;
import com.android.launcher3.DropTarget;
-import com.android.launcher3.IconCache;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAnimUtils;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
+import com.android.launcher3.graphics.LauncherIcons;
import com.android.launcher3.graphics.TriangleShape;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.launcher3.userevent.nano.LauncherLogProto.ItemType;
}
for (int i = 0; i < shortcuts.size(); i++) {
final ShortcutInfoCompat shortcut = shortcuts.get(i);
- uiHandler.post(new UpdateShortcutChild(
- i, new UnbadgedShortcutInfo(shortcut, mLauncher)));
+ ShortcutInfo si = new ShortcutInfo(shortcut, mLauncher);
+ // Use unbadged icon for the menu.
+ si.iconBitmap = LauncherIcons.createShortcutIcon(
+ shortcut, mLauncher, false /* badged */);
+ uiHandler.post(new UpdateShortcutChild(i, si, shortcut));
}
}
});
/** Updates the child of this container at the given index based on the given shortcut info. */
private class UpdateShortcutChild implements Runnable {
- private int mShortcutChildIndex;
- private UnbadgedShortcutInfo mShortcutChildInfo;
+ private final int mShortcutChildIndex;
+ private final ShortcutInfo mShortcutChildInfo;
+ private final ShortcutInfoCompat mDetail;
- public UpdateShortcutChild(int shortcutChildIndex, UnbadgedShortcutInfo shortcutChildInfo) {
+
+ public UpdateShortcutChild(int shortcutChildIndex, ShortcutInfo shortcutChildInfo,
+ ShortcutInfoCompat detail) {
mShortcutChildIndex = shortcutChildIndex;
mShortcutChildInfo = shortcutChildInfo;
+ mDetail = detail;
}
@Override
public void run() {
getShortcutAt(mShortcutChildIndex)
- .applyShortcutInfo(mShortcutChildInfo, DeepShortcutsContainer.this);
+ .applyShortcutInfo(mShortcutChildInfo, mDetail, DeepShortcutsContainer.this);
}
}
}
/**
- * Extension of {@link ShortcutInfo} which does not badge the icons.
- */
- static class UnbadgedShortcutInfo extends ShortcutInfo {
- public final ShortcutInfoCompat mDetail;
-
- public UnbadgedShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) {
- super(shortcutInfo, context);
- mDetail = shortcutInfo;
- }
-
- @Override
- protected Bitmap getBadgedIcon(Bitmap unbadgedBitmap, ShortcutInfoCompat shortcutInfo,
- IconCache cache, Context context) {
- return unbadgedBitmap;
- }
- }
-
- /**
* Returns a DeepShortcutsContainer which is already open or null
*/
public static DeepShortcutsContainer getOpen(Launcher launcher) {