|
|
@ -1685,136 +1685,140 @@ public class VerticalViewPager extends ViewGroup {
|
|
1685
|
1685
|
* If we return true, onMotionEvent will be called and we do the actual
|
|
1686
|
1686
|
* scrolling there.
|
|
1687
|
1687
|
*/
|
|
|
1688
|
try {
|
|
1688
|
1689
|
|
|
1689
|
|
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
|
|
|
1690
|
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
|
|
1690
|
1691
|
|
|
1691
|
|
// Always take care of the touch gesture being complete.
|
|
1692
|
|
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
|
|
1693
|
|
// Release the drag.
|
|
1694
|
|
if (DEBUG) Log.v(TAG, "Intercept done!");
|
|
1695
|
|
mIsBeingDragged = false;
|
|
1696
|
|
mIsUnableToDrag = false;
|
|
1697
|
|
mActivePointerId = INVALID_POINTER;
|
|
1698
|
|
if (mVelocityTracker != null) {
|
|
1699
|
|
mVelocityTracker.recycle();
|
|
1700
|
|
mVelocityTracker = null;
|
|
1701
|
|
}
|
|
1702
|
|
return false;
|
|
1703
|
|
}
|
|
1704
|
|
|
|
1705
|
|
// Nothing more to do here if we have decided whether or not we
|
|
1706
|
|
// are dragging.
|
|
1707
|
|
if (action != MotionEvent.ACTION_DOWN) {
|
|
1708
|
|
if (mIsBeingDragged) {
|
|
1709
|
|
if (DEBUG) Log.v(TAG, "Intercept returning true!");
|
|
1710
|
|
return true;
|
|
1711
|
|
}
|
|
1712
|
|
if (mIsUnableToDrag) {
|
|
1713
|
|
if (DEBUG) Log.v(TAG, "Intercept returning false!");
|
|
|
1692
|
// Always take care of the touch gesture being complete.
|
|
|
1693
|
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
|
|
|
1694
|
// Release the drag.
|
|
|
1695
|
if (DEBUG) Log.v(TAG, "Intercept done!");
|
|
|
1696
|
mIsBeingDragged = false;
|
|
|
1697
|
mIsUnableToDrag = false;
|
|
|
1698
|
mActivePointerId = INVALID_POINTER;
|
|
|
1699
|
if (mVelocityTracker != null) {
|
|
|
1700
|
mVelocityTracker.recycle();
|
|
|
1701
|
mVelocityTracker = null;
|
|
|
1702
|
}
|
|
1714
|
1703
|
return false;
|
|
1715
|
1704
|
}
|
|
1716
|
|
}
|
|
1717
|
1705
|
|
|
1718
|
|
switch (action) {
|
|
1719
|
|
case MotionEvent.ACTION_MOVE: {
|
|
1720
|
|
/*
|
|
1721
|
|
* mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
|
|
1722
|
|
* whether the user has moved far enough from his original down touch.
|
|
1723
|
|
*/
|
|
1724
|
|
|
|
1725
|
|
/*
|
|
1726
|
|
* Locally do absolute value. mLastMotionY is set to the y value
|
|
1727
|
|
* of the down event.
|
|
1728
|
|
*/
|
|
1729
|
|
final int activePointerId = mActivePointerId;
|
|
1730
|
|
if (activePointerId == INVALID_POINTER) {
|
|
1731
|
|
// If we don't have a valid id, the touch down wasn't on content.
|
|
1732
|
|
break;
|
|
|
1706
|
// Nothing more to do here if we have decided whether or not we
|
|
|
1707
|
// are dragging.
|
|
|
1708
|
if (action != MotionEvent.ACTION_DOWN) {
|
|
|
1709
|
if (mIsBeingDragged) {
|
|
|
1710
|
if (DEBUG) Log.v(TAG, "Intercept returning true!");
|
|
|
1711
|
return true;
|
|
1733
|
1712
|
}
|
|
1734
|
|
|
|
1735
|
|
final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
|
|
1736
|
|
final float y = MotionEventCompat.getY(ev, pointerIndex);
|
|
1737
|
|
final float dy = y - mLastMotionY;
|
|
1738
|
|
final float yDiff = Math.abs(dy);
|
|
1739
|
|
final float x = MotionEventCompat.getX(ev, pointerIndex);
|
|
1740
|
|
final float xDiff = Math.abs(x - mInitialMotionX);
|
|
1741
|
|
if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
|
|
1742
|
|
|
|
1743
|
|
if (dy != 0 && !isGutterDrag(mLastMotionY, dy) &&
|
|
1744
|
|
canScroll(this, false, (int) dy, (int) x, (int) y)) {
|
|
1745
|
|
// Nested view has scrollable area under this point. Let it be handled there.
|
|
1746
|
|
mLastMotionX = x;
|
|
1747
|
|
mLastMotionY = y;
|
|
1748
|
|
mIsUnableToDrag = true;
|
|
|
1713
|
if (mIsUnableToDrag) {
|
|
|
1714
|
if (DEBUG) Log.v(TAG, "Intercept returning false!");
|
|
1749
|
1715
|
return false;
|
|
1750
|
1716
|
}
|
|
1751
|
|
if (yDiff > mTouchSlop && yDiff * 0.5f > xDiff) {
|
|
1752
|
|
if (DEBUG) Log.v(TAG, "Starting drag!");
|
|
1753
|
|
mIsBeingDragged = true;
|
|
1754
|
|
requestParentDisallowInterceptTouchEvent(true);
|
|
1755
|
|
setScrollState(SCROLL_STATE_DRAGGING);
|
|
1756
|
|
mLastMotionY = dy > 0 ? mInitialMotionY + mTouchSlop :
|
|
1757
|
|
mInitialMotionY - mTouchSlop;
|
|
1758
|
|
mLastMotionX = x;
|
|
1759
|
|
setScrollingCacheEnabled(true);
|
|
1760
|
|
} else if (xDiff > mTouchSlop) {
|
|
1761
|
|
// The finger has moved enough in the vertical
|
|
1762
|
|
// direction to be counted as a drag... abort
|
|
1763
|
|
// any attempt to drag horizontally, to work correctly
|
|
1764
|
|
// with children that have scrolling containers.
|
|
1765
|
|
if (DEBUG) Log.v(TAG, "Starting unable to drag!");
|
|
1766
|
|
mIsUnableToDrag = true;
|
|
1767
|
|
}
|
|
1768
|
|
if (mIsBeingDragged) {
|
|
1769
|
|
// Scroll to follow the motion event
|
|
1770
|
|
if (performDrag(y)) {
|
|
1771
|
|
ViewCompat.postInvalidateOnAnimation(this);
|
|
|
1717
|
}
|
|
|
1718
|
|
|
|
1719
|
switch (action) {
|
|
|
1720
|
case MotionEvent.ACTION_MOVE: {
|
|
|
1721
|
/*
|
|
|
1722
|
* mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
|
|
|
1723
|
* whether the user has moved far enough from his original down touch.
|
|
|
1724
|
*/
|
|
|
1725
|
|
|
|
1726
|
/*
|
|
|
1727
|
* Locally do absolute value. mLastMotionY is set to the y value
|
|
|
1728
|
* of the down event.
|
|
|
1729
|
*/
|
|
|
1730
|
final int activePointerId = mActivePointerId;
|
|
|
1731
|
if (activePointerId == INVALID_POINTER) {
|
|
|
1732
|
// If we don't have a valid id, the touch down wasn't on content.
|
|
|
1733
|
break;
|
|
|
1734
|
}
|
|
|
1735
|
|
|
|
1736
|
final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
|
|
|
1737
|
final float y = MotionEventCompat.getY(ev, pointerIndex);
|
|
|
1738
|
final float dy = y - mLastMotionY;
|
|
|
1739
|
final float yDiff = Math.abs(dy);
|
|
|
1740
|
final float x = MotionEventCompat.getX(ev, pointerIndex);
|
|
|
1741
|
final float xDiff = Math.abs(x - mInitialMotionX);
|
|
|
1742
|
if (DEBUG)
|
|
|
1743
|
Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
|
|
|
1744
|
|
|
|
1745
|
if (dy != 0 && !isGutterDrag(mLastMotionY, dy) &&
|
|
|
1746
|
canScroll(this, false, (int) dy, (int) x, (int) y)) {
|
|
|
1747
|
// Nested view has scrollable area under this point. Let it be handled there.
|
|
|
1748
|
mLastMotionX = x;
|
|
|
1749
|
mLastMotionY = y;
|
|
|
1750
|
mIsUnableToDrag = true;
|
|
|
1751
|
return false;
|
|
|
1752
|
}
|
|
|
1753
|
if (yDiff > mTouchSlop && yDiff * 0.5f > xDiff) {
|
|
|
1754
|
if (DEBUG) Log.v(TAG, "Starting drag!");
|
|
|
1755
|
mIsBeingDragged = true;
|
|
|
1756
|
requestParentDisallowInterceptTouchEvent(true);
|
|
|
1757
|
setScrollState(SCROLL_STATE_DRAGGING);
|
|
|
1758
|
mLastMotionY = dy > 0 ? mInitialMotionY + mTouchSlop :
|
|
|
1759
|
mInitialMotionY - mTouchSlop;
|
|
|
1760
|
mLastMotionX = x;
|
|
|
1761
|
setScrollingCacheEnabled(true);
|
|
|
1762
|
} else if (xDiff > mTouchSlop) {
|
|
|
1763
|
// The finger has moved enough in the vertical
|
|
|
1764
|
// direction to be counted as a drag... abort
|
|
|
1765
|
// any attempt to drag horizontally, to work correctly
|
|
|
1766
|
// with children that have scrolling containers.
|
|
|
1767
|
if (DEBUG) Log.v(TAG, "Starting unable to drag!");
|
|
|
1768
|
mIsUnableToDrag = true;
|
|
|
1769
|
}
|
|
|
1770
|
if (mIsBeingDragged) {
|
|
|
1771
|
// Scroll to follow the motion event
|
|
|
1772
|
if (performDrag(y)) {
|
|
|
1773
|
ViewCompat.postInvalidateOnAnimation(this);
|
|
|
1774
|
}
|
|
1772
|
1775
|
}
|
|
|
1776
|
break;
|
|
1773
|
1777
|
}
|
|
1774
|
|
break;
|
|
1775
|
|
}
|
|
1776
|
1778
|
|
|
1777
|
|
case MotionEvent.ACTION_DOWN: {
|
|
1778
|
|
/*
|
|
1779
|
|
* Remember location of down touch.
|
|
1780
|
|
* ACTION_DOWN always refers to pointer index 0.
|
|
1781
|
|
*/
|
|
1782
|
|
mLastMotionX = mInitialMotionX = ev.getX();
|
|
1783
|
|
mLastMotionY = mInitialMotionY = ev.getY();
|
|
1784
|
|
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
|
|
1785
|
|
mIsUnableToDrag = false;
|
|
|
1779
|
case MotionEvent.ACTION_DOWN: {
|
|
|
1780
|
/*
|
|
|
1781
|
* Remember location of down touch.
|
|
|
1782
|
* ACTION_DOWN always refers to pointer index 0.
|
|
|
1783
|
*/
|
|
|
1784
|
mLastMotionX = mInitialMotionX = ev.getX();
|
|
|
1785
|
mLastMotionY = mInitialMotionY = ev.getY();
|
|
|
1786
|
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
|
|
|
1787
|
mIsUnableToDrag = false;
|
|
|
1788
|
|
|
|
1789
|
mScroller.computeScrollOffset();
|
|
|
1790
|
if (mScrollState == SCROLL_STATE_SETTLING &&
|
|
|
1791
|
Math.abs(mScroller.getFinalY() - mScroller.getCurrY()) > mCloseEnough) {
|
|
|
1792
|
// Let the user 'catch' the pager as it animates.
|
|
|
1793
|
mScroller.abortAnimation();
|
|
|
1794
|
mPopulatePending = false;
|
|
|
1795
|
populate();
|
|
|
1796
|
mIsBeingDragged = true;
|
|
|
1797
|
requestParentDisallowInterceptTouchEvent(true);
|
|
|
1798
|
setScrollState(SCROLL_STATE_DRAGGING);
|
|
|
1799
|
} else {
|
|
|
1800
|
completeScroll(false);
|
|
|
1801
|
mIsBeingDragged = false;
|
|
|
1802
|
}
|
|
1786
|
1803
|
|
|
1787
|
|
mScroller.computeScrollOffset();
|
|
1788
|
|
if (mScrollState == SCROLL_STATE_SETTLING &&
|
|
1789
|
|
Math.abs(mScroller.getFinalY() - mScroller.getCurrY()) > mCloseEnough) {
|
|
1790
|
|
// Let the user 'catch' the pager as it animates.
|
|
1791
|
|
mScroller.abortAnimation();
|
|
1792
|
|
mPopulatePending = false;
|
|
1793
|
|
populate();
|
|
1794
|
|
mIsBeingDragged = true;
|
|
1795
|
|
requestParentDisallowInterceptTouchEvent(true);
|
|
1796
|
|
setScrollState(SCROLL_STATE_DRAGGING);
|
|
1797
|
|
} else {
|
|
1798
|
|
completeScroll(false);
|
|
1799
|
|
mIsBeingDragged = false;
|
|
|
1804
|
if (DEBUG) Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY
|
|
|
1805
|
+ " mIsBeingDragged=" + mIsBeingDragged
|
|
|
1806
|
+ "mIsUnableToDrag=" + mIsUnableToDrag);
|
|
|
1807
|
break;
|
|
1800
|
1808
|
}
|
|
1801
|
1809
|
|
|
1802
|
|
if (DEBUG) Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY
|
|
1803
|
|
+ " mIsBeingDragged=" + mIsBeingDragged
|
|
1804
|
|
+ "mIsUnableToDrag=" + mIsUnableToDrag);
|
|
1805
|
|
break;
|
|
|
1810
|
case MotionEventCompat.ACTION_POINTER_UP:
|
|
|
1811
|
onSecondaryPointerUp(ev);
|
|
|
1812
|
break;
|
|
1806
|
1813
|
}
|
|
1807
|
1814
|
|
|
1808
|
|
case MotionEventCompat.ACTION_POINTER_UP:
|
|
1809
|
|
onSecondaryPointerUp(ev);
|
|
1810
|
|
break;
|
|
1811
|
|
}
|
|
1812
|
|
|
|
1813
|
|
if (mVelocityTracker == null) {
|
|
1814
|
|
mVelocityTracker = VelocityTracker.obtain();
|
|
|
1815
|
if (mVelocityTracker == null) {
|
|
|
1816
|
mVelocityTracker = VelocityTracker.obtain();
|
|
|
1817
|
}
|
|
|
1818
|
mVelocityTracker.addMovement(ev);
|
|
|
1819
|
} catch (IllegalArgumentException ex) {
|
|
|
1820
|
ex.printStackTrace();
|
|
1815
|
1821
|
}
|
|
1816
|
|
mVelocityTracker.addMovement(ev);
|
|
1817
|
|
|
|
1818
|
1822
|
/*
|
|
1819
|
1823
|
* The only time we want to intercept motion events is if we are in the
|
|
1820
|
1824
|
* drag mode.
|
|
|
@ -1824,128 +1828,133 @@ public class VerticalViewPager extends ViewGroup {
|
|
1824
|
1828
|
|
|
1825
|
1829
|
@Override
|
|
1826
|
1830
|
public boolean onTouchEvent(MotionEvent ev) {
|
|
1827
|
|
if (mFakeDragging) {
|
|
1828
|
|
// A fake drag is in progress already, ignore this real one
|
|
1829
|
|
// but still eat the touch events.
|
|
1830
|
|
// (It is likely that the user is multi-touching the screen.)
|
|
1831
|
|
return true;
|
|
1832
|
|
}
|
|
1833
|
|
|
|
1834
|
|
if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
|
|
1835
|
|
// Don't handle edge touches immediately -- they may actually belong to one of our
|
|
1836
|
|
// descendants.
|
|
1837
|
|
return false;
|
|
1838
|
|
}
|
|
|
1831
|
try {
|
|
|
1832
|
if (mFakeDragging) {
|
|
|
1833
|
// A fake drag is in progress already, ignore this real one
|
|
|
1834
|
// but still eat the touch events.
|
|
|
1835
|
// (It is likely that the user is multi-touching the screen.)
|
|
|
1836
|
return true;
|
|
|
1837
|
}
|
|
1839
|
1838
|
|
|
1840
|
|
if (mAdapter == null || mAdapter.getCount() == 0) {
|
|
1841
|
|
// Nothing to present or scroll; nothing to touch.
|
|
1842
|
|
return false;
|
|
1843
|
|
}
|
|
|
1839
|
if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
|
|
|
1840
|
// Don't handle edge touches immediately -- they may actually belong to one of our
|
|
|
1841
|
// descendants.
|
|
|
1842
|
return false;
|
|
|
1843
|
}
|
|
1844
|
1844
|
|
|
1845
|
|
if (mVelocityTracker == null) {
|
|
1846
|
|
mVelocityTracker = VelocityTracker.obtain();
|
|
1847
|
|
}
|
|
1848
|
|
mVelocityTracker.addMovement(ev);
|
|
|
1845
|
if (mAdapter == null || mAdapter.getCount() == 0) {
|
|
|
1846
|
// Nothing to present or scroll; nothing to touch.
|
|
|
1847
|
return false;
|
|
|
1848
|
}
|
|
1849
|
1849
|
|
|
1850
|
|
final int action = ev.getAction();
|
|
1851
|
|
boolean needsInvalidate = false;
|
|
|
1850
|
if (mVelocityTracker == null) {
|
|
|
1851
|
mVelocityTracker = VelocityTracker.obtain();
|
|
|
1852
|
}
|
|
|
1853
|
mVelocityTracker.addMovement(ev);
|
|
1852
|
1854
|
|
|
1853
|
|
switch (action & MotionEventCompat.ACTION_MASK) {
|
|
1854
|
|
case MotionEvent.ACTION_DOWN: {
|
|
1855
|
|
mScroller.abortAnimation();
|
|
1856
|
|
mPopulatePending = false;
|
|
1857
|
|
populate();
|
|
|
1855
|
final int action = ev.getAction();
|
|
|
1856
|
boolean needsInvalidate = false;
|
|
1858
|
1857
|
|
|
1859
|
|
// Remember where the motion event started
|
|
1860
|
|
mLastMotionX = mInitialMotionX = ev.getX();
|
|
1861
|
|
mLastMotionY = mInitialMotionY = ev.getY();
|
|
1862
|
|
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
|
|
1863
|
|
break;
|
|
1864
|
|
}
|
|
1865
|
|
case MotionEvent.ACTION_MOVE:
|
|
1866
|
|
if (!mIsBeingDragged) {
|
|
1867
|
|
final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
|
|
1868
|
|
final float y = MotionEventCompat.getY(ev, pointerIndex);
|
|
1869
|
|
final float yDiff = Math.abs(y - mLastMotionY);
|
|
1870
|
|
final float x = MotionEventCompat.getX(ev, pointerIndex);
|
|
1871
|
|
final float xDiff = Math.abs(x - mLastMotionX);
|
|
1872
|
|
if (DEBUG)
|
|
1873
|
|
Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
|
|
1874
|
|
if (yDiff > mTouchSlop && yDiff > xDiff) {
|
|
1875
|
|
if (DEBUG) Log.v(TAG, "Starting drag!");
|
|
1876
|
|
mIsBeingDragged = true;
|
|
1877
|
|
requestParentDisallowInterceptTouchEvent(true);
|
|
1878
|
|
mLastMotionY = y - mInitialMotionY > 0 ? mInitialMotionY + mTouchSlop :
|
|
1879
|
|
mInitialMotionY - mTouchSlop;
|
|
1880
|
|
mLastMotionX = x;
|
|
1881
|
|
setScrollState(SCROLL_STATE_DRAGGING);
|
|
1882
|
|
setScrollingCacheEnabled(true);
|
|
|
1858
|
switch (action & MotionEventCompat.ACTION_MASK) {
|
|
|
1859
|
case MotionEvent.ACTION_DOWN: {
|
|
|
1860
|
mScroller.abortAnimation();
|
|
|
1861
|
mPopulatePending = false;
|
|
|
1862
|
populate();
|
|
1883
|
1863
|
|
|
1884
|
|
// Disallow Parent Intercept, just in case
|
|
1885
|
|
ViewParent parent = getParent();
|
|
1886
|
|
if (parent != null) {
|
|
1887
|
|
parent.requestDisallowInterceptTouchEvent(true);
|
|
|
1864
|
// Remember where the motion event started
|
|
|
1865
|
mLastMotionX = mInitialMotionX = ev.getX();
|
|
|
1866
|
mLastMotionY = mInitialMotionY = ev.getY();
|
|
|
1867
|
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
|
|
|
1868
|
break;
|
|
|
1869
|
}
|
|
|
1870
|
case MotionEvent.ACTION_MOVE:
|
|
|
1871
|
if (!mIsBeingDragged) {
|
|
|
1872
|
final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
|
|
|
1873
|
final float y = MotionEventCompat.getY(ev, pointerIndex);
|
|
|
1874
|
final float yDiff = Math.abs(y - mLastMotionY);
|
|
|
1875
|
final float x = MotionEventCompat.getX(ev, pointerIndex);
|
|
|
1876
|
final float xDiff = Math.abs(x - mLastMotionX);
|
|
|
1877
|
if (DEBUG)
|
|
|
1878
|
Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
|
|
|
1879
|
if (yDiff > mTouchSlop && yDiff > xDiff) {
|
|
|
1880
|
if (DEBUG) Log.v(TAG, "Starting drag!");
|
|
|
1881
|
mIsBeingDragged = true;
|
|
|
1882
|
requestParentDisallowInterceptTouchEvent(true);
|
|
|
1883
|
mLastMotionY = y - mInitialMotionY > 0 ? mInitialMotionY + mTouchSlop :
|
|
|
1884
|
mInitialMotionY - mTouchSlop;
|
|
|
1885
|
mLastMotionX = x;
|
|
|
1886
|
setScrollState(SCROLL_STATE_DRAGGING);
|
|
|
1887
|
setScrollingCacheEnabled(true);
|
|
|
1888
|
|
|
|
1889
|
// Disallow Parent Intercept, just in case
|
|
|
1890
|
ViewParent parent = getParent();
|
|
|
1891
|
if (parent != null) {
|
|
|
1892
|
parent.requestDisallowInterceptTouchEvent(true);
|
|
|
1893
|
}
|
|
1888
|
1894
|
}
|
|
1889
|
1895
|
}
|
|
|
1896
|
// Not else! Note that mIsBeingDragged can be set above.
|
|
|
1897
|
if (mIsBeingDragged) {
|
|
|
1898
|
// Scroll to follow the motion event
|
|
|
1899
|
final int activePointerIndex = MotionEventCompat.findPointerIndex(
|
|
|
1900
|
ev, mActivePointerId);
|
|
|
1901
|
final float y = MotionEventCompat.getY(ev, activePointerIndex);
|
|
|
1902
|
needsInvalidate |= performDrag(y);
|
|
|
1903
|
}
|
|
|
1904
|
break;
|
|
|
1905
|
case MotionEvent.ACTION_UP:
|
|
|
1906
|
if (mIsBeingDragged) {
|
|
|
1907
|
final VelocityTracker velocityTracker = mVelocityTracker;
|
|
|
1908
|
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
|
|
|
1909
|
int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
|
|
|
1910
|
velocityTracker, mActivePointerId);
|
|
|
1911
|
mPopulatePending = true;
|
|
|
1912
|
final int height = getClientHeight();
|
|
|
1913
|
final int scrollY = getScrollY();
|
|
|
1914
|
final ItemInfo ii = infoForCurrentScrollPosition();
|
|
|
1915
|
final int currentPage = ii.position;
|
|
|
1916
|
final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
|
|
|
1917
|
final int activePointerIndex =
|
|
|
1918
|
MotionEventCompat.findPointerIndex(ev, mActivePointerId);
|
|
|
1919
|
final float y = MotionEventCompat.getY(ev, activePointerIndex);
|
|
|
1920
|
final int totalDelta = (int) (y - mInitialMotionY);
|
|
|
1921
|
int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
|
|
|
1922
|
totalDelta);
|
|
|
1923
|
setCurrentItemInternal(nextPage, true, true, initialVelocity);
|
|
|
1924
|
|
|
|
1925
|
mActivePointerId = INVALID_POINTER;
|
|
|
1926
|
endDrag();
|
|
|
1927
|
needsInvalidate = mTopEdge.onRelease() | mBottomEdge.onRelease();
|
|
|
1928
|
}
|
|
|
1929
|
break;
|
|
|
1930
|
case MotionEvent.ACTION_CANCEL:
|
|
|
1931
|
if (mIsBeingDragged) {
|
|
|
1932
|
scrollToItem(mCurItem, true, 0, false);
|
|
|
1933
|
mActivePointerId = INVALID_POINTER;
|
|
|
1934
|
endDrag();
|
|
|
1935
|
needsInvalidate = mTopEdge.onRelease() | mBottomEdge.onRelease();
|
|
|
1936
|
}
|
|
|
1937
|
break;
|
|
|
1938
|
case MotionEventCompat.ACTION_POINTER_DOWN: {
|
|
|
1939
|
final int index = MotionEventCompat.getActionIndex(ev);
|
|
|
1940
|
final float y = MotionEventCompat.getY(ev, index);
|
|
|
1941
|
mLastMotionY = y;
|
|
|
1942
|
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
|
|
|
1943
|
break;
|
|
1890
|
1944
|
}
|
|
1891
|
|
// Not else! Note that mIsBeingDragged can be set above.
|
|
1892
|
|
if (mIsBeingDragged) {
|
|
1893
|
|
// Scroll to follow the motion event
|
|
1894
|
|
final int activePointerIndex = MotionEventCompat.findPointerIndex(
|
|
1895
|
|
ev, mActivePointerId);
|
|
1896
|
|
final float y = MotionEventCompat.getY(ev, activePointerIndex);
|
|
1897
|
|
needsInvalidate |= performDrag(y);
|
|
1898
|
|
}
|
|
1899
|
|
break;
|
|
1900
|
|
case MotionEvent.ACTION_UP:
|
|
1901
|
|
if (mIsBeingDragged) {
|
|
1902
|
|
final VelocityTracker velocityTracker = mVelocityTracker;
|
|
1903
|
|
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
|
|
1904
|
|
int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
|
|
1905
|
|
velocityTracker, mActivePointerId);
|
|
1906
|
|
mPopulatePending = true;
|
|
1907
|
|
final int height = getClientHeight();
|
|
1908
|
|
final int scrollY = getScrollY();
|
|
1909
|
|
final ItemInfo ii = infoForCurrentScrollPosition();
|
|
1910
|
|
final int currentPage = ii.position;
|
|
1911
|
|
final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
|
|
1912
|
|
final int activePointerIndex =
|
|
1913
|
|
MotionEventCompat.findPointerIndex(ev, mActivePointerId);
|
|
1914
|
|
final float y = MotionEventCompat.getY(ev, activePointerIndex);
|
|
1915
|
|
final int totalDelta = (int) (y - mInitialMotionY);
|
|
1916
|
|
int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
|
|
1917
|
|
totalDelta);
|
|
1918
|
|
setCurrentItemInternal(nextPage, true, true, initialVelocity);
|
|
1919
|
|
|
|
1920
|
|
mActivePointerId = INVALID_POINTER;
|
|
1921
|
|
endDrag();
|
|
1922
|
|
needsInvalidate = mTopEdge.onRelease() | mBottomEdge.onRelease();
|
|
1923
|
|
}
|
|
1924
|
|
break;
|
|
1925
|
|
case MotionEvent.ACTION_CANCEL:
|
|
1926
|
|
if (mIsBeingDragged) {
|
|
1927
|
|
scrollToItem(mCurItem, true, 0, false);
|
|
1928
|
|
mActivePointerId = INVALID_POINTER;
|
|
1929
|
|
endDrag();
|
|
1930
|
|
needsInvalidate = mTopEdge.onRelease() | mBottomEdge.onRelease();
|
|
1931
|
|
}
|
|
1932
|
|
break;
|
|
1933
|
|
case MotionEventCompat.ACTION_POINTER_DOWN: {
|
|
1934
|
|
final int index = MotionEventCompat.getActionIndex(ev);
|
|
1935
|
|
final float y = MotionEventCompat.getY(ev, index);
|
|
1936
|
|
mLastMotionY = y;
|
|
1937
|
|
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
|
|
1938
|
|
break;
|
|
|
1945
|
case MotionEventCompat.ACTION_POINTER_UP:
|
|
|
1946
|
onSecondaryPointerUp(ev);
|
|
|
1947
|
mLastMotionY = MotionEventCompat.getY(ev,
|
|
|
1948
|
MotionEventCompat.findPointerIndex(ev, mActivePointerId));
|
|
|
1949
|
break;
|
|
1939
|
1950
|
}
|
|
1940
|
|
case MotionEventCompat.ACTION_POINTER_UP:
|
|
1941
|
|
onSecondaryPointerUp(ev);
|
|
1942
|
|
mLastMotionY = MotionEventCompat.getY(ev,
|
|
1943
|
|
MotionEventCompat.findPointerIndex(ev, mActivePointerId));
|
|
1944
|
|
break;
|
|
1945
|
|
}
|
|
1946
|
|
if (needsInvalidate) {
|
|
1947
|
|
ViewCompat.postInvalidateOnAnimation(this);
|
|
|
1951
|
if (needsInvalidate) {
|
|
|
1952
|
ViewCompat.postInvalidateOnAnimation(this);
|
|
|
1953
|
}
|
|
|
1954
|
} catch (IllegalArgumentException ex) {
|
|
|
1955
|
ex.printStackTrace();
|
|
1948
|
1956
|
}
|
|
|
1957
|
|
|
1949
|
1958
|
return true;
|
|
1950
|
1959
|
}
|
|
1951
|
1960
|
|