From 4b66bf3cff049ba39da74c0fb0f9edbced410f7c Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Fri, 18 Sep 2015 12:15:19 -0700 Subject: [PATCH] Cleanup some incorrect / noisey calls to CustomContentCallbacks#onShow / onHide -> In some instances, onResume would incorrectly call onShow -> When pressing Home from CustomContent, we'd get a sequence of onHide, onShow, and then onHide due to some deferred actions in onNewIntent. Got rid of the onShow. issue 17629011 Change-Id: I9b4f2ef682f5a7060e68210866fa05452076e428 --- src/com/android/launcher3/Launcher.java | 17 +++++++++++++++-- src/com/android/launcher3/Workspace.java | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 1f843cb702..37e4076448 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -345,6 +345,8 @@ public class Launcher extends Activity private DeviceProfile mDeviceProfile; + private boolean mMoveToDefaultScreenFromNewIntent; + // This is set to the view that launched the activity that navigated the user away from // launcher. Since there is no callback for when the activity has finished launching, enable // the press state and keep this reference to reset the press state when we return to launcher. @@ -1048,14 +1050,21 @@ public class Launcher extends Activity Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime)); } - if (mWorkspace.getCustomContentCallbacks() != null) { + // We want to suppress callbacks about CustomContent being shown if we have just received + // onNewIntent while the user was present within launcher. In that case, we post a call + // to move the user to the main screen (which will occur after onResume). We don't want to + // have onHide (from onPause), then onShow, then onHide again, which we get if we don't + // suppress here. + if (mWorkspace.getCustomContentCallbacks() != null + && !mMoveToDefaultScreenFromNewIntent) { // If we are resuming and the custom content is the current page, we call onShow(). - // It is also poassible that onShow will instead be called slightly after first layout + // It is also possible that onShow will instead be called slightly after first layout // if PagedView#setRestorePage was set to the custom content page in onCreate(). if (mWorkspace.isOnOrMovingToCustomContent()) { mWorkspace.getCustomContentCallbacks().onShow(true); } } + mMoveToDefaultScreenFromNewIntent = false; updateInteraction(Workspace.State.NORMAL, mWorkspace.getState()); mWorkspace.onResume(); @@ -1922,6 +1931,10 @@ public class Launcher extends Activity mLauncherCallbacks.shouldMoveToDefaultScreenOnHomeIntent() : true; if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && openFolder == null && moveToDefaultScreen) { + + // We use this flag to suppress noisy callbacks above custom content state + // from onResume. + mMoveToDefaultScreenFromNewIntent = true; mWorkspace.post(new Runnable() { @Override public void run() { diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 856e3b88ad..be9f3f2ad1 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1606,7 +1606,7 @@ public class Workspace extends PagedView } public boolean isOnOrMovingToCustomContent() { - return hasCustomContent() && getNextPage() == 0; + return hasCustomContent() && getNextPage() == 0 && mRestorePage == INVALID_RESTORE_PAGE; } private void updateStateForCustomContent(int screenCenter) {