expo-h3 0.1.6 → 0.1.8
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.
package/android/build.gradle
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
2
|
|
|
3
3
|
group = 'expo.modules.h3'
|
|
4
|
-
version = '0.1.
|
|
4
|
+
version = '0.1.8'
|
|
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.
|
|
38
|
+
versionName "0.1.8"
|
|
39
39
|
}
|
|
40
40
|
lintOptions {
|
|
41
41
|
abortOnError false
|
|
@@ -15,25 +15,21 @@ import java.io.File;
|
|
|
15
15
|
import java.io.IOException;
|
|
16
16
|
|
|
17
17
|
public class PrintHelper {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
File pdfFile, Context context, Promise promise) {
|
|
21
|
-
|
|
22
|
-
adapter.onLayout(null, attributes, null, new MyLayoutCallback(pdfFile, context, promise, adapter), null);
|
|
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);
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
private static
|
|
26
|
-
|
|
22
|
+
private static class LayoutResultCallbackImpl extends PrintDocumentAdapter.LayoutResultCallback {
|
|
23
|
+
private final PrintDocumentAdapter adapter;
|
|
27
24
|
private final File pdfFile;
|
|
28
25
|
private final Context context;
|
|
29
26
|
private final Promise promise;
|
|
30
|
-
private final PrintDocumentAdapter adapter;
|
|
31
27
|
|
|
32
|
-
|
|
28
|
+
LayoutResultCallbackImpl(PrintDocumentAdapter adapter, File pdfFile, Context context, Promise promise) {
|
|
29
|
+
this.adapter = adapter;
|
|
33
30
|
this.pdfFile = pdfFile;
|
|
34
31
|
this.context = context;
|
|
35
32
|
this.promise = promise;
|
|
36
|
-
this.adapter = adapter;
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
@Override
|
|
@@ -41,29 +37,32 @@ public class PrintHelper {
|
|
|
41
37
|
ParcelFileDescriptor fd = null;
|
|
42
38
|
try {
|
|
43
39
|
fd = ParcelFileDescriptor.open(pdfFile, ParcelFileDescriptor.MODE_READ_WRITE);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
new MyWriteCallback(fd, pdfFile, context, promise));
|
|
47
|
-
|
|
40
|
+
adapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, fd, new CancellationSignal(),
|
|
41
|
+
new WriteResultCallbackImpl(fd, pdfFile, context, promise));
|
|
48
42
|
} catch (IOException e) {
|
|
49
43
|
promise.reject("FILE_ERROR", e.getMessage(), e);
|
|
44
|
+
if (fd != null) {
|
|
45
|
+
try {
|
|
46
|
+
fd.close();
|
|
47
|
+
} catch (IOException ignore) {
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
@Override
|
|
54
54
|
public void onLayoutFailed(CharSequence error) {
|
|
55
|
-
promise.reject("PDF_LAYOUT_ERROR", error != null ? error.toString() : "
|
|
55
|
+
promise.reject("PDF_LAYOUT_ERROR", error != null ? error.toString() : "Unknown error", null);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
private static
|
|
60
|
-
|
|
59
|
+
private static class WriteResultCallbackImpl extends PrintDocumentAdapter.WriteResultCallback {
|
|
61
60
|
private final ParcelFileDescriptor fd;
|
|
62
61
|
private final File pdfFile;
|
|
63
62
|
private final Context context;
|
|
64
63
|
private final Promise promise;
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
WriteResultCallbackImpl(ParcelFileDescriptor fd, File pdfFile, Context context, Promise promise) {
|
|
67
66
|
this.fd = fd;
|
|
68
67
|
this.pdfFile = pdfFile;
|
|
69
68
|
this.context = context;
|
|
@@ -73,17 +72,17 @@ public class PrintHelper {
|
|
|
73
72
|
@Override
|
|
74
73
|
public void onWriteFinished(PageRange[] pages) {
|
|
75
74
|
try {
|
|
76
|
-
if (fd != null)
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
if (fd != null) {
|
|
76
|
+
fd.close();
|
|
77
|
+
}
|
|
78
|
+
Intent intent = new Intent();
|
|
79
|
+
intent.setAction(Intent.ACTION_SEND);
|
|
79
80
|
intent.setPackage("comb.bld.settings.print");
|
|
80
81
|
intent.putExtra(Intent.EXTRA_TEXT, pdfFile.getAbsolutePath());
|
|
81
82
|
intent.setType("application/pdf");
|
|
82
83
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
83
|
-
|
|
84
84
|
context.startActivity(intent);
|
|
85
85
|
pdfFile.delete();
|
|
86
|
-
|
|
87
86
|
promise.resolve("Printed successfully");
|
|
88
87
|
} catch (Exception e) {
|
|
89
88
|
promise.reject("PRINT_ERROR", e.getMessage(), e);
|
|
@@ -92,7 +91,13 @@ public class PrintHelper {
|
|
|
92
91
|
|
|
93
92
|
@Override
|
|
94
93
|
public void onWriteFailed(CharSequence error) {
|
|
95
|
-
|
|
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);
|
|
96
101
|
}
|
|
97
102
|
}
|
|
98
103
|
}
|