diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2016-09-27 14:38:58 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2016-09-28 11:35:13 -0700 |
commit | fe770c9feb5f7fc05853f1d3a9eb2c825787b0a5 (patch) | |
tree | 7fbe08ffaee0e1d99e93508c04ecefc2e5a5157f /src/com/android | |
parent | e2b9696023f5d87e26d31640c0e7b02bd108191f (diff) | |
download | android_packages_apps_Trebuchet-fe770c9feb5f7fc05853f1d3a9eb2c825787b0a5.tar.gz android_packages_apps_Trebuchet-fe770c9feb5f7fc05853f1d3a9eb2c825787b0a5.tar.bz2 android_packages_apps_Trebuchet-fe770c9feb5f7fc05853f1d3a9eb2c825787b0a5.zip |
Cleaning up restore instance state logic
Restore instance state is only used for first binding. But in case of restore,
the binding happens synchronously, so there is not need to store the bundle
in a global variable
Change-Id: Ibc496bcd7c0d171056b8afc69f2c4d9a1270d40c
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 52 | ||||
-rw-r--r-- | src/com/android/launcher3/PagedView.java | 19 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 14 |
3 files changed, 19 insertions, 66 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index b18dee327..469e78e71 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -254,7 +254,6 @@ public class Launcher extends Activity @Thunk WidgetsContainerView mWidgetsView; @Thunk WidgetsModel mWidgetsModel; - private Bundle mSavedState; // We set the state in both onCreate and then onNewIntent in some cases, which causes both // scroll issues (because the workspace may not have been measured yet) and extra work. // Instead, just save the state that we need to restore Launcher to, and commit it in onResume. @@ -440,8 +439,7 @@ public class Launcher extends Activity lockAllApps(); - mSavedState = savedInstanceState; - restoreState(mSavedState); + restoreState(savedInstanceState); if (LauncherAppState.PROFILE_STARTUP) { Trace.endSection(); @@ -449,11 +447,18 @@ public class Launcher extends Activity // We only load the page synchronously if the user rotates (or triggers a // configuration change) while launcher is in the foreground - if (!mModel.startLoader(mWorkspace.getRestorePage())) { + int currentScreen = PagedView.INVALID_RESTORE_PAGE; + if (savedInstanceState != null) { + currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen); + } + if (!mModel.startLoader(currentScreen)) { // If we are not binding synchronously, show a fade in animation when // the first page bind completes. mDragLayer.setAlpha(0); } else { + // Pages bound synchronously. + mWorkspace.setCurrentPage(currentScreen); + setWorkspaceLoading(true); } @@ -594,7 +599,7 @@ public class Launcher extends Activity } /** - * Invoked by subclasses to signal a change to the {@link #addCustomContentToLeft} value to + * Invoked by subclasses to signal a change to the {@link #addToCustomContentPage} value to * ensure the custom content page is added or removed if necessary. */ protected void invalidateHasCustomContentToLeft() { @@ -1246,22 +1251,6 @@ public class Launcher extends Activity } /** - * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type - * State - */ - private static State intToState(int stateOrdinal) { - State state = State.WORKSPACE; - final State[] stateValues = State.values(); - for (int i = 0; i < stateValues.length; i++) { - if (stateValues[i].ordinal() == stateOrdinal) { - state = stateValues[i]; - break; - } - } - return state; - } - - /** * Restores the previous state, if it exists. * * @param savedState The previous state. @@ -1271,17 +1260,14 @@ public class Launcher extends Activity return; } - State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); + int stateOrdinal = savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()); + State[] stateValues = State.values(); + State state = (stateOrdinal >= 0 && stateOrdinal < stateValues.length) + ? stateValues[stateOrdinal] : State.WORKSPACE; if (state == State.APPS || state == State.WIDGETS) { mOnResumeState = state; } - int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, - PagedView.INVALID_RESTORE_PAGE); - if (currentScreen != PagedView.INVALID_RESTORE_PAGE) { - mWorkspace.setRestorePage(currentScreen); - } - PendingRequestArgs requestArgs = savedState.getParcelable(RUNTIME_STATE_PENDING_REQUEST_ARGS); if (requestArgs != null) { setWaitingForResult(requestArgs); @@ -2761,6 +2747,7 @@ public class Launcher extends Activity } } + @TargetApi(Build.VERSION_CODES.M) private Bundle getActivityLaunchOptions(View v) { if (Utilities.ATLEAST_MARSHMALLOW) { int left = 0, top = 0; @@ -3976,14 +3963,6 @@ public class Launcher extends Activity if (LauncherAppState.PROFILE_STARTUP) { Trace.beginSection("Page bind completed"); } - if (mSavedState != null) { - if (!mWorkspace.hasFocus()) { - mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); - } - - mSavedState = null; - } - mWorkspace.restoreInstanceStateForRemainingPages(); setWorkspaceLoading(false); @@ -4405,7 +4384,6 @@ public class Launcher extends Activity */ public void dumpState() { Log.d(TAG, "BEGIN launcher3 dump state for launcher " + this); - Log.d(TAG, "mSavedState=" + mSavedState); Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); Log.d(TAG, "mPendingRequestArgs=" + mPendingRequestArgs); Log.d(TAG, "mPendingActivityResult=" + mPendingActivityResult); diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index bea55d215..0b9bf09df 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -98,7 +98,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc @ViewDebug.ExportedProperty(category = "launcher") protected int mCurrentPage; - protected int mRestorePage = INVALID_RESTORE_PAGE; private int mChildCountOnLastLayout; @ViewDebug.ExportedProperty(category = "launcher") @@ -418,17 +417,6 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } /** - * The restore page will be set in place of the current page at the next (likely first) - * layout. - */ - void setRestorePage(int restorePage) { - mRestorePage = restorePage; - } - int getRestorePage() { - return mRestorePage; - } - - /** * Should be called whenever the page changes. In the case of a scroll, we wait until the page * has settled. */ @@ -879,12 +867,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc } if (mScroller.isFinished() && mChildCountOnLastLayout != childCount) { - if (mRestorePage != INVALID_RESTORE_PAGE) { - setCurrentPage(mRestorePage); - mRestorePage = INVALID_RESTORE_PAGE; - } else { - setCurrentPage(getNextPage()); - } + setCurrentPage(getNextPage()); } mChildCountOnLastLayout = childCount; diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 977395fc7..af4dc07e6 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -734,11 +734,7 @@ public class Workspace extends PagedView addFullScreenPage(customScreen); // Update the custom content hint - if (mRestorePage != INVALID_RESTORE_PAGE) { - mRestorePage = mRestorePage + 1; - } else { - setCurrentPage(getCurrentPage() + 1); - } + setCurrentPage(getCurrentPage() + 1); } public void removeCustomContentPage() { @@ -759,11 +755,7 @@ public class Workspace extends PagedView mCustomContentCallbacks = null; // Update the custom content hint - if (mRestorePage != INVALID_RESTORE_PAGE) { - mRestorePage = mRestorePage - 1; - } else { - setCurrentPage(getCurrentPage() - 1); - } + setCurrentPage(getCurrentPage() - 1); } public void addToCustomContentPage(View customContent, CustomContentCallbacks callbacks, @@ -1753,7 +1745,7 @@ public class Workspace extends PagedView } public boolean isOnOrMovingToCustomContent() { - return hasCustomContent() && getNextPage() == 0 && mRestorePage == INVALID_RESTORE_PAGE; + return hasCustomContent() && getNextPage() == 0; } private void updateStateForCustomContent(int screenCenter) { |