From 997a92348a6d6e061737399321393449c16cd4d8 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Wed, 24 Jul 2013 15:33:46 -0700 Subject: Removing old new-app animation code, and refactoring InstallShortcutReceiver to use new add/bind logic. Change-Id: Ide27dbcf1d1b1631fcd33a6c54a51b31e125c2f4 --- src/com/android/launcher3/ApplicationInfo.java | 4 + .../android/launcher3/InstallShortcutReceiver.java | 188 ++++++--------------- src/com/android/launcher3/ItemInfo.java | 4 + src/com/android/launcher3/Launcher.java | 128 ++------------ src/com/android/launcher3/LauncherModel.java | 70 ++++++-- src/com/android/launcher3/ShortcutInfo.java | 4 + .../launcher3/UninstallShortcutReceiver.java | 35 +--- src/com/android/launcher3/Workspace.java | 28 --- 8 files changed, 136 insertions(+), 325 deletions(-) (limited to 'src/com/android/launcher3') diff --git a/src/com/android/launcher3/ApplicationInfo.java b/src/com/android/launcher3/ApplicationInfo.java index 1bc147a20..1b396f752 100644 --- a/src/com/android/launcher3/ApplicationInfo.java +++ b/src/com/android/launcher3/ApplicationInfo.java @@ -60,6 +60,10 @@ class ApplicationInfo extends ItemInfo { itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; } + protected Intent getIntent() { + return intent; + } + /** * Must not hold the Context. */ diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java index f97ed5310..244b3db88 100644 --- a/src/com/android/launcher3/InstallShortcutReceiver.java +++ b/src/com/android/launcher3/InstallShortcutReceiver.java @@ -38,8 +38,6 @@ import org.json.*; public class InstallShortcutReceiver extends BroadcastReceiver { public static final String ACTION_INSTALL_SHORTCUT = "com.android.launcher3.action.INSTALL_SHORTCUT"; - public static final String NEW_APPS_PAGE_KEY = "apps.new.page"; - public static final String NEW_APPS_LIST_KEY = "apps.new.list"; public static final String DATA_INTENT_KEY = "intent.data"; public static final String LAUNCH_INTENT_KEY = "intent.launch"; @@ -51,11 +49,10 @@ public class InstallShortcutReceiver extends BroadcastReceiver { public static final String APPS_PENDING_INSTALL = "apps_to_install"; public static final int NEW_SHORTCUT_BOUNCE_DURATION = 450; - public static final int NEW_SHORTCUT_STAGGER_DELAY = 75; + public static final int NEW_SHORTCUT_STAGGER_DELAY = 85; private static final int INSTALL_SHORTCUT_SUCCESSFUL = 0; private static final int INSTALL_SHORTCUT_IS_DUPLICATE = -1; - private static final int INSTALL_SHORTCUT_NO_SPACE = -2; // A mime-type representing shortcut data public static final String SHORTCUT_MIMETYPE = @@ -201,12 +198,12 @@ public class InstallShortcutReceiver extends BroadcastReceiver { PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent); info.icon = icon; info.iconResource = iconResource; - if (mUseInstallQueue || launcherNotLoaded) { - String spKey = LauncherAppState.getSharedPreferencesKey(); - SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); - addToInstallQueue(sp, info); - } else { - processInstallShortcut(context, info); + + String spKey = LauncherAppState.getSharedPreferencesKey(); + SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); + addToInstallQueue(sp, info); + if (!mUseInstallQueue && !launcherNotLoaded) { + flushInstallQueue(context); } } @@ -221,142 +218,59 @@ public class InstallShortcutReceiver extends BroadcastReceiver { String spKey = LauncherAppState.getSharedPreferencesKey(); SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); ArrayList installQueue = getAndClearInstallQueue(sp); - Iterator iter = installQueue.iterator(); - while (iter.hasNext()) { - processInstallShortcut(context, iter.next()); - } - } - - private static void processInstallShortcut(Context context, - PendingInstallShortcutInfo pendingInfo) { - String spKey = LauncherAppState.getSharedPreferencesKey(); - SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); - - final Intent data = pendingInfo.data; - final Intent intent = pendingInfo.launchIntent; - final String name = pendingInfo.name; - - // Lock on the app so that we don't try and get the items while apps are being added - LauncherAppState app = LauncherAppState.getInstance(); - final int[] result = {INSTALL_SHORTCUT_SUCCESSFUL}; - boolean found = false; - synchronized (app) { - // Flush the LauncherModel worker thread, so that if we just did another - // processInstallShortcut, we give it time for its shortcut to get added to the - // database (getItemsInLocalCoordinates reads the database) - app.getModel().flushWorkerThread(); - final ArrayList items = LauncherModel.getItemsInLocalCoordinates(context); - final boolean exists = LauncherModel.shortcutExists(context, name, intent); - - // Try adding to the workspace screens incrementally, starting at the default or center - // screen and alternating between +1, -1, +2, -2, etc. (using ~ ceil(i/2f)*(-1)^(i-1)) - final int screen = Launcher.DEFAULT_SCREEN; - for (int i = 0; i < Launcher.SCREEN_COUNT && !found; i++) { - int si = i; - if (0 <= si && si < Launcher.SCREEN_COUNT) { - found = installShortcut(context, data, items, name, intent, si, exists, sp, - result); + if (!installQueue.isEmpty()) { + Iterator iter = installQueue.iterator(); + ArrayList addShortcuts = new ArrayList(); + int result = INSTALL_SHORTCUT_SUCCESSFUL; + String duplicateName = ""; + while (iter.hasNext()) { + final PendingInstallShortcutInfo pendingInfo = iter.next(); + final Intent data = pendingInfo.data; + final Intent intent = pendingInfo.launchIntent; + final String name = pendingInfo.name; + final boolean exists = LauncherModel.shortcutExists(context, name, intent); + final boolean allowDuplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true); + + // TODO-XXX: Disable duplicates for now + if (!exists /* && allowDuplicate */) { + // Generate a shortcut info to add into the model + ShortcutInfo info = getShortcutInfo(context, pendingInfo.data, + pendingInfo.launchIntent); + addShortcuts.add(info); + } + /* + else if (exists && !allowDuplicate) { + result = INSTALL_SHORTCUT_IS_DUPLICATE; + duplicateName = name; } + */ } - } - // We only report error messages (duplicate shortcut or out of space) as the add-animation - // will provide feedback otherwise - if (!found) { - if (result[0] == INSTALL_SHORTCUT_NO_SPACE) { - Toast.makeText(context, context.getString(R.string.completely_out_of_space), - Toast.LENGTH_SHORT).show(); - } else if (result[0] == INSTALL_SHORTCUT_IS_DUPLICATE) { - Toast.makeText(context, context.getString(R.string.shortcut_duplicate, name), - Toast.LENGTH_SHORT).show(); + // Notify the user once if we weren't able to place any duplicates + if (result == INSTALL_SHORTCUT_IS_DUPLICATE) { + Toast.makeText(context, context.getString(R.string.shortcut_duplicate, + duplicateName), Toast.LENGTH_SHORT).show(); } - } - } - - private static boolean installShortcut(Context context, Intent data, ArrayList items, - String name, final Intent intent, final int screen, boolean shortcutExists, - final SharedPreferences sharedPrefs, int[] result) { - int[] tmpCoordinates = new int[2]; - if (findEmptyCell(context, items, tmpCoordinates, screen)) { - if (intent != null) { - if (intent.getAction() == null) { - intent.setAction(Intent.ACTION_VIEW); - } else if (intent.getAction().equals(Intent.ACTION_MAIN) && - intent.getCategories() != null && - intent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { - intent.addFlags( - Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); - } - - // By default, we allow for duplicate entries (located in - // different places) - boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true); - if (duplicate || !shortcutExists) { - new Thread("setNewAppsThread") { - public void run() { - synchronized (sLock) { - // If the new app is going to fall into the same page as before, - // then just continue adding to the current page - final int newAppsScreen = sharedPrefs.getInt( - NEW_APPS_PAGE_KEY, screen); - SharedPreferences.Editor editor = sharedPrefs.edit(); - if (newAppsScreen == -1 || newAppsScreen == screen) { - addToStringSet(sharedPrefs, - editor, NEW_APPS_LIST_KEY, intent.toUri(0)); - } - editor.putInt(NEW_APPS_PAGE_KEY, screen); - editor.commit(); - } - } - }.start(); - // Update the Launcher db - LauncherAppState app = LauncherAppState.getInstance(); - ShortcutInfo info = app.getModel().addShortcut(context, data, - LauncherSettings.Favorites.CONTAINER_DESKTOP, screen, - tmpCoordinates[0], tmpCoordinates[1], true); - if (info == null) { - return false; - } - } else { - result[0] = INSTALL_SHORTCUT_IS_DUPLICATE; - } - - return true; + // Add the new apps to the model and bind them + if (!addShortcuts.isEmpty()) { + LauncherAppState app = LauncherAppState.getInstance(); + app.getModel().addAndBindAddedApps(context, addShortcuts); } - } else { - result[0] = INSTALL_SHORTCUT_NO_SPACE; } - - return false; } - // TODO: this needs to be updated to take a screenId instead of a screen index - private static boolean findEmptyCell(Context context, ArrayList items, int[] xy, - int screen) { - final int xCount = LauncherModel.getCellCountX(); - final int yCount = LauncherModel.getCellCountY(); - boolean[][] occupied = new boolean[xCount][yCount]; - - ItemInfo item = null; - int cellX, cellY, spanX, spanY; - for (int i = 0; i < items.size(); ++i) { - item = items.get(i); - if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { - if (item.screenId == screen) { - cellX = item.cellX; - cellY = item.cellY; - spanX = item.spanX; - spanY = item.spanY; - for (int x = cellX; 0 <= x && x < cellX + spanX && x < xCount; x++) { - for (int y = cellY; 0 <= y && y < cellY + spanY && y < yCount; y++) { - occupied[x][y] = true; - } - } - } - } + private static ShortcutInfo getShortcutInfo(Context context, Intent data, + Intent launchIntent) { + if (launchIntent.getAction() == null) { + launchIntent.setAction(Intent.ACTION_VIEW); + } else if (launchIntent.getAction().equals(Intent.ACTION_MAIN) && + launchIntent.getCategories() != null && + launchIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) { + launchIntent.addFlags( + Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); } - - return CellLayout.findVacantCell(xy, 1, 1, xCount, yCount, occupied); + LauncherAppState app = LauncherAppState.getInstance(); + return app.getModel().infoFromShortcutIntent(context, data, null); } } diff --git a/src/com/android/launcher3/ItemInfo.java b/src/com/android/launcher3/ItemInfo.java index 7ab30a989..8c4cefd5f 100644 --- a/src/com/android/launcher3/ItemInfo.java +++ b/src/com/android/launcher3/ItemInfo.java @@ -118,6 +118,10 @@ class ItemInfo { LauncherModel.checkItemInfo(this); } + protected Intent getIntent() { + throw new RuntimeException("Unexpected Intent"); + } + /** * Write the fields of this item to the DB * diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 359204542..c32de33f6 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -311,8 +311,6 @@ public class Launcher extends Activity // Holds the page that we need to animate to, and the icon views that we need to animate up // when we scroll to that page on resume. - private long mNewShortcutAnimateScreenId = -1; - private ArrayList mNewShortcutAnimateViews = new ArrayList(); private ImageView mFolderIconImageView; private Bitmap mFolderIconBitmap; private Canvas mFolderIconCanvas; @@ -764,7 +762,7 @@ public class Launcher extends Activity setWorkspaceBackground(mState == State.WORKSPACE); // Process any items that were added while Launcher was away - InstallShortcutReceiver.flushInstallQueue(this); + InstallShortcutReceiver.disableAndFlushInstallQueue(this); mPaused = false; sPausedFromUserAction = false; @@ -829,6 +827,9 @@ public class Launcher extends Activity // when Launcher resumes and we are still in AllApps. updateWallpaperVisibility(true); + // Ensure that items added to Launcher are queued until Launcher returns + InstallShortcutReceiver.enableInstallQueue(); + super.onPause(); mPaused = true; mDragController.cancelDrag(); @@ -3487,8 +3488,6 @@ public class Launcher extends Activity mBindOnResumeCallbacks.clear(); final Workspace workspace = mWorkspace; - mNewShortcutAnimateScreenId = -1; - mNewShortcutAnimateViews.clear(); mWorkspace.clearDropTargets(); int count = workspace.getChildCount(); for (int i = 0; i < count; i++) { @@ -3556,12 +3555,11 @@ public class Launcher extends Activity } // Get the list of added shortcuts and intersect them with the set of shortcuts here - Set newApps = new HashSet(); - newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps); - final AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); final Collection bounceAnims = new ArrayList(); + final boolean animateIcons = forceAnimateIcons && canRunNewAppsAnimation(); Workspace workspace = mWorkspace; + long newShortcutsScreenId = -1; for (int i = start; i < end; i++) { final ItemInfo item = shortcuts.get(i); @@ -3575,7 +3573,6 @@ public class Launcher extends Activity case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: ShortcutInfo info = (ShortcutInfo) item; - String uri = info.intent.toUri(0).toString(); View shortcut = createShortcut(info); /* @@ -3590,27 +3587,13 @@ public class Launcher extends Activity workspace.addInScreenFromBind(shortcut, item.container, item.screenId, item.cellX, item.cellY, 1, 1); - boolean animateIconUp = false; - synchronized (newApps) { - if (newApps.contains(uri)) { - animateIconUp = newApps.remove(uri); - } - } - if (forceAnimateIcons) { + if (animateIcons) { // Animate all the applications up now shortcut.setAlpha(0f); shortcut.setScaleX(0f); shortcut.setScaleY(0f); bounceAnims.add(createNewAppBounceAnimation(shortcut, i)); - } else if (animateIconUp) { - // Prepare the view to be animated up - shortcut.setAlpha(0f); - shortcut.setScaleX(0f); - shortcut.setScaleY(0f); - mNewShortcutAnimateScreenId = item.screenId; - if (!mNewShortcutAnimateViews.contains(shortcut)) { - mNewShortcutAnimateViews.add(shortcut); - } + newShortcutsScreenId = item.screenId; } break; case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: @@ -3623,7 +3606,16 @@ public class Launcher extends Activity } } - if (forceAnimateIcons) { + if (animateIcons) { + // Animate to the correct page + if (newShortcutsScreenId > -1) { + long currentScreenId = mWorkspace.getScreenIdForPageIndex(mWorkspace.getNextPage()); + int newScreenIndex = mWorkspace.getPageIndexForScreenId(newShortcutsScreenId); + if (newShortcutsScreenId != currentScreenId) { + mWorkspace.snapToPage(newScreenIndex); + } + } + // We post the animation slightly delayed to prevent slowdowns when we are loading // right after we return to launcher. mWorkspace.postDelayed(new Runnable() { @@ -3731,32 +3723,6 @@ public class Launcher extends Activity // package changes in bindSearchablesChanged() updateAppMarketIcon(); - // Animate up any icons as necessary - if (mVisible || mWorkspaceLoading) { - Runnable newAppsRunnable = new Runnable() { - @Override - public void run() { - runNewAppsAnimation(false); - } - }; - - boolean willSnapPage = mNewShortcutAnimateScreenId > -1 && - mNewShortcutAnimateScreenId != mWorkspace.getCurrentPage(); - if (canRunNewAppsAnimation()) { - // If the user has not interacted recently, then either snap to the new page to show - // the new-apps animation or just run them if they are to appear on the current page - if (willSnapPage) { - mWorkspace.snapToScreenId(mNewShortcutAnimateScreenId, newAppsRunnable); - } else { - runNewAppsAnimation(false); - } - } else { - // If the user has interacted recently, then just add the items in place if they - // are on another page (or just normally if they are added to the current page) - runNewAppsAnimation(willSnapPage); - } - } - mWorkspaceLoading = false; if (upgradePath) { mWorkspace.saveWorkspaceToDb(); @@ -3788,64 +3754,6 @@ public class Launcher extends Activity return bounceAnim; } - /** - * Runs a new animation that scales up icons that were added while Launcher was in the - * background. - * - * @param immediate whether to run the animation or show the results immediately - */ - private void runNewAppsAnimation(boolean immediate) { - AnimatorSet anim = LauncherAnimUtils.createAnimatorSet(); - Collection bounceAnims = new ArrayList(); - - // Order these new views spatially so that they animate in order - Collections.sort(mNewShortcutAnimateViews, new Comparator() { - @Override - public int compare(View a, View b) { - CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams(); - CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams(); - int cellCountX = LauncherModel.getCellCountX(); - return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX); - } - }); - - // Animate each of the views in place (or show them immediately if requested) - if (immediate) { - for (View v : mNewShortcutAnimateViews) { - v.setAlpha(1f); - v.setScaleX(1f); - v.setScaleY(1f); - } - } else { - for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) { - View v = mNewShortcutAnimateViews.get(i); - bounceAnims.add(createNewAppBounceAnimation(v, i)); - } - anim.playTogether(bounceAnims); - anim.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - if (mWorkspace != null) { - mWorkspace.postDelayed(mBuildLayersRunnable, 500); - } - } - }); - anim.start(); - } - - // Clean up - mNewShortcutAnimateScreenId = -1; - mNewShortcutAnimateViews.clear(); - new Thread("clearNewAppsThread") { - public void run() { - mSharedPrefs.edit() - .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1) - .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null) - .commit(); - } - }.start(); - } - @Override public void bindSearchablesChanged() { boolean searchVisible = updateGlobalSearchIcon(); diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 28530e6ac..f79e08166 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -265,12 +265,18 @@ public class LauncherModel extends BroadcastReceiver { } } } - // XXX: Create a new page and add it to the first spot return null; } - public void addAndBindAddedApps(final Context context, final ArrayList added, + public void addAndBindAddedApps(final Context context, final ArrayList added) { + Callbacks cb = mCallbacks != null ? mCallbacks.get() : null; + addAndBindAddedApps(context, added, cb); + } + public void addAndBindAddedApps(final Context context, final ArrayList added, final Callbacks callbacks) { + if (added.isEmpty()) { + throw new RuntimeException("EMPTY ADDED ARRAY?"); + } // Process the newly added applications and add them to the database first Runnable r = new Runnable() { public void run() { @@ -278,11 +284,11 @@ public class LauncherModel extends BroadcastReceiver { final ArrayList addedWorkspaceScreensFinal = new ArrayList(); synchronized(sBgLock) { - Iterator iter = added.iterator(); + Iterator iter = added.iterator(); while (iter.hasNext()) { - ApplicationInfo a = iter.next(); + ItemInfo a = iter.next(); final String name = a.title.toString(); - final Intent launchIntent = a.intent; + final Intent launchIntent = a.getIntent(); // Short-circuit this logic if the icon exists somewhere on the workspace if (LauncherModel.shortcutExists(context, name, launchIntent)) { @@ -307,13 +313,20 @@ public class LauncherModel extends BroadcastReceiver { addedWorkspaceScreensFinal.add(screenId); // Find the coordinate again coords = LauncherModel.findNextAvailableIconSpace(context, - a.title.toString(), a.intent, startSearchPageIndex); + name, launchIntent, startSearchPageIndex); } if (coords == null) { throw new RuntimeException("Coordinates should not be null"); } - final ShortcutInfo shortcutInfo = a.makeShortcut(); + ShortcutInfo shortcutInfo; + if (a instanceof ShortcutInfo) { + shortcutInfo = (ShortcutInfo) a; + } else if (a instanceof ApplicationInfo) { + shortcutInfo = ((ApplicationInfo) a).makeShortcut(); + } else { + throw new RuntimeException("Unexpected info type"); + } // Add the shortcut to the db addItemToDatabase(context, shortcutInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP, @@ -323,16 +336,38 @@ public class LauncherModel extends BroadcastReceiver { } } - runOnMainThread(new Runnable() { - public void run() { - Callbacks cb = mCallbacks != null ? mCallbacks.get() : null; - if (callbacks == cb && cb != null) { - callbacks.bindAddScreens(addedWorkspaceScreensFinal); - callbacks.bindItems(addedShortcutsFinal, 0, - addedShortcutsFinal.size(), true); + if (!addedShortcutsFinal.isEmpty()) { + runOnMainThread(new Runnable() { + public void run() { + Callbacks cb = mCallbacks != null ? mCallbacks.get() : null; + if (callbacks == cb && cb != null) { + callbacks.bindAddScreens(addedWorkspaceScreensFinal); + + ItemInfo info = addedShortcutsFinal.get(addedShortcutsFinal.size() - 1); + long lastScreenId = info.screenId; + final ArrayList addAnimated = new ArrayList(); + final ArrayList addNotAnimated = new ArrayList(); + for (ItemInfo i : addedShortcutsFinal) { + if (i.screenId == lastScreenId) { + addAnimated.add(i); + } else { + addNotAnimated.add(i); + } + } + // We add the items without animation on non-visible pages, and with + // animations on the new page (which we will try and snap to). + if (!addNotAnimated.isEmpty()) { + callbacks.bindItems(addNotAnimated, 0, + addNotAnimated.size(), false); + } + if (!addAnimated.isEmpty()) { + callbacks.bindItems(addAnimated, 0, + addAnimated.size(), true); + } + } } - } - }); + }); + } } }; runOnWorkerThread(r); @@ -2374,8 +2409,9 @@ public class LauncherModel extends BroadcastReceiver { if (added != null) { // Ensure that we add all the workspace applications to the db + final ArrayList addedInfos = new ArrayList(added); Callbacks cb = mCallbacks != null ? mCallbacks.get() : null; - addAndBindAddedApps(context, added, cb); + addAndBindAddedApps(context, addedInfos, cb); } if (modified != null) { final ArrayList modifiedFinal = modified; diff --git a/src/com/android/launcher3/ShortcutInfo.java b/src/com/android/launcher3/ShortcutInfo.java index b6139b79e..fac96d2a2 100644 --- a/src/com/android/launcher3/ShortcutInfo.java +++ b/src/com/android/launcher3/ShortcutInfo.java @@ -67,6 +67,10 @@ class ShortcutInfo extends ItemInfo { ShortcutInfo() { itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; } + + protected Intent getIntent() { + return intent; + } public ShortcutInfo(Context context, ShortcutInfo info) { super(info); diff --git a/src/com/android/launcher3/UninstallShortcutReceiver.java b/src/com/android/launcher3/UninstallShortcutReceiver.java index 8e968cd76..2e1ed6967 100644 --- a/src/com/android/launcher3/UninstallShortcutReceiver.java +++ b/src/com/android/launcher3/UninstallShortcutReceiver.java @@ -79,19 +79,15 @@ public class UninstallShortcutReceiver extends BroadcastReceiver { private static void processUninstallShortcut(Context context, PendingUninstallShortcutInfo pendingInfo) { - String spKey = LauncherAppState.getSharedPreferencesKey(); - SharedPreferences sharedPrefs = context.getSharedPreferences(spKey, Context.MODE_PRIVATE); - final Intent data = pendingInfo.data; LauncherAppState app = LauncherAppState.getInstance(); synchronized (app) { // TODO: make removeShortcut internally threadsafe - removeShortcut(context, data, sharedPrefs); + removeShortcut(context, data); } } - private static void removeShortcut(Context context, Intent data, - final SharedPreferences sharedPrefs) { + private static void removeShortcut(Context context, Intent data) { Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT); String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true); @@ -132,33 +128,6 @@ public class UninstallShortcutReceiver extends BroadcastReceiver { Toast.makeText(context, context.getString(R.string.shortcut_uninstalled, name), Toast.LENGTH_SHORT).show(); } - - // Remove any items due to be animated - boolean appRemoved; - Set newApps = new HashSet(); - newApps = sharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps); - synchronized (newApps) { - do { - appRemoved = newApps.remove(intent.toUri(0).toString()); - } while (appRemoved); - } - if (appRemoved) { - final Set savedNewApps = newApps; - new Thread("setNewAppsThread-remove") { - public void run() { - synchronized (savedNewApps) { - SharedPreferences.Editor editor = sharedPrefs.edit(); - editor.putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, - savedNewApps); - if (savedNewApps.isEmpty()) { - // Reset the page index if there are no more items - editor.putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1); - } - editor.commit(); - } - } - }.start(); - } } } } diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index edf372144..90b54c679 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -3945,34 +3945,6 @@ public class Workspace extends SmoothPagedView // Strip all the empty screens stripEmptyScreens(); - - // Clean up new-apps animation list - final Context context = getContext(); - post(new Runnable() { - @Override - public void run() { - String spKey = LauncherAppState.getSharedPreferencesKey(); - SharedPreferences sp = context.getSharedPreferences(spKey, - Context.MODE_PRIVATE); - Set newApps = sp.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, - null); - - // Remove all queued items that match the same package - if (newApps != null) { - synchronized (newApps) { - Iterator iter = newApps.iterator(); - while (iter.hasNext()) { - try { - Intent intent = Intent.parseUri(iter.next(), 0); - if (componentNames.contains(intent.getComponent())) { - iter.remove(); - } - } catch (URISyntaxException e) {} - } - } - } - } - }); } void updateShortcuts(ArrayList apps) { -- cgit v1.2.3