summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
diff options
context:
space:
mode:
authorDaniel Sandler <dsandler@android.com>2012-04-04 14:04:21 -0400
committerDaniel Sandler <dsandler@android.com>2012-04-19 11:39:49 -0400
commitf7a1956b06faeb6025fdea331f81d66edda58b3c (patch)
treedfba6fe76ce0bab0a964959cb04980972e4424b1 /packages/SystemUI/src/com/android/systemui/SwipeHelper.java
parent3dfc82b5677a77e805511c263197c95c52a1665e (diff)
downloadframeworks_base-f7a1956b06faeb6025fdea331f81d66edda58b3c.zip
frameworks_base-f7a1956b06faeb6025fdea331f81d66edda58b3c.tar.gz
frameworks_base-f7a1956b06faeb6025fdea331f81d66edda58b3c.tar.bz2
Long-press a notification to find out who sent it.
Bug: 5547401 Change-Id: I8d5d73723b3f03f5b0f8717faaca826b1530df7a
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/SwipeHelper.java')
-rw-r--r--packages/SystemUI/src/com/android/systemui/SwipeHelper.java49
1 files changed, 48 insertions, 1 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/SwipeHelper.java b/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
index 19657a9..414af89 100644
--- a/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
@@ -23,11 +23,14 @@ import android.animation.Animator.AnimatorListener;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.graphics.RectF;
+import android.os.Handler;
import android.util.Log;
+import android.view.accessibility.AccessibilityEvent;
import android.view.animation.LinearInterpolator;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
+import android.view.ViewConfiguration;
public class SwipeHelper implements Gefingerpoken {
static final String TAG = "com.android.systemui.SwipeHelper";
@@ -57,6 +60,7 @@ public class SwipeHelper implements Gefingerpoken {
private float mPagingTouchSlop;
private Callback mCallback;
+ private Handler mHandler;
private int mSwipeDirection;
private VelocityTracker mVelocityTracker;
@@ -67,15 +71,24 @@ public class SwipeHelper implements Gefingerpoken {
private boolean mCanCurrViewBeDimissed;
private float mDensityScale;
+ private boolean mLongPressSent;
+ private View.OnLongClickListener mLongPressListener;
+ private Runnable mWatchLongPress;
+
public SwipeHelper(int swipeDirection, Callback callback, float densityScale,
float pagingTouchSlop) {
mCallback = callback;
+ mHandler = new Handler();
mSwipeDirection = swipeDirection;
mVelocityTracker = VelocityTracker.obtain();
mDensityScale = densityScale;
mPagingTouchSlop = pagingTouchSlop;
}
+ public void setLongPressListener(View.OnLongClickListener listener) {
+ mLongPressListener = listener;
+ }
+
public void setDensityScale(float densityScale) {
mDensityScale = densityScale;
}
@@ -167,12 +180,19 @@ public class SwipeHelper implements Gefingerpoken {
}
}
+ private void removeLongPressCallback() {
+ if (mWatchLongPress != null) {
+ mHandler.removeCallbacks(mWatchLongPress);
+ }
+ }
+
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
mDragging = false;
+ mLongPressSent = false;
mCurrView = mCallback.getChildAtPosition(ev);
mVelocityTracker.clear();
if (mCurrView != null) {
@@ -180,10 +200,28 @@ public class SwipeHelper implements Gefingerpoken {
mCanCurrViewBeDimissed = mCallback.canChildBeDismissed(mCurrView);
mVelocityTracker.addMovement(ev);
mInitialTouchPos = getPos(ev);
+
+ if (mLongPressListener != null) {
+ if (mWatchLongPress == null) {
+ mWatchLongPress = new Runnable() {
+ @Override
+ public void run() {
+ if (mCurrView != null && !mLongPressSent) {
+ mLongPressSent = true;
+ mCurrView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
+ mLongPressListener.onLongClick(mCurrView);
+ }
+ }
+ };
+ }
+ mHandler.postDelayed(mWatchLongPress, ViewConfiguration.getLongPressTimeout());
+ }
+
}
break;
+
case MotionEvent.ACTION_MOVE:
- if (mCurrView != null) {
+ if (mCurrView != null && !mLongPressSent) {
mVelocityTracker.addMovement(ev);
float pos = getPos(ev);
float delta = pos - mInitialTouchPos;
@@ -191,14 +229,19 @@ public class SwipeHelper implements Gefingerpoken {
mCallback.onBeginDrag(mCurrView);
mDragging = true;
mInitialTouchPos = getPos(ev) - getTranslation(mCurrAnimView);
+
+ removeLongPressCallback();
}
}
+
break;
+
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mDragging = false;
mCurrView = null;
mCurrAnimView = null;
+ mLongPressSent = false;
break;
}
return mDragging;
@@ -269,6 +312,10 @@ public class SwipeHelper implements Gefingerpoken {
}
public boolean onTouchEvent(MotionEvent ev) {
+ if (mLongPressSent) {
+ return true;
+ }
+
if (!mDragging) {
return false;
}