@@ -114,8 +114,12 @@ public boolean onDown(MotionEvent e) {
114
114
public boolean onScroll (MotionEvent e1 , MotionEvent e2 , float distanceX , float distanceY ) {
115
115
if (mCurrentScrollDirection == Direction .NONE ) {
116
116
if (Math .abs (distanceX ) > Math .abs (distanceY )){
117
- mCurrentScrollDirection = Direction .HORIZONTAL ;
118
- mCurrentFlingDirection = Direction .HORIZONTAL ;
117
+ if (distanceX > 0 )
118
+ mCurrentScrollDirection = Direction .LEFT ;
119
+ else
120
+ mCurrentScrollDirection = Direction .RIGHT ;
121
+
122
+ mCurrentFlingDirection = mCurrentScrollDirection ;
119
123
}
120
124
else {
121
125
mCurrentFlingDirection = Direction .VERTICAL ;
@@ -133,7 +137,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
133
137
mScroller .forceFinished (true );
134
138
mStickyScroller .forceFinished (true );
135
139
136
- if (mCurrentFlingDirection == Direction . HORIZONTAL ){
140
+ if (mCurrentFlingDirection . isHorizontal () ){
137
141
mScroller .fling ((int ) mCurrentOrigin .x , 0 , (int ) velocityX , 0 , Integer .MIN_VALUE , Integer .MAX_VALUE , 0 , 0 );
138
142
}
139
143
else if (mCurrentFlingDirection == Direction .VERTICAL ){
@@ -181,7 +185,16 @@ public void onLongPress(MotionEvent e) {
181
185
182
186
183
187
private enum Direction {
184
- NONE , HORIZONTAL , VERTICAL
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 ;
185
198
}
186
199
187
200
public WeekView (Context context ) {
@@ -357,7 +370,7 @@ private void drawHeaderRowAndEvents(Canvas canvas) {
357
370
}
358
371
359
372
// Consider scroll offset.
360
- if (mCurrentScrollDirection == Direction . HORIZONTAL ) mCurrentOrigin .x -= mDistanceX ;
373
+ if (mCurrentScrollDirection . isHorizontal () ) mCurrentOrigin .x -= mDistanceX ;
361
374
int leftDaysWithGaps = (int ) -(Math .ceil (mCurrentOrigin .x / (mWidthPerDay + mColumnGap )));
362
375
float startFromPixel = mCurrentOrigin .x + (mWidthPerDay + mColumnGap ) * leftDaysWithGaps +
363
376
mHeaderColumnWidth ;
@@ -1133,27 +1146,28 @@ public Calendar getLastVisibleDay() {
1133
1146
@ Override
1134
1147
public boolean onTouchEvent (MotionEvent event ) {
1135
1148
if (event .getAction () == MotionEvent .ACTION_UP ) {
1136
-
1137
- if (mCurrentScrollDirection == Direction .HORIZONTAL ) {
1149
+ if (mCurrentScrollDirection .isHorizontal ()) {
1138
1150
float leftDays = Math .round (mCurrentOrigin .x / (mWidthPerDay + mColumnGap ));
1139
1151
int nearestOrigin = (int ) (mCurrentOrigin .x - leftDays * (mWidthPerDay +mColumnGap ));
1140
1152
mStickyScroller .startScroll ((int ) mCurrentOrigin .x , 0 , - nearestOrigin , 0 );
1141
1153
ViewCompat .postInvalidateOnAnimation (WeekView .this );
1142
1154
}
1143
- mCurrentScrollDirection = Direction .NONE ;
1144
1155
}
1145
1156
return mGestureDetector .onTouchEvent (event );
1146
1157
}
1147
1158
1148
-
1149
1159
@ Override
1150
1160
public void computeScroll () {
1151
1161
super .computeScroll ();
1152
1162
if (mScroller .computeScrollOffset ()) {
1153
1163
if (Math .abs (mScroller .getFinalX () - mScroller .getCurrX ()) < mWidthPerDay + mColumnGap && Math .abs (mScroller .getFinalX () - mScroller .getStartX ()) != 0 ) {
1154
1164
mScroller .forceFinished (true );
1155
1165
float leftDays = Math .round (mCurrentOrigin .x / (mWidthPerDay + mColumnGap ));
1156
- int nearestOrigin = (int ) (mCurrentOrigin .x - leftDays * (mWidthPerDay +mColumnGap ));
1166
+ if (mCurrentScrollDirection == Direction .LEFT )
1167
+ leftDays --;
1168
+ else
1169
+ leftDays ++;
1170
+ int nearestOrigin = (int ) ((mCurrentOrigin .x - leftDays * (mWidthPerDay +mColumnGap )));
1157
1171
mStickyScroller .startScroll ((int ) mCurrentOrigin .x , 0 , - nearestOrigin , 0 );
1158
1172
ViewCompat .postInvalidateOnAnimation (WeekView .this );
1159
1173
}
@@ -1162,6 +1176,7 @@ public void computeScroll() {
1162
1176
else mCurrentOrigin .x = mScroller .getCurrX ();
1163
1177
ViewCompat .postInvalidateOnAnimation (this );
1164
1178
}
1179
+ mCurrentScrollDirection = Direction .NONE ;
1165
1180
}
1166
1181
if (mStickyScroller .computeScrollOffset ()) {
1167
1182
mCurrentOrigin .x = mStickyScroller .getCurrX ();
0 commit comments