expo-h3 0.1.6 → 0.1.7
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.7'
|
|
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.7"
|
|
39
39
|
}
|
|
40
40
|
lintOptions {
|
|
41
41
|
abortOnError false
|
|
@@ -15,84 +15,61 @@ import java.io.File;
|
|
|
15
15
|
import java.io.IOException;
|
|
16
16
|
|
|
17
17
|
public class PrintHelper {
|
|
18
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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 PrintDocumentAdapter.LayoutResultCallback() {
|
|
20
|
+
@Override
|
|
21
|
+
public void onLayoutFinished(PrintDocumentInfo info, boolean changed) {
|
|
22
|
+
ParcelFileDescriptor fd = null;
|
|
23
|
+
try {
|
|
24
|
+
fd = ParcelFileDescriptor.open(pdfFile, ParcelFileDescriptor.MODE_READ_WRITE);
|
|
25
|
+
final ParcelFileDescriptor finalFd = fd; // For access in inner class
|
|
26
|
+
adapter.onWrite(new PageRange[]{PageRange.ALL_PAGES}, fd, new CancellationSignal(), new PrintDocumentAdapter.WriteResultCallback() {
|
|
27
|
+
@Override
|
|
28
|
+
public void onWriteFinished(PageRange[] pages) {
|
|
29
|
+
try {
|
|
30
|
+
if (finalFd != null) {
|
|
31
|
+
finalFd.close();
|
|
32
|
+
}
|
|
33
|
+
Intent intent = new Intent();
|
|
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
|
+
}
|
|
46
|
+
|
|
47
|
+
@Override
|
|
48
|
+
public void onWriteFailed(CharSequence error) {
|
|
49
|
+
try {
|
|
50
|
+
if (finalFd != null) {
|
|
51
|
+
finalFd.close();
|
|
52
|
+
}
|
|
53
|
+
} catch (IOException ignore) {
|
|
54
|
+
}
|
|
55
|
+
promise.reject("PDF_WRITE_ERROR", error != null ? error.toString() : "Unknown error", null);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
} catch (IOException e) {
|
|
59
|
+
promise.reject("FILE_ERROR", e.getMessage(), e);
|
|
60
|
+
if (fd != null) {
|
|
61
|
+
try {
|
|
62
|
+
fd.close();
|
|
63
|
+
} catch (IOException ignore) {
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
50
67
|
}
|
|
51
|
-
}
|
|
52
68
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private static final class MyWriteCallback extends PrintDocumentAdapter.WriteResultCallback {
|
|
60
|
-
|
|
61
|
-
private final ParcelFileDescriptor fd;
|
|
62
|
-
private final File pdfFile;
|
|
63
|
-
private final Context context;
|
|
64
|
-
private final Promise promise;
|
|
65
|
-
|
|
66
|
-
MyWriteCallback(ParcelFileDescriptor fd, File pdfFile, Context context, Promise promise) {
|
|
67
|
-
this.fd = fd;
|
|
68
|
-
this.pdfFile = pdfFile;
|
|
69
|
-
this.context = context;
|
|
70
|
-
this.promise = promise;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
@Override
|
|
74
|
-
public void onWriteFinished(PageRange[] pages) {
|
|
75
|
-
try {
|
|
76
|
-
if (fd != null) fd.close();
|
|
77
|
-
|
|
78
|
-
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
79
|
-
intent.setPackage("comb.bld.settings.print");
|
|
80
|
-
intent.putExtra(Intent.EXTRA_TEXT, pdfFile.getAbsolutePath());
|
|
81
|
-
intent.setType("application/pdf");
|
|
82
|
-
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
83
|
-
|
|
84
|
-
context.startActivity(intent);
|
|
85
|
-
pdfFile.delete();
|
|
86
|
-
|
|
87
|
-
promise.resolve("Printed successfully");
|
|
88
|
-
} catch (Exception e) {
|
|
89
|
-
promise.reject("PRINT_ERROR", e.getMessage(), e);
|
|
69
|
+
@Override
|
|
70
|
+
public void onLayoutFailed(CharSequence error) {
|
|
71
|
+
promise.reject("PDF_LAYOUT_ERROR", error != null ? error.toString() : "Unknown error", null);
|
|
90
72
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
@Override
|
|
94
|
-
public void onWriteFailed(CharSequence error) {
|
|
95
|
-
promise.reject("PDF_WRITE_ERROR", error != null ? error.toString() : "Write failed", null);
|
|
96
|
-
}
|
|
73
|
+
}, null);
|
|
97
74
|
}
|
|
98
75
|
}
|