From 3faa7c3869404e0c1e4f5e042b1931edbcdb51ca Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Mon, 13 Feb 2012 11:15:22 +0100 Subject: Furtherly fix up notification swipe handling. - Add debug code - Fix up 'handled' flag return handling - Fix remaining paths that could leave mItem set --- .../android/systemui/statusbar/ExpandedView.java | 9 ++++++-- .../systemui/statusbar/ItemTouchDispatcher.java | 21 ++++++++++++++--- .../systemui/statusbar/LatestItemContainer.java | 26 +++++++++++++++++++--- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandedView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandedView.java index 5c0b76b..d83d26b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandedView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandedView.java @@ -56,8 +56,13 @@ public class ExpandedView extends LinearLayout { @Override public boolean onTouchEvent(MotionEvent event) { - mTouchDispatcher.handleTouchEvent(event); - return super.onTouchEvent(event); + boolean handled = mTouchDispatcher.handleTouchEvent(event); + + if (super.onTouchEvent(event)) { + handled = true; + } + + return handled; } @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ItemTouchDispatcher.java b/packages/SystemUI/src/com/android/systemui/statusbar/ItemTouchDispatcher.java index 4c5dfaf..ad8bc1d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ItemTouchDispatcher.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ItemTouchDispatcher.java @@ -26,6 +26,7 @@ import com.android.systemui.R; public class ItemTouchDispatcher { private static final String TAG = "NotificationTouchDispatcher"; + /* package */ static final boolean DBG = false; private final GestureDetector mGestureDetector; private LatestItemContainer mItem; @@ -39,12 +40,22 @@ public class ItemTouchDispatcher { final ViewConfiguration vc = ViewConfiguration.get(context); int minDistance = vc.getScaledTouchSlop(); int distance = (int) Math.abs(e2.getX() - e1.getX()); + boolean result = false; + + if (DBG) { + Log.v(TAG, "Fling detected, distance " + distance + " vs. " + + minDistance + " vX " + vX + " vY " + vY); + } + if (distance > minDistance && Math.abs(vX) > Math.abs(vY)) { mItem.finishSwipe(vX > 0); - mItem = null; - return true; + result = true; + } else { + mItem.stopSwipe(); } - return false; + + mItem = null; + return result; } }); } @@ -72,6 +83,7 @@ public class ItemTouchDispatcher { } } if (mItem != null) { + if (DBG) Log.v(TAG, "Need to intercept touch event " + event + " due to item " + mItem); mItem.setEventsControlledByDispatcher(); return true; } @@ -87,6 +99,7 @@ public class ItemTouchDispatcher { real.setLocation(event.getRawX(), event.getRawY()); boolean handled = mGestureDetector.onTouchEvent(real); + if (DBG) Log.v(TAG, "Handling touch event " + event + " handled " + handled); if (mItem != null) { /* @@ -95,12 +108,14 @@ public class ItemTouchDispatcher { mItem.getLocationOnScreen(mItemLocation); real.offsetLocation(mItemLocation[0], mItemLocation[1]); mItem.dispatchTouchEvent(real); + if (DBG) Log.v(TAG, "Converted event to " + real); switch (real.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mItem.stopSwipe(); mItem = null; + handled = true; break; } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/LatestItemContainer.java b/packages/SystemUI/src/com/android/systemui/statusbar/LatestItemContainer.java index 4f389bf..7732005 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/LatestItemContainer.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/LatestItemContainer.java @@ -20,6 +20,7 @@ import android.content.Context; import android.graphics.Point; import android.os.Handler; import android.util.AttributeSet; +import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.ViewConfiguration; @@ -30,6 +31,9 @@ import android.widget.LinearLayout; import com.android.systemui.R; public class LatestItemContainer extends LinearLayout { + private static final String TAG = "NotificationContainer"; + private static final boolean DBG = ItemTouchDispatcher.DBG; + private boolean mEventsControlledByDispatcher = false; private ItemTouchDispatcher mDispatcher = null; private Runnable mSwipeCallback = null; @@ -46,12 +50,15 @@ public class LatestItemContainer extends LinearLayout { public void finishSwipe(boolean toRight) { int id = toRight ? R.anim.slide_out_right_basic : R.anim.slide_out_left_basic; Animation animation = AnimationUtils.loadAnimation(getContext(), id); + + if (DBG) Log.v(TAG, "Finishing swipe of item " + this + " to " + (toRight ? "right" : "left")); startAnimation(animation); mHandler.postDelayed(mSwipeCallback, animation.getDuration()); mEventsControlledByDispatcher = false; } public void stopSwipe() { + if (DBG) Log.v(TAG, "Swipe of item " + this + "cancelled"); reset(); mEventsControlledByDispatcher = false; } @@ -62,9 +69,9 @@ public class LatestItemContainer extends LinearLayout { @Override public boolean dispatchTouchEvent(MotionEvent event) { - if (mDispatcher != null) { - boolean handled = false; + boolean handled = false; + if (mDispatcher != null) { /* * Only call into dispatcher when we're not registered with it yet, * otherwise we get into a loop @@ -73,9 +80,15 @@ public class LatestItemContainer extends LinearLayout { handled = mDispatcher.handleTouchEvent(event); } + if (DBG) { + Log.v(TAG, "Got touch event " + event + " dispatcher handled " + + handled + " controlled " + mEventsControlledByDispatcher); + } + switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mStartPoint.set((int) event.getX(), (int) event.getY()); + handled = true; break; case MotionEvent.ACTION_MOVE: int diffX = ((int) event.getX()) - mStartPoint.x; @@ -84,6 +97,7 @@ public class LatestItemContainer extends LinearLayout { mDispatcher.setItem(this); } scrollTo(-diffX, 0); + handled = true; break; case MotionEvent.ACTION_UP: if (!handled) { @@ -92,6 +106,7 @@ public class LatestItemContainer extends LinearLayout { if (!mEventsControlledByDispatcher) { mDispatcher.releaseItem(this); } + handled = true; break; case MotionEvent.ACTION_CANCEL: /* @@ -104,11 +119,16 @@ public class LatestItemContainer extends LinearLayout { mDispatcher.releaseItem(this); reset(); } + handled = true; break; } } - return super.dispatchTouchEvent(event); + if (super.dispatchTouchEvent(event)) { + handled = true; + } + + return handled; } private void reset() { -- cgit v1.1