feat: Add option to clear home screen in settings (#6125)

Signed-off-by: abhixv <abhi.sharma1@hotmail.com>
This commit is contained in:
Abhishek Sharma authored and Pun Butrach committed 2026-01-10 20:51:01 +07:00
1 parent 9898749619
commit 5f3a03f4fb
1577 files changed
+112559 -80244

No files matched your search

@@ -16,6 +16,7 @@
package com.android.launcher3.allapps;
import static com.android.app.animation.Interpolators.DECELERATE_1_7;
import static com.android.app.animation.Interpolators.INSTANT;
import static com.android.app.animation.Interpolators.LINEAR;
import static com.android.launcher3.LauncherAnimUtils.SCALE_PROPERTY;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_Y;
@@ -27,6 +28,7 @@ import static com.android.launcher3.UtilitiesKt.CLIP_CHILDREN_FALSE_MODIFIER;
import static com.android.launcher3.UtilitiesKt.modifyAttributesOnViewTree;
import static com.android.launcher3.UtilitiesKt.restoreAttributesOnViewTree;
import static com.android.launcher3.anim.PropertySetter.NO_ANIM_PROPERTY_SETTER;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_ALL_APPS_BOTTOM_SHEET_FADE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_ALL_APPS_FADE;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_VERTICAL_PROGRESS;
import static com.android.launcher3.util.SystemUiController.FLAG_DARK_NAV;
@@ -34,8 +36,8 @@ import static com.android.launcher3.util.SystemUiController.FLAG_LIGHT_NAV;
import static com.android.launcher3.util.SystemUiController.UI_STATE_ALL_APPS;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.util.FloatProperty;
import android.view.HapticFeedbackConstants;
import android.view.View;
@@ -44,28 +46,28 @@ import android.view.animation.Interpolator;
import androidx.annotation.FloatRange;
import androidx.annotation.Nullable;
import com.android.app.animation.Interpolators;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.Flags;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import com.android.launcher3.anim.AnimatedFloat;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.anim.PropertySetter;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.statemanager.StateManager.StateHandler;
import com.android.launcher3.states.StateAnimationConfig;
import com.android.launcher3.touch.AllAppsSwipeController;
import com.android.launcher3.util.MSDLPlayerWrapper;
import com.android.launcher3.util.MultiPropertyFactory;
import com.android.launcher3.util.MultiPropertyFactory.MultiProperty;
import com.android.launcher3.util.MultiValueAlpha;
import com.android.launcher3.util.ScrollableLayoutManager;
import com.android.launcher3.util.Themes;
import com.android.launcher3.util.VibratorWrapper;
import com.android.launcher3.views.ScrimView;
import com.google.android.msdl.data.model.MSDLToken;
/**
* Handles AllApps view transition.
* 1) Slides all apps view using direct manipulation
@@ -73,88 +75,90 @@ import com.google.android.msdl.data.model.MSDLToken;
* <p/>
* Algorithm:
* If release velocity > THRES1, snap according to the direction of movement.
* If release velocity < THRES1, snap according to either top or bottom depending on whether it's
* If release velocity < THRES1, snap according to either top or bottom
* depending on whether it's
* closer to top or closer to the page indicator.
*/
public class AllAppsTransitionController
implements StateHandler<LauncherState>, OnDeviceProfileChangeListener {
// This constant should match the second derivative of the animator interpolator.
// This constant should match the second derivative of the animator
// interpolator.
public static final float INTERP_COEFF = 1.7f;
public static final int REVERT_SWIPE_ALL_APPS_TO_HOME_ANIMATION_DURATION_MS = 200;
private static final float NAV_BAR_COLOR_FORCE_UPDATE_THRESHOLD = 0.1f;
private static final float SWIPE_DRAG_COMMIT_THRESHOLD =
1 - AllAppsSwipeController.ALL_APPS_STATE_TRANSITION_MANUAL;
private static final float SWIPE_DRAG_COMMIT_THRESHOLD = 1
- AllAppsSwipeController.ALL_APPS_STATE_TRANSITION_MANUAL;
public static final FloatProperty<AllAppsTransitionController> ALL_APPS_PROGRESS =
new FloatProperty<AllAppsTransitionController>("allAppsProgress") {
public static final FloatProperty<AllAppsTransitionController> ALL_APPS_PROGRESS = new FloatProperty<AllAppsTransitionController>(
"allAppsProgress") {
@Override
public Float get(AllAppsTransitionController controller) {
return controller.mProgress;
}
@Override
public Float get(AllAppsTransitionController controller) {
return controller.mProgress;
}
@Override
public void setValue(AllAppsTransitionController controller, float progress) {
controller.setProgress(progress);
}
};
@Override
public void setValue(AllAppsTransitionController controller, float progress) {
controller.setProgress(progress);
}
};
private static final float ALL_APPS_PULL_BACK_TRANSLATION_DEFAULT = 0f;
public static final FloatProperty<AllAppsTransitionController> ALL_APPS_PULL_BACK_TRANSLATION =
new FloatProperty<AllAppsTransitionController>("allAppsPullBackTranslation") {
public static final FloatProperty<AllAppsTransitionController> ALL_APPS_PULL_BACK_TRANSLATION = new FloatProperty<AllAppsTransitionController>(
"allAppsPullBackTranslation") {
@Override
public Float get(AllAppsTransitionController controller) {
if (controller.mShouldShowAllAppsOnSheet) {
return controller.mAppsView.getActiveRecyclerView().getTranslationY();
} else {
return controller.getAppsViewPullbackTranslationY().getValue();
}
}
@Override
public Float get(AllAppsTransitionController controller) {
if (controller.mIsTablet) {
return controller.mAppsView.getActiveRecyclerView().getTranslationY();
} else {
return controller.getAppsViewPullbackTranslationY().getValue();
}
}
@Override
public void setValue(AllAppsTransitionController controller, float translation) {
if (controller.mShouldShowAllAppsOnSheet) {
controller.mAppsView.getActiveRecyclerView().setTranslationY(translation);
controller.getAppsViewPullbackTranslationY().setValue(
ALL_APPS_PULL_BACK_TRANSLATION_DEFAULT);
} else {
controller.getAppsViewPullbackTranslationY().setValue(translation);
controller.mAppsView.getActiveRecyclerView().setTranslationY(
ALL_APPS_PULL_BACK_TRANSLATION_DEFAULT);
}
}
};
@Override
public void setValue(AllAppsTransitionController controller, float translation) {
if (controller.mIsTablet) {
controller.mAppsView.getActiveRecyclerView().setTranslationY(translation);
controller.getAppsViewPullbackTranslationY().setValue(
ALL_APPS_PULL_BACK_TRANSLATION_DEFAULT);
} else {
controller.getAppsViewPullbackTranslationY().setValue(translation);
controller.mAppsView.getActiveRecyclerView().setTranslationY(
ALL_APPS_PULL_BACK_TRANSLATION_DEFAULT);
}
}
};
private static final float ALL_APPS_PULL_BACK_ALPHA_DEFAULT = 1f;
public static final FloatProperty<AllAppsTransitionController> ALL_APPS_PULL_BACK_ALPHA =
new FloatProperty<AllAppsTransitionController>("allAppsPullBackAlpha") {
public static final FloatProperty<AllAppsTransitionController> ALL_APPS_PULL_BACK_ALPHA = new FloatProperty<AllAppsTransitionController>(
"allAppsPullBackAlpha") {
@Override
public Float get(AllAppsTransitionController controller) {
if (controller.mShouldShowAllAppsOnSheet) {
return controller.mAppsView.getActiveRecyclerView().getAlpha();
} else {
return controller.getAppsViewPullbackAlpha().getValue();
}
}
@Override
public Float get(AllAppsTransitionController controller) {
if (controller.mIsTablet) {
return controller.mAppsView.getActiveRecyclerView().getAlpha();
} else {
return controller.getAppsViewPullbackAlpha().getValue();
}
}
@Override
public void setValue(AllAppsTransitionController controller, float alpha) {
if (controller.mShouldShowAllAppsOnSheet) {
controller.mAppsView.getActiveRecyclerView().setAlpha(alpha);
controller.getAppsViewPullbackAlpha().setValue(
ALL_APPS_PULL_BACK_ALPHA_DEFAULT);
} else {
controller.getAppsViewPullbackAlpha().setValue(alpha);
controller.mAppsView.getActiveRecyclerView().setAlpha(
ALL_APPS_PULL_BACK_ALPHA_DEFAULT);
}
}
};
@Override
public void setValue(AllAppsTransitionController controller, float alpha) {
if (controller.mIsTablet) {
controller.mAppsView.getActiveRecyclerView().setAlpha(alpha);
controller.getAppsViewPullbackAlpha().setValue(
ALL_APPS_PULL_BACK_ALPHA_DEFAULT);
} else {
controller.getAppsViewPullbackAlpha().setValue(alpha);
controller.mAppsView.getActiveRecyclerView().setAlpha(
ALL_APPS_PULL_BACK_ALPHA_DEFAULT);
}
}
};
private static final int INDEX_APPS_VIEW_PROGRESS = 0;
private static final int INDEX_APPS_VIEW_PULLBACK = 1;
@@ -166,41 +170,45 @@ public class AllAppsTransitionController
private final AnimatedFloat mAllAppScale = new AnimatedFloat(this::onScaleProgressChanged);
private final int mNavScrimFlag;
@Nullable private Animator.AnimatorListener mAllAppsSearchBackAnimationListener;
@Nullable
private Animator.AnimatorListener mAllAppsSearchBackAnimationListener;
private boolean mIsVerticalLayout;
private boolean mShouldShowAllAppsOnSheet;
// Animation in this class is controlled by a single variable {@link mProgress}.
// Visually, it represents top y coordinate of the all apps container if multiplied with
// Visually, it represents top y coordinate of the all apps container if
// multiplied with
// {@link mShiftRange}.
// When {@link mProgress} is 0, all apps container is pulled up.
// When {@link mProgress} is 1, all apps container is pulled down.
private float mShiftRange; // changes depending on the orientation
private float mProgress; // [0, 1], mShiftRange * mProgress = shiftCurrent
private float mShiftRange; // changes depending on the orientation
private float mProgress; // [0, 1], mShiftRange * mProgress = shiftCurrent
private ScrimView mScrimView;
private MultiValueAlpha mAppsViewAlpha;
private MultiPropertyFactory<View> mAppsViewTranslationY;
private boolean mIsTablet;
private boolean mHasScaleEffect;
private final MSDLPlayerWrapper mMSDLPlayerWrapper;
private final VibratorWrapper mVibratorWrapper;
public AllAppsTransitionController(Launcher l) {
mLauncher = l;
DeviceProfile dp = mLauncher.getDeviceProfile();
mProgress = 1f;
mIsVerticalLayout = dp.isVerticalBarLayout();
mShouldShowAllAppsOnSheet = dp.shouldShowAllAppsOnSheet();
mIsTablet = dp.isTablet;
mNavScrimFlag = Themes.getAttrBoolean(l, R.attr.isMainColorDark)
? FLAG_DARK_NAV : FLAG_LIGHT_NAV;
? FLAG_DARK_NAV
: FLAG_LIGHT_NAV;
setShiftRange(dp.allAppsShiftRange);
mAllAppScale.value = 1;
mLauncher.addOnDeviceProfileChangeListener(this);
mMSDLPlayerWrapper = MSDLPlayerWrapper.INSTANCE.get(mLauncher.getApplicationContext());
mVibratorWrapper = VibratorWrapper.INSTANCE.get(mLauncher.getApplicationContext());
}
public float getShiftRange() {
@@ -217,21 +225,22 @@ public class AllAppsTransitionController
mLauncher.getWorkspace().getPageIndicator().setTranslationY(0);
}
mShouldShowAllAppsOnSheet = dp.shouldShowAllAppsOnSheet();
mIsTablet = dp.isTablet;
}
/**
* Note this method should not be called outside this class. This is public because it is used
* Note this method should not be called outside this class. This is public
* because it is used
* in xml-based animations which also handle updating the appropriate UI.
*
* @param progress value between 0 and 1, 0 shows all apps and 1 shows workspace
* @see #setState(LauncherState)
* @see #setStateWithAnimation(LauncherState, StateAnimationConfig, PendingAnimation)
* @see #setStateWithAnimation(LauncherState, StateAnimationConfig,
* PendingAnimation)
*/
public void setProgress(float progress) {
mProgress = progress;
boolean fromBackground =
mLauncher.getStateManager().getCurrentStableState() == BACKGROUND_APP;
boolean fromBackground = mLauncher.getStateManager().getCurrentStableState() == BACKGROUND_APP;
// Allow apps panel to shift the full screen if coming from another app.
float shiftRange = fromBackground ? mLauncher.getDeviceProfile().heightPx : mShiftRange;
getAppsViewProgressTranslationY().setValue(mProgress * shiftRange);
@@ -264,7 +273,8 @@ public class AllAppsTransitionController
}
/**
* Sets the vertical transition progress to {@param state} and updates all the dependent UI
* Sets the vertical transition progress to {@param state} and updates all the
* dependent UI
* accordingly.
*/
@Override
@@ -280,9 +290,10 @@ public class AllAppsTransitionController
return;
}
float deceleratedProgress = Interpolators.BACK_GESTURE.getInterpolation(backProgress);
float scaleProgress = ScrollableLayoutManager.PREDICTIVE_BACK_MIN_SCALE
+ (1 - ScrollableLayoutManager.PREDICTIVE_BACK_MIN_SCALE)
* (1 - backProgress);
* (1 - deceleratedProgress);
mAllAppScale.updateValue(scaleProgress);
}
@@ -290,16 +301,18 @@ public class AllAppsTransitionController
private void onScaleProgressChanged() {
final float scaleProgress = mAllAppScale.value;
SCALE_PROPERTY.set(mLauncher.getAppsView(), scaleProgress);
if (!mLauncher.getAppsView().isSearching()
|| !mLauncher.getDeviceProfile().shouldShowAllAppsOnSheet()) {
if (!mLauncher.getAppsView().isSearching() || !mLauncher.getDeviceProfile().isTablet) {
mLauncher.getScrimView().setScrimHeaderScale(scaleProgress);
}
AllAppsRecyclerView rv = mLauncher.getAppsView().getActiveRecyclerView();
// Disable view clipping from all apps' RecyclerView up to all apps view during scale
// animation, and vice versa. The goal is to display extra roll(s) app icons (rendered in
// {@link AppsGridLayoutManager#calculateExtraLayoutSpace}) during scale animation.
// Disable view clipping from all apps' RecyclerView up to all apps view during
// scale
// animation, and vice versa. The goal is to display extra roll(s) app icons
// (rendered in
// {@link AppsGridLayoutManager#calculateExtraLayoutSpace}) during scale
// animation.
boolean hasScaleEffect = scaleProgress < 1f;
if (hasScaleEffect != mHasScaleEffect) {
mHasScaleEffect = hasScaleEffect;
@@ -313,13 +326,17 @@ public class AllAppsTransitionController
}
}
/** Set {@link Animator.AnimatorListener} for scaling all apps scale to 1 animation. */
/**
* Set {@link Animator.AnimatorListener} for scaling all apps scale to 1
* animation.
*/
public void setAllAppsSearchBackAnimationListener(Animator.AnimatorListener listener) {
mAllAppsSearchBackAnimationListener = listener;
}
/**
* Animate all apps view to 1f scale. This is called when backing (exiting) from all apps
* Animate all apps view to 1f scale. This is called when backing (exiting) from
* all apps
* search view to all apps view.
*/
public void animateAllAppsToNoScale() {
@@ -335,12 +352,16 @@ public class AllAppsTransitionController
}
/**
* Creates an animation which updates the vertical transition progress and updates all the
* Creates an animation which updates the vertical transition progress and
* updates all the
* dependent UI using various animation events
*
* This method also dictates where along the progress the haptics should be played. As the user
* scrolls up from workspace or down from AllApps, a drag haptic is being played until the
* commit point where it plays a commit haptic. Where we play the haptics differs when going
* This method also dictates where along the progress the haptics should be
* played. As the user
* scrolls up from workspace or down from AllApps, a drag haptic is being played
* until the
* commit point where it plays a commit haptic. Where we play the haptics
* differs when going
* from workspace -> allApps and vice versa.
*/
@Override
@@ -356,6 +377,22 @@ public class AllAppsTransitionController
});
}
if (FeatureFlags.ENABLE_PREMIUM_HAPTICS_ALL_APPS.get() && config.isUserControlled()
&& Utilities.ATLEAST_S) {
if (toState == ALL_APPS) {
builder.addOnFrameListener(
new VibrationAnimatorUpdateListener(this, mVibratorWrapper,
SWIPE_DRAG_COMMIT_THRESHOLD, 1));
} else {
builder.addOnFrameListener(
new VibrationAnimatorUpdateListener(this, mVibratorWrapper,
0, SWIPE_DRAG_COMMIT_THRESHOLD));
}
builder.addEndListener((unused) -> {
mVibratorWrapper.cancelVibrate();
});
}
float targetProgress = toState.getVerticalProgress(mLauncher);
if (Float.compare(mProgress, targetProgress) == 0) {
setAlphas(toState, config, builder);
@@ -367,28 +404,15 @@ public class AllAppsTransitionController
Interpolator verticalProgressInterpolator = config.getInterpolator(ANIM_VERTICAL_PROGRESS,
config.isUserControlled() ? LINEAR : DECELERATE_1_7);
Animator anim = createSpringAnimation(mProgress, targetProgress);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
setProgress(targetProgress);
}
});
anim.setInterpolator(verticalProgressInterpolator);
builder.add(anim);
setAlphas(toState, config, builder);
// This controls both haptics for tapping on QSB and going to all apps.
if (ALL_APPS.equals(toState) && mLauncher.isInState(NORMAL)) {
if (Flags.msdlFeedback()) {
if (config.isUserControlled()) {
mMSDLPlayerWrapper.playToken(MSDLToken.SWIPE_THRESHOLD_INDICATOR);
} else {
mMSDLPlayerWrapper.playToken(MSDLToken.TAP_HIGH_EMPHASIS);
}
} else {
mLauncher.getAppsView().performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
}
if (ALL_APPS.equals(toState) && mLauncher.isInState(NORMAL) &&
!FeatureFlags.ENABLE_PREMIUM_HAPTICS_ALL_APPS.get()) {
mLauncher.getAppsView().performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
}
}
@@ -409,6 +433,10 @@ public class AllAppsTransitionController
setter.setFloat(getAppsViewPullbackAlpha(), MultiPropertyFactory.MULTI_PROPERTY_VALUE,
hasAllAppsContent ? 1 : 0, allAppsFade);
setter.setFloat(mLauncher.getAppsView(),
ActivityAllAppsContainerView.BOTTOM_SHEET_ALPHA, hasAllAppsContent ? 1 : 0,
config.getInterpolator(ANIM_ALL_APPS_BOTTOM_SHEET_FADE, INSTANT));
boolean shouldProtectHeader = !config.hasAnimationFlag(StateAnimationConfig.SKIP_SCRIM)
&& (ALL_APPS == state || mLauncher.getStateManager().getState() == ALL_APPS);
mScrimView.setDrawingController(shouldProtectHeader ? mAppsView : null);
@@ -422,7 +450,8 @@ public class AllAppsTransitionController
mAppsView = appsView;
mAppsView.setScrimView(scrimView);
mAppsViewAlpha = new MultiValueAlpha(mAppsView, APPS_VIEW_INDEX_COUNT, View.GONE);
mAppsViewAlpha = new MultiValueAlpha(mAppsView, APPS_VIEW_INDEX_COUNT,
FeatureFlags.ALL_APPS_GONE_VISIBILITY.get() ? View.GONE : View.INVISIBLE);
mAppsViewAlpha.setUpdateVisibility(true);
mAppsViewTranslationY = new MultiPropertyFactory<>(
mAppsView, VIEW_TRANSLATE_Y, APPS_VIEW_INDEX_COUNT, Float::sum);
@@ -434,4 +463,49 @@ public class AllAppsTransitionController
public void setShiftRange(float shiftRange) {
mShiftRange = shiftRange;
}
/**
* This VibrationAnimatorUpdateListener class takes in four parameters, a
* controller, start
* threshold, end threshold, and a Vibrator wrapper. We use the progress given
* by the controller
* as it gives an accurate progress that dictates where the vibrator should
* vibrate.
* Note: once the user begins a gesture and does the commit haptic, there should
* not be anymore
* haptics played for that gesture.
*/
private static class VibrationAnimatorUpdateListener implements
ValueAnimator.AnimatorUpdateListener {
private final VibratorWrapper mVibratorWrapper;
private final AllAppsTransitionController mController;
private final float mStartThreshold;
private final float mEndThreshold;
private boolean mHasCommitted;
VibrationAnimatorUpdateListener(AllAppsTransitionController controller,
VibratorWrapper vibratorWrapper, float startThreshold,
float endThreshold) {
mController = controller;
mVibratorWrapper = vibratorWrapper;
mStartThreshold = startThreshold;
mEndThreshold = endThreshold;
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
if (mHasCommitted) {
return;
}
float currentProgress = AllAppsTransitionController.ALL_APPS_PROGRESS.get(mController);
if (currentProgress > mStartThreshold && currentProgress < mEndThreshold) {
mVibratorWrapper.vibrateForDragTexture();
} else if (!(currentProgress == 0 || currentProgress == 1)) {
// This check guards against committing at the location of the start of the
// gesture
mVibratorWrapper.vibrateForDragCommit();
mHasCommitted = true;
}
}
}
}