Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion app/src/main/java/app/grapheneos/pdfviewer/GestureHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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?

void onZoomOut(float value);
void onZoom(float scaleFactor, float focusX, float focusY);
void onZoomEnd();
}
Expand All @@ -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) {

Choose a reason for hiding this comment

The 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,
Expand Down
37 changes: 36 additions & 1 deletion app/src/main/java/app/grapheneos/pdfviewer/PdfViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)) {

Choose a reason for hiding this comment

The 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)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest moving this condition over to the higher-level if clause, to simplify and avoid repeating it.

Log.d("Horizontal", "Left movement Position");
onJumpToPageInDocument(mPage + 1);
}
}
return true;
}

@Override
public boolean onDown() {

Choose a reason for hiding this comment

The 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);

Choose a reason for hiding this comment

The 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
Expand Down
Loading