diff options
| author | Alan Viverette <alanv@google.com> | 2013-06-25 17:27:37 -0700 |
|---|---|---|
| committer | Alan Viverette <alanv@google.com> | 2013-06-25 17:27:37 -0700 |
| commit | 3d15a2b8f43f5b184f8fdcd3661711111bcf4674 (patch) | |
| tree | 442596d17134d918b974ce7159de4efc42601c1b /core/java | |
| parent | 066bdcfe83e49ad4bfb97670521c1b7e7297ba53 (diff) | |
Minor ListView clean up. Exposes View.pointInView() as hidden API.
Change-Id: Ia628f8438fac5af2471efd8558c8876fae3dafb0
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/view/View.java | 4 | ||||
| -rw-r--r-- | core/java/android/widget/AbsListView.java | 62 |
2 files changed, 30 insertions, 36 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 525b58fb2b6f..0c1b1929418a 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -10063,8 +10063,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * is inside the view, where the area of the view is expanded by the slop factor. * This method is called while processing touch-move events to determine if the event * is still within the view. + * + * @hide */ - private boolean pointInView(float localX, float localY, float slop) { + public boolean pointInView(float localX, float localY, float slop) { return localX >= -slop && localY >= -slop && localX < ((mRight - mLeft) + slop) && localY < ((mBottom - mTop) + slop); } diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java index bb1f95430037..1e20ab2cec21 100644 --- a/core/java/android/widget/AbsListView.java +++ b/core/java/android/widget/AbsListView.java @@ -3369,68 +3369,62 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te } private void onTouchDown(MotionEvent ev) { - View v; - switch (mTouchMode) { - case TOUCH_MODE_OVERFLING: { + mActivePointerId = ev.getPointerId(0); + + if (mTouchMode == TOUCH_MODE_OVERFLING) { + // Stopped the fling. It is a scroll. mFlingRunnable.endFling(); if (mPositionScroller != null) { mPositionScroller.stop(); } mTouchMode = TOUCH_MODE_OVERSCROLL; mMotionX = (int) ev.getX(); - mMotionY = mLastY = (int) ev.getY(); + mMotionY = (int) ev.getY(); + mLastY = mMotionY; mMotionCorrection = 0; - mActivePointerId = ev.getPointerId(0); mDirection = 0; - break; - } - - default: { - mActivePointerId = ev.getPointerId(0); + } else { final int x = (int) ev.getX(); final int y = (int) ev.getY(); int motionPosition = pointToPosition(x, y); + if (!mDataChanged) { - if ((mTouchMode != TOUCH_MODE_FLING) && (motionPosition >= 0) - && (getAdapter().isEnabled(motionPosition))) { - // User clicked on an actual view (and was not stopping a fling). - // It might be a click or a scroll. Assume it is a click until - // proven otherwise + if (mTouchMode == TOUCH_MODE_FLING) { + // Stopped a fling. It is a scroll. + createScrollingCache(); + mTouchMode = TOUCH_MODE_SCROLL; + mMotionCorrection = 0; + motionPosition = findMotionRow(y); + mFlingRunnable.flywheelTouch(); + } else if ((motionPosition >= 0) && getAdapter().isEnabled(motionPosition)) { + // User clicked on an actual view (and was not stopping a + // fling). It might be a click or a scroll. Assume it is a + // click until proven otherwise. mTouchMode = TOUCH_MODE_DOWN; + // FIXME Debounce if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } + postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); - } else { - if (mTouchMode == TOUCH_MODE_FLING) { - // Stopped a fling. It is a scroll. - createScrollingCache(); - mTouchMode = TOUCH_MODE_SCROLL; - mMotionCorrection = 0; - motionPosition = findMotionRow(y); - mFlingRunnable.flywheelTouch(); - } } } if (motionPosition >= 0) { // Remember where the motion event started - v = getChildAt(motionPosition - mFirstPosition); + final View v = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalTop = v.getTop(); } + mMotionX = x; mMotionY = y; mMotionPosition = motionPosition; mLastY = Integer.MIN_VALUE; - break; - } } - if (performButtonActionOnTouchDown(ev)) { - if (mTouchMode == TOUCH_MODE_DOWN) { - removeCallbacks(mPendingCheckForTap); - } + if (performButtonActionOnTouchDown(ev) && (mTouchMode == TOUCH_MODE_DOWN)) { + removeCallbacks(mPendingCheckForTap); } } @@ -3460,10 +3454,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te } // Otherwise, check containment within list bounds. If we're // outside bounds, cancel any active presses. - final float x = ev.getX(); - final boolean inList = (x > mListPadding.left) - && (x < getWidth() - mListPadding.right); - if (!inList) { + final float x = ev.getX(pointerIndex); + if (!pointInView(x, y, mTouchSlop)) { setPressed(false); final View motionView = getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { |
