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
This commit is contained in:
1 parent
245c244fed
commit
badcf77c28
1 file changed
+14
-7
@@ -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<BaseActivity>
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<BaseActivity>
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user