summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/LauncherModel.java
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2013-08-02 21:54:25 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-08-02 21:54:25 +0000
commit3dba179949b4c1ce6d91c8eb847a91d9f2c56282 (patch)
treeb9fc8a6929936ac49f764048c823037b678f6292 /src/com/android/launcher3/LauncherModel.java
parent114cbcebbc9726782763d5823e78fccbdd7bceb7 (diff)
parent997a92348a6d6e061737399321393449c16cd4d8 (diff)
downloadandroid_packages_apps_Trebuchet-3dba179949b4c1ce6d91c8eb847a91d9f2c56282.tar.gz
android_packages_apps_Trebuchet-3dba179949b4c1ce6d91c8eb847a91d9f2c56282.tar.bz2
android_packages_apps_Trebuchet-3dba179949b4c1ce6d91c8eb847a91d9f2c56282.zip
Merge "Removing old new-app animation code, and refactoring InstallShortcutReceiver to use new add/bind logic." into jb-ub-gel-agar
Diffstat (limited to 'src/com/android/launcher3/LauncherModel.java')
-rw-r--r--src/com/android/launcher3/LauncherModel.java67
1 files changed, 52 insertions, 15 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index b231e3a95..63089870a 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -268,8 +268,15 @@ public class LauncherModel extends BroadcastReceiver {
return null;
}
- public void addAndBindAddedApps(final Context context, final ArrayList<ApplicationInfo> added,
+ public void addAndBindAddedApps(final Context context, final ArrayList<ItemInfo> added) {
+ Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
+ addAndBindAddedApps(context, added, cb);
+ }
+ public void addAndBindAddedApps(final Context context, final ArrayList<ItemInfo> 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() {
@@ -277,11 +284,11 @@ public class LauncherModel extends BroadcastReceiver {
final ArrayList<Long> addedWorkspaceScreensFinal = new ArrayList<Long>();
synchronized(sBgLock) {
- Iterator<ApplicationInfo> iter = added.iterator();
+ Iterator<ItemInfo> 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)) {
@@ -319,7 +326,14 @@ public class LauncherModel extends BroadcastReceiver {
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,
@@ -329,16 +343,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<ItemInfo> addAnimated = new ArrayList<ItemInfo>();
+ final ArrayList<ItemInfo> addNotAnimated = new ArrayList<ItemInfo>();
+ 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);
@@ -2402,8 +2438,9 @@ public class LauncherModel extends BroadcastReceiver {
if (added != null) {
// Ensure that we add all the workspace applications to the db
+ final ArrayList<ItemInfo> addedInfos = new ArrayList<ItemInfo>(added);
Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
- addAndBindAddedApps(context, added, cb);
+ addAndBindAddedApps(context, addedInfos, cb);
}
if (modified != null) {
final ArrayList<ApplicationInfo> modifiedFinal = modified;