diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/AppletManageModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/AppletManageModule.java index 216c4ae..4593530 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/AppletManageModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/AppletManageModule.java @@ -1,11 +1,20 @@ package com.finogeeks.mop.api.mop; 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.db.entity.FinApplet; +import com.finogeeks.lib.applet.interfaces.FinCallback; import com.finogeeks.mop.api.BaseApi; import com.finogeeks.mop.interfaces.ICallback; +import com.google.gson.Gson; import java.util.HashMap; import java.util.Map; @@ -13,13 +22,16 @@ import java.util.Map; public class AppletManageModule extends BaseApi { + private static final String TAG = "AppletManageModule"; + public AppletManageModule(Context context) { super(context); } @Override public String[] apis() { - return new String[]{"currentApplet", "closeAllApplets", "clearApplets", "removeUsedApplet"}; + return new String[]{"currentApplet", "closeAllApplets", "clearApplets", "removeUsedApplet", + "setActivityTransitionAnim", "sendCustomEvent", "callJS"}; } @Override @@ -57,6 +69,70 @@ public class AppletManageModule extends BaseApi { } else { 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() { + @Override + public void onSuccess(String s) { + Map 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); + } } } } diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java index 15a7494..d9cc4a0 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/AppletModule.java @@ -5,6 +5,7 @@ import android.text.TextUtils; import android.util.Log; 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.mop.api.BaseApi; import com.finogeeks.mop.interfaces.ICallback; @@ -53,19 +54,20 @@ public class AppletModule extends BaseApi { String appId = String.valueOf(param.get("appId")); Integer sequence = (Integer) param.get("sequence"); Map params = (Map) param.get("params"); + String apiServer = (String) param.get("apiServer"); // mContext是FlutterActivity, // 在Android 6.0、7.0系统的部分设备中热启动小程序时,如果context参数用mContext,会出现无法启动小程序的问题 // 所以这里使用Application Context Context context = mContext.getApplicationContext(); - if (params == null) { - if (sequence == null) { - FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, appId); - } else { - FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, appId, sequence, null); - } + FinAppInfo.StartParams startParams = params == null ? null : new FinAppInfo.StartParams(params.get("path"), params.get("query"), params.get("scene")); + Log.d(TAG, "openApplet:" + appId + "," + param + "," + sequence + "," + apiServer); + + if (apiServer != null) { + FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, apiServer, appId, sequence, startParams); } else { - FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, appId, params); + FinAppClient.INSTANCE.getAppletApiManager().startApplet(context, appId, sequence, startParams); } + // String apiServer = (String) param.get("apiServer"); // String apiPrefix = (String) param.get("apiPrefix"); // if (apiServer == null || apiServer.isEmpty() || apiPrefix == null || apiPrefix.isEmpty()) { diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/BaseModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/BaseModule.java index f892b22..1db0bb0 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/BaseModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/BaseModule.java @@ -2,6 +2,7 @@ package com.finogeeks.mop.api.mop; import android.app.Application; import android.content.Context; +import android.util.Log; import com.finogeeks.lib.applet.BuildConfig; 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.interfaces.ICallback; import com.finogeeks.mop.service.MopPluginService; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import java.util.ArrayList; import java.util.List; @@ -74,7 +77,22 @@ public class BaseModule extends BaseApi { Boolean bindAppletWithMainProcess = (Boolean) param.get("bindAppletWithMainProcess"); 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 finStoreConfigs = null; + if (param.get("finStoreConfigs") != null) { + finStoreConfigs = gson.fromJson(gson.toJson(param.get("finStoreConfigs")), new TypeToken>() { + }.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) .setSdkSecret(secret) .setApiUrl(apiServer) @@ -84,8 +102,18 @@ public class BaseModule extends BaseApi { .setUserId(userId) .setDebugMode(debug) .setDisableRequestPermissions(disablePermission) - .setBindAppletWithMainProcess(bindAppletWithMainProcess) - .build(); + .setBindAppletWithMainProcess(bindAppletWithMainProcess); + + 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(); // SDK初始化结果回调,用于接收SDK初始化状态 diff --git a/android/src/main/java/com/finogeeks/mop/api/mop/ExtensionApiModule.java b/android/src/main/java/com/finogeeks/mop/api/mop/ExtensionApiModule.java index b6cc51f..3e07c59 100644 --- a/android/src/main/java/com/finogeeks/mop/api/mop/ExtensionApiModule.java +++ b/android/src/main/java/com/finogeeks/mop/api/mop/ExtensionApiModule.java @@ -33,66 +33,126 @@ public class ExtensionApiModule extends BaseApi { @Override public String[] apis() { - return new String[]{"registerExtensionApi"}; + return new String[]{"registerExtensionApi","addWebExtentionApi"}; } @Override public void invoke(String s, Map param, ICallback iCallback) { - MethodChannel channel = MopPluginService.getInstance().getMethodChannel(); - String name = (String) param.get("name"); - FinAppClient.INSTANCE.getExtensionApiManager().registerApi(new com.finogeeks.lib.applet.api.BaseApi(getContext()) { - @Override - public String[] apis() { - return new String[]{name}; - } + if(s.equals("registerExtensionApi")) { + MethodChannel channel = MopPluginService.getInstance().getMethodChannel(); + String name = (String) param.get("name"); + Log.d(TAG, "registerExtensionApi:" + name); + FinAppClient.INSTANCE.getExtensionApiManager().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 extensionApi:" + s + ",params:" + jsonObject); - Map params = GsonUtil.gson.fromJson(jsonObject.toString(), HashMap.class); - handler.post(() -> { - channel.invokeMethod("extensionApi:" + 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; + @Override + public void invoke(String s, JSONObject jsonObject, com.finogeeks.lib.applet.interfaces.ICallback iCallback) { + Log.d("MopPlugin", "invoke extensionApi:" + s + ",params:" + jsonObject); + Map params = GsonUtil.gson.fromJson(jsonObject.toString(), HashMap.class); + handler.post(() -> { + channel.invokeMethod("extensionApi:" + 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(); } - } catch (JSONException e) { - e.printStackTrace(); } + + iCallback.onSuccess(ret); } - 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 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(); - } + @Override + public void notImplemented() { + iCallback.onFail(); + } + }); }); - }); - } - }); + } + }); + }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(); + } + }); + }); + } + }); + } } } diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 8acb99d..fe53f56 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/lib/mop.dart b/lib/mop.dart index 0be396e..b4d191b 100644 --- a/lib/mop.dart +++ b/lib/mop.dart @@ -315,8 +315,8 @@ class Mop { List? finStoreConfigs, UIConfig? uiConfig, String? customWebViewUserAgent, - int appletIntervalUpdateLimit = 0, - int maxRunningApplet = 5, + int? appletIntervalUpdateLimit, + int? maxRunningApplet, }) async { List>? storeConfigs = finStoreConfigs?.map((e) => e.toMap()).toList();