OSDN Git Service

Merge "Badging shortcuts with app icons" into ub-launcher3-calgary
authorSunny Goyal <sunnygoyal@google.com>
Fri, 29 Jul 2016 23:14:51 +0000 (23:14 +0000)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Fri, 29 Jul 2016 23:14:51 +0000 (23:14 +0000)
1  2 
src/com/android/launcher3/ShortcutInfo.java
src/com/android/launcher3/shortcuts/DeepShortcutsContainer.java
src/com/android/launcher3/shortcuts/ShortcutInfoCompat.java

@@@ -299,22 -293,34 +299,39 @@@ public class ShortcutInfo extends ItemI
          }
          contentDescription = UserManagerCompat.getInstance(context)
                  .getBadgedLabelForUser(label, user);
 +        if (shortcutInfo.isEnabled()) {
 +            isDisabled &= ~FLAG_DISABLED_BY_PUBLISHER;
 +        } else {
 +            isDisabled |= FLAG_DISABLED_BY_PUBLISHER;
 +        }
  
+         // TODO: Use cache for this
          LauncherAppState launcherAppState = LauncherAppState.getInstance();
-         Drawable unbadgedIcon = launcherAppState.getShortcutManager()
+         Drawable unbadgedDrawable = launcherAppState.getShortcutManager()
                  .getShortcutIconDrawable(shortcutInfo,
                          launcherAppState.getInvariantDeviceProfile().fillResIconDpi);
-         Bitmap icon = unbadgedIcon == null ? null : getBadgedIcon(unbadgedIcon, context);
-         setIcon(icon != null ? icon : launcherAppState.getIconCache().getDefaultIcon(user));
+         IconCache cache = launcherAppState.getIconCache();
+         Bitmap unbadgedBitmap = unbadgedDrawable == null
+                 ? cache.getDefaultIcon(UserHandleCompat.myUserHandle())
+                 : Utilities.createScaledBitmapWithoutShadow(unbadgedDrawable, context);
+         setIcon(getBadgedIcon(unbadgedBitmap, shortcutInfo, cache, context));
      }
  
-     protected Bitmap getBadgedIcon(Drawable unbadgedIcon, Context context) {
-         return Utilities.createBadgedIconBitmapWithShadow(unbadgedIcon, user, context);
+     protected Bitmap getBadgedIcon(Bitmap unbadgedBitmap, ShortcutInfoCompat shortcutInfo,
+             IconCache cache, Context context) {
+         unbadgedBitmap = Utilities.addShadowToIcon(unbadgedBitmap);
+         // Get the app info for the source activity.
+         AppInfo appInfo = new AppInfo();
+         appInfo.user = user;
+         appInfo.componentName = shortcutInfo.getActivity();
+         try {
+             cache.getTitleAndIcon(appInfo, shortcutInfo.getActivityInfo(context), false);
+         } catch (NullPointerException e) {
+             // This may happen when we fail to load the activity info. Worst case ignore badging.
+             return Utilities.badgeIconForUser(unbadgedBitmap, user, context);
+         }
+         return Utilities.badgeWithBitmap(unbadgedBitmap, appInfo.iconBitmap, context);
      }
  
      /** Returns the ShortcutInfo id associated with the deep shortcut. */
@@@ -24,8 -24,11 +24,10 @@@ import android.content.pm.ShortcutInfo
  import android.os.Build;
  
  import com.android.launcher3.ItemInfo;
+ import com.android.launcher3.compat.DeferredLauncherActivityInfo;
+ import com.android.launcher3.compat.LauncherActivityInfoCompat;
  import com.android.launcher3.compat.UserHandleCompat;
  import com.android.launcher3.compat.UserManagerCompat;
 -import com.android.launcher3.util.ComponentKey;
  
  /**
   * Wrapper class for {@link android.content.pm.ShortcutInfo}, representing deep shortcuts into apps.