Add tap-to-add button to widget picker
This change introduces an "Add" button that appears when a widget preview is clicked in the widget picker. This button disappears when the preview is clicked again, or another preview is clicked. When the button is pressed, it adds that widget to the picker. The add button is available in the app-specific widget sheet as well. Bug: 323886237 Test: Manual Flag: ACONFIG com.android.launcher3.enable_widget_tap_to_add DEVELOPMENT Change-Id: I86a8a4c22119960c54a885fd2efeb91916b4f9a0
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.launcher3.widget;
|
||||
import static com.android.app.animation.Interpolators.EMPHASIZED;
|
||||
import static com.android.launcher3.Flags.enableCategorizedWidgetSuggestions;
|
||||
import static com.android.launcher3.Flags.enableUnfoldedTwoPanePicker;
|
||||
import static com.android.launcher3.Flags.enableWidgetTapToAdd;
|
||||
import static com.android.launcher3.LauncherPrefs.WIDGETS_EDUCATION_TIP_SEEN;
|
||||
|
||||
import android.content.Context;
|
||||
@@ -41,8 +42,10 @@ import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
|
||||
import com.android.launcher3.Insettable;
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.LauncherPrefs;
|
||||
import com.android.launcher3.PendingAddItemInfo;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.logging.StatsLogManager;
|
||||
import com.android.launcher3.popup.PopupDataProvider;
|
||||
import com.android.launcher3.testing.TestLogging;
|
||||
import com.android.launcher3.testing.shared.TestProtocol;
|
||||
@@ -73,6 +76,8 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<BaseActivity>
|
||||
|
||||
private boolean mDisableNavBarScrim = false;
|
||||
|
||||
@Nullable private WidgetCell mWidgetCellWithAddButton = null;
|
||||
|
||||
public BaseWidgetSheet(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
mContentHorizontalMargin = getWidgetListHorizontalMargin();
|
||||
@@ -123,13 +128,49 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView<BaseActivity>
|
||||
|
||||
@Override
|
||||
public final void onClick(View v) {
|
||||
if (v instanceof WidgetCell) {
|
||||
mActivityContext.getItemOnClickListener().onClick(v);
|
||||
} else if (v.getParent() instanceof WidgetCell wc) {
|
||||
WidgetCell wc;
|
||||
if (v instanceof WidgetCell view) {
|
||||
wc = view;
|
||||
} else if (v.getParent() instanceof WidgetCell parent) {
|
||||
wc = parent;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
if (enableWidgetTapToAdd()) {
|
||||
if (mWidgetCellWithAddButton != null) {
|
||||
// If there is a add button currently showing, hide it.
|
||||
mWidgetCellWithAddButton.hideAddButton(/* animate= */ true);
|
||||
}
|
||||
|
||||
if (mWidgetCellWithAddButton != wc) {
|
||||
// If click is on a cell not showing an add button, show it now.
|
||||
final PendingAddItemInfo info = (PendingAddItemInfo) wc.getTag();
|
||||
if (mActivityContext instanceof Launcher) {
|
||||
wc.showAddButton((view) -> addWidget(info));
|
||||
} else {
|
||||
wc.showAddButton((view) -> mActivityContext.getItemOnClickListener()
|
||||
.onClick(wc));
|
||||
}
|
||||
}
|
||||
|
||||
mWidgetCellWithAddButton = mWidgetCellWithAddButton != wc ? wc : null;
|
||||
} else {
|
||||
mActivityContext.getItemOnClickListener().onClick(wc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Click handler for tap to add button.
|
||||
*/
|
||||
public void addWidget(PendingAddItemInfo info) {
|
||||
mActivityContext.getStatsLogManager().logger().withItemInfo(info).log(
|
||||
StatsLogManager.LauncherEvent.LAUNCHER_WIDGET_ADD_BUTTON_TAP);
|
||||
handleClose(true);
|
||||
Launcher.getLauncher(mActivityContext).getAccessibilityDelegate()
|
||||
.addToWorkspace(info, /*accessibility=*/ false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "Widgets.onLongClick");
|
||||
|
||||
Reference in New Issue
Block a user