@capacitor/android 7.0.0-alpha.1 → 7.0.0-beta.0

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.
@@ -1,19 +1,19 @@
1
1
  ext {
2
- androidxActivityVersion = project.hasProperty('androidxActivityVersion') ? rootProject.ext.androidxActivityVersion : '1.8.0'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
2
+ androidxActivityVersion = project.hasProperty('androidxActivityVersion') ? rootProject.ext.androidxActivityVersion : '1.9.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
4
  androidxCoordinatorLayoutVersion = project.hasProperty('androidxCoordinatorLayoutVersion') ? rootProject.ext.androidxCoordinatorLayoutVersion : '1.2.0'
5
- androidxCoreVersion = project.hasProperty('androidxCoreVersion') ? rootProject.ext.androidxCoreVersion : '1.12.0'
6
- androidxFragmentVersion = project.hasProperty('androidxFragmentVersion') ? rootProject.ext.androidxFragmentVersion : '1.6.2'
7
- androidxWebkitVersion = project.hasProperty('androidxWebkitVersion') ? rootProject.ext.androidxWebkitVersion : '1.9.0'
5
+ androidxCoreVersion = project.hasProperty('androidxCoreVersion') ? rootProject.ext.androidxCoreVersion : '1.15.0'
6
+ androidxFragmentVersion = project.hasProperty('androidxFragmentVersion') ? rootProject.ext.androidxFragmentVersion : '1.8.4'
7
+ androidxWebkitVersion = project.hasProperty('androidxWebkitVersion') ? rootProject.ext.androidxWebkitVersion : '1.12.1'
8
8
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
9
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
10
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
9
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
10
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
11
11
  cordovaAndroidVersion = project.hasProperty('cordovaAndroidVersion') ? rootProject.ext.cordovaAndroidVersion : '10.1.1'
12
12
  }
13
13
 
14
14
 
15
15
  buildscript {
16
- ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.10'
16
+ ext.kotlin_version = project.hasProperty("kotlin_version") ? rootProject.ext.kotlin_version : '1.9.25'
17
17
  repositories {
18
18
  google()
19
19
  mavenCentral()
@@ -22,7 +22,7 @@ buildscript {
22
22
  }
23
23
  }
24
24
  dependencies {
25
- classpath 'com.android.tools.build:gradle:8.7.0'
25
+ classpath 'com.android.tools.build:gradle:8.7.2'
26
26
 
27
27
  if (System.getenv("CAP_PUBLISH") == "true") {
28
28
  classpath 'io.github.gradle-nexus:publish-plugin:1.3.0'
@@ -64,8 +64,8 @@ android {
64
64
  lintConfig file('lint.xml')
65
65
  }
66
66
  compileOptions {
67
- sourceCompatibility JavaVersion.VERSION_17
68
- targetCompatibility JavaVersion.VERSION_17
67
+ sourceCompatibility JavaVersion.VERSION_21
68
+ targetCompatibility JavaVersion.VERSION_21
69
69
  }
70
70
  publishing {
71
71
  singleVariant("release")
@@ -90,7 +90,7 @@ dependencies {
90
90
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
91
91
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
92
92
  implementation "org.apache.cordova:framework:$cordovaAndroidVersion"
93
- testImplementation 'org.json:json:20231013'
94
- testImplementation 'org.mockito:mockito-inline:5.2.0'
93
+ testImplementation 'org.json:json:20240303'
94
+ testImplementation 'org.mockito:mockito-core:5.14.1'
95
95
  }
96
96
 
@@ -142,9 +142,7 @@ var nativeBridge = (function (exports) {
142
142
  const CAPACITOR_HTTP_INTERCEPTOR = '/_capacitor_http_interceptor_';
143
143
  const CAPACITOR_HTTP_INTERCEPTOR_URL_PARAM = 'u';
144
144
  // TODO: export as Cap function
145
- const isRelativeOrProxyUrl = (url) => !url ||
146
- !(url.startsWith('http:') || url.startsWith('https:')) ||
147
- url.indexOf(CAPACITOR_HTTP_INTERCEPTOR) > -1;
145
+ const isRelativeOrProxyUrl = (url) => !url || !(url.startsWith('http:') || url.startsWith('https:')) || url.indexOf(CAPACITOR_HTTP_INTERCEPTOR) > -1;
148
146
  // TODO: export as Cap function
149
147
  const createProxyUrl = (url, win) => {
150
148
  var _a, _b;
@@ -174,11 +172,10 @@ var nativeBridge = (function (exports) {
174
172
  return webviewServerUrl + '/_capacitor_file_' + filePath;
175
173
  }
176
174
  else if (filePath.startsWith('file://')) {
177
- return (webviewServerUrl + filePath.replace('file://', '/_capacitor_file_'));
175
+ return webviewServerUrl + filePath.replace('file://', '/_capacitor_file_');
178
176
  }
179
177
  else if (filePath.startsWith('content://')) {
180
- return (webviewServerUrl +
181
- filePath.replace('content:/', '/_capacitor_content_'));
178
+ return webviewServerUrl + filePath.replace('content:/', '/_capacitor_content_');
182
179
  }
183
180
  }
184
181
  return filePath;
@@ -289,9 +286,6 @@ var nativeBridge = (function (exports) {
289
286
  return docAddEventListener.apply(doc, args);
290
287
  };
291
288
  }
292
- // deprecated in v3, remove from v4
293
- cap.platform = cap.getPlatform();
294
- cap.isNative = cap.isNativePlatform();
295
289
  win.Capacitor = cap;
296
290
  };
297
291
  const initVendor = (win, cap) => {
@@ -321,27 +315,14 @@ var nativeBridge = (function (exports) {
321
315
  win.Ionic.WebView = IonicWebView;
322
316
  };
323
317
  const initLogger = (win, cap) => {
324
- const BRIDGED_CONSOLE_METHODS = [
325
- 'debug',
326
- 'error',
327
- 'info',
328
- 'log',
329
- 'trace',
330
- 'warn',
331
- ];
318
+ const BRIDGED_CONSOLE_METHODS = ['debug', 'error', 'info', 'log', 'trace', 'warn'];
332
319
  const createLogFromNative = (c) => (result) => {
333
320
  if (isFullConsole(c)) {
334
321
  const success = result.success === true;
335
322
  const tagStyles = success
336
323
  ? 'font-style: italic; font-weight: lighter; color: gray'
337
324
  : 'font-style: italic; font-weight: lighter; color: red';
338
- c.groupCollapsed('%cresult %c' +
339
- result.pluginId +
340
- '.' +
341
- result.methodName +
342
- ' (#' +
343
- result.callbackId +
344
- ')', tagStyles, 'font-style: italic; font-weight: bold; color: #444');
325
+ c.groupCollapsed('%cresult %c' + result.pluginId + '.' + result.methodName + ' (#' + result.callbackId + ')', tagStyles, 'font-style: italic; font-weight: bold; color: #444');
345
326
  if (result.success === false) {
346
327
  c.error(result.error);
347
328
  }
@@ -361,13 +342,7 @@ var nativeBridge = (function (exports) {
361
342
  };
362
343
  const createLogToNative = (c) => (call) => {
363
344
  if (isFullConsole(c)) {
364
- c.groupCollapsed('%cnative %c' +
365
- call.pluginId +
366
- '.' +
367
- call.methodName +
368
- ' (#' +
369
- call.callbackId +
370
- ')', 'font-weight: lighter; color: gray', 'font-weight: bold; color: #000');
345
+ c.groupCollapsed('%cnative %c' + call.pluginId + '.' + call.methodName + ' (#' + call.callbackId + ')', 'font-weight: lighter; color: gray', 'font-weight: bold; color: #000');
371
346
  c.dir(call);
372
347
  c.groupEnd();
373
348
  }
@@ -379,9 +354,7 @@ var nativeBridge = (function (exports) {
379
354
  if (!c) {
380
355
  return false;
381
356
  }
382
- return (typeof c.groupCollapsed === 'function' ||
383
- typeof c.groupEnd === 'function' ||
384
- typeof c.dir === 'function');
357
+ return typeof c.groupCollapsed === 'function' || typeof c.groupEnd === 'function' || typeof c.dir === 'function';
385
358
  };
386
359
  const serializeConsoleMessage = (msg) => {
387
360
  try {
@@ -440,9 +413,7 @@ var nativeBridge = (function (exports) {
440
413
  set: function (val) {
441
414
  const cookiePairs = val.split(';');
442
415
  const domainSection = val.toLowerCase().split('domain=')[1];
443
- const domain = cookiePairs.length > 1 &&
444
- domainSection != null &&
445
- domainSection.length > 0
416
+ const domain = cookiePairs.length > 1 && domainSection != null && domainSection.length > 0
446
417
  ? domainSection.split(';')[0].trim()
447
418
  : '';
448
419
  if (platform === 'ios') {
@@ -527,8 +498,7 @@ var nativeBridge = (function (exports) {
527
498
  dataType: type,
528
499
  headers: Object.assign(Object.assign({}, headers), optionHeaders),
529
500
  });
530
- const contentType = nativeResponse.headers['Content-Type'] ||
531
- nativeResponse.headers['content-type'];
501
+ const contentType = nativeResponse.headers['Content-Type'] || nativeResponse.headers['content-type'];
532
502
  let data = (contentType === null || contentType === void 0 ? void 0 : contentType.startsWith('application/json'))
533
503
  ? JSON.stringify(nativeResponse.data)
534
504
  : nativeResponse.data;
@@ -570,8 +540,7 @@ var nativeBridge = (function (exports) {
570
540
  },
571
541
  });
572
542
  const prototype = win.CapacitorWebXMLHttpRequest.prototype;
573
- const isProgressEventAvailable = () => typeof ProgressEvent !== 'undefined' &&
574
- ProgressEvent.prototype instanceof Event;
543
+ const isProgressEventAvailable = () => typeof ProgressEvent !== 'undefined' && ProgressEvent.prototype instanceof Event;
575
544
  // XHR patch abort
576
545
  prototype.abort = function () {
577
546
  if (isRelativeOrProxyUrl(this._url)) {
@@ -652,9 +621,7 @@ var nativeBridge = (function (exports) {
652
621
  },
653
622
  });
654
623
  convertBody(body).then(({ data, type, headers }) => {
655
- const otherHeaders = this._headers != null && Object.keys(this._headers).length > 0
656
- ? this._headers
657
- : undefined;
624
+ const otherHeaders = this._headers != null && Object.keys(this._headers).length > 0 ? this._headers : undefined;
658
625
  // intercept request & pass to the bridge
659
626
  cap
660
627
  .nativePromise('CapacitorHttp', 'request', {
@@ -678,8 +645,7 @@ var nativeBridge = (function (exports) {
678
645
  }
679
646
  this._headers = nativeResponse.headers;
680
647
  this.status = nativeResponse.status;
681
- if (this.responseType === '' ||
682
- this.responseType === 'text') {
648
+ if (this.responseType === '' || this.responseType === 'text') {
683
649
  this.response =
684
650
  typeof nativeResponse.data !== 'string'
685
651
  ? JSON.stringify(nativeResponse.data)
@@ -688,8 +654,7 @@ var nativeBridge = (function (exports) {
688
654
  else {
689
655
  this.response = nativeResponse.data;
690
656
  }
691
- this.responseText = ((_a = (nativeResponse.headers['Content-Type'] ||
692
- nativeResponse.headers['content-type'])) === null || _a === void 0 ? void 0 : _a.startsWith('application/json'))
657
+ this.responseText = ((_a = (nativeResponse.headers['Content-Type'] || nativeResponse.headers['content-type'])) === null || _a === void 0 ? void 0 : _a.startsWith('application/json'))
693
658
  ? JSON.stringify(nativeResponse.data)
694
659
  : nativeResponse.data;
695
660
  this.responseURL = nativeResponse.url;
@@ -805,7 +770,7 @@ var nativeBridge = (function (exports) {
805
770
  };
806
771
  cap.logToNative = createLogToNative(win.console);
807
772
  cap.logFromNative = createLogFromNative(win.console);
808
- cap.handleError = err => win.console.error(err);
773
+ cap.handleError = (err) => win.console.error(err);
809
774
  win.Capacitor = cap;
810
775
  };
811
776
  function initNativeBridge(win) {
@@ -814,7 +779,7 @@ var nativeBridge = (function (exports) {
814
779
  const callbacks = new Map();
815
780
  const webviewServerUrl = typeof win.WEBVIEW_SERVER_URL === 'string' ? win.WEBVIEW_SERVER_URL : '';
816
781
  cap.getServerUrl = () => webviewServerUrl;
817
- cap.convertFileSrc = filePath => convertFileSrcServerUrl(webviewServerUrl, filePath);
782
+ cap.convertFileSrc = (filePath) => convertFileSrcServerUrl(webviewServerUrl, filePath);
818
783
  // Counter of callback ids, randomized to avoid
819
784
  // any issues during reloads if a call comes back with
820
785
  // an existing callback id from an old session
@@ -823,12 +788,12 @@ var nativeBridge = (function (exports) {
823
788
  const isNativePlatform = () => true;
824
789
  const getPlatform = () => getPlatformId(win);
825
790
  cap.getPlatform = getPlatform;
826
- cap.isPluginAvailable = name => Object.prototype.hasOwnProperty.call(cap.Plugins, name);
791
+ cap.isPluginAvailable = (name) => Object.prototype.hasOwnProperty.call(cap.Plugins, name);
827
792
  cap.isNativePlatform = isNativePlatform;
828
793
  // create the postToNative() fn if needed
829
794
  if (getPlatformId(win) === 'android') {
830
795
  // android platform
831
- postToNative = data => {
796
+ postToNative = (data) => {
832
797
  var _a;
833
798
  try {
834
799
  win.androidBridge.postMessage(JSON.stringify(data));
@@ -840,7 +805,7 @@ var nativeBridge = (function (exports) {
840
805
  }
841
806
  else if (getPlatformId(win) === 'ios') {
842
807
  // ios platform
843
- postToNative = data => {
808
+ postToNative = (data) => {
844
809
  var _a;
845
810
  try {
846
811
  data.type = data.type ? data.type : 'message';
@@ -885,8 +850,7 @@ var nativeBridge = (function (exports) {
885
850
  if (typeof postToNative === 'function') {
886
851
  let callbackId = '-1';
887
852
  if (storedCallback &&
888
- (typeof storedCallback.callback === 'function' ||
889
- typeof storedCallback.resolve === 'function')) {
853
+ (typeof storedCallback.callback === 'function' || typeof storedCallback.resolve === 'function')) {
890
854
  // store the call for later lookup
891
855
  callbackId = String(++callbackIdCount);
892
856
  callbacks.set(callbackId, storedCallback);
@@ -921,7 +885,7 @@ var nativeBridge = (function (exports) {
921
885
  /**
922
886
  * Process a response from the native layer.
923
887
  */
924
- cap.fromNative = result => {
888
+ cap.fromNative = (result) => {
925
889
  returnResult(result);
926
890
  };
927
891
  const returnResult = (result) => {
@@ -15,7 +15,11 @@ import android.os.Build;
15
15
  import android.os.Bundle;
16
16
  import android.os.Handler;
17
17
  import android.os.HandlerThread;
18
+ import android.webkit.ServiceWorkerClient;
19
+ import android.webkit.ServiceWorkerController;
18
20
  import android.webkit.ValueCallback;
21
+ import android.webkit.WebResourceRequest;
22
+ import android.webkit.WebResourceResponse;
19
23
  import android.webkit.WebSettings;
20
24
  import android.webkit.WebView;
21
25
  import androidx.activity.result.ActivityResultCallback;
@@ -274,6 +278,18 @@ public class Bridge {
274
278
  webView.setWebChromeClient(new BridgeWebChromeClient(this));
275
279
  webView.setWebViewClient(this.webViewClient);
276
280
 
281
+ if (Build.VERSION.SDK_INT >= 24 && config.isResolveServiceWorkerRequests()) {
282
+ ServiceWorkerController swController = ServiceWorkerController.getInstance();
283
+ swController.setServiceWorkerClient(
284
+ new ServiceWorkerClient() {
285
+ @Override
286
+ public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {
287
+ return getLocalServer().shouldInterceptRequest(request);
288
+ }
289
+ }
290
+ );
291
+ }
292
+
277
293
  if (!isDeployDisabled() && !isNewBinary()) {
278
294
  SharedPreferences prefs = getContext()
279
295
  .getSharedPreferences(com.getcapacitor.plugin.WebView.WEBVIEW_PREFS_NAME, Activity.MODE_PRIVATE);
@@ -53,6 +53,7 @@ public class CapConfig {
53
53
  private int minHuaweiWebViewVersion = DEFAULT_HUAWEI_WEBVIEW_VERSION;
54
54
  private String errorPath;
55
55
  private boolean zoomableWebView = false;
56
+ private boolean resolveServiceWorkerRequests = true;
56
57
 
57
58
  // Embedded
58
59
  private String startPath;
@@ -179,6 +180,7 @@ public class CapConfig {
179
180
  this.minHuaweiWebViewVersion = builder.minHuaweiWebViewVersion;
180
181
  this.errorPath = builder.errorPath;
181
182
  this.zoomableWebView = builder.zoomableWebView;
183
+ this.resolveServiceWorkerRequests = builder.resolveServiceWorkerRequests;
182
184
 
183
185
  // Embedded
184
186
  this.startPath = builder.startPath;
@@ -282,6 +284,7 @@ public class CapConfig {
282
284
  useLegacyBridge = JSONUtils.getBoolean(configJSON, "android.useLegacyBridge", useLegacyBridge);
283
285
  webContentsDebuggingEnabled = JSONUtils.getBoolean(configJSON, "android.webContentsDebuggingEnabled", isDebug);
284
286
  zoomableWebView = JSONUtils.getBoolean(configJSON, "android.zoomEnabled", JSONUtils.getBoolean(configJSON, "zoomEnabled", false));
287
+ resolveServiceWorkerRequests = JSONUtils.getBoolean(configJSON, "android.resolveServiceWorkerRequests", true);
285
288
 
286
289
  String logBehavior = JSONUtils.getString(
287
290
  configJSON,
@@ -299,7 +302,11 @@ public class CapConfig {
299
302
  loggingEnabled = isDebug;
300
303
  }
301
304
 
302
- initialFocus = JSONUtils.getBoolean(configJSON, "android.initialFocus", initialFocus);
305
+ initialFocus = JSONUtils.getBoolean(
306
+ configJSON,
307
+ "android.initialFocus",
308
+ JSONUtils.getBoolean(configJSON, "initialFocus", initialFocus)
309
+ );
303
310
 
304
311
  // Plugins
305
312
  pluginsConfiguration = deserializePluginsConfig(JSONUtils.getObject(configJSON, "plugins"));
@@ -370,6 +377,10 @@ public class CapConfig {
370
377
  return captureInput;
371
378
  }
372
379
 
380
+ public boolean isResolveServiceWorkerRequests() {
381
+ return resolveServiceWorkerRequests;
382
+ }
383
+
373
384
  public boolean isWebContentsDebuggingEnabled() {
374
385
  return webContentsDebuggingEnabled;
375
386
  }
@@ -569,6 +580,7 @@ public class CapConfig {
569
580
  private int minWebViewVersion = DEFAULT_ANDROID_WEBVIEW_VERSION;
570
581
  private int minHuaweiWebViewVersion = DEFAULT_HUAWEI_WEBVIEW_VERSION;
571
582
  private boolean zoomableWebView = false;
583
+ private boolean resolveServiceWorkerRequests = true;
572
584
 
573
585
  // Embedded
574
586
  private String startPath = null;
@@ -668,6 +680,11 @@ public class CapConfig {
668
680
  return this;
669
681
  }
670
682
 
683
+ public Builder setResolveServiceWorkerRequests(boolean resolveServiceWorkerRequests) {
684
+ this.resolveServiceWorkerRequests = resolveServiceWorkerRequests;
685
+ return this;
686
+ }
687
+
671
688
  public Builder setWebContentsDebuggingEnabled(boolean webContentsDebuggingEnabled) {
672
689
  this.webContentsDebuggingEnabled = webContentsDebuggingEnabled;
673
690
  return this;
@@ -143,7 +143,7 @@ public class UriMatcher {
143
143
  int lj = list.size();
144
144
  for (int j = 0; j < lj; j++) {
145
145
  UriMatcher n = list.get(j);
146
- which_switch:switch (n.mWhich) {
146
+ which_switch: switch (n.mWhich) {
147
147
  case MASK:
148
148
  if (HostMask.Parser.parse(n.mText).matches(u)) {
149
149
  node = n;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/android",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-beta.0",
4
4
  "description": "Capacitor: Cross-platform apps with JavaScript and the web",
5
5
  "homepage": "https://capacitorjs.com",
6
6
  "author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
@@ -23,7 +23,7 @@
23
23
  "verify": "./gradlew clean lint build test -b capacitor/build.gradle"
24
24
  },
25
25
  "peerDependencies": {
26
- "@capacitor/core": "^7.0.0-alpha.1"
26
+ "@capacitor/core": "^7.0.0-beta.0"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"
@@ -1,133 +0,0 @@
1
- package com.getcapacitor;
2
-
3
- import android.content.Context;
4
- import android.content.res.TypedArray;
5
- import android.os.Bundle;
6
- import android.util.AttributeSet;
7
- import android.view.LayoutInflater;
8
- import android.view.View;
9
- import android.view.ViewGroup;
10
- import androidx.fragment.app.Fragment;
11
- import com.getcapacitor.android.R;
12
- import java.util.ArrayList;
13
- import java.util.List;
14
-
15
- /**
16
- * A simple {@link Fragment} subclass.
17
- * Use the {@link BridgeFragment#newInstance} factory method to
18
- * create an instance of this fragment.
19
- */
20
- public class BridgeFragment extends Fragment {
21
-
22
- private static final String ARG_START_DIR = "startDir";
23
-
24
- protected Bridge bridge;
25
- protected boolean keepRunning = true;
26
-
27
- private final List<Class<? extends Plugin>> initialPlugins = new ArrayList<>();
28
- private CapConfig config = null;
29
-
30
- private final List<WebViewListener> webViewListeners = new ArrayList<>();
31
-
32
- public BridgeFragment() {
33
- // Required empty public constructor
34
- }
35
-
36
- /**
37
- * Use this factory method to create a new instance of
38
- * this fragment using the provided parameters.
39
- *
40
- * @param startDir the directory to serve content from
41
- * @return A new instance of fragment BridgeFragment.
42
- */
43
- public static BridgeFragment newInstance(String startDir) {
44
- BridgeFragment fragment = new BridgeFragment();
45
- Bundle args = new Bundle();
46
- args.putString(ARG_START_DIR, startDir);
47
- fragment.setArguments(args);
48
- return fragment;
49
- }
50
-
51
- public void addPlugin(Class<? extends Plugin> plugin) {
52
- this.initialPlugins.add(plugin);
53
- }
54
-
55
- public void setConfig(CapConfig config) {
56
- this.config = config;
57
- }
58
-
59
- public Bridge getBridge() {
60
- return bridge;
61
- }
62
-
63
- public void addWebViewListener(WebViewListener webViewListener) {
64
- webViewListeners.add(webViewListener);
65
- }
66
-
67
- /**
68
- * Load the WebView and create the Bridge
69
- */
70
- protected void load(Bundle savedInstanceState) {
71
- Logger.debug("Loading Bridge with BridgeFragment");
72
-
73
- Bundle args = getArguments();
74
- String startDir = null;
75
-
76
- if (args != null) {
77
- startDir = getArguments().getString(ARG_START_DIR);
78
- }
79
-
80
- bridge = new Bridge.Builder(this)
81
- .setInstanceState(savedInstanceState)
82
- .setPlugins(initialPlugins)
83
- .setConfig(config)
84
- .addWebViewListeners(webViewListeners)
85
- .create();
86
-
87
- if (startDir != null) {
88
- bridge.setServerAssetPath(startDir);
89
- }
90
-
91
- this.keepRunning = bridge.shouldKeepRunning();
92
- }
93
-
94
- @Override
95
- public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) {
96
- super.onInflate(context, attrs, savedInstanceState);
97
-
98
- TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.bridge_fragment);
99
- CharSequence c = a.getString(R.styleable.bridge_fragment_start_dir);
100
-
101
- if (c != null) {
102
- String startDir = c.toString();
103
- Bundle args = new Bundle();
104
- args.putString(ARG_START_DIR, startDir);
105
- setArguments(args);
106
- }
107
- }
108
-
109
- @Override
110
- public void onCreate(Bundle savedInstanceState) {
111
- super.onCreate(savedInstanceState);
112
- }
113
-
114
- @Override
115
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
116
- // Inflate the layout for this fragment
117
- return inflater.inflate(R.layout.fragment_bridge, container, false);
118
- }
119
-
120
- @Override
121
- public void onViewCreated(View view, Bundle savedInstanceState) {
122
- super.onViewCreated(view, savedInstanceState);
123
- this.load(savedInstanceState);
124
- }
125
-
126
- @Override
127
- public void onDestroy() {
128
- super.onDestroy();
129
- if (this.bridge != null) {
130
- this.bridge.onDestroy();
131
- }
132
- }
133
- }
@@ -1,13 +0,0 @@
1
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
- xmlns:tools="http://schemas.android.com/tools"
3
- android:layout_width="match_parent"
4
- android:layout_height="match_parent"
5
- android:background="#F0FF1414"
6
- tools:context="com.getcapacitor.BridgeFragment">
7
-
8
- <com.getcapacitor.CapacitorWebView
9
- android:id="@+id/webview"
10
- android:layout_width="fill_parent"
11
- android:layout_height="fill_parent" />
12
-
13
- </FrameLayout>
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <resources>
3
- <declare-styleable name="bridge_fragment">
4
- <attr name="start_dir" format="string"/>
5
- </declare-styleable>
6
- </resources>