From 7607c2fb2729c7743022ff3fde9cfc75ae6f504f Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Wed, 3 Apr 2013 14:33:19 -0700 Subject: Fix occasional widget flashing Bug: 7619759 Change-Id: Ic07ddfcc3ee76862691f940ad018f2c271d3614a --- src/com/android/launcher2/Launcher.java | 99 ++++++++++++++++++++++++++++----- 1 file changed, 86 insertions(+), 13 deletions(-) (limited to 'src/com/android/launcher2') diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 9e651c60c..c3bec843e 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -250,6 +250,8 @@ public final class Launcher extends Activity private boolean mWaitingForResult; private boolean mOnResumeNeedsLoad; + private ArrayList mOnResumeCallbacks = new ArrayList(); + // Keep track of whether the user has left launcher private static boolean sPausedFromUserAction = false; @@ -741,6 +743,12 @@ public final class Launcher extends Activity mRestoring = false; mOnResumeNeedsLoad = false; } + // We might have postponed some bind calls until onResume (see waitUntilResume) -- + // execute them here + for (int i = 0; i < mOnResumeCallbacks.size(); i++) { + mOnResumeCallbacks.get(i).run(); + } + mOnResumeCallbacks.clear(); // Reset the pressed state of icons that were locked in the press state while activities // were launching @@ -3233,6 +3241,30 @@ public final class Launcher extends Activity } } + /** + * If the activity is currently paused, signal that we need to run the passed Runnable + * in onResume. + * + * This needs to be called from incoming places where resources might have been loaded + * while we are paused. That is becaues the Configuration might be wrong + * when we're not running, and if it comes back to what it was when we + * were paused, we are not restarted. + * + * Implementation of the method from LauncherModel.Callbacks. + * + * @return true if we are currently paused. The caller might be able to + * skip some work in that case since we will come back again. + */ + private boolean waitUntilResume(Runnable run) { + if (mPaused) { + Log.i(TAG, "Deferring update until onResume"); + mOnResumeCallbacks.add(run); + return true; + } else { + return false; + } + } + /** * If the activity is currently paused, signal that we need to re-run the loader * in onResume. @@ -3274,8 +3306,12 @@ public final class Launcher extends Activity * Implementation of the method from LauncherModel.Callbacks. */ public void startBinding() { - final Workspace workspace = mWorkspace; + // If we're starting binding all over again, clear any bind calls we'd postponed in + // the past (see waitUntilResume) -- we don't need them since we're starting binding + // from scratch again + mOnResumeCallbacks.clear(); + final Workspace workspace = mWorkspace; mNewShortcutAnimatePage = -1; mNewShortcutAnimateViews.clear(); mWorkspace.clearDropTargets(); @@ -3296,8 +3332,14 @@ public final class Launcher extends Activity * * Implementation of the method from LauncherModel.Callbacks. */ - public void bindItems(ArrayList shortcuts, int start, int end) { - setLoadOnResume(); + public void bindItems(final ArrayList shortcuts, final int start, final int end) { + if (waitUntilResume(new Runnable() { + public void run() { + bindItems(shortcuts, start, end); + } + })) { + return; + } // Get the list of added shortcuts and intersect them with the set of shortcuts here Set newApps = new HashSet(); @@ -3354,8 +3396,14 @@ public final class Launcher extends Activity /** * Implementation of the method from LauncherModel.Callbacks. */ - public void bindFolders(HashMap folders) { - setLoadOnResume(); + public void bindFolders(final HashMap folders) { + if (waitUntilResume(new Runnable() { + public void run() { + bindFolders(folders); + } + })) { + return; + } sFolders.clear(); sFolders.putAll(folders); } @@ -3365,8 +3413,14 @@ public final class Launcher extends Activity * * Implementation of the method from LauncherModel.Callbacks. */ - public void bindAppWidget(LauncherAppWidgetInfo item) { - setLoadOnResume(); + public void bindAppWidget(final LauncherAppWidgetInfo item) { + if (waitUntilResume(new Runnable() { + public void run() { + bindAppWidget(item); + } + })) { + return; + } final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; if (DEBUG_WIDGETS) { @@ -3407,8 +3461,13 @@ public final class Launcher extends Activity * Implementation of the method from LauncherModel.Callbacks. */ public void finishBindingItems() { - setLoadOnResume(); - + if (waitUntilResume(new Runnable() { + public void run() { + finishBindingItems(); + } + })) { + return; + } if (mSavedState != null) { if (!mWorkspace.hasFocus()) { mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); @@ -3574,8 +3633,15 @@ public final class Launcher extends Activity * * Implementation of the method from LauncherModel.Callbacks. */ - public void bindAppsAdded(ArrayList apps) { - setLoadOnResume(); + public void bindAppsAdded(final ArrayList apps) { + if (waitUntilResume(new Runnable() { + public void run() { + bindAppsAdded(apps); + } + })) { + return; + } + if (mAppsCustomizeContent != null) { mAppsCustomizeContent.addApps(apps); @@ -3587,8 +3653,15 @@ public final class Launcher extends Activity * * Implementation of the method from LauncherModel.Callbacks. */ - public void bindAppsUpdated(ArrayList apps) { - setLoadOnResume(); + public void bindAppsUpdated(final ArrayList apps) { + if (waitUntilResume(new Runnable() { + public void run() { + bindAppsUpdated(apps); + } + })) { + return; + } + if (mWorkspace != null) { mWorkspace.updateShortcuts(apps); } -- cgit v1.2.3