OSDN Git Service

Work profile badge alignment
authorHyunyoung Song <hyunyoungs@google.com>
Mon, 15 Jun 2015 19:26:54 +0000 (12:26 -0700)
committerHyunyoung Song <hyunyoungs@google.com>
Mon, 15 Jun 2015 19:26:54 +0000 (12:26 -0700)
b/21336417

Change-Id: Icd54320fa0d0976cac0ae66d180cc2c99ddd0c1c

res/values/dimens.xml
src/com/android/launcher3/WidgetPreviewLoader.java
src/com/android/launcher3/compat/AppWidgetManagerCompatV16.java
src/com/android/launcher3/compat/AppWidgetManagerCompatVL.java

index 2184ead..370b312 100644 (file)
 
 <!-- Sizes for managed profile badges -->
     <dimen name="profile_badge_size">24dp</dimen>
-    <dimen name="profile_badge_margin">4dp</dimen>
+    <dimen name="profile_badge_margin">5dp</dimen>
     <dimen name="profile_badge_minimum_top">2dp</dimen>
 
 <!-- Shadows and outlines -->
index cfeced2..75952d1 100644 (file)
@@ -64,7 +64,7 @@ public class WidgetPreviewLoader {
     private final UserManagerCompat mUserManager;
     private final AppWidgetManagerCompat mManager;
     private final CacheDb mDb;
-    private final InvariantDeviceProfile mDeviceProfile;
+    private final int mProfileBadgeMargin;
 
     private final MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
     @Thunk final Handler mWorkerHandler;
@@ -76,7 +76,8 @@ public class WidgetPreviewLoader {
         mUserManager = UserManagerCompat.getInstance(context);
         mDb = new CacheDb(context);
         mWorkerHandler = new Handler(LauncherModel.getWorkerLooper());
-        mDeviceProfile = inv;
+        mProfileBadgeMargin = context.getResources()
+                .getDimensionPixelSize(R.dimen.profile_badge_margin);
     }
 
     /**
@@ -401,7 +402,7 @@ public class WidgetPreviewLoader {
         }
 
         // Draw the scaled preview into the final bitmap
-        int x = (preview.getWidth() - previewWidth) / 2;
+        int x = (preview.getWidth() - previewWidth - mProfileBadgeMargin) / 2;
         if (widgetPreviewExists) {
             drawable.setBounds(x, 0, x + previewWidth, previewHeight);
             drawable.draw(c);
@@ -445,7 +446,8 @@ public class WidgetPreviewLoader {
             } catch (Resources.NotFoundException e) { }
             c.setBitmap(null);
         }
-        return mManager.getBadgeBitmap(info, preview, Math.min(preview.getHeight(), previewHeight));
+        int imageHeight = Math.min(preview.getHeight(), previewHeight + mProfileBadgeMargin);
+        return mManager.getBadgeBitmap(info, preview, imageHeight);
     }
 
     private Bitmap generateShortcutPreview(
index a64c705..f7f4b7e 100644 (file)
@@ -87,7 +87,8 @@ class AppWidgetManagerCompatV16 extends AppWidgetManagerCompat {
     }
 
     @Override
-    public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, int imageHeight) {
+    public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap,
+            int imageHeight) {
         return bitmap;
     }
 }
index 96ace84..13712d8 100644 (file)
@@ -108,7 +108,8 @@ class AppWidgetManagerCompatVL extends AppWidgetManagerCompat {
     }
 
     @Override
-    public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap, int imageHeight) {
+    public Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap,
+            int imageHeight) {
         if (info.isCustomWidget || info.getProfile().equals(android.os.Process.myUserHandle())) {
             return bitmap;
         }
@@ -116,15 +117,14 @@ class AppWidgetManagerCompatVL extends AppWidgetManagerCompat {
         // 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 badgeMargin = res.getDimensionPixelSize(R.dimen.profile_badge_margin);
         final int badgeMinTop = res.getDimensionPixelSize(R.dimen.profile_badge_minimum_top);
         final Rect badgeLocation = new Rect(0, 0, badgeSize, badgeSize);
 
-        final int top = Math.max(imageHeight - badgeSize - badgeMargin, badgeMinTop);
+        final int top = Math.max(imageHeight - badgeSize, badgeMinTop);
         if (res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) {
-            badgeLocation.offset(badgeMargin, top);
+            badgeLocation.offset(0, top);
         } else {
-            badgeLocation.offset(bitmap.getWidth() - badgeSize - badgeMargin, top);
+            badgeLocation.offset(bitmap.getWidth() - badgeSize, top);
         }
 
         Drawable drawable = mPm.getUserBadgedDrawableForDensity(