summaryrefslogtreecommitdiffstats
path: root/src/com/cyanogenmod/trebuchet/Launcher.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/cyanogenmod/trebuchet/Launcher.java')
-rw-r--r--src/com/cyanogenmod/trebuchet/Launcher.java122
1 files changed, 85 insertions, 37 deletions
diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java
index a2e73f03d..f32b11cf0 100644
--- a/src/com/cyanogenmod/trebuchet/Launcher.java
+++ b/src/com/cyanogenmod/trebuchet/Launcher.java
@@ -185,7 +185,7 @@ public final class Launcher extends Activity
"com.android.launcher.toolbar_voice_search_icon";
/** The different states that Launcher can be in. */
- private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
+ private enum State { NONE, WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED };
private State mState = State.WORKSPACE;
private AnimatorSet mStateAnimation;
private AnimatorSet mDividerAnimator;
@@ -233,6 +233,10 @@ public final class Launcher extends Activity
private boolean mAutoAdvanceRunning = false;
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.
+ private State mOnResumeState = State.NONE;
private SpannableStringBuilder mDefaultKeySsb = null;
@@ -243,6 +247,9 @@ public final class Launcher extends Activity
private boolean mWaitingForResult;
private boolean mOnResumeNeedsLoad;
+ // Keep track of whether the user has left launcher
+ private static boolean sPausedFromUserAction = false;
+
private Bundle mSavedInstanceState;
private LauncherModel mModel;
@@ -275,6 +282,8 @@ public final class Launcher extends Activity
private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2];
private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2];
+ private final ArrayList<Integer> mSynchronouslyBoundPages = new ArrayList<Integer>();
+
static final ArrayList<String> sDumpLogs = new ArrayList<String>();
// We only want to get the SharedPreferences once since it does an FS stat each time we get
@@ -354,6 +363,11 @@ public final class Launcher extends Activity
mHideIconLabels = PreferencesProvider.Interface.Homescreen.getHideIconLabels(this);
mAutoRotate = PreferencesProvider.Interface.General.getAutoRotate(this, getResources().getBoolean(R.bool.allow_rotation));
+ // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
+ // this also ensures that any synchronous binding below doesn't re-trigger another
+ // LauncherModel load.
+ mPaused = false;
+
if (PROFILE_STARTUP) {
android.os.Debug.startMethodTracing(
Environment.getExternalStorageDirectory() + "/launcher");
@@ -373,7 +387,7 @@ public final class Launcher extends Activity
// Update customization drawer _after_ restoring the states
if (mAppsCustomizeContent != null) {
- mAppsCustomizeContent.onPackagesUpdated();
+ mAppsCustomizeContent.onPackagesUpdated(true);
}
if (PROFILE_STARTUP) {
@@ -381,7 +395,15 @@ public final class Launcher extends Activity
}
if (!mRestoring) {
- mModel.startLoader(true);
+ if (sPausedFromUserAction) {
+ // If the user leaves launcher, then we should just load items asynchronously when
+ // they return.
+ mModel.startLoader(true, -1);
+ } 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());
+ }
}
if (!mModel.isAllAppsLoaded()) {
@@ -402,6 +424,11 @@ public final class Launcher extends Activity
unlockScreenOrientation(true);
}
+ protected void onUserLeaveHint() {
+ super.onUserLeaveHint();
+ sPausedFromUserAction = true;
+ }
+
private void updateGlobalIcons() {
boolean searchVisible = false;
boolean voiceVisible = false;
@@ -687,6 +714,14 @@ public final class Launcher extends Activity
protected void onResume() {
super.onResume();
+ // Restore the previous launcher state
+ if (mOnResumeState == State.WORKSPACE) {
+ showWorkspace(false);
+ } else if (mOnResumeState == State.APPS_CUSTOMIZE) {
+ showAllApps(false);
+ }
+ mOnResumeState = State.NONE;
+
// Process any items that were added while Launcher was away
InstallShortcutReceiver.flushInstallQueue(this);
@@ -695,9 +730,11 @@ public final class Launcher extends Activity
if (preferencesChanged()) {
android.os.Process.killProcess(android.os.Process.myPid());
}
+
+ sPausedFromUserAction = false;
if (mRestoring || mOnResumeNeedsLoad) {
mWorkspaceLoading = true;
- mModel.startLoader(true);
+ mModel.startLoader(true, -1);
mRestoring = false;
mOnResumeNeedsLoad = false;
}
@@ -838,7 +875,7 @@ public final class Launcher extends Activity
State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal()));
if (state == State.APPS_CUSTOMIZE) {
- showAllApps(false);
+ mOnResumeState = State.APPS_CUSTOMIZE;
}
int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
@@ -874,10 +911,8 @@ public final class Launcher extends Activity
if (mAppsCustomizeTabHost != null) {
String curTab = savedState.getString("apps_customize_currentTab");
if (curTab != null) {
- // We set this directly so that there is no delay before the tab is set
- mAppsCustomizeContent.setContentType(
+ mAppsCustomizeTabHost.setContentTypeImmediate(
mAppsCustomizeTabHost.getContentTypeForTabTag(curTab));
- mAppsCustomizeTabHost.setCurrentTabByTag(curTab);
mAppsCustomizeContent.loadAssociatedPages(
mAppsCustomizeContent.getCurrentPage());
}
@@ -1387,7 +1422,14 @@ public final class Launcher extends Activity
closeFolder();
exitSpringLoadedDragMode();
- showWorkspace(alreadyOnHome);
+
+ // If we are already on home, then just animate back to the workspace, otherwise, just
+ // wait until onResume to set the state back to Workspace
+ if (alreadyOnHome) {
+ showWorkspace(true);
+ } else {
+ mOnResumeState = State.WORKSPACE;
+ }
final View v = getWindow().peekDecorView();
if (v != null && v.getWindowToken() != null) {
@@ -1404,14 +1446,16 @@ public final class Launcher extends Activity
}
@Override
- protected void onRestoreInstanceState(Bundle savedInstanceState) {
- // Do not call super here
- mSavedInstanceState = savedInstanceState;
+ public void onRestoreInstanceState(Bundle state) {
+ super.onRestoreInstanceState(state);
+ for (int page: mSynchronouslyBoundPages) {
+ mWorkspace.restoreInstanceStateForChild(page);
+ }
}
@Override
protected void onSaveInstanceState(Bundle outState) {
- outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage());
+ outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getNextPage());
super.onSaveInstanceState(outState);
outState.putInt(RUNTIME_STATE, mState.ordinal());
@@ -1807,7 +1851,7 @@ public final class Launcher extends Activity
@Override
public void onBackPressed() {
- if (mState == State.APPS_CUSTOMIZE) {
+ if (isAllAppsVisible()) {
showWorkspace(true);
} else if (mWorkspace.getOpenFolder() != null) {
Folder openFolder = mWorkspace.getOpenFolder();
@@ -1880,7 +1924,7 @@ public final class Launcher extends Activity
handleFolderClick(fi);
}
} else if (v == mAllAppsButton) {
- if (mState == State.APPS_CUSTOMIZE) {
+ if (isAllAppsVisible()) {
showWorkspace(true);
} else {
onClickAllAppsButton(v);
@@ -2331,7 +2375,7 @@ public final class Launcher extends Activity
// Now a part of LauncherModel.Callbacks. Used to reorder loading steps.
public boolean isAllAppsVisible() {
- return (mState == State.APPS_CUSTOMIZE);
+ return (mState == State.APPS_CUSTOMIZE) || (mOnResumeState == State.APPS_CUSTOMIZE);
}
public boolean isAllAppsButtonRank(int rank) {
@@ -2358,7 +2402,7 @@ public final class Launcher extends Activity
void disableWallpaperIfInAllApps() {
// Only disable it if we are in all apps
- if (mState == State.APPS_CUSTOMIZE) {
+ if (isAllAppsVisible()) {
if (mAppsCustomizeTabHost != null &&
!mAppsCustomizeTabHost.isTransitioning()) {
updateWallpaperVisibility(false);
@@ -2799,7 +2843,7 @@ public final class Launcher extends Activity
}
void enterSpringLoadedDragMode() {
- if (mState == State.APPS_CUSTOMIZE) {
+ if (isAllAppsVisible()) {
hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null);
hideDockDivider();
mState = State.APPS_CUSTOMIZE_SPRING_LOADED;
@@ -2883,10 +2927,6 @@ public final class Launcher extends Activity
// TODO
}
- public boolean isAllAppsCustomizeOpen() {
- return mState == State.APPS_CUSTOMIZE;
- }
-
/**
* Shows the hotseat area.
*/
@@ -3381,6 +3421,10 @@ public final class Launcher extends Activity
}
}
+ public void onPageBoundSynchronously(int page) {
+ mSynchronouslyBoundPages.add(page);
+ }
+
/**
* Callback saying that there aren't any more items to bind.
*
@@ -3396,10 +3440,7 @@ public final class Launcher extends Activity
mSavedState = null;
}
- if (mSavedInstanceState != null) {
- super.onRestoreInstanceState(mSavedInstanceState);
- mSavedInstanceState = null;
- }
+ mWorkspace.restoreInstanceStateForRemainingPages();
// If we received the result of any pending adds while the loader was running (e.g. the
// widget configuration forced an orientation change), process them now.
@@ -3522,23 +3563,30 @@ public final class Launcher extends Activity
* Implementation of the method from LauncherModel.Callbacks.
*/
public void bindAllApplications(final ArrayList<ApplicationInfo> apps) {
+ Runnable setAllAppsRunnable = new Runnable() {
+ public void run() {
+ if (mAppsCustomizeContent != null) {
+ mAppsCustomizeContent.setApps(apps);
+ }
+ }
+ };
+
// Remove the progress bar entirely; we could also make it GONE
// but better to remove it since we know it's not going to be used
View progressBar = mAppsCustomizeTabHost.
findViewById(R.id.apps_customize_progress_bar);
if (progressBar != null) {
((ViewGroup)progressBar.getParent()).removeView(progressBar);
+
+ // We just post the call to setApps so the user sees the progress bar
+ // disappear-- otherwise, it just looks like the progress bar froze
+ // which doesn't look great
+ mAppsCustomizeTabHost.post(setAllAppsRunnable);
+ } else {
+ // If we did not initialize the spinner in onCreate, then we can directly set the
+ // list of applications without waiting for any progress bars views to be hidden.
+ setAllAppsRunnable.run();
}
- // We just post the call to setApps so the user sees the progress bar
- // disappear-- otherwise, it just looks like the progress bar froze
- // which doesn't look great
- mAppsCustomizeTabHost.post(new Runnable() {
- public void run() {
- if (mAppsCustomizeContent != null) {
- mAppsCustomizeContent.setApps(apps);
- }
- }
- });
}
/**
@@ -3593,7 +3641,7 @@ public final class Launcher extends Activity
*/
public void bindPackagesUpdated() {
if (mAppsCustomizeContent != null) {
- mAppsCustomizeContent.onPackagesUpdated();
+ mAppsCustomizeContent.onPackagesUpdated(false);
}
}