From badcf77c28bd947ec3dd0de56e79235ec3754417 Mon Sep 17 00:00:00 2001 From: Willie Koomson Date: Tue, 7 May 2024 21:32:25 +0000 Subject: [PATCH] Go to NORMAL state before adding widget with add button Updates add button behavior to go to NORMAL state before adding the widget to the workspace. This has the effect of dismissing the All Apps view if it is open. This fixes an issue where the add button did not work if used from the WidgetsBottomSheet while All Apps is open, particularly if a new screen had to be created. See screencasts in gerrit for before/after. Bug: 335906123 Test: manual, add widget with button from all apps > bottom sheet while there is no space on the launcher Flag: ACONFIG com.android.launcher3.enable_widget_tap_to_add NEXTFOOD Change-Id: I2fd961c09c473045088feba5d572c26a812e6619 --- .../launcher3/widget/BaseWidgetSheet.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java index 4f2327c47b..0d97adc739 100644 --- a/src/com/android/launcher3/widget/BaseWidgetSheet.java +++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java @@ -17,6 +17,8 @@ package com.android.launcher3.widget; import static com.android.app.animation.Interpolators.EMPHASIZED; import static com.android.launcher3.Flags.enableWidgetTapToAdd; +import static com.android.launcher3.LauncherState.NORMAL; +import static com.android.launcher3.anim.AnimatorListeners.forSuccessCallback; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGET_ADD_BUTTON_TAP; import android.content.Context; @@ -174,7 +176,8 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView } /** - * Click handler for tap to add button. + * Click handler for tap to add button. This handler assumes we are in the Launcher activity and + * should not be used when the widget sheet is displayed elsewhere. */ private void addWidget(@NonNull PendingAddItemInfo info) { // Using a boolean flag here to make sure the callback is only run once. This should never @@ -182,19 +185,23 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView // needed. final AtomicBoolean hasRun = new AtomicBoolean(false); addOnCloseListener(() -> { - if (!hasRun.get()) { - Launcher.getLauncher(mActivityContext).getAccessibilityDelegate().addToWorkspace( - info, /*accessibility=*/ false, + if (hasRun.get()) return; + hasRun.set(true); + + // Going to NORMAL state will also dismiss the All Apps view if it is showing. + Launcher launcher = Launcher.getLauncher(mActivityContext); + launcher.getStateManager().goToState(NORMAL, forSuccessCallback(() -> { + launcher.getAccessibilityDelegate().addToWorkspace(info, + /*accessibility=*/ false, /*finishCallback=*/ (success) -> { mActivityContext.getStatsLogManager() .logger() .withItemInfo(info) .log(LAUNCHER_WIDGET_ADD_BUTTON_TAP); }); - hasRun.set(true); - } + })); }); - handleClose(true); + close(/* animate= */ true); } /**