@capacitor-plus/android 8.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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/capacitor/build.gradle +94 -0
  3. package/capacitor/lint-baseline.xml +136 -0
  4. package/capacitor/lint.xml +9 -0
  5. package/capacitor/proguard-rules.pro +28 -0
  6. package/capacitor/src/main/AndroidManifest.xml +3 -0
  7. package/capacitor/src/main/assets/native-bridge.js +1029 -0
  8. package/capacitor/src/main/java/com/getcapacitor/AndroidProtocolHandler.java +94 -0
  9. package/capacitor/src/main/java/com/getcapacitor/App.java +61 -0
  10. package/capacitor/src/main/java/com/getcapacitor/AppUUID.java +65 -0
  11. package/capacitor/src/main/java/com/getcapacitor/Bridge.java +1627 -0
  12. package/capacitor/src/main/java/com/getcapacitor/BridgeActivity.java +212 -0
  13. package/capacitor/src/main/java/com/getcapacitor/BridgeWebChromeClient.java +467 -0
  14. package/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java +105 -0
  15. package/capacitor/src/main/java/com/getcapacitor/CapConfig.java +709 -0
  16. package/capacitor/src/main/java/com/getcapacitor/CapacitorWebView.java +57 -0
  17. package/capacitor/src/main/java/com/getcapacitor/FileUtils.java +303 -0
  18. package/capacitor/src/main/java/com/getcapacitor/InvalidPluginException.java +8 -0
  19. package/capacitor/src/main/java/com/getcapacitor/InvalidPluginMethodException.java +16 -0
  20. package/capacitor/src/main/java/com/getcapacitor/JSArray.java +51 -0
  21. package/capacitor/src/main/java/com/getcapacitor/JSExport.java +208 -0
  22. package/capacitor/src/main/java/com/getcapacitor/JSExportException.java +16 -0
  23. package/capacitor/src/main/java/com/getcapacitor/JSInjector.java +127 -0
  24. package/capacitor/src/main/java/com/getcapacitor/JSObject.java +164 -0
  25. package/capacitor/src/main/java/com/getcapacitor/JSValue.java +65 -0
  26. package/capacitor/src/main/java/com/getcapacitor/Logger.java +103 -0
  27. package/capacitor/src/main/java/com/getcapacitor/MessageHandler.java +157 -0
  28. package/capacitor/src/main/java/com/getcapacitor/NativePlugin.java +37 -0
  29. package/capacitor/src/main/java/com/getcapacitor/PermissionState.java +31 -0
  30. package/capacitor/src/main/java/com/getcapacitor/Plugin.java +1050 -0
  31. package/capacitor/src/main/java/com/getcapacitor/PluginCall.java +394 -0
  32. package/capacitor/src/main/java/com/getcapacitor/PluginConfig.java +116 -0
  33. package/capacitor/src/main/java/com/getcapacitor/PluginHandle.java +160 -0
  34. package/capacitor/src/main/java/com/getcapacitor/PluginInvocationException.java +16 -0
  35. package/capacitor/src/main/java/com/getcapacitor/PluginLoadException.java +19 -0
  36. package/capacitor/src/main/java/com/getcapacitor/PluginManager.java +56 -0
  37. package/capacitor/src/main/java/com/getcapacitor/PluginMethod.java +15 -0
  38. package/capacitor/src/main/java/com/getcapacitor/PluginMethodHandle.java +33 -0
  39. package/capacitor/src/main/java/com/getcapacitor/PluginResult.java +84 -0
  40. package/capacitor/src/main/java/com/getcapacitor/ProcessedRoute.java +37 -0
  41. package/capacitor/src/main/java/com/getcapacitor/RouteProcessor.java +8 -0
  42. package/capacitor/src/main/java/com/getcapacitor/ServerPath.java +25 -0
  43. package/capacitor/src/main/java/com/getcapacitor/UriMatcher.java +184 -0
  44. package/capacitor/src/main/java/com/getcapacitor/WebViewListener.java +57 -0
  45. package/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java +758 -0
  46. package/capacitor/src/main/java/com/getcapacitor/annotation/ActivityCallback.java +10 -0
  47. package/capacitor/src/main/java/com/getcapacitor/annotation/CapacitorPlugin.java +35 -0
  48. package/capacitor/src/main/java/com/getcapacitor/annotation/Permission.java +22 -0
  49. package/capacitor/src/main/java/com/getcapacitor/annotation/PermissionCallback.java +10 -0
  50. package/capacitor/src/main/java/com/getcapacitor/cordova/CapacitorCordovaCookieManager.java +42 -0
  51. package/capacitor/src/main/java/com/getcapacitor/cordova/MockCordovaInterfaceImpl.java +39 -0
  52. package/capacitor/src/main/java/com/getcapacitor/cordova/MockCordovaWebViewImpl.java +282 -0
  53. package/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookieManager.java +239 -0
  54. package/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorCookies.java +119 -0
  55. package/capacitor/src/main/java/com/getcapacitor/plugin/CapacitorHttp.java +119 -0
  56. package/capacitor/src/main/java/com/getcapacitor/plugin/SystemBars.java +220 -0
  57. package/capacitor/src/main/java/com/getcapacitor/plugin/WebView.java +48 -0
  58. package/capacitor/src/main/java/com/getcapacitor/plugin/util/AssetUtil.java +358 -0
  59. package/capacitor/src/main/java/com/getcapacitor/plugin/util/CapacitorHttpUrlConnection.java +473 -0
  60. package/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java +465 -0
  61. package/capacitor/src/main/java/com/getcapacitor/plugin/util/ICapacitorHttpUrlConnection.java +15 -0
  62. package/capacitor/src/main/java/com/getcapacitor/plugin/util/MimeType.java +17 -0
  63. package/capacitor/src/main/java/com/getcapacitor/util/HostMask.java +123 -0
  64. package/capacitor/src/main/java/com/getcapacitor/util/InternalUtils.java +27 -0
  65. package/capacitor/src/main/java/com/getcapacitor/util/JSONUtils.java +166 -0
  66. package/capacitor/src/main/java/com/getcapacitor/util/PermissionHelper.java +114 -0
  67. package/capacitor/src/main/java/com/getcapacitor/util/WebColor.java +28 -0
  68. package/capacitor/src/main/res/layout/capacitor_bridge_layout_main.xml +15 -0
  69. package/capacitor/src/main/res/layout/no_webview.xml +14 -0
  70. package/capacitor/src/main/res/values/colors.xml +6 -0
  71. package/capacitor/src/main/res/values/strings.xml +3 -0
  72. package/capacitor/src/main/res/values/styles.xml +6 -0
  73. package/package.json +31 -0
@@ -0,0 +1,56 @@
1
+ package com.getcapacitor;
2
+
3
+ import android.content.res.AssetManager;
4
+ import java.io.BufferedReader;
5
+ import java.io.IOException;
6
+ import java.io.InputStreamReader;
7
+ import java.util.ArrayList;
8
+ import java.util.List;
9
+ import org.json.JSONArray;
10
+ import org.json.JSONException;
11
+ import org.json.JSONObject;
12
+
13
+ public class PluginManager {
14
+
15
+ private final AssetManager assetManager;
16
+
17
+ public PluginManager(AssetManager assetManager) {
18
+ this.assetManager = assetManager;
19
+ }
20
+
21
+ public List<Class<? extends Plugin>> loadPluginClasses() throws PluginLoadException {
22
+ JSONArray pluginsJSON = parsePluginsJSON();
23
+ ArrayList<Class<? extends Plugin>> pluginList = new ArrayList<>();
24
+
25
+ try {
26
+ for (int i = 0, size = pluginsJSON.length(); i < size; i++) {
27
+ JSONObject pluginJSON = pluginsJSON.getJSONObject(i);
28
+ String classPath = pluginJSON.getString("classpath");
29
+ Class<?> c = Class.forName(classPath);
30
+ pluginList.add(c.asSubclass(Plugin.class));
31
+ }
32
+ } catch (JSONException e) {
33
+ throw new PluginLoadException("Could not parse capacitor.plugins.json as JSON");
34
+ } catch (ClassNotFoundException e) {
35
+ throw new PluginLoadException("Could not find class by class path: " + e.getMessage());
36
+ }
37
+
38
+ return pluginList;
39
+ }
40
+
41
+ private JSONArray parsePluginsJSON() throws PluginLoadException {
42
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(assetManager.open("capacitor.plugins.json")))) {
43
+ StringBuilder builder = new StringBuilder();
44
+ String line;
45
+ while ((line = reader.readLine()) != null) {
46
+ builder.append(line);
47
+ }
48
+ String jsonString = builder.toString();
49
+ return new JSONArray(jsonString);
50
+ } catch (IOException e) {
51
+ throw new PluginLoadException("Could not load capacitor.plugins.json");
52
+ } catch (JSONException e) {
53
+ throw new PluginLoadException("Could not parse capacitor.plugins.json as JSON");
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,15 @@
1
+ package com.getcapacitor;
2
+
3
+ import java.lang.annotation.Retention;
4
+ import java.lang.annotation.RetentionPolicy;
5
+
6
+ @Retention(RetentionPolicy.RUNTIME)
7
+ public @interface PluginMethod {
8
+ String RETURN_PROMISE = "promise";
9
+
10
+ String RETURN_CALLBACK = "callback";
11
+
12
+ String RETURN_NONE = "none";
13
+
14
+ String returnType() default RETURN_PROMISE;
15
+ }
@@ -0,0 +1,33 @@
1
+ package com.getcapacitor;
2
+
3
+ import java.lang.reflect.Method;
4
+
5
+ public class PluginMethodHandle {
6
+
7
+ // The reflect method reference
8
+ private final Method method;
9
+ // The name of the method
10
+ private final String name;
11
+ // The return type of the method (see PluginMethod for constants)
12
+ private final String returnType;
13
+
14
+ public PluginMethodHandle(Method method, PluginMethod methodDecorator) {
15
+ this.method = method;
16
+
17
+ this.name = method.getName();
18
+
19
+ this.returnType = methodDecorator.returnType();
20
+ }
21
+
22
+ public String getReturnType() {
23
+ return returnType;
24
+ }
25
+
26
+ public String getName() {
27
+ return name;
28
+ }
29
+
30
+ public Method getMethod() {
31
+ return method;
32
+ }
33
+ }
@@ -0,0 +1,84 @@
1
+ package com.getcapacitor;
2
+
3
+ import java.text.DateFormat;
4
+ import java.text.SimpleDateFormat;
5
+ import java.util.Date;
6
+ import java.util.TimeZone;
7
+
8
+ /**
9
+ * Wraps a result for web from calling a native plugin.
10
+ */
11
+ public class PluginResult {
12
+
13
+ private final JSObject json;
14
+
15
+ public PluginResult() {
16
+ this(new JSObject());
17
+ }
18
+
19
+ public PluginResult(JSObject json) {
20
+ this.json = json;
21
+ }
22
+
23
+ public PluginResult put(String name, boolean value) {
24
+ return this.jsonPut(name, value);
25
+ }
26
+
27
+ public PluginResult put(String name, double value) {
28
+ return this.jsonPut(name, value);
29
+ }
30
+
31
+ public PluginResult put(String name, int value) {
32
+ return this.jsonPut(name, value);
33
+ }
34
+
35
+ public PluginResult put(String name, long value) {
36
+ return this.jsonPut(name, value);
37
+ }
38
+
39
+ /**
40
+ * Format a date as an ISO string
41
+ */
42
+ public PluginResult put(String name, Date value) {
43
+ TimeZone tz = TimeZone.getTimeZone("UTC");
44
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
45
+ df.setTimeZone(tz);
46
+ return this.jsonPut(name, df.format(value));
47
+ }
48
+
49
+ public PluginResult put(String name, Object value) {
50
+ return this.jsonPut(name, value);
51
+ }
52
+
53
+ public PluginResult put(String name, PluginResult value) {
54
+ return this.jsonPut(name, value.json);
55
+ }
56
+
57
+ PluginResult jsonPut(String name, Object value) {
58
+ try {
59
+ this.json.put(name, value);
60
+ } catch (Exception ex) {
61
+ Logger.error(Logger.tags("Plugin"), "", ex);
62
+ }
63
+ return this;
64
+ }
65
+
66
+ public String toString() {
67
+ return this.json.toString();
68
+ }
69
+
70
+ /**
71
+ * Return plugin metadata and information about the result, if it succeeded the data, or error information if it didn't.
72
+ * This is used for appRestoredResult, as it's technically a raw data response from a plugin.
73
+ * @return the raw data response from the plugin.
74
+ */
75
+ public JSObject getWrappedResult() {
76
+ JSObject ret = new JSObject();
77
+ ret.put("pluginId", this.json.getString("pluginId"));
78
+ ret.put("methodName", this.json.getString("methodName"));
79
+ ret.put("success", this.json.getBoolean("success", false));
80
+ ret.put("data", this.json.getJSObject("data"));
81
+ ret.put("error", this.json.getJSObject("error"));
82
+ return ret;
83
+ }
84
+ }
@@ -0,0 +1,37 @@
1
+ package com.getcapacitor;
2
+
3
+ /**
4
+ * An data class used in conjunction with RouteProcessor.
5
+ *
6
+ * @see com.getcapacitor.RouteProcessor
7
+ */
8
+ public class ProcessedRoute {
9
+
10
+ private String path;
11
+ private boolean isAsset;
12
+ private boolean ignoreAssetPath;
13
+
14
+ public String getPath() {
15
+ return path;
16
+ }
17
+
18
+ public void setPath(String path) {
19
+ this.path = path;
20
+ }
21
+
22
+ public boolean isAsset() {
23
+ return isAsset;
24
+ }
25
+
26
+ public void setAsset(boolean asset) {
27
+ isAsset = asset;
28
+ }
29
+
30
+ public boolean isIgnoreAssetPath() {
31
+ return ignoreAssetPath;
32
+ }
33
+
34
+ public void setIgnoreAssetPath(boolean ignoreAssetPath) {
35
+ this.ignoreAssetPath = ignoreAssetPath;
36
+ }
37
+ }
@@ -0,0 +1,8 @@
1
+ package com.getcapacitor;
2
+
3
+ /**
4
+ * An interface used in the processing of routes
5
+ */
6
+ public interface RouteProcessor {
7
+ ProcessedRoute process(String basePath, String path);
8
+ }
@@ -0,0 +1,25 @@
1
+ package com.getcapacitor;
2
+
3
+ public class ServerPath {
4
+
5
+ public enum PathType {
6
+ BASE_PATH,
7
+ ASSET_PATH
8
+ }
9
+
10
+ private final PathType type;
11
+ private final String path;
12
+
13
+ public ServerPath(PathType type, String path) {
14
+ this.type = type;
15
+ this.path = path;
16
+ }
17
+
18
+ public PathType getType() {
19
+ return type;
20
+ }
21
+
22
+ public String getPath() {
23
+ return path;
24
+ }
25
+ }
@@ -0,0 +1,184 @@
1
+ /*
2
+ * Copyright (C) 2006 The Android Open Source Project
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ //package com.google.webviewlocalserver.third_party.android;
17
+ package com.getcapacitor;
18
+
19
+ import android.net.Uri;
20
+ import com.getcapacitor.util.HostMask;
21
+ import java.util.ArrayList;
22
+ import java.util.List;
23
+ import java.util.regex.Pattern;
24
+
25
+ public class UriMatcher {
26
+
27
+ /**
28
+ * Creates the root node of the URI tree.
29
+ *
30
+ * @param code the code to match for the root URI
31
+ */
32
+ public UriMatcher(Object code) {
33
+ mCode = code;
34
+ mWhich = -1;
35
+ mChildren = new ArrayList<>();
36
+ mText = null;
37
+ }
38
+
39
+ private UriMatcher() {
40
+ mCode = null;
41
+ mWhich = -1;
42
+ mChildren = new ArrayList<>();
43
+ mText = null;
44
+ }
45
+
46
+ /**
47
+ * Add a URI to match, and the code to return when this URI is
48
+ * matched. URI nodes may be exact match string, the token "*"
49
+ * that matches any text, or the token "#" that matches only
50
+ * numbers.
51
+ * <p>
52
+ * Starting from API level {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2},
53
+ * this method will accept a leading slash in the path.
54
+ *
55
+ * @param authority the authority to match
56
+ * @param path the path to match. * may be used as a wild card for
57
+ * any text, and # may be used as a wild card for numbers.
58
+ * @param code the code that is returned when a URI is matched
59
+ * against the given components. Must be positive.
60
+ */
61
+ public void addURI(String scheme, String authority, String path, Object code) {
62
+ if (code == null) {
63
+ throw new IllegalArgumentException("Code can't be null");
64
+ }
65
+
66
+ String[] tokens = null;
67
+ if (path != null) {
68
+ String newPath = path;
69
+ // Strip leading slash if present.
70
+ if (!path.isEmpty() && path.charAt(0) == '/') {
71
+ newPath = path.substring(1);
72
+ }
73
+ tokens = PATH_SPLIT_PATTERN.split(newPath);
74
+ }
75
+
76
+ int numTokens = tokens != null ? tokens.length : 0;
77
+ UriMatcher node = this;
78
+ for (int i = -2; i < numTokens; i++) {
79
+ String token;
80
+ if (i == -2) token = scheme;
81
+ else if (i == -1) token = authority;
82
+ else token = tokens[i];
83
+ ArrayList<UriMatcher> children = node.mChildren;
84
+ int numChildren = children.size();
85
+ UriMatcher child;
86
+ int j;
87
+ for (j = 0; j < numChildren; j++) {
88
+ child = children.get(j);
89
+ if (token.equals(child.mText)) {
90
+ node = child;
91
+ break;
92
+ }
93
+ }
94
+ if (j == numChildren) {
95
+ // Child not found, create it
96
+ child = new UriMatcher();
97
+ if (i == -1 && token.contains("*")) {
98
+ child.mWhich = MASK;
99
+ } else if (token.equals("**")) {
100
+ child.mWhich = REST;
101
+ } else if (token.equals("*")) {
102
+ child.mWhich = TEXT;
103
+ } else {
104
+ child.mWhich = EXACT;
105
+ }
106
+ child.mText = token;
107
+ node.mChildren.add(child);
108
+ node = child;
109
+ }
110
+ }
111
+ node.mCode = code;
112
+ }
113
+
114
+ static final Pattern PATH_SPLIT_PATTERN = Pattern.compile("/");
115
+
116
+ /**
117
+ * Try to match against the path in a url.
118
+ *
119
+ * @param uri The url whose path we will match against.
120
+ * @return The code for the matched node (added using addURI),
121
+ * or null if there is no matched node.
122
+ */
123
+ public Object match(Uri uri) {
124
+ final List<String> pathSegments = uri.getPathSegments();
125
+ final int li = pathSegments.size();
126
+
127
+ UriMatcher node = this;
128
+
129
+ if (li == 0 && uri.getAuthority() == null) {
130
+ return this.mCode;
131
+ }
132
+
133
+ for (int i = -2; i < li; i++) {
134
+ String u;
135
+ if (i == -2) u = uri.getScheme();
136
+ else if (i == -1) u = uri.getAuthority();
137
+ else u = pathSegments.get(i);
138
+ ArrayList<UriMatcher> list = node.mChildren;
139
+ if (list == null) {
140
+ break;
141
+ }
142
+ node = null;
143
+ int lj = list.size();
144
+ for (int j = 0; j < lj; j++) {
145
+ UriMatcher n = list.get(j);
146
+ which_switch: switch (n.mWhich) {
147
+ case MASK:
148
+ if (HostMask.Parser.parse(n.mText).matches(u)) {
149
+ node = n;
150
+ }
151
+ break;
152
+ case EXACT:
153
+ if (n.mText.equals(u)) {
154
+ node = n;
155
+ }
156
+ break;
157
+ case TEXT:
158
+ node = n;
159
+ break;
160
+ case REST:
161
+ return n.mCode;
162
+ }
163
+ if (node != null) {
164
+ break;
165
+ }
166
+ }
167
+ if (node == null) {
168
+ return null;
169
+ }
170
+ }
171
+
172
+ return node.mCode;
173
+ }
174
+
175
+ private static final int EXACT = 0;
176
+ private static final int TEXT = 1;
177
+ private static final int REST = 2;
178
+ private static final int MASK = 3;
179
+
180
+ private Object mCode;
181
+ private int mWhich;
182
+ private String mText;
183
+ private ArrayList<UriMatcher> mChildren;
184
+ }
@@ -0,0 +1,57 @@
1
+ package com.getcapacitor;
2
+
3
+ import android.webkit.RenderProcessGoneDetail;
4
+ import android.webkit.WebView;
5
+
6
+ /**
7
+ * Provides callbacks associated with the {@link BridgeWebViewClient}
8
+ */
9
+ public abstract class WebViewListener {
10
+
11
+ /**
12
+ * Callback for page load event.
13
+ *
14
+ * @param webView The WebView that loaded
15
+ */
16
+ public void onPageLoaded(WebView webView) {
17
+ // Override me to add behavior to the page loaded event
18
+ }
19
+
20
+ /**
21
+ * Callback for onReceivedError event.
22
+ *
23
+ * @param webView The WebView that loaded
24
+ */
25
+ public void onReceivedError(WebView webView) {
26
+ // Override me to add behavior to handle the onReceivedError event
27
+ }
28
+
29
+ /**
30
+ * Callback for onReceivedHttpError event.
31
+ *
32
+ * @param webView The WebView that loaded
33
+ */
34
+ public void onReceivedHttpError(WebView webView) {
35
+ // Override me to add behavior to handle the onReceivedHttpError event
36
+ }
37
+
38
+ /**
39
+ * Callback for page start event.
40
+ *
41
+ * @param webView The WebView that loaded
42
+ */
43
+ public void onPageStarted(WebView webView) {
44
+ // Override me to add behavior to the page started event
45
+ }
46
+
47
+ /**
48
+ * Callback for render process gone event. Return true if the state is handled.
49
+ *
50
+ * @param webView The WebView that loaded
51
+ * @return returns false by default if the listener is not overridden and used
52
+ */
53
+ public boolean onRenderProcessGone(WebView webView, RenderProcessGoneDetail detail) {
54
+ // Override me to add behavior to the web view render process gone event
55
+ return false;
56
+ }
57
+ }