From 9b9fb967b2305413520dc676d6d3c472b2b6b25e Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Fri, 15 Nov 2013 15:39:34 -0800 Subject: [PATCH 1/2] Updating LauncherModel filtering to use screen ids. (Bug 11685286) - Fixes the issue with the current page not synchronously binding Change-Id: I3dfa45cc1777f846c77f3e86059dfb715553e1a3 --- src/com/android/launcher3/Launcher.java | 5 +- src/com/android/launcher3/LauncherModel.java | 53 +++++++++++--------- src/com/android/launcher3/PagedView.java | 3 ++ 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 89abd9f2a0..7d84a3c88f 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -459,7 +459,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()); } } @@ -1801,7 +1801,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 5a3b1b80fb..c3d4666447 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -2026,7 +2026,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 allWorkspaceItems, ArrayList currentScreenItems, ArrayList otherScreenItems) { @@ -2041,8 +2041,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 @@ -2057,7 +2057,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 { @@ -2078,20 +2078,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 appWidgets, ArrayList currentScreenWidgets, ArrayList 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); @@ -2100,15 +2100,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 itemsIdMap, HashMap folders, HashMap currentScreenFolders, HashMap 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()) { @@ -2116,7 +2116,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); @@ -2243,13 +2243,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 workspaceItems = new ArrayList(); ArrayList appWidgets = new ArrayList(); @@ -2264,6 +2258,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 currentWorkspaceItems = new ArrayList(); ArrayList otherWorkspaceItems = new ArrayList(); ArrayList currentAppWidgets = @@ -2273,12 +2281,11 @@ public class LauncherModel extends BroadcastReceiver { HashMap currentFolders = new HashMap(); HashMap otherFolders = new HashMap(); - // 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 3eecedbccf..e095c15d2b 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -564,6 +564,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 9b17fcd9e7..08a6e436a2 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -3956,7 +3956,7 @@ public class Workspace extends SmoothPagedView return mDragInfo; } - public int getRestorePage() { + public int getCurrentPageOffsetFromCustomContent() { return getNextPage() - numCustomPages(); } From 268f1c563f4179ee2fb6c87b662679451e23a7c8 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Mon, 18 Nov 2013 14:04:41 -0800 Subject: [PATCH 2/2] Initialize FastBitmapDrawable bounds with default bitmap dimensions. Change-Id: Ida9603e35b242a581b9401c6440875cd511725a1 --- src/com/android/launcher3/FastBitmapDrawable.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/android/launcher3/FastBitmapDrawable.java b/src/com/android/launcher3/FastBitmapDrawable.java index 83be143695..85e90202b3 100644 --- a/src/com/android/launcher3/FastBitmapDrawable.java +++ b/src/com/android/launcher3/FastBitmapDrawable.java @@ -32,6 +32,7 @@ class FastBitmapDrawable extends Drawable { FastBitmapDrawable(Bitmap b) { mAlpha = 255; mBitmap = b; + setBounds(0, 0, b.getWidth(), b.getHeight()); } @Override