예제 #1
0
  public boolean onTouchEvent(@NonNull MotionEvent event) {
    final int action = MotionEventCompat.getActionMasked(event);
    if (action == MotionEvent.ACTION_MOVE) {
      mVelocityTracker.addMovement(event);
    }
    if (mState == State.DRAGGING) {
      switch (action) {
        case MotionEvent.ACTION_MOVE:
          int deltaY = calculateDistanceForDrag(event);
          mProgressManager.applyDelta(deltaY);
          break;
        case MotionEvent.ACTION_UP:
          finishMotionEvent();
          if (type == LEFT) {
            mCalendarView.prev();
          } else if (type == RIGHT) {
            mCalendarView.next();
          }
          break;
      }

    } else if (action == MotionEvent.ACTION_MOVE) {
      checkForResizing(event);
    } else if (action == MotionEvent.ACTION_UP) {
      if (type == LEFT) {
        mCalendarView.prev();
      } else if (type == RIGHT) {
        mCalendarView.next();
      }
    }

    return true;
  }
예제 #2
0
 public ResizeManager(@NonNull CollapseCalendarView calendarView) {
   mCalendarView = calendarView;
   mScroller = new Scroller(calendarView.getContext());
   ViewConfiguration viewConfig = ViewConfiguration.get(mCalendarView.getContext());
   mTouchSlop = viewConfig.getScaledTouchSlop();
   mMinFlingVelocity = viewConfig.getScaledMinimumFlingVelocity();
   mMaxFlingVelocity = viewConfig.getScaledMaximumFlingVelocity();
 }
예제 #3
0
  private void startScolling() {

    mVelocityTracker.computeCurrentVelocity(1000, mMaxFlingVelocity);
    int velocity = (int) mVelocityTracker.getYVelocity();

    if (!mScroller.isFinished()) {
      mScroller.forceFinished(true);
    }

    int progress = mProgressManager.getCurrentHeight();
    int end;
    if (Math.abs(velocity) > mMinFlingVelocity) {

      if (velocity > 0) {
        end = mProgressManager.getEndSize() - progress;
      } else {
        end = -progress;
      }

    } else {

      int endSize = mProgressManager.getEndSize();
      if (endSize / 2 <= progress) {
        end = endSize - progress;
      } else {
        end = -progress;
      }
    }

    mScroller.startScroll(0, progress, 0, end);
    mCalendarView.postInvalidate();

    mState = State.SETTLING;
  }
예제 #4
0
 public boolean onInterceptTouchEvent(@NonNull MotionEvent ev) {
   final int action = MotionEventCompat.getActionMasked(ev);
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       type = -1;
       return onDownEvent(ev);
     case MotionEvent.ACTION_MOVE:
       mVelocityTracker.addMovement(ev);
       return checkForResizing(ev);
     case MotionEvent.ACTION_UP:
       finishMotionEvent();
       if (type == LEFT) {
         mCalendarView.prev();
       } else if (type == RIGHT) {
         mCalendarView.next();
       }
       return false;
   }
   return false;
 }
예제 #5
0
 public void onDraw() {
   if (!mScroller.isFinished()) {
     mScroller.computeScrollOffset();
     float position = mScroller.getCurrY() * 1f / mProgressManager.getEndSize();
     mProgressManager.apply(position);
     mCalendarView.postInvalidate();
   } else if (mState == State.SETTLING) {
     mState = State.IDLE;
     float position = mScroller.getCurrY() * 1f / mProgressManager.getEndSize();
     mProgressManager.finish(position > 0);
     mProgressManager = null;
   }
 }
예제 #6
0
  public boolean checkForResizing(
      MotionEvent
          ev) { // FIXME this method should only return true / false. Make another method for
                // starting animation
    if (mState == State.DRAGGING) {
      return true;
    }

    final float yDIff = calculateDistance(ev);
    if (Math.abs(calculateXDistanse(ev)) > Math.abs(calculateDistance(ev))) {
      if (calculateXDistanse(ev) > 100) {
        type = LEFT;
      } else if (calculateXDistanse(ev) < -100) {
        type = RIGHT;
      }
    } else {
      CalendarManager manager = mCalendarView.getManager();
      CalendarManager.State state = manager.getState();
      if (Math.abs(yDIff)
          > mTouchSlop) { // FIXME this should happen only if dragging int right direction
        mState = State.DRAGGING;
        mDragStartY = ev.getY();
        if (mProgressManager == null) {
          int weekOfMonth = manager.getWeekOfMonth();
          if (state == CalendarManager.State.WEEK) { // always animate in month view
            manager.toggleView();
            mCalendarView.populateLayout();
          }
          mProgressManager =
              new ProgressManagerImpl(
                  mCalendarView, weekOfMonth, state == CalendarManager.State.MONTH);
        }
        return true;
      }
    }
    return false;
  }