diff options
author | huiwan <huiwan@codeaurora.org> | 2014-11-10 10:35:03 -0800 |
---|---|---|
committer | Rajesh Yengisetty <rajesh@cyngn.com> | 2014-11-21 00:13:25 +0000 |
commit | 9b398417ff00bb67a43579c748fd335effad1c5b (patch) | |
tree | aa112a7fc0d0128df46e63795c4717f9263e2cf4 /src/com/android/launcher3/Utilities.java | |
parent | 783be63c0a6d9b47f900c5d711a6a1663f1ca112 (diff) | |
download | android_packages_apps_Trebuchet-9b398417ff00bb67a43579c748fd335effad1c5b.tar.gz android_packages_apps_Trebuchet-9b398417ff00bb67a43579c748fd335effad1c5b.tar.bz2 android_packages_apps_Trebuchet-9b398417ff00bb67a43579c748fd335effad1c5b.zip |
Launcher: show unread notify info number at APP icon on Launcher
Show APP's unread info number at Launcher:
- Register a receiver to receive the UNREAD_CHANGED event to update the APP icon
- When the unread number changed, recreate the icon bitmap of icon cache
Change-Id: I7dd0fb2c29959f1584682965fb1476e3f3c77739
Diffstat (limited to 'src/com/android/launcher3/Utilities.java')
-rw-r--r-- | src/com/android/launcher3/Utilities.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 80d4b22ce..addd74cfc 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -32,8 +32,11 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; +import android.graphics.Paint.Style; import android.graphics.PaintFlagsDrawFilter; import android.graphics.Rect; +import android.graphics.RectF; +import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.PaintDrawable; @@ -75,6 +78,48 @@ public final class Utilities { static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher_force_rotate"; public static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY); + static Bitmap createIconBitmap(Drawable icon, Context context, int count) { + Bitmap b = createIconBitmap(icon, context); + + if (!LauncherApplication.LAUNCHER_SHOW_UNREAD_NUMBER || count <= 0) { + return b; + } + + int textureWidth = b.getWidth(); + final Resources resources = context.getResources(); + final Canvas canvas = sCanvas; + canvas.setBitmap(b); + + float textsize = resources.getDimension(R.dimen.infomation_count_textsize); + Paint countPaint = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.DEV_KERN_TEXT_FLAG); + countPaint.setColor(Color.WHITE); + countPaint.setTextSize(textsize); + + String text = String.valueOf(count); + if (count >= 1000) { + text = "999+"; + } + + float count_hight = resources.getDimension(R.dimen.infomation_count_height); + float padding = resources.getDimension(R.dimen.infomation_count_padding); + float radius = resources.getDimension(R.dimen.infomation_count_circle_radius); + int textwidth = (int) (countPaint.measureText(text) + 1); + float width =textwidth + padding * 2; + width = Math.max(width, resources.getDimensionPixelSize(R.dimen.infomation_count_min_width)); + + RectF rect = new RectF(textureWidth - width -1, 1, textureWidth - 1, count_hight + 1); + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(resources.getColor(R.color.infomation_count_circle_color)); + canvas.drawRoundRect(rect , radius, radius, paint); + + float x = textureWidth - (width + textwidth ) / 2 - 1; + float y = textsize; + canvas.drawText(text, x, y, countPaint); + + return b; + } + /** * Returns a FastBitmapDrawable with the icon, accurately sized. */ |