Loading src/com/android/launcher3/AppInfo.java +4 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,10 @@ class AppInfo extends ItemInfo { return intent; } protected Intent getRestoredIntent() { return null; } /** * Must not hold the Context. */ Loading src/com/android/launcher3/ItemInfo.java +4 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,10 @@ public class ItemInfo { throw new RuntimeException("Unexpected Intent"); } protected Intent getRestoredIntent() { throw new RuntimeException("Unexpected Intent"); } /** * Write the fields of this item to the DB * Loading src/com/android/launcher3/LauncherModel.java +54 −3 Original line number Diff line number Diff line Loading @@ -302,6 +302,15 @@ public class LauncherModel extends BroadcastReceiver { return; } final ArrayList<AppInfo> restoredAppsFinal = new ArrayList<AppInfo>(); Iterator<AppInfo> iter = allAppsApps.iterator(); while (iter.hasNext()) { ItemInfo a = iter.next(); if (LauncherModel.appWasRestored(ctx, a.getIntent())) { restoredAppsFinal.add((AppInfo) a); } } // Process the newly added applications and add them to the database first Runnable r = new Runnable() { public void run() { Loading @@ -310,6 +319,9 @@ public class LauncherModel extends BroadcastReceiver { Callbacks cb = mCallbacks != null ? mCallbacks.get() : null; if (callbacks == cb && cb != null) { callbacks.bindAppsAdded(null, null, null, allAppsApps); if (!restoredAppsFinal.isEmpty()) { callbacks.bindAppsUpdated(restoredAppsFinal); } } } }); Loading @@ -333,6 +345,7 @@ public class LauncherModel extends BroadcastReceiver { public void run() { final ArrayList<ItemInfo> addedShortcutsFinal = new ArrayList<ItemInfo>(); final ArrayList<Long> addedWorkspaceScreensFinal = new ArrayList<Long>(); final ArrayList<AppInfo> restoredAppsFinal = new ArrayList<AppInfo>(); // Get the list of workspace screens. We need to append to this list and // can not use sBgWorkspaceScreens because loadWorkspace() may not have been Loading @@ -353,6 +366,11 @@ public class LauncherModel extends BroadcastReceiver { // Short-circuit this logic if the icon exists somewhere on the workspace if (LauncherModel.shortcutExists(context, name, launchIntent)) { // Only InstallShortcutReceiver sends us shortcutInfos, ignore them if (a instanceof AppInfo && LauncherModel.appWasRestored(context, launchIntent)) { restoredAppsFinal.add((AppInfo) a); } continue; } Loading Loading @@ -428,6 +446,9 @@ public class LauncherModel extends BroadcastReceiver { } callbacks.bindAppsAdded(addedWorkspaceScreensFinal, addNotAnimated, addAnimated, null); if (!restoredAppsFinal.isEmpty()) { callbacks.bindAppsUpdated(restoredAppsFinal); } } } }); Loading Loading @@ -792,6 +813,30 @@ public class LauncherModel extends BroadcastReceiver { return result; } /** * Returns true if the shortcuts already exists in the database. * we identify a shortcut by the component name of the intent. */ static boolean appWasRestored(Context context, Intent intent) { final ContentResolver cr = context.getContentResolver(); final ComponentName component = intent.getComponent(); if (component == null) { return false; } String componentName = component.flattenToString(); final String where = "intent glob \"*component=" + componentName + "*\" and restored = 1"; Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, new String[]{"intent", "restored"}, where, null, null); boolean result = false; try { result = c.moveToFirst(); } finally { c.close(); } Log.d(TAG, "shortcutWasRestored is " + result + " for " + componentName); return result; } /** * Returns an ItemInfo array containing all the items in the LauncherModel. * The ItemInfo.id is not set through this function. Loading Loading @@ -1839,7 +1884,7 @@ public class LauncherModel extends BroadcastReceiver { Launcher.addDumpLog(TAG, "constructing info for partially restored package", true); info = getRestoredItemInfo(c, titleIndex); info = getRestoredItemInfo(c, titleIndex, intent); intent = getRestoredItemIntent(c, context, intent); } else if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { Loading Loading @@ -2810,7 +2855,7 @@ public class LauncherModel extends BroadcastReceiver { * Make an ShortcutInfo object for a restored application or shortcut item that points * to a package that is not yet installed on the system. */ public ShortcutInfo getRestoredItemInfo(Cursor cursor, int titleIndex) { public ShortcutInfo getRestoredItemInfo(Cursor cursor, int titleIndex, Intent intent) { final ShortcutInfo info = new ShortcutInfo(); info.usingFallbackIcon = true; info.setIcon(getFallbackIcon()); Loading @@ -2820,6 +2865,7 @@ public class LauncherModel extends BroadcastReceiver { info.title = ""; } info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; info.restoredIntent = intent; return info; } Loading @@ -2828,6 +2874,7 @@ public class LauncherModel extends BroadcastReceiver { * to the market page for the item. */ private Intent getRestoredItemIntent(Cursor c, Context context, Intent intent) { final boolean debug = false; ComponentName componentName = intent.getComponent(); Intent marketIntent = new Intent(Intent.ACTION_VIEW); Uri marketUri = new Uri.Builder() Loading @@ -2835,7 +2882,7 @@ public class LauncherModel extends BroadcastReceiver { .authority("details") .appendQueryParameter("id", componentName.getPackageName()) .build(); Log.d(TAG, "manufactured intent uri: " + marketUri.toString()); if (debug) Log.d(TAG, "manufactured intent uri: " + marketUri.toString()); marketIntent.setData(marketUri); return marketIntent; } Loading Loading @@ -3001,6 +3048,10 @@ public class LauncherModel extends BroadcastReceiver { Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) { return true; } // placeholder shortcuts get special treatment, let them through too. if (info.getRestoredIntent() != null) { return true; } } return false; } Loading src/com/android/launcher3/ShortcutInfo.java +21 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,12 @@ class ShortcutInfo extends ItemInfo { long firstInstallTime; int flags = 0; /** * If this shortcut is a placeholder, then intent will be a market intent for the package, and * this will hold the original intent from the database. Otherwise, null. */ Intent restoredIntent; ShortcutInfo() { itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; } Loading @@ -72,6 +78,21 @@ class ShortcutInfo extends ItemInfo { return intent; } protected Intent getRestoredIntent() { return restoredIntent; } /** * Overwrite placeholder data with restored data, or do nothing if this is not a placeholder. */ public void restore() { if (restoredIntent != null) { intent = restoredIntent; restoredIntent = null; } } ShortcutInfo(Intent intent, CharSequence title, Bitmap icon) { this(); this.intent = intent; Loading src/com/android/launcher3/Workspace.java +10 −5 Original line number Diff line number Diff line Loading @@ -2709,12 +2709,13 @@ public class Workspace extends SmoothPagedView mTargetCell); float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); if (willCreateUserFolder((ItemInfo) d.dragInfo, dropTargetLayout, mTargetCell, distance, true)) { if (mCreateUserFolderOnDrop && willCreateUserFolder((ItemInfo) d.dragInfo, dropTargetLayout, mTargetCell, distance, true)) { return true; } if (willAddToExistingUserFolder((ItemInfo) d.dragInfo, dropTargetLayout, mTargetCell, distance)) { if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder((ItemInfo) d.dragInfo, dropTargetLayout, mTargetCell, distance)) { return true; } Loading Loading @@ -4612,11 +4613,15 @@ public class Workspace extends SmoothPagedView private void updateShortcut(HashMap<ComponentName, AppInfo> appsMap, ItemInfo info, View child) { ComponentName cn = info.getIntent().getComponent(); if (info.getRestoredIntent() != null) { cn = info.getRestoredIntent().getComponent(); } if (cn != null) { AppInfo appInfo = appsMap.get(info.getIntent().getComponent()); AppInfo appInfo = appsMap.get(cn); if ((appInfo != null) && LauncherModel.isShortcutInfoUpdateable(info)) { ShortcutInfo shortcutInfo = (ShortcutInfo) info; BubbleTextView shortcut = (BubbleTextView) child; shortcutInfo.restore(); shortcutInfo.updateIcon(mIconCache); shortcutInfo.title = appInfo.title.toString(); shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache); Loading Loading
src/com/android/launcher3/AppInfo.java +4 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,10 @@ class AppInfo extends ItemInfo { return intent; } protected Intent getRestoredIntent() { return null; } /** * Must not hold the Context. */ Loading
src/com/android/launcher3/ItemInfo.java +4 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,10 @@ public class ItemInfo { throw new RuntimeException("Unexpected Intent"); } protected Intent getRestoredIntent() { throw new RuntimeException("Unexpected Intent"); } /** * Write the fields of this item to the DB * Loading
src/com/android/launcher3/LauncherModel.java +54 −3 Original line number Diff line number Diff line Loading @@ -302,6 +302,15 @@ public class LauncherModel extends BroadcastReceiver { return; } final ArrayList<AppInfo> restoredAppsFinal = new ArrayList<AppInfo>(); Iterator<AppInfo> iter = allAppsApps.iterator(); while (iter.hasNext()) { ItemInfo a = iter.next(); if (LauncherModel.appWasRestored(ctx, a.getIntent())) { restoredAppsFinal.add((AppInfo) a); } } // Process the newly added applications and add them to the database first Runnable r = new Runnable() { public void run() { Loading @@ -310,6 +319,9 @@ public class LauncherModel extends BroadcastReceiver { Callbacks cb = mCallbacks != null ? mCallbacks.get() : null; if (callbacks == cb && cb != null) { callbacks.bindAppsAdded(null, null, null, allAppsApps); if (!restoredAppsFinal.isEmpty()) { callbacks.bindAppsUpdated(restoredAppsFinal); } } } }); Loading @@ -333,6 +345,7 @@ public class LauncherModel extends BroadcastReceiver { public void run() { final ArrayList<ItemInfo> addedShortcutsFinal = new ArrayList<ItemInfo>(); final ArrayList<Long> addedWorkspaceScreensFinal = new ArrayList<Long>(); final ArrayList<AppInfo> restoredAppsFinal = new ArrayList<AppInfo>(); // Get the list of workspace screens. We need to append to this list and // can not use sBgWorkspaceScreens because loadWorkspace() may not have been Loading @@ -353,6 +366,11 @@ public class LauncherModel extends BroadcastReceiver { // Short-circuit this logic if the icon exists somewhere on the workspace if (LauncherModel.shortcutExists(context, name, launchIntent)) { // Only InstallShortcutReceiver sends us shortcutInfos, ignore them if (a instanceof AppInfo && LauncherModel.appWasRestored(context, launchIntent)) { restoredAppsFinal.add((AppInfo) a); } continue; } Loading Loading @@ -428,6 +446,9 @@ public class LauncherModel extends BroadcastReceiver { } callbacks.bindAppsAdded(addedWorkspaceScreensFinal, addNotAnimated, addAnimated, null); if (!restoredAppsFinal.isEmpty()) { callbacks.bindAppsUpdated(restoredAppsFinal); } } } }); Loading Loading @@ -792,6 +813,30 @@ public class LauncherModel extends BroadcastReceiver { return result; } /** * Returns true if the shortcuts already exists in the database. * we identify a shortcut by the component name of the intent. */ static boolean appWasRestored(Context context, Intent intent) { final ContentResolver cr = context.getContentResolver(); final ComponentName component = intent.getComponent(); if (component == null) { return false; } String componentName = component.flattenToString(); final String where = "intent glob \"*component=" + componentName + "*\" and restored = 1"; Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, new String[]{"intent", "restored"}, where, null, null); boolean result = false; try { result = c.moveToFirst(); } finally { c.close(); } Log.d(TAG, "shortcutWasRestored is " + result + " for " + componentName); return result; } /** * Returns an ItemInfo array containing all the items in the LauncherModel. * The ItemInfo.id is not set through this function. Loading Loading @@ -1839,7 +1884,7 @@ public class LauncherModel extends BroadcastReceiver { Launcher.addDumpLog(TAG, "constructing info for partially restored package", true); info = getRestoredItemInfo(c, titleIndex); info = getRestoredItemInfo(c, titleIndex, intent); intent = getRestoredItemIntent(c, context, intent); } else if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { Loading Loading @@ -2810,7 +2855,7 @@ public class LauncherModel extends BroadcastReceiver { * Make an ShortcutInfo object for a restored application or shortcut item that points * to a package that is not yet installed on the system. */ public ShortcutInfo getRestoredItemInfo(Cursor cursor, int titleIndex) { public ShortcutInfo getRestoredItemInfo(Cursor cursor, int titleIndex, Intent intent) { final ShortcutInfo info = new ShortcutInfo(); info.usingFallbackIcon = true; info.setIcon(getFallbackIcon()); Loading @@ -2820,6 +2865,7 @@ public class LauncherModel extends BroadcastReceiver { info.title = ""; } info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; info.restoredIntent = intent; return info; } Loading @@ -2828,6 +2874,7 @@ public class LauncherModel extends BroadcastReceiver { * to the market page for the item. */ private Intent getRestoredItemIntent(Cursor c, Context context, Intent intent) { final boolean debug = false; ComponentName componentName = intent.getComponent(); Intent marketIntent = new Intent(Intent.ACTION_VIEW); Uri marketUri = new Uri.Builder() Loading @@ -2835,7 +2882,7 @@ public class LauncherModel extends BroadcastReceiver { .authority("details") .appendQueryParameter("id", componentName.getPackageName()) .build(); Log.d(TAG, "manufactured intent uri: " + marketUri.toString()); if (debug) Log.d(TAG, "manufactured intent uri: " + marketUri.toString()); marketIntent.setData(marketUri); return marketIntent; } Loading Loading @@ -3001,6 +3048,10 @@ public class LauncherModel extends BroadcastReceiver { Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) { return true; } // placeholder shortcuts get special treatment, let them through too. if (info.getRestoredIntent() != null) { return true; } } return false; } Loading
src/com/android/launcher3/ShortcutInfo.java +21 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,12 @@ class ShortcutInfo extends ItemInfo { long firstInstallTime; int flags = 0; /** * If this shortcut is a placeholder, then intent will be a market intent for the package, and * this will hold the original intent from the database. Otherwise, null. */ Intent restoredIntent; ShortcutInfo() { itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; } Loading @@ -72,6 +78,21 @@ class ShortcutInfo extends ItemInfo { return intent; } protected Intent getRestoredIntent() { return restoredIntent; } /** * Overwrite placeholder data with restored data, or do nothing if this is not a placeholder. */ public void restore() { if (restoredIntent != null) { intent = restoredIntent; restoredIntent = null; } } ShortcutInfo(Intent intent, CharSequence title, Bitmap icon) { this(); this.intent = intent; Loading
src/com/android/launcher3/Workspace.java +10 −5 Original line number Diff line number Diff line Loading @@ -2709,12 +2709,13 @@ public class Workspace extends SmoothPagedView mTargetCell); float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); if (willCreateUserFolder((ItemInfo) d.dragInfo, dropTargetLayout, mTargetCell, distance, true)) { if (mCreateUserFolderOnDrop && willCreateUserFolder((ItemInfo) d.dragInfo, dropTargetLayout, mTargetCell, distance, true)) { return true; } if (willAddToExistingUserFolder((ItemInfo) d.dragInfo, dropTargetLayout, mTargetCell, distance)) { if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder((ItemInfo) d.dragInfo, dropTargetLayout, mTargetCell, distance)) { return true; } Loading Loading @@ -4612,11 +4613,15 @@ public class Workspace extends SmoothPagedView private void updateShortcut(HashMap<ComponentName, AppInfo> appsMap, ItemInfo info, View child) { ComponentName cn = info.getIntent().getComponent(); if (info.getRestoredIntent() != null) { cn = info.getRestoredIntent().getComponent(); } if (cn != null) { AppInfo appInfo = appsMap.get(info.getIntent().getComponent()); AppInfo appInfo = appsMap.get(cn); if ((appInfo != null) && LauncherModel.isShortcutInfoUpdateable(info)) { ShortcutInfo shortcutInfo = (ShortcutInfo) info; BubbleTextView shortcut = (BubbleTextView) child; shortcutInfo.restore(); shortcutInfo.updateIcon(mIconCache); shortcutInfo.title = appInfo.title.toString(); shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache); Loading