From 531fc4985bd01e6ee103a2c3753ee841ffb2da24 Mon Sep 17 00:00:00 2001 From: Will Leshner Date: Fri, 1 Dec 2023 15:34:59 -0800 Subject: [PATCH] Handle widget taps in WidgetPickerActivity. Bug: 307306823 Test: atest Launcher3Tests Flag: NA Change-Id: I05cd42eae91447cfe99165096a735f6e04257203 --- .../launcher3/WidgetPickerActivity.java | 21 +++++++++++++++++++ .../android/launcher3/widget/WidgetCell.java | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/quickstep/src/com/android/launcher3/WidgetPickerActivity.java b/quickstep/src/com/android/launcher3/WidgetPickerActivity.java index 43716abd97..477cd84444 100644 --- a/quickstep/src/com/android/launcher3/WidgetPickerActivity.java +++ b/quickstep/src/com/android/launcher3/WidgetPickerActivity.java @@ -22,7 +22,10 @@ import static android.view.WindowInsets.Type.statusBars; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; +import android.appwidget.AppWidgetProviderInfo; +import android.content.Intent; import android.os.Bundle; +import android.view.View; import android.view.WindowInsetsController; import android.view.WindowManager; @@ -32,6 +35,7 @@ import com.android.launcher3.dragndrop.SimpleDragLayer; import com.android.launcher3.model.WidgetsModel; import com.android.launcher3.popup.PopupDataProvider; import com.android.launcher3.widget.BaseWidgetSheet; +import com.android.launcher3.widget.WidgetCell; import com.android.launcher3.widget.model.WidgetsListBaseEntry; import com.android.launcher3.widget.picker.WidgetsFullSheet; @@ -81,6 +85,23 @@ public class WidgetPickerActivity extends BaseActivity { return mDragLayer; } + @Override + public View.OnClickListener getItemOnClickListener() { + return v -> { + final AppWidgetProviderInfo info = + (v instanceof WidgetCell) ? ((WidgetCell) v).getWidgetItem().widgetInfo : null; + if (info == null || info.provider == null) { + return; + } + + setResult(RESULT_OK, new Intent() + .putExtra(Intent.EXTRA_COMPONENT_NAME, info.provider) + .putExtra(Intent.EXTRA_USER, info.getProfile())); + + finish(); + }; + } + private void refreshAndBindWidgets() { MODEL_EXECUTOR.execute(() -> { LauncherAppState app = LauncherAppState.getInstance(this); diff --git a/src/com/android/launcher3/widget/WidgetCell.java b/src/com/android/launcher3/widget/WidgetCell.java index c30342ad4b..8f5e2b66e1 100644 --- a/src/com/android/launcher3/widget/WidgetCell.java +++ b/src/com/android/launcher3/widget/WidgetCell.java @@ -147,6 +147,11 @@ public class WidgetCell extends LinearLayout { return mAppWidgetHostViewScale; } + /** Returns the {@link WidgetItem} for this {@link WidgetCell}. */ + public WidgetItem getWidgetItem() { + return mItem; + } + /** * Called to clear the view and free attached resources. (e.g., {@link Bitmap} */