From 500ba75c9a53786ce3f60a9cd985b6cc29eb665d Mon Sep 17 00:00:00 2001 From: Winson Date: Wed, 30 Mar 2016 11:59:22 -0700 Subject: [PATCH] Disabling the nav bar scrim when Recents is docked. Bug: 27869246 Change-Id: I554b299c7e577f40811fc02d6ff4a46313ff1622 --- .../systemui/recents/RecentsActivity.java | 56 +++++------- .../activity/ConfigurationChangedEvent.java | 5 +- .../MultiWindowStateChangedEvent.java | 4 +- .../recents/views/SystemBarScrimViews.java | 87 +++++++++++++++---- .../views/TaskStackLayoutAlgorithm.java | 2 + 5 files changed, 102 insertions(+), 52 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java index fff7d78d0078a..8060e07801bbd 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java @@ -344,7 +344,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD // Update the nav bar scrim, but defer the animation until the enter-window event boolean animateNavBarScrim = !launchState.launchedViaDockGesture; - updateNavBarScrim(animateNavBarScrim, null); + mScrimViews.updateNavBarScrim(animateNavBarScrim, stack.getTaskCount() > 0, null); // If this is a new instance relaunched by AM, without going through the normal mechanisms, // then we have to manually trigger the enter animation state @@ -417,39 +417,43 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - // Update the nav bar for the current orientation - updateNavBarScrim(false /* animateNavBarScrim */, AnimationProps.IMMEDIATE); // Notify of the config change int newOrientation = getResources().getConfiguration().orientation; + int numStackTasks = mRecentsView.getStack().getStackTaskCount(); EventBus.getDefault().send(new ConfigurationChangedEvent(false /* fromMultiWindow */, - (mLastOrientation != newOrientation))); + (mLastOrientation != newOrientation), numStackTasks > 0)); mLastOrientation = newOrientation; } @Override public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { super.onMultiWindowModeChanged(isInMultiWindowMode); + + // Reload the task stack completely + RecentsConfiguration config = Recents.getConfiguration(); + RecentsActivityLaunchState launchState = config.getLaunchState(); + RecentsTaskLoader loader = Recents.getTaskLoader(); + RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(this); + loader.preloadTasks(loadPlan, -1 /* topTaskId */, false /* isTopTaskHome */); + + RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options(); + loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks; + loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails; + loader.loadTasks(this, loadPlan, loadOpts); + + TaskStack stack = loadPlan.getTaskStack(); + int numStackTasks = stack.getStackTaskCount(); + EventBus.getDefault().send(new ConfigurationChangedEvent(true /* fromMultiWindow */, - false /* fromOrientationChange */)); + false /* fromOrientationChange */, numStackTasks > 0)); if (mRecentsView != null) { - // Reload the task stack completely - RecentsConfiguration config = Recents.getConfiguration(); - RecentsActivityLaunchState launchState = config.getLaunchState(); - RecentsTaskLoader loader = Recents.getTaskLoader(); - RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(this); - loader.preloadTasks(loadPlan, -1 /* topTaskId */, false /* isTopTaskHome */); - - RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options(); - loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks; - loadOpts.numVisibleTaskThumbnails = launchState.launchedNumVisibleThumbnails; - loader.loadTasks(this, loadPlan, loadOpts); - - mRecentsView.updateStack(loadPlan.getTaskStack()); + mRecentsView.updateStack(stack); } - EventBus.getDefault().send(new MultiWindowStateChangedEvent(isInMultiWindowMode)); + EventBus.getDefault().send(new MultiWindowStateChangedEvent(isInMultiWindowMode, + numStackTasks > 0)); } @Override @@ -729,18 +733,4 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD }); return true; } - - /** - * Updates the nav bar scrim. - */ - private void updateNavBarScrim(boolean animateNavBarScrim, AnimationProps animation) { - // Animate the SystemUI scrims into view - SystemServicesProxy ssp = Recents.getSystemServices(); - int taskCount = mRecentsView.getStack().getTaskCount(); - boolean hasNavBarScrim = (taskCount > 0) && !ssp.hasTransposedNavBar(); - mScrimViews.prepareEnterRecentsAnimation(hasNavBarScrim, animateNavBarScrim); - if (animateNavBarScrim && animation != null) { - mScrimViews.animateNavBarScrimVisibility(true, animation); - } - } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/ConfigurationChangedEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/ConfigurationChangedEvent.java index 8be9ca7b5f2bc..e3bc2a760b5fa 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/events/activity/ConfigurationChangedEvent.java +++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/ConfigurationChangedEvent.java @@ -25,9 +25,12 @@ public class ConfigurationChangedEvent extends EventBus.AnimatedEvent { public final boolean fromMultiWindow; public final boolean fromOrientationChange; + public final boolean hasStackTasks; - public ConfigurationChangedEvent(boolean fromMultiWindow, boolean fromOrientationChange) { + public ConfigurationChangedEvent(boolean fromMultiWindow, boolean fromOrientationChange, + boolean hasStackTasks) { this.fromMultiWindow = fromMultiWindow; this.fromOrientationChange = fromOrientationChange; + this.hasStackTasks = hasStackTasks; } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/events/activity/MultiWindowStateChangedEvent.java b/packages/SystemUI/src/com/android/systemui/recents/events/activity/MultiWindowStateChangedEvent.java index 19245d9534dfd..cf2a68e2cf955 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/events/activity/MultiWindowStateChangedEvent.java +++ b/packages/SystemUI/src/com/android/systemui/recents/events/activity/MultiWindowStateChangedEvent.java @@ -24,8 +24,10 @@ import com.android.systemui.recents.events.EventBus; public class MultiWindowStateChangedEvent extends EventBus.Event { public final boolean inMultiWindow; + public final boolean hasStackTasks; - public MultiWindowStateChangedEvent(boolean inMultiWindow) { + public MultiWindowStateChangedEvent(boolean inMultiWindow, boolean hasStackTasks) { this.inMultiWindow = inMultiWindow; + this.hasStackTasks = hasStackTasks; } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/SystemBarScrimViews.java b/packages/SystemUI/src/com/android/systemui/recents/views/SystemBarScrimViews.java index 13ad9a5ee90d8..07a1d4edaeaf5 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/SystemBarScrimViews.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/SystemBarScrimViews.java @@ -16,40 +16,58 @@ package com.android.systemui.recents.views; -import android.app.Activity; import android.content.Context; import android.view.View; import com.android.systemui.Interpolators; import com.android.systemui.R; +import com.android.systemui.recents.Recents; +import com.android.systemui.recents.RecentsActivity; +import com.android.systemui.recents.events.activity.ConfigurationChangedEvent; import com.android.systemui.recents.events.activity.DismissRecentsToHomeAnimationStarted; import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationCompletedEvent; import com.android.systemui.recents.events.ui.DismissAllTaskViewsEvent; +import com.android.systemui.recents.events.activity.MultiWindowStateChangedEvent; +import com.android.systemui.recents.misc.SystemServicesProxy; /** Manages the scrims for the various system bars. */ public class SystemBarScrimViews { - Context mContext; + private static final int DEFAULT_ANIMATION_DURATION = 150; - View mNavBarScrimView; + private Context mContext; - boolean mHasNavBarScrim; - boolean mShouldAnimateNavBarScrim; + private View mNavBarScrimView; - int mNavBarScrimEnterDuration; + private boolean mHasNavBarScrim; + private boolean mShouldAnimateNavBarScrim; - public SystemBarScrimViews(Activity activity) { + private int mNavBarScrimEnterDuration; + + public SystemBarScrimViews(RecentsActivity activity) { mContext = activity; mNavBarScrimView = activity.findViewById(R.id.nav_bar_scrim); + mNavBarScrimView.forceHasOverlappingRendering(false); mNavBarScrimEnterDuration = activity.getResources().getInteger( R.integer.recents_nav_bar_scrim_enter_duration); } + /** + * Updates the nav bar scrim. + */ + public void updateNavBarScrim(boolean animateNavBarScrim, boolean hasStackTasks, + AnimationProps animation) { + prepareEnterRecentsAnimation(isNavBarScrimRequired(hasStackTasks), animateNavBarScrim); + if (animateNavBarScrim && animation != null) { + animateNavBarScrimVisibility(true, animation); + } + } + /** * Prepares the scrim views for animating when entering Recents. This will be called before * the first draw, unless we are updating the scrim on configuration change. */ - public void prepareEnterRecentsAnimation(boolean hasNavBarScrim, boolean animateNavBarScrim) { + private void prepareEnterRecentsAnimation(boolean hasNavBarScrim, boolean animateNavBarScrim) { mHasNavBarScrim = hasNavBarScrim; mShouldAnimateNavBarScrim = animateNavBarScrim; @@ -60,7 +78,7 @@ public class SystemBarScrimViews { /** * Animates the nav bar scrim visibility. */ - public void animateNavBarScrimVisibility(boolean visible, AnimationProps animation) { + private void animateNavBarScrimVisibility(boolean visible, AnimationProps animation) { int toY = 0; if (visible) { mNavBarScrimView.setVisibility(View.VISIBLE); @@ -79,6 +97,14 @@ public class SystemBarScrimViews { } } + /** + * @return Whether to show the nav bar scrim. + */ + private boolean isNavBarScrimRequired(boolean hasStackTasks) { + SystemServicesProxy ssp = Recents.getSystemServices(); + return hasStackTasks && !ssp.hasTransposedNavBar() && !ssp.hasDockedTask(); + } + /**** EventBus events ****/ /** @@ -101,21 +127,48 @@ public class SystemBarScrimViews { */ public final void onBusEvent(DismissRecentsToHomeAnimationStarted event) { if (mHasNavBarScrim) { - AnimationProps animation = new AnimationProps() - .setDuration(AnimationProps.BOUNDS, - TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION) - .setInterpolator(AnimationProps.BOUNDS, Interpolators.FAST_OUT_SLOW_IN); + AnimationProps animation = createBoundsAnimation( + TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION); animateNavBarScrimVisibility(false, animation); } } public final void onBusEvent(DismissAllTaskViewsEvent event) { if (mHasNavBarScrim) { - AnimationProps animation = new AnimationProps() - .setDuration(AnimationProps.BOUNDS, - TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION) - .setInterpolator(AnimationProps.BOUNDS, Interpolators.FAST_OUT_SLOW_IN); + AnimationProps animation = createBoundsAnimation( + TaskStackAnimationHelper.EXIT_TO_HOME_TRANSLATION_DURATION); animateNavBarScrimVisibility(false, animation); } } + + public final void onBusEvent(ConfigurationChangedEvent event) { + animateScrimToCurrentNavBarState(event.hasStackTasks); + } + + public final void onBusEvent(MultiWindowStateChangedEvent event) { + animateScrimToCurrentNavBarState(event.hasStackTasks); + } + + /** + * Animates the scrim to match the state of the current nav bar. + */ + private void animateScrimToCurrentNavBarState(boolean hasStackTasks) { + boolean hasNavBarScrim = isNavBarScrimRequired(hasStackTasks); + if (mHasNavBarScrim != hasNavBarScrim) { + AnimationProps animation = hasNavBarScrim + ? createBoundsAnimation(DEFAULT_ANIMATION_DURATION) + : AnimationProps.IMMEDIATE; + animateNavBarScrimVisibility(hasNavBarScrim, animation); + } + mHasNavBarScrim = hasNavBarScrim; + } + + /** + * @return a default animation to aniamte the bounds of the scrim. + */ + private AnimationProps createBoundsAnimation(int duration) { + return new AnimationProps() + .setDuration(AnimationProps.BOUNDS, duration) + .setInterpolator(AnimationProps.BOUNDS, Interpolators.FAST_OUT_SLOW_IN); + } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java index 1cddde73e4ace..9eab0f60584f8 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackLayoutAlgorithm.java @@ -537,11 +537,13 @@ public class TaskStackLayoutAlgorithm { } else { mInitialScrollP = Utilities.clamp(launchTaskIndex - 1, mMinScrollP, mMaxScrollP); } + mInitialNormX = null; } else if (!ssp.hasFreeformWorkspaceSupport() && mNumStackTasks == 1) { // If there is one stack task, ignore the min/max/initial scroll positions mMinScrollP = 0; mMaxScrollP = 0; mInitialScrollP = 0; + mInitialNormX = null; } else { // Set the max scroll to be the point where the front most task is visible with the // stack bottom offset