summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authorfred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local>2016-08-10 15:48:43 -0700
committerfredross-perry <fross-perry@conceptuamath.com>2016-08-16 11:21:02 -0700
commitc8665eae28ca2f4aa56239eb411c6ea1200d65fb (patch)
tree86b4ab5d86d0cc5117422eaa7afd83e2dd3630da /platform/android
parentf1b8593a2289060430763b1d918f4b3c9debe6f3 (diff)
downloadmupdf-c8665eae28ca2f4aa56239eb411c6ea1200d65fb.tar.xz
Android example: fix initial layout timing issue.
Diffstat (limited to 'platform/android')
-rwxr-xr-xplatform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java10
-rw-r--r--platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocActivityView.java183
-rw-r--r--platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocView.java6
-rwxr-xr-xplatform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocViewBase.java13
-rw-r--r--platform/android/example/mupdf/src/main/res/values/integers.xml4
5 files changed, 94 insertions, 122 deletions
diff --git a/platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java b/platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java
index 5a23c5fd..7cc4b076 100755
--- a/platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java
+++ b/platform/android/example/app/src/main/java/com/artifex/mupdf/example/DocViewActivity.java
@@ -15,16 +15,16 @@ public class DocViewActivity extends Activity
{
super.onCreate(savedInstanceState);
- // set up UI
- setContentView(R.layout.activity_doc_view);
- mDocActivityView = (DocActivityView) findViewById(R.id.doc_view);
-
// get the file path
Uri uri = getIntent().getData();
final String path = Uri.decode(uri.getEncodedPath());
- // start the view
+ // set up UI
+ setContentView(R.layout.activity_doc_view);
+ mDocActivityView = (DocActivityView) findViewById(R.id.doc_view);
mDocActivityView.showUI(true); // set to false for no built-in UI
+
+ // Go!
mDocActivityView.start(path);
}
diff --git a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocActivityView.java b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocActivityView.java
index dc9c75fd..cad103a4 100644
--- a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocActivityView.java
+++ b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocActivityView.java
@@ -1,11 +1,13 @@
package com.artifex.mupdf.android;
+import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewTreeObserver;
+import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
@@ -21,8 +23,7 @@ public class DocActivityView extends FrameLayout implements TabHost.OnTabChangeL
{
private DocView mDocView;
private DocListPagesView mDocView2;
- private Context mContext = null;
- private boolean layoutAgain = false;
+ private boolean mShowUI = true;
// tab tags
private String mTagHidden;
@@ -33,69 +34,16 @@ public class DocActivityView extends FrameLayout implements TabHost.OnTabChangeL
public DocActivityView(Context context)
{
super(context);
- initialize(context);
}
public DocActivityView(Context context, AttributeSet attrs)
{
super(context, attrs);
- initialize(context);
}
public DocActivityView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
- initialize(context);
- }
-
- protected void initialize(Context context)
- {
- mContext = context;
-
- final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- final LinearLayout view = (LinearLayout) inflater.inflate(R.layout.doc_view, null);
- addView(view);
-
- mDocView = (DocView) view.findViewById(R.id.doc_view_inner);
-
- if (usePagesView())
- {
- mDocView2 = new DocListPagesView(context);
- mDocView2.setMainView(mDocView);
- }
-
- if (usePagesView())
- {
- // pages container
- LinearLayout layout2 = (LinearLayout) findViewById(R.id.pages_container);
- layout2.addView(mDocView2);
- }
-
- // tabs
- setupTabs();
-
- // selection handles
- View v = view.findViewById(R.id.doc_wrapper);
- RelativeLayout layout = (RelativeLayout) v;
- mDocView.setupHandles(layout);
-
- // listen for layout changes on the main doc view, and
- // copy the "most visible" value to the page list.
- ViewTreeObserver observer2 = mDocView.getViewTreeObserver();
- observer2.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
- {
- @Override
- public void onGlobalLayout()
- {
- if (usePagesView())
- {
- int mvp = mDocView.getMostVisiblePage();
- mDocView2.setMostVisiblePage(mvp);
- }
- }
- });
-
- // TODO: connect buttons to functions
}
protected boolean usePagesView()
@@ -160,7 +108,6 @@ public class DocActivityView extends FrameLayout implements TabHost.OnTabChangeL
private void showSearchSelected(boolean selected)
{
-
}
protected void handlePagesTab(String tabId)
@@ -218,7 +165,7 @@ public class DocActivityView extends FrameLayout implements TabHost.OnTabChangeL
public boolean showKeyboard()
{
// show keyboard
- InputMethodManager im = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
+ InputMethodManager im = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
im.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
return true;
@@ -227,48 +174,101 @@ public class DocActivityView extends FrameLayout implements TabHost.OnTabChangeL
public void hideKeyboard()
{
// hide the keyboard
- InputMethodManager im = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
+ InputMethodManager im = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(mDocView.getWindowToken(), 0);
}
+ private boolean started = false;
public void start(final String path)
{
- // wait for the first layout to finish
- ViewTreeObserver observer = getViewTreeObserver();
- observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
+ started = false;
+
+ ((Activity)getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
+ ((Activity)getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
+
+ // inflate the UI
+ final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ final LinearLayout view = (LinearLayout) inflater.inflate(R.layout.doc_view, null);
+
+ final ViewTreeObserver vto = getViewTreeObserver();
+ vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
- getViewTreeObserver().removeOnGlobalLayoutListener(this);
+ if (!started)
+ {
+ findViewById(R.id.tabhost).setVisibility(mShowUI?View.VISIBLE:View.GONE);
+ findViewById(R.id.footer).setVisibility(mShowUI?View.VISIBLE:View.GONE);
+ start2(path);
+
+ started = true;
+ }
+ }
+ });
- // signal that we want one more layout. When the title bar get hidden,
- // this view will get an additional layout, at which time we'll
- // re-layout the inner view. (see below)
- // I don't like this, but it seems to work.
- layoutAgain = true;
- mDocView.start(path);
+ addView(view);
+ }
+
+ public void start2(final String path)
+ {
+ // main view
+ mDocView = (DocView) findViewById(R.id.doc_view_inner);
+ // page list
+ if (usePagesView())
+ {
+ mDocView2 = new DocListPagesView(getContext());
+ mDocView2.setMainView(mDocView);
+ LinearLayout layout2 = (LinearLayout) findViewById(R.id.pages_container);
+ layout2.addView(mDocView2);
+ }
+
+ // tabs
+ setupTabs();
+
+ // selection handles
+ View v = findViewById(R.id.doc_wrapper);
+ RelativeLayout layout = (RelativeLayout) v;
+ mDocView.setupHandles(layout);
+
+ // listen for layout changes on the main doc view, and
+ // copy the "most visible" value to the page list.
+ ViewTreeObserver observer2 = mDocView.getViewTreeObserver();
+ observer2.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
+ {
+ @Override
+ public void onGlobalLayout()
+ {
if (usePagesView())
{
- mDocView2.clone(mDocView);
+ int mvp = mDocView.getMostVisiblePage();
+ mDocView2.setMostVisiblePage(mvp);
}
-
}
});
+
+ // TODO: connect buttons to functions
+
+ // start the views
+ mDocView.start(path);
+ if (usePagesView())
+ {
+ mDocView2.clone(mDocView);
+ }
}
- protected void onLayout(boolean changed, int left, int top, int right, int bottom)
+ public void showUI(boolean show)
{
+ mShowUI = show;
+ }
- super.onLayout(changed, left, top, right, bottom);
-
- if (layoutAgain)
+ public void stop()
+ {
+ mDocView.finish();
+ if (usePagesView())
{
- // this is the additional layout.
- // so now re-lay out the inner view.
- layoutAgain = false;
- mDocView.requestLayout();
+ mDocView2.finish();
}
}
@@ -322,31 +322,4 @@ public class DocActivityView extends FrameLayout implements TabHost.OnTabChangeL
}
}
-
- public void showUI(boolean show)
- {
- View tabHost = findViewById(R.id.tabhost);
- View footer = findViewById(R.id.footer);
- if (show)
- {
- tabHost.setVisibility(View.VISIBLE);
- footer.setVisibility(View.VISIBLE);
- requestLayout();
- }
- else
- {
- tabHost.setVisibility(View.GONE);
- footer.setVisibility(View.GONE);
- requestLayout();
- }
- }
-
- public void stop()
- {
- mDocView.finish();
- if (usePagesView())
- {
- mDocView2.finish();
- }
- }
}
diff --git a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocView.java b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocView.java
index c057da5c..00e3e14c 100644
--- a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocView.java
+++ b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocView.java
@@ -59,7 +59,6 @@ public class DocView extends DocViewBase implements DragHandleListener
selectionHandlePadPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, padDp, metrics);
selectionHandleSizePx = (int) (scale * TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeDp, metrics));
- selectionHandleSizePx = selectionHandleSizePx * 8 / 10;
}
// create the selection handles
@@ -149,7 +148,6 @@ public class DocView extends DocViewBase implements DragHandleListener
@Override
protected void doDoubleTap(float fx, float fy)
{
-
}
private Point viewToScreen(Point p)
@@ -189,7 +187,6 @@ public class DocView extends DocViewBase implements DragHandleListener
@Override
public void onStartDrag(DragHandle handle)
{
-
}
@Override
@@ -249,7 +246,6 @@ public class DocView extends DocViewBase implements DragHandleListener
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
{
-
super.onLayout(changed, left, top, right, bottom);
moveHandlesToCorners();
@@ -269,8 +265,6 @@ public class DocView extends DocViewBase implements DragHandleListener
positionHandle(mSelectionHandleTopLeft, selectionStartPage, selectionStartLoc.x, selectionStartLoc.y);
positionHandle(mSelectionHandleBottomRight, selectionEndPage, selectionEndLoc.x, selectionEndLoc.y);
}
-
-
}
}
}
diff --git a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocViewBase.java b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocViewBase.java
index 71cf1bbf..06de523a 100755
--- a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocViewBase.java
+++ b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocViewBase.java
@@ -935,8 +935,13 @@ public class DocViewBase
protected void smoothScrollBy(int dx, int dy)
{
+ smoothScrollBy(dx, dy, 400);
+ }
+
+ protected void smoothScrollBy(int dx, int dy, int ms)
+ {
mScrollerLastX = mScrollerLastY = 0;
- mScroller.startScroll(0, 0, dx, dy, 400);
+ mScroller.startScroll(0, 0, dx, dy, ms);
mStepper.prod();
}
@@ -961,7 +966,7 @@ public class DocViewBase
if ((childRect.height()) > viewport.height())
{
// put the top of the page at the top and the left at 0
- smoothScrollBy(getScrollX(), getScrollY() - childRect.top);
+ smoothScrollBy(getScrollX(), getScrollY() - childRect.top, 1);
}
else
{
@@ -969,9 +974,9 @@ public class DocViewBase
if (childRect.top < viewport.top || childRect.bottom > viewport.bottom)
{
if (childRect.top == 0)
- smoothScrollBy(0, getScrollY());
+ smoothScrollBy(0, getScrollY(), 1);
else
- smoothScrollBy(0, getScrollY() + viewport.height() / 2 - (childRect.bottom + childRect.top) / 2);
+ smoothScrollBy(0, getScrollY() + viewport.height() / 2 - (childRect.bottom + childRect.top) / 2, 1);
}
}
}
diff --git a/platform/android/example/mupdf/src/main/res/values/integers.xml b/platform/android/example/mupdf/src/main/res/values/integers.xml
index ea63e64a..f7f1e528 100644
--- a/platform/android/example/mupdf/src/main/res/values/integers.xml
+++ b/platform/android/example/mupdf/src/main/res/values/integers.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <integer name="page_width_percentage">87</integer>
- <integer name="pagelist_width_percentage">13</integer>
+ <integer name="page_width_percentage">90</integer>
+ <integer name="pagelist_width_percentage">10</integer>
<integer name="text_highlight_alpha">60</integer>