diff options
author | Paul Gardiner <paulg.artifex@glidos.net> | 2013-04-03 16:29:12 +0100 |
---|---|---|
committer | Paul Gardiner <paulg.artifex@glidos.net> | 2013-04-03 16:29:12 +0100 |
commit | 2d5d9b8540a87a16f2cdf98827bc37682cabe4c9 (patch) | |
tree | fdd4b3954ceba3ad8d65ba92fb12bc11e99c2f23 /android | |
parent | 004ecb30612bb2572f2614c84930e3ee5891c8e6 (diff) | |
download | mupdf-2d5d9b8540a87a16f2cdf98827bc37682cabe4c9.tar.xz |
Android: avoid SEGV when printing fails, and display error
Diffstat (limited to 'android')
-rw-r--r-- | android/src/com/artifex/mupdfdemo/MuPDFActivity.java | 18 | ||||
-rw-r--r-- | android/src/com/artifex/mupdfdemo/PrintDialogActivity.java | 9 |
2 files changed, 23 insertions, 4 deletions
diff --git a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java index 56ca9b0c..63f5b963 100644 --- a/android/src/com/artifex/mupdfdemo/MuPDFActivity.java +++ b/android/src/com/artifex/mupdfdemo/MuPDFActivity.java @@ -47,6 +47,8 @@ public class MuPDFActivity extends Activity /* The core rendering instance */ enum TopBarMode {Main, Search, Text, AnnotSelect, AnnotCreate, InkCreate}; + private final int OUTLINE_REQUEST=0; + private final int PRINT_REQUEST=1; private MuPDFCore core; private String mFileName; private MuPDFReaderView mDocView; @@ -545,7 +547,7 @@ public class MuPDFActivity extends Activity if (outline != null) { OutlineActivityData.get().items = outline; Intent intent = new Intent(MuPDFActivity.this, OutlineActivity.class); - startActivityForResult(intent, 0); + startActivityForResult(intent, OUTLINE_REQUEST); } } }); @@ -577,8 +579,16 @@ public class MuPDFActivity extends Activity @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (resultCode >= 0) - mDocView.setDisplayedViewIndex(resultCode); + switch (requestCode) { + case OUTLINE_REQUEST: + if (resultCode >= 0) + mDocView.setDisplayedViewIndex(resultCode); + break; + case PRINT_REQUEST: + if (resultCode == RESULT_CANCELED) + showInfo(getString(R.string.print_failed)); + break; + } super.onActivityResult(requestCode, resultCode, data); } @@ -787,7 +797,7 @@ public class MuPDFActivity extends Activity Intent printIntent = new Intent(this, PrintDialogActivity.class); printIntent.setDataAndType(docUri, "aplication/pdf"); printIntent.putExtra("title", mFileName); - startActivity(printIntent); + startActivityForResult(printIntent, PRINT_REQUEST); } private void showInfo(String message) { diff --git a/android/src/com/artifex/mupdfdemo/PrintDialogActivity.java b/android/src/com/artifex/mupdfdemo/PrintDialogActivity.java index cbfe07b9..8377255d 100644 --- a/android/src/com/artifex/mupdfdemo/PrintDialogActivity.java +++ b/android/src/com/artifex/mupdfdemo/PrintDialogActivity.java @@ -39,10 +39,13 @@ public class PrintDialogActivity extends Activity { */ Intent cloudPrintIntent; + private int resultCode; + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); + resultCode = RESULT_OK; setContentView(R.layout.print_dialog); dialogWebView = (WebView) findViewById(R.id.webview); cloudPrintIntent = this.getIntent(); @@ -90,8 +93,13 @@ public class PrintDialogActivity extends Activity { return Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT); } catch (FileNotFoundException e) { + resultCode = RESULT_CANCELED; e.printStackTrace(); } catch (IOException e) { + resultCode = RESULT_CANCELED; + e.printStackTrace(); + } catch (OutOfMemoryError e) { + resultCode = RESULT_CANCELED; e.printStackTrace(); } return ""; @@ -103,6 +111,7 @@ public class PrintDialogActivity extends Activity { public void onPostMessage(String message) { if (message.startsWith(CLOSE_POST_MESSAGE_NAME)) { + setResult(resultCode); finish(); } } |