expo-h3 0.1.7 → 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.
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.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.
|
|
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.
|
|
10
|
+
import android.webkit.WebView;
|
|
11
11
|
|
|
12
12
|
import expo.modules.kotlin.Promise;
|
|
13
13
|
|
|
@@ -16,60 +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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static class PrintDocumentAdapterWrapper extends PrintDocumentAdapter {
|
|
33
|
+
private final PrintDocumentAdapter wrapped;
|
|
34
|
+
private final ParcelFileDescriptor pfd;
|
|
35
|
+
private final File pdfFile;
|
|
36
|
+
private final Context context;
|
|
37
|
+
private final Promise promise;
|
|
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;
|
|
46
|
+
this.pdfFile = pdfFile;
|
|
47
|
+
this.context = context;
|
|
48
|
+
this.promise = promise;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Override
|
|
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
|
+
}
|
|
46
79
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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);
|
|
56
91
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@Override
|
|
95
|
+
public void onLayoutFailed(CharSequence error) {
|
|
61
96
|
try {
|
|
62
|
-
|
|
63
|
-
} catch (IOException ignore) {
|
|
64
|
-
|
|
97
|
+
pfd.close();
|
|
98
|
+
} catch (IOException ignore) {}
|
|
99
|
+
promise.reject("PDF_LAYOUT_ERROR",
|
|
100
|
+
error != null ? error.toString() : "Unknown error", null);
|
|
65
101
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
102
|
+
}, extras);
|
|
103
|
+
}
|
|
68
104
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
105
|
+
@Override
|
|
106
|
+
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination,
|
|
107
|
+
CancellationSignal cancellationSignal, WriteResultCallback callback) {
|
|
108
|
+
// Not used in our flow
|
|
109
|
+
}
|
|
74
110
|
}
|
|
75
111
|
}
|