metamap-capacitor-plugin 4.7.15 → 4.7.16
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,9 +1,111 @@
|
|
|
1
|
+
//package com.getmati.plugins.capacitor;
|
|
2
|
+
//
|
|
3
|
+
//import android.app.Activity;
|
|
4
|
+
//import android.content.Intent;
|
|
5
|
+
//import android.util.Log;
|
|
6
|
+
//import androidx.activity.result.ActivityResult;
|
|
7
|
+
//import com.getcapacitor.JSObject;
|
|
8
|
+
//import com.getcapacitor.Plugin;
|
|
9
|
+
//import com.getcapacitor.PluginCall;
|
|
10
|
+
//import com.getcapacitor.PluginMethod;
|
|
11
|
+
//import com.getcapacitor.annotation.ActivityCallback;
|
|
12
|
+
//import com.getcapacitor.annotation.CapacitorPlugin;
|
|
13
|
+
//import com.metamap.metamap_sdk.MetamapSdk;
|
|
14
|
+
//import com.metamap.metamap_sdk.Metadata;
|
|
15
|
+
//import org.json.JSONObject;
|
|
16
|
+
//import org.json.JSONException;
|
|
17
|
+
//
|
|
18
|
+
//
|
|
19
|
+
//import java.util.Iterator;
|
|
20
|
+
//
|
|
21
|
+
//import android.graphics.Color;
|
|
22
|
+
//
|
|
23
|
+
//@CapacitorPlugin(name = "MetaMapCapacitor")
|
|
24
|
+
//public class MetaMapCapacitorPlugin extends Plugin {
|
|
25
|
+
//
|
|
26
|
+
// @SuppressWarnings("unused")
|
|
27
|
+
// @PluginMethod
|
|
28
|
+
// public void showMetaMapFlow(PluginCall call) {
|
|
29
|
+
// Log.e("MetaMapCapacitorPlugin", "showMetaMapFlow");
|
|
30
|
+
// bridge.getActivity().runOnUiThread(new Runnable() {
|
|
31
|
+
// @Override
|
|
32
|
+
// public void run() {
|
|
33
|
+
//
|
|
34
|
+
// final String clientId = call.getString("clientId");
|
|
35
|
+
// final String flowId = call.getString("flowId");
|
|
36
|
+
// final JSONObject metadata = call.getObject("metadata", new JSObject());
|
|
37
|
+
// try {
|
|
38
|
+
// if (clientId == null) {
|
|
39
|
+
// Log.e("MetaMapCapacitorPlugin", "\"Client Id should be not null\"");
|
|
40
|
+
// } else {
|
|
41
|
+
//
|
|
42
|
+
// Iterator<String> keys = metadata.keys();
|
|
43
|
+
//
|
|
44
|
+
// Metadata.Builder metadataBuilder = new Metadata.Builder();
|
|
45
|
+
//
|
|
46
|
+
// while (keys.hasNext()) {
|
|
47
|
+
// String key = keys.next();
|
|
48
|
+
// try {
|
|
49
|
+
// if (key.toLowerCase().contains("color")) {
|
|
50
|
+
// String hexColor = (String) metadata.get(key);
|
|
51
|
+
// int color = Color.parseColor(hexColor);
|
|
52
|
+
// if (hexColor.length() == 9) {
|
|
53
|
+
// color = Color.argb(Color.blue(color), Color.alpha(color), Color.red(color), Color.green(color));
|
|
54
|
+
// }
|
|
55
|
+
// metadataBuilder.with(key, color);
|
|
56
|
+
// } else {
|
|
57
|
+
// metadataBuilder.with(key, metadata.get(key));
|
|
58
|
+
// }
|
|
59
|
+
// } catch (Exception e) {
|
|
60
|
+
// throw new RuntimeException(e);
|
|
61
|
+
// }
|
|
62
|
+
// }
|
|
63
|
+
// metadataBuilder.with("sdkType", "capacitor");
|
|
64
|
+
// Metadata data = metadataBuilder.build();
|
|
65
|
+
//
|
|
66
|
+
//
|
|
67
|
+
//
|
|
68
|
+
//
|
|
69
|
+
// Intent flowIntent = MetamapSdk.INSTANCE.createFlowIntent(bridge.getActivity(), clientId, flowId, data, null, null);
|
|
70
|
+
// startActivityForResult(call, flowIntent, "callback");
|
|
71
|
+
// }
|
|
72
|
+
// } catch(Exception excepion) {
|
|
73
|
+
// call.reject("Verification failed");
|
|
74
|
+
// }
|
|
75
|
+
// }
|
|
76
|
+
// });
|
|
77
|
+
// }
|
|
78
|
+
//
|
|
79
|
+
// @Override
|
|
80
|
+
// protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
|
|
81
|
+
// super.handleOnActivityResult(requestCode, resultCode, data);
|
|
82
|
+
// Log.e("MetaMapCapacitorPlugin", "WILL NOT BE CALLED");
|
|
83
|
+
// }
|
|
84
|
+
//
|
|
85
|
+
// @SuppressWarnings("unused")
|
|
86
|
+
// @ActivityCallback
|
|
87
|
+
// public void callback(PluginCall call, ActivityResult activityResult) {
|
|
88
|
+
// if(activityResult.getResultCode() == Activity.RESULT_OK && activityResult.getData() != null) {
|
|
89
|
+
// JSObject result = new JSObject();
|
|
90
|
+
// String identityId = activityResult.getData().getStringExtra("ARG_IDENTITY_ID");
|
|
91
|
+
// String verificationID = activityResult.getData().getStringExtra("ARG_VERIFICATION_ID");
|
|
92
|
+
// result.put("identityId", identityId);
|
|
93
|
+
// result.put("verificationID", verificationID);
|
|
94
|
+
// call.resolve(result);
|
|
95
|
+
// Log.e("MetaMapCapacitorPlugin", "Activity.RESULT_OK");
|
|
96
|
+
// } else {
|
|
97
|
+
// call.reject("verificationCancelled");
|
|
98
|
+
// Log.e("MetaMapCapacitorPlugin", "Activity.RESULT_CANCELLED");
|
|
99
|
+
// }
|
|
100
|
+
// }
|
|
101
|
+
//}
|
|
1
102
|
package com.getmati.plugins.capacitor;
|
|
2
103
|
|
|
3
104
|
import android.app.Activity;
|
|
4
105
|
import android.content.Intent;
|
|
5
106
|
import android.util.Log;
|
|
6
107
|
import androidx.activity.result.ActivityResult;
|
|
108
|
+
|
|
7
109
|
import com.getcapacitor.JSObject;
|
|
8
110
|
import com.getcapacitor.Plugin;
|
|
9
111
|
import com.getcapacitor.PluginCall;
|
|
@@ -12,9 +114,8 @@ import com.getcapacitor.annotation.ActivityCallback;
|
|
|
12
114
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
13
115
|
import com.metamap.metamap_sdk.MetamapSdk;
|
|
14
116
|
import com.metamap.metamap_sdk.Metadata;
|
|
15
|
-
import org.json.JSONObject;
|
|
16
|
-
import org.json.JSONException;
|
|
17
117
|
|
|
118
|
+
import org.json.JSONObject;
|
|
18
119
|
|
|
19
120
|
import java.util.Iterator;
|
|
20
121
|
|
|
@@ -23,79 +124,89 @@ import android.graphics.Color;
|
|
|
23
124
|
@CapacitorPlugin(name = "MetaMapCapacitor")
|
|
24
125
|
public class MetaMapCapacitorPlugin extends Plugin {
|
|
25
126
|
|
|
26
|
-
@SuppressWarnings("unused")
|
|
27
127
|
@PluginMethod
|
|
28
128
|
public void showMetaMapFlow(PluginCall call) {
|
|
29
|
-
Log.
|
|
30
|
-
bridge.getActivity().runOnUiThread(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (hexColor.length() == 9) {
|
|
53
|
-
color = Color.argb(Color.blue(color), Color.alpha(color), Color.red(color), Color.green(color));
|
|
54
|
-
}
|
|
55
|
-
metadataBuilder.with(key, color);
|
|
56
|
-
} else {
|
|
57
|
-
metadataBuilder.with(key, metadata.get(key));
|
|
58
|
-
}
|
|
59
|
-
} catch (Exception e) {
|
|
60
|
-
throw new RuntimeException(e);
|
|
129
|
+
Log.d("MetaMapCapacitorPlugin", "showMetaMapFlow called");
|
|
130
|
+
bridge.getActivity().runOnUiThread(() -> {
|
|
131
|
+
String clientId = call.getString("clientId");
|
|
132
|
+
String flowId = call.getString("flowId");
|
|
133
|
+
JSONObject metadata = call.getObject("metadata", new JSObject());
|
|
134
|
+
|
|
135
|
+
if (clientId == null || clientId.isEmpty()) {
|
|
136
|
+
call.reject("Client Id should not be null or empty");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
Metadata.Builder metadataBuilder = new Metadata.Builder();
|
|
142
|
+
|
|
143
|
+
Iterator<String> keys = metadata.keys();
|
|
144
|
+
while (keys.hasNext()) {
|
|
145
|
+
String key = keys.next();
|
|
146
|
+
try {
|
|
147
|
+
if (key.toLowerCase().contains("color")) {
|
|
148
|
+
String hexColor = metadata.getString(key);
|
|
149
|
+
int color = Color.parseColor(hexColor);
|
|
150
|
+
if (hexColor.length() == 9) {
|
|
151
|
+
color = Color.argb(Color.blue(color), Color.alpha(color), Color.red(color), Color.green(color));
|
|
61
152
|
}
|
|
153
|
+
metadataBuilder.with(key, color);
|
|
154
|
+
} else {
|
|
155
|
+
metadataBuilder.with(key, metadata.get(key));
|
|
62
156
|
}
|
|
63
|
-
|
|
64
|
-
|
|
157
|
+
} catch (Exception e) {
|
|
158
|
+
Log.e("MetaMapCapacitorPlugin", "Error parsing metadata key: " + key, e);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
65
161
|
|
|
162
|
+
metadataBuilder.with("sdkType", "capacitor");
|
|
163
|
+
Metadata builtMetadata = metadataBuilder.build();
|
|
66
164
|
|
|
165
|
+
Intent flowIntent = MetamapSdk.INSTANCE.createFlowIntent(
|
|
166
|
+
bridge.getActivity(),
|
|
167
|
+
clientId,
|
|
168
|
+
flowId,
|
|
169
|
+
builtMetadata,
|
|
170
|
+
null,
|
|
171
|
+
null
|
|
172
|
+
);
|
|
67
173
|
|
|
174
|
+
startActivityForResult(call, flowIntent, "callback");
|
|
68
175
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
} catch(Exception excepion) {
|
|
73
|
-
call.reject("Verification failed");
|
|
74
|
-
}
|
|
176
|
+
} catch (Exception e) {
|
|
177
|
+
Log.e("MetaMapCapacitorPlugin", "Error starting flow", e);
|
|
178
|
+
call.reject("Failed to start MetaMap flow: " + e.getMessage());
|
|
75
179
|
}
|
|
76
180
|
});
|
|
77
181
|
}
|
|
78
182
|
|
|
79
|
-
@Override
|
|
80
|
-
protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
|
|
81
|
-
super.handleOnActivityResult(requestCode, resultCode, data);
|
|
82
|
-
Log.e("MetaMapCapacitorPlugin", "WILL NOT BE CALLED");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
@SuppressWarnings("unused")
|
|
86
183
|
@ActivityCallback
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
184
|
+
private void callback(PluginCall call, ActivityResult activityResult) {
|
|
185
|
+
Intent data = activityResult.getData();
|
|
186
|
+
if (data == null) {
|
|
187
|
+
call.reject("MetaMap result data is null");
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
String identityId = data.getStringExtra("ARG_IDENTITY_ID");
|
|
192
|
+
String verificationId = data.getStringExtra("ARG_VERIFICATION_ID");
|
|
193
|
+
|
|
194
|
+
JSObject result = new JSObject();
|
|
195
|
+
result.put("identityId", identityId != null ? identityId : "");
|
|
196
|
+
result.put("verificationId", verificationId != null ? verificationId : "");
|
|
197
|
+
|
|
198
|
+
if (activityResult.getResultCode() == Activity.RESULT_OK) {
|
|
199
|
+
Log.d("MetaMapCapacitorPlugin", "✅ verificationSuccess");
|
|
94
200
|
call.resolve(result);
|
|
95
|
-
Log.e("MetaMapCapacitorPlugin", "Activity.RESULT_OK");
|
|
96
201
|
} else {
|
|
97
|
-
|
|
98
|
-
Log.
|
|
202
|
+
result.put("status", "cancelled");
|
|
203
|
+
Log.d("MetaMapCapacitorPlugin", "❌ verificationCancelled");
|
|
204
|
+
call.reject(
|
|
205
|
+
"Verification was cancelled by the user",
|
|
206
|
+
"verificationCancelled",
|
|
207
|
+
null,
|
|
208
|
+
result
|
|
209
|
+
);
|
|
99
210
|
}
|
|
100
211
|
}
|
|
101
|
-
}
|
|
212
|
+
}
|