diff options
| author | Owen Lin <owenlin@google.com> | 2011-09-13 20:48:13 +0800 |
|---|---|---|
| committer | Wei Huang <weih@google.com> | 2011-09-19 16:22:44 -0700 |
| commit | 5da31f8fd85d7c1e33133473bd1fbc5e3a240f2d (patch) | |
| tree | 3690848c45031b1417fa5325ec94c0f879dbd850 | |
| parent | d2ee3f2ac4bf9faed16b8007efe8daf6ef4edcac (diff) | |
| download | android_packages_apps_Gallery2-5da31f8fd85d7c1e33133473bd1fbc5e3a240f2d.tar.gz android_packages_apps_Gallery2-5da31f8fd85d7c1e33133473bd1fbc5e3a240f2d.tar.bz2 android_packages_apps_Gallery2-5da31f8fd85d7c1e33133473bd1fbc5e3a240f2d.zip | |
Add a hard limit on the size of the widget images.
There is a limit on the size of the data transfered by binder.
For now, we just add a hard limit (360 pixel) to ensure the widget's image
can be passed by binder.
Also adjust the size of widget to make it looks better.
Fix a bug in DecodeUtils which cause OOM for a image in size 12200x1920.
In that case, we should generate a screen nail of size 640x101 instead of
4066x640.
Change-Id: Ia8227d8e5368471fe7af94bf164d67017aa321fa
fix: 5273271
| -rw-r--r-- | gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java | 2 | ||||
| -rw-r--r-- | res/values-xlarge/dimensions.xml | 6 | ||||
| -rw-r--r-- | res/values/dimensions.xml | 8 | ||||
| -rw-r--r-- | res/xml/widget_info.xml | 4 | ||||
| -rw-r--r-- | src/com/android/gallery3d/data/DecodeUtils.java | 2 | ||||
| -rw-r--r-- | src/com/android/gallery3d/gadget/WidgetConfigure.java | 17 |
6 files changed, 24 insertions, 15 deletions
diff --git a/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java b/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java index aaf4f6665..060d7f32e 100644 --- a/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java +++ b/gallerycommon/src/com/android/gallery3d/common/BitmapUtils.java @@ -85,7 +85,7 @@ public class BitmapUtils { // minSideLength long. If that's not possible, return 1. public static int computeSampleSizeLarger(int w, int h, int minSideLength) { - int initialSize = Math.min(w / minSideLength, h / minSideLength); + int initialSize = Math.max(w / minSideLength, h / minSideLength); if (initialSize <= 1) return 1; return initialSize <= 8 diff --git a/res/values-xlarge/dimensions.xml b/res/values-xlarge/dimensions.xml index a0160549f..4fa398f32 100644 --- a/res/values-xlarge/dimensions.xml +++ b/res/values-xlarge/dimensions.xml @@ -15,9 +15,9 @@ --> <resources> <dimen name="appwidget_width">240dp</dimen> - <dimen name="appwidget_height">200dp</dimen> - <dimen name="stack_photo_width">230dp</dimen> - <dimen name="stack_photo_height">190dp</dimen> + <dimen name="appwidget_height">240dp</dimen> + <dimen name="stack_photo_width">220dp</dimen> + <dimen name="stack_photo_height">165dp</dimen> <!-- configuration for album set page --> <integer name="albumset_rows_land">3</integer> diff --git a/res/values/dimensions.xml b/res/values/dimensions.xml index 7cbd87506..428de3a14 100644 --- a/res/values/dimensions.xml +++ b/res/values/dimensions.xml @@ -14,10 +14,10 @@ limitations under the License. --> <resources> - <dimen name="appwidget_width">146dp</dimen> - <dimen name="appwidget_height">146dp</dimen> - <dimen name="stack_photo_width">140dp</dimen> - <dimen name="stack_photo_height">110dp</dimen> + <dimen name="appwidget_width">180dp</dimen> + <dimen name="appwidget_height">180dp</dimen> + <dimen name="stack_photo_width">160dp</dimen> + <dimen name="stack_photo_height">120dp</dimen> <!-- configuration for album set page --> <integer name="albumset_rows_land">2</integer> diff --git a/res/xml/widget_info.xml b/res/xml/widget_info.xml index e03124c2d..4aa460f8d 100644 --- a/res/xml/widget_info.xml +++ b/res/xml/widget_info.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" - android:minWidth="180dp" - android:minHeight="180dp" + android:minWidth="@dimen/appwidget_width" + android:minHeight="@dimen/appwidget_height" android:updatePeriodMillis="86400000" android:previewImage="@drawable/preview" android:initialLayout="@layout/appwidget_main" diff --git a/src/com/android/gallery3d/data/DecodeUtils.java b/src/com/android/gallery3d/data/DecodeUtils.java index d2b4ebc4e..afd5faa66 100644 --- a/src/com/android/gallery3d/data/DecodeUtils.java +++ b/src/com/android/gallery3d/data/DecodeUtils.java @@ -110,7 +110,7 @@ public class DecodeUtils { * Decodes the bitmap from the given byte array if the image size is larger than the given * requirement. * - * Note: The returned image may be resized down. However, both width and heigh must be + * Note: The returned image may be resized down. However, both width and height must be * larger than the <code>targetSize</code>. */ public static Bitmap requestDecodeIfBigEnough(JobContext jc, byte[] data, diff --git a/src/com/android/gallery3d/gadget/WidgetConfigure.java b/src/com/android/gallery3d/gadget/WidgetConfigure.java index 747cc3a6d..a871e24fe 100644 --- a/src/com/android/gallery3d/gadget/WidgetConfigure.java +++ b/src/com/android/gallery3d/gadget/WidgetConfigure.java @@ -48,6 +48,7 @@ public class WidgetConfigure extends Activity { // Note: There is also a limit on the size of data that can be // passed in Binder's transaction. private static float WIDGET_SCALE_FACTOR = 1.5f; + private static int MAX_WIDGET_SIDE = 360; private int mAppWidgetId = -1; private int mWidgetType = 0; @@ -115,10 +116,18 @@ public class WidgetConfigure extends Activity { private void setChoosenPhoto(Intent data) { Resources res = getResources(); - int widgetWidth = Math.round(WIDGET_SCALE_FACTOR - * res.getDimension(R.dimen.appwidget_width)); - int widgetHeight = Math.round(WIDGET_SCALE_FACTOR - * res.getDimension(R.dimen.appwidget_height)); + + float width = res.getDimension(R.dimen.appwidget_width); + float height = res.getDimension(R.dimen.appwidget_height); + + // We try to crop a larger image (by scale factor), but there is still + // a bound on the binder limit. + float scale = Math.min(WIDGET_SCALE_FACTOR, + MAX_WIDGET_SIDE / Math.max(width, height)); + + int widgetWidth = Math.round(width * scale); + int widgetHeight = Math.round(height * scale); + mPickedItem = data.getData(); Intent request = new Intent(CropImage.ACTION_CROP, mPickedItem) .putExtra(CropImage.KEY_OUTPUT_X, widgetWidth) |
