Loading src/com/android/launcher3/WidgetPreviewLoader.java +22 −8 Original line number Original line Diff line number Diff line Loading @@ -65,7 +65,7 @@ public class WidgetPreviewLoader { private final Context mContext; private final Context mContext; private final IconCache mIconCache; private final IconCache mIconCache; private final UserManagerCompat mUserManager; private final UserManagerCompat mUserManager; private final AppWidgetManagerCompat mManager; private final AppWidgetManagerCompat mWidgetManager; private final CacheDb mDb; private final CacheDb mDb; private final int mProfileBadgeMargin; private final int mProfileBadgeMargin; Loading @@ -75,7 +75,7 @@ public class WidgetPreviewLoader { public WidgetPreviewLoader(Context context, IconCache iconCache) { public WidgetPreviewLoader(Context context, IconCache iconCache) { mContext = context; mContext = context; mIconCache = iconCache; mIconCache = iconCache; mManager = AppWidgetManagerCompat.getInstance(context); mWidgetManager = AppWidgetManagerCompat.getInstance(context); mUserManager = UserManagerCompat.getInstance(context); mUserManager = UserManagerCompat.getInstance(context); mDb = new CacheDb(context); mDb = new CacheDb(context); mWorkerHandler = new Handler(LauncherModel.getWorkerLooper()); mWorkerHandler = new Handler(LauncherModel.getWorkerLooper()); Loading Loading @@ -139,7 +139,7 @@ public class WidgetPreviewLoader { // should cache the string builder // should cache the string builder if (o instanceof LauncherAppWidgetProviderInfo) { if (o instanceof LauncherAppWidgetProviderInfo) { LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) o; LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) o; return new WidgetCacheKey(info.provider, mManager.getUser(info), size); return new WidgetCacheKey(info.provider, mWidgetManager.getUser(info), size); } else { } else { ResolveInfo info = (ResolveInfo) o; ResolveInfo info = (ResolveInfo) o; return new WidgetCacheKey( return new WidgetCacheKey( Loading Loading @@ -193,7 +193,7 @@ public class WidgetPreviewLoader { pkg = ((ResolveInfo) obj).activityInfo.packageName; pkg = ((ResolveInfo) obj).activityInfo.packageName; } else { } else { LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) obj; LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) obj; user = mManager.getUser(info); user = mWidgetManager.getUser(info); pkg = info.provider.getPackageName(); pkg = info.provider.getPackageName(); } } Loading Loading @@ -305,6 +305,17 @@ public class WidgetPreviewLoader { } } } } /** * Generates the widget preview from either the {@link AppWidgetManagerCompat} or cache * and add badge at the bottom right corner. * * @param launcher * @param info information about the widget * @param maxPreviewWidth width of the preview on either workspace or tray * @param preview bitmap that can be recycled * @param preScaledWidthOut return the width of the returned bitmap * @return */ public Bitmap generateWidgetPreview(Launcher launcher, LauncherAppWidgetProviderInfo info, public Bitmap generateWidgetPreview(Launcher launcher, LauncherAppWidgetProviderInfo info, int maxPreviewWidth, Bitmap preview, int[] preScaledWidthOut) { int maxPreviewWidth, Bitmap preview, int[] preScaledWidthOut) { // Load the preview image if possible // Load the preview image if possible Loading @@ -312,7 +323,7 @@ public class WidgetPreviewLoader { Drawable drawable = null; Drawable drawable = null; if (info.previewImage != 0) { if (info.previewImage != 0) { drawable = mManager.loadPreview(info); drawable = mWidgetManager.loadPreview(info); if (drawable != null) { if (drawable != null) { drawable = mutateOnMainThread(drawable); drawable = mutateOnMainThread(drawable); } else { } else { Loading @@ -327,6 +338,7 @@ public class WidgetPreviewLoader { int previewWidth; int previewWidth; int previewHeight; int previewHeight; Bitmap tileBitmap = null; Bitmap tileBitmap = null; if (widgetPreviewExists) { if (widgetPreviewExists) { Loading Loading @@ -398,7 +410,7 @@ public class WidgetPreviewLoader { float iconScale = Math.min((float) smallestSide / (appIconSize + 2 * minOffset), scale); float iconScale = Math.min((float) smallestSide / (appIconSize + 2 * minOffset), scale); try { try { Drawable icon = mManager.loadIcon(info, mIconCache); Drawable icon = mWidgetManager.loadIcon(info, mIconCache); if (icon != null) { if (icon != null) { icon = mutateOnMainThread(icon); icon = mutateOnMainThread(icon); int hoffset = (int) ((tileW - appIconSize * iconScale) / 2) + x; int hoffset = (int) ((tileW - appIconSize * iconScale) / 2) + x; Loading @@ -408,11 +420,13 @@ public class WidgetPreviewLoader { yoffset + (int) (appIconSize * iconScale)); yoffset + (int) (appIconSize * iconScale)); icon.draw(c); icon.draw(c); } } } catch (Resources.NotFoundException e) { } } catch (Resources.NotFoundException e) { } c.setBitmap(null); c.setBitmap(null); } } int imageWidth = Math.min(preview.getWidth(), previewWidth + mProfileBadgeMargin); int imageHeight = Math.min(preview.getHeight(), previewHeight + mProfileBadgeMargin); int imageHeight = Math.min(preview.getHeight(), previewHeight + mProfileBadgeMargin); return mManager.getBadgeBitmap(info, preview, imageHeight); return mWidgetManager.getBadgeBitmap(info, preview, imageWidth, imageHeight); } } private Bitmap generateShortcutPreview( private Bitmap generateShortcutPreview( Loading src/com/android/launcher3/compat/AppWidgetManagerCompat.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -79,6 +79,6 @@ public abstract class AppWidgetManagerCompat { public abstract Drawable loadIcon(LauncherAppWidgetProviderInfo info, IconCache cache); public abstract Drawable loadIcon(LauncherAppWidgetProviderInfo info, IconCache cache); public abstract Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, public abstract Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, int imageHeight); int imageWidth, int imageHeight); } } src/com/android/launcher3/compat/AppWidgetManagerCompatV16.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -88,7 +88,7 @@ class AppWidgetManagerCompatV16 extends AppWidgetManagerCompat { @Override @Override public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, int imageHeight) { int imageWidth, int imageHeight) { return bitmap; return bitmap; } } } } src/com/android/launcher3/compat/AppWidgetManagerCompatVL.java +8 −2 Original line number Original line Diff line number Diff line Loading @@ -107,18 +107,24 @@ class AppWidgetManagerCompatVL extends AppWidgetManagerCompat { @Override @Override public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, int imageHeight) { int imageWidth, int imageHeight) { if (info.isCustomWidget || info.getProfile().equals(android.os.Process.myUserHandle())) { if (info.isCustomWidget || info.getProfile().equals(android.os.Process.myUserHandle())) { return bitmap; return bitmap; } } // Add a user badge in the bottom right of the image. // Add a user badge in the bottom right of the image. final Resources res = mContext.getResources(); final Resources res = mContext.getResources(); final int badgeSize = res.getDimensionPixelSize(R.dimen.profile_badge_size); final int badgeMinTop = res.getDimensionPixelSize(R.dimen.profile_badge_minimum_top); final int badgeMinTop = res.getDimensionPixelSize(R.dimen.profile_badge_minimum_top); // choose min between badge size defined for widget tray versus width, height of the image. // Width, height of the image can be smaller than widget tray badge size when being dropped // to the workspace. final int badgeSize = Math.min(res.getDimensionPixelSize(R.dimen.profile_badge_size), Math.min(imageWidth, imageHeight - badgeMinTop)); final Rect badgeLocation = new Rect(0, 0, badgeSize, badgeSize); final Rect badgeLocation = new Rect(0, 0, badgeSize, badgeSize); final int top = Math.max(imageHeight - badgeSize, badgeMinTop); final int top = Math.max(imageHeight - badgeSize, badgeMinTop); if (res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { if (res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { badgeLocation.offset(0, top); badgeLocation.offset(0, top); } else { } else { Loading Loading
src/com/android/launcher3/WidgetPreviewLoader.java +22 −8 Original line number Original line Diff line number Diff line Loading @@ -65,7 +65,7 @@ public class WidgetPreviewLoader { private final Context mContext; private final Context mContext; private final IconCache mIconCache; private final IconCache mIconCache; private final UserManagerCompat mUserManager; private final UserManagerCompat mUserManager; private final AppWidgetManagerCompat mManager; private final AppWidgetManagerCompat mWidgetManager; private final CacheDb mDb; private final CacheDb mDb; private final int mProfileBadgeMargin; private final int mProfileBadgeMargin; Loading @@ -75,7 +75,7 @@ public class WidgetPreviewLoader { public WidgetPreviewLoader(Context context, IconCache iconCache) { public WidgetPreviewLoader(Context context, IconCache iconCache) { mContext = context; mContext = context; mIconCache = iconCache; mIconCache = iconCache; mManager = AppWidgetManagerCompat.getInstance(context); mWidgetManager = AppWidgetManagerCompat.getInstance(context); mUserManager = UserManagerCompat.getInstance(context); mUserManager = UserManagerCompat.getInstance(context); mDb = new CacheDb(context); mDb = new CacheDb(context); mWorkerHandler = new Handler(LauncherModel.getWorkerLooper()); mWorkerHandler = new Handler(LauncherModel.getWorkerLooper()); Loading Loading @@ -139,7 +139,7 @@ public class WidgetPreviewLoader { // should cache the string builder // should cache the string builder if (o instanceof LauncherAppWidgetProviderInfo) { if (o instanceof LauncherAppWidgetProviderInfo) { LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) o; LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) o; return new WidgetCacheKey(info.provider, mManager.getUser(info), size); return new WidgetCacheKey(info.provider, mWidgetManager.getUser(info), size); } else { } else { ResolveInfo info = (ResolveInfo) o; ResolveInfo info = (ResolveInfo) o; return new WidgetCacheKey( return new WidgetCacheKey( Loading Loading @@ -193,7 +193,7 @@ public class WidgetPreviewLoader { pkg = ((ResolveInfo) obj).activityInfo.packageName; pkg = ((ResolveInfo) obj).activityInfo.packageName; } else { } else { LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) obj; LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) obj; user = mManager.getUser(info); user = mWidgetManager.getUser(info); pkg = info.provider.getPackageName(); pkg = info.provider.getPackageName(); } } Loading Loading @@ -305,6 +305,17 @@ public class WidgetPreviewLoader { } } } } /** * Generates the widget preview from either the {@link AppWidgetManagerCompat} or cache * and add badge at the bottom right corner. * * @param launcher * @param info information about the widget * @param maxPreviewWidth width of the preview on either workspace or tray * @param preview bitmap that can be recycled * @param preScaledWidthOut return the width of the returned bitmap * @return */ public Bitmap generateWidgetPreview(Launcher launcher, LauncherAppWidgetProviderInfo info, public Bitmap generateWidgetPreview(Launcher launcher, LauncherAppWidgetProviderInfo info, int maxPreviewWidth, Bitmap preview, int[] preScaledWidthOut) { int maxPreviewWidth, Bitmap preview, int[] preScaledWidthOut) { // Load the preview image if possible // Load the preview image if possible Loading @@ -312,7 +323,7 @@ public class WidgetPreviewLoader { Drawable drawable = null; Drawable drawable = null; if (info.previewImage != 0) { if (info.previewImage != 0) { drawable = mManager.loadPreview(info); drawable = mWidgetManager.loadPreview(info); if (drawable != null) { if (drawable != null) { drawable = mutateOnMainThread(drawable); drawable = mutateOnMainThread(drawable); } else { } else { Loading @@ -327,6 +338,7 @@ public class WidgetPreviewLoader { int previewWidth; int previewWidth; int previewHeight; int previewHeight; Bitmap tileBitmap = null; Bitmap tileBitmap = null; if (widgetPreviewExists) { if (widgetPreviewExists) { Loading Loading @@ -398,7 +410,7 @@ public class WidgetPreviewLoader { float iconScale = Math.min((float) smallestSide / (appIconSize + 2 * minOffset), scale); float iconScale = Math.min((float) smallestSide / (appIconSize + 2 * minOffset), scale); try { try { Drawable icon = mManager.loadIcon(info, mIconCache); Drawable icon = mWidgetManager.loadIcon(info, mIconCache); if (icon != null) { if (icon != null) { icon = mutateOnMainThread(icon); icon = mutateOnMainThread(icon); int hoffset = (int) ((tileW - appIconSize * iconScale) / 2) + x; int hoffset = (int) ((tileW - appIconSize * iconScale) / 2) + x; Loading @@ -408,11 +420,13 @@ public class WidgetPreviewLoader { yoffset + (int) (appIconSize * iconScale)); yoffset + (int) (appIconSize * iconScale)); icon.draw(c); icon.draw(c); } } } catch (Resources.NotFoundException e) { } } catch (Resources.NotFoundException e) { } c.setBitmap(null); c.setBitmap(null); } } int imageWidth = Math.min(preview.getWidth(), previewWidth + mProfileBadgeMargin); int imageHeight = Math.min(preview.getHeight(), previewHeight + mProfileBadgeMargin); int imageHeight = Math.min(preview.getHeight(), previewHeight + mProfileBadgeMargin); return mManager.getBadgeBitmap(info, preview, imageHeight); return mWidgetManager.getBadgeBitmap(info, preview, imageWidth, imageHeight); } } private Bitmap generateShortcutPreview( private Bitmap generateShortcutPreview( Loading
src/com/android/launcher3/compat/AppWidgetManagerCompat.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -79,6 +79,6 @@ public abstract class AppWidgetManagerCompat { public abstract Drawable loadIcon(LauncherAppWidgetProviderInfo info, IconCache cache); public abstract Drawable loadIcon(LauncherAppWidgetProviderInfo info, IconCache cache); public abstract Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, public abstract Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, int imageHeight); int imageWidth, int imageHeight); } }
src/com/android/launcher3/compat/AppWidgetManagerCompatV16.java +1 −1 Original line number Original line Diff line number Diff line Loading @@ -88,7 +88,7 @@ class AppWidgetManagerCompatV16 extends AppWidgetManagerCompat { @Override @Override public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, int imageHeight) { int imageWidth, int imageHeight) { return bitmap; return bitmap; } } } }
src/com/android/launcher3/compat/AppWidgetManagerCompatVL.java +8 −2 Original line number Original line Diff line number Diff line Loading @@ -107,18 +107,24 @@ class AppWidgetManagerCompatVL extends AppWidgetManagerCompat { @Override @Override public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, int imageHeight) { int imageWidth, int imageHeight) { if (info.isCustomWidget || info.getProfile().equals(android.os.Process.myUserHandle())) { if (info.isCustomWidget || info.getProfile().equals(android.os.Process.myUserHandle())) { return bitmap; return bitmap; } } // Add a user badge in the bottom right of the image. // Add a user badge in the bottom right of the image. final Resources res = mContext.getResources(); final Resources res = mContext.getResources(); final int badgeSize = res.getDimensionPixelSize(R.dimen.profile_badge_size); final int badgeMinTop = res.getDimensionPixelSize(R.dimen.profile_badge_minimum_top); final int badgeMinTop = res.getDimensionPixelSize(R.dimen.profile_badge_minimum_top); // choose min between badge size defined for widget tray versus width, height of the image. // Width, height of the image can be smaller than widget tray badge size when being dropped // to the workspace. final int badgeSize = Math.min(res.getDimensionPixelSize(R.dimen.profile_badge_size), Math.min(imageWidth, imageHeight - badgeMinTop)); final Rect badgeLocation = new Rect(0, 0, badgeSize, badgeSize); final Rect badgeLocation = new Rect(0, 0, badgeSize, badgeSize); final int top = Math.max(imageHeight - badgeSize, badgeMinTop); final int top = Math.max(imageHeight - badgeSize, badgeMinTop); if (res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { if (res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { badgeLocation.offset(0, top); badgeLocation.offset(0, top); } else { } else { Loading