diff options
author | Winson Chung <winsonc@google.com> | 2013-11-15 15:39:34 -0800 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2014-06-06 22:54:19 -0700 |
commit | a2f35d358f12a4714f2fb4b07356456225837e40 (patch) | |
tree | 3d2190cd04251d4a6a81d6039e5e33151dbb3ebe /src | |
parent | 78fde7064f537296a2ea7780082504c137ea0155 (diff) | |
download | android_packages_apps_Trebuchet-a2f35d358f12a4714f2fb4b07356456225837e40.tar.gz android_packages_apps_Trebuchet-a2f35d358f12a4714f2fb4b07356456225837e40.tar.bz2 android_packages_apps_Trebuchet-a2f35d358f12a4714f2fb4b07356456225837e40.zip |
Updating LauncherModel filtering to use screen ids. (Bug 11685286)
- Fixes the issue with the current page not synchronously binding
Change-Id: I3dfa45cc1777f846c77f3e86059dfb715553e1a3
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 5 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherModel.java | 53 | ||||
-rw-r--r-- | src/com/android/launcher3/PagedView.java | 3 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 2 |
4 files changed, 37 insertions, 26 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 4d478ed59..57f7d5501 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -474,7 +474,7 @@ public class Launcher extends Activity } else { // We only load the page synchronously if the user rotates (or triggers a // configuration change) while launcher is in the foreground - mModel.startLoader(true, mWorkspace.getCurrentPage()); + mModel.startLoader(true, mWorkspace.getRestorePage()); } } @@ -1979,7 +1979,8 @@ public class Launcher extends Activity @Override protected void onSaveInstanceState(Bundle outState) { if (mWorkspace.getChildCount() > 0) { - outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getRestorePage()); + outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, + mWorkspace.getCurrentPageOffsetFromCustomContent()); } super.onSaveInstanceState(outState); diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 65dcc0743..69c90369e 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -2110,7 +2110,7 @@ public class LauncherModel extends BroadcastReceiver { /** Filters the set of items who are directly or indirectly (via another container) on the * specified screen. */ - private void filterCurrentWorkspaceItems(int currentScreen, + private void filterCurrentWorkspaceItems(long currentScreenId, ArrayList<ItemInfo> allWorkspaceItems, ArrayList<ItemInfo> currentScreenItems, ArrayList<ItemInfo> otherScreenItems) { @@ -2125,8 +2125,8 @@ public class LauncherModel extends BroadcastReceiver { // If we aren't filtering on a screen, then the set of items to load is the full set of // items given. - if (currentScreen < 0) { - currentScreenItems.addAll(allWorkspaceItems); + if (currentScreenId < 0) { + throw new RuntimeException("Unexpected screen id"); } // Order the set of items by their containers first, this allows use to walk through the @@ -2141,7 +2141,7 @@ public class LauncherModel extends BroadcastReceiver { }); for (ItemInfo info : allWorkspaceItems) { if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { - if (info.screenId == currentScreen) { + if (info.screenId == currentScreenId) { currentScreenItems.add(info); itemsOnScreen.add(info.id); } else { @@ -2162,20 +2162,20 @@ public class LauncherModel extends BroadcastReceiver { } /** Filters the set of widgets which are on the specified screen. */ - private void filterCurrentAppWidgets(int currentScreen, + private void filterCurrentAppWidgets(long currentScreenId, ArrayList<LauncherAppWidgetInfo> appWidgets, ArrayList<LauncherAppWidgetInfo> currentScreenWidgets, ArrayList<LauncherAppWidgetInfo> otherScreenWidgets) { // If we aren't filtering on a screen, then the set of items to load is the full set of // widgets given. - if (currentScreen < 0) { - currentScreenWidgets.addAll(appWidgets); + if (currentScreenId < 0) { + throw new RuntimeException("Unexpected screen id"); } for (LauncherAppWidgetInfo widget : appWidgets) { if (widget == null) continue; if (widget.container == LauncherSettings.Favorites.CONTAINER_DESKTOP && - widget.screenId == currentScreen) { + widget.screenId == currentScreenId) { currentScreenWidgets.add(widget); } else { otherScreenWidgets.add(widget); @@ -2184,15 +2184,15 @@ public class LauncherModel extends BroadcastReceiver { } /** Filters the set of folders which are on the specified screen. */ - private void filterCurrentFolders(int currentScreen, + private void filterCurrentFolders(long currentScreenId, HashMap<Long, ItemInfo> itemsIdMap, HashMap<Long, FolderInfo> folders, HashMap<Long, FolderInfo> currentScreenFolders, HashMap<Long, FolderInfo> otherScreenFolders) { // If we aren't filtering on a screen, then the set of items to load is the full set of // widgets given. - if (currentScreen < 0) { - currentScreenFolders.putAll(folders); + if (currentScreenId < 0) { + throw new RuntimeException("Unexpected screen id"); } for (long id : folders.keySet()) { @@ -2200,7 +2200,7 @@ public class LauncherModel extends BroadcastReceiver { FolderInfo folder = folders.get(id); if (info == null || folder == null) continue; if (info.container == LauncherSettings.Favorites.CONTAINER_DESKTOP && - info.screenId == currentScreen) { + info.screenId == currentScreenId) { currentScreenFolders.put(id, folder); } else { otherScreenFolders.put(id, folder); @@ -2415,13 +2415,7 @@ public class LauncherModel extends BroadcastReceiver { return; } - final boolean isLoadingSynchronously = (synchronizeBindPage > -1); - final int currentScreen = isLoadingSynchronously ? synchronizeBindPage : - oldCallbacks.getCurrentWorkspaceScreen(); - - // Load all the items that are on the current page first (and in the process, unbind - // all the existing workspace items before we call startBinding() below. - unbindWorkspaceItemsOnMainThread(); + // Save a copy of all the bg-thread collections ArrayList<ItemInfo> workspaceItems = new ArrayList<ItemInfo>(); ArrayList<LauncherAppWidgetInfo> appWidgets = new ArrayList<LauncherAppWidgetInfo>(); @@ -2436,6 +2430,20 @@ public class LauncherModel extends BroadcastReceiver { orderedScreenIds.addAll(sBgWorkspaceScreens); } + final boolean isLoadingSynchronously = (synchronizeBindPage > -1); + final int currentScreen = isLoadingSynchronously ? synchronizeBindPage : + oldCallbacks.getCurrentWorkspaceScreen(); + if (currentScreen >= orderedScreenIds.size()) { + Log.w(TAG, "Invalid screen id to synchronously load"); + return; + } + final long currentScreenId = orderedScreenIds.get(currentScreen); + + // Load all the items that are on the current page first (and in the process, unbind + // all the existing workspace items before we call startBinding() below. + unbindWorkspaceItemsOnMainThread(); + + // Separate the items that are on the current screen, and all the other remaining items ArrayList<ItemInfo> currentWorkspaceItems = new ArrayList<ItemInfo>(); ArrayList<ItemInfo> otherWorkspaceItems = new ArrayList<ItemInfo>(); ArrayList<LauncherAppWidgetInfo> currentAppWidgets = @@ -2445,12 +2453,11 @@ public class LauncherModel extends BroadcastReceiver { HashMap<Long, FolderInfo> currentFolders = new HashMap<Long, FolderInfo>(); HashMap<Long, FolderInfo> otherFolders = new HashMap<Long, FolderInfo>(); - // Separate the items that are on the current screen, and all the other remaining items - filterCurrentWorkspaceItems(currentScreen, workspaceItems, currentWorkspaceItems, + filterCurrentWorkspaceItems(currentScreenId, workspaceItems, currentWorkspaceItems, otherWorkspaceItems); - filterCurrentAppWidgets(currentScreen, appWidgets, currentAppWidgets, + filterCurrentAppWidgets(currentScreenId, appWidgets, currentAppWidgets, otherAppWidgets); - filterCurrentFolders(currentScreen, itemsIdMap, folders, currentFolders, + filterCurrentFolders(currentScreenId, itemsIdMap, folders, currentFolders, otherFolders); sortWorkspaceItemsSpatially(currentWorkspaceItems); sortWorkspaceItemsSpatially(otherWorkspaceItems); diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index b1b3a9328..76d54fc08 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -573,6 +573,9 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc void setRestorePage(int restorePage) { mRestorePage = restorePage; } + int getRestorePage() { + return mRestorePage; + } protected void notifyPageSwitchListener() { if (mPageSwitchListener != null) { diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index a24c94b8c..eeb49f8e0 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -4103,7 +4103,7 @@ public class Workspace extends SmoothPagedView return mDragInfo; } - public int getRestorePage() { + public int getCurrentPageOffsetFromCustomContent() { return getNextPage() - numCustomPages() - (hasExtraEmptyScreenLeft() ? 1 : 0); } |