@@ -647,7 +647,8 @@ public void copyToClipboard( String text ) {
647647// private int selectionEndX = 0;
648648// private int selectionEndY = 0;
649649 private boolean doubleTapSelectionEnabled = false ;
650- private boolean gesturePageFlippingEnabled = true ;
650+ private int mGesturePageFlipsPerFullSwipe ;
651+ private boolean mIsPageMode ;
651652 private int secondaryTapActionType = TAP_ACTION_TYPE_LONGPRESS ;
652653 private boolean selectionModeActive = false ;
653654
@@ -936,6 +937,7 @@ public class TapHandler {
936937 private final static int STATE_WAIT_FOR_DOUBLE_CLICK = 5 ; // flipping is in progress
937938 private final static int STATE_DONE = 6 ; // done: no more tracking
938939 private final static int STATE_BRIGHTNESS = 7 ; // brightness change in progress
940+ private final static int STATE_FLIP_TRACKING = 8 ; // pages flip tracking in progress
939941
940942 private final static int EXPIRATION_TIME_MS = 180000 ;
941943
@@ -979,6 +981,7 @@ private boolean cancel() {
979981 case STATE_WAIT_FOR_DOUBLE_CLICK :
980982 case STATE_DONE :
981983 case STATE_BRIGHTNESS :
984+ case STATE_FLIP_TRACKING :
982985 stopBrightnessControl (-1 , -1 );
983986 break ;
984987 }
@@ -988,6 +991,41 @@ private boolean cancel() {
988991 return true ;
989992 }
990993
994+ private void adjustStartValuesOnDrag (int swipeDistance , int distanceForFlip ) {
995+ if (Math .abs (swipeDistance ) < distanceForFlip ) {
996+ return ; // Nothing to do
997+ }
998+ int direction = swipeDistance > 0 ? 1 : -1 ; // Left-to-right or right-to-left swipe?
999+ int value = direction * distanceForFlip ;
1000+ while (Math .abs (swipeDistance ) >= distanceForFlip ) {
1001+ if (mIsPageMode ) {
1002+ start_x += value ;
1003+ } else {
1004+ start_y += value ;
1005+ }
1006+ swipeDistance -= value ;
1007+ }
1008+ }
1009+
1010+ private void updatePageFlipTracking (final int x , final int y ) {
1011+ final int swipeDistance = mIsPageMode ? x - start_x : y - start_y ;
1012+ final int distanceForFlip = surface .getWidth () / mGesturePageFlipsPerFullSwipe ;
1013+ int pagesToFlip = swipeDistance / distanceForFlip ;
1014+ if (pagesToFlip == 0 ) {
1015+ return ; // Nothing to do
1016+ }
1017+ adjustStartValuesOnDrag (swipeDistance , distanceForFlip );
1018+ ReaderAction action = pagesToFlip > 0 ? ReaderAction .PAGE_DOWN : ReaderAction .PAGE_UP ;
1019+ while (pagesToFlip != 0 ) {
1020+ onAction (action );
1021+ if (pagesToFlip > 0 ) {
1022+ pagesToFlip --;
1023+ } else {
1024+ pagesToFlip ++;
1025+ }
1026+ }
1027+ }
1028+
9911029 /// perform action and reset touch tracking state
9921030 private boolean performAction (final ReaderAction action , boolean checkForLinks ) {
9931031 log .d ("performAction on touch: " + action );
@@ -1190,6 +1228,10 @@ public boolean onTouchEvent(MotionEvent event) {
11901228 selectionModeActive = false ;
11911229 state = STATE_DONE ;
11921230 return cancel ();
1231+ case STATE_FLIP_TRACKING :
1232+ updatePageFlipTracking (x , y );
1233+ state = STATE_DONE ;
1234+ return cancel ();
11931235 }
11941236 } else if (event .getAction () == MotionEvent .ACTION_DOWN ) {
11951237 switch (state ) {
@@ -1214,6 +1256,7 @@ public boolean onTouchEvent(MotionEvent event) {
12141256 case STATE_BRIGHTNESS :
12151257 case STATE_FLIPPING :
12161258 case STATE_SELECTION :
1259+ case STATE_FLIP_TRACKING :
12171260 return unexpectedEvent ();
12181261 case STATE_WAIT_FOR_DOUBLE_CLICK :
12191262 if (doubleTapAction == ReaderAction .START_SELECTION )
@@ -1241,9 +1284,8 @@ public boolean onTouchEvent(MotionEvent event) {
12411284 return true ;
12421285 }
12431286 }
1244- boolean isPageMode = mSettings .getInt (PROP_PAGE_VIEW_MODE , 1 ) == 1 ;
1245- int dir = isPageMode ? x - start_x : y - start_y ;
1246- if (gesturePageFlippingEnabled ) {
1287+ int dir = mIsPageMode ? x - start_x : y - start_y ;
1288+ if (mGesturePageFlipsPerFullSwipe == 1 ) {
12471289 if (pageFlipAnimationSpeedMs == 0 || DeviceInfo .EINK_SCREEN ) {
12481290 // no animation
12491291 return performAction (dir < 0 ? ReaderAction .PAGE_DOWN : ReaderAction .PAGE_UP , false );
@@ -1252,13 +1294,20 @@ public boolean onTouchEvent(MotionEvent event) {
12521294 updateAnimation (x , y );
12531295 state = STATE_FLIPPING ;
12541296 }
1297+ if (mGesturePageFlipsPerFullSwipe > 1 ) {
1298+ state = STATE_FLIP_TRACKING ;
1299+ updatePageFlipTracking (start_x , start_y );
1300+ }
12551301 return true ;
12561302 case STATE_FLIPPING :
12571303 updateAnimation (x , y );
12581304 return true ;
12591305 case STATE_BRIGHTNESS :
12601306 updateBrightnessControl (x , y );
12611307 return true ;
1308+ case STATE_FLIP_TRACKING :
1309+ updatePageFlipTracking (x , y );
1310+ return true ;
12621311 case STATE_WAIT_FOR_DOUBLE_CLICK :
12631312 return true ;
12641313 case STATE_SELECTION :
@@ -2625,7 +2674,9 @@ public void applyAppSetting( String key, String value )
26252674 } else if ( key .equals (PROP_APP_DOUBLE_TAP_SELECTION ) ) {
26262675 doubleTapSelectionEnabled = flg ;
26272676 } else if ( key .equals (PROP_APP_GESTURE_PAGE_FLIPPING ) ) {
2628- gesturePageFlippingEnabled = flg ;
2677+ mGesturePageFlipsPerFullSwipe = Integer .valueOf (value );
2678+ } else if ( key .equals (PROP_PAGE_VIEW_MODE )) {
2679+ mIsPageMode = flg ;
26292680 } else if ( key .equals (PROP_APP_SECONDARY_TAP_ACTION_TYPE ) ) {
26302681 secondaryTapActionType = flg ? TAP_ACTION_TYPE_DOUBLE : TAP_ACTION_TYPE_LONGPRESS ;
26312682 } else if ( key .equals (PROP_APP_FLICK_BACKLIGHT_CONTROL ) ) {
@@ -2697,6 +2748,7 @@ public void setAppSettings(Properties newSettings, Properties oldSettings)
26972748 viewMode = flg ? ViewMode .PAGES : ViewMode .SCROLL ;
26982749 } else if ( PROP_APP_SCREEN_ORIENTATION .equals (key )
26992750 || PROP_PAGE_ANIMATION .equals (key )
2751+ || PROP_PAGE_VIEW_MODE .equals (key )
27002752 || PROP_CONTROLS_ENABLE_VOLUME_KEYS .equals (key )
27012753 || PROP_APP_SHOW_COVERPAGES .equals (key )
27022754 || PROP_APP_COVERPAGE_SIZE .equals (key )
0 commit comments