From 7c5c7a560e345ca0b06e86883929aacefbf875c3 Mon Sep 17 00:00:00 2001 From: Christian Gogolin Date: Mon, 6 Nov 2017 18:34:22 +0100 Subject: [PATCH] also perform export for printing and sharing in background --- platform/android/AndroidManifest.xml | 2 +- platform/android/res/values-de/strings.xml | 2 + platform/android/res/values-es/strings.xml | 2 + platform/android/res/values/strings.xml | 2 + .../cgogolin/penandpdf/PenAndPDFActivity.java | 154 +++++++++++++----- 5 files changed, 116 insertions(+), 46 deletions(-) diff --git a/platform/android/AndroidManifest.xml b/platform/android/AndroidManifest.xml index c59d5eb5..e5522f23 100644 --- a/platform/android/AndroidManifest.xml +++ b/platform/android/AndroidManifest.xml @@ -1,7 +1,7 @@ diff --git a/platform/android/res/values-de/strings.xml b/platform/android/res/values-de/strings.xml index 7a3f1fee..ab2d576e 100644 --- a/platform/android/res/values-de/strings.xml +++ b/platform/android/res/values-de/strings.xml @@ -95,6 +95,8 @@ Überschreibe Überschreiben? .. + Drucken vorbereiten… + Teilen vorbereiten… Drucken Grund Kürzlich diff --git a/platform/android/res/values-es/strings.xml b/platform/android/res/values-es/strings.xml index ad97ddb9..afa04242 100644 --- a/platform/android/res/values-es/strings.xml +++ b/platform/android/res/values-es/strings.xml @@ -95,6 +95,8 @@ Reemplazar ¿Quieres reemplazar el archivo? .. + Preparando a imprimir… + Preparando a compartir… Imprimir Motivo Reciente diff --git a/platform/android/res/values/strings.xml b/platform/android/res/values/strings.xml index d9bffcb6..29f70fe7 100644 --- a/platform/android/res/values/strings.xml +++ b/platform/android/res/values/strings.xml @@ -95,6 +95,8 @@ Overwrite Overwrite? .. + Preparing to print… + Preparing to share… Print Reason Recent diff --git a/platform/android/src/com/cgogolin/penandpdf/PenAndPDFActivity.java b/platform/android/src/com/cgogolin/penandpdf/PenAndPDFActivity.java index 23df1ee2..11199033 100644 --- a/platform/android/src/com/cgogolin/penandpdf/PenAndPDFActivity.java +++ b/platform/android/src/com/cgogolin/penandpdf/PenAndPDFActivity.java @@ -1723,28 +1723,30 @@ private void showSaveAsActivity() { } private void saveAsInBackground(final Uri uri, final Callable successCallable, final Callable failureCallable) { - saveAsOrSaveInBackground(new Callable() { - @Override - public Exception call() { - return saveAs(uri); - } - }, - successCallable, failureCallable); + callInBackgroundAndShowDialog(getString(R.string.saving), + new Callable() { + @Override + public Exception call() { + return saveAs(uri); + } + }, + successCallable, failureCallable); } private void saveInBackground(final Callable successCallable, final Callable failureCallable) { - saveAsOrSaveInBackground(new Callable() { - @Override - public Exception call() { - return save(); - } - }, - successCallable, failureCallable); + callInBackgroundAndShowDialog(getString(R.string.saving), + new Callable() { + @Override + public Exception call() { + return save(); + } + }, + successCallable, failureCallable); } - private void saveAsOrSaveInBackground(final Callable saveCallable, final Callable successCallable, final Callable failureCallable) { + private void callInBackgroundAndShowDialog(final String messege, final Callable saveCallable, final Callable successCallable, final Callable failureCallable) { final AlertDialog waitWhileSavingDialog = mAlertBuilder.create(); - waitWhileSavingDialog.setTitle(getString(R.string.saving)); + waitWhileSavingDialog.setTitle(messege); waitWhileSavingDialog.setCancelable(false); waitWhileSavingDialog.setCanceledOnTouchOutside(false); final ProgressBar busyIndicator = new ProgressBar(this); @@ -1995,38 +1997,100 @@ private void printDoc() { showInfo(getString(R.string.format_currently_not_supported)); return; } - Intent printIntent = new Intent(this, PrintDialogActivity.class); - try - { - printIntent.setDataAndType(core.export(this), "aplication/pdf"); - } - catch(Exception e) - { - showInfo(getString(R.string.error_exporting)+" "+e.toString()); - } - printIntent.putExtra("title", core.getFileName()); - startActivityForResult(printIntent, PRINT_REQUEST); + + final Intent printIntent = new Intent(); + + callInBackgroundAndShowDialog( + getString(R.string.preparing_to_print), + new Callable() { + @Override + public Exception call() { + try + { + printIntent.setDataAndType(core.export(getApplicationContext()), "aplication/pdf"); + printIntent.putExtra("title", core.getFileName()); + } + catch(Exception e) + { + return e; + } + return null; + } + }, + new Callable() { + @Override + public Void call() { + mIgnoreSaveOnStopThisTime = true; + startActivityForResult(printIntent, PRINT_REQUEST); + return null; + } + }, + null); + // Intent printIntent = new Intent(this, PrintDialogActivity.class); + // try + // { + // printIntent.setDataAndType(core.export(this), "aplication/pdf"); + // } + // catch(Exception e) + // { + // showInfo(getString(R.string.error_exporting)+" "+e.toString()); + // } + // printIntent.putExtra("title", core.getFileName()); + // mIgnoreSaveOnStopThisTime = true; + // startActivityForResult(printIntent, PRINT_REQUEST); } private void shareDoc() { - Uri exportedUri = null; - try - { - exportedUri = core.export(this); - } - catch(Exception e) - { - showInfo(getString(R.string.error_exporting)+" "+e.toString()); - } - if(exportedUri != null) - { - Intent shareIntent = new Intent(); - shareIntent.setAction(Intent.ACTION_SEND); - shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - shareIntent.setDataAndType(exportedUri, getContentResolver().getType(exportedUri)); - shareIntent.putExtra(Intent.EXTRA_STREAM, exportedUri); - startActivity(Intent.createChooser(shareIntent, getString(R.string.share_with))); - } + final Intent shareIntent = new Intent(); + + callInBackgroundAndShowDialog( + getString(R.string.preparing_to_share), + new Callable() { + @Override + public Exception call() { + Uri exportedUri = null; + try + { + exportedUri = core.export(getApplicationContext()); + } + catch(Exception e) + { + return e; + } + shareIntent.setAction(Intent.ACTION_SEND); + shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + shareIntent.setDataAndType(exportedUri, getContentResolver().getType(exportedUri)); + shareIntent.putExtra(Intent.EXTRA_STREAM, exportedUri); + return null; + } + }, + new Callable() { + @Override + public Void call() { + mIgnoreSaveOnStopThisTime = true; + startActivity(Intent.createChooser(shareIntent, getString(R.string.share_with))); + return null; + } + }, + null); + // try + // { + // exportedUri = core.export(this); + // } + // catch(Exception e) + // { + // showInfo(getString(R.string.error_exporting)+" "+e.toString()); + // } + // if(exportedUri != null) + // { + // Intent shareIntent = new Intent(); + // shareIntent.setAction(Intent.ACTION_SEND); + // shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + // shareIntent.setDataAndType(exportedUri, getContentResolver().getType(exportedUri)); + // shareIntent.putExtra(Intent.EXTRA_STREAM, exportedUri); + // mIgnoreSaveOnStopThisTime = true; + // startActivity(Intent.createChooser(shareIntent, getString(R.string.share_with))); + // } }