summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gardiner <paulg.artifex@glidos.net>2013-03-19 10:57:09 +0000
committerPaul Gardiner <paulg.artifex@glidos.net>2013-03-24 16:53:15 +0000
commitf031719c18e610269e85aa1d1b83a619ddc7fec7 (patch)
tree475813de8fc5c9b9da287cc984820066459847ad
parent03a7b530fc05426f4b9537784b6dab5e45a337f6 (diff)
downloadmupdf-f031719c18e610269e85aa1d1b83a619ddc7fec7.tar.xz
Android: warn when no text selected and avoid creating empty annotations
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFActivity.java80
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFPageView.java7
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFReflowView.java3
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFView.java2
4 files changed, 55 insertions, 37 deletions
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
index 41a71405..01783ede 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
@@ -488,7 +488,6 @@ public class MuPDFActivity extends Activity
}
});
- final Context context = this;
mCopySelectButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView();
@@ -498,69 +497,49 @@ public class MuPDFActivity extends Activity
mDocView.setMode(MuPDFReaderView.Mode.Viewing);
mTopBarMode = TopBarMode.Main;
mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
- mInfoView.setText(copied?"Copied to clipboard":"No text selected");
-
- int currentApiVersion = android.os.Build.VERSION.SDK_INT;
- if (currentApiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) {
- AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(context, R.animator.info);
- set.setTarget(mInfoView);
- set.addListener(new Animator.AnimatorListener() {
- public void onAnimationStart(Animator animation) {
- mInfoView.setVisibility(View.VISIBLE);
- }
-
- public void onAnimationRepeat(Animator animation) {
- }
-
- public void onAnimationEnd(Animator animation) {
- mInfoView.setVisibility(View.INVISIBLE);
- }
-
- public void onAnimationCancel(Animator animation) {
- }
- });
- set.start();
- } else {
- mInfoView.setVisibility(View.VISIBLE);
- mHandler.postDelayed(new Runnable() {
- public void run() {
- mInfoView.setVisibility(View.INVISIBLE);
- }
- }, 500);
- }
+ showInfo(copied?"Copied to clipboard":"No text selected");
}
});
mHighlightButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView();
+ boolean success = false;
if (pageView != null)
- pageView.markupSelection(Annotation.Type.HIGHLIGHT);
+ success = pageView.markupSelection(Annotation.Type.HIGHLIGHT);
mDocView.setMode(MuPDFReaderView.Mode.Viewing);
mTopBarMode = TopBarMode.Main;
mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
+ if (!success)
+ showInfo("No text selected");
}
});
mUnderlineButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView();
+ boolean success = false;
if (pageView != null)
- pageView.markupSelection(Annotation.Type.UNDERLINE);
+ success = pageView.markupSelection(Annotation.Type.UNDERLINE);
mDocView.setMode(MuPDFReaderView.Mode.Viewing);
mTopBarMode = TopBarMode.Main;
mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
+ if (!success)
+ showInfo("No text selected");
}
});
mStrikeOutButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
MuPDFView pageView = (MuPDFView) mDocView.getDisplayedView();
+ boolean success = false;
if (pageView != null)
- pageView.markupSelection(Annotation.Type.STRIKEOUT);
+ success = pageView.markupSelection(Annotation.Type.STRIKEOUT);
mDocView.setMode(MuPDFReaderView.Mode.Viewing);
mTopBarMode = TopBarMode.Main;
mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
+ if (!success)
+ showInfo("No text selected");
}
});
@@ -868,6 +847,39 @@ public class MuPDFActivity extends Activity
mPageNumberView.setText(String.format("%d / %d", index+1, core.countPages()));
}
+ private void showInfo(String message) {
+ mInfoView.setText(message);
+
+ int currentApiVersion = android.os.Build.VERSION.SDK_INT;
+ if (currentApiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) {
+ AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.info);
+ set.setTarget(mInfoView);
+ set.addListener(new Animator.AnimatorListener() {
+ public void onAnimationStart(Animator animation) {
+ mInfoView.setVisibility(View.VISIBLE);
+ }
+
+ public void onAnimationRepeat(Animator animation) {
+ }
+
+ public void onAnimationEnd(Animator animation) {
+ mInfoView.setVisibility(View.INVISIBLE);
+ }
+
+ public void onAnimationCancel(Animator animation) {
+ }
+ });
+ set.start();
+ } else {
+ mInfoView.setVisibility(View.VISIBLE);
+ mHandler.postDelayed(new Runnable() {
+ public void run() {
+ mInfoView.setVisibility(View.INVISIBLE);
+ }
+ }, 500);
+ }
+ }
+
void makeButtonsView() {
mButtonsView = getLayoutInflater().inflate(R.layout.buttons,null);
mFilenameView = (TextView)mButtonsView.findViewById(R.id.docNameText);
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
index 092af33b..06c3827a 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
@@ -279,7 +279,7 @@ public class MuPDFPageView extends PageView implements MuPDFView {
return true;
}
- public void markupSelection(final Annotation.Type type) {
+ public boolean markupSelection(final Annotation.Type type) {
final ArrayList<PointF> quadPoints = new ArrayList<PointF>();
processSelectedText(new TextProcessor() {
RectF rect;
@@ -302,6 +302,9 @@ public class MuPDFPageView extends PageView implements MuPDFView {
}
});
+ if (quadPoints.size() == 0)
+ return false;
+
mAddStrikeOut = new AsyncTask<PointF[],Void,Void>() {
@Override
protected Void doInBackground(PointF[]... params) {
@@ -319,6 +322,8 @@ public class MuPDFPageView extends PageView implements MuPDFView {
mAddStrikeOut.execute(quadPoints.toArray(new PointF[quadPoints.size()]));
deselectText();
+
+ return true;
}
public void deleteSelectedAnnotation() {
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java
index d21140f4..1a2f1d91 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java
@@ -99,7 +99,8 @@ public class MuPDFReflowView extends WebView implements MuPDFView {
return false;
}
- public void markupSelection(Annotation.Type type) {
+ public boolean markupSelection(Annotation.Type type) {
+ 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 fe93b532..5f7f19e0 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFView.java
@@ -15,7 +15,7 @@ public interface MuPDFView {
public void selectText(float x0, float y0, float x1, float y1);
public void deselectText();
public boolean copySelection();
- public void markupSelection(Annotation.Type type);
+ public boolean markupSelection(Annotation.Type type);
public void deleteSelectedAnnotation();
public void setSearchBoxes(RectF searchBoxes[]);
public void setLinkHighlighting(boolean f);