コード例 #1
0
ファイル: PtrFrameLayout.java プロジェクト: yqfs/AGOCAL
 /** If at the top and not in loading, reset */
 private boolean tryToNotifyReset() {
   if ((mStatus == PTR_STATUS_COMPLETE || mStatus == PTR_STATUS_PREPARE)
       && mPtrIndicator.isInStartPosition()) {
     if (mPtrUIHandlerHolder.hasHandler()) {
       mPtrUIHandlerHolder.onUIReset(this);
       if (DEBUG) {
         PtrCLog.i(LOG_TAG, "PtrUIHandler: onUIReset");
       }
     }
     mStatus = PTR_STATUS_INIT;
     clearFlag();
     return true;
   }
   return false;
 }
コード例 #2
0
ファイル: PtrFrameLayout.java プロジェクト: yqfs/AGOCAL
  /**
   * if deltaY > 0, move the content down
   *
   * @param deltaY
   */
  private void movePos(float deltaY) {
    // has reached the top
    if ((deltaY < 0 && mPtrIndicator.isInStartPosition())) {
      if (DEBUG) {
        PtrCLog.e(LOG_TAG, String.format("has reached the top"));
      }
      return;
    }

    int to = mPtrIndicator.getCurrentPosY() + (int) deltaY;

    // over top
    if (mPtrIndicator.willOverTop(to)) {
      if (DEBUG) {
        PtrCLog.e(LOG_TAG, String.format("over top"));
      }
      to = PtrIndicator.POS_START;
    }

    mPtrIndicator.setCurrentPos(to);
    int change = to - mPtrIndicator.getLastPosY();
    updatePos(change);
  }
コード例 #3
0
ファイル: PtrFrameLayout.java プロジェクト: yqfs/AGOCAL
  @Override
  public boolean dispatchTouchEvent(MotionEvent e) {
    if (!isEnabled() || mContent == null || mHeaderView == null) {
      return dispatchTouchEventSupper(e);
    }
    int action = e.getAction();
    switch (action) {
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        mPtrIndicator.onRelease();
        if (mPtrIndicator.hasLeftStartPosition()) {
          if (DEBUG) {
            PtrCLog.d(LOG_TAG, "call onRelease when user release");
          }
          onRelease(false);
          if (mPtrIndicator.hasMovedAfterPressedDown()) {
            sendCancelEvent();
            return true;
          }
          return dispatchTouchEventSupper(e);
        } else {
          return dispatchTouchEventSupper(e);
        }

      case MotionEvent.ACTION_DOWN:
        mHasSendCancelEvent = false;
        mPtrIndicator.onPressDown(e.getX(), e.getY());

        mScrollChecker.abortIfWorking();

        mPreventForHorizontal = false;
        // The cancel event will be sent once the position is moved.
        // So let the event pass to children.
        // fix #93, #102
        dispatchTouchEventSupper(e);
        return true;

      case MotionEvent.ACTION_MOVE:
        mLastMoveEvent = e;
        mPtrIndicator.onMove(e.getX(), e.getY());
        float offsetX = mPtrIndicator.getOffsetX();
        float offsetY = mPtrIndicator.getOffsetY();

        if (mDisableWhenHorizontalMove
            && !mPreventForHorizontal
            && (Math.abs(offsetX) > mPagingTouchSlop && Math.abs(offsetX) > Math.abs(offsetY))) {
          if (mPtrIndicator.isInStartPosition()) {
            mPreventForHorizontal = true;
          }
        }
        if (mPreventForHorizontal) {
          return dispatchTouchEventSupper(e);
        }

        boolean moveDown = offsetY > 0;
        boolean moveUp = !moveDown;
        boolean canMoveUp = mPtrIndicator.hasLeftStartPosition();

        if (DEBUG) {
          boolean canMoveDown =
              mPtrHandler != null && mPtrHandler.checkCanDoRefresh(this, mContent, mHeaderView);
          PtrCLog.v(
              LOG_TAG,
              "ACTION_MOVE: offsetY:%s, currentPos: %s, moveUp: %s, canMoveUp: %s, moveDown: %s: canMoveDown: %s",
              offsetY,
              mPtrIndicator.getCurrentPosY(),
              moveUp,
              canMoveUp,
              moveDown,
              canMoveDown);
        }

        // disable move when header not reach top
        if (moveDown
            && mPtrHandler != null
            && !mPtrHandler.checkCanDoRefresh(this, mContent, mHeaderView)) {
          return dispatchTouchEventSupper(e);
        }

        if ((moveUp && canMoveUp) || moveDown) {
          movePos(offsetY);
          return true;
        }
    }
    return dispatchTouchEventSupper(e);
  }