@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,166 @@
1
+ package com.getcapacitor.util;
2
+
3
+ import org.json.JSONArray;
4
+ import org.json.JSONException;
5
+ import org.json.JSONObject;
6
+
7
+ /**
8
+ * Helper methods for parsing JSON objects.
9
+ */
10
+ public class JSONUtils {
11
+
12
+ /**
13
+ * Get a string value from the given JSON object.
14
+ *
15
+ * @param jsonObject A JSON object to search
16
+ * @param key A key to fetch from the JSON object
17
+ * @param defaultValue A default value to return if the key cannot be found
18
+ * @return The value at the given key in the JSON object, or the default value
19
+ */
20
+ public static String getString(JSONObject jsonObject, String key, String defaultValue) {
21
+ String k = getDeepestKey(key);
22
+ try {
23
+ JSONObject o = getDeepestObject(jsonObject, key);
24
+
25
+ String value = o.getString(k);
26
+ if (value == null) {
27
+ return defaultValue;
28
+ }
29
+ return value;
30
+ } catch (JSONException ignore) {
31
+ // value was not found
32
+ }
33
+
34
+ return defaultValue;
35
+ }
36
+
37
+ /**
38
+ * Get a boolean value from the given JSON object.
39
+ *
40
+ * @param jsonObject A JSON object to search
41
+ * @param key A key to fetch from the JSON object
42
+ * @param defaultValue A default value to return if the key cannot be found
43
+ * @return The value at the given key in the JSON object, or the default value
44
+ */
45
+ public static boolean getBoolean(JSONObject jsonObject, String key, boolean defaultValue) {
46
+ String k = getDeepestKey(key);
47
+ try {
48
+ JSONObject o = getDeepestObject(jsonObject, key);
49
+
50
+ return o.getBoolean(k);
51
+ } catch (JSONException ignore) {
52
+ // value was not found
53
+ }
54
+
55
+ return defaultValue;
56
+ }
57
+
58
+ /**
59
+ * Get an int value from the given JSON object.
60
+ *
61
+ * @param jsonObject A JSON object to search
62
+ * @param key A key to fetch from the JSON object
63
+ * @param defaultValue A default value to return if the key cannot be found
64
+ * @return The value at the given key in the JSON object, or the default value
65
+ */
66
+ public static int getInt(JSONObject jsonObject, String key, int defaultValue) {
67
+ String k = getDeepestKey(key);
68
+ try {
69
+ JSONObject o = getDeepestObject(jsonObject, key);
70
+ return o.getInt(k);
71
+ } catch (JSONException ignore) {
72
+ // value was not found
73
+ }
74
+
75
+ return defaultValue;
76
+ }
77
+
78
+ /**
79
+ * Get a JSON object 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
+ * @return The value from the config, if exists. Null if not
84
+ */
85
+ public static JSONObject getObject(JSONObject jsonObject, String key) {
86
+ String k = getDeepestKey(key);
87
+ try {
88
+ JSONObject o = getDeepestObject(jsonObject, key);
89
+
90
+ return o.getJSONObject(k);
91
+ } catch (JSONException ignore) {
92
+ // value was not found
93
+ }
94
+
95
+ return null;
96
+ }
97
+
98
+ /**
99
+ * Get a string array value from the given JSON object.
100
+ *
101
+ * @param jsonObject A JSON object to search
102
+ * @param key A key to fetch from the JSON object
103
+ * @param defaultValue A default value to return if the key cannot be found
104
+ * @return The value at the given key in the JSON object, or the default value
105
+ */
106
+ public static String[] getArray(JSONObject jsonObject, String key, String[] defaultValue) {
107
+ String k = getDeepestKey(key);
108
+ try {
109
+ JSONObject o = getDeepestObject(jsonObject, key);
110
+
111
+ JSONArray a = o.getJSONArray(k);
112
+ if (a == null) {
113
+ return defaultValue;
114
+ }
115
+
116
+ int l = a.length();
117
+ String[] value = new String[l];
118
+
119
+ for (int i = 0; i < l; i++) {
120
+ value[i] = (String) a.get(i);
121
+ }
122
+
123
+ return value;
124
+ } catch (JSONException ignore) {
125
+ // value was not found
126
+ }
127
+
128
+ return defaultValue;
129
+ }
130
+
131
+ /**
132
+ * Given a JSON key path, gets the deepest key.
133
+ *
134
+ * @param key The key path
135
+ * @return The deepest key
136
+ */
137
+ private static String getDeepestKey(String key) {
138
+ String[] parts = key.split("\\.");
139
+ if (parts.length > 0) {
140
+ return parts[parts.length - 1];
141
+ }
142
+
143
+ return null;
144
+ }
145
+
146
+ /**
147
+ * Given a JSON object and key path, gets the deepest object in the path.
148
+ *
149
+ * @param jsonObject A JSON object
150
+ * @param key The key path to follow
151
+ * @return The deepest object along the key path
152
+ * @throws JSONException Thrown if any JSON errors
153
+ */
154
+ private static JSONObject getDeepestObject(JSONObject jsonObject, String key) throws JSONException {
155
+ String[] parts = key.split("\\.");
156
+ JSONObject o = jsonObject;
157
+
158
+ // Search until the second to last part of the key
159
+ for (int i = 0; i < parts.length - 1; i++) {
160
+ String k = parts[i];
161
+ o = o.getJSONObject(k);
162
+ }
163
+
164
+ return o;
165
+ }
166
+ }
@@ -0,0 +1,114 @@
1
+ package com.getcapacitor.util;
2
+
3
+ import android.content.Context;
4
+ import android.content.pm.PackageInfo;
5
+ import android.content.pm.PackageManager;
6
+ import androidx.core.app.ActivityCompat;
7
+ import java.util.ArrayList;
8
+ import java.util.Arrays;
9
+ import java.util.List;
10
+
11
+ /**
12
+ * A helper class for checking permissions.
13
+ *
14
+ * @since 3.0.0
15
+ */
16
+ public class PermissionHelper {
17
+
18
+ /**
19
+ * Checks if a list of given permissions are all granted by the user
20
+ *
21
+ * @since 3.0.0
22
+ * @param permissions Permissions to check.
23
+ * @return True if all permissions are granted, false if at least one is not.
24
+ */
25
+ public static boolean hasPermissions(Context context, String[] permissions) {
26
+ for (String perm : permissions) {
27
+ if (ActivityCompat.checkSelfPermission(context, perm) != PackageManager.PERMISSION_GRANTED) {
28
+ return false;
29
+ }
30
+ }
31
+ return true;
32
+ }
33
+
34
+ /**
35
+ * Check whether the given permission has been defined in the AndroidManifest.xml
36
+ *
37
+ * @since 3.0.0
38
+ * @param permission A permission to check.
39
+ * @return True if the permission has been defined in the Manifest, false if not.
40
+ */
41
+ public static boolean hasDefinedPermission(Context context, String permission) {
42
+ boolean hasPermission = false;
43
+ String[] requestedPermissions = PermissionHelper.getManifestPermissions(context);
44
+ if (requestedPermissions != null && requestedPermissions.length > 0) {
45
+ List<String> requestedPermissionsList = Arrays.asList(requestedPermissions);
46
+ ArrayList<String> requestedPermissionsArrayList = new ArrayList<>(requestedPermissionsList);
47
+ if (requestedPermissionsArrayList.contains(permission)) {
48
+ hasPermission = true;
49
+ }
50
+ }
51
+ return hasPermission;
52
+ }
53
+
54
+ /**
55
+ * Check whether all of the given permissions have been defined in the AndroidManifest.xml
56
+ * @param context the app context
57
+ * @param permissions a list of permissions
58
+ * @return true only if all permissions are defined in the AndroidManifest.xml
59
+ */
60
+ public static boolean hasDefinedPermissions(Context context, String[] permissions) {
61
+ for (String permission : permissions) {
62
+ if (!PermissionHelper.hasDefinedPermission(context, permission)) {
63
+ return false;
64
+ }
65
+ }
66
+
67
+ return true;
68
+ }
69
+
70
+ /**
71
+ * Get the permissions defined in AndroidManifest.xml
72
+ *
73
+ * @since 3.0.0
74
+ * @return The permissions defined in AndroidManifest.xml
75
+ */
76
+ public static String[] getManifestPermissions(Context context) {
77
+ String[] requestedPermissions = null;
78
+ try {
79
+ PackageManager pm = context.getPackageManager();
80
+ PackageInfo packageInfo = InternalUtils.getPackageInfo(pm, context.getPackageName(), PackageManager.GET_PERMISSIONS);
81
+
82
+ if (packageInfo != null) {
83
+ requestedPermissions = packageInfo.requestedPermissions;
84
+ }
85
+ } catch (Exception ex) {}
86
+ return requestedPermissions;
87
+ }
88
+
89
+ /**
90
+ * Given a list of permissions, return a new list with the ones not present in AndroidManifest.xml
91
+ *
92
+ * @since 3.0.0
93
+ * @param neededPermissions The permissions needed.
94
+ * @return The permissions not present in AndroidManifest.xml
95
+ */
96
+ public static String[] getUndefinedPermissions(Context context, String[] neededPermissions) {
97
+ ArrayList<String> undefinedPermissions = new ArrayList<>();
98
+ String[] requestedPermissions = getManifestPermissions(context);
99
+ if (requestedPermissions != null && requestedPermissions.length > 0) {
100
+ List<String> requestedPermissionsList = Arrays.asList(requestedPermissions);
101
+ ArrayList<String> requestedPermissionsArrayList = new ArrayList<>(requestedPermissionsList);
102
+ for (String permission : neededPermissions) {
103
+ if (!requestedPermissionsArrayList.contains(permission)) {
104
+ undefinedPermissions.add(permission);
105
+ }
106
+ }
107
+ String[] undefinedPermissionArray = new String[undefinedPermissions.size()];
108
+ undefinedPermissionArray = undefinedPermissions.toArray(undefinedPermissionArray);
109
+
110
+ return undefinedPermissionArray;
111
+ }
112
+ return neededPermissions;
113
+ }
114
+ }
@@ -0,0 +1,28 @@
1
+ package com.getcapacitor.util;
2
+
3
+ import android.graphics.Color;
4
+
5
+ public class WebColor {
6
+
7
+ /**
8
+ * Parse the color string, and return the corresponding color-int. If the string cannot be parsed, throws an IllegalArgumentException exception.
9
+ * @param colorString The hexadecimal color string. The format is an RGB or RGBA hex string.
10
+ * @return The corresponding color as an int.
11
+ */
12
+ public static int parseColor(String colorString) {
13
+ String formattedColor = colorString;
14
+ if (colorString.charAt(0) != '#') {
15
+ formattedColor = "#" + formattedColor;
16
+ }
17
+
18
+ if (formattedColor.length() != 7 && formattedColor.length() != 9) {
19
+ throw new IllegalArgumentException("The encoded color space is invalid or unknown");
20
+ } else if (formattedColor.length() == 7) {
21
+ return Color.parseColor(formattedColor);
22
+ } else {
23
+ // Convert to Android format #AARRGGBB from #RRGGBBAA
24
+ formattedColor = "#" + formattedColor.substring(7) + formattedColor.substring(1, 7);
25
+ return Color.parseColor(formattedColor);
26
+ }
27
+ }
28
+ }
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+ xmlns:app="http://schemas.android.com/apk/res-auto"
4
+ xmlns:tools="http://schemas.android.com/tools"
5
+ android:layout_width="match_parent"
6
+ android:layout_height="match_parent"
7
+ tools:context="com.getcapacitor.BridgeActivity"
8
+ >
9
+
10
+ <com.getcapacitor.CapacitorWebView
11
+ android:id="@+id/webview"
12
+ android:layout_width="fill_parent"
13
+ android:layout_height="fill_parent" />
14
+
15
+ </androidx.coordinatorlayout.widget.CoordinatorLayout>
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+ android:layout_width="match_parent"
4
+ android:layout_height="match_parent">
5
+
6
+ <TextView
7
+ android:id="@+id/textView"
8
+ android:layout_width="0dp"
9
+ android:layout_height="match_parent"
10
+ android:layout_weight="1"
11
+ android:text="@string/no_webview_text"
12
+ android:gravity="center"
13
+ android:textSize="48sp" />
14
+ </LinearLayout>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources xmlns:tools="http://schemas.android.com/tools">
3
+ <color tools:ignore="UnusedResources" name="colorPrimary">#3F51B5</color>
4
+ <color tools:ignore="UnusedResources" name="colorPrimaryDark">#303F9F</color>
5
+ <color tools:ignore="UnusedResources" name="colorAccent">#FF4081</color>
6
+ </resources>
@@ -0,0 +1,3 @@
1
+ <resources>
2
+ <string name="no_webview_text">This app requires a WebView to work</string>
3
+ </resources>
@@ -0,0 +1,6 @@
1
+ <resources>
2
+ <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.NoActionBar">
3
+ <item name="windowActionBar">false</item>
4
+ <item name="windowNoTitle">true</item>
5
+ </style>
6
+ </resources>
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@capacitor-plus/android",
3
+ "version": "8.0.0-beta.0",
4
+ "description": "Capacitor+: Enhanced Capacitor with automated upstream sync - Cross-platform apps with JavaScript and the web",
5
+ "homepage": "https://github.com/Cap-go/capacitor-plus",
6
+ "author": "Capgo Team <support@capgo.app> (https://capgo.app)",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Cap-go/capacitor-plus.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/Cap-go/capacitor-plus/issues"
14
+ },
15
+ "files": [
16
+ "capacitor/build.gradle",
17
+ "capacitor/lint-baseline.xml",
18
+ "capacitor/lint.xml",
19
+ "capacitor/proguard-rules.pro",
20
+ "capacitor/src/main/"
21
+ ],
22
+ "scripts": {
23
+ "verify": "./gradlew clean lint build test -b capacitor/build.gradle"
24
+ },
25
+ "peerDependencies": {
26
+ "@capacitor-plus/core": "^8.0.0-beta.0"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ }
31
+ }