expo-h3 0.1.7 → 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
|
|
@@ -16,60 +16,88 @@ 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
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
intent.setAction(Intent.ACTION_SEND);
|
|
35
|
-
intent.setPackage("comb.bld.settings.print");
|
|
36
|
-
intent.putExtra(Intent.EXTRA_TEXT, pdfFile.getAbsolutePath());
|
|
37
|
-
intent.setType("application/pdf");
|
|
38
|
-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
39
|
-
context.startActivity(intent);
|
|
40
|
-
pdfFile.delete();
|
|
41
|
-
promise.resolve("Printed successfully");
|
|
42
|
-
} catch (Exception e) {
|
|
43
|
-
promise.reject("PRINT_ERROR", e.getMessage(), e);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
19
|
+
adapter.onLayout(null, attributes, null, new LayoutResultCallbackImpl(adapter, pdfFile, context, promise), null);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private static class LayoutResultCallbackImpl extends PrintDocumentAdapter.LayoutResultCallback {
|
|
23
|
+
private final PrintDocumentAdapter adapter;
|
|
24
|
+
private final File pdfFile;
|
|
25
|
+
private final Context context;
|
|
26
|
+
private final Promise promise;
|
|
27
|
+
|
|
28
|
+
LayoutResultCallbackImpl(PrintDocumentAdapter adapter, File pdfFile, Context context, Promise promise) {
|
|
29
|
+
this.adapter = adapter;
|
|
30
|
+
this.pdfFile = pdfFile;
|
|
31
|
+
this.context = context;
|
|
32
|
+
this.promise = promise;
|
|
33
|
+
}
|
|
46
34
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (fd != null) {
|
|
61
|
-
try {
|
|
62
|
-
fd.close();
|
|
63
|
-
} catch (IOException ignore) {
|
|
64
|
-
}
|
|
35
|
+
@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) {
|
|
65
48
|
}
|
|
66
49
|
}
|
|
67
50
|
}
|
|
51
|
+
}
|
|
52
|
+
|
|
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;
|
|
68
64
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
}
|
|
71
|
+
|
|
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
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@Override
|
|
93
|
+
public void onWriteFailed(CharSequence error) {
|
|
94
|
+
try {
|
|
95
|
+
if (fd != null) {
|
|
96
|
+
fd.close();
|
|
97
|
+
}
|
|
98
|
+
} catch (IOException ignore) {
|
|
72
99
|
}
|
|
73
|
-
|
|
100
|
+
promise.reject("PDF_WRITE_ERROR", error != null ? error.toString() : "Unknown error", null);
|
|
101
|
+
}
|
|
74
102
|
}
|
|
75
103
|
}
|