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
2025-12-20 03:26:30 +05:30
committed by Pun Butrach
parent 9898749619
commit 5f3a03f4fb
1577 changed files with 112563 additions and 80248 deletions
@@ -19,7 +19,6 @@ package com.android.launcher3.statehandlers;
import static com.android.app.animation.Interpolators.LINEAR;
import static com.android.launcher3.states.StateAnimationConfig.ANIM_DEPTH;
import static com.android.launcher3.states.StateAnimationConfig.SKIP_DEPTH_CONTROLLER;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.MultiPropertyFactory.MULTI_PROPERTY_VALUE;
import android.animation.Animator;
@@ -30,8 +29,6 @@ import android.view.View;
import android.view.ViewRootImpl;
import android.view.ViewTreeObserver;
import androidx.annotation.VisibleForTesting;
import com.android.launcher3.BaseActivity;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
@@ -40,11 +37,11 @@ import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.statemanager.StateManager.StateHandler;
import com.android.launcher3.states.StateAnimationConfig;
import com.android.quickstep.util.BaseDepthController;
import com.patrykmichalik.opto.core.PreferenceExtensionsKt;
import java.io.PrintWriter;
import java.util.function.Consumer;
import com.patrykmichalik.opto.core.PreferenceExtensionsKt;
import app.lawnchair.compat.LawnchairQuickstepCompat;
import app.lawnchair.preferences2.PreferenceManager2;
@@ -53,8 +50,8 @@ import app.lawnchair.preferences2.PreferenceManager2;
*/
public class DepthController extends BaseDepthController implements StateHandler<LauncherState>,
BaseActivity.MultiWindowModeChangedListener {
@VisibleForTesting
final ViewTreeObserver.OnDrawListener mOnDrawListener = this::onLauncherDraw;
private final ViewTreeObserver.OnDrawListener mOnDrawListener = this::onLauncherDraw;
private final Consumer<Boolean> mCrossWindowBlurListener = this::setCrossWindowBlursEnabled;
@@ -65,10 +62,6 @@ public class DepthController extends BaseDepthController implements StateHandler
private View.OnAttachStateChangeListener mOnAttachListener;
// Ensure {@link mOnDrawListener} is added only once to avoid spamming DragLayer's mRunQueue
// via {@link View#post(Runnable)}
private boolean mIsOnDrawListenerAdded = false;
private final boolean mEnableDepth;
public DepthController(Launcher l) {
@@ -82,46 +75,41 @@ public class DepthController extends BaseDepthController implements StateHandler
ViewRootImpl viewRootImpl = view.getViewRootImpl();
try {
if (Utilities.ATLEAST_Q) {
setBaseSurface(viewRootImpl != null ? viewRootImpl.getSurfaceControl() : null);
setSurface(viewRootImpl != null ? viewRootImpl.getSurfaceControl() : null);
}
} catch (Throwable t) {
// LC-Ignored
// Ignore any exceptions
}
view.post(this::removeOnDrawListener);
view.post(() -> view.getViewTreeObserver().removeOnDrawListener(mOnDrawListener));
}
private void ensureDependencies() {
View rootView = mLauncher.getRootView();
if (rootView == null) {
return;
}
if (mOnAttachListener != null) {
return;
}
mOnAttachListener = new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View view) {
try {
UI_HELPER_EXECUTOR.execute(() ->
CrossWindowBlurListeners.getInstance().addListener(
mLauncher.getMainExecutor(), mCrossWindowBlurListener));
} catch (Throwable t) {
// LC-Ignored
if (mLauncher.getRootView() != null && mOnAttachListener == null) {
View rootView = mLauncher.getRootView();
mOnAttachListener = new View.OnAttachStateChangeListener() {
@Override
public void onViewAttachedToWindow(View view) {
try {
CrossWindowBlurListeners.getInstance().addListener(mLauncher.getMainExecutor(),
mCrossWindowBlurListener);
} catch (Throwable t) {
// Ignore
}
mLauncher.getScrimView().addOpaquenessListener(mOpaquenessListener);
// To handle the case where window token is invalid during last setDepth call.
applyDepthAndBlur();
}
mLauncher.getScrimView().addOpaquenessListener(mOpaquenessListener);
// To handle the case where window token is invalid during last setDepth call.
applyDepthAndBlur();
@Override
public void onViewDetachedFromWindow(View view) {
removeSecondaryListeners();
}
};
rootView.addOnAttachStateChangeListener(mOnAttachListener);
if (rootView.isAttachedToWindow()) {
mOnAttachListener.onViewAttachedToWindow(rootView);
}
@Override
public void onViewDetachedFromWindow(View view) {
removeSecondaryListeners();
}
};
rootView.addOnAttachStateChangeListener(mOnAttachListener);
if (rootView.isAttachedToWindow()) {
mOnAttachListener.onViewAttachedToWindow(rootView);
}
}
@@ -138,12 +126,12 @@ public class DepthController extends BaseDepthController implements StateHandler
}
private void removeSecondaryListeners() {
try {
UI_HELPER_EXECUTOR.execute(() ->
CrossWindowBlurListeners.getInstance()
.removeListener(mCrossWindowBlurListener));
} catch (Throwable t) {
// LC-Ignored
if (mCrossWindowBlurListener != null) {
try {
CrossWindowBlurListeners.getInstance().removeListener(mCrossWindowBlurListener);
} catch (Throwable t) {
// Ignore
}
}
if (mOpaquenessListener != null) {
mLauncher.getScrimView().removeOpaquenessListener(mOpaquenessListener);
@@ -155,10 +143,10 @@ public class DepthController extends BaseDepthController implements StateHandler
*/
public void setActivityStarted(boolean isStarted) {
if (isStarted) {
addOnDrawListener();
mLauncher.getDragLayer().getViewTreeObserver().addOnDrawListener(mOnDrawListener);
} else {
removeOnDrawListener();
setBaseSurface(null);
mLauncher.getDragLayer().getViewTreeObserver().removeOnDrawListener(mOnDrawListener);
setSurface(null);
}
}
@@ -170,13 +158,13 @@ public class DepthController extends BaseDepthController implements StateHandler
stateDepth.setValue(toState.getDepth(mLauncher));
if (toState == LauncherState.BACKGROUND_APP) {
addOnDrawListener();
mLauncher.getDragLayer().getViewTreeObserver().addOnDrawListener(mOnDrawListener);
}
}
@Override
public void setStateWithAnimation(LauncherState toState, StateAnimationConfig config,
PendingAnimation animation) {
PendingAnimation animation) {
if (config.hasAnimationFlag(SKIP_DEPTH_CONTROLLER)
|| mIgnoreStateChangesDuringMultiWindowAnimation) {
return;
@@ -195,30 +183,14 @@ public class DepthController extends BaseDepthController implements StateHandler
super.applyDepthAndBlur();
}
} catch (Throwable t) {
// LC-Ignored
// Ignore
}
}
@Override
protected void onInvalidSurface() {
// Lets wait for surface to become valid again
addOnDrawListener();
}
private void addOnDrawListener() {
if (mIsOnDrawListenerAdded) {
return;
}
mLauncher.getDragLayer().getViewTreeObserver().addOnDrawListener(mOnDrawListener);
mIsOnDrawListenerAdded = true;
}
private void removeOnDrawListener() {
if (!mIsOnDrawListenerAdded) {
return;
}
mLauncher.getDragLayer().getViewTreeObserver().removeOnDrawListener(mOnDrawListener);
mIsOnDrawListenerAdded = false;
}
@Override
@@ -226,7 +198,7 @@ public class DepthController extends BaseDepthController implements StateHandler
mIgnoreStateChangesDuringMultiWindowAnimation = true;
ObjectAnimator mwAnimation = ObjectAnimator.ofFloat(stateDepth, MULTI_PROPERTY_VALUE,
mLauncher.getStateManager().getState().getDepth(mLauncher, isInMultiWindowMode))
mLauncher.getStateManager().getState().getDepth(mLauncher, isInMultiWindowMode))
.setDuration(300);
mwAnimation.addListener(new AnimatorListenerAdapter() {
@Override
@@ -242,8 +214,7 @@ public class DepthController extends BaseDepthController implements StateHandler
writer.println(prefix + "DepthController");
writer.println(prefix + "\tmMaxBlurRadius=" + mMaxBlurRadius);
writer.println(prefix + "\tmCrossWindowBlursEnabled=" + mCrossWindowBlursEnabled);
writer.println(prefix + "\tmBaseSurface=" + mBaseSurface);
writer.println(prefix + "\tmBaseSurfaceOverride=" + mBaseSurfaceOverride);
writer.println(prefix + "\tmSurface=" + mSurface);
writer.println(prefix + "\tmStateDepth=" + stateDepth.getValue());
writer.println(prefix + "\tmWidgetDepth=" + widgetDepth.getValue());
writer.println(prefix + "\tmCurrentBlur=" + mCurrentBlur);
@@ -253,4 +224,4 @@ public class DepthController extends BaseDepthController implements StateHandler
writer.println(prefix + "\tmPauseBlurs=" + mPauseBlurs);
writer.println(prefix + "\tmWaitingOnSurfaceValidity=" + mWaitingOnSurfaceValidity);
}
}
}