-
-
Notifications
You must be signed in to change notification settings - Fork 112
Added in swipe gestures to navigate pages #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a3cc174
30f9613
1c8b93a
6a15e14
449accd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,21 @@ | |
import android.view.ScaleGestureDetector; | ||
import android.view.View; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
/* | ||
The GestureHelper present a simple gesture api for the PdfViewer | ||
*/ | ||
|
||
class GestureHelper { | ||
public interface GestureListener { | ||
boolean onTapUp(); | ||
boolean onFling(@Nullable MotionEvent e1, @NonNull MotionEvent e2, float velocityX, float velocityY); | ||
boolean onDown(); | ||
// Can be replaced with ratio when supported | ||
void onZoomIn(float value); | ||
void onZoomOut(float value); | ||
void onZoom(float scaleFactor, float focusX, float focusY); | ||
void onZoomEnd(); | ||
} | ||
|
@@ -24,9 +32,20 @@ static void attach(Context context, View gestureView, GestureListener listener) | |
final GestureDetector detector = new GestureDetector(context, | ||
new GestureDetector.SimpleOnGestureListener() { | ||
@Override | ||
public boolean onSingleTapUp(MotionEvent motionEvent) { | ||
public boolean onSingleTapUp(@NonNull MotionEvent motionEvent) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems unrelated to the PR topic, I'd suggest removing, to avoid polluting git history. |
||
return listener.onTapUp(); | ||
} | ||
|
||
@Override | ||
public boolean onFling(@Nullable MotionEvent e1, @NonNull MotionEvent e2, float velocityX, float velocityY) { | ||
return listener.onFling(e1, e2, velocityX, velocityY); | ||
} | ||
|
||
@Override | ||
public boolean onDown(@NonNull MotionEvent motionEvent){ | ||
return listener.onDown(); | ||
} | ||
|
||
}); | ||
|
||
final ScaleGestureDetector scaleDetector = new ScaleGestureDetector(context, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import android.view.Menu; | ||
import android.view.MenuInflater; | ||
import android.view.MenuItem; | ||
import android.view.MotionEvent; | ||
import android.view.View; | ||
import android.webkit.CookieManager; | ||
import android.webkit.JavascriptInterface; | ||
|
@@ -29,6 +30,7 @@ | |
import androidx.activity.result.ActivityResultLauncher; | ||
import androidx.activity.result.contract.ActivityResultContracts; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import androidx.fragment.app.Fragment; | ||
import androidx.fragment.app.FragmentTransaction; | ||
|
@@ -452,8 +454,41 @@ public boolean onTapUp() { | |
} | ||
|
||
@Override | ||
|
||
public boolean onFling(@Nullable MotionEvent e1, @NonNull MotionEvent e2, float velocityX, float velocityY) { | ||
assert e1 != null; | ||
float maxXVelocity = 4000; | ||
float deltaX = e2.getX() - e1.getX(); | ||
float deltaY = e2.getY() - e1.getY(); | ||
|
||
if (Math.abs(deltaX) > Math.abs(deltaY)){ | ||
if ((deltaX > 0) & (Math.abs(velocityX) > maxXVelocity)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bitwise & operator used instead of the boolean one. |
||
Log.d("Horizontal", "Right movement Position"); | ||
onJumpToPageInDocument(mPage - 1); | ||
} else if ((Math.abs(velocityX) > maxXVelocity)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest moving this condition over to the higher-level |
||
Log.d("Horizontal", "Left movement Position"); | ||
onJumpToPageInDocument(mPage + 1); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onDown() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this one really necessary? |
||
return true; | ||
} | ||
|
||
@Override | ||
public void onZoomIn(float value) { | ||
zoomIn(value, false); | ||
} | ||
|
||
@Override | ||
public void onZoomOut(float value) { | ||
zoomOut(value, false); | ||
|
||
public void onZoom(float scaleFactor, float focusX, float focusY) { | ||
zoom(scaleFactor, focusX, focusY, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whitespace-only changes like this are usually discouraged, or at least should be split out to dedicated commits. |
||
zoom(scaleFactor, focusX, focusY, false); | ||
} | ||
|
||
@Override | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why would this and the next one are needed, given it's not about zooming?