summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Holgate <matt@emobix.co.uk>2014-07-01 16:51:50 +0100
committerMatt Holgate <matt@emobix.co.uk>2014-07-01 16:51:50 +0100
commitbae042e93be9e516d950b317349f206cf1921aea (patch)
tree7abe08dc3f169497260f2fa7fe277a8b57867d42
parent821ca4070ead82474ccafb22118ed0f2f350a326 (diff)
downloadmupdf-bae042e93be9e516d950b317349f206cf1921aea.tar.xz
Bug #694104 - Allow using MuPDFReaderView from GUI layout tool.
The GUI layout tool instantiates custom controls classes to display a preview in the IDE. It relies on the 2-argument constructor being implemented. Use a different means to get the window manager that works for non-activity contexts, and avoid creating gesture recognizers in this situation. Based on a patch supplied by Masaki Muranaka
-rw-r--r--platform/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java23
-rw-r--r--platform/android/src/com/artifex/mupdfdemo/ReaderView.java26
2 files changed, 41 insertions, 8 deletions
diff --git a/platform/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java b/platform/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java
index a8f41fb2..383a581c 100644
--- a/platform/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java
+++ b/platform/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java
@@ -4,10 +4,12 @@ import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
+import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
+import android.view.WindowManager;
public class MuPDFReaderView extends ReaderView {
enum Mode {Viewing, Selecting, Drawing}
@@ -30,9 +32,8 @@ public class MuPDFReaderView extends ReaderView {
mMode = m;
}
- public MuPDFReaderView(Activity act) {
- super(act);
- mContext = act;
+ private void setup()
+ {
// 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
@@ -41,7 +42,8 @@ public class MuPDFReaderView extends ReaderView {
// 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();
- act.getWindowManager().getDefaultDisplay().getMetrics(dm);
+ WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
+ wm.getDefaultDisplay().getMetrics(dm);
tapPageMargin = (int)dm.xdpi;
if (tapPageMargin < 100)
tapPageMargin = 100;
@@ -49,6 +51,19 @@ public class MuPDFReaderView extends ReaderView {
tapPageMargin = dm.widthPixels/5;
}
+ public MuPDFReaderView(Context context) {
+ super(context);
+ mContext = context;
+ setup();
+ }
+
+ public MuPDFReaderView(Context context, AttributeSet attrs)
+ {
+ super(context, attrs);
+ mContext = context;
+ setup();
+ }
+
public boolean onSingleTapUp(MotionEvent e) {
LinkInfo link = null;
diff --git a/platform/android/src/com/artifex/mupdfdemo/ReaderView.java b/platform/android/src/com/artifex/mupdfdemo/ReaderView.java
index 774c8dbe..2552e928 100644
--- a/platform/android/src/com/artifex/mupdfdemo/ReaderView.java
+++ b/platform/android/src/com/artifex/mupdfdemo/ReaderView.java
@@ -72,10 +72,23 @@ public class ReaderView
public ReaderView(Context context, AttributeSet attrs) {
super(context, attrs);
- mGestureDetector = new GestureDetector(this);
- mScaleGestureDetector = new ScaleGestureDetector(context, this);
- mScroller = new Scroller(context);
- mStepper = new Stepper(this, this);
+
+ // "Edit mode" means when the View is being displayed in the Android GUI editor. (this class
+ // is instantiated in the IDE, so we need to be a bit careful what we do).
+ if (isInEditMode())
+ {
+ mGestureDetector = null;
+ mScaleGestureDetector = null;
+ mScroller = null;
+ mStepper = null;
+ }
+ else
+ {
+ mGestureDetector = new GestureDetector(this);
+ mScaleGestureDetector = new ScaleGestureDetector(context, this);
+ mScroller = new Scroller(context);
+ mStepper = new Stepper(this, this);
+ }
}
public ReaderView(Context context, AttributeSet attrs, int defStyle) {
@@ -527,6 +540,11 @@ public class ReaderView
int bottom) {
super.onLayout(changed, left, top, right, bottom);
+ // "Edit mode" means when the View is being displayed in the Android GUI editor. (this class
+ // is instantiated in the IDE, so we need to be a bit careful what we do).
+ if (isInEditMode())
+ return;
+
View cv = mChildViews.get(mCurrent);
Point cvOffset;