diff options
author | Robin Watts <robin.watts@artifex.com> | 2013-01-22 15:45:50 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2013-01-22 16:15:33 +0000 |
commit | 8c1a2377de0b83626d3461f7d1554d3c4c9741b2 (patch) | |
tree | 4805443dc6db406527838faf76753e039bb8b946 /android/src | |
parent | 9e714087533038580f7af51ea1b385c689e0274d (diff) | |
download | mupdf-8c1a2377de0b83626d3461f7d1554d3c4c9741b2.tar.xz |
Android: Make the 'tap to skip page' regions more smartly sized.
Rather than always using 20% of the screen for the tap region
(which can be excessive and confusing on a large tablet), instead
try to use just the left/right inch.
We do this by reading the dpi of the screen. As (apparently) some
devices lie about the dpi of the screen we arrange first to always
use at least 100 pixels, and then never to use more than 1/5 of the
screen.
Diffstat (limited to 'android/src')
-rw-r--r-- | android/src/com/artifex/mupdfdemo/MuPDFActivity.java | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java index 25cb68e9..9a8b691f 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java @@ -21,6 +21,7 @@ import android.os.Handler; import android.text.Editable; import android.text.TextWatcher; import android.text.method.PasswordTransformationMethod; +import android.util.DisplayMetrics; import android.view.KeyEvent; import android.view.Menu; import android.view.MotionEvent; @@ -85,7 +86,7 @@ class ProgressDialogX extends ProgressDialog { public class MuPDFActivity extends Activity { /* The core rendering instance */ - private final int TAP_PAGE_MARGIN = 5; + private static int tapPageMargin; private static final int SEARCH_PROGRESS_DELAY = 200; private MuPDFCore core; private String mFileName; @@ -265,6 +266,21 @@ public class MuPDFActivity extends Activity { super.onCreate(savedInstanceState); + // Get the screen size etc to customise tap margins. + // We calculate the size of 1 inch of the screen for tapping. + // On some devices the dpi values returned are wrong, so we + // sanity check it: we first restrict it so that we are never + // less than 100 pixels (the smallest Android device screen + // dimension I've seen is 480 pixels or so). Then we check + // to ensure we are never more than 1/5 of the screen width. + DisplayMetrics dm = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(dm); + tapPageMargin = (int)dm.xdpi; + if (tapPageMargin < 100) + tapPageMargin = 100; + if (tapPageMargin > dm.widthPixels/5) + tapPageMargin = dm.widthPixels/5; + mAlertBuilder = new AlertDialog.Builder(this); if (core == null) { @@ -376,9 +392,9 @@ public class MuPDFActivity extends Activity // Clicked on a remote (GoToR) link } }); - } else if (e.getX() < super.getWidth()/TAP_PAGE_MARGIN) { + } else if (e.getX() < tapPageMargin) { super.moveToPrevious(); - } else if (e.getX() > super.getWidth()*(TAP_PAGE_MARGIN-1)/TAP_PAGE_MARGIN) { + } else if (e.getX() > super.getWidth()-tapPageMargin) { super.moveToNext(); } else if (!mButtonsVisible) { showButtons(); |