diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2016-07-19 14:19:53 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2016-07-20 11:26:22 -0700 |
commit | 4a464794f202c6e913ff0ea442d248e86bebbd12 (patch) | |
tree | ba45ff264757e0c20f4217e36e0729f2061a1231 /src/com/android/launcher3/Utilities.java | |
parent | 77ba6b9cad542a78910b6d7c638a1254b31d79ab (diff) | |
download | android_packages_apps_Trebuchet-4a464794f202c6e913ff0ea442d248e86bebbd12.tar.gz android_packages_apps_Trebuchet-4a464794f202c6e913ff0ea442d248e86bebbd12.tar.bz2 android_packages_apps_Trebuchet-4a464794f202c6e913ff0ea442d248e86bebbd12.zip |
Adding support for dynamically adding shadows to the icon
Change-Id: I94d98750aea1faef8879e25990aa5c41a4894708
Diffstat (limited to 'src/com/android/launcher3/Utilities.java')
-rw-r--r-- | src/com/android/launcher3/Utilities.java | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index cedbe74c7..7b1a16c5f 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -40,6 +40,7 @@ import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PaintFlagsDrawFilter; import android.graphics.Rect; +import android.graphics.RectF; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.PaintDrawable; @@ -64,6 +65,7 @@ import android.widget.Toast; import com.android.launcher3.compat.UserHandleCompat; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.config.ProviderConfig; +import com.android.launcher3.graphics.ShadowGenerator; import com.android.launcher3.util.IconNormalizer; import java.io.ByteArrayOutputStream; @@ -244,7 +246,7 @@ public final class Utilities { public static Bitmap createBadgedIconBitmap( Drawable icon, UserHandleCompat user, Context context) { float scale = FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION ? - 1 : IconNormalizer.getInstance().getScale(icon); + 1 : IconNormalizer.getInstance().getScale(icon, null); Bitmap bitmap = createIconBitmap(icon, context, scale); if (Utilities.ATLEAST_LOLLIPOP && user != null && !UserHandleCompat.myUserHandle().equals(user)) { @@ -262,6 +264,34 @@ public final class Utilities { } /** + * Same as {@link #createBadgedIconBitmap} but adds a shadow before badging the icon + */ + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public static Bitmap createBadgedIconBitmapWithShadow( + Drawable icon, UserHandleCompat user, Context context) { + RectF iconBounds = new RectF(); + float scale = FeatureFlags.LAUNCHER3_DISABLE_ICON_NORMALIZATION ? + 1 : IconNormalizer.getInstance().getScale(icon, iconBounds); + scale = Math.min(scale, ShadowGenerator.getScaleForBounds(iconBounds)); + + Bitmap bitmap = createIconBitmap(icon, context, scale); + bitmap = ShadowGenerator.getInstance().recreateIcon(bitmap); + if (Utilities.ATLEAST_LOLLIPOP && user != null + && !UserHandleCompat.myUserHandle().equals(user)) { + BitmapDrawable drawable = new FixedSizeBitmapDrawable(bitmap); + Drawable badged = context.getPackageManager().getUserBadgedIcon( + drawable, user.getUser()); + if (badged instanceof BitmapDrawable) { + return ((BitmapDrawable) badged).getBitmap(); + } else { + return createIconBitmap(badged, context); + } + } else { + return bitmap; + } + } + + /** * Returns a bitmap suitable for the all apps view. */ public static Bitmap createIconBitmap(Drawable icon, Context context) { |