diff options
author | Winson Chung <winsonc@google.com> | 2010-11-08 17:17:47 -0800 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2010-11-08 17:18:57 -0800 |
commit | 94ba5b1b92a2e8bb32dd578f0f4ec1293c5bd16c (patch) | |
tree | 3f2d4d7a42749a7a0a1c1091ac596d16ff4b0f36 /src | |
parent | ec30827e734ba9c3d2b8a27f3b5224412d1cf2f7 (diff) | |
download | android_packages_apps_Trebuchet-94ba5b1b92a2e8bb32dd578f0f4ec1293c5bd16c.tar.gz android_packages_apps_Trebuchet-94ba5b1b92a2e8bb32dd578f0f4ec1293c5bd16c.tar.bz2 android_packages_apps_Trebuchet-94ba5b1b92a2e8bb32dd578f0f4ec1293c5bd16c.zip |
Fixing issue with widget previews using the widget dimensions instead of the preview dimensions
Change-Id: Ie786c45f6e050e0eb02145b0bc9b1f5b1cc37ca2
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher2/CustomizePagedView.java | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java index 4cce81e97..c432f37c1 100644 --- a/src/com/android/launcher2/CustomizePagedView.java +++ b/src/com/android/launcher2/CustomizePagedView.java @@ -462,7 +462,7 @@ public class CustomizePagedView extends PagedView * otherwise, it will try to generate a default image preview with the widget's package icon. * @return the drawable will be used and sized in the ImageView to represent the widget */ - private Drawable getWidgetIcon(AppWidgetProviderInfo info) { + private Drawable getWidgetPreview(AppWidgetProviderInfo info) { PackageManager packageManager = mLauncher.getPackageManager(); String packageName = info.provider.getPackageName(); Drawable drawable = null; @@ -510,19 +510,21 @@ public class CustomizePagedView extends PagedView drawable = new FastBitmapDrawable(bitmap); } else { // Scale down the preview if necessary - final float aspect = (float) info.minWidth / info.minHeight; - final int boundedWidth = (int) Math.max(minDim, Math.min(maxDim, info.minWidth)); - final int boundedHeight = (int) Math.max(minDim, Math.min(maxDim, info.minHeight)); - final int scaledWidth = (int) (boundedWidth * sScaleFactor); - final int scaledHeight = (int) (boundedHeight * sScaleFactor); + final float imageWidth = drawable.getIntrinsicWidth(); + final float imageHeight = drawable.getIntrinsicHeight(); + final float aspect = (float) imageWidth / imageHeight; + final int scaledWidth = + (int) (Math.max(minDim, Math.min(maxDim, imageWidth)) * sScaleFactor); + final int scaledHeight = + (int) (Math.max(minDim, Math.min(maxDim, imageHeight)) * sScaleFactor); int width; int height; - if (scaledWidth > scaledHeight) { + if (aspect >= 1.0f) { width = scaledWidth; - height = (int) (width / aspect); + height = (int) (((float) scaledWidth / imageWidth) * imageHeight); } else { height = scaledHeight; - width = (int) (height * aspect); + width = (int) (((float) scaledHeight / imageHeight) * imageWidth); } final Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); @@ -590,7 +592,7 @@ public class CustomizePagedView extends PagedView l.setOnClickListener(this); l.setOnLongClickListener(this); - final Drawable icon = getWidgetIcon(info); + final Drawable icon = getWidgetPreview(info); int[] spans = CellLayout.rectToCell(getResources(), info.minWidth, info.minHeight, null); final int hSpan = spans[0]; |