From b5e74c8b60b97c5a03dd3e5bbc982474746b9c74 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Fri, 28 Oct 2011 16:39:20 -0700 Subject: Fixing issue where widget previews were being scaled up. Change-Id: I94eaa1beb0579c8045a3b4c6ff72f7b9622a62ff --- res/layout-sw720dp/apps_customize_widget.xml | 79 ---------------------- res/layout/apps_customize_widget.xml | 3 +- res/values-sw720dp/dimens.xml | 20 ++++++ res/values/dimens.xml | 2 + .../android/launcher2/AppsCustomizePagedView.java | 26 ++++--- 5 files changed, 39 insertions(+), 91 deletions(-) delete mode 100644 res/layout-sw720dp/apps_customize_widget.xml create mode 100644 res/values-sw720dp/dimens.xml diff --git a/res/layout-sw720dp/apps_customize_widget.xml b/res/layout-sw720dp/apps_customize_widget.xml deleted file mode 100644 index e707ef774..000000000 --- a/res/layout-sw720dp/apps_customize_widget.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/res/layout/apps_customize_widget.xml b/res/layout/apps_customize_widget.xml index 2c11c1db9..704401a83 100644 --- a/res/layout/apps_customize_widget.xml +++ b/res/layout/apps_customize_widget.xml @@ -68,6 +68,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" - android:padding="8dp" + android:paddingTop="@dimen/app_widget_preview_padding_top" + android:paddingLeft="@dimen/app_widget_preview_padding_left" android:scaleType="matrix" /> diff --git a/res/values-sw720dp/dimens.xml b/res/values-sw720dp/dimens.xml new file mode 100644 index 000000000..0373295d4 --- /dev/null +++ b/res/values-sw720dp/dimens.xml @@ -0,0 +1,20 @@ + + + + + 0dp + 10dp + \ No newline at end of file diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 124cf16b2..9ba77a98a 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -108,6 +108,8 @@ 16dp 16dp 16dp + 8dp + 8dp diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index 5a54c7897..4d8a9cf71 100644 --- a/src/com/android/launcher2/AppsCustomizePagedView.java +++ b/src/com/android/launcher2/AppsCustomizePagedView.java @@ -949,18 +949,22 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen Log.w(LOG_TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon) + " for provider: " + info.provider); } else { - // Scale down the preview to something that is closer to the cellWidth/Height - int imageWidth = drawable.getIntrinsicWidth(); - int imageHeight = drawable.getIntrinsicHeight(); - int bitmapWidth = imageWidth; - int bitmapHeight = imageHeight; - if (imageWidth > imageHeight) { - bitmapWidth = cellWidth; - bitmapHeight = (int) (imageHeight * ((float) bitmapWidth / imageWidth)); + // Map the target width/height to the cell dimensions + int targetWidth = mWidgetSpacingLayout.estimateCellWidth(cellHSpan); + int targetHeight = mWidgetSpacingLayout.estimateCellHeight(cellVSpan); + int targetCellWidth; + int targetCellHeight; + if (targetWidth >= targetHeight) { + targetCellWidth = Math.min(targetWidth, cellWidth); + targetCellHeight = (int) (cellHeight * ((float) targetCellWidth / cellWidth)); } else { - bitmapHeight = cellHeight; - bitmapWidth = (int) (imageWidth * ((float) bitmapHeight / imageHeight)); + targetCellHeight = Math.min(targetHeight, cellHeight); + targetCellWidth = (int) (cellWidth * ((float) targetCellHeight / cellHeight)); } + // Map the preview to the target cell dimensions + int bitmapWidth = Math.min(targetCellWidth, drawable.getIntrinsicWidth()); + int bitmapHeight = (int) (drawable.getIntrinsicHeight() * + ((float) bitmapWidth / drawable.getIntrinsicWidth())); preview = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888); renderDrawableToBitmap(drawable, preview, 0, 0, bitmapWidth, bitmapHeight); @@ -989,7 +993,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } } else { // Otherwise, ensure that we are properly sized within the cellWidth/Height - if (targetWidth > targetHeight) { + if (targetWidth >= targetHeight) { bitmapWidth = Math.min(targetWidth, cellWidth); bitmapHeight = (int) (targetHeight * ((float) bitmapWidth / targetWidth)); iconScale = Math.min((float) bitmapHeight / (mAppIconSize + 2 * minOffset), 1f); -- cgit v1.2.3