From 360bc25ab6ae22869b867350b87ee7e82f06389a Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 1 Jul 2015 11:17:15 -0700 Subject: Using RGB_565 for low-res icons > Using a non-transparent image with flat background for low-res icons > Changing the scale factor from 8 to 5 > The overall size change is 1/50 instead of 1/64 Bug: 22204941 Change-Id: I6cda4b4b3450c23a7bb8218ebd2de2b09af9c414 --- res/drawable/widgets_row_divider.xml | 2 +- res/layout/widgets_list_row_view.xml | 2 +- res/values/colors.xml | 3 +- src/com/android/launcher3/IconCache.java | 94 +++++++++++++++++++++++--------- 4 files changed, 70 insertions(+), 31 deletions(-) diff --git a/res/drawable/widgets_row_divider.xml b/res/drawable/widgets_row_divider.xml index 074d60167..bb5b6b55b 100644 --- a/res/drawable/widgets_row_divider.xml +++ b/res/drawable/widgets_row_divider.xml @@ -15,5 +15,5 @@ --> - + diff --git a/res/layout/widgets_list_row_view.xml b/res/layout/widgets_list_row_view.xml index 67b4acb4b..ced564801 100644 --- a/res/layout/widgets_list_row_view.xml +++ b/res/layout/widgets_list_row_view.xml @@ -30,7 +30,7 @@ android:id="@+id/section" android:layout_width="match_parent" android:layout_height="@dimen/widget_section_height" - android:background="@color/widget_text_panel" + android:background="@color/quantum_panel_bg_color_dark" android:drawablePadding="@dimen/widget_section_horizontal_padding" android:ellipsize="end" android:focusable="true" diff --git a/res/values/colors.xml b/res/values/colors.xml index 5afc5b98d..51e4d40a5 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -34,10 +34,9 @@ #FF666666 #FFF5F5F5 - #FF243036 + #FF374248 #FFFFFFFF - #FF374248 #42000000 diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java index 14ad33799..b9ac2a47a 100644 --- a/src/com/android/launcher3/IconCache.java +++ b/src/com/android/launcher3/IconCache.java @@ -32,6 +32,9 @@ import android.database.sqlite.SQLiteOpenHelper; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.os.Handler; import android.os.SystemClock; @@ -68,7 +71,7 @@ public class IconCache { private static final boolean DEBUG = false; - private static final int LOW_RES_SCALE_FACTOR = 8; + private static final int LOW_RES_SCALE_FACTOR = 5; @Thunk static final Object ICON_UPDATE_TOKEN = new Object(); @@ -93,6 +96,20 @@ public class IconCache { @Thunk final Handler mWorkerHandler; + // The background color used for activity icons. Since these icons are displayed in all-apps + // and folders, this would be same as the light quantum panel background. This color + // is used to convert icons to RGB_565. + private final int mActivityBgColor; + // The background color used for package icons. These are displayed in widget tray, which + // has a dark quantum panel background. + private final int mPackageBgColor; + private final BitmapFactory.Options mLowResOptions; + + private String mSystemState; + private Bitmap mLowResBitmap; + private Canvas mLowResCanvas; + private Paint mLowResPaint; + public IconCache(Context context, InvariantDeviceProfile inv) { mContext = context; mPackageManager = context.getPackageManager(); @@ -102,6 +119,14 @@ public class IconCache { mIconDb = new IconDB(context); mWorkerHandler = new Handler(LauncherModel.getWorkerLooper()); + + mActivityBgColor = context.getResources().getColor(R.color.quantum_panel_bg_color); + mPackageBgColor = context.getResources().getColor(R.color.quantum_panel_bg_color_dark); + mLowResOptions = new BitmapFactory.Options(); + // Always prefer RGB_565 config for low res. If the bitmap has transparency, it will + // automatically be loaded as ALPHA_8888. + mLowResOptions.inPreferredConfig = Bitmap.Config.RGB_565; + updateSystemStateString(); } private Drawable getFullResDefaultActivityIcon() { @@ -221,7 +246,7 @@ public class IconCache { // Remove all active icon update tasks. mWorkerHandler.removeCallbacksAndMessages(ICON_UPDATE_TOKEN); - mIconDb.updateSystemStateString(); + updateSystemStateString(); for (UserHandleCompat user : mUserManager.getUserProfiles()) { // Query for the set of apps final List apps = mLauncherApps.getActivityList(null, user); @@ -294,7 +319,7 @@ public class IconCache { int version = c.getInt(indexVersion); LauncherActivityInfoCompat app = componentMap.remove(component); if (version == info.versionCode && updateTime == info.lastUpdateTime && - TextUtils.equals(mIconDb.mSystemState, c.getString(systemStateIndex))) { + TextUtils.equals(mSystemState, c.getString(systemStateIndex))) { continue; } if (app == null) { @@ -361,7 +386,7 @@ public class IconCache { entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, app.getUser()); mCache.put(new ComponentKey(app.getComponentName(), app.getUser()), entry); - return mIconDb.newContentValues(entry.icon, entry.title.toString()); + return newContentValues(entry.icon, entry.title.toString(), mActivityBgColor); } /** @@ -596,7 +621,7 @@ public class IconCache { // Add the icon in the DB here, since these do not get written during // package updates. ContentValues values = - mIconDb.newContentValues(entry.icon, entry.title.toString()); + newContentValues(entry.icon, entry.title.toString(), mPackageBgColor); addIconToDB(values, cn, info, mUserManager.getSerialNumberForUser(user)); } catch (NameNotFoundException e) { @@ -635,7 +660,7 @@ public class IconCache { // pass } - ContentValues values = mIconDb.newContentValues(icon, label); + ContentValues values = newContentValues(icon, label, Color.TRANSPARENT); values.put(IconDB.COLUMN_COMPONENT, componentName.flattenToString()); values.put(IconDB.COLUMN_USER, userSerial); mIconDb.getWritableDatabase().insertWithOnConflict(IconDB.TABLE_NAME, null, values, @@ -653,7 +678,7 @@ public class IconCache { null, null, null); try { if (c.moveToNext()) { - entry.icon = loadIconNoResize(c, 0); + entry.icon = loadIconNoResize(c, 0, lowRes ? mLowResOptions : null); entry.isLowResIcon = lowRes; entry.title = c.getString(1); if (entry.title == null) { @@ -744,8 +769,12 @@ public class IconCache { } } + private void updateSystemStateString() { + mSystemState = Locale.getDefault().toString(); + } + private static final class IconDB extends SQLiteOpenHelper { - private final static int DB_VERSION = 5; + private final static int DB_VERSION = 6; private final static String TABLE_NAME = "icons"; private final static String COLUMN_ROWID = "rowid"; @@ -758,15 +787,8 @@ public class IconCache { private final static String COLUMN_LABEL = "label"; private final static String COLUMN_SYSTEM_STATE = "system_state"; - public String mSystemState; - public IconDB(Context context) { super(context, LauncherFiles.APP_ICONS_DB, null, DB_VERSION); - updateSystemStateString(); - } - - public void updateSystemStateString() { - mSystemState = Locale.getDefault().toString(); } @Override @@ -802,24 +824,42 @@ public class IconCache { db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); onCreate(db); } + } + + private ContentValues newContentValues(Bitmap icon, String label, int lowResBackgroundColor) { + ContentValues values = new ContentValues(); + values.put(IconDB.COLUMN_ICON, Utilities.flattenBitmap(icon)); + + values.put(IconDB.COLUMN_LABEL, label); + values.put(IconDB.COLUMN_SYSTEM_STATE, mSystemState); - public ContentValues newContentValues(Bitmap icon, String label) { - ContentValues values = new ContentValues(); - values.put(COLUMN_ICON, Utilities.flattenBitmap(icon)); - values.put(COLUMN_ICON_LOW_RES, Utilities.flattenBitmap( - Bitmap.createScaledBitmap(icon, - icon.getWidth() / LOW_RES_SCALE_FACTOR, - icon.getHeight() / LOW_RES_SCALE_FACTOR, true))); - values.put(COLUMN_LABEL, label); - values.put(COLUMN_SYSTEM_STATE, mSystemState); - return values; + if (lowResBackgroundColor == Color.TRANSPARENT) { + values.put(IconDB.COLUMN_ICON_LOW_RES, Utilities.flattenBitmap( + Bitmap.createScaledBitmap(icon, + icon.getWidth() / LOW_RES_SCALE_FACTOR, + icon.getHeight() / LOW_RES_SCALE_FACTOR, true))); + } else { + synchronized (this) { + if (mLowResBitmap == null) { + mLowResBitmap = Bitmap.createBitmap(icon.getWidth() / LOW_RES_SCALE_FACTOR, + icon.getHeight() / LOW_RES_SCALE_FACTOR, Bitmap.Config.RGB_565); + mLowResCanvas = new Canvas(mLowResBitmap); + mLowResPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); + } + mLowResCanvas.drawColor(lowResBackgroundColor); + mLowResCanvas.drawBitmap(icon, new Rect(0, 0, icon.getWidth(), icon.getHeight()), + new Rect(0, 0, mLowResBitmap.getWidth(), mLowResBitmap.getHeight()), + mLowResPaint); + values.put(IconDB.COLUMN_ICON_LOW_RES, Utilities.flattenBitmap(mLowResBitmap)); + } } + return values; } - private static Bitmap loadIconNoResize(Cursor c, int iconIndex) { + private static Bitmap loadIconNoResize(Cursor c, int iconIndex, BitmapFactory.Options options) { byte[] data = c.getBlob(iconIndex); try { - return BitmapFactory.decodeByteArray(data, 0, data.length); + return BitmapFactory.decodeByteArray(data, 0, data.length, options); } catch (Exception e) { return null; } -- cgit v1.2.3