Merge "Fixing some issues with AppsCustomize" into ics-mr0

This commit is contained in:
Winson Chung
2011-10-12 14:49:45 -07:00
committed by Android (Google) Code Review
9 changed files with 110 additions and 88 deletions
+7 -15
View File
@@ -45,12 +45,8 @@
android:ellipsize="marquee" android:ellipsize="marquee"
android:fadingEdge="horizontal" android:fadingEdge="horizontal"
android:textColor="#FFBBBBBB" android:textColor="#FFFFFFFF"
android:textSize="14sp" android:textSize="13sp" />
android:shadowColor="#FF000000"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0" />
<!-- The original dimensions of the widget (can't be the same text as above due to different <!-- The original dimensions of the widget (can't be the same text as above due to different
style. --> style. -->
@@ -58,17 +54,13 @@
android:id="@+id/widget_dims" android:id="@+id/widget_dims"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="center"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:layout_weight="0" android:layout_weight="0"
android:gravity="left" android:gravity="left"
android:textColor="#FF666666" android:textColor="#FF555555"
android:textSize="12sp" android:textSize="12sp" />
android:shadowColor="#99000000"
android:shadowDx="0.0"
android:shadowDy="1.0"
android:shadowRadius="1.0" />
</LinearLayout> </LinearLayout>
<!-- The icon of the widget. --> <!-- The icon of the widget. -->
@@ -77,6 +69,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:adjustViewBounds="true" android:padding="8dp"
android:scaleType="fitStart" /> android:scaleType="matrix" />
</com.android.launcher2.PagedViewWidget> </com.android.launcher2.PagedViewWidget>
+1
View File
@@ -24,6 +24,7 @@
<dimen name="workspace_bottom_padding">0dp</dimen> <dimen name="workspace_bottom_padding">0dp</dimen>
<dimen name="workspace_page_spacing">-1dp</dimen> <dimen name="workspace_page_spacing">-1dp</dimen>
<!-- AppsCustomize -->
<integer name="apps_customize_cellCountX">4</integer> <integer name="apps_customize_cellCountX">4</integer>
<integer name="apps_customize_cellCountY">5</integer> <integer name="apps_customize_cellCountY">5</integer>
<dimen name="apps_customize_pageLayoutWidthGap">-1dp</dimen> <dimen name="apps_customize_pageLayoutWidthGap">-1dp</dimen>
+8
View File
@@ -49,4 +49,12 @@
<dimen name="button_bar_width_left_padding">8dp</dimen> <dimen name="button_bar_width_left_padding">8dp</dimen>
<dimen name="button_bar_width_right_padding">8dp</dimen> <dimen name="button_bar_width_right_padding">8dp</dimen>
<dimen name="button_bar_height_plus_padding">80dp</dimen> <dimen name="button_bar_height_plus_padding">80dp</dimen>
<!-- AppsCustomize -->
<dimen name="apps_customize_pageLayoutPaddingTop">16dp</dimen>
<dimen name="apps_customize_pageLayoutPaddingBottom">20dp</dimen>
<dimen name="apps_customize_pageLayoutPaddingLeft">8dp</dimen>
<dimen name="apps_customize_pageLayoutPaddingRight">8dp</dimen>
<dimen name="apps_customize_cell_height">92dp</dimen>
<dimen name="apps_customize_widget_cell_height_gap">16dp</dimen>
</resources> </resources>
+12
View File
@@ -32,4 +32,16 @@
<item name="android:paddingTop">@dimen/toolbar_button_vertical_padding</item> <item name="android:paddingTop">@dimen/toolbar_button_vertical_padding</item>
<item name="android:paddingBottom">@dimen/toolbar_button_vertical_padding</item> <item name="android:paddingBottom">@dimen/toolbar_button_vertical_padding</item>
</style> </style>
<!-- AppsCustomize -->
<style name="WorkspaceIcon.Portrait.AppsCustomize">
<item name="android:singleLine">false</item>
<item name="android:maxLines">2</item>
<item name="android:background">@null</item>
<item name="android:paddingTop">4dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:paddingLeft">0dp</item>
<item name="android:paddingRight">0dp</item>
<item name="android:drawablePadding">6dp</item>
</style>
</resources> </resources>
+3 -3
View File
@@ -55,11 +55,11 @@
<dimen name="apps_customize_tab_bar_height">56dp</dimen> <dimen name="apps_customize_tab_bar_height">56dp</dimen>
<dimen name="app_icon_size">48dp</dimen> <dimen name="app_icon_size">48dp</dimen>
<!-- The width can be 72dp because we don't have L/R padding --> <!-- The width can be 72dp because we don't have L/R padding -->
<dimen name="apps_customize_cell_width">72dp</dimen> <dimen name="apps_customize_cell_width">74dp</dimen>
<dimen name="apps_customize_cell_height">80dp</dimen> <dimen name="apps_customize_cell_height">82dp</dimen>
<dimen name="apps_customize_max_gap">18dp</dimen> <dimen name="apps_customize_max_gap">18dp</dimen>
<dimen name="apps_customize_widget_cell_width_gap">10dp</dimen> <dimen name="apps_customize_widget_cell_width_gap">10dp</dimen>
<dimen name="apps_customize_widget_cell_height_gap">10dp</dimen> <dimen name="apps_customize_widget_cell_height_gap">8dp</dimen>
<dimen name="title_texture_width">120px</dimen> <dimen name="title_texture_width">120px</dimen>
<!-- height of the bottom row of controls --> <!-- height of the bottom row of controls -->
+4 -2
View File
@@ -95,12 +95,14 @@
</style> </style>
<style name="WorkspaceIcon.Portrait.AppsCustomize"> <style name="WorkspaceIcon.Portrait.AppsCustomize">
<item name="android:singleLine">false</item>
<item name="android:maxLines">2</item>
<item name="android:background">@null</item> <item name="android:background">@null</item>
<item name="android:paddingTop">4dp</item> <item name="android:paddingTop">0dp</item>
<item name="android:paddingBottom">0dp</item> <item name="android:paddingBottom">0dp</item>
<item name="android:paddingLeft">0dp</item> <item name="android:paddingLeft">0dp</item>
<item name="android:paddingRight">0dp</item> <item name="android:paddingRight">0dp</item>
<item name="android:drawablePadding">8dp</item> <item name="android:drawablePadding">2dp</item>
</style> </style>
<style name="WorkspaceIcon.Landscape.AppsCustomize"> <style name="WorkspaceIcon.Landscape.AppsCustomize">
<item name="android:background">@null</item> <item name="android:background">@null</item>
@@ -31,10 +31,11 @@ import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.Bitmap.Config; import android.graphics.RectF;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Process; import android.os.Process;
@@ -46,7 +47,6 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.animation.AccelerateInterpolator; import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.GridLayout; import android.widget.GridLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.Toast; import android.widget.Toast;
@@ -277,7 +277,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
@Override @Override
protected void init() { protected void init() {
super.init(); super.init();
mCenterPagesVertically = false; mCenterPagesVertically = true;
Context context = getContext(); Context context = getContext();
Resources r = context.getResources(); Resources r = context.getResources();
@@ -531,8 +531,11 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
// Compose the drag image // Compose the drag image
Bitmap b; Bitmap b;
Drawable preview = image.getDrawable(); Drawable preview = image.getDrawable();
int w = preview.getIntrinsicWidth(); RectF mTmpScaleRect = new RectF(0f,0f,1f,1f);
int h = preview.getIntrinsicHeight(); image.getImageMatrix().mapRect(mTmpScaleRect);
float scale = mTmpScaleRect.right;
int w = (int) (preview.getIntrinsicWidth() * scale);
int h = (int) (preview.getIntrinsicHeight() * scale);
if (createItemInfo instanceof PendingAddWidgetInfo) { if (createItemInfo instanceof PendingAddWidgetInfo) {
PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) createItemInfo; PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) createItemInfo;
int[] spanXY = mLauncher.getSpanForWidget(createWidgetInfo, null); int[] spanXY = mLauncher.getSpanForWidget(createWidgetInfo, null);
@@ -540,7 +543,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
createItemInfo.spanY = spanXY[1]; createItemInfo.spanY = spanXY[1];
b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
renderDrawableToBitmap(preview, b, 0, 0, w, h, 1, 1, mDragViewMultiplyColor); renderDrawableToBitmap(preview, b, 0, 0, w, h, scale, mDragViewMultiplyColor);
} else { } else {
// Workaround for the fact that we don't keep the original ResolveInfo associated with // Workaround for the fact that we don't keep the original ResolveInfo associated with
// the shortcut around. To get the icon, we just render the preview image (which has // the shortcut around. To get the icon, we just render the preview image (which has
@@ -891,15 +894,18 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
layout.setMinimumWidth(getPageContentWidth()); layout.setMinimumWidth(getPageContentWidth());
layout.measure(widthSpec, heightSpec); layout.measure(widthSpec, heightSpec);
} }
private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h, private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h) {
float scaleX, float scaleY) { renderDrawableToBitmap(d, bitmap, x, y, w, h, 1f, 0xFFFFFFFF);
renderDrawableToBitmap(d, bitmap, x, y, w, h, scaleX, scaleY, 0xFFFFFFFF);
} }
private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h, private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h,
float scaleX, float scaleY, int multiplyColor) { float scale) {
renderDrawableToBitmap(d, bitmap, x, y, w, h, scale, 0xFFFFFFFF);
}
private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h,
float scale, int multiplyColor) {
if (bitmap != null) { if (bitmap != null) {
Canvas c = new Canvas(bitmap); Canvas c = new Canvas(bitmap);
c.scale(scaleX, scaleY); c.scale(scale, scale);
Rect oldBounds = d.copyBounds(); Rect oldBounds = d.copyBounds();
d.setBounds(x, y, x + w, y + h); d.setBounds(x, y, x + w, y + h);
d.draw(c); d.draw(c);
@@ -911,26 +917,20 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
} }
} }
private Bitmap getShortcutPreview(ResolveInfo info, int cellWidth, int cellHeight) { private Bitmap getShortcutPreview(ResolveInfo info, int cellWidth, int cellHeight) {
// Render the background
int offset = (int) (mAppIconSize * sWidgetPreviewIconPaddingPercentage);
int bitmapSize = mAppIconSize + 2 * offset;
Bitmap preview = Bitmap.createBitmap(bitmapSize, bitmapSize, Config.ARGB_8888);
renderDrawableToBitmap(mDefaultWidgetBackground, preview, 0, 0, bitmapSize, bitmapSize);
// Render the icon // Render the icon
Bitmap preview = Bitmap.createBitmap(cellWidth, mAppIconSize, Config.ARGB_8888);
Drawable icon = mIconCache.getFullResIcon(info, mPackageManager); Drawable icon = mIconCache.getFullResIcon(info, mPackageManager);
renderDrawableToBitmap(icon, preview, 0, 0, mAppIconSize, mAppIconSize, 1f, 1f); renderDrawableToBitmap(icon, preview, offset, offset, mAppIconSize, mAppIconSize);
return preview; return preview;
} }
private Bitmap getWidgetPreview(AppWidgetProviderInfo info, private Bitmap getWidgetPreview(AppWidgetProviderInfo info,
int cellHSpan, int cellVSpan, int cellWidth, int cellHeight) { int cellHSpan, int cellVSpan, int cellWidth, int cellHeight) {
// Calculate the size of the drawable
cellHSpan = Math.max(mMinWidgetSpan, Math.min(mMaxWidgetSpan, cellHSpan));
cellVSpan = Math.max(mMinWidgetSpan, Math.min(mMaxWidgetSpan, cellVSpan));
int expectedWidth = mWidgetSpacingLayout.estimateCellWidth(cellHSpan);
int expectedHeight = mWidgetSpacingLayout.estimateCellHeight(cellVSpan);
// Scale down the bitmap to fit the space
float widgetPreviewScale = (float) cellWidth / expectedWidth;
expectedWidth = (int) (widgetPreviewScale * expectedWidth);
expectedHeight = (int) (widgetPreviewScale * expectedHeight);
// Load the preview image if possible // Load the preview image if possible
String packageName = info.provider.getPackageName(); String packageName = info.provider.getPackageName();
Drawable drawable = null; Drawable drawable = null;
@@ -941,49 +941,59 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
Log.w(LOG_TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon) Log.w(LOG_TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon)
+ " for provider: " + info.provider); + " for provider: " + info.provider);
} else { } else {
// Scale down the preview to the dimensions we want // Scale down the preview to something that is closer to the cellWidth/Height
int imageWidth = drawable.getIntrinsicWidth(); int imageWidth = drawable.getIntrinsicWidth();
int imageHeight = drawable.getIntrinsicHeight(); int imageHeight = drawable.getIntrinsicHeight();
float aspect = (float) imageWidth / imageHeight; int bitmapWidth = imageWidth;
int newWidth = imageWidth; int bitmapHeight = imageHeight;
int newHeight = imageHeight; if (imageWidth > imageHeight) {
if (aspect > 1f) { bitmapWidth = cellWidth;
newWidth = expectedWidth; bitmapHeight = (int) (imageHeight * ((float) bitmapWidth / imageWidth));
newHeight = (int) (imageHeight * ((float) expectedWidth / imageWidth));
} else { } else {
newHeight = expectedHeight; bitmapHeight = cellHeight;
newWidth = (int) (imageWidth * ((float) expectedHeight / imageHeight)); bitmapWidth = (int) (imageWidth * ((float) bitmapHeight / imageHeight));
} }
preview = Bitmap.createBitmap(newWidth, newHeight, Config.ARGB_8888); preview = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
renderDrawableToBitmap(drawable, preview, 0, 0, newWidth, newHeight, 1f, 1f); renderDrawableToBitmap(drawable, preview, 0, 0, bitmapWidth, bitmapHeight);
} }
} }
// Generate a preview image if we couldn't load one // Generate a preview image if we couldn't load one
if (drawable == null) { if (drawable == null) {
Resources resources = mLauncher.getResources(); Resources resources = mLauncher.getResources();
int bitmapWidth; // TODO: This actually uses the apps customize cell layout params, where as we make want
int bitmapHeight; // the Workspace params for more accuracy.
int targetWidth = mWidgetSpacingLayout.estimateCellWidth(cellHSpan);
int targetHeight = mWidgetSpacingLayout.estimateCellHeight(cellVSpan);
int bitmapWidth = targetWidth;
int bitmapHeight = targetHeight;
int offset = (int) (mAppIconSize * sWidgetPreviewIconPaddingPercentage);
float iconScale = 1f;
// Specify the dimensions of the bitmap (since we are using a default preview bg with // Determine the size of the bitmap we want to draw
// the full icon, we only imply the aspect ratio of the widget)
if (cellHSpan == cellVSpan) { if (cellHSpan == cellVSpan) {
bitmapWidth = bitmapHeight = cellWidth; // For square widgets, we just have a fixed size for 1x1 and larger-than-1x1
expectedWidth = expectedHeight = mWidgetPreviewIconPaddedDimension; if (cellHSpan <= 1) {
} else if (cellHSpan >= cellVSpan) { bitmapWidth = bitmapHeight = mAppIconSize + 2 * offset;
bitmapWidth = expectedWidth = cellWidth; } else {
bitmapHeight = expectedHeight = mWidgetPreviewIconPaddedDimension; bitmapWidth = bitmapHeight = mAppIconSize + 4 * offset;
}
} else { } else {
// Note that in vertical widgets, we might not have enough space due to the text // Otherwise, ensure that we are properly sized within the cellWidth/Height
// label, so be conservative and use the width as a height bound if (targetWidth > targetHeight) {
bitmapWidth = expectedWidth = mWidgetPreviewIconPaddedDimension; bitmapWidth = Math.min(targetWidth, cellWidth);
bitmapHeight = expectedHeight = cellWidth; bitmapHeight = (int) (targetHeight * ((float) bitmapWidth / targetWidth));
iconScale = Math.min((float) bitmapHeight / (mAppIconSize + 2 * offset), 1f);
} else {
bitmapHeight = Math.min(targetHeight, cellHeight);
bitmapWidth = (int) (targetWidth * ((float) bitmapHeight / targetHeight));
iconScale = Math.min((float) bitmapWidth / (mAppIconSize + 2 * offset), 1f);
}
} }
preview = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888); preview = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
renderDrawableToBitmap(mDefaultWidgetBackground, preview, 0, 0, expectedWidth, renderDrawableToBitmap(mDefaultWidgetBackground, preview, 0, 0, bitmapWidth,
expectedHeight, 1f, 1f); bitmapWidth);
// Draw the icon in the top left corner // Draw the icon in the top left corner
try { try {
@@ -991,9 +1001,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
if (info.icon > 0) icon = mPackageManager.getDrawable(packageName, info.icon, null); if (info.icon > 0) icon = mPackageManager.getDrawable(packageName, info.icon, null);
if (icon == null) icon = resources.getDrawable(R.drawable.ic_launcher_application); if (icon == null) icon = resources.getDrawable(R.drawable.ic_launcher_application);
int offset = (int) (mAppIconSize * sWidgetPreviewIconPaddingPercentage); renderDrawableToBitmap(icon, preview, (int) (offset * iconScale),
renderDrawableToBitmap(icon, preview, offset, offset, (int) (offset * iconScale), (int) (mAppIconSize * iconScale),
mAppIconSize, mAppIconSize, 1f, 1f); (int) (mAppIconSize * iconScale));
} catch (Resources.NotFoundException e) {} } catch (Resources.NotFoundException e) {}
} }
return preview; return preview;
@@ -1007,7 +1017,8 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
PagedViewGridLayout layout = new PagedViewGridLayout(context, mWidgetCountX, PagedViewGridLayout layout = new PagedViewGridLayout(context, mWidgetCountX,
mWidgetCountY); mWidgetCountY);
setupPage(layout); setupPage(layout);
addView(layout); addView(layout, new PagedViewGridLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
} }
} }
public void syncWidgetPageItems(int page, boolean immediate) { public void syncWidgetPageItems(int page, boolean immediate) {
@@ -1126,7 +1137,12 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
PagedViewWidget widget = (PagedViewWidget) layout.getChildAt(i); PagedViewWidget widget = (PagedViewWidget) layout.getChildAt(i);
if (widget != null) { if (widget != null) {
widget.applyPreview(new FastBitmapDrawable(data.generatedImages.get(i)), i); Bitmap preview = data.generatedImages.get(i);
boolean scale =
(preview.getWidth() >= data.cellWidth ||
preview.getHeight() >= data.cellHeight);
widget.applyPreview(new FastBitmapDrawable(preview), i, scale);
} }
} }
layout.createHardwareLayer(); layout.createHardwareLayer();
@@ -367,7 +367,7 @@ public class PagedViewCellLayout extends ViewGroup implements Page {
} }
/** /**
* Estimates the width that the number of vSpan cells will take up. * Estimates the width that the number of hSpan cells will take up.
*/ */
public int estimateCellWidth(int hSpan) { public int estimateCellWidth(int hSpan) {
// TODO: we need to take widthGap into effect // TODO: we need to take widthGap into effect
+2 -11
View File
@@ -22,23 +22,13 @@ import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF; import android.graphics.RectF;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View;
import android.widget.Checkable; import android.widget.Checkable;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@@ -145,10 +135,11 @@ public class PagedViewWidget extends LinearLayout implements Checkable {
} }
} }
void applyPreview(FastBitmapDrawable preview, int index) { void applyPreview(FastBitmapDrawable preview, int index, boolean scale) {
final ImageView image = (ImageView) findViewById(R.id.widget_preview); final ImageView image = (ImageView) findViewById(R.id.widget_preview);
if (preview != null) { if (preview != null) {
image.setImageDrawable(preview); image.setImageDrawable(preview);
image.setScaleType(scale ? ImageView.ScaleType.FIT_START : ImageView.ScaleType.MATRIX);
image.setAlpha(0f); image.setAlpha(0f);
image.animate() image.animate()
.alpha(1f) .alpha(1f)