-
Notifications
You must be signed in to change notification settings - Fork 65
Allow scroll by the amount of days setted in NumberOfVisibleDays #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,6 +179,11 @@ private enum Direction { | |
| private ScrollListener mScrollListener; | ||
| private AddEventClickListener mAddEventClickListener; | ||
|
|
||
| //Scroll by amount of days desired functionnality | ||
| private boolean mIsCustomScrollableAmountsOfDaysEnabled = false; | ||
| private float startOriginForScroll = 0; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference and relation with
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current origin.x is updated when I started to scroll.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, but wouldn't it be possible without this variable ? If it is possible, please remove this extra variable |
||
| private float sizeOfScrollableView; | ||
|
||
|
|
||
| private final GestureDetector.SimpleOnGestureListener mGestureListener = new GestureDetector.SimpleOnGestureListener() { | ||
|
|
||
| @Override | ||
|
|
@@ -279,7 +284,9 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve | |
| switch (mCurrentFlingDirection) { | ||
| case LEFT: | ||
| case RIGHT: | ||
| mScroller.fling((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, (int) (velocityX * mXScrollingSpeed), 0, (int) getXMinLimit(), (int) getXMaxLimit(), (int) getYMinLimit(), (int) getYMaxLimit()); | ||
| if(!mIsCustomScrollableAmountsOfDaysEnabled) { | ||
| mScroller.fling((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, (int) (velocityX * mXScrollingSpeed), 0, (int) getXMinLimit(), (int) getXMaxLimit(), (int) getYMinLimit(), (int) getYMaxLimit()); | ||
| } | ||
| break; | ||
| case VERTICAL: | ||
| mScroller.fling((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, 0, (int) velocityY, (int) getXMinLimit(), (int) getXMaxLimit(), (int) getYMinLimit(), (int) getYMaxLimit()); | ||
|
|
@@ -1643,6 +1650,7 @@ public void setNumberOfVisibleDays(int numberOfVisibleDays) { | |
| this.mNumberOfVisibleDays = numberOfVisibleDays; | ||
| resetHomeDate(); | ||
| mCurrentOrigin.x = 0; | ||
| startOriginForScroll = mCurrentOrigin.x; | ||
| mCurrentOrigin.y = 0; | ||
| invalidate(); | ||
| } | ||
|
|
@@ -2418,40 +2426,72 @@ public boolean onTouchEvent(MotionEvent event) { | |
| } | ||
|
|
||
| private void goToNearestOrigin(){ | ||
| double leftDays = mCurrentOrigin.x / (mWidthPerDay + mColumnGap); | ||
|
|
||
| if (mCurrentFlingDirection != Direction.NONE) { | ||
| // snap to nearest day | ||
| leftDays = Math.round(leftDays); | ||
| } else if (mCurrentScrollDirection == Direction.LEFT) { | ||
| // snap to last day | ||
| leftDays = Math.floor(leftDays); | ||
| } else if (mCurrentScrollDirection == Direction.RIGHT) { | ||
| // snap to next day | ||
| leftDays = Math.ceil(leftDays); | ||
| } else { | ||
| // snap to nearest day | ||
| leftDays = Math.round(leftDays); | ||
| } | ||
| if(!mIsCustomScrollableAmountsOfDaysEnabled) { | ||
| double leftDays = mCurrentOrigin.x / (mWidthPerDay + mColumnGap); | ||
|
|
||
| int nearestOrigin = (int) (mCurrentOrigin.x - leftDays * (mWidthPerDay + mColumnGap)); | ||
| boolean mayScrollHorizontal = mCurrentOrigin.x - nearestOrigin < getXMaxLimit() | ||
| && mCurrentOrigin.x - nearestOrigin > getXMinLimit(); | ||
| if (mCurrentFlingDirection != Direction.NONE) { | ||
| // snap to nearest day | ||
| leftDays = Math.round(leftDays); | ||
| } else if (mCurrentScrollDirection == Direction.LEFT) { | ||
| // snap to last day | ||
| leftDays = Math.floor(leftDays); | ||
| } else if (mCurrentScrollDirection == Direction.RIGHT) { | ||
| // snap to next day | ||
| leftDays = Math.ceil(leftDays); | ||
| } else { | ||
| // snap to nearest day | ||
| leftDays = Math.round(leftDays); | ||
| } | ||
|
|
||
| if (mayScrollHorizontal) { | ||
| mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, - nearestOrigin, 0); | ||
| ViewCompat.postInvalidateOnAnimation(WeekView.this); | ||
| } | ||
| int nearestOrigin = (int) (mCurrentOrigin.x - leftDays * (mWidthPerDay + mColumnGap)); | ||
| boolean mayScrollHorizontal = mCurrentOrigin.x - nearestOrigin < getXMaxLimit() | ||
| && mCurrentOrigin.x - nearestOrigin > getXMinLimit(); | ||
|
|
||
| if (mayScrollHorizontal) { | ||
| mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, -nearestOrigin, 0); | ||
| ViewCompat.postInvalidateOnAnimation(WeekView.this); | ||
| } | ||
|
|
||
| if (nearestOrigin != 0 && mayScrollHorizontal) { | ||
| // Stop current animation. | ||
| mScroller.forceFinished(true); | ||
| // Snap to date. | ||
| mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, -nearestOrigin, 0, (int) (Math.abs(nearestOrigin) / mWidthPerDay * mScrollDuration)); | ||
| ViewCompat.postInvalidateOnAnimation(WeekView.this); | ||
| } | ||
| // Reset scrolling and fling direction. | ||
| mCurrentScrollDirection = mCurrentFlingDirection = Direction.NONE; | ||
| }else { | ||
| sizeOfScrollableView = (mWidthPerDay + mColumnGap) * getNumberOfVisibleDays(); | ||
|
||
| float beforeScroll = startOriginForScroll; | ||
| boolean isPassed = false; | ||
|
|
||
| if (mCurrentScrollDirection == Direction.LEFT) { | ||
| startOriginForScroll -= sizeOfScrollableView; | ||
| isPassed = true; | ||
| } else if (mCurrentScrollDirection == Direction.RIGHT) { | ||
| startOriginForScroll += sizeOfScrollableView; | ||
| isPassed = true; | ||
| } | ||
|
|
||
| boolean mayScrollHorizontal = beforeScroll - startOriginForScroll < getXMaxLimit() | ||
| && mCurrentOrigin.x - startOriginForScroll > getXMinLimit(); | ||
|
|
||
| if (nearestOrigin != 0 && mayScrollHorizontal) { | ||
| // Stop current animation. | ||
| mScroller.forceFinished(true); | ||
| // Snap to date. | ||
| mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, -nearestOrigin, 0, (int) (Math.abs(nearestOrigin) / mWidthPerDay * mScrollDuration)); | ||
| ViewCompat.postInvalidateOnAnimation(WeekView.this); | ||
|
|
||
| if (isPassed && mayScrollHorizontal) { | ||
| // Snap to date. | ||
| if (mCurrentScrollDirection == Direction.LEFT) { | ||
| mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, (int) ((beforeScroll - mCurrentOrigin.x) - sizeOfScrollableView), 0, 200); | ||
| } else if (mCurrentScrollDirection == Direction.RIGHT) { | ||
| mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, (int) (sizeOfScrollableView - (mCurrentOrigin.x - beforeScroll)), 0, 200); | ||
| } | ||
| ViewCompat.postInvalidateOnAnimation(WeekView.this); | ||
| } | ||
| // Reset scrolling and fling direction. | ||
| mCurrentScrollDirection = mCurrentFlingDirection = Direction.NONE; | ||
| } | ||
| // Reset scrolling and fling direction. | ||
| mCurrentScrollDirection = mCurrentFlingDirection = Direction.NONE; | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -2488,6 +2528,10 @@ private boolean forceFinishScroll() { | |
| } | ||
| } | ||
|
|
||
| public void setCustomScrolableDaysEnabled(boolean isEnabled){ | ||
|
||
| mIsCustomScrollableAmountsOfDaysEnabled = isEnabled; | ||
| } | ||
|
|
||
|
|
||
| ///////////////////////////////////////////////////////////////// | ||
| // | ||
|
|
@@ -2524,6 +2568,7 @@ public void goToDate(Calendar date) { | |
| mRefreshEvents = true; | ||
|
|
||
| mCurrentOrigin.x = - daysBetween(mHomeDate, date) * (mWidthPerDay + mColumnGap); | ||
| startOriginForScroll = mCurrentOrigin.x; | ||
| invalidate(); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have a better name,
mIsScrollByAmountOfVisibleDaysEnabledfor exampleUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok ( Mixing bad english and bad imagination created that x) )