diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2017-01-18 11:30:23 -0800 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2017-01-18 11:30:59 -0800 |
commit | 1b0726359b5157db8d3d96c52a37f05fce065618 (patch) | |
tree | 976beb740a63b928e35c41d026d7ea5af00222f8 /src/com/android/launcher3/shortcuts | |
parent | a3db1fc674ed9a09cf1fae880506673cb7d8f83f (diff) | |
download | android_packages_apps_Trebuchet-1b0726359b5157db8d3d96c52a37f05fce065618.tar.gz android_packages_apps_Trebuchet-1b0726359b5157db8d3d96c52a37f05fce065618.tar.bz2 android_packages_apps_Trebuchet-1b0726359b5157db8d3d96c52a37f05fce065618.zip |
Moving icon generation out of ShortcutInfo constructor so that it
can be created on the UI thread
Change-Id: If84e52041eb4ab20807f5cfd4b7f31d7b5f381ed
Diffstat (limited to 'src/com/android/launcher3/shortcuts')
-rw-r--r-- | src/com/android/launcher3/shortcuts/DeepShortcutView.java | 23 | ||||
-rw-r--r-- | src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java | 40 |
2 files changed, 23 insertions, 40 deletions
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutView.java b/src/com/android/launcher3/shortcuts/DeepShortcutView.java index 04c71ecd2..6e9810007 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutView.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutView.java @@ -31,10 +31,8 @@ import com.android.launcher3.LogAccelerateInterpolator; 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}. @@ -50,7 +48,8 @@ public class DeepShortcutView extends FrameLayout implements ValueAnimator.Anima private View mIconView; private float mOpenAnimationProgress; - private UnbadgedShortcutInfo mInfo; + private ShortcutInfo mInfo; + private ShortcutInfoCompat mDetail; public DeepShortcutView(Context context) { this(context, null, 0); @@ -92,18 +91,20 @@ public class DeepShortcutView extends FrameLayout implements ValueAnimator.Anima } /** 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())); @@ -118,14 +119,8 @@ public class DeepShortcutView extends FrameLayout implements ValueAnimator.Anima 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; } diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java index e547f4468..172954e53 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java @@ -25,7 +25,6 @@ import android.annotation.TargetApi; 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; @@ -49,7 +48,6 @@ import com.android.launcher3.AbstractFloatingView; 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; @@ -65,6 +63,7 @@ import com.android.launcher3.dragndrop.DragController; 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; @@ -174,8 +173,11 @@ public class DeepShortcutsContainer extends AbstractFloatingView } 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)); } } }); @@ -183,18 +185,22 @@ public class DeepShortcutsContainer extends AbstractFloatingView /** 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); } } @@ -677,24 +683,6 @@ public class DeepShortcutsContainer extends AbstractFloatingView } /** - * 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) { |