Removing icon_type column

Icon type is not used consistently. It is used initially
during the loader. Afterwards, we save both the icon and resource to the db.
Instead of changing the logic to always read the shortcut-resource first, and fallback to the bitmap if the resource is not available,
always write the bitmap to DB whenever the shortcut is edited.

Change-Id: I0ea5e88f8904bd3250ca669220b3e5d6aeef1bfd
This commit is contained in:
Sunny Goyal
2016-04-21 14:30:18 -07:00
parent 4dcd8ffecc
commit eb4b79935e
9 changed files with 41 additions and 104 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ message Favorite {
optional string appWidgetProvider = 12;
optional string intent = 13;
optional string uri = 14;
optional int32 iconType = 15;
optional int32 iconType = 15 [deprecated = true];
optional string iconPackage = 16;
optional string iconResource = 17;
optional bytes icon = 18;
@@ -436,7 +436,6 @@ public class AutoInstallsLayout {
}
ItemInfo.writeBitmap(mValues, Utilities.createIconBitmap(icon, mContext));
mValues.put(Favorites.ICON_TYPE, Favorites.ICON_TYPE_RESOURCE);
mValues.put(Favorites.ICON_PACKAGE, mIconRes.getResourcePackageName(iconId));
mValues.put(Favorites.ICON_RESOURCE, mIconRes.getResourceName(iconId));
@@ -68,7 +68,6 @@ public class CommonAppTypeParser implements LayoutParserCallback {
parsedValues = values;
// Remove unwanted values
values.put(Favorites.ICON_TYPE, (Integer) null);
values.put(Favorites.ICON_PACKAGE, (String) null);
values.put(Favorites.ICON_RESOURCE, (String) null);
values.put(Favorites.ICON, (byte[]) null);
@@ -103,14 +103,13 @@ public class LauncherBackupHelper implements BackupHelper {
Favorites.ICON, // 8
Favorites.ICON_PACKAGE, // 9
Favorites.ICON_RESOURCE, // 10
Favorites.ICON_TYPE, // 11
Favorites.ITEM_TYPE, // 12
Favorites.SCREEN, // 13
Favorites.SPANX, // 14
Favorites.SPANY, // 15
Favorites.TITLE, // 16
Favorites.PROFILE_ID, // 17
Favorites.RANK, // 18
Favorites.ITEM_TYPE, // 11
Favorites.SCREEN, // 12
Favorites.SPANX, // 13
Favorites.SPANY, // 14
Favorites.TITLE, // 15
Favorites.PROFILE_ID, // 16
Favorites.RANK, // 17
};
private static final int ID_INDEX = 0;
@@ -124,13 +123,12 @@ public class LauncherBackupHelper implements BackupHelper {
private static final int ICON_INDEX = 8;
private static final int ICON_PACKAGE_INDEX = 9;
private static final int ICON_RESOURCE_INDEX = 10;
private static final int ICON_TYPE_INDEX = 11;
private static final int ITEM_TYPE_INDEX = 12;
private static final int SCREEN_INDEX = 13;
private static final int SPANX_INDEX = 14;
private static final int SPANY_INDEX = 15;
private static final int TITLE_INDEX = 16;
private static final int RANK_INDEX = 18;
private static final int ITEM_TYPE_INDEX = 11;
private static final int SCREEN_INDEX = 12;
private static final int SPANX_INDEX = 13;
private static final int SPANY_INDEX = 14;
private static final int TITLE_INDEX = 15;
private static final int RANK_INDEX = 17;
private static final String[] SCREEN_PROJECTION = {
WorkspaceScreens._ID, // 0
@@ -814,7 +812,6 @@ public class LauncherBackupHelper implements BackupHelper {
favorite.cellY = c.getInt(CELLY_INDEX);
favorite.spanX = c.getInt(SPANX_INDEX);
favorite.spanY = c.getInt(SPANY_INDEX);
favorite.iconType = c.getInt(ICON_TYPE_INDEX);
favorite.rank = c.getInt(RANK_INDEX);
String title = c.getString(TITLE_INDEX);
@@ -840,15 +837,11 @@ public class LauncherBackupHelper implements BackupHelper {
favorite.appWidgetProvider = appWidgetProvider;
}
} else if (favorite.itemType == Favorites.ITEM_TYPE_SHORTCUT) {
if (favorite.iconType == Favorites.ICON_TYPE_RESOURCE) {
String iconPackage = c.getString(ICON_PACKAGE_INDEX);
if (!TextUtils.isEmpty(iconPackage)) {
favorite.iconPackage = iconPackage;
}
String iconResource = c.getString(ICON_RESOURCE_INDEX);
if (!TextUtils.isEmpty(iconResource)) {
favorite.iconResource = iconResource;
}
String iconPackage = c.getString(ICON_PACKAGE_INDEX);
String iconResource = c.getString(ICON_RESOURCE_INDEX);
if (!TextUtils.isEmpty(iconPackage) && !TextUtils.isEmpty(iconResource)) {
favorite.iconResource = iconResource;
favorite.iconPackage = iconPackage;
}
byte[] blob = c.getBlob(ICON_INDEX);
@@ -906,11 +899,8 @@ public class LauncherBackupHelper implements BackupHelper {
values.put(Favorites.RANK, favorite.rank);
if (favorite.itemType == Favorites.ITEM_TYPE_SHORTCUT) {
values.put(Favorites.ICON_TYPE, favorite.iconType);
if (favorite.iconType == Favorites.ICON_TYPE_RESOURCE) {
values.put(Favorites.ICON_PACKAGE, favorite.iconPackage);
values.put(Favorites.ICON_RESOURCE, favorite.iconResource);
}
values.put(Favorites.ICON_PACKAGE, favorite.iconPackage);
values.put(Favorites.ICON_RESOURCE, favorite.iconResource);
values.put(Favorites.ICON, favorite.icon);
}
@@ -3473,7 +3473,6 @@ public class LauncherModel extends BroadcastReceiver
info.title = Utilities.trim(name);
info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user);
info.intent = intent;
info.customIcon = customIcon;
info.iconResource = iconResource;
return info;
@@ -1077,8 +1077,6 @@ public class LauncherProvider extends ContentProvider {
= c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT);
final int titleIndex
= c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE);
final int iconTypeIndex
= c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_TYPE);
final int iconIndex
= c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON);
final int iconPackageIndex
@@ -1195,8 +1193,6 @@ public class LauncherProvider extends ContentProvider {
values.put(LauncherSettings.Favorites._ID, c.getInt(idIndex));
values.put(LauncherSettings.Favorites.INTENT, intentStr);
values.put(LauncherSettings.Favorites.TITLE, c.getString(titleIndex));
values.put(LauncherSettings.Favorites.ICON_TYPE,
c.getInt(iconTypeIndex));
values.put(LauncherSettings.Favorites.ICON, c.getBlob(iconIndex));
values.put(LauncherSettings.Favorites.ICON_PACKAGE,
c.getString(iconPackageIndex));
@@ -70,35 +70,19 @@ public class LauncherSettings {
public static final int ITEM_TYPE_SHORTCUT = 1;
/**
* The icon type.
* <P>Type: INTEGER</P>
*/
public static final String ICON_TYPE = "iconType";
/**
* The icon is a resource identified by a package name and an integer id.
*/
public static final int ICON_TYPE_RESOURCE = 0;
/**
* The icon is a bitmap.
*/
public static final int ICON_TYPE_BITMAP = 1;
/**
* The icon package name, if icon type is ICON_TYPE_RESOURCE.
* The icon package name in Intent.ShortcutIconResource
* <P>Type: TEXT</P>
*/
public static final String ICON_PACKAGE = "iconPackage";
/**
* The icon resource id, if icon type is ICON_TYPE_RESOURCE.
* The icon resource name in Intent.ShortcutIconResource
* <P>Type: TEXT</P>
*/
public static final String ICON_RESOURCE = "iconResource";
/**
* The custom icon bitmap, if icon type is ICON_TYPE_BITMAP.
* The custom icon bitmap.
* <P>Type: BLOB</P>
*/
public static final String ICON = "icon";
@@ -272,7 +256,6 @@ public class LauncherSettings {
"spanY INTEGER," +
"itemType INTEGER," +
"appWidgetId INTEGER NOT NULL DEFAULT -1," +
"iconType INTEGER," +
"iconPackage TEXT," +
"iconResource TEXT," +
"icon BLOB," +
+7 -25
View File
@@ -73,13 +73,6 @@ public class ShortcutInfo extends ItemInfo {
*/
public Intent intent;
/**
* Indicates whether the icon comes from an application's resource (if false)
* or from a custom Bitmap (if true.)
* TODO: remove this flag
*/
public boolean customIcon;
/**
* Indicates whether we're using the default fallback icon instead of something from the
* app.
@@ -175,7 +168,6 @@ public class ShortcutInfo extends ItemInfo {
iconResource.resourceName = info.iconResource.resourceName;
}
mIcon = info.mIcon; // TODO: should make a copy here. maybe we don't need this ctor at all
customIcon = info.customIcon;
flags = info.flags;
user = info.user;
status = info.status;
@@ -186,7 +178,6 @@ public class ShortcutInfo extends ItemInfo {
super(info);
title = Utilities.trim(info.title);
intent = new Intent(info.intent);
customIcon = false;
flags = info.flags;
isDisabled = info.isDisabled;
}
@@ -225,22 +216,14 @@ public class ShortcutInfo extends ItemInfo {
values.put(LauncherSettings.BaseLauncherColumns.INTENT, uri);
values.put(LauncherSettings.Favorites.RESTORED, status);
if (customIcon) {
values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
LauncherSettings.BaseLauncherColumns.ICON_TYPE_BITMAP);
if (!usingFallbackIcon && !usingLowResIcon) {
writeBitmap(values, mIcon);
} else {
if (!usingFallbackIcon) {
writeBitmap(values, mIcon);
}
if (iconResource != null) {
values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
LauncherSettings.BaseLauncherColumns.ICON_TYPE_RESOURCE);
values.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE,
iconResource.packageName);
values.put(LauncherSettings.BaseLauncherColumns.ICON_RESOURCE,
iconResource.resourceName);
}
}
if (iconResource != null) {
values.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE,
iconResource.packageName);
values.put(LauncherSettings.BaseLauncherColumns.ICON_RESOURCE,
iconResource.resourceName);
}
}
@@ -284,7 +267,6 @@ public class ShortcutInfo extends ItemInfo {
shortcut.title = Utilities.trim(info.getLabel());
shortcut.contentDescription = UserManagerCompat.getInstance(context)
.getBadgedLabelForUser(info.getLabel(), info.getUser());
shortcut.customIcon = false;
shortcut.intent = AppInfo.makeLaunchIntent(context, info, info.getUser());
shortcut.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
shortcut.flags = AppInfo.initFlags(info);
@@ -30,13 +30,11 @@ import com.android.launcher3.Utilities;
* Utility class to load icon from a cursor.
*/
public class CursorIconInfo {
public final int iconTypeIndex;
public final int iconPackageIndex;
public final int iconResourceIndex;
public final int iconIndex;
public CursorIconInfo(Cursor c) {
iconTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_TYPE);
iconIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON);
iconPackageIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_PACKAGE);
iconResourceIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_RESOURCE);
@@ -44,26 +42,17 @@ public class CursorIconInfo {
public Bitmap loadIcon(Cursor c, ShortcutInfo info, Context context) {
Bitmap icon = null;
int iconType = c.getInt(iconTypeIndex);
switch (iconType) {
case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
String packageName = c.getString(iconPackageIndex);
String resourceName = c.getString(iconResourceIndex);
if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
info.iconResource = new ShortcutIconResource();
info.iconResource.packageName = packageName;
info.iconResource.resourceName = resourceName;
icon = Utilities.createIconBitmap(packageName, resourceName, context);
}
if (icon == null) {
// Failed to load from resource, try loading from DB.
icon = Utilities.createIconBitmap(c, iconIndex, context);
}
break;
case LauncherSettings.Favorites.ICON_TYPE_BITMAP:
String packageName = c.getString(iconPackageIndex);
String resourceName = c.getString(iconResourceIndex);
if (!TextUtils.isEmpty(packageName) || !TextUtils.isEmpty(resourceName)) {
info.iconResource = new ShortcutIconResource();
info.iconResource.packageName = packageName;
info.iconResource.resourceName = resourceName;
icon = Utilities.createIconBitmap(packageName, resourceName, context);
}
if (icon == null) {
// Failed to load from resource, try loading from DB.
icon = Utilities.createIconBitmap(c, iconIndex, context);
info.customIcon = icon != null;
break;
}
return icon;
}