Commit 3a16ccfd authored by Jidong Chen's avatar Jidong Chen

android message opt

parent fae46f29
...@@ -56,7 +56,6 @@ import io.flutter.plugin.common.PluginRegistry; ...@@ -56,7 +56,6 @@ import io.flutter.plugin.common.PluginRegistry;
public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Application.ActivityLifecycleCallbacks { public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Application.ActivityLifecycleCallbacks {
private static int kRid = 0;
private static FlutterBoostPlugin sInstance = null; private static FlutterBoostPlugin sInstance = null;
private MessageDispatcher dispatcher = new MessageDispatcherImp(); private MessageDispatcher dispatcher = new MessageDispatcherImp();
private Broadcastor broadcastor = null; private Broadcastor broadcastor = null;
...@@ -161,15 +160,12 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -161,15 +160,12 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
private final IPlatform mPlatform; private final IPlatform mPlatform;
private final IContainerManager mManager; private final IContainerManager mManager;
private final PageResultMediator mMediator;
private Activity mCurrentActiveActivity; private Activity mCurrentActiveActivity;
private FlutterBoostPlugin(IPlatform platform) { private FlutterBoostPlugin(IPlatform platform) {
mPlatform = platform; mPlatform = platform;
mManager = new FlutterViewContainerManager(); mManager = new FlutterViewContainerManager();
mMediator = new PageResultMediator();
} }
public IFlutterViewContainer findContainerById(String id) { public IFlutterViewContainer findContainerById(String id) {
...@@ -194,47 +190,6 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -194,47 +190,6 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
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) {
if (handler != null) {
String rid = createResultId();
sInstance.mMediator.setHandler(rid, handler);
params.put("result_id", rid);
}
openPage(context, url, params, requestCode);
}
private static String createResultId() {
kRid += 2;
return "result_id_" + kRid;
}
public static void onPageResult(String key, Map resultData, Map params) {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet!");
}
sInstance.mMediator.onPageResult(key, resultData, params);
}
public static void setHandler(String key, PageResultHandler handler) {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet!");
}
sInstance.mMediator.setHandler(key, handler);
}
public static void removeHandler(String key) {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet!");
}
sInstance.mMediator.removeHandler(key);
}
@Override @Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) { public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
......
/*
* 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;
import java.util.Map;
public interface PageResultHandler {
void onResult(String key , Map resultData);
}
/*
* 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;
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.Map;
class PageResultMediator {
private Map<String,PageResultHandler> _handlers = new HashMap<>();
void onPageResult(String key , Map resultData,Map params){
if(key == null) return;
if(_handlers.containsKey(key)){
_handlers.get(key).onResult(key,resultData);
_handlers.remove(key);
}else{
if(params == null || !params.containsKey("forward")){
if(params == null){
params = new HashMap();
}
params.put("forward",1);
NavigationService.onNativePageResult(new MessageResult<Boolean>() {
@Override
public void success(Boolean var1) {
}
@Override
public void error(String var1, String var2, Object var3) {
}
@Override
public void notImplemented() {
}
},key,key,resultData,params);
}else{
int forward = (Integer) params.get("forward");
params.put("forward",++forward);
if(forward <= 2){
NavigationService.onNativePageResult(new MessageResult<Boolean>() {
@Override
public void success(Boolean var1) {
}
@Override
public void error(String var1, String var2, Object var3) {
}
@Override
public void notImplemented() {
}
},key,key,resultData,params);
}
}
}
}
void setHandler(String key, PageResultHandler handler){
if(key == null || handler == null) return;
_handlers.put(key,handler);
}
void removeHandler(String key){
if(key == null) return;;
_handlers.remove(key);
}
}
...@@ -35,17 +35,18 @@ import java.util.Map; ...@@ -35,17 +35,18 @@ import java.util.Map;
public class ClosePageHandler implements MessageHandler<Boolean> { 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!============== //==================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"));
//TODO:接入新的close消息
String uniqueId = (String)args.get("uniqueId");
Map resultData = (Map)args.get("result");
Map exts = (Map)args.get("exts");
FlutterBoostPlugin.containerManager().closeContainer(uniqueId, null);
result.success(true);
return true; return true;
} }
......
...@@ -37,7 +37,6 @@ public class OnFlutterPageResultHandler implements MessageHandler<Boolean> { ...@@ -37,7 +37,6 @@ public class OnFlutterPageResultHandler implements MessageHandler<Boolean> {
private boolean onCall(MessageResult<Boolean> result, String uniqueId, String key, Map resultData, Map params) { private boolean onCall(MessageResult<Boolean> result, String uniqueId, String key, Map resultData, Map params) {
// FlutterBoostPlugin.containerManager().setContainerResult(uniqueId, resultData);
result.success(true); result.success(true);
return true; return true;
} }
......
...@@ -29,35 +29,38 @@ import com.taobao.idlefish.flutterboost.messageing.base.MessageHandler; ...@@ -29,35 +29,38 @@ import com.taobao.idlefish.flutterboost.messageing.base.MessageHandler;
import com.taobao.idlefish.flutterboost.messageing.base.MessageResult; import com.taobao.idlefish.flutterboost.messageing.base.MessageResult;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class OpenPageHandler implements MessageHandler<Boolean> { public class OpenPageHandler implements MessageHandler<Map> {
@Override
public boolean onMethodCall(String name, Map args, MessageResult<Map> result) {
//TODO:接入新的open方法,同时兼容老方法
Map params = (Map)args.get("urlParams");
Map exts = (Map)args.get("exts");
String url = (String)args.get("url");
private boolean onCall(MessageResult<Boolean> result, String pageName, Map params, Boolean animated) {
int requestCode = 0; int requestCode = 0;
if (params != null && params.get("requestCode") != null) { if (params != null && params.get("requestCode") != null) {
requestCode = (int) params.get("requestCode"); requestCode = (int) params.get("requestCode");
} }
FlutterBoostPlugin.openPage(null, pageName, params, 0); FlutterBoostPlugin.openPage(null, url, params, 0);
//TODO: to call future.
if (result != null) { if (result != null) {
result.success(true); result.success(new HashMap());
} }
return true; return true;
} }
@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 @Override
public List<String> handleMessageNames() { public List<String> handleMessageNames() {
List<String> h = new ArrayList<>(); List<String> h = new ArrayList<>();
......
...@@ -52,7 +52,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -52,7 +52,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
PageRouter.openPageByUrl(this, PageRouter.NATIVE_PAGE_URL , params); PageRouter.openPageByUrl(this, PageRouter.NATIVE_PAGE_URL , params);
} else if (v == mOpenFlutter) { } else if (v == mOpenFlutter) {
PageRouter.openPageByUrl(this, PageRouter.FLUTTER_PAGE_URL,params); PageRouter.openPageByUrl(this, PageRouter.FLUTTER_PAGE_URL,params);
FlutterBoostPlugin.onPageResult("result_id_100",new HashMap(),new HashMap());
} else if (v == mOpenFlutterFragment) { } else if (v == mOpenFlutterFragment) {
PageRouter.openPageByUrl(this, PageRouter.FLUTTER_FRAGMENT_PAGE_URL,params); PageRouter.openPageByUrl(this, PageRouter.FLUTTER_FRAGMENT_PAGE_URL,params);
} }
......
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