summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorPaul Gardiner <paulg.artifex@glidos.net>2013-02-21 13:50:12 +0000
committerRobin Watts <robin.watts@artifex.com>2013-02-26 19:02:00 +0000
commitdf1f7eb75709a95fdf3838976ebdf49a46430c3b (patch)
treef0408c021bdd3ba6b0498d82a9bc72d780ae8ed4 /android
parent5d6087bbce6ad9177244f823f38eee802a2aa23c (diff)
downloadmupdf-df1f7eb75709a95fdf3838976ebdf49a46430c3b.tar.xz
Android: implement annotation deletion
Diffstat (limited to 'android')
-rw-r--r--android/jni/mupdf.c32
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFActivity.java12
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFCore.java6
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFPageView.java42
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFReaderView.java2
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFReflowView.java5
-rw-r--r--android/src/com/artifex/mupdfdemo/MuPDFView.java3
7 files changed, 98 insertions, 4 deletions
diff --git a/android/jni/mupdf.c b/android/jni/mupdf.c
index d2aa124f..88c7a8c6 100644
--- a/android/jni/mupdf.c
+++ b/android/jni/mupdf.c
@@ -1477,6 +1477,38 @@ JNI_FN(MuPDFCore_addStrikeOutAnnotationInternal)(JNIEnv * env, jobject thiz, job
}
}
+JNIEXPORT void JNICALL
+JNI_FN(MuPDFCore_deleteAnnotationInternal)(JNIEnv * env, jobject thiz, int annot_index)
+{
+ globals *glo = get_globals(env, thiz);
+ fz_context *ctx = glo->ctx;
+ fz_document *doc = glo->doc;
+ fz_interactive *idoc = fz_interact(doc);
+ page_cache *pc = &glo->pages[glo->current];
+ fz_annot *annot;
+ int i;
+
+ if (idoc == NULL)
+ return;
+
+ fz_try(ctx)
+ {
+ annot = fz_first_annot(glo->doc, pc->page);
+ for (i = 0; i < annot_index && annot; i++)
+ annot = fz_next_annot(glo->doc, annot);
+
+ if (annot)
+ {
+ fz_delete_annot(idoc, pc->page, annot);
+ dump_annotation_display_lists(glo);
+ }
+ }
+ fz_catch(ctx)
+ {
+ LOGE("deleteAnnotationInternal: %s", ctx->error->message);
+ }
+}
+
static void close_doc(globals *glo)
{
int i;
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
index f0c94c6a..2e1b310c 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java
@@ -65,6 +65,7 @@ public class MuPDFActivity extends Activity
private ImageButton mStrikeOutButton;
private ImageButton mCancelButton;
private ImageButton mOutlineButton;
+ private ImageButton mDeleteButton;
private ViewAnimator mTopBarSwitcher;
private ImageButton mLinkButton;
private TopBarMode mTopBarMode;
@@ -635,6 +636,16 @@ public class MuPDFActivity extends Activity
mOutlineButton.setVisibility(View.GONE);
}
+ mDeleteButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ View cv = mDocView.getDisplayedView();
+ if (cv != null)
+ ((MuPDFView)cv).deleteSelectedAnnotation();
+ mTopBarMode = TopBarMode.Main;
+ mTopBarSwitcher.setDisplayedChild(mTopBarMode.ordinal());
+ }
+ });
+
// Reenstate last state if it was recorded
SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE);
mDocView.setDisplayedViewIndex(prefs.getInt("page"+mFileName, 0));
@@ -844,6 +855,7 @@ public class MuPDFActivity extends Activity
mStrikeOutButton = (ImageButton)mButtonsView.findViewById(R.id.strikeOutButton);
mCancelButton = (ImageButton)mButtonsView.findViewById(R.id.cancel);
mOutlineButton = (ImageButton)mButtonsView.findViewById(R.id.outlineButton);
+ mDeleteButton = (ImageButton)mButtonsView.findViewById(R.id.deleteButton);
mTopBarSwitcher = (ViewAnimator)mButtonsView.findViewById(R.id.switcher);
mSearchBack = (ImageButton)mButtonsView.findViewById(R.id.searchBack);
mSearchFwd = (ImageButton)mButtonsView.findViewById(R.id.searchForward);
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFCore.java b/android/src/com/artifex/mupdfdemo/MuPDFCore.java
index ec8fd513..f9b5f779 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFCore.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFCore.java
@@ -40,6 +40,7 @@ public class MuPDFCore
private native TextChar[][][][] text();
private native byte[] textAsHtml();
private native void addStrikeOutAnnotationInternal(RectF[] lines);
+ private native void deleteAnnotationInternal(int annot_index);
private native int passClickEventInternal(int page, float x, float y);
private native void setFocusedWidgetChoiceSelectedInternal(String [] selected);
private native String [] getFocusedWidgetChoiceSelected();
@@ -252,6 +253,11 @@ public class MuPDFCore
addStrikeOutAnnotationInternal(lines);
}
+ public synchronized void deleteAnnotation(int page, int annot_index) {
+ gotoPage(page);
+ deleteAnnotationInternal(annot_index);
+ }
+
public synchronized boolean hasOutline() {
return hasOutlineInternal();
}
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
index ae206c1e..63531ec8 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFPageView.java
@@ -65,6 +65,7 @@ public class MuPDFPageView extends PageView implements MuPDFView {
private AsyncTask<Void,Void,PassClickResult> mPassClick;
private RectF mWidgetAreas[];
private Annotation mAnnotations[];
+ private int mSelectedAnnotationIndex = -1;
private AsyncTask<Void,Void,RectF[]> mLoadWidgetAreas;
private AsyncTask<Void,Void,Annotation[]> mLoadAnnotations;
private AlertDialog.Builder mTextEntryBuilder;
@@ -73,7 +74,8 @@ public class MuPDFPageView extends PageView implements MuPDFView {
private EditText mEditText;
private AsyncTask<String,Void,Boolean> mSetWidgetText;
private AsyncTask<String,Void,Void> mSetWidgetChoice;
- private AsyncTask<RectF[],Void,Void> mAddStrikeOut;
+ private AsyncTask<RectF[],Void,Void> mAddStrikeOut;
+ private AsyncTask<Integer,Void,Void> mDeleteAnnotation;
private Runnable changeReporter;
public MuPDFPageView(Context c, MuPDFCore core, Point parentSize) {
@@ -183,12 +185,14 @@ public class MuPDFPageView extends PageView implements MuPDFView {
case UNDERLINE:
case SQUIGGLY:
case STRIKEOUT:
+ mSelectedAnnotationIndex = i;
setItemSelectBox(mAnnotations[i]);
return Hit.Annotation;
}
}
}
+ mSelectedAnnotationIndex = -1;
setItemSelectBox(null);
if (!MuPDFCore.javascriptSupported())
@@ -320,6 +324,37 @@ public class MuPDFPageView extends PageView implements MuPDFView {
deselectText();
}
+ public void deleteSelectedAnnotation() {
+ if (mSelectedAnnotationIndex != -1) {
+ if (mDeleteAnnotation != null)
+ mDeleteAnnotation.cancel(true);
+
+ mDeleteAnnotation = new AsyncTask<Integer,Void,Void>() {
+ @Override
+ protected Void doInBackground(Integer... params) {
+ mCore.deleteAnnotation(mPageNumber, params[0]);
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void result) {
+ loadAnnotations();
+ update();
+ }
+ };
+
+ mDeleteAnnotation.execute(mSelectedAnnotationIndex);
+
+ mSelectedAnnotationIndex = -1;
+ setItemSelectBox(null);
+ }
+ }
+
+ public void deselectAnnotation() {
+ mSelectedAnnotationIndex = -1;
+ setItemSelectBox(null);
+ }
+
@Override
protected Bitmap drawPage(int sizeX, int sizeY,
int patchX, int patchY, int patchWidth, int patchHeight) {
@@ -424,6 +459,11 @@ public class MuPDFPageView extends PageView implements MuPDFView {
mAddStrikeOut = null;
}
+ if (mDeleteAnnotation != null) {
+ mDeleteAnnotation.cancel(true);
+ mDeleteAnnotation = null;
+ }
+
super.releaseResources();
}
}
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java b/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java
index dfb7cf0b..13575dc7 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFReaderView.java
@@ -165,7 +165,7 @@ public class MuPDFReaderView extends ReaderView {
protected void onMoveOffChild(int i) {
View v = getView(i);
if (v != null)
- ((MuPDFView)v).setItemSelectBox(null);
+ ((MuPDFView)v).deselectAnnotation();
}
protected void onSettle(View v) {
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java
index 789314f5..0cc2960a 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFReflowView.java
@@ -108,7 +108,10 @@ public class MuPDFReflowView extends WebView implements MuPDFView {
public void setLinkHighlighting(boolean f) {
}
- public void setItemSelectBox(RectF rect) {
+ public void deleteSelectedAnnotation() {
+ }
+
+ public void deselectAnnotation() {
}
public void setChangeReporter(Runnable reporter) {
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFView.java b/android/src/com/artifex/mupdfdemo/MuPDFView.java
index d16fc818..a213b349 100644
--- a/android/src/com/artifex/mupdfdemo/MuPDFView.java
+++ b/android/src/com/artifex/mupdfdemo/MuPDFView.java
@@ -16,9 +16,10 @@ public interface MuPDFView {
public void deselectText();
public boolean copySelection();
public void strikeOutSelection();
+ public void deleteSelectedAnnotation();
public void setSearchBoxes(RectF searchBoxes[]);
public void setLinkHighlighting(boolean f);
- public void setItemSelectBox(RectF rect);
+ public void deselectAnnotation();
public void setChangeReporter(Runnable reporter);
public void update();
public void addHq(boolean update);