Put the label into the same texture as the icon.

This commit is contained in:
Joe Onorato committed 2010-01-14 19:10:18 -05:00
1 parent c5cfa73ef9
commit f5e4dd01ad
5 files changed
+153 -149

No files matched your search

+34 -31
View File
@@ -273,16 +273,16 @@ int positionStrip(float row, float column, int isTop, float p, int isText)
if (isText) { if (isText) {
matrixScale(mat1, 1.f, 2.f, 1.f); matrixScale(mat1, 1.f, 2.f, 1.f);
} }
matrixTranslate(mat1, 0, soff - 0.97f, 0); matrixTranslate(mat1, 0, soff - 0.95f + 0.18f, 0);
} else { } else {
matrixLoadScale(mat1, 1.f, 0.85f, 1.f); matrixLoadScale(mat1, 1.f, 0.85f, 1.f);
if (isText) { if (isText) {
matrixScale(mat1, 1.f, 2.f, 1.f); matrixScale(mat1, 1.f, 2.f, 1.f);
} }
matrixTranslate(mat1, 0, soff - 0.45f, 0); matrixTranslate(mat1, 0, soff - 0.65f, 0);
} }
vpLoadTextureMatrix(mat1); vpLoadTextureMatrix(mat1);
return -soff * 10.f; return -(soff + 0.3f) * 10.f;
} }
void void
@@ -312,8 +312,12 @@ void drawFrontGrid(float rowOffset, float p)
int row, col; int row, col;
int iconNum = intRowOffset * 4; int iconNum = intRowOffset * 4;
float ymax = yoff; float ymax = yoff + rowHeight;
float ymin = yoff - (3 * rowHeight) - 70; float ymin = yoff - (3 * rowHeight) - 70;
float gridTop = yoff -3;
float gridBottom = ymin;
gridBottom += 50;
for (row = 0; row < 5; row++) { for (row = 0; row < 5; row++) {
float y = yoff - ((-rowFrac + row) * rowHeight); float y = yoff - ((-rowFrac + row) * rowHeight);
@@ -327,18 +331,28 @@ void drawFrontGrid(float rowOffset, float p)
float x = colWidth * col - ((128 - colWidth) / 2); float x = colWidth * col - ((128 - colWidth) / 2);
if ((y >= ymin) && (y <= ymax)) { if ((y >= ymin) && (y <= ymax)) {
float iconY = y - 20;
setColor(1.f, 1.f, 1.f, 1.f); setColor(1.f, 1.f, 1.f, 1.f);
if (state->selectedIconIndex == iconNum && !p) { if (state->selectedIconIndex == iconNum && !p) {
bindTexture(NAMED_PFTexNearest, 0, state->selectedIconTexture); bindTexture(NAMED_PFTexNearest, 0, state->selectedIconTexture);
drawSpriteScreenspace(x, y, 0, 128, 128); drawSpriteScreenspace(x, iconY, 0, 128, 128);
} }
bindTexture(NAMED_PFTexNearest, 0, loadI32(ALLOC_ICON_IDS, iconNum)); bindTexture(NAMED_PFTexNearest, 0, loadI32(ALLOC_ICON_IDS, iconNum));
if (!p) { if (!p) {
drawSpriteScreenspace(x, y, 0, 128, 128); int cropT = 0;
if (y > gridTop) {
cropT = y - gridTop;
}
int cropB = 0;
if (y < gridBottom) {
cropB = gridBottom - y;
}
drawSpriteScreenspaceCropped(x, iconY+cropB, 0, 128, 128-cropT-cropB,
0, 128-cropB, 128, -128+cropT+cropB);
} else { } else {
float px = ((x + 64) - (getWidth() / 2)) / (getWidth() / 2); float px = ((x + 64) - (getWidth() / 2)) / (getWidth() / 2);
float py = ((y + 64) - (getHeight() / 2)) / (getWidth() / 2); float py = ((iconY + 64) - (getHeight() / 2)) / (getWidth() / 2);
float d = 64.f / (getWidth() / 2); float d = 64.f / (getWidth() / 2);
px *= p + 1; px *= p + 1;
py *= p + 1; py *= p + 1;
@@ -348,15 +362,6 @@ void drawFrontGrid(float rowOffset, float p)
px + d, py - d, -p, 1, 1); px + d, py - d, -p, 1, 1);
} }
} }
float y2 = y - 44;
if ((y2 >= ymin) && (y2 <= ymax)) {
float a = maxf(0, 1.f - p * 5.f);
setColor(1.f, 1.f, 1.f, a);
bindTexture(NAMED_PFTexNearest, 0, loadI32(ALLOC_LABEL_IDS, iconNum));
drawSpriteScreenspace(x, y - 44, 0,
params->bubbleBitmapWidth, params->bubbleBitmapHeight);
}
} }
iconNum++; iconNum++;
} }
@@ -370,18 +375,14 @@ void drawStrip(float row, float column, int isTop, int iconNum, float p)
bindTexture(NAMED_PFTexMip, 0, loadI32(ALLOC_ICON_IDS, iconNum)); bindTexture(NAMED_PFTexMip, 0, loadI32(ALLOC_ICON_IDS, iconNum));
if (offset < -20) return; if (offset < -20) return;
offset = clamp(offset, 0, 199 - 20); offset = clamp(offset, 0, 199 - 20);
drawSimpleMeshRange(NAMED_SMMesh, offset * 6, 20 * 6);
if (isTop) { int len = 20;
offset = positionStrip(row - 0.72f, column, isTop, p, 1); if (isTop && (offset < 7)) {
} else { len -= 7 - offset;
offset = positionStrip(row + 0.73f, column, isTop, p, 1); offset = 7;
} }
if (offset < -20) return;
if (offset > 200) return; drawSimpleMeshRange(NAMED_SMMesh, offset * 6, len * 6);
bindTexture(NAMED_PFTexMip, 0, loadI32(ALLOC_LABEL_IDS, iconNum));
offset = clamp(offset, 0, 199 - 20);
drawSimpleMeshRange(NAMED_SMMesh, offset * 6, 20 * 6);
//drawSimpleMesh(NAMED_SMMesh); //drawSimpleMesh(NAMED_SMMesh);
} }
@@ -389,7 +390,7 @@ void drawTop(float rowOffset, float p)
{ {
int row, col; int row, col;
int iconNum = 0; int iconNum = 0;
for (row = 0; row < rowOffset; row++) { for (row = 0; row <= (int)(rowOffset+1); row++) {
for (col=0; col < 4; col++) { for (col=0; col < 4; col++) {
if (iconNum >= state->iconCount) { if (iconNum >= state->iconCount) {
return; return;
@@ -484,16 +485,18 @@ main(int launchID)
// Draw the icons ======================================== // Draw the icons ========================================
//bindProgramFragment(NAMED_PFColor); /*
//positionStrip(1, 0, 0); bindProgramFragment(NAMED_PFColor);
//drawSimpleMesh(NAMED_SMMesh); positionStrip(1, 0, 1, 0, 0);
drawSimpleMesh(NAMED_SMMesh);
*/
bindProgramFragment(NAMED_PFTexMip); bindProgramFragment(NAMED_PFTexMip);
drawTop(g_PosPage, 1-g_Zoom); drawTop(g_PosPage, 1-g_Zoom);
drawBottom(g_PosPage, 1-g_Zoom); drawBottom(g_PosPage, 1-g_Zoom);
bindProgramFragment(NAMED_PFTexMip);
{ {
float mat1[16]; float mat1[16];
matrixLoadIdentity(mat1); matrixLoadIdentity(mat1);
+21 -56
View File
@@ -125,15 +125,11 @@ public class AllAppsView extends RSSurfaceView
public static final int ALLOC_PARAMS = 0; public static final int ALLOC_PARAMS = 0;
public static final int ALLOC_STATE = 1; public static final int ALLOC_STATE = 1;
public static final int ALLOC_ICON_IDS = 3; public static final int ALLOC_ICON_IDS = 3;
public static final int ALLOC_LABEL_IDS = 4;
public static final int COLUMNS_PER_PAGE = 4; public static final int COLUMNS_PER_PAGE = 4;
public static final int ROWS_PER_PAGE = 4; public static final int ROWS_PER_PAGE = 4;
public static final int ICON_WIDTH_PX = 64;
public static final int ICON_TEXTURE_WIDTH_PX = 128; public static final int ICON_TEXTURE_WIDTH_PX = 128;
public static final int ICON_HEIGHT_PX = 64;
public static final int ICON_TEXTURE_HEIGHT_PX = 128; public static final int ICON_TEXTURE_HEIGHT_PX = 128;
public int SCREEN_WIDTH_PX; public int SCREEN_WIDTH_PX;
@@ -571,15 +567,18 @@ public class AllAppsView extends RSSurfaceView
&& mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) { && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex); ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
// We don't really have an accurate location to use. This will do. Bitmap bmp = Utilities.extractIconFromTexture(app.iconBitmap, getContext());
int screenX = mMotionDownRawX - (mDefines.ICON_WIDTH_PX / 2);
int screenY = mMotionDownRawY - mDefines.ICON_HEIGHT_PX;
int left = (mDefines.ICON_TEXTURE_WIDTH_PX - mDefines.ICON_WIDTH_PX) / 2; final int w = bmp.getWidth();
int top = (mDefines.ICON_TEXTURE_HEIGHT_PX - mDefines.ICON_HEIGHT_PX) / 2; final int h = bmp.getHeight();
mDragController.startDrag(app.iconBitmap, screenX, screenY,
left, top, mDefines.ICON_WIDTH_PX, mDefines.ICON_HEIGHT_PX, // We don't really have an accurate location to use. This will do.
this, app, DragController.DRAG_ACTION_COPY); int screenX = mMotionDownRawX - (w / 2);
int screenY = mMotionDownRawY - h;
mDragController.startDrag(bmp, screenX, screenY,
0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
bmp.recycle();
mLauncher.closeAllApps(true); mLauncher.closeAllApps(true);
} }
@@ -787,10 +786,6 @@ public class AllAppsView extends RSSurfaceView
private Allocation[] mIcons; private Allocation[] mIcons;
private int[] mIconIds; private int[] mIconIds;
private Allocation mAllocIconIds; private Allocation mAllocIconIds;
private Allocation[] mLabels;
private int[] mLabelIds;
private Allocation mAllocLabelIds;
private Allocation mSelectedIcon; private Allocation mSelectedIcon;
private int[] mTouchYBorders; private int[] mTouchYBorders;
@@ -883,7 +878,7 @@ public class AllAppsView extends RSSurfaceView
float maxAngle = 3.14f * 0.16f; float maxAngle = 3.14f * 0.16f;
float l = 1.f; float l = 1.f;
l = 1 - ((ct-5) * 0.10f); l = 1 - ((ct-7) * 0.10f);
if (ct > 7) { if (ct > 7) {
angle = maxAngle * (ct - 7) * 0.2f; angle = maxAngle * (ct - 7) * 0.2f;
angle = Math.min(angle, maxAngle); angle = Math.min(angle, maxAngle);
@@ -949,8 +944,8 @@ public class AllAppsView extends RSSurfaceView
Sampler nearest = sb.create(); Sampler nearest = sb.create();
ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null); ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null);
//mPFColor = bf.create(); mPFColor = bf.create();
//mPFColor.setName("PFColor"); mPFColor.setName("PFColor");
bf.setTexEnable(true, 0); bf.setTexEnable(true, 0);
bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0); bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0);
@@ -1040,7 +1035,6 @@ public class AllAppsView extends RSSurfaceView
mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS); mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE); mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS); mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
mRS.contextBindRootScript(mScript); mRS.contextBindRootScript(mScript);
} }
@@ -1071,16 +1065,15 @@ public class AllAppsView extends RSSurfaceView
mIconIds = new int[allocCount]; mIconIds = new int[allocCount];
mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount); mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount);
mLabels = new Allocation[count];
mLabelIds = new int[allocCount];
mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount);
Element ie8888 = Element.RGBA_8888(mRS); Element ie8888 = Element.RGBA_8888(mRS);
mState.iconCount = count; mState.iconCount = count;
long before = SystemClock.uptimeMillis();
for (int i=0; i < mState.iconCount; i++) { for (int i=0; i < mState.iconCount; i++) {
createAppIconAllocations(i, list.get(i)); createAppIconAllocations(i, list.get(i));
} }
long after = SystemClock.uptimeMillis();
//Log.d(TAG, "createAppIconAllocations took " + (after-before) + "ms");
if (mHasSurface) { if (mHasSurface) {
for (int i=0; i < mState.iconCount; i++) { for (int i=0; i < mState.iconCount; i++) {
uploadAppIcon(i, list.get(i)); uploadAppIcon(i, list.get(i));
@@ -1123,18 +1116,11 @@ public class AllAppsView extends RSSurfaceView
} }
private void createAppIconAllocations(int index, ApplicationInfo item) { private void createAppIconAllocations(int index, ApplicationInfo item) {
mIcons[index] = Allocation.createFromBitmap(mRS, item.iconBitmap, Bitmap bitmap = item.iconBitmap;
Element.RGBA_8888(mRS), true); mIcons[index] = Allocation.createFromBitmap(mRS, bitmap, Element.RGBA_8888(mRS), true);
frameBitmapAllocMips(mIcons[index], item.iconBitmap.getWidth(), frameBitmapAllocMips(mIcons[index], bitmap.getWidth(), bitmap.getHeight());
item.iconBitmap.getHeight());
mLabels[index] = Allocation.createFromBitmap(mRS, item.titleBitmap,
Element.RGBA_8888(mRS), true);
frameBitmapAllocMips(mLabels[index], item.titleBitmap.getWidth(),
item.titleBitmap.getHeight());
mIconIds[index] = mIcons[index].getID(); mIconIds[index] = mIcons[index].getID();
mLabelIds[index] = mLabels[index].getID();
} }
private void uploadAppIcon(int index, ApplicationInfo item) { private void uploadAppIcon(int index, ApplicationInfo item) {
@@ -1145,7 +1131,6 @@ public class AllAppsView extends RSSurfaceView
+ " item=" + item); + " item=" + item);
} }
mIcons[index].uploadToTexture(0); mIcons[index].uploadToTexture(0);
mLabels[index].uploadToTexture(0);
} }
/** /**
@@ -1157,21 +1142,13 @@ public class AllAppsView extends RSSurfaceView
int[] iconIds = new int[count]; int[] iconIds = new int[count];
mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count); mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count);
Allocation[] labels = new Allocation[count];
int[] labelIds = new int[count];
mAllocLabelIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count);
final int oldCount = mRollo.mState.iconCount; final int oldCount = mRollo.mState.iconCount;
System.arraycopy(mIcons, 0, icons, 0, oldCount); System.arraycopy(mIcons, 0, icons, 0, oldCount);
System.arraycopy(mIconIds, 0, iconIds, 0, oldCount); System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
System.arraycopy(mLabels, 0, labels, 0, oldCount);
System.arraycopy(mLabelIds, 0, labelIds, 0, oldCount);
mIcons = icons; mIcons = icons;
mIconIds = iconIds; mIconIds = iconIds;
mLabels = labels;
mLabelIds = labelIds;
} }
/** /**
@@ -1183,8 +1160,6 @@ public class AllAppsView extends RSSurfaceView
System.arraycopy(mIcons, index, mIcons, dest, count); System.arraycopy(mIcons, index, mIcons, dest, count);
System.arraycopy(mIconIds, index, mIconIds, dest, count); System.arraycopy(mIconIds, index, mIconIds, dest, count);
System.arraycopy(mLabels, index, mLabels, dest, count);
System.arraycopy(mLabelIds, index, mLabelIds, dest, count);
createAppIconAllocations(index, item); createAppIconAllocations(index, item);
@@ -1206,16 +1181,12 @@ public class AllAppsView extends RSSurfaceView
System.arraycopy(mIcons, src, mIcons, index, count); System.arraycopy(mIcons, src, mIcons, index, count);
System.arraycopy(mIconIds, src, mIconIds, index, count); System.arraycopy(mIconIds, src, mIconIds, index, count);
System.arraycopy(mLabels, src, mLabels, index, count);
System.arraycopy(mLabelIds, src, mLabelIds, index, count);
mRollo.mState.iconCount--; mRollo.mState.iconCount--;
final int last = mState.iconCount; final int last = mState.iconCount;
mIcons[last] = null; mIcons[last] = null;
mIconIds[last] = 0; mIconIds[last] = 0;
mLabels[last] = null;
mLabelIds[last] = 0;
} }
/** /**
@@ -1225,11 +1196,9 @@ public class AllAppsView extends RSSurfaceView
mRS.contextBindRootScript(null); mRS.contextBindRootScript(null);
mAllocIconIds.data(mIconIds); mAllocIconIds.data(mIconIds);
mAllocLabelIds.data(mLabelIds);
if (mScript != null) { // this happens when we init it if (mScript != null) { // this happens when we init it
mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS); mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
mScript.bindAllocation(mAllocLabelIds, Defines.ALLOC_LABEL_IDS);
} }
mState.save(); mState.save();
@@ -1344,7 +1313,7 @@ public class AllAppsView extends RSSurfaceView
ApplicationInfo info = mAllAppsList.get(index); ApplicationInfo info = mAllAppsList.get(index);
Bitmap selectionBitmap = mSelectionBitmap; Bitmap selectionBitmap = mSelectionBitmap;
Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas, Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas, selectionBitmap,
selectionBitmap.getWidth(), selectionBitmap.getHeight(), selectionBitmap.getWidth(), selectionBitmap.getHeight(),
pressed == SELECTED_PRESSED, info.iconBitmap); pressed == SELECTED_PRESSED, info.iconBitmap);
@@ -1399,10 +1368,6 @@ public class AllAppsView extends RSSurfaceView
Log.d(TAG, "mRollo.mIconIds.length=" + mIconIds.length); Log.d(TAG, "mRollo.mIconIds.length=" + mIconIds.length);
} }
Log.d(TAG, "mRollo.mIconIds=" + Arrays.toString(mIconIds)); Log.d(TAG, "mRollo.mIconIds=" + Arrays.toString(mIconIds));
if (mLabelIds != null) {
Log.d(TAG, "mRollo.mLabelIds.length=" + mLabelIds.length);
}
Log.d(TAG, "mRollo.mLabelIds=" + Arrays.toString(mLabelIds));
Log.d(TAG, "mRollo.mTouchXBorders=" + Arrays.toString(mTouchXBorders)); Log.d(TAG, "mRollo.mTouchXBorders=" + Arrays.toString(mTouchXBorders));
Log.d(TAG, "mRollo.mTouchYBorders=" + Arrays.toString(mTouchYBorders)); Log.d(TAG, "mRollo.mTouchYBorders=" + Arrays.toString(mTouchYBorders));
Log.d(TAG, "mRollo.mHasSurface=" + mHasSurface); Log.d(TAG, "mRollo.mHasSurface=" + mHasSurface);
+6 -3
View File
@@ -168,10 +168,13 @@ public class AppInfoCache {
application.title = info.activityInfo.name; application.title = info.activityInfo.name;
} }
// TODO: turn this on in froyo, not enough time for testing in mr3
//if (application.iconBitmap != null) {
// application.iconBitmap.recycle();
//}
application.iconBitmap = Utilities.createAllAppsBitmap( application.iconBitmap = Utilities.createAllAppsBitmap(
info.activityInfo.loadIcon(packageManager), context); info.activityInfo.loadIcon(packageManager),
application.title.toString(), bubble, context);
application.titleBitmap = bubble.createTextBitmap(application.title.toString());
} }
} }
@@ -36,11 +36,6 @@ class ApplicationInfo extends ItemInfo {
*/ */
CharSequence title; CharSequence title;
/**
* A bitmap of the application's text in the bubble.
*/
Bitmap titleBitmap;
/** /**
* The intent used to start the application. * The intent used to start the application.
*/ */
@@ -52,7 +47,7 @@ class ApplicationInfo extends ItemInfo {
Drawable icon; Drawable icon;
/** /**
* A bitmap version of the application icon. * What we show in all apps, including the text.
*/ */
Bitmap iconBitmap; Bitmap iconBitmap;
@@ -149,9 +144,9 @@ class ApplicationInfo extends ItemInfo {
ArrayList<ApplicationInfo> list) { ArrayList<ApplicationInfo> list) {
Log.d(tag, label + " size=" + list.size()); Log.d(tag, label + " size=" + list.size());
for (ApplicationInfo info: list) { for (ApplicationInfo info: list) {
Log.d(tag, " title=\"" + info.title + "\" titleBitmap=" + info.titleBitmap Log.d(tag, " title=\"" + info.title + "\" icon=" + info.icon
+ " icon=" + info.icon + " iconBitmap=" + info.iconBitmap + " iconBitmap=" + info.iconBitmap + " filtered=" + info.filtered
+ " filtered=" + info.filtered + " customIcon=" + info.customIcon); + " customIcon=" + info.customIcon);
} }
} }
} }
+88 -50
View File
@@ -52,6 +52,10 @@ final class Utilities {
private static int sIconTextureWidth = -1; private static int sIconTextureWidth = -1;
private static int sIconTextureHeight = -1; private static int sIconTextureHeight = -1;
private static int sTitleMargin = -1;
private static float sBlurRadius = -1;
private static Rect sIconTextureRect;
private static final Paint sPaint = new Paint(); private static final Paint sPaint = new Paint();
private static final Paint sBlurPaint = new Paint(); private static final Paint sBlurPaint = new Paint();
private static final Paint sGlowColorPressedPaint = new Paint(); private static final Paint sGlowColorPressedPaint = new Paint();
@@ -175,7 +179,8 @@ final class Utilities {
* Returns a bitmap suitable for the all apps view. The bitmap will be a power * Returns a bitmap suitable for the all apps view. The bitmap will be a power
* of two sized ARGB_8888 bitmap that can be used as a gl texture. * of two sized ARGB_8888 bitmap that can be used as a gl texture.
*/ */
static Bitmap createAllAppsBitmap(Drawable icon, Context context) { static Bitmap createAllAppsBitmap(Drawable icon, String title, BubbleText bubble,
Context context) {
synchronized (sCanvas) { // we share the statics :-( synchronized (sCanvas) { // we share the statics :-(
if (sIconWidth == -1) { if (sIconWidth == -1) {
initStatics(context); initStatics(context);
@@ -217,8 +222,8 @@ final class Utilities {
} }
// no intrinsic size --> use default size // no intrinsic size --> use default size
int textureWidth = sIconTextureWidth; final int textureWidth = sIconTextureWidth;
int textureHeight = sIconTextureHeight; final int textureHeight = sIconTextureHeight;
final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight, final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight,
Bitmap.Config.ARGB_8888); Bitmap.Config.ARGB_8888);
@@ -226,7 +231,7 @@ final class Utilities {
canvas.setBitmap(bitmap); canvas.setBitmap(bitmap);
final int left = (textureWidth-width) / 2; final int left = (textureWidth-width) / 2;
final int top = (textureHeight-height) / 2; final int top = sIconTextureRect.top;
if (false) { if (false) {
// draw a big box for the icon for debugging // draw a big box for the icon for debugging
@@ -242,12 +247,34 @@ final class Utilities {
icon.draw(canvas); icon.draw(canvas);
icon.setBounds(sOldBounds); icon.setBounds(sOldBounds);
if (title != null) {
bubble.drawText(canvas, title);
}
return bitmap; return bitmap;
} }
} }
static void drawSelectedAllAppsBitmap(Canvas dest, int destWidth, int destHeight, static Bitmap extractIconFromTexture(Bitmap src, Context context) {
boolean pressed, Bitmap src) { synchronized (sCanvas) { // we share the statics :-(
if (sIconWidth == -1) {
initStatics(context);
}
final Bitmap bitmap = Bitmap.createBitmap(sIconWidth, sIconHeight,
Bitmap.Config.ARGB_8888);
final Canvas canvas = sCanvas;
canvas.setBitmap(bitmap);
Rect r = new Rect(0, 0, sIconWidth, sIconHeight);
canvas.drawColor(0, PorterDuff.Mode.CLEAR);
canvas.drawBitmap(src, sIconTextureRect, r, sEmptyPaint);
return bitmap;
}
}
static void drawSelectedAllAppsBitmap(Canvas dest, Bitmap destBitmap,
int destWidth, int destHeight, boolean pressed, Bitmap src) {
synchronized (sCanvas) { // we share the statics :-( synchronized (sCanvas) { // we share the statics :-(
if (sIconWidth == -1) { if (sIconWidth == -1) {
// We can't have gotten to here without src being initialized, which // We can't have gotten to here without src being initialized, which
@@ -257,12 +284,14 @@ final class Utilities {
} }
dest.drawColor(0, PorterDuff.Mode.CLEAR); dest.drawColor(0, PorterDuff.Mode.CLEAR);
dest.drawBitmap(src, sIconTextureRect, sIconTextureRect, sEmptyPaint);
int[] xy = new int[2]; int[] xy = new int[2];
Bitmap mask = src.extractAlpha(sBlurPaint, xy); Bitmap mask = destBitmap.extractAlpha(sBlurPaint, xy);
float px = (destWidth - src.getWidth()) / 2; float px = (destWidth - src.getWidth()) / 2;
float py = (destHeight - src.getHeight()) / 2; float py = (destHeight - src.getHeight()) / 2;
dest.drawColor(0, PorterDuff.Mode.CLEAR);
dest.drawBitmap(mask, px + xy[0], py + xy[1], dest.drawBitmap(mask, px + xy[0], py + xy[1],
pressed ? sGlowColorPressedPaint : sGlowColorFocusedPaint); pressed ? sGlowColorPressedPaint : sGlowColorFocusedPaint);
@@ -341,6 +370,12 @@ final class Utilities {
sIconWidth = sIconHeight = (int) resources.getDimension(android.R.dimen.app_icon_size); sIconWidth = sIconHeight = (int) resources.getDimension(android.R.dimen.app_icon_size);
sIconTextureWidth = sIconTextureHeight = roundToPow2(sIconWidth); sIconTextureWidth = sIconTextureHeight = roundToPow2(sIconWidth);
sTitleMargin = (int)(1 * density);
sBlurRadius = 5 * density;
final int left = (sIconTextureWidth-sIconWidth)/2;
final int top = (int)(sBlurRadius) + 1;
sIconTextureRect = new Rect(left, top, left+sIconWidth, top+sIconHeight);
sBlurPaint.setMaskFilter(new BlurMaskFilter(5 * density, BlurMaskFilter.Blur.NORMAL)); sBlurPaint.setMaskFilter(new BlurMaskFilter(5 * density, BlurMaskFilter.Blur.NORMAL));
sGlowColorPressedPaint.setColor(0xffffc300); sGlowColorPressedPaint.setColor(0xffffc300);
sGlowColorPressedPaint.setMaskFilter(TableMaskFilter.CreateClipTable(0, 30)); sGlowColorPressedPaint.setMaskFilter(TableMaskFilter.CreateClipTable(0, 30));
@@ -364,60 +399,65 @@ final class Utilities {
private int mBitmapHeight; private int mBitmapHeight;
BubbleText(Context context) { BubbleText(Context context) {
final Resources resources = context.getResources(); synchronized (sCanvas) { // we share the statics :-(
if (sIconWidth == -1) {
initStatics(context);
}
final Resources resources = context.getResources();
final float scale = resources.getDisplayMetrics().density; final float scale = resources.getDisplayMetrics().density;
final float paddingLeft = 5.0f * scale; final float paddingLeft = 5.0f * scale;
final float paddingRight = 5.0f * scale; final float paddingRight = 5.0f * scale;
final float cellWidth = resources.getDimension(R.dimen.workspace_cell_width); final float cellWidth = resources.getDimension(R.dimen.workspace_cell_width);
final float bubbleWidth = cellWidth - paddingLeft - paddingRight; final float bubbleWidth = cellWidth - paddingLeft - paddingRight;
mBubblePadding = 3.0f * scale; mBubblePadding = 3.0f * scale;
RectF bubbleRect = mBubbleRect; RectF bubbleRect = mBubbleRect;
bubbleRect.left = 0; bubbleRect.left = 0;
bubbleRect.top = 0; bubbleRect.top = 0;
bubbleRect.right = (int)(bubbleWidth+0.5f); bubbleRect.right = (int)(bubbleWidth+0.5f);
mTextWidth = bubbleWidth - mBubblePadding - mBubblePadding; mTextWidth = bubbleWidth - mBubblePadding - mBubblePadding;
Paint rectPaint = new Paint(); Paint rectPaint = new Paint();
rectPaint.setColor(0xff000000); rectPaint.setColor(0xff000000);
rectPaint.setAntiAlias(true); rectPaint.setAntiAlias(true);
TextPaint textPaint = mTextPaint = new TextPaint(); TextPaint textPaint = mTextPaint = new TextPaint();
textPaint.setTypeface(Typeface.DEFAULT); textPaint.setTypeface(Typeface.DEFAULT);
textPaint.setTextSize(13*scale); textPaint.setTextSize(13*scale);
textPaint.setColor(0xffffffff); //textPaint.setColor(0xff00ff00);
textPaint.setAntiAlias(true); textPaint.setColor(0xffffffff);
if (TEXT_BURN) { textPaint.setAntiAlias(true);
textPaint.setShadowLayer(8, 0, 0, 0xff000000); if (TEXT_BURN) {
} textPaint.setShadowLayer(8, 0, 0, 0xff000000);
}
float ascent = -textPaint.ascent(); final int iconTop = (int)(sBlurRadius) + 1;
float descent = textPaint.descent(); final int iconBottom = iconTop + sIconHeight;
float leading = 0.0f;//(ascent+descent) * 0.1f;
mLeading = (int)(leading + 0.5f);
mFirstLineY = (int)(leading + ascent + 0.5f);
mLineHeight = (int)(leading + ascent + descent + 0.5f);
mBitmapWidth = roundToPow2((int)(mBubbleRect.width() + 0.5f)); float ascent = -textPaint.ascent();
mBitmapHeight = roundToPow2((int)((MAX_LINES * mLineHeight) + leading + 0.5f)); float descent = textPaint.descent();
float leading = -1.0f;//(ascent+descent) * 0.1f;
mLeading = (int)(leading + 0.5f);
mFirstLineY = (int)(iconBottom + sTitleMargin + ascent + 0.5f);
mLineHeight = (int)(leading + ascent + descent + 0.5f);
mBubbleRect.offsetTo((mBitmapWidth-mBubbleRect.width())/2, 0); mBitmapWidth = roundToPow2((int)(mBubbleRect.width() + 0.5f));
mBitmapHeight = roundToPow2((int)((MAX_LINES * mLineHeight) + leading + 0.5f));
if (false) { mBubbleRect.offsetTo((mBitmapWidth-mBubbleRect.width())/2, 0);
Log.d(TAG, "mBitmapWidth=" + mBitmapWidth + " mBitmapHeight="
+ mBitmapHeight + " w=" + ((int)(mBubbleRect.width() + 0.5f)) if (false) {
+ " h=" + ((int)((MAX_LINES * mLineHeight) + leading + 0.5f))); Log.d(TAG, "mBitmapWidth=" + mBitmapWidth + " mBitmapHeight="
+ mBitmapHeight + " w=" + ((int)(mBubbleRect.width() + 0.5f))
+ " h=" + ((int)((MAX_LINES * mLineHeight) + leading + 0.5f)));
}
} }
} }
/** You own the bitmap after this and you must call recycle on it. */ void drawText(Canvas c, String text) {
Bitmap createTextBitmap(String text) {
Bitmap b = Bitmap.createBitmap(mBitmapWidth, mBitmapHeight, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
StaticLayout layout = new StaticLayout(text, mTextPaint, (int)mTextWidth, StaticLayout layout = new StaticLayout(text, mTextPaint, (int)mTextWidth,
Alignment.ALIGN_CENTER, 1, 0, true); Alignment.ALIGN_CENTER, 1, 0, true);
int lineCount = layout.getLineCount(); int lineCount = layout.getLineCount();
@@ -438,8 +478,6 @@ final class Utilities {
c.drawText(text.substring(layout.getLineStart(i), layout.getLineEnd(i)), c.drawText(text.substring(layout.getLineStart(i), layout.getLineEnd(i)),
x, y, mTextPaint); x, y, mTextPaint);
} }
return b;
} }
private int height(int lineCount) { private int height(int lineCount) {