summaryrefslogtreecommitdiff
path: root/platform/android
diff options
context:
space:
mode:
authorfred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local>2016-09-13 12:40:32 -0700
committerfred ross-perry <fredross-perry@Fred-Ross-Perrys-Computer.local>2016-09-14 09:10:04 -0700
commit49ed7cd9b1f484e84e3393d7638ff5f2d140633d (patch)
treee93a12ac43753d3c50480e3fc9da9926da181332 /platform/android
parent71ecb46b3e69bf32314f120503461deeadd73ab6 (diff)
downloadmupdf-49ed7cd9b1f484e84e3393d7638ff5f2d140633d.tar.xz
Android example - delete temp files after proofing, destroy the document and pages after use.
Diffstat (limited to 'platform/android')
-rw-r--r--platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/DocPageView.java50
-rw-r--r--platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/ProofActivity.java25
2 files changed, 53 insertions, 22 deletions
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 e862d87a..60611b2a 100644
--- 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
@@ -126,23 +126,11 @@ public class DocPageView extends View implements Callback
// make a new page object.
if (thePageNum != mPageNum)
{
- mPageNum = thePageNum;
-
- // de-cache contents and annotations
- if (pageContents != null)
- {
- pageContents.destroy();
- pageContents = null;
- }
- if (annotContents != null)
- {
- annotContents.destroy();
- annotContents = null;
- }
+ // destroy current page and lists
+ destroyPageAndLists();
- // destroy the page before making a new one.
- if (mPage != null)
- mPage.destroy();
+ // switch to the new page
+ mPageNum = thePageNum;
mPage = mDoc.loadPage(mPageNum);
}
@@ -157,6 +145,26 @@ public class DocPageView extends View implements Callback
mSize = new Point((int) (pagew * mZoom), (int) (pageH * mZoom));
}
+ private void destroyPageAndLists()
+ {
+ // de-cache contents and annotations
+ if (pageContents != null)
+ {
+ pageContents.destroy();
+ pageContents = null;
+ }
+ if (annotContents != null)
+ {
+ annotContents.destroy();
+ annotContents = null;
+ }
+
+ // destroy the page before making a new one.
+ if (mPage != null)
+ mPage.destroy();
+ mPage = null;
+ }
+
public Page getPage()
{
return mPage;
@@ -364,6 +372,7 @@ public class DocPageView extends View implements Callback
catch (RuntimeException e)
{
pageContents.destroy();
+ pageContents = null;
dispDev.destroy();
throw (e);
}
@@ -392,6 +401,7 @@ public class DocPageView extends View implements Callback
catch (RuntimeException e)
{
annotContents.destroy();
+ annotContents = null;
annotDev.destroy();
throw (e);
}
@@ -806,12 +816,8 @@ public class DocPageView extends View implements Callback
{
mFinished = true;
- // destroy the page
- if (mPage != null)
- {
- mPage.destroy();
- mPage = null;
- }
+ // destroy page and lists
+ destroyPageAndLists();
}
public boolean getMostVisible() {return isMostVisible;}
diff --git a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/ProofActivity.java b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/ProofActivity.java
index 0d11f063..04ba3089 100644
--- a/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/ProofActivity.java
+++ b/platform/android/example/mupdf/src/main/java/com/artifex/mupdf/android/ProofActivity.java
@@ -29,7 +29,11 @@ import com.artifex.mupdf.fitz.Page;
import com.artifex.mupdf.fitz.R;
import com.artifex.mupdf.fitz.Separation;
+import java.io.File;
+import java.io.FileFilter;
import java.util.LinkedList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class ProofActivity extends Activity implements View.OnClickListener, DocViewBase.IdleRenderListener
{
@@ -112,9 +116,30 @@ public class ProofActivity extends Activity implements View.OnClickListener, Doc
// stop the view
mDocView.finish();
+ // kill the document
+ mDoc.destroy();
+
// delete the .gproof file
Utilities.deleteFile(mPath);
+ // delete temp files left by the proofing.
+ // these are of the form gprf_n_xxxxxx
+ File dir = new File(mPath).getParentFile();
+ final Pattern pattern = Pattern.compile("gprf_.*_.*");
+ File[] files = dir.listFiles(new FileFilter()
+ {
+ public boolean accept(File file)
+ {
+ Matcher matcher = pattern.matcher(file.getName());
+ return matcher.matches();
+ }
+ });
+ for (File file:files)
+ {
+ System.out.println(String.format("deleting %s", file.getAbsolutePath()));
+ file.delete();
+ }
+
super.finish();
}