summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/Utilities.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-03-19 14:31:19 -0700
committerSunny Goyal <sunnygoyal@google.com>2015-03-20 17:31:11 -0700
commit5b0e669169ea2c951bf2f6f71faf793b24db3c23 (patch)
tree32ab7b4381d40ee1e6b7a66691feb4439e6253cd /src/com/android/launcher3/Utilities.java
parent71c3baf5ebc520d5146946e0d7907a5dc12366db (diff)
downloadandroid_packages_apps_Trebuchet-5b0e669169ea2c951bf2f6f71faf793b24db3c23.tar.gz
android_packages_apps_Trebuchet-5b0e669169ea2c951bf2f6f71faf793b24db3c23.tar.bz2
android_packages_apps_Trebuchet-5b0e669169ea2c951bf2f6f71faf793b24db3c23.zip
Rewrite: Widget preview loader logic
> Widget previews are saved in data dir instead of cache dir > Expiring widget previews similar to IconCache > Removed support for setting thread priorities Bug: 19865031 Change-Id: Ib6033c2b1ff8ae61bba8762ca994ccd8217d3c75
Diffstat (limited to 'src/com/android/launcher3/Utilities.java')
-rw-r--r--src/com/android/launcher3/Utilities.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 497b43874..22677c8ea 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -50,6 +50,8 @@ import android.util.SparseArray;
import android.view.View;
import android.widget.Toast;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
@@ -555,6 +557,25 @@ public final class Utilities {
return defaultWidgetForSearchPackage;
}
+ /**
+ * Compresses the bitmap to a byte array for serialization.
+ */
+ public static byte[] flattenBitmap(Bitmap bitmap) {
+ // Try go guesstimate how much space the icon will take when serialized
+ // to avoid unnecessary allocations/copies during the write.
+ int size = bitmap.getWidth() * bitmap.getHeight() * 4;
+ ByteArrayOutputStream out = new ByteArrayOutputStream(size);
+ try {
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
+ out.flush();
+ out.close();
+ return out.toByteArray();
+ } catch (IOException e) {
+ Log.w(TAG, "Could not write bitmap");
+ return null;
+ }
+ }
+
public static final Comparator<ItemInfo> RANK_COMPARATOR = new Comparator<ItemInfo>() {
@Override