Commit aa1f6e09 authored by Jidong Chen's avatar Jidong Chen

android

1, remove xservice
2, broadcast
parent 08756127
...@@ -25,15 +25,14 @@ package com.taobao.idlefish.flutterboost; ...@@ -25,15 +25,14 @@ package com.taobao.idlefish.flutterboost;
import android.content.Intent; import android.content.Intent;
import com.taobao.idlefish.flutterboost.NavigationService.NavigationService; import com.taobao.idlefish.flutterboost.messageing.NavigationService;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import com.taobao.idlefish.flutterboost.interfaces.IContainerRecord; import com.taobao.idlefish.flutterboost.interfaces.IContainerRecord;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer; import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
public class ContainerRecord implements IContainerRecord { public class ContainerRecord implements IContainerRecord {
private final FlutterViewContainerManager mManager; private final FlutterViewContainerManager mManager;
private final IFlutterViewContainer mContainer; private final IFlutterViewContainer mContainer;
...@@ -142,7 +141,8 @@ public class ContainerRecord implements IContainerRecord { ...@@ -142,7 +141,8 @@ public class ContainerRecord implements IContainerRecord {
map.put("type", "backPressedCallback"); map.put("type", "backPressedCallback");
map.put("name", mContainer.getContainerName()); map.put("name", mContainer.getContainerName());
map.put("uniqueId", mUniqueId); map.put("uniqueId", mUniqueId);
NavigationService.getService().emitEvent(map);
FlutterBoostPlugin.getInstance().sendEvent("backPressedCallback",map);
mContainer.getBoostFlutterView().onBackPressed(); mContainer.getBoostFlutterView().onBackPressed();
} }
......
...@@ -27,24 +27,28 @@ import android.app.Activity; ...@@ -27,24 +27,28 @@ import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import com.alibaba.fastjson.JSON; import com.taobao.idlefish.flutterboost.messageing.NavigationService;
import com.taobao.idlefish.flutterboost.NavigationService.NavigationService;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer; import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
import com.taobao.idlefish.flutterboost.loader.ServiceLoader;
import com.taobao.idlefish.flutterboost.interfaces.IContainerManager; import com.taobao.idlefish.flutterboost.interfaces.IContainerManager;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterEngineProvider; import com.taobao.idlefish.flutterboost.interfaces.IFlutterEngineProvider;
import com.taobao.idlefish.flutterboost.interfaces.IPlatform; import com.taobao.idlefish.flutterboost.interfaces.IPlatform;
import com.taobao.idlefish.flutterboost.messageing.base.Broadcastor;
import com.taobao.idlefish.flutterboost.messageing.base.EvenListener;
import com.taobao.idlefish.flutterboost.messageing.base.MessageDispatcher;
import com.taobao.idlefish.flutterboost.messageing.base.MessageDispatcherImp;
import com.taobao.idlefish.flutterboost.messageing.base.MessageImp;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import com.taobao.idlefish.flutterboost.messageing.handlers.ClosePageHandler;
import com.taobao.idlefish.flutterboost.messageing.handlers.OnFlutterPageResultHandler;
import com.taobao.idlefish.flutterboost.messageing.handlers.OnShownContainerChangedHandler;
import com.taobao.idlefish.flutterboost.messageing.handlers.OpenPageHandler;
import com.taobao.idlefish.flutterboost.messageing.handlers.PageOnStartHandler;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.List;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.common.PluginRegistry;
...@@ -52,20 +56,75 @@ import io.flutter.plugin.common.PluginRegistry; ...@@ -52,20 +56,75 @@ import io.flutter.plugin.common.PluginRegistry;
public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Application.ActivityLifecycleCallbacks { public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Application.ActivityLifecycleCallbacks {
private static FlutterBoostPlugin sInstance = null;
private static int kRid = 0; private static int kRid = 0;
private static FlutterBoostPlugin sInstance = null;
private MessageDispatcher dispatcher = new MessageDispatcherImp();
private Broadcastor broadcastor = null;
public static FlutterBoostPlugin getInstance(){
return sInstance;
}
public static synchronized void init(IPlatform platform) { public static synchronized void init(IPlatform platform) {
if (sInstance == null) { if (sInstance == null) {
sInstance = new FlutterBoostPlugin(platform); sInstance = new FlutterBoostPlugin(platform);
//Config handler
sInstance.dispatcher.addHandler(new OnShownContainerChangedHandler());
sInstance.dispatcher.addHandler(new OnFlutterPageResultHandler());
sInstance.dispatcher.addHandler(new PageOnStartHandler());
sInstance.dispatcher.addHandler(new OpenPageHandler());
sInstance.dispatcher.addHandler(new ClosePageHandler());
platform.getApplication().registerActivityLifecycleCallbacks(sInstance); platform.getApplication().registerActivityLifecycleCallbacks(sInstance);
ServiceLoader.load();
} }
} }
public static void registerWith(PluginRegistry.Registrar registrar) { public static void registerWith(PluginRegistry.Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_boost"); final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_boost");
NavigationService.methodChannel = channel;
channel.setMethodCallHandler(sInstance); channel.setMethodCallHandler(sInstance);
sInstance.broadcastor = new Broadcastor(channel);
}
public void sendEvent(String name, Map arguments) {
broadcastor.sendEvent(name, arguments);
}
void addEventListener(String name, EvenListener listener) {
broadcastor.addEventListener(name, listener);
}
void removeEventListener(String name, EvenListener listener) {
broadcastor.removeEventListener(name, listener);
}
@Override
public void onMethodCall(MethodCall call, final MethodChannel.Result result) {
if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else if(call.method.equals("__event__")){
broadcastor.dispatch(call.method,(Map)call.arguments);
}else{
dispatcher.dispatch(new MessageImp(call.method, (Map)call.arguments), new MessageResult() {
@Override
public void success(Object var1) {
result.success(var1);
}
@Override
public void error(String var1, String var2, Object var3) {
result.error(var1, var2, var3);
}
@Override
public void notImplemented() {
result.notImplemented();
}
});
}
} }
public static IFlutterEngineProvider engineProvider() { public static IFlutterEngineProvider engineProvider() {
...@@ -117,14 +176,6 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -117,14 +176,6 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
return mManager.findContainerById(id); return mManager.findContainerById(id);
} }
@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else {
result.notImplemented();
}
}
public static void openPage(Context context, String url, final Map params, int requestCode) { public static void openPage(Context context, String url, final Map params, int requestCode) {
if (sInstance == null) { if (sInstance == null) {
...@@ -140,32 +191,32 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -140,32 +191,32 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
ctx = sInstance.mPlatform.getApplication(); ctx = sInstance.mPlatform.getApplication();
} }
sInstance.mPlatform.startActivity(ctx, url ,params, requestCode); sInstance.mPlatform.startActivity(ctx, url, params, requestCode);
} }
public static void openPage(Context context, String url, final Map params, int requestCode,PageResultHandler handler) { public static void openPage(Context context, String url, final Map params, int requestCode, PageResultHandler handler) {
if(handler != null){ if (handler != null) {
String rid = createResultId(); String rid = createResultId();
sInstance.mMediator.setHandler(rid,handler); sInstance.mMediator.setHandler(rid, handler);
params.put("result_id",rid); params.put("result_id", rid);
} }
openPage(context,url,params,requestCode); openPage(context, url, params, requestCode);
} }
private static String createResultId(){ private static String createResultId() {
kRid += 2; kRid += 2;
return "result_id_" + kRid; return "result_id_" + kRid;
} }
public static void onPageResult(String key , Map resultData, Map params){ public static void onPageResult(String key, Map resultData, Map params) {
if (sInstance == null) { if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet!"); throw new RuntimeException("FlutterBoostPlugin not init yet!");
} }
sInstance.mMediator.onPageResult(key,resultData,params); sInstance.mMediator.onPageResult(key, resultData, params);
} }
public static void setHandler(String key, PageResultHandler handler) { public static void setHandler(String key, PageResultHandler handler) {
...@@ -185,7 +236,6 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -185,7 +236,6 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
} }
@Override @Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) { public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
...@@ -199,7 +249,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -199,7 +249,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
if (BoostEngineProvider.sInstance.tryGetEngine() != null) { if (BoostEngineProvider.sInstance.tryGetEngine() != null) {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("type", "foreground"); map.put("type", "foreground");
NavigationService.getService().emitEvent(map); sInstance.sendEvent("lifecycle",map);
} }
} }
mCurrentActiveActivity = activity; mCurrentActiveActivity = activity;
...@@ -223,7 +273,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -223,7 +273,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
if (BoostEngineProvider.sInstance.tryGetEngine() != null) { if (BoostEngineProvider.sInstance.tryGetEngine() != null) {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("type", "background"); map.put("type", "background");
NavigationService.getService().emitEvent(map); sInstance.sendEvent("lifecycle",map);
} }
mCurrentActiveActivity = null; mCurrentActiveActivity = null;
} }
...@@ -242,7 +292,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -242,7 +292,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
if (BoostEngineProvider.sInstance.tryGetEngine() != null) { if (BoostEngineProvider.sInstance.tryGetEngine() != null) {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("type", "background"); map.put("type", "background");
NavigationService.getService().emitEvent(map); sInstance.sendEvent("lifecycle",map);
} }
mCurrentActiveActivity = null; mCurrentActiveActivity = null;
} }
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageHandler;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
import fleamarket.taobao.com.xservicekit.service.ServiceGateway;
public class NavigationService_openPage implements MessageHandler<Boolean>{
private Object mContext = null;
private boolean onCall(MessageResult<Boolean> result,String pageName,Map params,Boolean animated){
int requestCode = 0;
if(params != null && params.get("requestCode") != null) {
requestCode = (int) params.get("requestCode");
}
FlutterBoostPlugin.openPage(null,pageName,params,0);
if(result != null){
result.success(true);
}
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
this.onCall(result,(String)args.get("pageName"),(Map)args.get("params"),(Boolean)args.get("animated"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("openPage");
return h;
}
@Override
public Object getContext() {
return mContext;
}
@Override
public void setContext(Object obj) {
mContext = obj;
}
@Override
public String service() {
return "NavigationService";
}
public static void register(){
ServiceGateway.sharedInstance().registerHandler(new NavigationService_openPage());
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.FlutterViewContainerManager;
import com.taobao.idlefish.flutterboost.interfaces.IContainerRecord;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageHandler;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
import fleamarket.taobao.com.xservicekit.service.ServiceGateway;
public class NavigationService_pageOnStart implements MessageHandler<Map>{
private Object mContext = null;
private boolean onCall(MessageResult<Map> result,Map params){
Map<String,Object> pageInfo = new HashMap<>();
try {
IContainerRecord record = FlutterBoostPlugin
.containerManager().getCurrentTopRecord();
if(record == null) {
record = FlutterBoostPlugin.containerManager().getLastGenerateRecord();
}
pageInfo.put("name",record.getContainer().getContainerName());
pageInfo.put("params",record.getContainer().getContainerParams());
pageInfo.put("uniqueId",record.uniqueId());
result.success(pageInfo);
}catch (Throwable t){
result.success(pageInfo);
}
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Map> result) {
this.onCall(result,(Map)args.get("params"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("pageOnStart");
return h;
}
@Override
public Object getContext() {
return mContext;
}
@Override
public void setContext(Object obj) {
mContext = obj;
}
@Override
public String service() {
return "NavigationService";
}
public static void register(){
ServiceGateway.sharedInstance().registerHandler(new NavigationService_pageOnStart());
}
}
\ No newline at end of file
...@@ -23,17 +23,19 @@ ...@@ -23,17 +23,19 @@
*/ */
package com.taobao.idlefish.flutterboost; package com.taobao.idlefish.flutterboost;
import com.taobao.idlefish.flutterboost.NavigationService.NavigationService; import com.taobao.idlefish.flutterboost.messageing.NavigationService;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import com.taobao.idlefish.flutterboost.PageResultHandler;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
class PageResultMediator { class PageResultMediator {
private Map<String,PageResultHandler> _handlers = new HashMap<>(); private Map<String,PageResultHandler> _handlers = new HashMap<>();
void onPageResult(String key , Map resultData,Map params){ void onPageResult(String key , Map resultData,Map params){
if(key == null) return; if(key == null) return;
...@@ -47,6 +49,7 @@ class PageResultMediator { ...@@ -47,6 +49,7 @@ class PageResultMediator {
params = new HashMap(); params = new HashMap();
} }
params.put("forward",1); params.put("forward",1);
NavigationService.onNativePageResult(new MessageResult<Boolean>() { NavigationService.onNativePageResult(new MessageResult<Boolean>() {
@Override @Override
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import java.util.HashMap;
import java.util.Map;
import io.flutter.plugin.common.MethodChannel;
public class NavigationService {
public static MethodChannel methodChannel = null;
public static void onNativePageResult(final MessageResult<Boolean> result, String uniqueId, String key, Map resultData, Map params) {
Map<String, Object> args = new HashMap<>();
args.put("uniqueId", uniqueId);
args.put("key", key);
args.put("resultData", resultData);
args.put("params", params);
methodChannel.invokeMethod("onNativePageResult", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
public static void didShowPageContainer(final MessageResult<Boolean> result, String pageName, Map params, String uniqueId) {
Map<String, Object> args = new HashMap<>();
args.put("pageName", pageName);
args.put("params", params);
args.put("uniqueId", uniqueId);
methodChannel.invokeMethod("didShowPageContainer", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
public static void willShowPageContainer(final MessageResult<Boolean> result, String pageName, Map params, String uniqueId) {
Map<String, Object> args = new HashMap<>();
args.put("pageName", pageName);
args.put("params", params);
args.put("uniqueId", uniqueId);
methodChannel.invokeMethod("willShowPageContainer", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
public static void willDisappearPageContainer(final MessageResult<Boolean> result, String pageName, Map params, String uniqueId) {
Map<String, Object> args = new HashMap<>();
args.put("pageName", pageName);
args.put("params", params);
args.put("uniqueId", uniqueId);
methodChannel.invokeMethod("willDisappearPageContainer", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
public static void didDisappearPageContainer(final MessageResult<Boolean> result, String pageName, Map params, String uniqueId) {
Map<String, Object> args = new HashMap<>();
args.put("pageName", pageName);
args.put("params", params);
args.put("uniqueId", uniqueId);
methodChannel.invokeMethod("didDisappearPageContainer", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
public static void didInitPageContainer(final MessageResult<Boolean> result, String pageName, Map params, String uniqueId) {
Map<String, Object> args = new HashMap<>();
args.put("pageName", pageName);
args.put("params", params);
args.put("uniqueId", uniqueId);
methodChannel.invokeMethod("didInitPageContainer", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
public static void willDeallocPageContainer(final MessageResult<Boolean> result, String pageName, Map params, String uniqueId) {
Map<String, Object> args = new HashMap<>();
args.put("pageName", pageName);
args.put("params", params);
args.put("uniqueId", uniqueId);
methodChannel.invokeMethod("willDeallocPageContainer", args, new MethodChannel.Result() {
@Override
public void success(Object o) {
if (o instanceof Boolean) {
result.success((Boolean) o);
} else {
result.error("return type error code dart code", "", "");
}
}
@Override
public void error(String s, String s1, Object o) {
if (result != null) {
result.error(s, s1, o);
}
}
@Override
public void notImplemented() {
if (result != null) {
result.notImplemented();
}
}
});
}
}
\ No newline at end of file
package com.taobao.idlefish.flutterboost.messageing.base;
import android.support.annotation.Nullable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import io.flutter.plugin.common.MethodChannel;
public class Broadcastor{
private MethodChannel channel = null;
private Map<String,List<EvenListener>> lists = new HashMap<>();
public Broadcastor(MethodChannel channel) {
this.channel = channel;
}
public void sendEvent(String name , Map arguments) {
if (name == null) {
return;
}
Map msg = new HashMap();
msg.put("name",name);
if(arguments != null){
msg.put("arguments",arguments);
}
channel.invokeMethod("__event__", msg, new MethodChannel.Result() {
@Override
public void success(@Nullable Object o) {
}
@Override
public void error(String s, @Nullable String s1, @Nullable Object o) {
}
@Override
public void notImplemented() {
}
});
}
public void dispatch(String name, Map arguments) {
if(name == null || arguments == null){
return ;
}
List<EvenListener> list = lists.get(name);
if(list == null){
return ;
}
String eventName = (String)arguments.get("name");
Map eventArguments = (Map)arguments.get("arguments");
for(EvenListener l : list){
l.onEvent(eventName,eventArguments);
}
return ;
}
public void addEventListener(String name , EvenListener listener){
if(listener == null || name == null){
return ;
}
List<EvenListener> list = lists.get(name);
if (list == null){
list = new LinkedList<>();
lists.put(name,list);
}
list.add(listener);
}
public void removeEventListener(String name ,EvenListener listener){
if(listener == null || name == null){
return ;
}
List<EvenListener> list = lists.get(name);
if(list != null){
list.remove(listener);
}
}
}
package com.taobao.idlefish.flutterboost.messageing.base;
import java.util.Map;
public interface EvenListener {
void onEvent(String eventName , Map arguments);
}
...@@ -22,11 +22,11 @@ ...@@ -22,11 +22,11 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
package com.taobao.idlefish.flutterboost.loader; package com.taobao.idlefish.flutterboost.messageing.base;
import java.util.Map;
public class ServiceLoader { public interface Message {
public static void load(){ String name();
com.taobao.idlefish.flutterboost.NavigationService.NavigationServiceRegister.register(); Map arguments();
} }
}
\ No newline at end of file
...@@ -21,18 +21,10 @@ ...@@ -21,18 +21,10 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
package com.taobao.idlefish.flutterboost.messageing.base;
package com.taobao.idlefish.flutterboost.NavigationService; public interface MessageDispatcher<T>{
boolean dispatch(Message msg,MessageResult<T> result);
void addHandler(MessageHandler<T> handler);
public class NavigationServiceRegister { void removeHandler(MessageHandler<T> handler);
public static void register(){ }
NavigationService.register();
NavigationService_onShownContainerChanged.register();
NavigationService_onFlutterPageResult.register();
NavigationService_pageOnStart.register();
NavigationService_openPage.register();
NavigationService_closePage.register();
}
}
\ No newline at end of file
...@@ -21,59 +21,53 @@ ...@@ -21,59 +21,53 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
package com.taobao.idlefish.flutterboost.messageing.base;
package com.taobao.idlefish.flutterboost.NavigationService; import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin; public class MessageDispatcherImp implements MessageDispatcher {
import java.util.ArrayList; private Map<String,MessageHandler> handlers = new HashMap<>();
import java.util.List;
import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageHandler;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
import fleamarket.taobao.com.xservicekit.service.ServiceGateway;
public class NavigationService_onFlutterPageResult implements MessageHandler<Boolean>{ @Override
private Object mContext = null; public boolean dispatch(Message msg, MessageResult result) {
if(msg == null){
return false;
}
MessageHandler h = handlers.get(msg.name());
private boolean onCall(MessageResult<Boolean> result,String uniqueId,String key,Map resultData,Map params){ if(h != null){
// FlutterBoostPlugin.containerManager().setContainerResult(uniqueId,resultData); return h.onMethodCall(msg.name(),msg.arguments(),result);
// result.success(true);
return true;
} }
return false;
}
//==================Do not edit code blow!==============
@Override @Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) { public void addHandler(MessageHandler handler) {
this.onCall(result,(String)args.get("uniqueId"),(String)args.get("key"),(Map)args.get("resultData"),(Map)args.get("params")); if(handler == null){
return true; return;
} }
@Override List<String> names = handler.handleMessageNames();
public List<String> handleMessageNames() { for(String name : names){
List<String> h = new ArrayList<>(); handlers.put(name,handler);
h.add("onFlutterPageResult");
return h;
} }
@Override
public Object getContext() {
return mContext;
} }
@Override @Override
public void setContext(Object obj) { public void removeHandler(MessageHandler handler) {
mContext = obj; if(handler == null){
return;
} }
@Override List<String> names = handler.handleMessageNames();
public String service() { for(String name : names){
return "NavigationService"; if(handler == handlers.get(name)){
handlers.remove(name);
} }
public static void register(){
ServiceGateway.sharedInstance().registerHandler(new NavigationService_onFlutterPageResult());
} }
} }
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.base;
import java.util.List;
import java.util.Map;
public interface MessageHandler<T> {
boolean onMethodCall(String name, Map args, MessageResult<T> result);
List<String> handleMessageNames();
}
...@@ -21,60 +21,26 @@ ...@@ -21,60 +21,26 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
package com.taobao.idlefish.flutterboost.messageing.base;
package com.taobao.idlefish.flutterboost.NavigationService; import java.util.Map;
import com.taobao.idlefish.flutterboost.Debuger; public class MessageImp implements Message{
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin; private String name;
private Map args;
import java.util.ArrayList; public MessageImp(String name,Map args){
import java.util.List; this.name = name;
import java.util.Map; this.args = args;
import fleamarket.taobao.com.xservicekit.handler.MessageHandler;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
import fleamarket.taobao.com.xservicekit.service.ServiceGateway;
public class NavigationService_onShownContainerChanged implements MessageHandler<Boolean>{
private Object mContext = null;
private boolean onCall(MessageResult<Boolean> result,String now,String old,Map params){
//Add your handler code here.
FlutterBoostPlugin.containerManager().onShownContainerChanged(old,now);
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
this.onCall(result,(String)args.get("newName"),(String)args.get("oldName"),(Map)args.get("params"));
return true;
} }
@Override @Override
public List<String> handleMessageNames() { public String name() {
List<String> h = new ArrayList<>(); return name;
h.add("onShownContainerChanged");
return h;
}
@Override
public Object getContext() {
return mContext;
} }
@Override @Override
public void setContext(Object obj) { public Map arguments() {
mContext = obj; return args;
}
@Override
public String service() {
return "NavigationService";
}
public static void register(){
ServiceGateway.sharedInstance().registerHandler(new NavigationService_onShownContainerChanged());
}
} }
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.base;
public interface MessageResult<T> {
void success(T var1);
void error(String var1, String var2, Object var3);
void notImplemented();
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.handlers;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.FlutterViewContainerManager;
import com.taobao.idlefish.flutterboost.messageing.base.MessageHandler;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ClosePageHandler implements MessageHandler<Boolean> {
private boolean onCall(MessageResult<Boolean> result, String uniqueId, String pageName, Map params, Boolean animated) {
FlutterBoostPlugin.containerManager().closeContainer(uniqueId, null);
result.success(true);
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
this.onCall(result, (String) args.get("uniqueId"), (String) args.get("pageName"), (Map) args.get("params"), (Boolean) args.get("animated"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("closePage");
return h;
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.handlers;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.messageing.base.MessageHandler;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import com.taobao.idlefish.flutterboost.interfaces.IContainerManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class OnFlutterPageResultHandler implements MessageHandler<Boolean> {
private boolean onCall(MessageResult<Boolean> result, String uniqueId, String key, Map resultData, Map params) {
// FlutterBoostPlugin.containerManager().setContainerResult(uniqueId, resultData);
result.success(true);
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
this.onCall(result, (String) args.get("uniqueId"), (String) args.get("key"), (Map) args.get("resultData"), (Map) args.get("params"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("onFlutterPageResult");
return h;
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.handlers;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.messageing.base.MessageHandler;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class OnShownContainerChangedHandler implements MessageHandler<Boolean> {
private boolean onCall(MessageResult<Boolean> result, String now, String old, Map params) {
//Add your handler code here.
FlutterBoostPlugin.containerManager().onShownContainerChanged(old, now);
return true;
}
//==================Do not edit code blow!==============
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
this.onCall(result, (String) args.get("newName"), (String) args.get("oldName"), (Map) args.get("params"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("onShownContainerChanged");
return h;
}
}
\ No newline at end of file
...@@ -22,59 +22,48 @@ ...@@ -22,59 +22,48 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
package com.taobao.idlefish.flutterboost.NavigationService; package com.taobao.idlefish.flutterboost.messageing.handlers;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin; import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.FlutterViewContainerManager; import com.taobao.idlefish.flutterboost.messageing.base.MessageHandler;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageHandler;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
import fleamarket.taobao.com.xservicekit.service.ServiceGateway;
public class NavigationService_closePage implements MessageHandler<Boolean>{
private Object mContext = null;
public class OpenPageHandler implements MessageHandler<Boolean> {
private boolean onCall(MessageResult<Boolean> result,String uniqueId,String pageName,Map params,Boolean animated){ private boolean onCall(MessageResult<Boolean> result, String pageName, Map params, Boolean animated) {
FlutterBoostPlugin.containerManager().closeContainer(uniqueId,null); int requestCode = 0;
if (params != null && params.get("requestCode") != null) {
requestCode = (int) params.get("requestCode");
}
FlutterBoostPlugin.openPage(null, pageName, params, 0);
if (result != null) {
result.success(true); result.success(true);
}
return true; return true;
} }
//==================Do not edit code blow!==============
@Override @Override
public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) { public boolean onMethodCall(String name, Map args, MessageResult<Boolean> result) {
this.onCall(result,(String)args.get("uniqueId"),(String)args.get("pageName"),(Map)args.get("params"),(Boolean)args.get("animated")); this.onCall(result, (String) args.get("pageName"), (Map) args.get("params"), (Boolean) args.get("animated"));
return true; return true;
} }
@Override @Override
public List<String> handleMessageNames() { public List<String> handleMessageNames() {
List<String> h = new ArrayList<>(); List<String> h = new ArrayList<>();
h.add("closePage"); h.add("openPage");
return h; return h;
} }
@Override
public Object getContext() {
return mContext;
}
@Override
public void setContext(Object obj) {
mContext = obj;
}
@Override
public String service() {
return "NavigationService";
}
public static void register(){ }
ServiceGateway.sharedInstance().registerHandler(new NavigationService_closePage()); \ No newline at end of file
}
}
\ No newline at end of file
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost.messageing.handlers;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.FlutterViewContainerManager;
import com.taobao.idlefish.flutterboost.interfaces.IContainerRecord;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
import com.taobao.idlefish.flutterboost.messageing.base.MessageHandler;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PageOnStartHandler implements MessageHandler<Map> {
private boolean onCall(MessageResult<Map> result, Map params) {
Map<String, Object> pageInfo = new HashMap<>();
try {
IContainerRecord record = FlutterBoostPlugin
.containerManager().getCurrentTopRecord();
if (record == null) {
record = FlutterBoostPlugin.containerManager().getLastGenerateRecord();
}
pageInfo.put("name", record.getContainer().getContainerName());
pageInfo.put("params", record.getContainer().getContainerParams());
pageInfo.put("uniqueId", record.uniqueId());
result.success(pageInfo);
} catch (Throwable t) {
result.success(pageInfo);
}
return true;
}
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Map> result) {
this.onCall(result, (Map) args.get("params"));
return true;
}
@Override
public List<String> handleMessageNames() {
List<String> h = new ArrayList<>();
h.add("pageOnStart");
return h;
}
}
\ No newline at end of file
...@@ -37,8 +37,7 @@ typedef void (^FLBVoidCallback)(void); ...@@ -37,8 +37,7 @@ typedef void (^FLBVoidCallback)(void);
- (instancetype)initWithMethodChannel:(FlutterMethodChannel *)channel; - (instancetype)initWithMethodChannel:(FlutterMethodChannel *)channel;
- (void)sendEvent:(NSString *)eventName - (void)sendEvent:(NSString *)eventName
arguments:(NSDictionary *)arguments arguments:(NSDictionary *)arguments;
result:(FlutterResult)result;
- (FLBVoidCallback)addEventListener:(FLBEventListener)listner - (FLBVoidCallback)addEventListener:(FLBEventListener)listner
forName:(NSString *)name; forName:(NSString *)name;
......
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
- (void)sendEvent:(NSString *)eventName - (void)sendEvent:(NSString *)eventName
arguments:(NSDictionary *)arguments arguments:(NSDictionary *)arguments
result:(void (^)(id _Nonnull))result
{ {
if(!eventName) return; if(!eventName) return;
NSMutableDictionary *msg = NSMutableDictionary.new; NSMutableDictionary *msg = NSMutableDictionary.new;
...@@ -52,7 +51,7 @@ ...@@ -52,7 +51,7 @@
msg[@"arguments"] = arguments; msg[@"arguments"] = arguments;
[_channel invokeMethod:@"__event__" [_channel invokeMethod:@"__event__"
arguments:msg arguments:msg
result:result]; result:^(id r){}];
} }
- (FLBVoidCallback)addEventListener:(FLBEventListener)listner - (FLBVoidCallback)addEventListener:(FLBEventListener)listner
......
...@@ -65,13 +65,16 @@ class FlutterBoost { ...@@ -65,13 +65,16 @@ class FlutterBoost {
final MethodChannel _methodChannel = MethodChannel('flutter_boost'); final MethodChannel _methodChannel = MethodChannel('flutter_boost');
final MessageDispatcher _dispatcher = MessageDispatcher(); final MessageDispatcher _dispatcher = MessageDispatcher();
final Broadcastor _broadcastor = Broadcastor(_methodChannel); Broadcastor _broadcastor;
FlutterBoost() { FlutterBoost() {
_router.resultMediator = _resultMediator; _router.resultMediator = _resultMediator;
_broadcastor = Broadcastor(_methodChannel);
//Config message handlers //Config message handlers
NavigationService.methodChannel = _methodChannel; NavigationService.methodChannel = _methodChannel;
_dispatcher.registerHandler(DidDisappearPageContainerHandler()); _dispatcher.registerHandler(DidDisappearPageContainerHandler());
_dispatcher.registerHandler(DidInitPageContainerHandler()); _dispatcher.registerHandler(DidInitPageContainerHandler());
_dispatcher.registerHandler(DidShowPageContainerHandler()); _dispatcher.registerHandler(DidShowPageContainerHandler());
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
typedef void VoidCallback();
typedef Future<dynamic> EventListener(String name , Map arguments); typedef Future<dynamic> EventListener(String name , Map arguments);
class Broadcastor{ class Broadcastor{
...@@ -52,7 +51,7 @@ class Broadcastor{ ...@@ -52,7 +51,7 @@ class Broadcastor{
_channel.invokeMethod("__event__",msg); _channel.invokeMethod("__event__",msg);
} }
VoidCallback addEventListener(String name , EventListener listener){ Function addEventListener(String name , EventListener listener){
if(name == null || listener == null){ if(name == null || listener == null){
return (){}; return (){};
} }
...@@ -72,17 +71,17 @@ class Broadcastor{ ...@@ -72,17 +71,17 @@ class Broadcastor{
Future<dynamic> handleCall(MethodCall call){ Future<dynamic> handleCall(MethodCall call){
if(!_lists.containsKey(call.method) || call.method != "__event__"){ if(!_lists.containsKey(call.method) || call.method != "__event__"){
return Future<dynamic>(); return Future<dynamic>((){});
} }
String name = call.arguments["name"]; String name = call.arguments["name"];
String arg = call.arguments["arguments"]; Map arg = call.arguments["arguments"];
List<EventListener> list = _lists[call.method]; List<EventListener> list = _lists[call.method];
for(EventListener l in list){ for(EventListener l in list){
l(name,arg); l(name,arg);
} }
return Future<dynamic>(); return Future<dynamic>((){});
} }
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment