实现flutter原生接口
parent
c17910963f
commit
425120e95c
|
@ -1,11 +1,20 @@
|
||||||
package com.finogeeks.mop.api.mop;
|
package com.finogeeks.mop.api.mop;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.finogeeks.lib.applet.anim.FadeInAnim;
|
||||||
|
import com.finogeeks.lib.applet.anim.NoneAnim;
|
||||||
|
import com.finogeeks.lib.applet.anim.SlideFromBottomToTopAnim;
|
||||||
|
import com.finogeeks.lib.applet.anim.SlideFromLeftToRightAnim;
|
||||||
|
import com.finogeeks.lib.applet.anim.SlideFromRightToLeftAnim;
|
||||||
|
import com.finogeeks.lib.applet.anim.SlideFromTopToBottomAnim;
|
||||||
import com.finogeeks.lib.applet.client.FinAppClient;
|
import com.finogeeks.lib.applet.client.FinAppClient;
|
||||||
import com.finogeeks.lib.applet.db.entity.FinApplet;
|
import com.finogeeks.lib.applet.db.entity.FinApplet;
|
||||||
|
import com.finogeeks.lib.applet.interfaces.FinCallback;
|
||||||
import com.finogeeks.mop.api.BaseApi;
|
import com.finogeeks.mop.api.BaseApi;
|
||||||
import com.finogeeks.mop.interfaces.ICallback;
|
import com.finogeeks.mop.interfaces.ICallback;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -13,13 +22,16 @@ import java.util.Map;
|
||||||
|
|
||||||
public class AppletManageModule extends BaseApi {
|
public class AppletManageModule extends BaseApi {
|
||||||
|
|
||||||
|
private static final String TAG = "AppletManageModule";
|
||||||
|
|
||||||
public AppletManageModule(Context context) {
|
public AppletManageModule(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] apis() {
|
public String[] apis() {
|
||||||
return new String[]{"currentApplet", "closeAllApplets", "clearApplets", "removeUsedApplet"};
|
return new String[]{"currentApplet", "closeAllApplets", "clearApplets", "removeUsedApplet",
|
||||||
|
"setActivityTransitionAnim", "sendCustomEvent", "callJS"};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,6 +69,70 @@ public class AppletManageModule extends BaseApi {
|
||||||
} else {
|
} else {
|
||||||
callback.onFail(null);
|
callback.onFail(null);
|
||||||
}
|
}
|
||||||
|
} else if (event.equals("setActivityTransitionAnim")) {
|
||||||
|
String anim = (String) param.get("anim");
|
||||||
|
Log.d(TAG, "setActivityTransitionAnim:" + anim);
|
||||||
|
if ("SlideFromLeftToRightAnim".equals(anim)) {
|
||||||
|
FinAppClient.INSTANCE.getAppletApiManager().setActivityTransitionAnim(SlideFromLeftToRightAnim.INSTANCE);
|
||||||
|
} else if ("SlideFromRightToLeftAnim".equals(anim)) {
|
||||||
|
FinAppClient.INSTANCE.getAppletApiManager().setActivityTransitionAnim(SlideFromRightToLeftAnim.INSTANCE);
|
||||||
|
} else if ("SlideFromTopToBottomAnim".equals(anim)) {
|
||||||
|
FinAppClient.INSTANCE.getAppletApiManager().setActivityTransitionAnim(SlideFromTopToBottomAnim.INSTANCE);
|
||||||
|
} else if ("SlideFromBottomToTopAnim".equals(anim)) {
|
||||||
|
FinAppClient.INSTANCE.getAppletApiManager().setActivityTransitionAnim(SlideFromBottomToTopAnim.INSTANCE);
|
||||||
|
} else if ("FadeInAnim".equals(anim)) {
|
||||||
|
FinAppClient.INSTANCE.getAppletApiManager().setActivityTransitionAnim(FadeInAnim.INSTANCE);
|
||||||
|
} else if ("NoneAnim".equals(anim)) {
|
||||||
|
FinAppClient.INSTANCE.getAppletApiManager().setActivityTransitionAnim(NoneAnim.INSTANCE);
|
||||||
|
}
|
||||||
|
callback.onSuccess(null);
|
||||||
|
} else if (event.equals("sendCustomEvent")) {
|
||||||
|
String appId = (String) param.get("appId");
|
||||||
|
Map eventData = (Map) param.get("eventData");
|
||||||
|
Log.d(TAG, "sendCustomEvent:" + appId);
|
||||||
|
if (appId != null) {
|
||||||
|
FinAppClient.INSTANCE.getAppletApiManager().sendCustomEvent(appId, eventData == null ? "" : new Gson().toJson(eventData));
|
||||||
|
callback.onSuccess(null);
|
||||||
|
} else {
|
||||||
|
callback.onFail(null);
|
||||||
|
}
|
||||||
|
} else if (event.equals("callJS")) {
|
||||||
|
String appId = (String) param.get("appId");
|
||||||
|
String eventName = (String) param.get("eventName");
|
||||||
|
String nativeViewId = (String) param.get("nativeViewId");
|
||||||
|
int viewId = 0;
|
||||||
|
if (nativeViewId != null && !nativeViewId.equals("")) {
|
||||||
|
try {
|
||||||
|
viewId = Integer.parseInt(nativeViewId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map eventData = (Map) param.get("eventData");
|
||||||
|
Log.d(TAG, "callJS:" + appId);
|
||||||
|
if (appId != null && eventName != null) {
|
||||||
|
FinAppClient.INSTANCE.getAppletApiManager().callJS(appId, eventName, eventData == null ? "" : new Gson().toJson(eventData),
|
||||||
|
viewId, new FinCallback<String>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(String s) {
|
||||||
|
Map<String, Object> res = new HashMap<>();
|
||||||
|
res.put("data", s);
|
||||||
|
callback.onSuccess(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(int i, String s) {
|
||||||
|
callback.onFail(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgress(int i, String s) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback.onFail(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.finogeeks.lib.applet.client.FinAppClient;
|
import com.finogeeks.lib.applet.client.FinAppClient;
|
||||||
|
import com.finogeeks.lib.applet.client.FinAppInfo;
|
||||||
import com.finogeeks.lib.applet.sdk.model.StartAppletDecryptRequest;
|
import com.finogeeks.lib.applet.sdk.model.StartAppletDecryptRequest;
|
||||||
import com.finogeeks.mop.api.BaseApi;
|
import com.finogeeks.mop.api.BaseApi;
|
||||||
import com.finogeeks.mop.interfaces.ICallback;
|
import com.finogeeks.mop.interfaces.ICallback;
|
||||||
|
@ -53,19 +54,20 @@ public class AppletModule extends BaseApi {
|
||||||
String appId = String.valueOf(param.get("appId"));
|
String appId = String.valueOf(param.get("appId"));
|
||||||
Integer sequence = (Integer) param.get("sequence");
|
Integer sequence = (Integer) param.get("sequence");
|
||||||
Map<String, String> params = (Map) param.get("params");
|
Map<String, String> params = (Map) param.get("params");
|
||||||
|
String apiServer = (String) param.get("apiServer");
|
||||||
// mContext是FlutterActivity,
|
// mContext是FlutterActivity,
|
||||||
// 在Android 6.0、7.0系统的部分设备中热启动小程序时,如果context参数用mContext,会出现无法启动小程序的问题
|
// 在Android 6.0、7.0系统的部分设备中热启动小程序时,如果context参数用mContext,会出现无法启动小程序的问题
|
||||||
// 所以这里使用Application Context
|
// 所以这里使用Application Context
|
||||||
Context context = mContext.getApplicationContext();
|
Context context = mContext.getApplicationContext();
|
||||||
if (params == null) {
|
FinAppInfo.StartParams startParams = params == null ? null : new FinAppInfo.StartParams(params.get("path"), params.get("query"), params.get("scene"));
|
||||||
if (sequence == null) {
|
Log.d(TAG, "openApplet:" + appId + "," + param + "," + sequence + "," + apiServer);
|
||||||
FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, appId);
|
|
||||||
|
if (apiServer != null) {
|
||||||
|
FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, apiServer, appId, sequence, startParams);
|
||||||
} else {
|
} else {
|
||||||
FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, appId, sequence, null);
|
FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, appId, sequence, startParams);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, appId, params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// String apiServer = (String) param.get("apiServer");
|
// String apiServer = (String) param.get("apiServer");
|
||||||
// String apiPrefix = (String) param.get("apiPrefix");
|
// String apiPrefix = (String) param.get("apiPrefix");
|
||||||
// if (apiServer == null || apiServer.isEmpty() || apiPrefix == null || apiPrefix.isEmpty()) {
|
// if (apiServer == null || apiServer.isEmpty() || apiPrefix == null || apiPrefix.isEmpty()) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.finogeeks.mop.api.mop;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.finogeeks.lib.applet.BuildConfig;
|
import com.finogeeks.lib.applet.BuildConfig;
|
||||||
import com.finogeeks.lib.applet.client.FinAppClient;
|
import com.finogeeks.lib.applet.client.FinAppClient;
|
||||||
|
@ -11,6 +12,8 @@ import com.finogeeks.lib.applet.interfaces.FinCallback;
|
||||||
import com.finogeeks.mop.api.BaseApi;
|
import com.finogeeks.mop.api.BaseApi;
|
||||||
import com.finogeeks.mop.interfaces.ICallback;
|
import com.finogeeks.mop.interfaces.ICallback;
|
||||||
import com.finogeeks.mop.service.MopPluginService;
|
import com.finogeeks.mop.service.MopPluginService;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -74,7 +77,22 @@ public class BaseModule extends BaseApi {
|
||||||
Boolean bindAppletWithMainProcess = (Boolean) param.get("bindAppletWithMainProcess");
|
Boolean bindAppletWithMainProcess = (Boolean) param.get("bindAppletWithMainProcess");
|
||||||
if (bindAppletWithMainProcess == null) bindAppletWithMainProcess = false;
|
if (bindAppletWithMainProcess == null) bindAppletWithMainProcess = false;
|
||||||
|
|
||||||
FinAppConfig config = new FinAppConfig.Builder()
|
String customWebViewUserAgent = (String) param.get("customWebViewUserAgent");
|
||||||
|
Integer appletIntervalUpdateLimit = (Integer) param.get("appletIntervalUpdateLimit");
|
||||||
|
Integer maxRunningApplet = (Integer) param.get("maxRunningApplet");
|
||||||
|
Gson gson = new Gson();
|
||||||
|
List<FinStoreConfig> finStoreConfigs = null;
|
||||||
|
if (param.get("finStoreConfigs") != null) {
|
||||||
|
finStoreConfigs = gson.fromJson(gson.toJson(param.get("finStoreConfigs")), new TypeToken<List<FinStoreConfig>>() {
|
||||||
|
}.getType());
|
||||||
|
}
|
||||||
|
FinAppConfig.UIConfig uiConfig = null;
|
||||||
|
if (param.get("uiConfig") != null) {
|
||||||
|
uiConfig = gson.fromJson(gson.toJson(param.get("uiConfig")), FinAppConfig.UIConfig.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FinAppConfig.Builder builder = new FinAppConfig.Builder()
|
||||||
.setSdkKey(appkey)
|
.setSdkKey(appkey)
|
||||||
.setSdkSecret(secret)
|
.setSdkSecret(secret)
|
||||||
.setApiUrl(apiServer)
|
.setApiUrl(apiServer)
|
||||||
|
@ -84,8 +102,18 @@ public class BaseModule extends BaseApi {
|
||||||
.setUserId(userId)
|
.setUserId(userId)
|
||||||
.setDebugMode(debug)
|
.setDebugMode(debug)
|
||||||
.setDisableRequestPermissions(disablePermission)
|
.setDisableRequestPermissions(disablePermission)
|
||||||
.setBindAppletWithMainProcess(bindAppletWithMainProcess)
|
.setBindAppletWithMainProcess(bindAppletWithMainProcess);
|
||||||
.build();
|
|
||||||
|
if (customWebViewUserAgent != null)
|
||||||
|
builder.setCustomWebViewUserAgent(customWebViewUserAgent);
|
||||||
|
if (appletIntervalUpdateLimit != null)
|
||||||
|
builder.setAppletIntervalUpdateLimit(appletIntervalUpdateLimit);
|
||||||
|
if (maxRunningApplet != null) builder.setMaxRunningApplet(maxRunningApplet);
|
||||||
|
if (finStoreConfigs != null) builder.setFinStoreConfigs(finStoreConfigs);
|
||||||
|
if (uiConfig != null) builder.setUiConfig(uiConfig);
|
||||||
|
|
||||||
|
FinAppConfig config = builder.build();
|
||||||
|
Log.d(TAG, "config:" + gson.toJson(config));
|
||||||
|
|
||||||
final Application application = MopPluginService.getInstance().getActivity().getApplication();
|
final Application application = MopPluginService.getInstance().getActivity().getApplication();
|
||||||
// SDK初始化结果回调,用于接收SDK初始化状态
|
// SDK初始化结果回调,用于接收SDK初始化状态
|
||||||
|
|
|
@ -33,13 +33,15 @@ public class ExtensionApiModule extends BaseApi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] apis() {
|
public String[] apis() {
|
||||||
return new String[]{"registerExtensionApi"};
|
return new String[]{"registerExtensionApi","addWebExtentionApi"};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String s, Map param, ICallback iCallback) {
|
public void invoke(String s, Map param, ICallback iCallback) {
|
||||||
|
if(s.equals("registerExtensionApi")) {
|
||||||
MethodChannel channel = MopPluginService.getInstance().getMethodChannel();
|
MethodChannel channel = MopPluginService.getInstance().getMethodChannel();
|
||||||
String name = (String) param.get("name");
|
String name = (String) param.get("name");
|
||||||
|
Log.d(TAG, "registerExtensionApi:" + name);
|
||||||
FinAppClient.INSTANCE.getExtensionApiManager().registerApi(new com.finogeeks.lib.applet.api.BaseApi(getContext()) {
|
FinAppClient.INSTANCE.getExtensionApiManager().registerApi(new com.finogeeks.lib.applet.api.BaseApi(getContext()) {
|
||||||
@Override
|
@Override
|
||||||
public String[] apis() {
|
public String[] apis() {
|
||||||
|
@ -93,6 +95,64 @@ public class ExtensionApiModule extends BaseApi {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}else if(s.equals("addWebExtentionApi")){
|
||||||
|
MethodChannel channel = MopPluginService.getInstance().getMethodChannel();
|
||||||
|
String name = (String) param.get("name");
|
||||||
|
Log.d(TAG, "addWebExtentionApi:" + name);
|
||||||
|
FinAppClient.INSTANCE.getExtensionWebApiManager().registerApi(new com.finogeeks.lib.applet.api.BaseApi(getContext()) {
|
||||||
|
@Override
|
||||||
|
public String[] apis() {
|
||||||
|
return new String[]{name};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invoke(String s, JSONObject jsonObject, com.finogeeks.lib.applet.interfaces.ICallback iCallback) {
|
||||||
|
Log.d("MopPlugin", "invoke webextensionApi:" + s + ",params:" + jsonObject);
|
||||||
|
Map params = GsonUtil.gson.fromJson(jsonObject.toString(), HashMap.class);
|
||||||
|
handler.post(() -> {
|
||||||
|
channel.invokeMethod("webExtentionApi:" + name, params, new MethodChannel.Result() {
|
||||||
|
@Override
|
||||||
|
public void success(Object result) {
|
||||||
|
String json = GsonUtil.gson.toJson(result);
|
||||||
|
FinAppTrace.d(ExtensionApiModule.TAG, "channel invokeMethod:" + name
|
||||||
|
+ " success, result=" + result + ", json=" + json);
|
||||||
|
JSONObject ret = null;
|
||||||
|
if (json != null && !json.equals("null")) {
|
||||||
|
try {
|
||||||
|
ret = new JSONObject(json);
|
||||||
|
if (ret.has("errMsg")) {
|
||||||
|
String errMsg = ret.getString("errMsg");
|
||||||
|
if (errMsg.startsWith(name + ":fail")) {
|
||||||
|
iCallback.onFail(ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iCallback.onSuccess(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(String errorCode, String errorMessage, Object errorDetails) {
|
||||||
|
FinAppTrace.e(ExtensionApiModule.TAG, "channel invokeMethod:" + name
|
||||||
|
+ " error, errorCode=" + errorCode
|
||||||
|
+ ", errorMessage=" + errorMessage
|
||||||
|
+ ", errorDetails=" + errorDetails);
|
||||||
|
iCallback.onFail();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notImplemented() {
|
||||||
|
iCallback.onFail();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"mop","path":"/Users/wangtao/Documents/fantai/code/finclip-flutter-sdk/","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/wangtao/development/flutter/.pub-cache/hosted/pub.flutter-io.cn/flutter_plugin_android_lifecycle-2.0.5/","dependencies":[]},{"name":"mop","path":"/Users/wangtao/Documents/fantai/code/finclip-flutter-sdk/","dependencies":["flutter_plugin_android_lifecycle"]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"mop","dependencies":["flutter_plugin_android_lifecycle"]}],"date_created":"2021-12-28 10:57:42.321282","version":"2.8.1"}
|
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"mop","path":"/Users/kangxuyao/StudioProjects/finclip-flutter-sdk/","dependencies":[]}],"android":[{"name":"flutter_plugin_android_lifecycle","path":"/Users/kangxuyao/.pub-cache/hosted/pub.flutter-io.cn/flutter_plugin_android_lifecycle-2.0.5/","dependencies":[]},{"name":"mop","path":"/Users/kangxuyao/StudioProjects/finclip-flutter-sdk/","dependencies":["flutter_plugin_android_lifecycle"]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"flutter_plugin_android_lifecycle","dependencies":[]},{"name":"mop","dependencies":["flutter_plugin_android_lifecycle"]}],"date_created":"2022-01-04 13:47:58.706248","version":"2.6.0-12.0.pre.553"}
|
|
@ -315,8 +315,8 @@ class Mop {
|
||||||
List<FinStoreConfig>? finStoreConfigs,
|
List<FinStoreConfig>? finStoreConfigs,
|
||||||
UIConfig? uiConfig,
|
UIConfig? uiConfig,
|
||||||
String? customWebViewUserAgent,
|
String? customWebViewUserAgent,
|
||||||
int appletIntervalUpdateLimit = 0,
|
int? appletIntervalUpdateLimit,
|
||||||
int maxRunningApplet = 5,
|
int? maxRunningApplet,
|
||||||
}) async {
|
}) async {
|
||||||
List<Map<String, dynamic>>? storeConfigs =
|
List<Map<String, dynamic>>? storeConfigs =
|
||||||
finStoreConfigs?.map((e) => e.toMap()).toList();
|
finStoreConfigs?.map((e) => e.toMap()).toList();
|
||||||
|
|
Loading…
Reference in New Issue