Merge "Fade back button in and out tied with the overview/shelf (2/3)" into ub-launcher3-edmonton

This commit is contained in:
TreeHugger Robot 2018-05-18 00:58:47 +00:00 committed by Android (Google) Code Review
commit f3cc505e86
6 changed files with 54 additions and 16 deletions

Binary file not shown.

View File

@ -93,7 +93,11 @@ public class UiFactory {
TYPE_ALL & ~TYPE_HIDE_BACK_BUTTON) == null; TYPE_ALL & ~TYPE_HIDE_BACK_BUTTON) == null;
} }
OverviewInteractionState.getInstance(launcher) OverviewInteractionState.getInstance(launcher)
.setBackButtonVisible(!shouldBackButtonBeHidden); .setBackButtonAlpha(shouldBackButtonBeHidden ? 0 : 1, true /* animate */);
}
public static void setBackButtonAlpha(Launcher launcher, float alpha, boolean animate) {
OverviewInteractionState.getInstance(launcher).setBackButtonAlpha(alpha,animate);
} }
public static void resetOverview(Launcher launcher) { public static void resetOverview(Launcher launcher) {

View File

@ -17,7 +17,6 @@ package com.android.quickstep;
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_QUICK_SCRUB; import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_QUICK_SCRUB;
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_SWIPE_UP; import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_DISABLE_SWIPE_UP;
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_HIDE_BACK_BUTTON;
import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_SHOW_OVERVIEW_BUTTON; import static com.android.systemui.shared.system.NavigationBarCompat.FLAG_SHOW_OVERVIEW_BUTTON;
import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME; import static com.android.systemui.shared.system.SettingsCompat.SWIPE_UP_SETTING_NAME;
@ -46,7 +45,6 @@ import java.util.concurrent.ExecutionException;
* *
* - FLAG_DISABLE_QUICK_SCRUB * - FLAG_DISABLE_QUICK_SCRUB
* - FLAG_DISABLE_SWIPE_UP * - FLAG_DISABLE_SWIPE_UP
* - FLAG_HIDE_BACK_BUTTON
* - FLAG_SHOW_OVERVIEW_BUTTON * - FLAG_SHOW_OVERVIEW_BUTTON
* *
* @see com.android.systemui.shared.system.NavigationBarCompat.InteractionType and associated flags. * @see com.android.systemui.shared.system.NavigationBarCompat.InteractionType and associated flags.
@ -81,7 +79,7 @@ public class OverviewInteractionState {
} }
private static final int MSG_SET_PROXY = 200; private static final int MSG_SET_PROXY = 200;
private static final int MSG_SET_BACK_BUTTON_VISIBLE = 201; private static final int MSG_SET_BACK_BUTTON_ALPHA = 201;
private static final int MSG_SET_SWIPE_UP_ENABLED = 202; private static final int MSG_SET_SWIPE_UP_ENABLED = 202;
private final SwipeUpGestureEnabledSettingObserver mSwipeUpSettingObserver; private final SwipeUpGestureEnabledSettingObserver mSwipeUpSettingObserver;
@ -92,13 +90,16 @@ public class OverviewInteractionState {
// These are updated on the background thread // These are updated on the background thread
private ISystemUiProxy mISystemUiProxy; private ISystemUiProxy mISystemUiProxy;
private boolean mBackButtonVisible = true;
private boolean mSwipeUpEnabled = true; private boolean mSwipeUpEnabled = true;
private Runnable mOnSwipeUpSettingChangedListener; private Runnable mOnSwipeUpSettingChangedListener;
private OverviewInteractionState(Context context) { private OverviewInteractionState(Context context) {
mContext = context; mContext = context;
// Data posted to the uihandler will be sent to the bghandler. Data is sent to uihandler
// because of its high send frequency and data may be very different than the previous value
// For example, send back alpha on uihandler to avoid flickering when setting its visibility
mUiHandler = new Handler(this::handleUiMessage); mUiHandler = new Handler(this::handleUiMessage);
mBgHandler = new Handler(UiThreadHelper.getBackgroundLooper(), this::handleBgMessage); mBgHandler = new Handler(UiThreadHelper.getBackgroundLooper(), this::handleBgMessage);
@ -116,9 +117,9 @@ public class OverviewInteractionState {
return mSwipeUpEnabled; return mSwipeUpEnabled;
} }
public void setBackButtonVisible(boolean visible) { public void setBackButtonAlpha(float alpha, boolean animate) {
mUiHandler.removeMessages(MSG_SET_BACK_BUTTON_VISIBLE); mUiHandler.removeMessages(MSG_SET_BACK_BUTTON_ALPHA);
mUiHandler.obtainMessage(MSG_SET_BACK_BUTTON_VISIBLE, visible ? 1 : 0, 0) mUiHandler.obtainMessage(MSG_SET_BACK_BUTTON_ALPHA, animate ? 1 : 0, 0, alpha)
.sendToTarget(); .sendToTarget();
} }
@ -127,7 +128,7 @@ public class OverviewInteractionState {
} }
private boolean handleUiMessage(Message msg) { private boolean handleUiMessage(Message msg) {
mBgHandler.obtainMessage(msg.what, msg.arg1, msg.arg2).sendToTarget(); mBgHandler.obtainMessage(msg.what, msg.arg1, msg.arg2, msg.obj).sendToTarget();
return true; return true;
} }
@ -136,9 +137,9 @@ public class OverviewInteractionState {
case MSG_SET_PROXY: case MSG_SET_PROXY:
mISystemUiProxy = (ISystemUiProxy) msg.obj; mISystemUiProxy = (ISystemUiProxy) msg.obj;
break; break;
case MSG_SET_BACK_BUTTON_VISIBLE: case MSG_SET_BACK_BUTTON_ALPHA:
mBackButtonVisible = msg.arg1 != 0; applyBackButtonAlpha((float) msg.obj, msg.arg1 == 1);
break; return true;
case MSG_SET_SWIPE_UP_ENABLED: case MSG_SET_SWIPE_UP_ENABLED:
mSwipeUpEnabled = msg.arg1 != 0; mSwipeUpEnabled = msg.arg1 != 0;
resetHomeBounceSeenOnQuickstepEnabledFirstTime(); resetHomeBounceSeenOnQuickstepEnabledFirstTime();
@ -162,10 +163,8 @@ public class OverviewInteractionState {
return; return;
} }
int flags; int flags = 0;
if (mSwipeUpEnabled) { if (!mSwipeUpEnabled) {
flags = mBackButtonVisible ? 0 : FLAG_HIDE_BACK_BUTTON;
} else {
flags = FLAG_DISABLE_SWIPE_UP | FLAG_DISABLE_QUICK_SCRUB | FLAG_SHOW_OVERVIEW_BUTTON; flags = FLAG_DISABLE_SWIPE_UP | FLAG_DISABLE_QUICK_SCRUB | FLAG_SHOW_OVERVIEW_BUTTON;
} }
try { try {
@ -175,6 +174,18 @@ public class OverviewInteractionState {
} }
} }
@WorkerThread
private void applyBackButtonAlpha(float alpha, boolean animate) {
if (mISystemUiProxy == null) {
return;
}
try {
mISystemUiProxy.setBackButtonAlpha(alpha, animate);
} catch (RemoteException e) {
Log.w(TAG, "Unable to update overview back button alpha", e);
}
}
private class SwipeUpGestureEnabledSettingObserver extends ContentObserver { private class SwipeUpGestureEnabledSettingObserver extends ContentObserver {
private Handler mHandler; private Handler mHandler;
private ContentResolver mResolver; private ContentResolver mResolver;

View File

@ -25,9 +25,11 @@ import com.android.launcher3.LauncherState;
import com.android.launcher3.LauncherStateManager.AnimationConfig; import com.android.launcher3.LauncherStateManager.AnimationConfig;
import com.android.launcher3.LauncherStateManager.StateHandler; import com.android.launcher3.LauncherStateManager.StateHandler;
import com.android.launcher3.R; import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimationSuccessListener; import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorSetBuilder; import com.android.launcher3.anim.AnimatorSetBuilder;
import com.android.launcher3.anim.PropertySetter; import com.android.launcher3.anim.PropertySetter;
import com.android.launcher3.uioverrides.UiFactory;
import com.android.launcher3.util.Themes; import com.android.launcher3.util.Themes;
import com.android.launcher3.views.ScrimView; import com.android.launcher3.views.ScrimView;
@ -182,6 +184,13 @@ public class AllAppsTransitionController implements StateHandler, OnDeviceProfil
anim.setDuration(config.duration); anim.setDuration(config.duration);
anim.setInterpolator(builder.getInterpolator(ANIM_VERTICAL_PROGRESS, interpolator)); anim.setInterpolator(builder.getInterpolator(ANIM_VERTICAL_PROGRESS, interpolator));
anim.addListener(getProgressAnimatorListener()); anim.addListener(getProgressAnimatorListener());
if (toState.hideBackButton) {
anim.addUpdateListener(animation -> {
final float alpha = (float) animation.getAnimatedValue();
UiFactory.setBackButtonAlpha(mLauncher, 1 - Utilities.boundToRange(alpha, 0, 1),
false /* animate */);
});
}
builder.play(anim); builder.play(anim);

View File

@ -42,6 +42,7 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimationSuccessListener; import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController; import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.AnimatorSetBuilder; import com.android.launcher3.anim.AnimatorSetBuilder;
import com.android.launcher3.uioverrides.UiFactory;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
@ -221,6 +222,8 @@ public abstract class AbstractStateChangeTouchController
cancelAtomicComponentsController(); cancelAtomicComponentsController();
} }
mProgressMultiplier = initCurrentAnimation(animComponents); mProgressMultiplier = initCurrentAnimation(animComponents);
mCurrentAnimation.getAnimationPlayer().addUpdateListener(animation ->
setBackButtonAlphaWithProgress((float) animation.getAnimatedValue()));
mCurrentAnimation.dispatchOnStart(); mCurrentAnimation.dispatchOnStart();
return true; return true;
} }
@ -279,6 +282,7 @@ public abstract class AbstractStateChangeTouchController
mAtomicComponentsController.setPlayFraction(fraction - mAtomicComponentsStartProgress); mAtomicComponentsController.setPlayFraction(fraction - mAtomicComponentsStartProgress);
} }
maybeUpdateAtomicAnim(mFromState, mToState, fraction); maybeUpdateAtomicAnim(mFromState, mToState, fraction);
setBackButtonAlphaWithProgress(fraction);
} }
/** /**
@ -471,6 +475,14 @@ public abstract class AbstractStateChangeTouchController
} }
} }
private void setBackButtonAlphaWithProgress(float progress) {
if (mFromState.hideBackButton ^ mToState.hideBackButton) {
progress = Utilities.boundToRange(progress, 0, 1);
final float alpha = mToState.hideBackButton ? 1 - progress : progress;
UiFactory.setBackButtonAlpha(mLauncher, alpha, false /* animate */);
}
}
private void logReachedState(int logAction) { private void logReachedState(int logAction) {
// Transition complete. log the action // Transition complete. log the action
mLauncher.getUserEventDispatcher().logStateChangeAction(logAction, mLauncher.getUserEventDispatcher().logStateChangeAction(logAction,

View File

@ -56,4 +56,6 @@ public class UiFactory {
} }
public static void prepareToShowOverview(Launcher launcher) { } public static void prepareToShowOverview(Launcher launcher) { }
public static void setBackButtonAlpha(Launcher launcher, float alpha, boolean animate) { }
} }