2014-10-22 23 views
5

我注意到該函數在Action_down之後沒有中斷,則代碼可以運行到ACTION_MOVE中,是嗎?在Android 5的SwipeRefreshLayout.java沒有中斷onInterceptTouchEvent模塊

@Override 
public boolean onInterceptTouchEvent(MotionEvent ev) { 
    ensureTarget(); 

    final int action = MotionEventCompat.getActionMasked(ev); 

    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { 
     mReturningToStart = false; 
    } 

    if (!isEnabled() || mReturningToStart || canChildScrollUp() || mRefreshing) { 
     // Fail fast if we're not in a state where a swipe is possible 
     return false; 
    } 

    switch (action) { 
     case MotionEvent.ACTION_DOWN: 
      setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCircleView.getTop(), true); 
      mActivePointerId = MotionEventCompat.getPointerId(ev, 0); 
      mIsBeingDragged = false; 
      final float initialMotionY = getMotionEventY(ev, mActivePointerId); 
      if (initialMotionY == -1) { 
       return false; 
      } 
      mInitialMotionY = initialMotionY; 
      //-------NO Break here, why? It will run down to ACTION_MOVE 
     case MotionEvent.ACTION_MOVE: 
      if (mActivePointerId == INVALID_POINTER) { 
       Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id."); 
       return false; 
      } 
      final float y = getMotionEventY(ev, mActivePointerId); 
      if (y == -1) { 
       return false; 
      } 
      final float yDiff = y - mInitialMotionY; 
      if (yDiff > mTouchSlop && !mIsBeingDragged) { 
       mIsBeingDragged = true; 
       mProgress.setAlpha(STARTING_PROGRESS_ALPHA); 
      } 
      break; 

     case MotionEventCompat.ACTION_POINTER_UP: 
      onSecondaryPointerUp(ev); 
      break; 

     case MotionEvent.ACTION_UP: 
     case MotionEvent.ACTION_CANCEL: 
      mIsBeingDragged = false; 
      mActivePointerId = INVALID_POINTER; 
      break; 
    } 

    return mIsBeingDragged; 
} 

我不知道爲什麼治療ACTION_DOWN,然後直接治療ACTION_MOVE,是這樣嗎? 在此先感謝。

+0

剛剛在我的日誌中注意到了這一點,很好的地方。謝謝。 – 2014-12-02 17:18:17

回答

相關問題