@capacitor-plus/android 8.3.11 → 8.5.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.
@@ -353,7 +353,7 @@ public class BridgeWebChromeClient extends WebChromeClient {
353
353
  boolean captureEnabled = fileChooserParams.isCaptureEnabled();
354
354
  boolean capturePhoto = captureEnabled && acceptTypes.contains("image/*");
355
355
  final boolean captureVideo = captureEnabled && acceptTypes.contains("video/*");
356
- if ((capturePhoto || captureVideo)) {
356
+ if (capturePhoto || captureVideo) {
357
357
  if (isMediaCaptureSupported()) {
358
358
  showMediaCaptureOrFilePicker(filePathCallback, fileChooserParams, captureVideo);
359
359
  } else {
@@ -411,6 +411,7 @@ public class BridgeWebChromeClient extends WebChromeClient {
411
411
  return false;
412
412
  }
413
413
  takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri);
414
+ takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
414
415
 
415
416
  // Store in static variables to survive activity recreation
416
417
  pendingFilePathCallback = filePathCallback;
@@ -539,7 +540,7 @@ public class BridgeWebChromeClient extends WebChromeClient {
539
540
  }
540
541
 
541
542
  public boolean isValidMsg(String msg) {
542
- return !(msg.contains("%cresult %c") || (msg.contains("%cnative %c")) || msg.equalsIgnoreCase("console.groupEnd"));
543
+ return !(msg.contains("%cresult %c") || msg.contains("%cnative %c") || msg.equalsIgnoreCase("console.groupEnd"));
543
544
  }
544
545
 
545
546
  private Uri createImageFileUri() throws IOException {
@@ -218,7 +218,7 @@ public class FileUtils {
218
218
  Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
219
219
  int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
220
220
  cursor.moveToFirst();
221
- String name = (cursor.getString(nameIndex));
221
+ String name = cursor.getString(nameIndex);
222
222
  String fileName = sanitizeFilename(name);
223
223
  File file = new File(context.getFilesDir(), fileName);
224
224
  try {
@@ -65,6 +65,17 @@ public class PluginConfig {
65
65
  return JSONUtils.getInt(config, configKey, defaultValue);
66
66
  }
67
67
 
68
+ /**
69
+ * Get a double value for a plugin in the Capacitor config.
70
+ *
71
+ * @param configKey The key of the value to retrieve
72
+ * @param defaultValue A default value to return if the key does not exist in the config
73
+ * @return The value from the config, if key exists. Default value returned if not
74
+ */
75
+ public double getDouble(String configKey, double defaultValue) {
76
+ return JSONUtils.getDouble(config, configKey, defaultValue);
77
+ }
78
+
68
79
  /**
69
80
  * Get a string array value for a plugin in the Capacitor config.
70
81
  *
@@ -221,7 +221,7 @@ public class WebViewLocalServer {
221
221
  }
222
222
 
223
223
  private boolean isMainUrl(Uri loadingUrl) {
224
- return (bridge.getServerUrl() == null && loadingUrl.getHost().equalsIgnoreCase(bridge.getHost()));
224
+ return bridge.getServerUrl() == null && loadingUrl.getHost().equalsIgnoreCase(bridge.getHost());
225
225
  }
226
226
 
227
227
  private boolean isAllowedUrl(Uri loadingUrl) {
@@ -728,31 +728,31 @@ public class WebViewLocalServer {
728
728
  @Override
729
729
  public int available() throws IOException {
730
730
  InputStream is = getInputStream();
731
- return (is != null) ? is.available() : -1;
731
+ return is != null ? is.available() : -1;
732
732
  }
733
733
 
734
734
  @Override
735
735
  public int read() throws IOException {
736
736
  InputStream is = getInputStream();
737
- return (is != null) ? is.read() : -1;
737
+ return is != null ? is.read() : -1;
738
738
  }
739
739
 
740
740
  @Override
741
741
  public int read(byte[] b) throws IOException {
742
742
  InputStream is = getInputStream();
743
- return (is != null) ? is.read(b) : -1;
743
+ return is != null ? is.read(b) : -1;
744
744
  }
745
745
 
746
746
  @Override
747
747
  public int read(byte[] b, int off, int len) throws IOException {
748
748
  InputStream is = getInputStream();
749
- return (is != null) ? is.read(b, off, len) : -1;
749
+ return is != null ? is.read(b, off, len) : -1;
750
750
  }
751
751
 
752
752
  @Override
753
753
  public long skip(long n) throws IOException {
754
754
  InputStream is = getInputStream();
755
- return (is != null) ? is.skip(n) : 0;
755
+ return is != null ? is.skip(n) : 0;
756
756
  }
757
757
  }
758
758
 
@@ -192,12 +192,12 @@ public class CapacitorCookieManager extends CookieManager {
192
192
  @Override
193
193
  public void put(URI uri, Map<String, List<String>> responseHeaders) {
194
194
  // make sure our args are valid
195
- if ((uri == null) || (responseHeaders == null)) return;
195
+ if (uri == null || responseHeaders == null) return;
196
196
 
197
197
  // go over the headers
198
198
  for (String headerKey : responseHeaders.keySet()) {
199
199
  // ignore headers which aren't cookie related
200
- if ((headerKey == null) || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey.equalsIgnoreCase("Set-Cookie"))) continue;
200
+ if (headerKey == null || !(headerKey.equalsIgnoreCase("Set-Cookie2") || headerKey.equalsIgnoreCase("Set-Cookie"))) continue;
201
201
 
202
202
  // process each of the headers
203
203
  for (String headerValue : Objects.requireNonNull(responseHeaders.get(headerKey))) {
@@ -215,7 +215,7 @@ public class CapacitorCookieManager extends CookieManager {
215
215
  @Override
216
216
  public Map<String, List<String>> get(URI uri, Map<String, List<String>> requestHeaders) {
217
217
  // make sure our args are valid
218
- if ((uri == null) || (requestHeaders == null)) throw new IllegalArgumentException("Argument is null");
218
+ if (uri == null || requestHeaders == null) throw new IllegalArgumentException("Argument is null");
219
219
 
220
220
  // save our url once
221
221
  String url = uri.toString();
@@ -17,6 +17,7 @@ import androidx.core.view.WindowCompat;
17
17
  import androidx.core.view.WindowInsetsCompat;
18
18
  import androidx.core.view.WindowInsetsControllerCompat;
19
19
  import androidx.webkit.WebViewCompat;
20
+ import com.getcapacitor.Logger;
20
21
  import com.getcapacitor.Plugin;
21
22
  import com.getcapacitor.PluginCall;
22
23
  import com.getcapacitor.PluginMethod;
@@ -33,6 +34,7 @@ public class SystemBars extends Plugin {
33
34
  static final String BAR_STATUS_BAR = "StatusBar";
34
35
  static final String BAR_GESTURE_BAR = "NavigationBar";
35
36
 
37
+ // TODO: In Cap 9, add an additional option "full"
36
38
  static final String INSETS_HANDLING_CSS = "css";
37
39
  static final String INSETS_HANDLING_DISABLE = "disable";
38
40
 
@@ -54,7 +56,7 @@ public class SystemBars extends Plugin {
54
56
  capacitorSystemBarsCheckMetaViewport();
55
57
  """;
56
58
 
57
- private boolean insetHandlingEnabled = true;
59
+ private String insetsHandling = INSETS_HANDLING_CSS;
58
60
  private boolean hasViewportCover = false;
59
61
 
60
62
  private String currentStatusBarStyle = STYLE_DEFAULT;
@@ -81,7 +83,7 @@ public class SystemBars extends Plugin {
81
83
  super.onPageCommitVisible(view, url);
82
84
  View parentView = (View) getBridge().getWebView().getParent();
83
85
  ViewCompat.requestApplyInsets(parentView);
84
- if (insetHandlingEnabled) {
86
+ if (INSETS_HANDLING_CSS.equals(insetsHandling)) {
85
87
  WindowInsetsCompat rootInsets = ViewCompat.getRootWindowInsets(parentView);
86
88
  if (rootInsets != null) {
87
89
  Insets safeArea = calcSafeAreaInsets(rootInsets);
@@ -105,9 +107,15 @@ public class SystemBars extends Plugin {
105
107
  String style = getConfig().getString("style", STYLE_DEFAULT).toUpperCase(Locale.US);
106
108
  boolean hidden = getConfig().getBoolean("hidden", false);
107
109
 
108
- String insetsHandling = getConfig().getString("insetsHandling", "css");
109
- if (insetsHandling.equals(INSETS_HANDLING_DISABLE)) {
110
- insetHandlingEnabled = false;
110
+ String configuredInsetsHandling = getConfig().getString("insetsHandling", INSETS_HANDLING_CSS);
111
+ if (INSETS_HANDLING_CSS.equals(configuredInsetsHandling) || INSETS_HANDLING_DISABLE.equals(configuredInsetsHandling)) {
112
+ insetsHandling = configuredInsetsHandling;
113
+ } else {
114
+ Logger.warn(
115
+ "SystemBars",
116
+ "Unknown insetsHandling value '" + configuredInsetsHandling + "'. Falling back to '" + INSETS_HANDLING_CSS + "'."
117
+ );
118
+ insetsHandling = INSETS_HANDLING_CSS;
111
119
  }
112
120
 
113
121
  initWindowInsetsListener();
@@ -184,12 +192,15 @@ public class SystemBars extends Plugin {
184
192
 
185
193
  @JavascriptInterface
186
194
  public void onDOMReady() {
187
- getActivity().runOnUiThread(() -> {
188
- this.bridge.getWebView().evaluateJavascript(viewportMetaJSFunction, (res) -> {
189
- hasViewportCover = res.equals("true");
190
- ViewCompat.requestApplyInsets((View) getBridge().getWebView().getParent());
195
+ if (INSETS_HANDLING_CSS.equals(insetsHandling)) {
196
+ getActivity().runOnUiThread(() -> {
197
+ this.bridge.getWebView().evaluateJavascript(viewportMetaJSFunction, (res) -> {
198
+ hasViewportCover = res.equals("true");
199
+
200
+ getBridge().getWebView().requestApplyInsets();
201
+ });
191
202
  });
192
- });
203
+ }
193
204
  }
194
205
 
195
206
  private Insets calcSafeAreaInsets(WindowInsetsCompat insets) {
@@ -224,9 +235,16 @@ public class SystemBars extends Plugin {
224
235
  }
225
236
 
226
237
  private void initSafeAreaCSSVariables() {
227
- if (insetHandlingEnabled) {
228
- View v = (View) this.getBridge().getWebView().getParent();
229
- WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(v);
238
+ if (INSETS_HANDLING_CSS.equals(insetsHandling)) {
239
+ WindowInsetsCompat insets;
240
+
241
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
242
+ View v = (View) this.getBridge().getWebView().getParent();
243
+ insets = ViewCompat.getRootWindowInsets(v);
244
+ } else {
245
+ insets = WindowInsetsCompat.CONSUMED;
246
+ }
247
+
230
248
  if (insets != null) {
231
249
  Insets safeAreaInsets = calcSafeAreaInsets(insets);
232
250
  injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
@@ -235,6 +253,10 @@ public class SystemBars extends Plugin {
235
253
  }
236
254
 
237
255
  private void initWindowInsetsListener() {
256
+ if (INSETS_HANDLING_DISABLE.equals(insetsHandling)) {
257
+ return;
258
+ }
259
+
238
260
  ViewCompat.setOnApplyWindowInsetsListener((View) getBridge().getWebView().getParent(), (v, insets) -> {
239
261
  // getRootWindowInsets() bypasses AppCompat's intermediate view consuming the bottom inset on API < 30
240
262
  WindowInsetsCompat rawInsets = ViewCompat.getRootWindowInsets(v);
@@ -250,10 +272,8 @@ public class SystemBars extends Plugin {
250
272
  // We need to correct for a possible shown IME
251
273
  v.setPadding(0, 0, 0, keyboardVisible ? imeInsets.bottom : 0);
252
274
 
253
- if (hasViewportCover && insetHandlingEnabled) {
254
- Insets safeAreaInsets = calcSafeAreaInsets(safeAreaSource);
255
- injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
256
- }
275
+ Insets safeAreaInsets = calcSafeAreaInsets(safeAreaSource);
276
+ injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
257
277
 
258
278
  return new WindowInsetsCompat.Builder(insets)
259
279
  .setInsets(
@@ -277,10 +297,8 @@ public class SystemBars extends Plugin {
277
297
  .setInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout(), Insets.of(0, 0, 0, 0))
278
298
  .build();
279
299
 
280
- if (insetHandlingEnabled) {
281
- Insets safeAreaInsets = calcSafeAreaInsets(safeAreaSource);
282
- injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
283
- }
300
+ Insets safeAreaInsets = calcSafeAreaInsets(safeAreaSource);
301
+ injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
284
302
 
285
303
  return newInsets;
286
304
  });
@@ -344,20 +362,24 @@ public class SystemBars extends Plugin {
344
362
  WindowInsetsControllerCompat windowInsetsControllerCompat = WindowCompat.getInsetsController(window, window.getDecorView());
345
363
 
346
364
  if (hide) {
347
- if (bar.isEmpty() || bar.equals(BAR_STATUS_BAR)) {
365
+ if (bar.isEmpty()) {
366
+ windowInsetsControllerCompat.hide(WindowInsetsCompat.Type.systemBars());
367
+ navBarVisible = false;
368
+ } else if (bar.equals(BAR_STATUS_BAR)) {
348
369
  windowInsetsControllerCompat.hide(WindowInsetsCompat.Type.statusBars());
349
- }
350
- if (bar.isEmpty() || bar.equals(BAR_GESTURE_BAR)) {
370
+ } else if (bar.equals(BAR_GESTURE_BAR)) {
351
371
  windowInsetsControllerCompat.hide(WindowInsetsCompat.Type.navigationBars());
352
372
  navBarVisible = false;
353
373
  }
354
374
  return;
355
375
  }
356
376
 
357
- if (bar.isEmpty() || bar.equals(BAR_STATUS_BAR)) {
377
+ if (bar.isEmpty()) {
358
378
  windowInsetsControllerCompat.show(WindowInsetsCompat.Type.systemBars());
359
- }
360
- if (bar.isEmpty() || bar.equals(BAR_GESTURE_BAR)) {
379
+ navBarVisible = true;
380
+ } else if (bar.equals(BAR_STATUS_BAR)) {
381
+ windowInsetsControllerCompat.show(WindowInsetsCompat.Type.statusBars());
382
+ } else if (bar.equals(BAR_GESTURE_BAR)) {
361
383
  windowInsetsControllerCompat.show(WindowInsetsCompat.Type.navigationBars());
362
384
  navBarVisible = true;
363
385
  }
@@ -168,8 +168,8 @@ public class HttpRequestHandler {
168
168
  "://" +
169
169
  uri.getAuthority() +
170
170
  uri.getPath() +
171
- ((!urlQuery.equals("")) ? "?" + urlQuery : "") +
172
- ((uri.getFragment() != null) ? uri.getFragment() : "");
171
+ (!urlQuery.equals("") ? "?" + urlQuery : "") +
172
+ (uri.getFragment() != null ? uri.getFragment() : "");
173
173
  this.url = new URL(unEncodedUrlString);
174
174
 
175
175
  return this;
@@ -75,6 +75,26 @@ public class JSONUtils {
75
75
  return defaultValue;
76
76
  }
77
77
 
78
+ /**
79
+ * Get a double value from the given JSON object.
80
+ *
81
+ * @param jsonObject A JSON object to search
82
+ * @param key A key to fetch from the JSON object
83
+ * @param defaultValue A default value to return if the key cannot be found
84
+ * @return The value at the given key in the JSON object, or the default value
85
+ */
86
+ public static double getDouble(JSONObject jsonObject, String key, double defaultValue) {
87
+ String k = getDeepestKey(key);
88
+ try {
89
+ JSONObject o = getDeepestObject(jsonObject, key);
90
+ return o.getDouble(k);
91
+ } catch (JSONException ignore) {
92
+ // value was not found
93
+ }
94
+
95
+ return defaultValue;
96
+ }
97
+
78
98
  /**
79
99
  * Get a JSON object value from the given JSON object.
80
100
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-plus/android",
3
- "version": "8.3.11",
3
+ "version": "8.5.1",
4
4
  "description": "Capacitor+: Enhanced Capacitor with automated upstream sync - Cross-platform apps with JavaScript and the web",
5
5
  "homepage": "https://capgo.app/docs/plugins/capacitor-plus/",
6
6
  "author": "Capgo Team <support@capgo.app> (https://capgo.app)",
@@ -23,8 +23,8 @@
23
23
  "verify": "./gradlew clean lint build test -b capacitor/build.gradle"
24
24
  },
25
25
  "peerDependencies": {
26
- "@capacitor-plus/core": "^8.3.0",
27
- "@capacitor/core": "^8.3.0"
26
+ "@capacitor-plus/core": "^8.5.0",
27
+ "@capacitor/core": "^8.5.0"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public"