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