summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/CheckLongPressHelper.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/CheckLongPressHelper.java')
-rw-r--r--src/com/android/launcher3/CheckLongPressHelper.java32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/com/android/launcher3/CheckLongPressHelper.java b/src/com/android/launcher3/CheckLongPressHelper.java
index 81149793d..483c62249 100644
--- a/src/com/android/launcher3/CheckLongPressHelper.java
+++ b/src/com/android/launcher3/CheckLongPressHelper.java
@@ -18,16 +18,27 @@ package com.android.launcher3;
import android.view.View;
+import com.android.launcher3.util.Thunk;
+
public class CheckLongPressHelper {
- private View mView;
- private boolean mHasPerformedLongPress;
+
+ @Thunk View mView;
+ @Thunk View.OnLongClickListener mListener;
+ @Thunk boolean mHasPerformedLongPress;
+ private int mLongPressTimeout = 300;
private CheckForLongPress mPendingCheckForLongPress;
class CheckForLongPress implements Runnable {
public void run() {
if ((mView.getParent() != null) && mView.hasWindowFocus()
&& !mHasPerformedLongPress) {
- if (mView.performLongClick()) {
+ boolean handled;
+ if (mListener != null) {
+ handled = mListener.onLongClick(mView);
+ } else {
+ handled = mView.performLongClick();
+ }
+ if (handled) {
mView.setPressed(false);
mHasPerformedLongPress = true;
}
@@ -39,14 +50,25 @@ public class CheckLongPressHelper {
mView = v;
}
+ public CheckLongPressHelper(View v, View.OnLongClickListener listener) {
+ mView = v;
+ mListener = listener;
+ }
+
+ /**
+ * Overrides the default long press timeout.
+ */
+ public void setLongPressTimeout(int longPressTimeout) {
+ mLongPressTimeout = longPressTimeout;
+ }
+
public void postCheckForLongPress() {
mHasPerformedLongPress = false;
if (mPendingCheckForLongPress == null) {
mPendingCheckForLongPress = new CheckForLongPress();
}
- mView.postDelayed(mPendingCheckForLongPress,
- LauncherAppState.getInstance().getLongPressTimeout());
+ mView.postDelayed(mPendingCheckForLongPress, mLongPressTimeout);
}
public void cancelLongPress() {