From 2ca999cf1bd3cbd4647f57b8345c02999c6fa771 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 24 Sep 2018 17:24:51 -0400 Subject: [PATCH] Change long press timeout to use a factor of ViewConfiguration.getLongPressTimeout() This way, if the default ViewConfiguration timeout changes, we will adjust accordingly. Bug: 113639506 Change-Id: Ic3b93311c8e8d8196db2850fa641ffc675a16fb2 --- src/com/android/launcher3/BubbleTextView.java | 4 ++-- src/com/android/launcher3/CheckLongPressHelper.java | 12 +++++++----- .../launcher3/allapps/AllAppsGridAdapter.java | 3 +-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 5d401433bf..08bcc1dd25 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -272,8 +272,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, /** * Overrides the default long press timeout. */ - public void setLongPressTimeout(int longPressTimeout) { - mLongPressHelper.setLongPressTimeout(longPressTimeout); + public void setLongPressTimeoutFactor(float longPressTimeoutFactor) { + mLongPressHelper.setLongPressTimeoutFactor(longPressTimeoutFactor); } @Override diff --git a/src/com/android/launcher3/CheckLongPressHelper.java b/src/com/android/launcher3/CheckLongPressHelper.java index dde733cd16..639c173dcc 100644 --- a/src/com/android/launcher3/CheckLongPressHelper.java +++ b/src/com/android/launcher3/CheckLongPressHelper.java @@ -17,17 +17,18 @@ package com.android.launcher3; import android.view.View; +import android.view.ViewConfiguration; import com.android.launcher3.util.Thunk; public class CheckLongPressHelper { - public static final int DEFAULT_LONG_PRESS_TIMEOUT = 300; + public static final float DEFAULT_LONG_PRESS_TIMEOUT_FACTOR = 0.75f; @Thunk View mView; @Thunk View.OnLongClickListener mListener; @Thunk boolean mHasPerformedLongPress; - private int mLongPressTimeout = DEFAULT_LONG_PRESS_TIMEOUT; + private float mLongPressTimeoutFactor = DEFAULT_LONG_PRESS_TIMEOUT_FACTOR; private CheckForLongPress mPendingCheckForLongPress; class CheckForLongPress implements Runnable { @@ -60,8 +61,8 @@ public class CheckLongPressHelper { /** * Overrides the default long press timeout. */ - public void setLongPressTimeout(int longPressTimeout) { - mLongPressTimeout = longPressTimeout; + public void setLongPressTimeoutFactor(float longPressTimeoutFactor) { + mLongPressTimeoutFactor = longPressTimeoutFactor; } public void postCheckForLongPress() { @@ -70,7 +71,8 @@ public class CheckLongPressHelper { if (mPendingCheckForLongPress == null) { mPendingCheckForLongPress = new CheckForLongPress(); } - mView.postDelayed(mPendingCheckForLongPress, mLongPressTimeout); + mView.postDelayed(mPendingCheckForLongPress, + (long) (ViewConfiguration.getLongPressTimeout() * mLongPressTimeoutFactor)); } public void cancelLongPress() { diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java index 0f13550199..69b4bdb1df 100644 --- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java +++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java @@ -22,7 +22,6 @@ import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnFocusChangeListener; -import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; import android.widget.TextView; @@ -252,7 +251,7 @@ public class AllAppsGridAdapter extends RecyclerView.Adapter