mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-18 10:18:20 +00:00
Stash/unstash the task bar based on states
Bug: 193938970 Test: go to any app, stash/unstash, and make sure the states are preserved Change-Id: I3adf826407e90275687ecea8302abf7a004f1df7
This commit is contained in:
@@ -31,12 +31,17 @@ import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
|
||||
import com.android.quickstep.AnimatedFloat;
|
||||
import com.android.quickstep.SystemUiProxy;
|
||||
|
||||
import java.util.function.IntPredicate;
|
||||
|
||||
/**
|
||||
* Coordinates between controllers such as TaskbarViewController and StashedHandleViewController to
|
||||
* create a cohesive animation between stashed/unstashed states.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
@@ -78,6 +83,9 @@ public class TaskbarStashController {
|
||||
private final int mStashedHeight;
|
||||
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.
|
||||
private TaskbarControllers mControllers;
|
||||
// Taskbar background properties.
|
||||
@@ -94,6 +102,7 @@ public class TaskbarStashController {
|
||||
private boolean mIsStashedInApp;
|
||||
/** Whether we are currently visually stashed (might change based on launcher state). */
|
||||
private boolean mIsStashed = false;
|
||||
private int mState;
|
||||
|
||||
private @Nullable AnimatorSet mAnimator;
|
||||
|
||||
@@ -124,6 +133,7 @@ public class TaskbarStashController {
|
||||
|
||||
mIsStashedInApp = supportsStashing()
|
||||
&& mPrefs.getBoolean(SHARED_PREFS_STASHED_KEY, DEFAULT_STASHED_PREF);
|
||||
updateStateForFlag(FLAG_STASHED_IN_APP, mIsStashedInApp);
|
||||
|
||||
SystemUiProxy.INSTANCE.get(mActivity)
|
||||
.notifyTaskbarStatus(/* visible */ true, /* stashed */ mIsStashedInApp);
|
||||
@@ -190,35 +200,19 @@ public class TaskbarStashController {
|
||||
return false;
|
||||
}
|
||||
if (mIsStashedInApp != isStashedInApp) {
|
||||
boolean wasStashed = mIsStashedInApp;
|
||||
mIsStashedInApp = isStashedInApp;
|
||||
mPrefs.edit().putBoolean(SHARED_PREFS_STASHED_KEY, mIsStashedInApp).apply();
|
||||
boolean isStashed = mIsStashedInApp;
|
||||
if (wasStashed != isStashed) {
|
||||
SystemUiProxy.INSTANCE.get(mActivity)
|
||||
.notifyTaskbarStatus(/* visible */ true, /* stashed */ isStashed);
|
||||
mControllers.uiController.onStashedInAppChanged();
|
||||
createAnimToIsStashed(isStashed, TASKBAR_STASH_DURATION).start();
|
||||
return true;
|
||||
}
|
||||
updateStateForFlag(FLAG_STASHED_IN_APP, mIsStashedInApp);
|
||||
applyState();
|
||||
|
||||
SystemUiProxy.INSTANCE.get(mActivity)
|
||||
.notifyTaskbarStatus(/* visible */ true, /* stashed */ mIsStashedInApp);
|
||||
mControllers.uiController.onStashedInAppChanged();
|
||||
return true;
|
||||
}
|
||||
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) {
|
||||
AnimatorSet fullLengthAnimatorSet = new AnimatorSet();
|
||||
// Not exactly half and may overlap. See [first|second]HalfDurationScale below.
|
||||
@@ -331,4 +325,47 @@ public class TaskbarStashController {
|
||||
private void onIsStashed(boolean 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