Merging widget item click listener to default click listener

> Also removing check for dragHandle, since dragHandle is already removed

Bug: 307306823
Test: atest Launcher3Tests
Flag: N/A
Change-Id: I0b452dd1fbccf15ed686370471e8866b179fd77e
diff --git a/res/drawable/ic_drag_handle.xml b/res/drawable/ic_drag_handle.xml
deleted file mode 100644
index 9db75f4..0000000
--- a/res/drawable/ic_drag_handle.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
-        android:width="@dimen/deep_shortcut_drag_handle_size"
-        android:height="@dimen/deep_shortcut_drag_handle_size"
-        android:viewportWidth="24.0"
-        android:viewportHeight="24.0"
-        android:tint="?android:attr/textColorPrimary" >
-
-    <path
-        android:pathData="M20,9H4v2h16V9z M4,15h16v-2H4V15z"
-        android:fillColor="@android:color/white" />
-</vector>
\ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 6c9a238..6aee3de 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -290,7 +290,6 @@
     <dimen name="popup_single_item_radius">100dp</dimen>
     <dimen name="popup_smaller_radius">4dp</dimen>
     <dimen name="deep_shortcut_drawable_padding">16dp</dimen>
-    <dimen name="deep_shortcut_drag_handle_size">16dp</dimen>
     <dimen name="popup_padding_start">10dp</dimen>
     <dimen name="popup_padding_end">14dp</dimen>
     <dimen name="popup_vertical_padding">4dp</dimen>
diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java b/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java
index ad3f8df..ded2cee 100644
--- a/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java
+++ b/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java
@@ -17,13 +17,11 @@
 package com.android.launcher3.shortcuts;
 
 import android.content.Context;
-import android.content.res.Resources;
 import android.graphics.Canvas;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.text.TextUtils;
 import android.util.AttributeSet;
-import android.widget.Toast;
 
 import com.android.launcher3.BubbleTextView;
 import com.android.launcher3.R;
@@ -33,11 +31,6 @@
  * A {@link BubbleTextView} that has the shortcut icon on the left and drag handle on the right.
  */
 public class DeepShortcutTextView extends BubbleTextView {
-    private final Rect mDragHandleBounds = new Rect();
-    private final int mDragHandleWidth;
-    private boolean mShowInstructionToast = false;
-
-    private Toast mInstructionToast;
 
     private boolean mShowLoadingState;
     private Drawable mLoadingStatePlaceholder;
@@ -53,23 +46,12 @@
 
     public DeepShortcutTextView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
-
-        Resources resources = getResources();
-        mDragHandleWidth = resources.getDimensionPixelSize(R.dimen.popup_padding_end)
-                + resources.getDimensionPixelSize(R.dimen.deep_shortcut_drag_handle_size)
-                + resources.getDimensionPixelSize(R.dimen.deep_shortcut_drawable_padding) / 2;
         showLoadingState(true);
     }
 
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
-
-        mDragHandleBounds.set(0, 0, mDragHandleWidth, getMeasuredHeight());
-        if (!Utilities.isRtl(getResources())) {
-            mDragHandleBounds.offset(getMeasuredWidth() - mDragHandleBounds.width(), 0);
-        }
-
         setLoadingBounds();
     }
 
@@ -80,10 +62,10 @@
         mLoadingStateBounds.set(
                 0,
                 0,
-                getMeasuredWidth() - mDragHandleWidth - getPaddingStart(),
+                getMeasuredWidth() - getPaddingEnd() - getPaddingStart(),
                 mLoadingStatePlaceholder.getIntrinsicHeight());
         mLoadingStateBounds.offset(
-                Utilities.isRtl(getResources()) ? mDragHandleWidth : getPaddingStart(),
+                Utilities.isRtl(getResources()) ? getPaddingEnd() : getPaddingStart(),
                 (int) ((getMeasuredHeight() - mLoadingStatePlaceholder.getIntrinsicHeight())
                         / 2.0f)
         );
@@ -106,23 +88,11 @@
 
     @Override
     protected boolean shouldIgnoreTouchDown(float x, float y) {
-        // Show toast if user touches the drag handle (long clicks still start the drag).
-        mShowInstructionToast = mDragHandleBounds.contains((int) x, (int) y);
-
         // assume the whole view as clickable
         return false;
     }
 
     @Override
-    public boolean performClick() {
-        if (mShowInstructionToast) {
-            showToast();
-            return true;
-        }
-        return super.performClick();
-    }
-
-    @Override
     public void onDraw(Canvas canvas) {
         if (!mShowLoadingState) {
             super.onDraw(canvas);
@@ -155,15 +125,4 @@
 
         invalidate();
     }
-
-    private void showToast() {
-        if (mInstructionToast != null) {
-            mInstructionToast.cancel();
-        }
-        CharSequence msg = Utilities.wrapForTts(
-                getContext().getText(R.string.long_press_shortcut_to_add),
-                getContext().getString(R.string.long_accessible_way_to_add_shortcut));
-        mInstructionToast = Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT);
-        mInstructionToast.show();
-    }
 }
diff --git a/src/com/android/launcher3/touch/ItemClickHandler.java b/src/com/android/launcher3/touch/ItemClickHandler.java
index db32829..3bce377 100644
--- a/src/com/android/launcher3/touch/ItemClickHandler.java
+++ b/src/com/android/launcher3/touch/ItemClickHandler.java
@@ -61,7 +61,10 @@
 import com.android.launcher3.util.ItemInfoMatcher;
 import com.android.launcher3.util.PackageManagerHelper;
 import com.android.launcher3.views.FloatingIconView;
+import com.android.launcher3.views.Snackbar;
 import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
+import com.android.launcher3.widget.PendingAddShortcutInfo;
+import com.android.launcher3.widget.PendingAddWidgetInfo;
 import com.android.launcher3.widget.PendingAppWidgetHostView;
 import com.android.launcher3.widget.WidgetAddFlowHandler;
 import com.android.launcher3.widget.WidgetManagerHelper;
@@ -107,6 +110,16 @@
             }
         } else if (tag instanceof ItemClickProxy) {
             ((ItemClickProxy) tag).onItemClicked(v);
+        } else if (tag instanceof PendingAddShortcutInfo) {
+            CharSequence msg = Utilities.wrapForTts(
+                    launcher.getText(R.string.long_press_shortcut_to_add),
+                    launcher.getString(R.string.long_accessible_way_to_add_shortcut));
+            Snackbar.show(launcher, msg, null);
+        } else if (tag instanceof PendingAddWidgetInfo) {
+            CharSequence msg = Utilities.wrapForTts(
+                    launcher.getText(R.string.long_press_widget_to_add),
+                    launcher.getString(R.string.long_accessible_way_to_add));
+            Snackbar.show(launcher, msg, null);
         }
     }
 
diff --git a/src/com/android/launcher3/views/Snackbar.java b/src/com/android/launcher3/views/Snackbar.java
index 99040ff..54aa6e4 100644
--- a/src/com/android/launcher3/views/Snackbar.java
+++ b/src/com/android/launcher3/views/Snackbar.java
@@ -66,8 +66,8 @@
     }
 
     /** Show a snackbar with just a label. */
-    public static <T extends Context & ActivityContext> void show(T activity, String labelString,
-            Runnable onDismissed) {
+    public static void show(
+            ActivityContext activity, CharSequence labelString, Runnable onDismissed) {
         show(activity, labelString, NO_ID, onDismissed, null);
     }
 
@@ -76,21 +76,21 @@
             int actionStringResId, Runnable onDismissed, @Nullable Runnable onActionClicked) {
         show(
                 activity,
-                activity.getResources().getString(labelStringResId),
+                activity.getResources().getText(labelStringResId),
                 actionStringResId,
                 onDismissed,
                 onActionClicked);
     }
 
     /** Show a snackbar with a label and action. */
-    public static <T extends Context & ActivityContext> void show(T activity, String labelString,
+    public static void show(ActivityContext activity, CharSequence labelString,
             int actionStringResId, Runnable onDismissed, @Nullable Runnable onActionClicked) {
         closeOpenViews(activity, true, TYPE_SNACKBAR);
-        Snackbar snackbar = new Snackbar(activity, null);
+        Snackbar snackbar = new Snackbar((Context) activity, null);
         // Set some properties here since inflated xml only contains the children.
         snackbar.setOrientation(HORIZONTAL);
         snackbar.setGravity(Gravity.CENTER_VERTICAL);
-        Resources res = activity.getResources();
+        Resources res = snackbar.getResources();
         snackbar.setElevation(res.getDimension(R.dimen.snackbar_elevation));
         int padding = res.getDimensionPixelSize(R.dimen.snackbar_padding);
         snackbar.setPadding(padding, padding, padding, padding);
@@ -143,7 +143,8 @@
             actionView.setVisibility(GONE);
         }
 
-        int totalContentWidth = (int) (labelView.getPaint().measureText(labelString) + actionWidth)
+        int totalContentWidth = (int) (labelView.getPaint().measureText(labelString.toString())
+                    + actionWidth)
                 + labelView.getPaddingRight() + labelView.getPaddingLeft()
                 + padding * 2;
         if (totalContentWidth > params.width) {
@@ -177,7 +178,7 @@
                 .setDuration(SHOW_DURATION_MS)
                 .setInterpolator(Interpolators.ACCELERATE_DECELERATE)
                 .start();
-        int timeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(activity,
+        int timeout = AccessibilityManagerCompat.getRecommendedTimeoutMillis(snackbar.getContext(),
                 TIMEOUT_DURATION_MS, FLAG_CONTENT_TEXT | FLAG_CONTENT_CONTROLS);
         snackbar.postDelayed(() -> snackbar.close(true), timeout);
     }
diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java
index 26e191d..5ec1022 100644
--- a/src/com/android/launcher3/widget/BaseWidgetSheet.java
+++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java
@@ -28,7 +28,6 @@
 import android.view.View.OnLongClickListener;
 import android.view.WindowInsets;
 import android.view.animation.Interpolator;
-import android.widget.Toast;
 
 import androidx.annotation.Nullable;
 import androidx.annotation.Px;
@@ -62,9 +61,6 @@
 
     protected final Rect mInsets = new Rect();
 
-    /* Touch handling related member variables. */
-    private Toast mWidgetInstructionToast;
-
     @Px protected int mContentHorizontalMargin;
     @Px protected int mWidgetCellHorizontalPadding;
 
@@ -113,16 +109,10 @@
 
     @Override
     public final void onClick(View v) {
-        Object tag = null;
         if (v instanceof WidgetCell) {
-            tag = v.getTag();
-        } else if (v.getParent() instanceof WidgetCell) {
-            tag = ((WidgetCell) v.getParent()).getTag();
-        }
-        if (tag instanceof PendingAddShortcutInfo) {
-            mWidgetInstructionToast = showShortcutToast(getContext(), mWidgetInstructionToast);
-        } else {
-            mWidgetInstructionToast = showWidgetToast(getContext(), mWidgetInstructionToast);
+            mActivityContext.getItemOnClickListener().onClick(v);
+        } else if (v.getParent() instanceof WidgetCell wc) {
+            mActivityContext.getItemOnClickListener().onClick(wc);
         }
     }
 
@@ -131,7 +121,7 @@
         TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "Widgets.onLongClick");
         v.cancelLongPress();
 
-        boolean result = false;
+        boolean result;
         if (v instanceof WidgetCell) {
             result = mActivityContext.getAllAppsItemLongClickListener().onLongClick(v);
         } else if (v.getParent() instanceof WidgetCell wc) {
@@ -238,40 +228,6 @@
         return mActivityContext.getSystemUiController();
     }
 
-    /**
-     * Show Widget tap toast prompting user to drag instead
-     */
-    public static Toast showWidgetToast(Context context, Toast toast) {
-        // Let the user know that they have to long press to add a widget
-        if (toast != null) {
-            toast.cancel();
-        }
-
-        CharSequence msg = Utilities.wrapForTts(
-                context.getText(R.string.long_press_widget_to_add),
-                context.getString(R.string.long_accessible_way_to_add));
-        toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
-        toast.show();
-        return toast;
-    }
-
-    /**
-     * Show shortcut tap toast prompting user to drag instead.
-     */
-    private static Toast showShortcutToast(Context context, Toast toast) {
-        // Let the user know that they have to long press to add a widget
-        if (toast != null) {
-            toast.cancel();
-        }
-
-        CharSequence msg = Utilities.wrapForTts(
-                context.getText(R.string.long_press_shortcut_to_add),
-                context.getString(R.string.long_accessible_way_to_add_shortcut));
-        toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
-        toast.show();
-        return toast;
-    }
-
     /** Shows education tip on top center of {@code view} if view is laid out. */
     @Nullable
     protected ArrowTipView showEducationTipOnViewIfPossible(@Nullable View view) {