expo-h3 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'expo.modules.h3'
4
- version = '0.1.8'
4
+ version = '0.1.9'
5
5
 
6
6
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
7
7
  apply from: expoModulesCorePlugin
@@ -35,7 +35,7 @@ android {
35
35
  namespace "expo.modules.h3"
36
36
  defaultConfig {
37
37
  versionCode 1
38
- versionName "0.1.8"
38
+ versionName "0.1.9"
39
39
  }
40
40
  lintOptions {
41
41
  abortOnError false
@@ -7,7 +7,7 @@ import android.os.ParcelFileDescriptor;
7
7
  import android.print.PageRange;
8
8
  import android.print.PrintAttributes;
9
9
  import android.print.PrintDocumentAdapter;
10
- import android.print.PrintDocumentInfo;
10
+ import android.webkit.WebView;
11
11
 
12
12
  import expo.modules.kotlin.Promise;
13
13
 
@@ -16,88 +16,96 @@ import java.io.IOException;
16
16
 
17
17
  public class PrintHelper {
18
18
  public static void printWebView(PrintDocumentAdapter adapter, PrintAttributes attributes, final File pdfFile, final Context context, final Promise promise) {
19
- adapter.onLayout(null, attributes, null, new LayoutResultCallbackImpl(adapter, pdfFile, context, promise), null);
19
+ try {
20
+ ParcelFileDescriptor pfd = ParcelFileDescriptor.open(pdfFile,
21
+ ParcelFileDescriptor.MODE_READ_WRITE | ParcelFileDescriptor.MODE_CREATE);
22
+
23
+ PrintDocumentAdapterWrapper wrapper = new PrintDocumentAdapterWrapper(
24
+ adapter, pfd, pdfFile, context, promise);
25
+
26
+ wrapper.onLayout(null, attributes, null, wrapper.layoutCallback, null);
27
+ } catch (IOException e) {
28
+ promise.reject("FILE_ERROR", e.getMessage(), e);
29
+ }
20
30
  }
21
-
22
- private static class LayoutResultCallbackImpl extends PrintDocumentAdapter.LayoutResultCallback {
23
- private final PrintDocumentAdapter adapter;
31
+
32
+ static class PrintDocumentAdapterWrapper extends PrintDocumentAdapter {
33
+ private final PrintDocumentAdapter wrapped;
34
+ private final ParcelFileDescriptor pfd;
24
35
  private final File pdfFile;
25
36
  private final Context context;
26
37
  private final Promise promise;
27
-
28
- LayoutResultCallbackImpl(PrintDocumentAdapter adapter, File pdfFile, Context context, Promise promise) {
29
- this.adapter = adapter;
38
+
39
+ LayoutResultCallback layoutCallback = new LayoutResultCallback() {};
40
+ WriteResultCallback writeCallback = new WriteResultCallback() {};
41
+
42
+ PrintDocumentAdapterWrapper(PrintDocumentAdapter wrapped, ParcelFileDescriptor pfd,
43
+ File pdfFile, Context context, Promise promise) {
44
+ this.wrapped = wrapped;
45
+ this.pfd = pfd;
30
46
  this.pdfFile = pdfFile;
31
47
  this.context = context;
32
48
  this.promise = promise;
33
49
  }
34
-
50
+
35
51
  @Override
36
- public void onLayoutFinished(PrintDocumentInfo info, boolean changed) {
37
- ParcelFileDescriptor fd = null;
38
- try {
39
- fd = ParcelFileDescriptor.open(pdfFile, ParcelFileDescriptor.MODE_READ_WRITE);
40
- adapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, fd, new CancellationSignal(),
41
- new WriteResultCallbackImpl(fd, pdfFile, context, promise));
42
- } catch (IOException e) {
43
- promise.reject("FILE_ERROR", e.getMessage(), e);
44
- if (fd != null) {
45
- try {
46
- fd.close();
47
- } catch (IOException ignore) {
48
- }
49
- }
50
- }
51
- }
52
+ public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
53
+ CancellationSignal cancellationSignal, LayoutResultCallback callback,
54
+ android.os.Bundle extras) {
55
+ wrapped.onLayout(oldAttributes, newAttributes, cancellationSignal,
56
+ new LayoutResultCallback() {
57
+ @Override
58
+ public void onLayoutFinished(android.print.PrintDocumentInfo info, boolean changed) {
59
+ try {
60
+ wrapped.onWrite(new PageRange[]{PageRange.ALL_PAGES}, pfd,
61
+ cancellationSignal, new WriteResultCallback() {
62
+ @Override
63
+ public void onWriteFinished(PageRange[] pages) {
64
+ try {
65
+ pfd.close();
66
+ Intent intent = new Intent();
67
+ intent.setAction(Intent.ACTION_SEND);
68
+ intent.setPackage("comb.bld.settings.print");
69
+ intent.putExtra(Intent.EXTRA_TEXT, pdfFile.getAbsolutePath());
70
+ intent.setType("application/pdf");
71
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
72
+ context.startActivity(intent);
73
+ pdfFile.delete();
74
+ promise.resolve("Printed successfully");
75
+ } catch (Exception e) {
76
+ promise.reject("PRINT_ERROR", e.getMessage(), e);
77
+ }
78
+ }
52
79
 
53
- @Override
54
- public void onLayoutFailed(CharSequence error) {
55
- promise.reject("PDF_LAYOUT_ERROR", error != null ? error.toString() : "Unknown error", null);
56
- }
57
- }
58
-
59
- private static class WriteResultCallbackImpl extends PrintDocumentAdapter.WriteResultCallback {
60
- private final ParcelFileDescriptor fd;
61
- private final File pdfFile;
62
- private final Context context;
63
- private final Promise promise;
64
-
65
- WriteResultCallbackImpl(ParcelFileDescriptor fd, File pdfFile, Context context, Promise promise) {
66
- this.fd = fd;
67
- this.pdfFile = pdfFile;
68
- this.context = context;
69
- this.promise = promise;
70
- }
80
+ @Override
81
+ public void onWriteFailed(CharSequence error) {
82
+ try {
83
+ pfd.close();
84
+ } catch (IOException ignore) {}
85
+ promise.reject("PDF_WRITE_ERROR",
86
+ error != null ? error.toString() : "Unknown error", null);
87
+ }
88
+ });
89
+ } catch (Exception e) {
90
+ promise.reject("WRITE_ERROR", e.getMessage(), e);
91
+ }
92
+ }
71
93
 
72
- @Override
73
- public void onWriteFinished(PageRange[] pages) {
74
- try {
75
- if (fd != null) {
76
- fd.close();
77
- }
78
- Intent intent = new Intent();
79
- intent.setAction(Intent.ACTION_SEND);
80
- intent.setPackage("comb.bld.settings.print");
81
- intent.putExtra(Intent.EXTRA_TEXT, pdfFile.getAbsolutePath());
82
- intent.setType("application/pdf");
83
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
84
- context.startActivity(intent);
85
- pdfFile.delete();
86
- promise.resolve("Printed successfully");
87
- } catch (Exception e) {
88
- promise.reject("PRINT_ERROR", e.getMessage(), e);
89
- }
94
+ @Override
95
+ public void onLayoutFailed(CharSequence error) {
96
+ try {
97
+ pfd.close();
98
+ } catch (IOException ignore) {}
99
+ promise.reject("PDF_LAYOUT_ERROR",
100
+ error != null ? error.toString() : "Unknown error", null);
101
+ }
102
+ }, extras);
90
103
  }
91
104
 
92
105
  @Override
93
- public void onWriteFailed(CharSequence error) {
94
- try {
95
- if (fd != null) {
96
- fd.close();
97
- }
98
- } catch (IOException ignore) {
99
- }
100
- promise.reject("PDF_WRITE_ERROR", error != null ? error.toString() : "Unknown error", null);
106
+ public void onWrite(PageRange[] pages, ParcelFileDescriptor destination,
107
+ CancellationSignal cancellationSignal, WriteResultCallback callback) {
108
+ // Not used in our flow
101
109
  }
102
110
  }
103
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-h3",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "My new module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",