Merge "Stash/unstash the task bar based on states" into sc-v2-dev
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
package com.android.launcher3.taskbar;
|
package com.android.launcher3.taskbar;
|
||||||
|
|
||||||
import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
|
import static com.android.launcher3.LauncherState.HOTSEAT_ICONS;
|
||||||
|
import static com.android.launcher3.taskbar.TaskbarStashController.FLAG_IN_APP;
|
||||||
import static com.android.launcher3.taskbar.TaskbarViewController.ALPHA_INDEX_HOME;
|
import static com.android.launcher3.taskbar.TaskbarViewController.ALPHA_INDEX_HOME;
|
||||||
|
|
||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
@@ -162,10 +163,9 @@ public class LauncherTaskbarUIController extends TaskbarUIController {
|
|||||||
anim.start();
|
anim.start();
|
||||||
mIsAnimatingToLauncherViaResume = isResumed;
|
mIsAnimatingToLauncherViaResume = isResumed;
|
||||||
|
|
||||||
if (!isResumed) {
|
TaskbarStashController stashController = mControllers.taskbarStashController;
|
||||||
TaskbarStashController stashController = mControllers.taskbarStashController;
|
stashController.updateStateForFlag(FLAG_IN_APP, !isResumed);
|
||||||
stashController.animateToIsStashed(stashController.isStashedInApp(), duration);
|
stashController.applyState(duration);
|
||||||
}
|
|
||||||
SystemUiProxy.INSTANCE.get(mContext).notifyTaskbarStatus(!isResumed,
|
SystemUiProxy.INSTANCE.get(mContext).notifyTaskbarStatus(!isResumed,
|
||||||
mControllers.taskbarStashController.isStashedInApp());
|
mControllers.taskbarStashController.isStashedInApp());
|
||||||
}
|
}
|
||||||
@@ -193,8 +193,11 @@ public class LauncherTaskbarUIController extends TaskbarUIController {
|
|||||||
public void onAnimationStart(Animator animation) {
|
public void onAnimationStart(Animator animation) {
|
||||||
mTargetStateOverride = toState;
|
mTargetStateOverride = toState;
|
||||||
mIsAnimatingToLauncherViaGesture = true;
|
mIsAnimatingToLauncherViaGesture = true;
|
||||||
// TODO: base this on launcher state
|
// TODO: FLAG_IN_APP might be sufficient for now, but in the future we do want to
|
||||||
stashController.animateToIsStashed(false, duration);
|
// add another flag for LauncherState as well. We will need to decide whether to
|
||||||
|
// show hotseat or the task bar.
|
||||||
|
stashController.updateStateForFlag(FLAG_IN_APP, false);
|
||||||
|
stashController.applyState(duration);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -327,9 +330,8 @@ public class LauncherTaskbarUIController extends TaskbarUIController {
|
|||||||
.start();
|
.start();
|
||||||
|
|
||||||
TaskbarStashController controller = mControllers.taskbarStashController;
|
TaskbarStashController controller = mControllers.taskbarStashController;
|
||||||
if (finishedToApp) {
|
controller.updateStateForFlag(FLAG_IN_APP, finishedToApp);
|
||||||
controller.animateToIsStashed(controller.isStashedInApp());
|
controller.applyState();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,12 +31,17 @@ import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
|
|||||||
import com.android.quickstep.AnimatedFloat;
|
import com.android.quickstep.AnimatedFloat;
|
||||||
import com.android.quickstep.SystemUiProxy;
|
import com.android.quickstep.SystemUiProxy;
|
||||||
|
|
||||||
|
import java.util.function.IntPredicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Coordinates between controllers such as TaskbarViewController and StashedHandleViewController to
|
* Coordinates between controllers such as TaskbarViewController and StashedHandleViewController to
|
||||||
* create a cohesive animation between stashed/unstashed states.
|
* create a cohesive animation between stashed/unstashed states.
|
||||||
*/
|
*/
|
||||||
public class TaskbarStashController {
|
public class TaskbarStashController {
|
||||||
|
|
||||||
|
public static final int FLAG_IN_APP = 1 << 0;
|
||||||
|
public static final int FLAG_STASHED_IN_APP = 1 << 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How long to stash/unstash when manually invoked via long press.
|
* How long to stash/unstash when manually invoked via long press.
|
||||||
*/
|
*/
|
||||||
@@ -78,6 +83,9 @@ public class TaskbarStashController {
|
|||||||
private final int mStashedHeight;
|
private final int mStashedHeight;
|
||||||
private final int mUnstashedHeight;
|
private final int mUnstashedHeight;
|
||||||
|
|
||||||
|
private final StatePropertyHolder mStatePropertyHolder = new StatePropertyHolder(
|
||||||
|
flags -> (((flags & FLAG_IN_APP) != 0) && (flags & FLAG_STASHED_IN_APP) != 0));
|
||||||
|
|
||||||
// Initialized in init.
|
// Initialized in init.
|
||||||
private TaskbarControllers mControllers;
|
private TaskbarControllers mControllers;
|
||||||
// Taskbar background properties.
|
// Taskbar background properties.
|
||||||
@@ -94,6 +102,7 @@ public class TaskbarStashController {
|
|||||||
private boolean mIsStashedInApp;
|
private boolean mIsStashedInApp;
|
||||||
/** Whether we are currently visually stashed (might change based on launcher state). */
|
/** Whether we are currently visually stashed (might change based on launcher state). */
|
||||||
private boolean mIsStashed = false;
|
private boolean mIsStashed = false;
|
||||||
|
private int mState;
|
||||||
|
|
||||||
private @Nullable AnimatorSet mAnimator;
|
private @Nullable AnimatorSet mAnimator;
|
||||||
|
|
||||||
@@ -124,6 +133,7 @@ public class TaskbarStashController {
|
|||||||
|
|
||||||
mIsStashedInApp = supportsStashing()
|
mIsStashedInApp = supportsStashing()
|
||||||
&& mPrefs.getBoolean(SHARED_PREFS_STASHED_KEY, DEFAULT_STASHED_PREF);
|
&& mPrefs.getBoolean(SHARED_PREFS_STASHED_KEY, DEFAULT_STASHED_PREF);
|
||||||
|
updateStateForFlag(FLAG_STASHED_IN_APP, mIsStashedInApp);
|
||||||
|
|
||||||
SystemUiProxy.INSTANCE.get(mActivity)
|
SystemUiProxy.INSTANCE.get(mActivity)
|
||||||
.notifyTaskbarStatus(/* visible */ true, /* stashed */ mIsStashedInApp);
|
.notifyTaskbarStatus(/* visible */ true, /* stashed */ mIsStashedInApp);
|
||||||
@@ -190,35 +200,19 @@ public class TaskbarStashController {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mIsStashedInApp != isStashedInApp) {
|
if (mIsStashedInApp != isStashedInApp) {
|
||||||
boolean wasStashed = mIsStashedInApp;
|
|
||||||
mIsStashedInApp = isStashedInApp;
|
mIsStashedInApp = isStashedInApp;
|
||||||
mPrefs.edit().putBoolean(SHARED_PREFS_STASHED_KEY, mIsStashedInApp).apply();
|
mPrefs.edit().putBoolean(SHARED_PREFS_STASHED_KEY, mIsStashedInApp).apply();
|
||||||
boolean isStashed = mIsStashedInApp;
|
updateStateForFlag(FLAG_STASHED_IN_APP, mIsStashedInApp);
|
||||||
if (wasStashed != isStashed) {
|
applyState();
|
||||||
SystemUiProxy.INSTANCE.get(mActivity)
|
|
||||||
.notifyTaskbarStatus(/* visible */ true, /* stashed */ isStashed);
|
SystemUiProxy.INSTANCE.get(mActivity)
|
||||||
mControllers.uiController.onStashedInAppChanged();
|
.notifyTaskbarStatus(/* visible */ true, /* stashed */ mIsStashedInApp);
|
||||||
createAnimToIsStashed(isStashed, TASKBAR_STASH_DURATION).start();
|
mControllers.uiController.onStashedInAppChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts an animation to the new stashed state with a default duration.
|
|
||||||
*/
|
|
||||||
public void animateToIsStashed(boolean isStashed) {
|
|
||||||
animateToIsStashed(isStashed, TASKBAR_STASH_DURATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts an animation to the new stashed state with the specified duration.
|
|
||||||
*/
|
|
||||||
public void animateToIsStashed(boolean isStashed, long duration) {
|
|
||||||
createAnimToIsStashed(isStashed, duration).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Animator createAnimToIsStashed(boolean isStashed, long duration) {
|
private Animator createAnimToIsStashed(boolean isStashed, long duration) {
|
||||||
AnimatorSet fullLengthAnimatorSet = new AnimatorSet();
|
AnimatorSet fullLengthAnimatorSet = new AnimatorSet();
|
||||||
// Not exactly half and may overlap. See [first|second]HalfDurationScale below.
|
// Not exactly half and may overlap. See [first|second]HalfDurationScale below.
|
||||||
@@ -331,4 +325,47 @@ public class TaskbarStashController {
|
|||||||
private void onIsStashed(boolean isStashed) {
|
private void onIsStashed(boolean isStashed) {
|
||||||
mControllers.stashedHandleViewController.onIsStashed(isStashed);
|
mControllers.stashedHandleViewController.onIsStashed(isStashed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void applyState() {
|
||||||
|
applyState(TASKBAR_STASH_DURATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void applyState(long duration) {
|
||||||
|
mStatePropertyHolder.setState(mState, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the proper flag to indicate whether the task bar should be stashed.
|
||||||
|
*
|
||||||
|
* Note that this only updates the flag. {@link #applyState()} needs to be called separately.
|
||||||
|
*
|
||||||
|
* @param flag The flag to update.
|
||||||
|
* @param enabled Whether to enable the flag: True will cause the task bar to be stashed /
|
||||||
|
* unstashed.
|
||||||
|
*/
|
||||||
|
public void updateStateForFlag(int flag, boolean enabled) {
|
||||||
|
if (enabled) {
|
||||||
|
mState |= flag;
|
||||||
|
} else {
|
||||||
|
mState &= ~flag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class StatePropertyHolder {
|
||||||
|
private final IntPredicate mStashCondition;
|
||||||
|
|
||||||
|
private boolean mIsStashed;
|
||||||
|
|
||||||
|
StatePropertyHolder(IntPredicate stashCondition) {
|
||||||
|
mStashCondition = stashCondition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setState(int flags, long duration) {
|
||||||
|
boolean isStashed = mStashCondition.test(flags);
|
||||||
|
if (mIsStashed != isStashed) {
|
||||||
|
mIsStashed = isStashed;
|
||||||
|
createAnimToIsStashed(mIsStashed, duration).start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user