@aigens/aigens-sdk-core 0.0.1 → 0.0.5

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.
@@ -3,7 +3,7 @@ require 'json'
3
3
  package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
4
 
5
5
  Pod::Spec.new do |s|
6
- s.name = 'CapacitorCommunityAigensCore'
6
+ s.name = 'AigensAigensSdkCore'
7
7
  s.version = package['version']
8
8
  s.summary = package['description']
9
9
  s.license = package['license']
package/README.md CHANGED
@@ -15,7 +15,9 @@ npx cap sync
15
15
 
16
16
  * [`echo(...)`](#echo)
17
17
  * [`finish(...)`](#finish)
18
+ * [`getMember(...)`](#getmember)
18
19
  * [`openBrowser(...)`](#openbrowser)
20
+ * [`scan(...)`](#scan)
19
21
 
20
22
  </docgen-index>
21
23
 
@@ -52,6 +54,21 @@ finish(options: any) => Promise<any>
52
54
  --------------------
53
55
 
54
56
 
57
+ ### getMember(...)
58
+
59
+ ```typescript
60
+ getMember(options: any) => Promise<any>
61
+ ```
62
+
63
+ | Param | Type |
64
+ | ------------- | ---------------- |
65
+ | **`options`** | <code>any</code> |
66
+
67
+ **Returns:** <code>Promise&lt;any&gt;</code>
68
+
69
+ --------------------
70
+
71
+
55
72
  ### openBrowser(...)
56
73
 
57
74
  ```typescript
@@ -66,4 +83,19 @@ openBrowser(options: any) => Promise<any>
66
83
 
67
84
  --------------------
68
85
 
86
+
87
+ ### scan(...)
88
+
89
+ ```typescript
90
+ scan(options: any) => Promise<any>
91
+ ```
92
+
93
+ | Param | Type |
94
+ | ------------- | ---------------- |
95
+ | **`options`** | <code>any</code> |
96
+
97
+ **Returns:** <code>Promise&lt;any&gt;</code>
98
+
99
+ --------------------
100
+
69
101
  </docgen-api>
@@ -52,6 +52,10 @@ dependencies {
52
52
  implementation fileTree(dir: 'libs', include: ['*.jar'])
53
53
  implementation project(':capacitor-android')
54
54
  implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
+
56
+ implementation('com.journeyapps:zxing-android-embedded:4.3.0') { transitive = false }
57
+ implementation 'com.google.zxing:core:3.3.0'
58
+
55
59
  testImplementation "junit:junit:$junitVersion"
56
60
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
61
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
@@ -1,3 +1,3 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
- package="com.aigens.sdk.plugins">
2
+ package="com.aigens.sdk">
3
3
  </manifest>
@@ -2,13 +2,26 @@ package com.aigens.sdk;
2
2
 
3
3
  import android.content.Intent;
4
4
  import android.content.res.AssetManager;
5
+ import android.graphics.Bitmap;
6
+ import android.net.Uri;
5
7
  import android.os.Bundle;
6
-
8
+ import android.view.View;
9
+ import android.webkit.WebResourceError;
10
+ import android.webkit.WebResourceRequest;
11
+ import android.webkit.WebResourceResponse;
12
+ import android.webkit.WebView;
13
+ import android.webkit.WebViewClient;
14
+ import android.widget.Button;
15
+
16
+ import com.aigens.sdk.plugins.CorePlugin;
17
+ import com.getcapacitor.Bridge;
7
18
  import com.getcapacitor.BridgeActivity;
19
+ import com.getcapacitor.BridgeWebViewClient;
8
20
  import com.getcapacitor.CapConfig;
9
21
  import com.getcapacitor.Plugin;
10
22
  import com.getcapacitor.PluginLoadException;
11
23
  import com.getcapacitor.PluginManager;
24
+ import com.aigens.sdk.R;
12
25
 
13
26
  import org.json.JSONException;
14
27
  import org.json.JSONObject;
@@ -19,9 +32,26 @@ import java.io.InputStream;
19
32
  import java.io.InputStreamReader;
20
33
  import java.util.ArrayList;
21
34
  import java.util.List;
35
+ import java.util.Map;
22
36
 
23
37
  public class WebContainerActivity extends BridgeActivity {
24
38
 
39
+ private boolean DEBUG = CorePlugin.DEBUG;
40
+ private String url;
41
+ private boolean navbar = false;
42
+ private Map member;
43
+
44
+ private void debug(Object... msgs){
45
+
46
+
47
+ if(DEBUG){
48
+ for(Object m: msgs){
49
+ System.out.println(m);
50
+ }
51
+
52
+ }
53
+ }
54
+
25
55
 
26
56
 
27
57
  @Override
@@ -29,17 +59,34 @@ public class WebContainerActivity extends BridgeActivity {
29
59
 
30
60
  super.onCreate(savedInstanceState);
31
61
 
62
+ setContentView(R.layout.sdk_layout_main);
63
+
32
64
  Intent intent = getIntent();
33
- String url = intent.getStringExtra("URL");
65
+ this.url = intent.getStringExtra("url");
34
66
 
35
- System.err.println("URL INPUT:"+ url);
67
+ //if navbar = true, show nav bar with "Done" button
68
+ this.navbar = intent.getBooleanExtra("navbar", false);
36
69
 
37
- if(url != null){
70
+ this.member = (Map) intent.getSerializableExtra("member");
71
+
72
+ if(this.member != null) {
73
+ CorePlugin.setMember(this.member);
74
+ }
75
+
76
+ System.out.println("OPEN URL:"+ url);
77
+
78
+ if(url == null){
38
79
  System.err.println("CONFIG ERROR MISSING NATIVE URL");
39
80
  }
40
81
 
82
+ if(member != null){
83
+ debug("member", member);
84
+ }
85
+
41
86
  JSONObject config = readConfig();
42
87
 
88
+ debug("config", config);
89
+
43
90
  JSONObject server = config.optJSONObject("server");
44
91
 
45
92
  try {
@@ -47,6 +94,9 @@ public class WebContainerActivity extends BridgeActivity {
47
94
  server.putOpt("url", url);
48
95
  }
49
96
 
97
+ //need to set this to avoid loading ServiceWorker
98
+ config.put("appendUserAgent", "AigensSDK");
99
+
50
100
  } catch (JSONException e) {
51
101
  e.printStackTrace();
52
102
  }
@@ -60,7 +110,6 @@ public class WebContainerActivity extends BridgeActivity {
60
110
  for(Class c: auto){
61
111
 
62
112
  String clsName = c.getName();
63
- System.err.println("auto loaded plugins:" + clsName);
64
113
 
65
114
  if(clsName.endsWith("SplashScreenPlugin")){
66
115
  //don't add the splash screen plugin so it doesn't show the splash screen again
@@ -70,15 +119,71 @@ public class WebContainerActivity extends BridgeActivity {
70
119
 
71
120
  }
72
121
 
73
- //plugins.addAll(auto);
122
+ debug("App plugins:" + plugins);
74
123
 
75
- //plugins.add(CorePlugin2.class);
76
- //plugins.add(AppPlugin.class);
77
- //plugins.add(GeolocationPlugin.class);
124
+ super.init(savedInstanceState, plugins, cc);
78
125
 
126
+ //still have time to override webview client to avoid any intercept
79
127
 
128
+ BypassWebViewClient wvc = new BypassWebViewClient(this.bridge);
129
+ this.bridge.getWebView().setWebViewClient(wvc);
80
130
 
81
- super.init(savedInstanceState, plugins, cc);
131
+ initView();
132
+ initLayout(false, true, false);
133
+ }
134
+
135
+ private void initView(){
136
+
137
+ Button backButton = (Button) findViewById(R.id.back);
138
+ backButton.setOnClickListener(new View.OnClickListener() {
139
+ @Override
140
+ public void onClick(View arg0) {
141
+
142
+ debug("Back Clicked");
143
+ WebContainerActivity.this.finish();
144
+ }
145
+ });
146
+
147
+ Button reloadButton = (Button) findViewById(R.id.reload);
148
+ reloadButton.setOnClickListener(new View.OnClickListener() {
149
+ @Override
150
+ public void onClick(View arg0) {
151
+
152
+ debug("Reload Clicked");
153
+ reload();
154
+ }
155
+ });
156
+
157
+ }
158
+
159
+ private void reload(){
160
+
161
+ String url = this.url;
162
+
163
+ /*
164
+ if(DEBUG){
165
+ url = "https://test.order.place/test/app/store/500?nocache=true";
166
+ }*/
167
+
168
+ this.initLayout(false, true, false);
169
+ this.bridge.getWebView().reload();
170
+
171
+ }
172
+
173
+ private void initLayout(boolean showWeb, boolean showInfo, boolean showError){
174
+
175
+ if(showError){
176
+ showWeb = false;
177
+ showInfo = false;
178
+ }
179
+
180
+ View info = findViewById(R.id.info);
181
+ info.setVisibility(showInfo ? View.VISIBLE : View.INVISIBLE);
182
+
183
+ View error = findViewById(R.id.error);
184
+ error.setVisibility(showError ? View.VISIBLE : View.INVISIBLE);
185
+
186
+ bridge.getWebView().setVisibility(showWeb ? View.VISIBLE : View.INVISIBLE);
82
187
 
83
188
 
84
189
  }
@@ -146,4 +251,88 @@ public class WebContainerActivity extends BridgeActivity {
146
251
  }
147
252
  }
148
253
 
254
+ //BridgeWebViewClient
255
+ class BypassWebViewClient extends BridgeWebViewClient {
256
+
257
+ public BypassWebViewClient(Bridge bridge) {
258
+ super(bridge);
259
+ }
260
+
261
+ //somehow this must call parent, otherwise plugins won't work
262
+ @Override
263
+ public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
264
+
265
+
266
+ String url = request.getUrl().toString();
267
+ //debug("shouldInterceptRequest", url);
268
+
269
+
270
+ if(url.indexOf("//scan") > 0){
271
+ return null;
272
+ }
273
+
274
+ return super.shouldInterceptRequest(view, request);
275
+
276
+ //super.shouldInterceptRequest(view, request);
277
+ //return null;
278
+ }
279
+
280
+
281
+ @Override
282
+ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
283
+ debug("shouldOverrideUrlLoading", request.getUrl());
284
+ //Uri url = request.getUrl();
285
+
286
+ //return super.shouldOverrideUrlLoading(view, request);
287
+
288
+ return false;
289
+ }
290
+
291
+ @Override
292
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
293
+ debug("shouldOverrideUrlLoading", url);
294
+ //return bridge.launchIntent(Uri.parse(url));
295
+
296
+ //return super.shouldOverrideUrlLoading(view, url);
297
+
298
+ return false;
299
+ }
300
+
301
+ @Override
302
+ public void onPageStarted(WebView view, String url, Bitmap favicon) {
303
+
304
+ debug("onPageStarted", url);
305
+
306
+ super.onPageStarted(view, url, favicon);
307
+
308
+ //bridge.getWebView().setVisibility(View.VISIBLE);
309
+ initLayout(true, false, false);
310
+ }
311
+
312
+ @Override
313
+ public void onPageFinished (WebView view, String url){
314
+
315
+ debug("onPageFinished", url);
316
+ //bridge.getWebView().setVisibility(View.VISIBLE);
317
+ }
318
+
319
+ @Override
320
+ public void onReceivedError (WebView view, int errorCode, String description, String failingUrl){
321
+ debug("onReceivedErrorOld", errorCode, description, failingUrl);
322
+
323
+ initLayout(false, true, true);
324
+ }
325
+
326
+ /*
327
+ @Override
328
+ public void onReceivedError (WebView view,
329
+ WebResourceRequest request,
330
+ WebResourceError error){
331
+
332
+ debug("onReceivedError2", request.getUrl());
333
+ }*/
334
+ }
335
+
336
+
337
+
149
338
  }
@@ -3,25 +3,158 @@ package com.aigens.sdk.plugins;
3
3
  import android.app.Activity;
4
4
  import android.content.Intent;
5
5
 
6
+ import androidx.activity.result.ActivityResultLauncher;
7
+ import androidx.appcompat.app.AppCompatActivity;
8
+
6
9
  import com.aigens.sdk.WebContainerActivity;
7
10
  import com.getcapacitor.JSObject;
8
11
  import com.getcapacitor.Plugin;
9
12
  import com.getcapacitor.PluginCall;
10
13
  import com.getcapacitor.PluginMethod;
11
14
  import com.getcapacitor.annotation.CapacitorPlugin;
15
+ import com.journeyapps.barcodescanner.ScanContract;
16
+ import com.journeyapps.barcodescanner.ScanOptions;
17
+
18
+ import org.json.JSONException;
19
+
20
+ import java.io.Serializable;
21
+ import java.util.HashMap;
22
+ import java.util.Iterator;
23
+ import java.util.Map;
12
24
 
13
25
  @CapacitorPlugin(name = "Core")
14
26
  public class CorePlugin extends Plugin {
15
27
 
28
+ public static boolean DEBUG = false;
29
+
30
+ private static Map member;
31
+
32
+ private void debug(Object msg){
33
+
34
+ if(DEBUG){
35
+ System.out.println(msg);
36
+ }
37
+
38
+ }
39
+
40
+ public static void setMember(Map member){
41
+ CorePlugin.member = member;
42
+ }
43
+
44
+ @Override
45
+ protected void handleOnStart(){
46
+
47
+ debug("CorePlugin handleOnStart");
48
+
49
+ prepareScan();
50
+
51
+ debug("CorePlugin handleOnStart END");
52
+ }
53
+
16
54
  @PluginMethod()
17
55
  public void echo(PluginCall call) {
18
56
  String value = call.getString("value");
19
57
 
58
+ debug("CorePlugin echo:" + value);
59
+
20
60
  JSObject ret = new JSObject();
21
61
  ret.put("value", value);
22
62
  call.resolve(ret);
23
63
  }
24
64
 
65
+ @PluginMethod()
66
+ public void getMember(PluginCall call) {
67
+
68
+ debug("CorePlugin getMember:" + member);
69
+
70
+ JSObject ret = new JSObject();
71
+ ret.put("member", member);
72
+ call.resolve(ret);
73
+ }
74
+
75
+ private PluginCall scanCall;
76
+
77
+ @PluginMethod()
78
+ public void scan(PluginCall call) {
79
+
80
+ debug("SCANNING!!");
81
+
82
+ this.scanCall = call;
83
+ scanRaw();
84
+
85
+
86
+ }
87
+
88
+ // Register the launcher and result handler
89
+
90
+ private ActivityResultLauncher<ScanOptions> barcodeLauncher;
91
+
92
+ private void prepareScan(){
93
+
94
+ AppCompatActivity act = getActivity();
95
+
96
+ barcodeLauncher = act.registerForActivityResult(new ScanContract(),
97
+ result -> {
98
+
99
+ if(scanCall == null){
100
+ debug("Missing scan callback");
101
+ return;
102
+ }
103
+
104
+ if(result.getContents() == null) {
105
+ //Toast.makeText(MyActivity.this, "Cancelled", Toast.LENGTH_LONG).show();
106
+ debug("scan cancelled");
107
+ JSObject ret = new JSObject();
108
+ ret.put("hasContent", false);
109
+ ret.put("success", false);
110
+ scanCall.resolve(ret);
111
+ } else {
112
+ //Toast.makeText(MyActivity.this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
113
+ String val = result.getContents();
114
+
115
+ debug("scan result:" + val);
116
+
117
+ if(val != null && val.length() > 0){
118
+
119
+ JSObject ret = new JSObject();
120
+ ret.put("content", val);
121
+ ret.put("hasContent", true);
122
+ ret.put("success", true);
123
+ scanCall.resolve(ret);
124
+ }else{
125
+
126
+ JSObject ret = new JSObject();
127
+ ret.put("hasContent", false);
128
+ ret.put("success", false);
129
+ scanCall.resolve(ret);
130
+ }
131
+
132
+
133
+
134
+ }
135
+ scanCall = null;
136
+ });
137
+ }
138
+
139
+ private void scanRaw(){
140
+
141
+ ScanOptions options = new ScanOptions();
142
+ //options.setDesiredBarcodeFormats(ScanOptions.ONE_D_CODE_TYPES);
143
+ options.setPrompt("");
144
+ //options.setCameraId(0); // Use a specific camera of the device
145
+ options.setBeepEnabled(false);
146
+ options.setOrientationLocked(false);
147
+ options.setBarcodeImageEnabled(true);
148
+
149
+ //options.setBarcodeImageEnabled(true);
150
+ barcodeLauncher.launch(options);
151
+ }
152
+
153
+ // Launch
154
+ //public void onButtonClick(View view) {
155
+ // barcodeLauncher.launch(new ScanOptions());
156
+ //}
157
+
25
158
  @PluginMethod()
26
159
  public void finish(PluginCall call) {
27
160
 
@@ -37,12 +170,31 @@ public class CorePlugin extends Plugin {
37
170
  if(url == null) return;
38
171
 
39
172
  JSObject options = call.getObject("options", null);
173
+ JSObject member = call.getObject("member", null);
174
+
175
+ Map memMap = new HashMap();
176
+
177
+ if(member != null){
178
+ Iterator<String> iter = member.keys();
179
+ while(iter.hasNext()){
180
+ String k = iter.next();
181
+ try {
182
+ Object v = member.get(k);
183
+ memMap.put(k, v);
184
+ } catch (JSONException e) {
185
+ e.printStackTrace();
186
+ }
187
+
188
+ }
189
+ }
40
190
 
41
191
  Activity act = getActivity();
42
192
 
43
193
  Intent intent = new Intent(act, WebContainerActivity.class);
44
194
 
45
- intent.putExtra("URL", url);
195
+ intent.putExtra("url", url);
196
+ intent.putExtra("member", (Serializable) memMap);
197
+
46
198
  act.startActivity(intent);
47
199
 
48
200
  JSObject ret = new JSObject();
@@ -0,0 +1,55 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <FrameLayout 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
+ </com.getcapacitor.CapacitorWebView>
16
+
17
+ <LinearLayout
18
+ android:id="@+id/info"
19
+ android:layout_width="match_parent"
20
+ android:layout_height="match_parent"
21
+ android:gravity="center"
22
+ android:orientation="vertical">
23
+
24
+ <ProgressBar
25
+ android:id="@+id/progress"
26
+ style="?android:attr/progressBarStyle"
27
+ android:layout_width="match_parent"
28
+ android:layout_height="wrap_content" />
29
+
30
+ </LinearLayout>
31
+
32
+ <LinearLayout
33
+ android:id="@+id/error"
34
+ android:layout_width="match_parent"
35
+ android:layout_height="match_parent"
36
+ android:gravity="center"
37
+ android:orientation="horizontal">
38
+
39
+ <Button
40
+ android:id="@+id/back"
41
+ android:layout_width="wrap_content"
42
+ android:layout_height="wrap_content"
43
+ android:layout_marginRight="8dp"
44
+ android:text="Exit" />
45
+
46
+ <Button
47
+ android:id="@+id/reload"
48
+ android:layout_width="wrap_content"
49
+ android:layout_height="wrap_content"
50
+ android:text="Reload" />
51
+
52
+ </LinearLayout>
53
+
54
+
55
+ </FrameLayout>
package/dist/docs.json CHANGED
@@ -37,6 +37,22 @@
37
37
  "complexTypes": [],
38
38
  "slug": "finish"
39
39
  },
40
+ {
41
+ "name": "getMember",
42
+ "signature": "(options: any) => Promise<any>",
43
+ "parameters": [
44
+ {
45
+ "name": "options",
46
+ "docs": "",
47
+ "type": "any"
48
+ }
49
+ ],
50
+ "returns": "Promise<any>",
51
+ "tags": [],
52
+ "docs": "",
53
+ "complexTypes": [],
54
+ "slug": "getmember"
55
+ },
40
56
  {
41
57
  "name": "openBrowser",
42
58
  "signature": "(options: any) => Promise<any>",
@@ -52,6 +68,22 @@
52
68
  "docs": "",
53
69
  "complexTypes": [],
54
70
  "slug": "openbrowser"
71
+ },
72
+ {
73
+ "name": "scan",
74
+ "signature": "(options: any) => Promise<any>",
75
+ "parameters": [
76
+ {
77
+ "name": "options",
78
+ "docs": "",
79
+ "type": "any"
80
+ }
81
+ ],
82
+ "returns": "Promise<any>",
83
+ "tags": [],
84
+ "docs": "",
85
+ "complexTypes": [],
86
+ "slug": "scan"
55
87
  }
56
88
  ],
57
89
  "properties": []
@@ -1,5 +1,7 @@
1
1
  export interface CorePlugin {
2
2
  echo(options: any): Promise<any>;
3
3
  finish(options: any): Promise<any>;
4
+ getMember(options: any): Promise<any>;
4
5
  openBrowser(options: any): Promise<any>;
6
+ scan(options: any): Promise<any>;
5
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CorePlugin {\n echo(options: any): Promise<any>;\n finish(options: any): Promise<any>;\n openBrowser(options: any): Promise<any>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface CorePlugin {\n echo(options: any): Promise<any>;\n finish(options: any): Promise<any>;\n getMember(options: any): Promise<any>;\n openBrowser(options: any): Promise<any>;\n scan(options: any): Promise<any>;\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -2,6 +2,8 @@ import { WebPlugin } from '@capacitor/core';
2
2
  import type { CorePlugin } from './definitions';
3
3
  export declare class CoreWeb extends WebPlugin implements CorePlugin {
4
4
  echo(options: any): Promise<any>;
5
+ getMember(options: any): Promise<any>;
5
6
  finish(options: any): Promise<any>;
6
7
  openBrowser(options: any): Promise<any>;
8
+ scan(options: any): Promise<any>;
7
9
  }
package/dist/esm/web.js CHANGED
@@ -4,6 +4,14 @@ export class CoreWeb extends WebPlugin {
4
4
  console.log('ECHO', options);
5
5
  return options;
6
6
  }
7
+ async getMember(options) {
8
+ var _a, _b;
9
+ console.log('GET MEMBER', options);
10
+ var result = {};
11
+ var w = window;
12
+ result.member = (_b = (_a = w.aigens) === null || _a === void 0 ? void 0 : _a.context) === null || _b === void 0 ? void 0 : _b.member;
13
+ return result;
14
+ }
7
15
  async finish(options) {
8
16
  console.log('FINISH', options);
9
17
  return options;
@@ -12,5 +20,9 @@ export class CoreWeb extends WebPlugin {
12
20
  console.log(options);
13
21
  throw new Error('Method not implemented.');
14
22
  }
23
+ async scan(options) {
24
+ console.log(options);
25
+ throw new Error('Method not implemented.');
26
+ }
15
27
  }
16
28
  //# sourceMappingURL=web.js.map