Skip to content

Commit

Permalink
also perform export for printing and sharing in background
Browse files Browse the repository at this point in the history
  • Loading branch information
cgogolin committed Nov 6, 2017
1 parent 934b3ec commit 7c5c7a5
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 46 deletions.
2 changes: 1 addition & 1 deletion platform/android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cgogolin.penandpdf"
android:versionCode="52"
android:versionCode="53"
android:versionName="1.3.3"
android:installLocation="auto">
<permission android:name="com.cgogolin.penandpdf.LAUNCH_PEN_AND_PDF_FILE_CHOOSER" />
Expand Down
2 changes: 2 additions & 0 deletions platform/android/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
<string name="overwrite">Überschreibe</string>
<string name="overwrite_question">Überschreiben?</string>
<string name="parent_directory">..</string>
<string name="preparing_to_print">Drucken vorbereiten&#8230;</string>
<string name="preparing_to_share">Teilen vorbereiten&#8230;</string>
<string name="print">Drucken</string>
<string name="reason">Grund</string>
<string name="recent">Kürzlich</string>
Expand Down
2 changes: 2 additions & 0 deletions platform/android/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
<string name="overwrite">Reemplazar</string>
<string name="overwrite_question">¿Quieres reemplazar el archivo?</string>
<string name="parent_directory">..</string>
<string name="preparing_to_print">Preparando a imprimir&#8230;</string>
<string name="preparing_to_share">Preparando a compartir&#8230;</string>
<string name="print">Imprimir</string>
<string name="reason">Motivo</string>
<string name="recent">Reciente</string>
Expand Down
2 changes: 2 additions & 0 deletions platform/android/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
<string name="overwrite">Overwrite</string>
<string name="overwrite_question">Overwrite?</string>
<string name="parent_directory">..</string>
<string name="preparing_to_print">Preparing to print&#8230;</string>
<string name="preparing_to_share">Preparing to share&#8230;</string>
<string name="print">Print</string>
<string name="reason">Reason</string>
<string name="recent">Recent</string>
Expand Down
154 changes: 109 additions & 45 deletions platform/android/src/com/cgogolin/penandpdf/PenAndPDFActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1723,28 +1723,30 @@ private void showSaveAsActivity() {
}

private void saveAsInBackground(final Uri uri, final Callable successCallable, final Callable failureCallable) {
saveAsOrSaveInBackground(new Callable<Exception>() {
@Override
public Exception call() {
return saveAs(uri);
}
},
successCallable, failureCallable);
callInBackgroundAndShowDialog(getString(R.string.saving),
new Callable<Exception>() {
@Override
public Exception call() {
return saveAs(uri);
}
},
successCallable, failureCallable);
}

private void saveInBackground(final Callable successCallable, final Callable failureCallable) {
saveAsOrSaveInBackground(new Callable<Exception>() {
@Override
public Exception call() {
return save();
}
},
successCallable, failureCallable);
callInBackgroundAndShowDialog(getString(R.string.saving),
new Callable<Exception>() {
@Override
public Exception call() {
return save();
}
},
successCallable, failureCallable);
}

private void saveAsOrSaveInBackground(final Callable<Exception> saveCallable, final Callable successCallable, final Callable failureCallable) {
private void callInBackgroundAndShowDialog(final String messege, final Callable<Exception> 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);
Expand Down Expand Up @@ -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<Exception>() {
@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<Void>() {
@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<Exception>() {
@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<Void>() {
@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)));
// }
}


Expand Down

0 comments on commit 7c5c7a5

Please sign in to comment.