summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Cohen <adamcohen@google.com>2013-10-02 17:41:50 -0700
committerAdam Cohen <adamcohen@google.com>2013-10-02 17:58:53 -0700
commit6fecd410e8567af916b1bbd53198d9878c686177 (patch)
tree12730447c90c8b5f6e68ef2f98b44d6fb14aa762
parentd3f333b995c038c5171478ef56dc6c1c6e780b39 (diff)
downloadandroid_packages_apps_Trebuchet-6fecd410e8567af916b1bbd53198d9878c686177.tar.gz
android_packages_apps_Trebuchet-6fecd410e8567af916b1bbd53198d9878c686177.tar.bz2
android_packages_apps_Trebuchet-6fecd410e8567af916b1bbd53198d9878c686177.zip
Trying to come up with a simpler approach for onShow/onHide.
-> In this approach, the shown/hidden state should be tracked by the CustomContent provider and excess calls to onShow and onHide should be debounced. That is, if onShow is called twice in a row, without an intermediate onHide, the second should be discarded. Viceversa for onHide. Change-Id: I2fa48d15f28767775a9a9cb84c1d920867a12176
-rw-r--r--src/com/android/launcher3/Launcher.java88
-rw-r--r--src/com/android/launcher3/Workspace.java11
2 files changed, 49 insertions, 50 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index f1d4c1d9b..5e10e8b78 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -911,6 +911,16 @@ public class Launcher extends Activity
if (DEBUG_RESUME_TIME) {
Log.d(TAG, "Time spent in onResume: " + (System.currentTimeMillis() - startTime));
}
+
+ if (mWorkspace.getCustomContentCallbacks() != null) {
+ // 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
+ // if PagedView#setRestorePage was set to the custom content page in onCreate().
+ if (mWorkspace.isOnOrMovingToCustomContent()) {
+ mWorkspace.getCustomContentCallbacks().onShow();
+ }
+ }
+
mWorkspace.updateInteractionForState();
}
@@ -923,6 +933,12 @@ public class Launcher extends Activity
mPaused = true;
mDragController.cancelDrag();
mDragController.resetLastGestureUpTime();
+
+ // We call onHide() aggressively. The custom content callbacks should be able to
+ // debounce excess onHide calls.
+ if (mWorkspace.getCustomContentCallbacks() != null) {
+ mWorkspace.getCustomContentCallbacks().onHide();
+ }
}
protected void onFinishBindingItems() {
@@ -1659,54 +1675,40 @@ public class Launcher extends Activity
((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
!= Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
- Runnable processIntent = new Runnable() {
- public void run() {
- if (mWorkspace == null) {
- // Can be cases where mWorkspace is null, this prevents a NPE
- return;
- }
- Folder openFolder = mWorkspace.getOpenFolder();
- // In all these cases, only animate if we're already on home
- mWorkspace.exitWidgetResizeMode();
- if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
- openFolder == null) {
- mWorkspace.moveToDefaultScreen(true);
- }
-
- closeFolder();
- exitSpringLoadedDragMode();
-
- // 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) {
- showWorkspaceAndExitOverviewMode(true);
- } else {
- mOnResumeState = State.WORKSPACE;
- }
-
- final View v = getWindow().peekDecorView();
- if (v != null && v.getWindowToken() != null) {
- InputMethodManager imm = (InputMethodManager)getSystemService(
- INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
- }
+ if (mWorkspace == null) {
+ // Can be cases where mWorkspace is null, this prevents a NPE
+ return;
+ }
+ Folder openFolder = mWorkspace.getOpenFolder();
+ // In all these cases, only animate if we're already on home
+ mWorkspace.exitWidgetResizeMode();
+ if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() &&
+ openFolder == null) {
+ mWorkspace.moveToDefaultScreen(true);
+ }
- // Reset the apps customize page
- if (mAppsCustomizeTabHost != null) {
- mAppsCustomizeTabHost.reset();
- }
- }
- };
+ closeFolder();
+ exitSpringLoadedDragMode();
- if (alreadyOnHome && !mWorkspace.hasWindowFocus()) {
- // Delay processing of the intent to allow the status bar animation to finish
- // first in order to avoid janky animations.
- mWorkspace.postDelayed(processIntent, 350);
+ // 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) {
+ showWorkspaceAndExitOverviewMode(true);
} else {
- // Process the intent immediately.
- processIntent.run();
+ mOnResumeState = State.WORKSPACE;
}
+ final View v = getWindow().peekDecorView();
+ if (v != null && v.getWindowToken() != null) {
+ InputMethodManager imm = (InputMethodManager)getSystemService(
+ INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
+ }
+
+ // Reset the apps customize page
+ if (mAppsCustomizeTabHost != null) {
+ mAppsCustomizeTabHost.reset();
+ }
}
if (DEBUG_RESUME_TIME) {
Log.d(TAG, "Time spent in onNewIntent: " + (System.currentTimeMillis() - startTime));
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 2b7a737a2..5a40d444e 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -853,13 +853,6 @@ public class Workspace extends SmoothPagedView
protected void onWindowVisibilityChanged (int visibility) {
mLauncher.onWindowVisibilityChanged(visibility);
- if (mCustomContentShowing && mCustomContentCallbacks != null) {
- if (visibility == View.VISIBLE) {
- mCustomContentCallbacks.onShow();
- } else if (visibility == View.GONE) {
- mCustomContentCallbacks.onHide();
- }
- }
}
@Override
@@ -1048,6 +1041,10 @@ public class Workspace extends SmoothPagedView
}
}
+ protected CustomContentCallbacks getCustomContentCallbacks() {
+ return mCustomContentCallbacks;
+ }
+
protected void setWallpaperDimension() {
String spKey = WallpaperCropActivity.getSharedPreferencesKey();
SharedPreferences sp = mLauncher.getSharedPreferences(spKey, Context.MODE_PRIVATE);