diff options
author | Joe Onorato <joeo@android.com> | 2009-09-15 15:07:25 -0400 |
---|---|---|
committer | Joe Onorato <joeo@android.com> | 2009-09-15 15:08:36 -0400 |
commit | 1291a8c236c84451321438cb68855f6f2eb24959 (patch) | |
tree | 46d7278d7dddbef2d8c09c2fc85714b8411cc015 /src/com/android/launcher2 | |
parent | b8898d5f8dfa71a8212dc502fda212b3ae029ad4 (diff) | |
download | android_packages_apps_Trebuchet-1291a8c236c84451321438cb68855f6f2eb24959.tar.gz android_packages_apps_Trebuchet-1291a8c236c84451321438cb68855f6f2eb24959.tar.bz2 android_packages_apps_Trebuchet-1291a8c236c84451321438cb68855f6f2eb24959.zip |
Add a glow selection to the icons. I'm not sure if I like it.
Diffstat (limited to 'src/com/android/launcher2')
-rw-r--r-- | src/com/android/launcher2/AllAppsView.java | 42 | ||||
-rw-r--r-- | src/com/android/launcher2/Utilities.java | 43 |
2 files changed, 66 insertions, 19 deletions
diff --git a/src/com/android/launcher2/AllAppsView.java b/src/com/android/launcher2/AllAppsView.java index f7908b6b5..2199432d1 100644 --- a/src/com/android/launcher2/AllAppsView.java +++ b/src/com/android/launcher2/AllAppsView.java @@ -39,7 +39,6 @@ import android.content.res.Resources; import android.database.DataSetObserver; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.graphics.BlurMaskFilter; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.drawable.BitmapDrawable; @@ -386,6 +385,7 @@ public class AllAppsView extends RSSurfaceView private Allocation mAllocTouchXBorders; private Bitmap mSelectionBitmap; + private Canvas mSelectionCanvas; Params mParams; State mState; @@ -534,20 +534,9 @@ public class AllAppsView extends RSSurfaceView mParams.save(); mState.save(); - mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_WIDTH_PX, Defines.ICON_HEIGHT_PX, - Bitmap.Config.ARGB_8888); - Bitmap selectionBitmap = mSelectionBitmap; - Paint paint = new Paint(); - float radius = 12 * getContext().getResources().getDisplayMetrics().density; - //paint.setMaskFilter(new BlurMaskFilter(radius, BlurMaskFilter.Blur.OUTER)); - Canvas canvas = new Canvas(selectionBitmap); - canvas.drawColor(0xffff0000); - - mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap, - Element.RGBA_8888, false); - mSelectedIcon.uploadToTexture(0); - - mState.selectedIconTexture = mSelectedIcon.getID(); + mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_TEXTURE_WIDTH_PX, + Defines.ICON_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888); + mSelectionCanvas = new Canvas(mSelectionBitmap); Log.d(TAG, "initData calling mRollo.setApps"); setApps(null); @@ -612,6 +601,9 @@ public class AllAppsView extends RSSurfaceView mScript.bindAllocation(mAllocLabelID, Defines.ALLOC_LABEL_IDS); } + if (mAllAppsList != null) { + selectIcon(0); // TODO remove + } mState.save(); } @@ -676,13 +668,29 @@ public class AllAppsView extends RSSurfaceView * You need to call save() on mState on your own after calling this. */ void selectIcon(int x, int y, int scrollX, int currentPage) { - int iconCount = mAllAppsList.size(); int index = chooseTappedIcon(x, y, scrollX, currentPage); + selectIcon(index); + } + + void selectIcon(int index) { + Log.d(TAG, "selectIcon index=" + index); + int iconCount = mAllAppsList.size(); if (index < 0 || index >= iconCount) { mState.selectedIconIndex = -1; return; } else { mState.selectedIconIndex = index; + + Bitmap selectionBitmap = mSelectionBitmap; + + Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas, + selectionBitmap.getWidth(), selectionBitmap.getHeight(), + mAllAppsList.get(index).iconBitmap); + + mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap, + Element.RGBA_8888, false); + mSelectedIcon.uploadToTexture(0); + mState.selectedIconTexture = mSelectedIcon.getID(); } } @@ -690,7 +698,7 @@ public class AllAppsView extends RSSurfaceView * You need to call save() on mState on your own after calling this. */ void clearSelectedIcon() { - mState.selectedIconIndex = -1; + //mState.selectedIconIndex = -1; } } } diff --git a/src/com/android/launcher2/Utilities.java b/src/com/android/launcher2/Utilities.java index 073b17927..50757ca59 100644 --- a/src/com/android/launcher2/Utilities.java +++ b/src/com/android/launcher2/Utilities.java @@ -20,10 +20,12 @@ import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.PaintDrawable; import android.graphics.Bitmap; +import android.graphics.BlurMaskFilter; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PaintFlagsDrawFilter; import android.graphics.PixelFormat; +import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Typeface; @@ -39,12 +41,17 @@ import android.content.Context; * Various utilities shared amongst the Launcher's classes. */ final class Utilities { + private static final String TAG = "Launcher.Utilities"; + private static int sIconWidth = -1; private static int sIconHeight = -1; private static int sIconTextureWidth = -1; private static int sIconTextureHeight = -1; private static final Paint sPaint = new Paint(); + private static final Paint sBlurPaint = new Paint(); + private static final Paint sGlowColorPaint = new Paint(); + private static final Paint sEmptyPaint = new Paint(); private static final Rect sBounds = new Rect(); private static final Rect sOldBounds = new Rect(); private static Canvas sCanvas = new Canvas(); @@ -236,6 +243,32 @@ final class Utilities { } } + static void drawSelectedAllAppsBitmap(Canvas dest, int destWidth, int destHeight, Bitmap src) { + synchronized (sCanvas) { // we share the statics :-( + if (sIconWidth == -1) { + // We can't have gotten to here without src being initialized, which + // comes from this file already. So just assert. + //initStatics(context); + throw new RuntimeException("Assertion failed: Utilities not initialized"); + } + + dest.drawColor(0, PorterDuff.Mode.CLEAR); + + final float scale = 1.55f; + Bitmap scaled = Bitmap.createScaledBitmap(src, (int)(src.getWidth()*scale), + (int)(src.getHeight()*scale), true); + + int[] xy = new int[2]; + Bitmap mask = scaled.extractAlpha(sBlurPaint, xy); + + dest.drawBitmap(mask, (destWidth - mask.getWidth()) / 2, + (destHeight - mask.getHeight()) / 2, sGlowColorPaint); + dest.drawBitmap(src, (destWidth - src.getWidth()) / 2, + (destHeight - src.getHeight()) / 2, sEmptyPaint); + + mask.recycle(); + } + } /** * Returns a Bitmap representing the thumbnail of the specified Bitmap. @@ -289,8 +322,14 @@ final class Utilities { private static void initStatics(Context context) { final Resources resources = context.getResources(); + final DisplayMetrics metrics = resources.getDisplayMetrics(); + final float density = metrics.density; + sIconWidth = sIconHeight = (int) resources.getDimension(android.R.dimen.app_icon_size); sIconTextureWidth = sIconTextureHeight = roundToPow2(sIconWidth); + + sBlurPaint.setMaskFilter(new BlurMaskFilter(7 * density, BlurMaskFilter.Blur.NORMAL)); + sGlowColorPaint.setColor(0xffff9000); } static class BubbleText { @@ -333,7 +372,7 @@ final class Utilities { rectPaint.setColor(0xff000000); rectPaint.setAntiAlias(true); - Log.d(Launcher.LOG_TAG, "scale=" + scale + " textSize=" + (13*scale)); + Log.d(TAG, "scale=" + scale + " textSize=" + (13*scale)); TextPaint textPaint = mTextPaint = new TextPaint(); textPaint.setTypeface(Typeface.DEFAULT); @@ -352,7 +391,7 @@ final class Utilities { mBitmapWidth = roundToPow2((int)(mBubbleRect.width() + 0.5f)); mBitmapHeight = roundToPow2((int)((MAX_LINES * mLineHeight) + leading + 0.5f)); - Log.d(Launcher.LOG_TAG, "mBitmapWidth=" + mBitmapWidth + " mBitmapHeight=" + Log.d(TAG, "mBitmapWidth=" + mBitmapWidth + " mBitmapHeight=" + mBitmapHeight + " w=" + ((int)(mBubbleRect.width() + 0.5f)) + " h=" + ((int)((MAX_LINES * mLineHeight) + leading + 0.5f))); } |