From b10cedd21c03f62ba89cc6496d8afde09b3136d1 Mon Sep 17 00:00:00 2001 From: minch Date: Fri, 21 Feb 2025 00:46:12 +0000 Subject: [PATCH] Handle AddDesktopButton's visibility in different launcher states Introduce [ADD_DESK_BUTTON] in LauncherState and change the button's visibility across different launcher states. E.g., the button shouldn't be visible in the quick switch. Bug: 389209338 Flag: com.android.window.flags.enable_multiple_desktops_frontend Flag: com.android.window.flags.enable_multiple_desktops_backend Test: 1. Swipe up from home, the button shown util in overview. 2. Swipe up from the fullscreen app, the button is invisible util release the finger. 3. The button is invisible in quick switch. 4. All the above tested with NexusLauncher and Nova launcher, which is a 3rd launcher. 5. Tested with gesture and 3-finger swipe on the touchpad. 6. Both the ClearAllButton and AddDesktopButton are not visibile when in select mode. Change-Id: I54e11d4d03401be68b5b67a6f591edd737c9ea30 --- .../uioverrides/RecentsViewStateController.kt | 15 +++++++++++---- .../uioverrides/states/BackgroundAppState.java | 3 ++- .../states/OverviewModalTaskState.java | 2 +- .../uioverrides/states/OverviewState.java | 4 ++-- .../FallbackRecentsStateController.java | 6 ++++++ .../quickstep/fallback/RecentsState.java | 13 +++++++++++-- .../quickstep/views/AddDesktopButton.kt | 18 ++++++++++++++++++ .../android/quickstep/views/RecentsView.java | 8 ++++++-- src/com/android/launcher3/LauncherState.java | 1 + 9 files changed, 58 insertions(+), 12 deletions(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.kt b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.kt index cca8bf8e17..04e1905578 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.kt +++ b/quickstep/src/com/android/launcher3/uioverrides/RecentsViewStateController.kt @@ -27,17 +27,16 @@ import com.android.launcher3.anim.AnimatedFloat import com.android.launcher3.anim.AnimatorListeners.forSuccessCallback import com.android.launcher3.anim.PendingAnimation import com.android.launcher3.anim.PropertySetter -import com.android.launcher3.logging.StatsLogManager.LauncherEvent import com.android.launcher3.statemanager.StateManager.StateHandler import com.android.launcher3.states.StateAnimationConfig import com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_ACTIONS_FADE import com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_FADE import com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_MODAL import com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_SCALE -import com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_SPLIT_SELECT_INSTRUCTIONS_FADE import com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_X import com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_Y import com.android.launcher3.states.StateAnimationConfig.SKIP_OVERVIEW +import com.android.launcher3.util.MultiPropertyFactory.MULTI_PROPERTY_VALUE import com.android.quickstep.util.AnimUtils import com.android.quickstep.views.ClearAllButton import com.android.quickstep.views.RecentsView @@ -226,8 +225,8 @@ class RecentsViewStateController(private val launcher: QuickstepLauncher) : builder: PendingAnimation, animate: Boolean, ) { - val goingToOverviewFromWorkspaceContextual = toState == LauncherState.OVERVIEW && - launcher.isSplitSelectionActive + val goingToOverviewFromWorkspaceContextual = + toState == LauncherState.OVERVIEW && launcher.isSplitSelectionActive if ( toState != LauncherState.OVERVIEW_SPLIT_SELECT && !goingToOverviewFromWorkspaceContextual @@ -302,6 +301,14 @@ class RecentsViewStateController(private val launcher: QuickstepLauncher) : overviewButtonAlpha, config.getInterpolator(ANIM_OVERVIEW_ACTIONS_FADE, LINEAR), ) + recentsView.addDeskButton?.let { + propertySetter.setFloat( + it.visibilityAlphaProperty, + MULTI_PROPERTY_VALUE, + if (state.areElementsVisible(launcher, LauncherState.ADD_DESK_BUTTON)) 1f else 0f, + LINEAR, + ) + } } private fun getOverviewInterpolator(fromState: LauncherState, toState: LauncherState) = diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java b/quickstep/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java index ca388c66e5..b1196af0ed 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/BackgroundAppState.java @@ -77,7 +77,8 @@ public class BackgroundAppState extends OverviewState { return super.getVisibleElements(launcher) & ~OVERVIEW_ACTIONS & ~CLEAR_ALL_BUTTON - & ~VERTICAL_SWIPE_INDICATOR; + & ~VERTICAL_SWIPE_INDICATOR + & ~ADD_DESK_BUTTON; } @Override diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewModalTaskState.java b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewModalTaskState.java index 80fc5fa391..0c0b4fd203 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewModalTaskState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewModalTaskState.java @@ -45,7 +45,7 @@ public class OverviewModalTaskState extends OverviewState { @Override public int getVisibleElements(Launcher launcher) { - return OVERVIEW_ACTIONS | CLEAR_ALL_BUTTON; + return OVERVIEW_ACTIONS; } @Override diff --git a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java index 15216febd5..5fdedccf99 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java +++ b/quickstep/src/com/android/launcher3/uioverrides/states/OverviewState.java @@ -110,7 +110,7 @@ public class OverviewState extends LauncherState { @Override public int getVisibleElements(Launcher launcher) { - int elements = CLEAR_ALL_BUTTON | OVERVIEW_ACTIONS; + int elements = CLEAR_ALL_BUTTON | OVERVIEW_ACTIONS | ADD_DESK_BUTTON; DeviceProfile dp = launcher.getDeviceProfile(); boolean showFloatingSearch; if (dp.isPhone) { @@ -124,7 +124,7 @@ public class OverviewState extends LauncherState { elements |= FLOATING_SEARCH_BAR; } if (launcher.isSplitSelectionActive()) { - elements &= ~CLEAR_ALL_BUTTON; + elements &= ~CLEAR_ALL_BUTTON & ~ADD_DESK_BUTTON; } return elements; } diff --git a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java index 56dd696550..537092f8f4 100644 --- a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java +++ b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java @@ -26,6 +26,7 @@ import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TR import static com.android.launcher3.states.StateAnimationConfig.ANIM_OVERVIEW_TRANSLATE_Y; import static com.android.launcher3.states.StateAnimationConfig.ANIM_SCRIM_FADE; import static com.android.launcher3.states.StateAnimationConfig.SKIP_OVERVIEW; +import static com.android.launcher3.util.MultiPropertyFactory.MULTI_PROPERTY_VALUE; import static com.android.quickstep.fallback.RecentsState.OVERVIEW_SPLIT_SELECT; import static com.android.quickstep.views.RecentsView.ADJACENT_PAGE_HORIZONTAL_OFFSET; import static com.android.quickstep.views.RecentsView.DESKTOP_CAROUSEL_DETACH_PROGRESS; @@ -99,6 +100,11 @@ public class FallbackRecentsStateController implements StateHandler { private static final int FLAG_RECENTS_VIEW_VISIBLE = BaseState.getFlag(7); private static final int FLAG_TASK_THUMBNAIL_SPLASH = BaseState.getFlag(8); private static final int FLAG_DETACH_DESKTOP_CAROUSEL = BaseState.getFlag(9); + private static final int FLAG_ADD_DESK_BUTTON = BaseState.getFlag(10); private static final RecentsState[] sAllStates = new RecentsState[6]; public static final RecentsState DEFAULT = new RecentsState(0, FLAG_DISABLE_RESTORE | FLAG_CLEAR_ALL_BUTTON | FLAG_OVERVIEW_ACTIONS | FLAG_SHOW_AS_GRID - | FLAG_SCRIM | FLAG_LIVE_TILE | FLAG_RECENTS_VIEW_VISIBLE); + | FLAG_SCRIM | FLAG_LIVE_TILE | FLAG_RECENTS_VIEW_VISIBLE + | FLAG_ADD_DESK_BUTTON); public static final RecentsState MODAL_TASK = new ModalState(1, - FLAG_DISABLE_RESTORE | FLAG_CLEAR_ALL_BUTTON | FLAG_OVERVIEW_ACTIONS | FLAG_MODAL + FLAG_DISABLE_RESTORE | FLAG_OVERVIEW_ACTIONS | FLAG_MODAL | FLAG_SHOW_AS_GRID | FLAG_SCRIM | FLAG_LIVE_TILE | FLAG_RECENTS_VIEW_VISIBLE); public static final RecentsState BACKGROUND_APP = new BackgroundAppState(2, FLAG_DISABLE_RESTORE | FLAG_NON_INTERACTIVE | FLAG_FULL_SCREEN @@ -121,6 +123,13 @@ public class RecentsState implements BaseState { return hasFlag(FLAG_CLEAR_ALL_BUTTON); } + /** + * For this state, whether add desk button should be shown. + */ + public boolean hasAddDeskButton() { + return hasFlag(FLAG_ADD_DESK_BUTTON); + } + /** * For this state, whether overview actions should be shown. */ diff --git a/quickstep/src/com/android/quickstep/views/AddDesktopButton.kt b/quickstep/src/com/android/quickstep/views/AddDesktopButton.kt index 99437709de..244c3b2800 100644 --- a/quickstep/src/com/android/quickstep/views/AddDesktopButton.kt +++ b/quickstep/src/com/android/quickstep/views/AddDesktopButton.kt @@ -20,10 +20,12 @@ import android.content.Context import android.graphics.Canvas import android.graphics.Rect import android.util.AttributeSet +import android.view.View import android.widget.ImageButton import com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X import com.android.launcher3.R import com.android.launcher3.util.MultiPropertyFactory +import com.android.launcher3.util.MultiValueAlpha import com.android.quickstep.util.BorderAnimator import com.android.quickstep.util.BorderAnimator.Companion.createSimpleBorderAnimator @@ -34,6 +36,22 @@ import com.android.quickstep.util.BorderAnimator.Companion.createSimpleBorderAni class AddDesktopButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ImageButton(context, attrs) { + private enum class Alpha { + CONTENT, + VISIBILITY, + } + + private val addDeskButtonAlpha = MultiValueAlpha(this, Alpha.entries.size) + + var contentAlpha + set(value) { + addDeskButtonAlpha.get(Alpha.CONTENT.ordinal).value = value + } + get() = addDeskButtonAlpha.get(Alpha.CONTENT.ordinal).value + + val visibilityAlphaProperty: MultiPropertyFactory.MultiProperty + get() = addDeskButtonAlpha.get(Alpha.VISIBILITY.ordinal) + private enum class TranslationX { GRID, OFFSET, diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index d17dfb831f..6b91df1b95 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -4762,9 +4762,8 @@ public abstract class RecentsView< } mClearAllButton.setContentAlpha(mContentAlpha); - // TODO(b/389209338): Handle the visibility of the `mAddDesktopButton`. if (mAddDesktopButton != null) { - mAddDesktopButton.setAlpha(mContentAlpha); + mAddDesktopButton.setContentAlpha(mContentAlpha); } int alphaInt = Math.round(alpha * 255); mEmptyMessagePaint.setAlpha(alphaInt); @@ -6329,6 +6328,11 @@ public abstract class RecentsView< return mClearAllButton; } + @Nullable + public AddDesktopButton getAddDeskButton() { + return mAddDesktopButton; + } + /** * @return How many pixels the running task is offset on the currently laid out dominant axis. */ diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java index 8c6555e9a9..78ad04bf05 100644 --- a/src/com/android/launcher3/LauncherState.java +++ b/src/com/android/launcher3/LauncherState.java @@ -70,6 +70,7 @@ public abstract class LauncherState implements BaseState { public static final int WORKSPACE_PAGE_INDICATOR = 1 << 5; public static final int SPLIT_PLACHOLDER_VIEW = 1 << 6; public static final int FLOATING_SEARCH_BAR = 1 << 7; + public static final int ADD_DESK_BUTTON = 1 << 8; // Flag indicating workspace has multiple pages visible. public static final int FLAG_MULTI_PAGE = BaseState.getFlag(0);