diff options
author | Hyunyoung Song <hyunyoungs@google.com> | 2016-03-01 11:57:44 -0800 |
---|---|---|
committer | Hyunyoung Song <hyunyoungs@google.com> | 2016-03-01 11:57:44 -0800 |
commit | 3e840f4343086ed78a8ae44fd543a9863d868dc9 (patch) | |
tree | 3defaae7a71a3e6ecede428de464ffbf2660066b /src/com/android/launcher3 | |
parent | 2cb92eb2bbfbd6ae4331657d3446f3f771aabd4b (diff) | |
download | android_packages_apps_Trebuchet-3e840f4343086ed78a8ae44fd543a9863d868dc9.tar.gz android_packages_apps_Trebuchet-3e840f4343086ed78a8ae44fd543a9863d868dc9.tar.bz2 android_packages_apps_Trebuchet-3e840f4343086ed78a8ae44fd543a9863d868dc9.zip |
Prevent work profile widget DnD crash
b/26079469
Change-Id: I3d49ac498bbaaef8ca8a3051f5ab4b35ef771410
Diffstat (limited to 'src/com/android/launcher3')
4 files changed, 32 insertions, 12 deletions
diff --git a/src/com/android/launcher3/WidgetPreviewLoader.java b/src/com/android/launcher3/WidgetPreviewLoader.java index b27fa60b7..314dd8a60 100644 --- a/src/com/android/launcher3/WidgetPreviewLoader.java +++ b/src/com/android/launcher3/WidgetPreviewLoader.java @@ -65,7 +65,7 @@ public class WidgetPreviewLoader { private final Context mContext; private final IconCache mIconCache; private final UserManagerCompat mUserManager; - private final AppWidgetManagerCompat mManager; + private final AppWidgetManagerCompat mWidgetManager; private final CacheDb mDb; private final int mProfileBadgeMargin; @@ -75,7 +75,7 @@ public class WidgetPreviewLoader { public WidgetPreviewLoader(Context context, IconCache iconCache) { mContext = context; mIconCache = iconCache; - mManager = AppWidgetManagerCompat.getInstance(context); + mWidgetManager = AppWidgetManagerCompat.getInstance(context); mUserManager = UserManagerCompat.getInstance(context); mDb = new CacheDb(context); mWorkerHandler = new Handler(LauncherModel.getWorkerLooper()); @@ -139,7 +139,7 @@ public class WidgetPreviewLoader { // should cache the string builder if (o instanceof LauncherAppWidgetProviderInfo) { LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) o; - return new WidgetCacheKey(info.provider, mManager.getUser(info), size); + return new WidgetCacheKey(info.provider, mWidgetManager.getUser(info), size); } else { ResolveInfo info = (ResolveInfo) o; return new WidgetCacheKey( @@ -193,7 +193,7 @@ public class WidgetPreviewLoader { pkg = ((ResolveInfo) obj).activityInfo.packageName; } else { LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo) obj; - user = mManager.getUser(info); + user = mWidgetManager.getUser(info); pkg = info.provider.getPackageName(); } @@ -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, int maxPreviewWidth, Bitmap preview, int[] preScaledWidthOut) { // Load the preview image if possible @@ -312,7 +323,7 @@ public class WidgetPreviewLoader { Drawable drawable = null; if (info.previewImage != 0) { - drawable = mManager.loadPreview(info); + drawable = mWidgetManager.loadPreview(info); if (drawable != null) { drawable = mutateOnMainThread(drawable); } else { @@ -327,6 +338,7 @@ public class WidgetPreviewLoader { int previewWidth; int previewHeight; + Bitmap tileBitmap = null; if (widgetPreviewExists) { @@ -398,7 +410,7 @@ public class WidgetPreviewLoader { float iconScale = Math.min((float) smallestSide / (appIconSize + 2 * minOffset), scale); try { - Drawable icon = mManager.loadIcon(info, mIconCache); + Drawable icon = mWidgetManager.loadIcon(info, mIconCache); if (icon != null) { icon = mutateOnMainThread(icon); int hoffset = (int) ((tileW - appIconSize * iconScale) / 2) + x; @@ -408,11 +420,13 @@ public class WidgetPreviewLoader { yoffset + (int) (appIconSize * iconScale)); icon.draw(c); } - } catch (Resources.NotFoundException e) { } + } catch (Resources.NotFoundException e) { + } c.setBitmap(null); } + int imageWidth = Math.min(preview.getWidth(), previewWidth + 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( diff --git a/src/com/android/launcher3/compat/AppWidgetManagerCompat.java b/src/com/android/launcher3/compat/AppWidgetManagerCompat.java index 434f13dcc..f0221bc24 100644 --- a/src/com/android/launcher3/compat/AppWidgetManagerCompat.java +++ b/src/com/android/launcher3/compat/AppWidgetManagerCompat.java @@ -79,6 +79,6 @@ public abstract class AppWidgetManagerCompat { public abstract Drawable loadIcon(LauncherAppWidgetProviderInfo info, IconCache cache); public abstract Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, - int imageHeight); + int imageWidth, int imageHeight); } diff --git a/src/com/android/launcher3/compat/AppWidgetManagerCompatV16.java b/src/com/android/launcher3/compat/AppWidgetManagerCompatV16.java index 463cf902d..e9d2510e8 100644 --- a/src/com/android/launcher3/compat/AppWidgetManagerCompatV16.java +++ b/src/com/android/launcher3/compat/AppWidgetManagerCompatV16.java @@ -88,7 +88,7 @@ class AppWidgetManagerCompatV16 extends AppWidgetManagerCompat { @Override public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, - int imageHeight) { + int imageWidth, int imageHeight) { return bitmap; } } diff --git a/src/com/android/launcher3/compat/AppWidgetManagerCompatVL.java b/src/com/android/launcher3/compat/AppWidgetManagerCompatVL.java index b3c5cc2a3..3bc3d0d80 100644 --- a/src/com/android/launcher3/compat/AppWidgetManagerCompatVL.java +++ b/src/com/android/launcher3/compat/AppWidgetManagerCompatVL.java @@ -107,18 +107,24 @@ class AppWidgetManagerCompatVL extends AppWidgetManagerCompat { @Override public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, - int imageHeight) { + int imageWidth, int imageHeight) { if (info.isCustomWidget || info.getProfile().equals(android.os.Process.myUserHandle())) { return bitmap; } // Add a user badge in the bottom right of the image. 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); + + // 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 int top = Math.max(imageHeight - badgeSize, badgeMinTop); + if (res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { badgeLocation.offset(0, top); } else { |