summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gardiner <paulg.artifex@glidos.net>2013-03-29 13:44:15 +0000
committerPaul Gardiner <paulg.artifex@glidos.net>2013-03-29 13:44:15 +0000
commitb8d9f5767c3057287dca3c26537f71110f705958 (patch)
treee9e2e2f11c96453a5a3264080c6ebc62fb4bc9d7
parente6b829c3c7f64d8e68fa4a379b1011c13a4bf767 (diff)
downloadmupdf-b8d9f5767c3057287dca3c26537f71110f705958.tar.xz
Android: some user-feedback improvements
Disable some features when in reflow mode Disable features when document format prohibits Add a few instructional on-scrren, info messages
-rw-r--r--android/jni/mupdf.c11
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFActivity.java94
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFCore.java9
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFPageView.java43
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFReflowView.java3
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFView.java2
6 files changed, 96 insertions, 66 deletions
diff --git a/android/jni/mupdf.c b/android/jni/mupdf.c
index 51bd1aa2..20d3a026 100644
--- a/android/jni/mupdf.c
+++ b/android/jni/mupdf.c
@@ -462,6 +462,17 @@ JNI_FN(MuPDFCore_countPagesInternal)(JNIEnv *env, jobject thiz)
return count;
}
+JNIEXPORT jstring JNICALL
+JNI_FN(MuPDFCore_fileFormatInternal)(JNIEnv * env, jobject thiz)
+{
+ char info[64];
+ globals *glo = get_globals(env, thiz);
+
+ fz_meta(glo->doc, FZ_META_FORMAT_INFO, info, sizeof(info));
+
+ return (*env)->NewStringUTF(env, info);
+}
+
JNIEXPORT void JNICALL
JNI_FN(MuPDFCore_gotoPageInternal)(JNIEnv *env, jobject thiz, int page)
{
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
index d320befd..ce05f470 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
@@ -477,12 +477,19 @@ public class MuPDFActivity extends Activity
}
});
- mAnnotButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- mTopBarMode = TopBarMode.AnnotCreate;
- mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
- }
- });
+ if (core.fileFormat().startsWith("PDF"))
+ {
+ mAnnotButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ mTopBarMode = TopBarMode.AnnotCreate;
+ mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
+ }
+ });
+ }
+ else
+ {
+ mAnnotButton.setVisibility(View.GONE);
+ }
// Activate the select button
mSelectButton.setOnClickListener(new View.OnClickListener() {
@@ -490,6 +497,7 @@ public class MuPDFActivity extends Activity
mDocView.setMode(MuPDFReaderView.Mode.Selecting);
mTopBarMode = TopBarMode.Text;
mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
+ showInfo("Select text");
}
});
@@ -509,6 +517,7 @@ public class MuPDFActivity extends Activity
mDocView.setMode(MuPDFReaderView.Mode.Drawing);
mTopBarMode = TopBarMode.InkCreate;
mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
+ showInfo("Draw annotation");
}
});
@@ -532,11 +541,14 @@ public class MuPDFActivity extends Activity
mSaveInkButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView();
+ boolean success = false;
if (pageView != null)
- pageView.saveDraw();
+ success = pageView.saveDraw();
mDocView.setMode(MuPDFReaderView.Mode.Viewing);
mTopBarMode = TopBarMode.Main;
mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
+ if (!success)
+ showInfo("Nothing to save");
}
});
@@ -634,15 +646,8 @@ public class MuPDFActivity extends Activity
public void afterTextChanged(Editable s) {
boolean haveText = s.toString().length() > 0;
- mSearchBack.setEnabled(haveText);
- mSearchFwd.setEnabled(haveText);
- if (haveText) {
- mSearchBack.setColorFilter(Color.argb(255, 255, 255, 255));
- mSearchFwd.setColorFilter(Color.argb(255, 255, 255, 255));
- } else {
- mSearchBack.setColorFilter(Color.argb(255, 128, 128, 128));
- mSearchFwd.setColorFilter(Color.argb(255, 128, 128, 128));
- }
+ setButtonEnabled(mSearchBack, haveText);
+ setButtonEnabled(mSearchFwd, haveText);
// Remove any previous search results
if (SearchTaskResult.get() != null && !mSearchText.getText().toString().equals(SearchTaskResult.get().txt)) {
@@ -687,16 +692,7 @@ public class MuPDFActivity extends Activity
mLinkButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
- if (mLinkHighlight) {
- mLinkButton.setColorFilter(Color.argb(0xFF, 255, 255, 255));
- mLinkHighlight = false;
- } else {
- // LINK_COLOR tint
- mLinkButton.setColorFilter(Color.argb(0xFF, 172, 114, 37));
- mLinkHighlight = true;
- }
- // Inform pages of the change.
- mDocView.setLinksEnabled(mLinkHighlight);
+ setLinkHighlight(!mLinkHighlight);
}
});
@@ -764,15 +760,12 @@ public class MuPDFActivity extends Activity
private void reflowModeSet(boolean reflow)
{
mReflow = reflow;
- if (mReflow) {
- mDocView.setAdapter(new MuPDFReflowAdapter(this, core));
- mReflowButton.setColorFilter(Color.argb(0xFF, 172, 114, 37));
- showInfo("Entering reflow mode");
- } else {
- mDocView.setAdapter(new MuPDFPageAdapter(this, core));
- mReflowButton.setColorFilter(Color.argb(0xFF, 255, 255, 255));
- showInfo("Exited reflow mode");
- }
+ mDocView.setAdapter(mReflow ? new MuPDFReflowAdapter(this, core) : new MuPDFPageAdapter(this, core));
+ mReflowButton.setColorFilter(mReflow ? Color.argb(0xFF, 172, 114, 37) : Color.argb(0xFF, 255, 255, 255));
+ setButtonEnabled(mAnnotButton, !reflow);
+ setButtonEnabled(mSearchButton, !reflow);
+ if (reflow) setLinkHighlight(false);
+ setButtonEnabled(mLinkButton, !reflow);
mDocView.refresh(mReflow);
}
@@ -835,7 +828,20 @@ public class MuPDFActivity extends Activity
super.onDestroy();
}
- void showButtons() {
+ private void setButtonEnabled(ImageButton button, boolean enabled) {
+ button.setEnabled(enabled);
+ button.setColorFilter(enabled ? Color.argb(255, 255, 255, 255):Color.argb(255, 128, 128, 128));
+ }
+
+ private void setLinkHighlight(boolean highlight) {
+ mLinkHighlight = highlight;
+ // LINK_COLOR tint
+ mLinkButton.setColorFilter(highlight ? Color.argb(0xFF, 172, 114, 37) : Color.argb(0xFF, 255, 255, 255));
+ // Inform pages of the change.
+ mDocView.setLinksEnabled(highlight);
+ }
+
+ private void showButtons() {
if (core == null)
return;
if (!mButtonsVisible) {
@@ -876,7 +882,7 @@ public class MuPDFActivity extends Activity
}
}
- void hideButtons() {
+ private void hideButtons() {
if (mButtonsVisible) {
mButtonsVisible = false;
hideKeyboard();
@@ -907,7 +913,7 @@ public class MuPDFActivity extends Activity
}
}
- void searchModeOn() {
+ private void searchModeOn() {
if (mTopBarMode != TopBarMode.Search) {
mTopBarMode = TopBarMode.Search;
//Focus on EditTextWidget
@@ -917,7 +923,7 @@ public class MuPDFActivity extends Activity
}
}
- void searchModeOff() {
+ private void searchModeOff() {
if (mTopBarMode == TopBarMode.Search) {
mTopBarMode = TopBarMode.Main;
hideKeyboard();
@@ -929,7 +935,7 @@ public class MuPDFActivity extends Activity
}
}
- void updatePageNumView(int index) {
+ private void updatePageNumView(int index) {
if (core == null)
return;
mPageNumberView.setText(String.format("%d / %d", index+1, core.countPages()));
@@ -985,7 +991,7 @@ public class MuPDFActivity extends Activity
}
}
- void makeButtonsView() {
+ private void makeButtonsView() {
mButtonsView = getLayoutInflater().inflate(R.layout.buttons,null);
mFilenameView = (TextView)mButtonsView.findViewById(R.id.docNameText);
mPageSlider = (SeekBar)mButtonsView.findViewById(R.id.pageSlider);
@@ -1020,19 +1026,19 @@ public class MuPDFActivity extends Activity
mPageSlider.setVisibility(View.INVISIBLE);
}
- void showKeyboard() {
+ private void showKeyboard() {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null)
imm.showSoftInput(mSearchText, 0);
}
- void hideKeyboard() {
+ private void hideKeyboard() {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null)
imm.hideSoftInputFromWindow(mSearchText.getWindowToken(), 0);
}
- void search(int direction) {
+ private void search(int direction) {
hideKeyboard();
int displayPage = mDocView.getDisplayedViewIndex();
SearchTaskResult r = SearchTaskResult.get();
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFCore.java b/android/src/com/artifex/mupdfdemo/MuPDFCore.java
index 2443784a..456cd1c5 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFCore.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFCore.java
@@ -19,10 +19,12 @@ public class MuPDFCore
private float pageHeight;
private long globals;
private byte fileBuffer[];
+ private String file_format;
/* The native functions */
private native long openFile(String filename);
private native long openBuffer();
+ private native String fileFormatInternal();
private native int countPagesInternal();
private native void gotoPageInternal(int localActionPageNum);
private native float getPageWidth();
@@ -73,6 +75,7 @@ public class MuPDFCore
{
throw new Exception("Failed to open "+filename);
}
+ file_format = fileFormatInternal();
}
public MuPDFCore(byte buffer[]) throws Exception
@@ -83,6 +86,7 @@ public class MuPDFCore
{
throw new Exception("Failed to open buffer");
}
+ file_format = fileFormatInternal();
}
public int countPages()
@@ -93,6 +97,11 @@ public class MuPDFCore
return numPages;
}
+ public String fileFormat()
+ {
+ return file_format;
+ }
+
private synchronized int countPagesSynchronized() {
return countPagesInternal();
}
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
index 69f038bb..cb3fac0b 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
@@ -357,32 +357,35 @@ public class MuPDFPageView extends PageView implements MuPDFView {
setItemSelectBox(null);
}
- public void saveDraw() {
+ public boolean saveDraw() {
PointF[][] path = getDraw();
- if (path != null) {
- if (mAddInk != null) {
- mAddInk.cancel(true);
- mAddInk = null;
+ if (path == null)
+ return false;
+
+ if (mAddInk != null) {
+ mAddInk.cancel(true);
+ mAddInk = null;
+ }
+ mAddInk = new AsyncTask<PointF[][],Void,Void>() {
+ @Override
+ protected Void doInBackground(PointF[][]... params) {
+ mCore.addInkAnnotation(mPageNumber, params[0]);
+ return null;
}
- mAddInk = new AsyncTask<PointF[][],Void,Void>() {
- @Override
- protected Void doInBackground(PointF[][]... params) {
- mCore.addInkAnnotation(mPageNumber, params[0]);
- return null;
- }
- @Override
- protected void onPostExecute(Void result) {
- loadAnnotations();
- update();
- }
+ @Override
+ protected void onPostExecute(Void result) {
+ loadAnnotations();
+ update();
+ }
- };
+ };
- mAddInk.execute(getDraw());
- cancelDraw();
- }
+ mAddInk.execute(getDraw());
+ cancelDraw();
+
+ return true;
}
@Override
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java
index 9200982a..0c7074bc 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java
@@ -112,7 +112,8 @@ public class MuPDFReflowView extends WebView implements MuPDFView {
public void cancelDraw() {
}
- public void saveDraw() {
+ public boolean saveDraw() {
+ return false;
}
public void setSearchBoxes(RectF[] searchBoxes) {
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFView.java b/android/src/com/artifex/mupdfdemo/MuPDFView.java
index 5731945d..cc0405d1 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFView.java
@@ -23,7 +23,7 @@ public interface MuPDFView {
public void startDraw(float x, float y);
public void continueDraw(float x, float y);
public void cancelDraw();
- public void saveDraw();
+ public boolean saveDraw();
public void setChangeReporter(Runnable reporter);
public void update();
public void addHq(boolean update);