2021-06-01 16:54:07 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2021 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package com.android.launcher3.taskbar;
|
|
|
|
|
|
|
|
|
|
import static android.view.HapticFeedbackConstants.LONG_PRESS;
|
|
|
|
|
|
2021-10-07 15:49:19 -07:00
|
|
|
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_LONGPRESS_HIDE;
|
|
|
|
|
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_LONGPRESS_SHOW;
|
2021-10-07 15:53:32 -07:00
|
|
|
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SCREEN_PINNING;
|
2021-10-07 15:49:19 -07:00
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
import android.animation.Animator;
|
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
|
import android.annotation.Nullable;
|
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
import android.content.res.Resources;
|
2021-07-16 12:15:35 -10:00
|
|
|
import android.view.ViewConfiguration;
|
2021-06-01 16:54:07 -07:00
|
|
|
|
|
|
|
|
import com.android.launcher3.R;
|
|
|
|
|
import com.android.launcher3.Utilities;
|
|
|
|
|
import com.android.launcher3.util.MultiValueAlpha.AlphaProperty;
|
|
|
|
|
import com.android.quickstep.AnimatedFloat;
|
2021-06-30 10:24:11 +00:00
|
|
|
import com.android.quickstep.SystemUiProxy;
|
2021-06-01 16:54:07 -07:00
|
|
|
|
2021-09-02 22:49:34 -07:00
|
|
|
import java.util.function.IntPredicate;
|
|
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
/**
|
|
|
|
|
* Coordinates between controllers such as TaskbarViewController and StashedHandleViewController to
|
|
|
|
|
* create a cohesive animation between stashed/unstashed states.
|
|
|
|
|
*/
|
|
|
|
|
public class TaskbarStashController {
|
|
|
|
|
|
2021-09-02 22:49:34 -07:00
|
|
|
public static final int FLAG_IN_APP = 1 << 0;
|
2021-10-07 15:49:19 -07:00
|
|
|
public static final int FLAG_STASHED_IN_APP_MANUAL = 1 << 1; // long press, persisted
|
2021-10-07 15:53:32 -07:00
|
|
|
public static final int FLAG_STASHED_IN_APP_PINNED = 1 << 2; // app pinning
|
|
|
|
|
public static final int FLAG_STASHED_IN_APP_EMPTY = 1 << 3; // no hotseat icons
|
|
|
|
|
public static final int FLAG_IN_STASHED_LAUNCHER_STATE = 1 << 4;
|
2021-09-02 22:49:34 -07:00
|
|
|
|
2021-10-07 15:49:19 -07:00
|
|
|
// If we're in an app and any of these flags are enabled, taskbar should be stashed.
|
2021-10-07 15:53:32 -07:00
|
|
|
public static final int FLAGS_STASHED_IN_APP = FLAG_STASHED_IN_APP_MANUAL
|
|
|
|
|
| FLAG_STASHED_IN_APP_PINNED | FLAG_STASHED_IN_APP_EMPTY;
|
2021-10-07 15:49:19 -07:00
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
/**
|
|
|
|
|
* How long to stash/unstash when manually invoked via long press.
|
|
|
|
|
*/
|
|
|
|
|
private static final long TASKBAR_STASH_DURATION = 300;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The scale TaskbarView animates to when being stashed.
|
|
|
|
|
*/
|
|
|
|
|
private static final float STASHED_TASKBAR_SCALE = 0.5f;
|
|
|
|
|
|
2021-07-16 12:15:35 -10:00
|
|
|
/**
|
|
|
|
|
* How long the hint animation plays, starting on motion down.
|
|
|
|
|
*/
|
|
|
|
|
private static final long TASKBAR_HINT_STASH_DURATION =
|
|
|
|
|
ViewConfiguration.DEFAULT_LONG_PRESS_TIMEOUT;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The scale that TaskbarView animates to when hinting towards the stashed state.
|
|
|
|
|
*/
|
|
|
|
|
private static final float STASHED_TASKBAR_HINT_SCALE = 0.9f;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The scale that the stashed handle animates to when hinting towards the unstashed state.
|
|
|
|
|
*/
|
|
|
|
|
private static final float UNSTASHED_TASKBAR_HANDLE_HINT_SCALE = 1.1f;
|
|
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
/**
|
|
|
|
|
* The SharedPreferences key for whether user has manually stashed the taskbar.
|
|
|
|
|
*/
|
|
|
|
|
private static final String SHARED_PREFS_STASHED_KEY = "taskbar_is_stashed";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether taskbar should be stashed out of the box.
|
|
|
|
|
*/
|
|
|
|
|
private static final boolean DEFAULT_STASHED_PREF = false;
|
|
|
|
|
|
|
|
|
|
private final TaskbarActivityContext mActivity;
|
|
|
|
|
private final SharedPreferences mPrefs;
|
|
|
|
|
private final int mStashedHeight;
|
|
|
|
|
private final int mUnstashedHeight;
|
|
|
|
|
|
|
|
|
|
// Initialized in init.
|
|
|
|
|
private TaskbarControllers mControllers;
|
|
|
|
|
// Taskbar background properties.
|
|
|
|
|
private AnimatedFloat mTaskbarBackgroundOffset;
|
|
|
|
|
// TaskbarView icon properties.
|
|
|
|
|
private AlphaProperty mIconAlphaForStash;
|
|
|
|
|
private AnimatedFloat mIconScaleForStash;
|
|
|
|
|
private AnimatedFloat mIconTranslationYForStash;
|
|
|
|
|
// Stashed handle properties.
|
|
|
|
|
private AnimatedFloat mTaskbarStashedHandleAlpha;
|
2021-07-16 12:15:35 -10:00
|
|
|
private AnimatedFloat mTaskbarStashedHandleHintScale;
|
2021-06-01 16:54:07 -07:00
|
|
|
|
|
|
|
|
/** Whether we are currently visually stashed (might change based on launcher state). */
|
|
|
|
|
private boolean mIsStashed = false;
|
2021-09-02 22:49:34 -07:00
|
|
|
private int mState;
|
2021-06-01 16:54:07 -07:00
|
|
|
|
|
|
|
|
private @Nullable AnimatorSet mAnimator;
|
|
|
|
|
|
2021-09-09 21:18:25 -07:00
|
|
|
// Evaluate whether the handle should be stashed
|
|
|
|
|
private final StatePropertyHolder mStatePropertyHolder = new StatePropertyHolder(
|
|
|
|
|
flags -> {
|
2021-10-07 15:49:19 -07:00
|
|
|
boolean inApp = hasAnyFlag(flags, FLAG_IN_APP);
|
|
|
|
|
boolean stashedInApp = hasAnyFlag(flags, FLAGS_STASHED_IN_APP);
|
|
|
|
|
boolean stashedLauncherState = hasAnyFlag(flags, FLAG_IN_STASHED_LAUNCHER_STATE);
|
2021-09-09 21:18:25 -07:00
|
|
|
return (inApp && stashedInApp) || (!inApp && stashedLauncherState);
|
|
|
|
|
});
|
|
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
public TaskbarStashController(TaskbarActivityContext activity) {
|
|
|
|
|
mActivity = activity;
|
|
|
|
|
mPrefs = Utilities.getPrefs(mActivity);
|
|
|
|
|
final Resources resources = mActivity.getResources();
|
|
|
|
|
mStashedHeight = resources.getDimensionPixelSize(R.dimen.taskbar_stashed_size);
|
|
|
|
|
mUnstashedHeight = mActivity.getDeviceProfile().taskbarSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void init(TaskbarControllers controllers) {
|
|
|
|
|
mControllers = controllers;
|
|
|
|
|
|
|
|
|
|
TaskbarDragLayerController dragLayerController = controllers.taskbarDragLayerController;
|
|
|
|
|
mTaskbarBackgroundOffset = dragLayerController.getTaskbarBackgroundOffset();
|
|
|
|
|
|
|
|
|
|
TaskbarViewController taskbarViewController = controllers.taskbarViewController;
|
|
|
|
|
mIconAlphaForStash = taskbarViewController.getTaskbarIconAlpha().getProperty(
|
|
|
|
|
TaskbarViewController.ALPHA_INDEX_STASH);
|
|
|
|
|
mIconScaleForStash = taskbarViewController.getTaskbarIconScaleForStash();
|
|
|
|
|
mIconTranslationYForStash = taskbarViewController.getTaskbarIconTranslationYForStash();
|
|
|
|
|
|
|
|
|
|
StashedHandleViewController stashedHandleController =
|
|
|
|
|
controllers.stashedHandleViewController;
|
|
|
|
|
mTaskbarStashedHandleAlpha = stashedHandleController.getStashedHandleAlpha();
|
2021-07-16 12:15:35 -10:00
|
|
|
mTaskbarStashedHandleHintScale = stashedHandleController.getStashedHandleHintScale();
|
2021-06-01 16:54:07 -07:00
|
|
|
|
2021-10-07 15:49:19 -07:00
|
|
|
boolean isManuallyStashedInApp = supportsManualStashing()
|
2021-06-01 16:54:07 -07:00
|
|
|
&& mPrefs.getBoolean(SHARED_PREFS_STASHED_KEY, DEFAULT_STASHED_PREF);
|
2021-10-07 15:49:19 -07:00
|
|
|
updateStateForFlag(FLAG_STASHED_IN_APP_MANUAL, isManuallyStashedInApp);
|
|
|
|
|
applyState();
|
2021-06-30 10:24:11 +00:00
|
|
|
|
|
|
|
|
SystemUiProxy.INSTANCE.get(mActivity)
|
2021-10-07 15:49:19 -07:00
|
|
|
.notifyTaskbarStatus(/* visible */ false, /* stashed */ isStashedInApp());
|
2021-06-01 16:54:07 -07:00
|
|
|
}
|
|
|
|
|
|
2021-09-22 13:58:10 -07:00
|
|
|
/**
|
|
|
|
|
* Returns whether the taskbar can visually stash into a handle based on the current device
|
|
|
|
|
* state.
|
|
|
|
|
*/
|
|
|
|
|
private boolean supportsVisualStashing() {
|
|
|
|
|
return !mActivity.isThreeButtonNav();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
/**
|
|
|
|
|
* Returns whether the user can manually stash the taskbar based on the current device state.
|
|
|
|
|
*/
|
2021-09-22 13:58:10 -07:00
|
|
|
private boolean supportsManualStashing() {
|
|
|
|
|
return supportsVisualStashing()
|
2021-07-15 14:42:33 -10:00
|
|
|
&& (!Utilities.IS_RUNNING_IN_TEST_HARNESS || supportsStashingForTests());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean supportsStashingForTests() {
|
|
|
|
|
// TODO: enable this for tests that specifically check stash/unstash behavior.
|
|
|
|
|
return false;
|
2021-06-01 16:54:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether the taskbar is currently visually stashed.
|
|
|
|
|
*/
|
|
|
|
|
public boolean isStashed() {
|
|
|
|
|
return mIsStashed;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-10-07 15:49:19 -07:00
|
|
|
* Returns whether the taskbar should be stashed in apps (e.g. user long pressed to stash).
|
2021-06-01 16:54:07 -07:00
|
|
|
*/
|
|
|
|
|
public boolean isStashedInApp() {
|
2021-10-07 15:49:19 -07:00
|
|
|
return hasAnyFlag(FLAGS_STASHED_IN_APP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean hasAnyFlag(int flagMask) {
|
|
|
|
|
return hasAnyFlag(mState, flagMask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean hasAnyFlag(int flags, int flagMask) {
|
|
|
|
|
return (flags & flagMask) != 0;
|
2021-06-01 16:54:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getContentHeight() {
|
|
|
|
|
return isStashed() ? mStashedHeight : mUnstashedHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getStashedHeight() {
|
|
|
|
|
return mStashedHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Should be called when long pressing the nav region when taskbar is present.
|
|
|
|
|
* @return Whether taskbar was stashed and now is unstashed.
|
|
|
|
|
*/
|
|
|
|
|
public boolean onLongPressToUnstashTaskbar() {
|
|
|
|
|
if (!isStashed()) {
|
|
|
|
|
// We only listen for long press on the nav region to unstash the taskbar. To stash the
|
|
|
|
|
// taskbar, we use an OnLongClickListener on TaskbarView instead.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-10-07 15:49:19 -07:00
|
|
|
if (updateAndAnimateIsManuallyStashedInApp(false)) {
|
2021-06-01 16:54:07 -07:00
|
|
|
mControllers.taskbarActivityContext.getDragLayer().performHapticFeedback(LONG_PRESS);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updates whether we should stash the taskbar when in apps, and animates to the changed state.
|
|
|
|
|
* @return Whether we started an animation to either be newly stashed or unstashed.
|
|
|
|
|
*/
|
2021-10-07 15:49:19 -07:00
|
|
|
public boolean updateAndAnimateIsManuallyStashedInApp(boolean isManuallyStashedInApp) {
|
2021-09-22 13:58:10 -07:00
|
|
|
if (!supportsManualStashing()) {
|
2021-06-01 16:54:07 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
2021-10-07 15:49:19 -07:00
|
|
|
if (hasAnyFlag(FLAG_STASHED_IN_APP_MANUAL) != isManuallyStashedInApp) {
|
|
|
|
|
mPrefs.edit().putBoolean(SHARED_PREFS_STASHED_KEY, isManuallyStashedInApp).apply();
|
|
|
|
|
updateStateForFlag(FLAG_STASHED_IN_APP_MANUAL, isManuallyStashedInApp);
|
2021-09-02 22:49:34 -07:00
|
|
|
applyState();
|
|
|
|
|
return true;
|
2021-06-01 16:54:07 -07:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Animator createAnimToIsStashed(boolean isStashed, long duration) {
|
2021-10-07 18:33:43 -07:00
|
|
|
if (mAnimator != null) {
|
|
|
|
|
mAnimator.cancel();
|
|
|
|
|
}
|
|
|
|
|
mAnimator = new AnimatorSet();
|
|
|
|
|
|
|
|
|
|
if (!supportsVisualStashing()) {
|
|
|
|
|
// Just hide/show the icons instead of stashing into a handle.
|
|
|
|
|
mAnimator.play(mIconAlphaForStash.animateToValue(isStashed ? 0 : 1)
|
|
|
|
|
.setDuration(duration));
|
|
|
|
|
return mAnimator;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 16:54:07 -07:00
|
|
|
AnimatorSet fullLengthAnimatorSet = new AnimatorSet();
|
|
|
|
|
// Not exactly half and may overlap. See [first|second]HalfDurationScale below.
|
|
|
|
|
AnimatorSet firstHalfAnimatorSet = new AnimatorSet();
|
|
|
|
|
AnimatorSet secondHalfAnimatorSet = new AnimatorSet();
|
|
|
|
|
|
|
|
|
|
final float firstHalfDurationScale;
|
|
|
|
|
final float secondHalfDurationScale;
|
|
|
|
|
|
|
|
|
|
if (isStashed) {
|
|
|
|
|
firstHalfDurationScale = 0.75f;
|
|
|
|
|
secondHalfDurationScale = 0.5f;
|
|
|
|
|
final float stashTranslation = (mUnstashedHeight - mStashedHeight) / 2f;
|
|
|
|
|
|
|
|
|
|
fullLengthAnimatorSet.playTogether(
|
|
|
|
|
mTaskbarBackgroundOffset.animateToValue(1),
|
|
|
|
|
mIconTranslationYForStash.animateToValue(stashTranslation)
|
|
|
|
|
);
|
|
|
|
|
firstHalfAnimatorSet.playTogether(
|
|
|
|
|
mIconAlphaForStash.animateToValue(0),
|
|
|
|
|
mIconScaleForStash.animateToValue(STASHED_TASKBAR_SCALE)
|
|
|
|
|
);
|
|
|
|
|
secondHalfAnimatorSet.playTogether(
|
|
|
|
|
mTaskbarStashedHandleAlpha.animateToValue(1)
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
firstHalfDurationScale = 0.5f;
|
|
|
|
|
secondHalfDurationScale = 0.75f;
|
|
|
|
|
|
|
|
|
|
fullLengthAnimatorSet.playTogether(
|
|
|
|
|
mTaskbarBackgroundOffset.animateToValue(0),
|
|
|
|
|
mIconScaleForStash.animateToValue(1),
|
|
|
|
|
mIconTranslationYForStash.animateToValue(0)
|
|
|
|
|
);
|
|
|
|
|
firstHalfAnimatorSet.playTogether(
|
|
|
|
|
mTaskbarStashedHandleAlpha.animateToValue(0)
|
|
|
|
|
);
|
|
|
|
|
secondHalfAnimatorSet.playTogether(
|
|
|
|
|
mIconAlphaForStash.animateToValue(1)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Animator stashedHandleRevealAnim = mControllers.stashedHandleViewController
|
|
|
|
|
.createRevealAnimToIsStashed(isStashed);
|
|
|
|
|
if (stashedHandleRevealAnim != null) {
|
|
|
|
|
fullLengthAnimatorSet.play(stashedHandleRevealAnim);
|
|
|
|
|
}
|
2021-07-16 12:15:35 -10:00
|
|
|
// Return the stashed handle to its default scale in case it was changed as part of the
|
|
|
|
|
// feedforward hint. Note that the reveal animation above also visually scales it.
|
|
|
|
|
fullLengthAnimatorSet.play(mTaskbarStashedHandleHintScale.animateToValue(1f));
|
2021-06-01 16:54:07 -07:00
|
|
|
|
|
|
|
|
fullLengthAnimatorSet.setDuration(duration);
|
|
|
|
|
firstHalfAnimatorSet.setDuration((long) (duration * firstHalfDurationScale));
|
|
|
|
|
secondHalfAnimatorSet.setDuration((long) (duration * secondHalfDurationScale));
|
|
|
|
|
secondHalfAnimatorSet.setStartDelay((long) (duration * (1 - secondHalfDurationScale)));
|
|
|
|
|
|
|
|
|
|
mAnimator.playTogether(fullLengthAnimatorSet, firstHalfAnimatorSet,
|
|
|
|
|
secondHalfAnimatorSet);
|
|
|
|
|
mAnimator.addListener(new AnimatorListenerAdapter() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationStart(Animator animation) {
|
|
|
|
|
mIsStashed = isStashed;
|
2021-08-17 16:07:22 -07:00
|
|
|
onIsStashed(mIsStashed);
|
2021-06-01 16:54:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
|
mAnimator = null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return mAnimator;
|
|
|
|
|
}
|
2021-07-16 12:15:35 -10:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates and starts a partial stash animation, hinting at the new state that will trigger when
|
|
|
|
|
* long press is detected.
|
|
|
|
|
* @param animateForward Whether we are going towards the new stashed state or returning to the
|
|
|
|
|
* unstashed state.
|
|
|
|
|
*/
|
|
|
|
|
public void startStashHint(boolean animateForward) {
|
2021-09-22 13:58:10 -07:00
|
|
|
if (isStashed() || !supportsManualStashing()) {
|
2021-07-16 12:15:35 -10:00
|
|
|
// Already stashed, no need to hint in that direction.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mIconScaleForStash.animateToValue(
|
|
|
|
|
animateForward ? STASHED_TASKBAR_HINT_SCALE : 1)
|
|
|
|
|
.setDuration(TASKBAR_HINT_STASH_DURATION).start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates and starts a partial unstash animation, hinting at the new state that will trigger
|
|
|
|
|
* when long press is detected.
|
|
|
|
|
* @param animateForward Whether we are going towards the new unstashed state or returning to
|
|
|
|
|
* the stashed state.
|
|
|
|
|
*/
|
|
|
|
|
public void startUnstashHint(boolean animateForward) {
|
|
|
|
|
if (!isStashed()) {
|
|
|
|
|
// Already unstashed, no need to hint in that direction.
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mTaskbarStashedHandleHintScale.animateToValue(
|
|
|
|
|
animateForward ? UNSTASHED_TASKBAR_HANDLE_HINT_SCALE : 1)
|
|
|
|
|
.setDuration(TASKBAR_HINT_STASH_DURATION).start();
|
|
|
|
|
}
|
2021-08-17 16:07:22 -07:00
|
|
|
|
|
|
|
|
private void onIsStashed(boolean isStashed) {
|
|
|
|
|
mControllers.stashedHandleViewController.onIsStashed(isStashed);
|
|
|
|
|
}
|
2021-09-02 22:49:34 -07:00
|
|
|
|
|
|
|
|
public void applyState() {
|
|
|
|
|
applyState(TASKBAR_STASH_DURATION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void applyState(long duration) {
|
2021-09-09 21:18:25 -07:00
|
|
|
mStatePropertyHolder.setState(mState, duration, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Animator applyStateWithoutStart() {
|
|
|
|
|
return applyStateWithoutStart(TASKBAR_STASH_DURATION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Animator applyStateWithoutStart(long duration) {
|
|
|
|
|
return mStatePropertyHolder.setState(mState, duration, false);
|
2021-09-02 22:49:34 -07:00
|
|
|
}
|
|
|
|
|
|
2021-10-07 15:53:32 -07:00
|
|
|
/** Called when some system ui state has changed. (See SYSUI_STATE_... in QuickstepContract) */
|
|
|
|
|
public void updateStateForSysuiFlags(int systemUiStateFlags) {
|
|
|
|
|
updateStateForFlag(FLAG_STASHED_IN_APP_PINNED,
|
|
|
|
|
hasAnyFlag(systemUiStateFlags, SYSUI_STATE_SCREEN_PINNING));
|
|
|
|
|
applyState();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-02 22:49:34 -07:00
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 15:49:19 -07:00
|
|
|
/**
|
|
|
|
|
* Called after updateStateForFlag() and applyState() have been called.
|
|
|
|
|
* @param changedFlags The flags that have changed.
|
|
|
|
|
*/
|
|
|
|
|
private void onStateChangeApplied(int changedFlags) {
|
|
|
|
|
if (hasAnyFlag(changedFlags, FLAGS_STASHED_IN_APP)) {
|
|
|
|
|
mControllers.uiController.onStashedInAppChanged();
|
|
|
|
|
}
|
|
|
|
|
if (hasAnyFlag(changedFlags, FLAGS_STASHED_IN_APP | FLAG_IN_APP)) {
|
|
|
|
|
SystemUiProxy.INSTANCE.get(mActivity)
|
|
|
|
|
.notifyTaskbarStatus(/* visible */ hasAnyFlag(FLAG_IN_APP),
|
|
|
|
|
/* stashed */ isStashedInApp());
|
|
|
|
|
}
|
|
|
|
|
if (hasAnyFlag(changedFlags, FLAG_STASHED_IN_APP_MANUAL)) {
|
|
|
|
|
if (hasAnyFlag(FLAG_STASHED_IN_APP_MANUAL)) {
|
|
|
|
|
mActivity.getStatsLogManager().logger().log(LAUNCHER_TASKBAR_LONGPRESS_HIDE);
|
|
|
|
|
} else {
|
|
|
|
|
mActivity.getStatsLogManager().logger().log(LAUNCHER_TASKBAR_LONGPRESS_SHOW);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-02 22:49:34 -07:00
|
|
|
private class StatePropertyHolder {
|
|
|
|
|
private final IntPredicate mStashCondition;
|
|
|
|
|
|
|
|
|
|
private boolean mIsStashed;
|
2021-10-07 15:49:19 -07:00
|
|
|
private int mPrevFlags;
|
2021-09-02 22:49:34 -07:00
|
|
|
|
|
|
|
|
StatePropertyHolder(IntPredicate stashCondition) {
|
|
|
|
|
mStashCondition = stashCondition;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-09 21:18:25 -07:00
|
|
|
public Animator setState(int flags, long duration, boolean start) {
|
2021-10-07 15:49:19 -07:00
|
|
|
if (mPrevFlags != flags) {
|
|
|
|
|
int changedFlags = mPrevFlags ^ flags;
|
|
|
|
|
onStateChangeApplied(changedFlags);
|
|
|
|
|
mPrevFlags = flags;
|
|
|
|
|
}
|
2021-09-02 22:49:34 -07:00
|
|
|
boolean isStashed = mStashCondition.test(flags);
|
|
|
|
|
if (mIsStashed != isStashed) {
|
|
|
|
|
mIsStashed = isStashed;
|
2021-09-09 21:18:25 -07:00
|
|
|
Animator animator = createAnimToIsStashed(mIsStashed, duration);
|
|
|
|
|
if (start) {
|
|
|
|
|
animator.start();
|
|
|
|
|
}
|
2021-09-02 22:49:34 -07:00
|
|
|
}
|
2021-09-09 21:18:25 -07:00
|
|
|
return mAnimator;
|
2021-09-02 22:49:34 -07:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-01 16:54:07 -07:00
|
|
|
}
|