@capgo/inappbrowser 7.6.12 → 7.7.1

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.
@@ -20,6 +20,9 @@ import android.net.Uri;
20
20
  import android.net.http.SslError;
21
21
  import android.os.Build;
22
22
  import android.os.Environment;
23
+ import android.print.PrintAttributes;
24
+ import android.print.PrintDocumentAdapter;
25
+ import android.print.PrintManager;
23
26
  import android.provider.MediaStore;
24
27
  import android.text.TextUtils;
25
28
  import android.util.Base64;
@@ -214,6 +217,44 @@ public class WebViewDialog extends Dialog {
214
217
  }
215
218
  }
216
219
 
220
+ public class PrintInterface {
221
+
222
+ private Context context;
223
+ private WebView webView;
224
+
225
+ public PrintInterface(Context context, WebView webView) {
226
+ this.context = context;
227
+ this.webView = webView;
228
+ }
229
+
230
+ @JavascriptInterface
231
+ public void print() {
232
+ // Run on UI thread since printing requires UI operations
233
+ ((Activity) context).runOnUiThread(
234
+ new Runnable() {
235
+ @Override
236
+ public void run() {
237
+ // Create a print job from the WebView content
238
+ PrintManager printManager =
239
+ (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
240
+ String jobName = "Document_" + System.currentTimeMillis();
241
+
242
+ PrintDocumentAdapter printAdapter;
243
+
244
+ // For API 21+ (Lollipop and above)
245
+ printAdapter = webView.createPrintDocumentAdapter(jobName);
246
+
247
+ printManager.print(
248
+ jobName,
249
+ printAdapter,
250
+ new PrintAttributes.Builder().build()
251
+ );
252
+ }
253
+ }
254
+ );
255
+ }
256
+ }
257
+
217
258
  @SuppressLint({ "SetJavaScriptEnabled", "AddJavascriptInterface" })
218
259
  public void presentWebView() {
219
260
  requestWindowFeature(Window.FEATURE_NO_TITLE);
@@ -317,6 +358,10 @@ public class WebViewDialog extends Dialog {
317
358
  new PreShowScriptInterface(),
318
359
  "PreShowScriptInterface"
319
360
  );
361
+ _webView.addJavascriptInterface(
362
+ new PrintInterface(this._context, _webView),
363
+ "PrintInterface"
364
+ );
320
365
  _webView.getSettings().setJavaScriptEnabled(true);
321
366
  _webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
322
367
  _webView.getSettings().setDatabaseEnabled(true);
@@ -1037,7 +1082,13 @@ public class WebViewDialog extends Dialog {
1037
1082
  " window.AndroidInterface.close(); " +
1038
1083
  " } " +
1039
1084
  " }; " +
1040
- "}";
1085
+ "} " +
1086
+ // Override the window.print function to use our PrintInterface
1087
+ "window.print = function() { " +
1088
+ " if (window.PrintInterface) { " +
1089
+ " window.PrintInterface.print(); " +
1090
+ " } " +
1091
+ "};";
1041
1092
  _webView.evaluateJavascript(script, null);
1042
1093
  }
1043
1094
 
@@ -8,14 +8,17 @@
8
8
  android:elevation="4dp"
9
9
  app:titleTextColor="#262626">
10
10
 
11
- <ImageButton
12
- android:id="@+id/closeButton"
13
- android:layout_width="wrap_content"
14
- android:layout_height="wrap_content"
15
- android:src="@drawable/ic_clear_24px"
16
- android:layout_gravity="start"
17
- android:background="#eeeeef"
18
- android:contentDescription="@string/close_button" />
11
+ <ImageButton
12
+ android:id="@+id/closeButton"
13
+ android:layout_width="wrap_content"
14
+ android:layout_height="wrap_content"
15
+ android:layout_gravity="start"
16
+ android:background="#eeeeef"
17
+ android:contentDescription="@string/close_button"
18
+ android:minWidth="38dp"
19
+ android:minHeight="38dp"
20
+ android:src="@drawable/ic_clear_24px"
21
+ android:translationX="-8dp" />
19
22
 
20
23
  <ImageButton
21
24
  android:id="@+id/buttonNearDone"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/inappbrowser",
3
- "version": "7.6.12",
3
+ "version": "7.7.1",
4
4
  "description": "Capacitor plugin in app browser",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",