Esempio n. 1
0
 @Override
 public void scrollBy(int x, int y) {
   super.scrollBy(x, y);
   progressUpdate();
 }
Esempio n. 2
0
  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        /*
         * 记录起始信息
         */
        mStartY = ev.getY();
        mLastY = ev.getY();
        mDispatched = true;
        mCanceledScroll = false;
        break;
      case MotionEvent.ACTION_MOVE:
        float dy = ev.getY() - mLastY;
        float dySinceStart = (ev.getY() - mStartY) / RATIO;
        mLastY = ev.getY();

        /*
         * 自动切换卡片事件触发
         */
        if ((mMovingAnimation == null || mMovingAnimation.isAnimationEnded())
            && mDispatched
            && mCurrentCardView != null
            && Math.abs(dySinceStart) > mCurrentCardView.getCardShrinkHeight()) {
          int indexNext = -1;
          if (dySinceStart > 0) {
            indexNext = mCardLayouts.indexOf(mCurrentCardView) - 1;
          } else {
            indexNext = mCardLayouts.indexOf(mCurrentCardView) + 1;
          }

          if (indexNext >= 0 && indexNext < mCardLayouts.size()) {
            onCardClick(mCardLayouts.get(indexNext));
            mDispatched = false;
            mCanceledScroll = true;
          }
        }

        /*
         * 操作滚动条
         */
        if (!mCanceledScroll) {
          mContainerScrollView.scrollBy(0, -(int) (dy / RATIO));
        }
        break;
      case MotionEvent.ACTION_UP:
        /*
         * 松开手指,自动回弹效果
         */
        if ((mMovingAnimation == null || mMovingAnimation.isAnimationEnded())
            && mCurrentCardView != null) {
          mContainerScrollView.smoothScrollTo(
              0,
              mCardLayouts.indexOf(mCurrentCardView) * mCurrentCardView.getCardShrinkHeight()
                  - (getMeasuredHeight() - mCurrentCardView.getCardExpandHeight()) / 2);
        }
        /*
         * 恢复初始状态
         */
        mDispatched = false;
        mCanceledScroll = false;
        break;
    }
    return super.dispatchTouchEvent(ev);
  }