|
43 | 43 | import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
|
44 | 44 | import androidx.customview.view.AbsSavedState;
|
45 | 45 | import androidx.viewpager.widget.PagerAdapter;
|
| 46 | + |
46 | 47 | import com.smarteist.autoimageslider.InfiniteAdapter.InfinitePagerAdapter;
|
| 48 | + |
47 | 49 | import java.lang.annotation.ElementType;
|
48 | 50 | import java.lang.annotation.Inherited;
|
49 | 51 | import java.lang.annotation.Retention;
|
@@ -2026,138 +2028,143 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
|
2026 | 2028 | * If we return true, onMotionEvent will be called and we do the actual
|
2027 | 2029 | * scrolling there.
|
2028 | 2030 | */
|
| 2031 | + try { |
| 2032 | + final int action = ev.getAction() & MotionEvent.ACTION_MASK; |
2029 | 2033 |
|
2030 |
| - final int action = ev.getAction() & MotionEvent.ACTION_MASK; |
2031 |
| - |
2032 |
| - // Always take care of the touch gesture being complete. |
2033 |
| - if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { |
2034 |
| - // Release the drag. |
2035 |
| - if (DEBUG) Log.v(TAG, "Intercept done!"); |
2036 |
| - resetTouch(); |
2037 |
| - return false; |
2038 |
| - } |
2039 |
| - |
2040 |
| - // Nothing more to do here if we have decided whether or not we |
2041 |
| - // are dragging. |
2042 |
| - if (action != MotionEvent.ACTION_DOWN) { |
2043 |
| - if (mIsBeingDragged) { |
2044 |
| - if (DEBUG) Log.v(TAG, "Intercept returning true!"); |
2045 |
| - return true; |
2046 |
| - } |
2047 |
| - if (mIsUnableToDrag) { |
2048 |
| - if (DEBUG) Log.v(TAG, "Intercept returning false!"); |
| 2034 | + // Always take care of the touch gesture being complete. |
| 2035 | + if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { |
| 2036 | + // Release the drag. |
| 2037 | + if (DEBUG) Log.v(TAG, "Intercept done!"); |
| 2038 | + resetTouch(); |
2049 | 2039 | return false;
|
2050 | 2040 | }
|
2051 |
| - } |
2052 | 2041 |
|
2053 |
| - switch (action) { |
2054 |
| - case MotionEvent.ACTION_MOVE: { |
2055 |
| - /* |
2056 |
| - * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
2057 |
| - * whether the user has moved far enough from his original down touch. |
2058 |
| - */ |
2059 |
| - |
2060 |
| - /* |
2061 |
| - * Locally do absolute value. mLastMotionY is set to the y value |
2062 |
| - * of the down event. |
2063 |
| - */ |
2064 |
| - final int activePointerId = mActivePointerId; |
2065 |
| - if (activePointerId == INVALID_POINTER) { |
2066 |
| - // If we don't have a valid id, the touch down wasn't on content. |
2067 |
| - break; |
| 2042 | + // Nothing more to do here if we have decided whether or not we |
| 2043 | + // are dragging. |
| 2044 | + if (action != MotionEvent.ACTION_DOWN) { |
| 2045 | + if (mIsBeingDragged) { |
| 2046 | + if (DEBUG) Log.v(TAG, "Intercept returning true!"); |
| 2047 | + return true; |
2068 | 2048 | }
|
2069 |
| - |
2070 |
| - final int pointerIndex = ev.findPointerIndex(activePointerId); |
2071 |
| - final float x = ev.getX(pointerIndex); |
2072 |
| - final float dx = x - mLastMotionX; |
2073 |
| - final float xDiff = Math.abs(dx); |
2074 |
| - final float y = ev.getY(pointerIndex); |
2075 |
| - final float yDiff = Math.abs(y - mInitialMotionY); |
2076 |
| - if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff); |
2077 |
| - |
2078 |
| - if (dx != 0 && !isGutterDrag(mLastMotionX, dx) |
2079 |
| - && canScroll(this, false, (int) dx, (int) x, (int) y)) { |
2080 |
| - // Nested view has scrollable area under this point. Let it be handled there. |
2081 |
| - mLastMotionX = x; |
2082 |
| - mLastMotionY = y; |
2083 |
| - mIsUnableToDrag = true; |
| 2049 | + if (mIsUnableToDrag) { |
| 2050 | + if (DEBUG) Log.v(TAG, "Intercept returning false!"); |
2084 | 2051 | return false;
|
2085 | 2052 | }
|
2086 |
| - if (xDiff > mTouchSlop && xDiff * 0.5f > yDiff) { |
2087 |
| - if (DEBUG) Log.v(TAG, "Starting drag!"); |
2088 |
| - mIsBeingDragged = true; |
2089 |
| - requestParentDisallowInterceptTouchEvent(true); |
2090 |
| - setScrollState(SCROLL_STATE_DRAGGING); |
2091 |
| - mLastMotionX = dx > 0 |
2092 |
| - ? mInitialMotionX + mTouchSlop : mInitialMotionX - mTouchSlop; |
2093 |
| - mLastMotionY = y; |
2094 |
| - setScrollingCacheEnabled(true); |
2095 |
| - } else if (yDiff > mTouchSlop) { |
2096 |
| - // The finger has moved enough in the vertical |
2097 |
| - // direction to be counted as a drag... abort |
2098 |
| - // any attempt to drag horizontally, to work correctly |
2099 |
| - // with children that have scrolling containers. |
2100 |
| - if (DEBUG) Log.v(TAG, "Starting unable to drag!"); |
2101 |
| - mIsUnableToDrag = true; |
2102 |
| - } |
2103 |
| - if (mIsBeingDragged) { |
2104 |
| - // Scroll to follow the motion event |
2105 |
| - if (performDrag(x)) { |
2106 |
| - ViewCompat.postInvalidateOnAnimation(this); |
2107 |
| - } |
2108 |
| - } |
2109 |
| - break; |
2110 | 2053 | }
|
2111 | 2054 |
|
2112 |
| - case MotionEvent.ACTION_DOWN: { |
2113 |
| - /* |
2114 |
| - * Remember location of down touch. |
2115 |
| - * ACTION_DOWN always refers to pointer index 0. |
2116 |
| - */ |
2117 |
| - mLastMotionX = mInitialMotionX = ev.getX(); |
2118 |
| - mLastMotionY = mInitialMotionY = ev.getY(); |
2119 |
| - mActivePointerId = ev.getPointerId(0); |
2120 |
| - mIsUnableToDrag = false; |
| 2055 | + switch (action) { |
| 2056 | + case MotionEvent.ACTION_MOVE: { |
| 2057 | + /* |
| 2058 | + * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check |
| 2059 | + * whether the user has moved far enough from his original down touch. |
| 2060 | + */ |
| 2061 | + |
| 2062 | + /* |
| 2063 | + * Locally do absolute value. mLastMotionY is set to the y value |
| 2064 | + * of the down event. |
| 2065 | + */ |
| 2066 | + final int activePointerId = mActivePointerId; |
| 2067 | + if (activePointerId == INVALID_POINTER) { |
| 2068 | + // If we don't have a valid id, the touch down wasn't on content. |
| 2069 | + break; |
| 2070 | + } |
2121 | 2071 |
|
2122 |
| - mIsScrollStarted = true; |
2123 |
| - mScroller.computeScrollOffset(); |
2124 |
| - if (mScrollState == SCROLL_STATE_SETTLING |
2125 |
| - && Math.abs(mScroller.getFinalX() - mScroller.getCurrX()) > mCloseEnough) { |
2126 |
| - // Let the user 'catch' the pager as it animates. |
2127 |
| - mScroller.abortAnimation(); |
2128 |
| - mPopulatePending = false; |
2129 |
| - populate(); |
2130 |
| - mIsBeingDragged = true; |
2131 |
| - requestParentDisallowInterceptTouchEvent(true); |
2132 |
| - setScrollState(SCROLL_STATE_DRAGGING); |
2133 |
| - } else { |
2134 |
| - completeScroll(false); |
2135 |
| - mIsBeingDragged = false; |
| 2072 | + final int pointerIndex = ev.findPointerIndex(activePointerId); |
| 2073 | + final float x = ev.getX(pointerIndex); |
| 2074 | + final float dx = x - mLastMotionX; |
| 2075 | + final float xDiff = Math.abs(dx); |
| 2076 | + final float y = ev.getY(pointerIndex); |
| 2077 | + final float yDiff = Math.abs(y - mInitialMotionY); |
| 2078 | + if (DEBUG) |
| 2079 | + Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff); |
| 2080 | + |
| 2081 | + if (dx != 0 && !isGutterDrag(mLastMotionX, dx) |
| 2082 | + && canScroll(this, false, (int) dx, (int) x, (int) y)) { |
| 2083 | + // Nested view has scrollable area under this point. Let it be handled there. |
| 2084 | + mLastMotionX = x; |
| 2085 | + mLastMotionY = y; |
| 2086 | + mIsUnableToDrag = true; |
| 2087 | + return false; |
| 2088 | + } |
| 2089 | + if (xDiff > mTouchSlop && xDiff * 0.5f > yDiff) { |
| 2090 | + if (DEBUG) Log.v(TAG, "Starting drag!"); |
| 2091 | + mIsBeingDragged = true; |
| 2092 | + requestParentDisallowInterceptTouchEvent(true); |
| 2093 | + setScrollState(SCROLL_STATE_DRAGGING); |
| 2094 | + mLastMotionX = dx > 0 |
| 2095 | + ? mInitialMotionX + mTouchSlop : mInitialMotionX - mTouchSlop; |
| 2096 | + mLastMotionY = y; |
| 2097 | + setScrollingCacheEnabled(true); |
| 2098 | + } else if (yDiff > mTouchSlop) { |
| 2099 | + // The finger has moved enough in the vertical |
| 2100 | + // direction to be counted as a drag... abort |
| 2101 | + // any attempt to drag horizontally, to work correctly |
| 2102 | + // with children that have scrolling containers. |
| 2103 | + if (DEBUG) Log.v(TAG, "Starting unable to drag!"); |
| 2104 | + mIsUnableToDrag = true; |
| 2105 | + } |
| 2106 | + if (mIsBeingDragged) { |
| 2107 | + // Scroll to follow the motion event |
| 2108 | + if (performDrag(x)) { |
| 2109 | + ViewCompat.postInvalidateOnAnimation(this); |
| 2110 | + } |
| 2111 | + } |
| 2112 | + break; |
2136 | 2113 | }
|
2137 | 2114 |
|
2138 |
| - if (DEBUG) { |
2139 |
| - Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY |
2140 |
| - + " mIsBeingDragged=" + mIsBeingDragged |
2141 |
| - + "mIsUnableToDrag=" + mIsUnableToDrag); |
| 2115 | + case MotionEvent.ACTION_DOWN: { |
| 2116 | + /* |
| 2117 | + * Remember location of down touch. |
| 2118 | + * ACTION_DOWN always refers to pointer index 0. |
| 2119 | + */ |
| 2120 | + mLastMotionX = mInitialMotionX = ev.getX(); |
| 2121 | + mLastMotionY = mInitialMotionY = ev.getY(); |
| 2122 | + mActivePointerId = ev.getPointerId(0); |
| 2123 | + mIsUnableToDrag = false; |
| 2124 | + |
| 2125 | + mIsScrollStarted = true; |
| 2126 | + mScroller.computeScrollOffset(); |
| 2127 | + if (mScrollState == SCROLL_STATE_SETTLING |
| 2128 | + && Math.abs(mScroller.getFinalX() - mScroller.getCurrX()) > mCloseEnough) { |
| 2129 | + // Let the user 'catch' the pager as it animates. |
| 2130 | + mScroller.abortAnimation(); |
| 2131 | + mPopulatePending = false; |
| 2132 | + populate(); |
| 2133 | + mIsBeingDragged = true; |
| 2134 | + requestParentDisallowInterceptTouchEvent(true); |
| 2135 | + setScrollState(SCROLL_STATE_DRAGGING); |
| 2136 | + } else { |
| 2137 | + completeScroll(false); |
| 2138 | + mIsBeingDragged = false; |
| 2139 | + } |
| 2140 | + |
| 2141 | + if (DEBUG) { |
| 2142 | + Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY |
| 2143 | + + " mIsBeingDragged=" + mIsBeingDragged |
| 2144 | + + "mIsUnableToDrag=" + mIsUnableToDrag); |
| 2145 | + } |
| 2146 | + break; |
2142 | 2147 | }
|
2143 |
| - break; |
| 2148 | + |
| 2149 | + case MotionEvent.ACTION_POINTER_UP: |
| 2150 | + onSecondaryPointerUp(ev); |
| 2151 | + break; |
2144 | 2152 | }
|
2145 | 2153 |
|
2146 |
| - case MotionEvent.ACTION_POINTER_UP: |
2147 |
| - onSecondaryPointerUp(ev); |
2148 |
| - break; |
2149 |
| - } |
| 2154 | + if (mVelocityTracker == null) { |
| 2155 | + mVelocityTracker = VelocityTracker.obtain(); |
| 2156 | + } |
| 2157 | + mVelocityTracker.addMovement(ev); |
2150 | 2158 |
|
2151 |
| - if (mVelocityTracker == null) { |
2152 |
| - mVelocityTracker = VelocityTracker.obtain(); |
| 2159 | + /* |
| 2160 | + * The only time we want to intercept motion events is if we are in the |
| 2161 | + * drag mode. |
| 2162 | + */ |
| 2163 | + return mIsBeingDragged; |
| 2164 | + } catch (Exception e) { |
| 2165 | + e.printStackTrace(); |
| 2166 | + return false; |
2153 | 2167 | }
|
2154 |
| - mVelocityTracker.addMovement(ev); |
2155 |
| - |
2156 |
| - /* |
2157 |
| - * The only time we want to intercept motion events is if we are in the |
2158 |
| - * drag mode. |
2159 |
| - */ |
2160 |
| - return mIsBeingDragged; |
2161 | 2168 | }
|
2162 | 2169 |
|
2163 | 2170 | @Override
|
|
0 commit comments