Skip to content

Commit e4b864d

Browse files
author
Jens Claes
committed
Revert "Made horizontal scrolling more intuitive"
This reverts commit 444d5d3.
1 parent 3aaf5c6 commit e4b864d

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

library/src/main/java/com/alamkanak/weekview/WeekView.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,8 @@ public boolean onDown(MotionEvent e) {
114114
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
115115
if (mCurrentScrollDirection == Direction.NONE) {
116116
if (Math.abs(distanceX) > Math.abs(distanceY)){
117-
if(distanceX > 0)
118-
mCurrentScrollDirection = Direction.LEFT;
119-
else
120-
mCurrentScrollDirection = Direction.RIGHT;
121-
122-
mCurrentFlingDirection = mCurrentScrollDirection;
117+
mCurrentScrollDirection = Direction.HORIZONTAL;
118+
mCurrentFlingDirection = Direction.HORIZONTAL;
123119
}
124120
else {
125121
mCurrentFlingDirection = Direction.VERTICAL;
@@ -137,7 +133,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
137133
mScroller.forceFinished(true);
138134
mStickyScroller.forceFinished(true);
139135

140-
if (mCurrentFlingDirection.isHorizontal()){
136+
if (mCurrentFlingDirection == Direction.HORIZONTAL){
141137
mScroller.fling((int) mCurrentOrigin.x, 0, (int) velocityX, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 0);
142138
}
143139
else if (mCurrentFlingDirection == Direction.VERTICAL){
@@ -185,16 +181,7 @@ public void onLongPress(MotionEvent e) {
185181

186182

187183
private enum Direction {
188-
NONE(false), VERTICAL(false), LEFT(true), RIGHT(true);
189-
190-
public boolean isHorizontal(){
191-
return this.isHorizontal;
192-
}
193-
194-
Direction(boolean isHorizontal){
195-
this.isHorizontal = isHorizontal;
196-
}
197-
private boolean isHorizontal;
184+
NONE, HORIZONTAL, VERTICAL
198185
}
199186

200187
public WeekView(Context context) {
@@ -370,7 +357,7 @@ private void drawHeaderRowAndEvents(Canvas canvas) {
370357
}
371358

372359
// Consider scroll offset.
373-
if (mCurrentScrollDirection.isHorizontal()) mCurrentOrigin.x -= mDistanceX;
360+
if (mCurrentScrollDirection == Direction.HORIZONTAL) mCurrentOrigin.x -= mDistanceX;
374361
int leftDaysWithGaps = (int) -(Math.ceil(mCurrentOrigin.x / (mWidthPerDay + mColumnGap)));
375362
float startFromPixel = mCurrentOrigin.x + (mWidthPerDay + mColumnGap) * leftDaysWithGaps +
376363
mHeaderColumnWidth;
@@ -1146,28 +1133,27 @@ public Calendar getLastVisibleDay() {
11461133
@Override
11471134
public boolean onTouchEvent(MotionEvent event) {
11481135
if (event.getAction() == MotionEvent.ACTION_UP) {
1149-
if (mCurrentScrollDirection.isHorizontal()) {
1136+
1137+
if (mCurrentScrollDirection == Direction.HORIZONTAL) {
11501138
float leftDays = Math.round(mCurrentOrigin.x / (mWidthPerDay + mColumnGap));
11511139
int nearestOrigin = (int) (mCurrentOrigin.x - leftDays * (mWidthPerDay+mColumnGap));
11521140
mStickyScroller.startScroll((int) mCurrentOrigin.x, 0, - nearestOrigin, 0);
11531141
ViewCompat.postInvalidateOnAnimation(WeekView.this);
11541142
}
1143+
mCurrentScrollDirection = Direction.NONE;
11551144
}
11561145
return mGestureDetector.onTouchEvent(event);
11571146
}
11581147

1148+
11591149
@Override
11601150
public void computeScroll() {
11611151
super.computeScroll();
11621152
if (mScroller.computeScrollOffset()) {
11631153
if (Math.abs(mScroller.getFinalX() - mScroller.getCurrX()) < mWidthPerDay + mColumnGap && Math.abs(mScroller.getFinalX() - mScroller.getStartX()) != 0) {
11641154
mScroller.forceFinished(true);
11651155
float leftDays = Math.round(mCurrentOrigin.x / (mWidthPerDay + mColumnGap));
1166-
if(mCurrentScrollDirection == Direction.LEFT)
1167-
leftDays--;
1168-
else
1169-
leftDays++;
1170-
int nearestOrigin = (int) ((mCurrentOrigin.x - leftDays * (mWidthPerDay+mColumnGap)));
1156+
int nearestOrigin = (int) (mCurrentOrigin.x - leftDays * (mWidthPerDay+mColumnGap));
11711157
mStickyScroller.startScroll((int) mCurrentOrigin.x, 0, - nearestOrigin, 0);
11721158
ViewCompat.postInvalidateOnAnimation(WeekView.this);
11731159
}
@@ -1176,7 +1162,6 @@ public void computeScroll() {
11761162
else mCurrentOrigin.x = mScroller.getCurrX();
11771163
ViewCompat.postInvalidateOnAnimation(this);
11781164
}
1179-
mCurrentScrollDirection = Direction.NONE;
11801165
}
11811166
if (mStickyScroller.computeScrollOffset()) {
11821167
mCurrentOrigin.x = mStickyScroller.getCurrX();

0 commit comments

Comments
 (0)