Loading iconloaderlib/src/com/android/launcher3/icons/GraphicsUtils.java +27 −0 Original line number Diff line number Diff line Loading @@ -15,10 +15,18 @@ */ package com.android.launcher3.icons; import android.graphics.Bitmap; import android.util.Log; import java.io.ByteArrayOutputStream; import java.io.IOException; import androidx.annotation.ColorInt; public class GraphicsUtils { private static final String TAG = "GraphicsUtils"; /** * Set the alpha component of {@code color} to be {@code alpha}. Unlike the support lib version, * it bounds the alpha in valid range instead of throwing an exception to allow for safer Loading @@ -33,4 +41,23 @@ public class GraphicsUtils { } return (color & 0x00ffffff) | (alpha << 24); } /** * 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 (4 bytes per pixel). 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; } } } src/com/android/launcher3/AutoInstallsLayout.java +2 −2 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.util.Patterns; import com.android.launcher3.LauncherProvider.SqlArguments; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.icons.GraphicsUtils; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.Thunk; Loading @@ -47,7 +48,6 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.ArrayList; import java.util.Locale; /** Loading Loading @@ -436,7 +436,7 @@ public class AutoInstallsLayout { // Auto installs should always support the current platform version. LauncherIcons li = LauncherIcons.obtain(mContext); mValues.put(LauncherSettings.Favorites.ICON, Utilities.flattenBitmap( mValues.put(LauncherSettings.Favorites.ICON, GraphicsUtils.flattenBitmap( li.createBadgedIconBitmap(icon, Process.myUserHandle(), VERSION.SDK_INT).icon)); li.recycle(); Loading src/com/android/launcher3/InstallShortcutReceiver.java +2 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.util.Pair; import com.android.launcher3.compat.LauncherAppsCompat; import com.android.launcher3.compat.UserManagerCompat; import com.android.launcher3.icons.BitmapInfo; import com.android.launcher3.icons.GraphicsUtils; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.shortcuts.ShortcutInfoCompat; Loading Loading @@ -457,7 +458,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver { .key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0)) .key(NAME_KEY).value(name); if (icon != null) { byte[] iconByteArray = Utilities.flattenBitmap(icon); byte[] iconByteArray = GraphicsUtils.flattenBitmap(icon); json = json.key(ICON_KEY).value( Base64.encodeToString( iconByteArray, 0, iconByteArray.length, Base64.DEFAULT)); Loading src/com/android/launcher3/Utilities.java +0 −19 Original line number Diff line number Diff line Loading @@ -356,25 +356,6 @@ public final class Utilities { return null; } /** * 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; } } /** * Trims the string, removing all whitespace at the beginning and end of the string. * Non-breaking whitespaces are also removed. Loading src/com/android/launcher3/WidgetPreviewLoader.java +2 −1 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.util.LongSparseArray; import com.android.launcher3.compat.AppWidgetManagerCompat; import com.android.launcher3.compat.ShortcutConfigActivityInfo; import com.android.launcher3.compat.UserManagerCompat; import com.android.launcher3.icons.GraphicsUtils; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.icons.ShadowGenerator; import com.android.launcher3.icons.IconCache; Loading Loading @@ -149,7 +150,7 @@ public class WidgetPreviewLoader { values.put(CacheDb.COLUMN_PACKAGE, key.componentName.getPackageName()); values.put(CacheDb.COLUMN_VERSION, versions[0]); values.put(CacheDb.COLUMN_LAST_UPDATED, versions[1]); values.put(CacheDb.COLUMN_PREVIEW_BITMAP, Utilities.flattenBitmap(preview)); values.put(CacheDb.COLUMN_PREVIEW_BITMAP, GraphicsUtils.flattenBitmap(preview)); mDb.insertOrReplace(values); } Loading Loading
iconloaderlib/src/com/android/launcher3/icons/GraphicsUtils.java +27 −0 Original line number Diff line number Diff line Loading @@ -15,10 +15,18 @@ */ package com.android.launcher3.icons; import android.graphics.Bitmap; import android.util.Log; import java.io.ByteArrayOutputStream; import java.io.IOException; import androidx.annotation.ColorInt; public class GraphicsUtils { private static final String TAG = "GraphicsUtils"; /** * Set the alpha component of {@code color} to be {@code alpha}. Unlike the support lib version, * it bounds the alpha in valid range instead of throwing an exception to allow for safer Loading @@ -33,4 +41,23 @@ public class GraphicsUtils { } return (color & 0x00ffffff) | (alpha << 24); } /** * 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 (4 bytes per pixel). 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; } } }
src/com/android/launcher3/AutoInstallsLayout.java +2 −2 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ import android.util.Patterns; import com.android.launcher3.LauncherProvider.SqlArguments; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.icons.GraphicsUtils; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.Thunk; Loading @@ -47,7 +48,6 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.ArrayList; import java.util.Locale; /** Loading Loading @@ -436,7 +436,7 @@ public class AutoInstallsLayout { // Auto installs should always support the current platform version. LauncherIcons li = LauncherIcons.obtain(mContext); mValues.put(LauncherSettings.Favorites.ICON, Utilities.flattenBitmap( mValues.put(LauncherSettings.Favorites.ICON, GraphicsUtils.flattenBitmap( li.createBadgedIconBitmap(icon, Process.myUserHandle(), VERSION.SDK_INT).icon)); li.recycle(); Loading
src/com/android/launcher3/InstallShortcutReceiver.java +2 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import android.util.Pair; import com.android.launcher3.compat.LauncherAppsCompat; import com.android.launcher3.compat.UserManagerCompat; import com.android.launcher3.icons.BitmapInfo; import com.android.launcher3.icons.GraphicsUtils; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.shortcuts.ShortcutInfoCompat; Loading Loading @@ -457,7 +458,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver { .key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0)) .key(NAME_KEY).value(name); if (icon != null) { byte[] iconByteArray = Utilities.flattenBitmap(icon); byte[] iconByteArray = GraphicsUtils.flattenBitmap(icon); json = json.key(ICON_KEY).value( Base64.encodeToString( iconByteArray, 0, iconByteArray.length, Base64.DEFAULT)); Loading
src/com/android/launcher3/Utilities.java +0 −19 Original line number Diff line number Diff line Loading @@ -356,25 +356,6 @@ public final class Utilities { return null; } /** * 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; } } /** * Trims the string, removing all whitespace at the beginning and end of the string. * Non-breaking whitespaces are also removed. Loading
src/com/android/launcher3/WidgetPreviewLoader.java +2 −1 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ import android.util.LongSparseArray; import com.android.launcher3.compat.AppWidgetManagerCompat; import com.android.launcher3.compat.ShortcutConfigActivityInfo; import com.android.launcher3.compat.UserManagerCompat; import com.android.launcher3.icons.GraphicsUtils; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.icons.ShadowGenerator; import com.android.launcher3.icons.IconCache; Loading Loading @@ -149,7 +150,7 @@ public class WidgetPreviewLoader { values.put(CacheDb.COLUMN_PACKAGE, key.componentName.getPackageName()); values.put(CacheDb.COLUMN_VERSION, versions[0]); values.put(CacheDb.COLUMN_LAST_UPDATED, versions[1]); values.put(CacheDb.COLUMN_PREVIEW_BITMAP, Utilities.flattenBitmap(preview)); values.put(CacheDb.COLUMN_PREVIEW_BITMAP, GraphicsUtils.flattenBitmap(preview)); mDb.insertOrReplace(values); } Loading