From 760d6f1186b6a34545b1559b677a4c8bc9dfff67 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 4 Apr 2020 11:41:06 -0400 Subject: [PATCH] avoid multiple renders per zoom --- .../org/grapheneos/pdfviewer/PdfViewer.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java b/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java index 44c9e62..f57df67 100644 --- a/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java +++ b/app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java @@ -254,16 +254,12 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader @Override public void onZoomIn(int steps) { - for (int i = 0; i < steps; i++) { - zoomIn(); - } + zoomIn(steps); } @Override public void onZoomOut(int steps) { - for (int i = 0; i < steps; i++) { - zoomOut(); - } + zoomOut(steps); } }); @@ -348,17 +344,17 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader startActivityForResult(intent, ACTION_OPEN_DOCUMENT_REQUEST_CODE); } - private void zoomIn() { + private void zoomIn(int steps) { if (mZoomRatio < MAX_ZOOM_RATIO) { - mZoomRatio += 0.25f; + mZoomRatio += 0.25f * steps; renderPage(true); invalidateOptionsMenu(); } } - private void zoomOut() { + private void zoomOut(int steps) { if (mZoomRatio > MIN_ZOOM_RATIO) { - mZoomRatio -= 0.25f; + mZoomRatio -= 0.25f * steps; renderPage(true); invalidateOptionsMenu(); } @@ -498,11 +494,11 @@ public class PdfViewer extends AppCompatActivity implements LoaderManager.Loader return super.onOptionsItemSelected(item); case R.id.action_zoom_out: - zoomOut(); + zoomOut(1); return true; case R.id.action_zoom_in: - zoomIn(); + zoomIn(1); return true; case R.id.action_rotate_clockwise: