From 464509b375d66867814b131f31c855197e84b312 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Mon, 27 Nov 2023 15:35:44 -0800 Subject: [PATCH] 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 --- res/drawable/ic_drag_handle.xml | 27 ---------- res/values/dimens.xml | 1 - .../shortcuts/DeepShortcutTextView.java | 45 +--------------- .../launcher3/touch/ItemClickHandler.java | 13 +++++ src/com/android/launcher3/views/Snackbar.java | 17 +++--- .../launcher3/widget/BaseWidgetSheet.java | 52 ++----------------- 6 files changed, 28 insertions(+), 127 deletions(-) delete mode 100644 res/drawable/ic_drag_handle.xml diff --git a/res/drawable/ic_drag_handle.xml b/res/drawable/ic_drag_handle.xml deleted file mode 100644 index 9db75f4a04..0000000000 --- a/res/drawable/ic_drag_handle.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 6c9a2388f5..6aee3deb3e 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -290,7 +290,6 @@ 100dp 4dp 16dp - 16dp 10dp 14dp 4dp diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java b/src/com/android/launcher3/shortcuts/DeepShortcutTextView.java index ad3f8df04b..ded2ceee42 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 @@ import com.android.launcher3.Utilities; * 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 class DeepShortcutTextView extends BubbleTextView { 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 @@ public class DeepShortcutTextView extends BubbleTextView { 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,22 +88,10 @@ public class DeepShortcutTextView extends BubbleTextView { @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) { @@ -155,15 +125,4 @@ public class DeepShortcutTextView extends BubbleTextView { 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 db328290c4..3bce377656 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.testing.shared.TestProtocol; 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 @@ public class ItemClickHandler { } } 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 99040ff845..54aa6e429f 100644 --- a/src/com/android/launcher3/views/Snackbar.java +++ b/src/com/android/launcher3/views/Snackbar.java @@ -66,8 +66,8 @@ public class Snackbar extends AbstractFloatingView { } /** Show a snackbar with just a label. */ - public static 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 @@ public class Snackbar extends AbstractFloatingView { 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 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 @@ public class Snackbar extends AbstractFloatingView { 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 @@ public class Snackbar extends AbstractFloatingView { .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 26e191d19e..5ec1022a62 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.OnClickListener; 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 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView 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 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView @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 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView 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 @@ public abstract class BaseWidgetSheet extends AbstractSlideInView 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) {