summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authorFred Ross-Perry <fross-perry@conceptuamath.com>2016-08-17 15:03:11 -0700
committerFred Ross-Perry <fross-perry@conceptuamath.com>2016-08-17 15:03:11 -0700
commitd1ad269c3bc46ac070d3c682df390d04bd8cd619 (patch)
treec3773bcfe53280687e3656aec6a19fd4d3f5be31 /platform/android
parent7f2c725945ac3da1202c6736fa2cdf6f74c2413c (diff)
downloadmupdf-d1ad269c3bc46ac070d3c682df390d04bd8cd619.tar.xz
Android example - add first page and last page buttons
also, change DocPageView to paint a white background before doing anything else. Makes for smoother-looking scrolling. And, re-introduce the slower scrolling (400 msec) when moving between pages.
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocActivityView.java44
-rwxr-xr-xplatform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java10
-rwxr-xr-xplatform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocViewBase.java8
-rwxr-xr-xplatform/android/example/mupdf/src/main/res/drawable/icon_first_page.xml23
-rwxr-xr-xplatform/android/example/mupdf/src/main/res/drawable/icon_last_page.xml23
-rw-r--r--platform/android/example/mupdf/src/main/res/layout/pages_toolbar.xml71
6 files changed, 162 insertions, 17 deletions
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 1c867b54..d04a0830 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
@@ -35,6 +35,8 @@ public class DocActivityView extends FrameLayout implements TabHost.OnTabChangeL
private String mTagPages;
ImageButton mReflowButton;
+ ImageButton mFirstPageButton;
+ ImageButton mLastPageButton;
public DocActivityView(Context context)
{
@@ -233,13 +235,7 @@ public class DocActivityView extends FrameLayout implements TabHost.OnTabChangeL
@Override
public void onPageSelected(int pageNumber)
{
- mDocView.scrollToPage(pageNumber);
-
- if (mDocReflowView.getVisibility() == View.VISIBLE)
- {
- setReflowText(pageNumber);
- mDocPagesView.setMostVisiblePage(pageNumber);
- }
+ goToPage(pageNumber);
}
});
@@ -274,11 +270,17 @@ public class DocActivityView extends FrameLayout implements TabHost.OnTabChangeL
}
});
- // TODO: connect buttons to functions
+ // connect buttons to functions
mReflowButton = (ImageButton)findViewById(R.id.reflow_button);
mReflowButton.setOnClickListener(this);
+ mFirstPageButton = (ImageButton)findViewById(R.id.first_page_button);
+ mFirstPageButton.setOnClickListener(this);
+
+ mLastPageButton = (ImageButton)findViewById(R.id.last_page_button);
+ mLastPageButton.setOnClickListener(this);
+
// start the views
mDocView.start(path);
if (usePagesView())
@@ -357,6 +359,32 @@ public class DocActivityView extends FrameLayout implements TabHost.OnTabChangeL
{
if (v == mReflowButton)
onReflowButton();
+ if (v == mFirstPageButton)
+ onFirstPageButton();
+ if (v == mLastPageButton)
+ onLastPageButton();
+ }
+
+ private void onFirstPageButton()
+ {
+ goToPage(0);
+ }
+
+ private void onLastPageButton()
+ {
+ int npages = mDocView.getPageCount();
+ goToPage(npages-1);
+ }
+
+ private void goToPage(int pageNumber)
+ {
+ mDocView.scrollToPage(pageNumber);
+
+ if (mDocReflowView.getVisibility() == View.VISIBLE)
+ {
+ setReflowText(pageNumber);
+ mDocPagesView.setMostVisiblePage(pageNumber);
+ }
}
private void onReflowButton()
diff --git a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java
index 944a5af7..a188f90a 100755
--- a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java
+++ b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java
@@ -54,6 +54,7 @@ public class DocPageView extends View implements Callback
private final Paint mPainter;
private final Paint mHighlightPainter;
+ private final Paint mBlankPainter;
private final Paint mDotPainter;
private final Rect mSrcRect = new Rect();
private final Rect mDstRect = new Rect();
@@ -92,6 +93,10 @@ public class DocPageView extends View implements Callback
mHighlightPainter.setStyle(Paint.Style.FILL);
mHighlightPainter.setAlpha(getContext().getResources().getInteger(R.integer.text_highlight_alpha));
+ mBlankPainter = new Paint();
+ mBlankPainter.setStyle(Paint.Style.FILL);
+ mBlankPainter.setColor(Color.WHITE);
+
mDotPainter = new Paint();
mDotPainter.setStyle(Paint.Style.FILL);
mDotPainter.setColor(ContextCompat.getColor(context, R.color.blue_dot_color));
@@ -470,6 +475,11 @@ public class DocPageView extends View implements Callback
@Override
public void onDraw(Canvas canvas)
{
+ // always start with a blank white background
+ Rect rBlank = new Rect();
+ getLocalVisibleRect(rBlank);
+ canvas.drawRect(rBlank, mBlankPainter);
+
if (mFinished)
return;
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 06de523a..c271cad4 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
@@ -949,6 +949,8 @@ public class DocViewBase
{
// scroll to bring the page into view
+ int scrollTime = 400;
+
// get current viewport
Rect viewport = new Rect();
getGlobalVisibleRect(viewport);
@@ -966,7 +968,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, 1);
+ smoothScrollBy(getScrollX(), getScrollY() - childRect.top, scrollTime);
}
else
{
@@ -974,9 +976,9 @@ public class DocViewBase
if (childRect.top < viewport.top || childRect.bottom > viewport.bottom)
{
if (childRect.top == 0)
- smoothScrollBy(0, getScrollY(), 1);
+ smoothScrollBy(0, getScrollY(), scrollTime);
else
- smoothScrollBy(0, getScrollY() + viewport.height() / 2 - (childRect.bottom + childRect.top) / 2, 1);
+ smoothScrollBy(0, getScrollY() + viewport.height() / 2 - (childRect.bottom + childRect.top) / 2, scrollTime);
}
}
}
diff --git a/platform/android/example/mupdf/src/main/res/drawable/icon_first_page.xml b/platform/android/example/mupdf/src/main/res/drawable/icon_first_page.xml
new file mode 100755
index 00000000..10714831
--- /dev/null
+++ b/platform/android/example/mupdf/src/main/res/drawable/icon_first_page.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="50dp"
+ android:height="50dp"
+ android:viewportWidth="50"
+ android:viewportHeight="50">
+
+ <path
+ android:fillColor="#333333"
+ android:pathData="M30.001,9.334l7.808,7.792v23.538H12.191V9.334H30.001z
+M30.418,8.326H11.182v33.348h27.636V16.708 L30.418,8.326z" />
+ <path
+ android:strokeColor="#333333"
+ android:strokeWidth="1.034"
+ android:pathData="M 29.965 8.911 L 29.965 16.931 L 37.957 16.931 " />
+ <path
+ android:strokeColor="#333333"
+ android:strokeWidth="0.833"
+ android:pathData="M 25.445 38.609 L 25.445 11.317" />
+ <path
+ android:fillColor="#333333"
+ android:pathData="M 22.26 14.942 L 28.51 14.942 L 25.385 10.817 Z" />
+</vector> \ No newline at end of file
diff --git a/platform/android/example/mupdf/src/main/res/drawable/icon_last_page.xml b/platform/android/example/mupdf/src/main/res/drawable/icon_last_page.xml
new file mode 100755
index 00000000..24796a83
--- /dev/null
+++ b/platform/android/example/mupdf/src/main/res/drawable/icon_last_page.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="50dp"
+ android:height="50dp"
+ android:viewportWidth="50"
+ android:viewportHeight="50">
+
+ <path
+ android:fillColor="#333333"
+ android:pathData="M30.001,9.334l7.808,7.792v23.538H12.191V9.334H30.001z
+M30.418,8.326H11.182v33.348h27.636V16.708 L30.418,8.326z" />
+ <path
+ android:strokeColor="#333333"
+ android:strokeWidth="1.034"
+ android:pathData="M 29.965 8.911 L 29.965 16.931 L 37.957 16.931 " />
+ <path
+ android:strokeColor="#333333"
+ android:strokeWidth="0.833"
+ android:pathData="M 25.028 10.818 L 25.028 38.11" />
+ <path
+ android:fillColor="#333333"
+ android:pathData="M 21.842 34.484 L 28.093 34.484 L 24.967 38.609 Z" />
+</vector> \ No newline at end of file
diff --git a/platform/android/example/mupdf/src/main/res/layout/pages_toolbar.xml b/platform/android/example/mupdf/src/main/res/layout/pages_toolbar.xml
index f5cbc4d6..39a097c0 100644
--- a/platform/android/example/mupdf/src/main/res/layout/pages_toolbar.xml
+++ b/platform/android/example/mupdf/src/main/res/layout/pages_toolbar.xml
@@ -15,10 +15,14 @@
android:paddingTop="10dp"
android:paddingBottom="10dp">
+
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:orientation="vertical">
+ android:orientation="vertical"
+ android:paddingLeft="10dp"
+ android:paddingRight="10dp"
+ >
<ImageButton
android:layout_width="wrap_content"
@@ -26,25 +30,80 @@
android:scaleType="fitXY"
android:layout_centerVertical="true"
android:background="@drawable/toolbar_button"
- android:id="@+id/reflow_button"
- android:src="@drawable/icon_reflow" />
+ android:id="@+id/first_page_button"
+ android:src="@drawable/icon_first_page" />
<TextView
- android:layout_width="match_parent"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/black"
android:textSize="11sp"
- android:text="REFLOW"/>
+ android:text="FIRST PAGE"/>
</LinearLayout>
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingLeft="10dp"
+ android:paddingRight="10dp"
+ >
+
+ <ImageButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:scaleType="fitXY"
+ android:layout_centerVertical="true"
+ android:background="@drawable/toolbar_button"
+ android:id="@+id/last_page_button"
+ android:src="@drawable/icon_last_page" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:textColor="@color/black"
+ android:textSize="11sp"
+ android:text="LAST PAGE"/>
+ </LinearLayout>
+
+
<!--a divider-->
<View
android:layout_width="1dp"
- android:paddingRight="3dp" android:paddingLeft="3dp"
+ android:paddingRight="8dp"
+ android:paddingLeft="8dp"
android:layout_height="match_parent"
android:background="#FF8E8F90" />
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:paddingLeft="10dp"
+ android:paddingRight="10dp"
+ >
+
+ <ImageButton
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:scaleType="fitXY"
+ android:layout_centerVertical="true"
+ android:background="@drawable/toolbar_button"
+ android:id="@+id/reflow_button"
+ android:src="@drawable/icon_reflow" />
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:textColor="@color/black"
+ android:textSize="11sp"
+ android:text="REFLOW"/>
+ </LinearLayout>
+
</LinearLayout>
</HorizontalScrollView>