77import  android .view .ScaleGestureDetector ;
88import  android .view .View ;
99
10+ import  androidx .annotation .NonNull ;
11+ 
1012/* 
1113    The GestureHelper present a simple gesture api for the PdfViewer 
1214*/ 
1315
1416class  GestureHelper  {
1517    public  interface  GestureListener  {
1618        boolean  onTapUp ();
19+ 
20+         void  onSwipeLeft ();
21+         void  onSwipeRight ();
22+ 
1723        // Can be replaced with ratio when supported 
1824        void  onZoomIn (float  value );
1925        void  onZoomOut (float  value );
@@ -29,6 +35,31 @@ static void attach(Context context, View gestureView, GestureListener listener)
2935                    public  boolean  onSingleTapUp (MotionEvent  motionEvent ) {
3036                        return  listener .onTapUp ();
3137                    }
38+ 
39+                     // inspired by https://www.geeksforgeeks.org/how-to-detect-swipe-direction-in-android/ 
40+                     @ Override 
41+                     public  boolean  onFling (@ NonNull  MotionEvent  e1 , @ NonNull  MotionEvent  e2 , float  velocityX , float  velocityY ) {
42+                         final  int  swipeThreshold  = 100 ;
43+                         final  int  swipeVelocityThreshold  = 100 ;
44+ 
45+                         final  float  diffX  = e2 .getX () - e1 .getX ();
46+                         final  float  absDiffX  = Math .abs (diffX );
47+                         final  float  diffY  = e2 .getY () - e1 .getY ();
48+                         final  float  absDiffY  = Math .abs (diffY );
49+ 
50+                         if  (absDiffX  > absDiffY  // only handle horizontal swipe 
51+                                 && absDiffX  > swipeThreshold 
52+                                 && Math .abs (velocityX ) > swipeVelocityThreshold ) {
53+                             if  (diffX  > 0 ) {
54+                                 listener .onSwipeRight ();
55+                             } else  {
56+                                 listener .onSwipeLeft ();
57+                             }
58+                             return  true ;
59+                         }
60+ 
61+                         return  false ;
62+                     }
3263                });
3364
3465        final  ScaleGestureDetector  scaleDetector  = new  ScaleGestureDetector (context ,
0 commit comments