Commit 6433ecc8 authored by Jidong Chen's avatar Jidong Chen Committed by GitHub

Merge branch 'no_query' into result_mediator

parents be587178 7aed07fe
...@@ -33,7 +33,10 @@ public class BoostFlutterNativeView extends FlutterNativeView { ...@@ -33,7 +33,10 @@ public class BoostFlutterNativeView extends FlutterNativeView {
super(context); super(context);
} }
@Override public void detachFromFlutterView() {
//do nothing...
}
public void detach() { public void detach() {
//do nothing... //do nothing...
} }
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
*/ */
package com.taobao.idlefish.flutterboost; package com.taobao.idlefish.flutterboost;
import android.os.Handler;
import com.taobao.idlefish.flutterboost.NavigationService.NavigationService; import com.taobao.idlefish.flutterboost.NavigationService.NavigationService;
import com.taobao.idlefish.flutterboost.interfaces.IContainerManager; import com.taobao.idlefish.flutterboost.interfaces.IContainerManager;
import com.taobao.idlefish.flutterboost.interfaces.IContainerRecord; import com.taobao.idlefish.flutterboost.interfaces.IContainerRecord;
...@@ -36,6 +38,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -36,6 +38,7 @@ public class ContainerRecord implements IContainerRecord {
private final IContainerManager mManager; private final IContainerManager mManager;
private final IFlutterViewContainer mContainer; private final IFlutterViewContainer mContainer;
private final String mUniqueId; private final String mUniqueId;
private final Handler mHandler = new Handler();
private int mState = STATE_UNKNOW; private int mState = STATE_UNKNOW;
private MethodChannelProxy mProxy = new MethodChannelProxy(); private MethodChannelProxy mProxy = new MethodChannelProxy();
...@@ -85,7 +88,12 @@ public class ContainerRecord implements IContainerRecord { ...@@ -85,7 +88,12 @@ public class ContainerRecord implements IContainerRecord {
* If current container is finishing, we should call destroy flutter page early. * If current container is finishing, we should call destroy flutter page early.
*/ */
if(mContainer.isFinishing()) { if(mContainer.isFinishing()) {
mProxy.destroy(); mHandler.post(new Runnable() {
@Override
public void run() {
mProxy.destroy();
}
});
} }
} }
......
/* /*
* The MIT License (MIT) * The MIT License (MIT)
* *
* Copyright (c) 2019 Alibaba Group * Copyright (c) 2019 Alibaba Group
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
...@@ -28,6 +28,7 @@ import android.app.Application; ...@@ -28,6 +28,7 @@ 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.net.Uri;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
...@@ -49,6 +50,7 @@ import fleamarket.taobao.com.xservicekit.handler.MessageResult; ...@@ -49,6 +50,7 @@ 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;
import io.flutter.view.FlutterView;
public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Application.ActivityLifecycleCallbacks { public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Application.ActivityLifecycleCallbacks {
...@@ -116,8 +118,8 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -116,8 +118,8 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
mMediator = new PageResultMediator(); mMediator = new PageResultMediator();
} }
public IFlutterViewContainer findContainerById(String id){ public IFlutterViewContainer findContainerById(String id) {
return mManager.findContainerById(id); return mManager.findContainerById(id);
} }
@Override @Override
...@@ -146,10 +148,8 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -146,10 +148,8 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
if (ctx == null) { if (ctx == null) {
ctx = sInstance.mPlatform.getApplication(); ctx = sInstance.mPlatform.getApplication();
} }
sInstance.mPlatform.startActivity(ctx, concatUrl(url, params), requestCode); sInstance.mPlatform.startActivity(ctx, concatUrl(url, params), requestCode);
onPageResult("result_id_100",new HashMap(),new HashMap());
} }
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) {
...@@ -167,9 +167,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -167,9 +167,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
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) {
...@@ -179,15 +177,15 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -179,15 +177,15 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
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) {
if (sInstance == null) { if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet!"); throw new RuntimeException("FlutterBoostPlugin not init yet!");
} }
sInstance.mMediator.setHandler(key,handler); sInstance.mMediator.setHandler(key, handler);
} }
public static void removeHandler(String key){ public static void removeHandler(String key) {
if (sInstance == null) { if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet!"); throw new RuntimeException("FlutterBoostPlugin not init yet!");
} }
...@@ -229,9 +227,11 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -229,9 +227,11 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
if (mCurrentActiveActivity == null) { if (mCurrentActiveActivity == null) {
Debuger.log("Application entry foreground"); Debuger.log("Application entry foreground");
Map<String, String> map = new HashMap<>(); if (mViewProvider.tryGetFlutterView() != null) {
map.put("type", "foreground"); Map<String, String> map = new HashMap<>();
NavigationService.getService().emitEvent(map); map.put("type", "foreground");
NavigationService.getService().emitEvent(map);
}
} }
mCurrentActiveActivity = activity; mCurrentActiveActivity = activity;
} }
...@@ -251,9 +251,11 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -251,9 +251,11 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
if (mCurrentActiveActivity == activity) { if (mCurrentActiveActivity == activity) {
Debuger.log("Application entry background"); Debuger.log("Application entry background");
Map<String, String> map = new HashMap<>(); if (mViewProvider.tryGetFlutterView() != null) {
map.put("type", "background"); Map<String, String> map = new HashMap<>();
NavigationService.getService().emitEvent(map); map.put("type", "background");
NavigationService.getService().emitEvent(map);
}
mCurrentActiveActivity = null; mCurrentActiveActivity = null;
} }
} }
...@@ -268,29 +270,44 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -268,29 +270,44 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
if (mCurrentActiveActivity == activity) { if (mCurrentActiveActivity == activity) {
Debuger.log("Application entry background"); Debuger.log("Application entry background");
Map<String, String> map = new HashMap<>(); if (mViewProvider.tryGetFlutterView() != null) {
map.put("type", "background"); Map<String, String> map = new HashMap<>();
NavigationService.getService().emitEvent(map); map.put("type", "background");
NavigationService.getService().emitEvent(map);
}
mCurrentActiveActivity = null; mCurrentActiveActivity = null;
} }
//reset view provider when single instance context is destroyed
// final FlutterView flutterView = mViewProvider.tryGetFlutterView();
// if(flutterView != null) {
// Activity ctxActivity = (Activity)flutterView.getContext();
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
// if((ctxActivity.isDestroyed() || ctxActivity == activity) &&
// mManager.getLastRecord() == null) {
// mViewProvider.reset();
// }
// }
// }
} }
public static void setBoostResult(Activity activity, HashMap result){ public static void setBoostResult(Activity activity, HashMap result) {
Intent intent = new Intent(); Intent intent = new Intent();
if(result != null) { if (result != null) {
intent.putExtra(IFlutterViewContainer.RESULT_KEY, result); intent.putExtra(IFlutterViewContainer.RESULT_KEY, result);
} }
activity.setResult(Activity.RESULT_OK,intent); activity.setResult(Activity.RESULT_OK, intent);
} }
public static void onBoostResult(IFlutterViewContainer container, int requestCode,int resultCode,Intent intent){ public static void onBoostResult(IFlutterViewContainer container, int requestCode, int resultCode, Intent intent) {
Map map = new HashMap(); Map map = new HashMap();
if(intent != null) { if (intent != null) {
map.put("result",intent.getSerializableExtra(IFlutterViewContainer.RESULT_KEY)); map.put("result", intent.getSerializableExtra(IFlutterViewContainer.RESULT_KEY));
} }
map.put("requestCode",requestCode); map.put("requestCode", requestCode);
map.put("responseCode",resultCode); map.put("responseCode", resultCode);
containerManager().onContainerResult(container,map); containerManager().onContainerResult(container, map);
} }
} }
......
...@@ -38,20 +38,10 @@ ...@@ -38,20 +38,10 @@
private boolean onCall(MessageResult<Boolean> result,String pageName,Map params,Boolean animated){ private boolean onCall(MessageResult<Boolean> result,String pageName,Map params,Boolean animated){
Map pageParams = null; FlutterBoostPlugin.openPage(null,pageName,params,0);
int requestCode = 0; if(result != null){
result.success(true);
if(params != null && params.get("query") != null) {
pageParams = (Map)params.get("query");
}
if(params != null && params.get("requestCode") != null) {
requestCode = (int)params.get("requestCode");
} }
FlutterBoostPlugin.openPage(null,pageName,pageParams,requestCode);
result.success(true);
return true; return true;
} }
......
...@@ -144,12 +144,11 @@ abstract public class FlutterViewStub extends FrameLayout { ...@@ -144,12 +144,11 @@ abstract public class FlutterViewStub extends FrameLayout {
if (flutterView == null) return; if (flutterView == null) return;
Debuger.log("detachFlutterView");
if (mSnapshot.getParent() == null) { if (mSnapshot.getParent() == null) {
mBitmap = flutterView.getBitmap(); mBitmap = flutterView.getBitmap();
if (mBitmap != null && !mBitmap.isRecycled()) { if (mBitmap != null && !mBitmap.isRecycled()) {
mSnapshot.setImageBitmap(mBitmap); mSnapshot.setImageBitmap(mBitmap);
Debuger.log("snapshot view");
addView(mSnapshot); addView(mSnapshot);
} }
} }
...@@ -160,11 +159,12 @@ abstract public class FlutterViewStub extends FrameLayout { ...@@ -160,11 +159,12 @@ abstract public class FlutterViewStub extends FrameLayout {
@Override @Override
public void run() { public void run() {
if (flutterView.getParent() != null && flutterView.getParent() == mStub) { if (flutterView.getParent() != null && flutterView.getParent() == mStub) {
Debuger.log("detachFlutterView");
mStub.removeView(flutterView); mStub.removeView(flutterView);
} }
} }
}; };
sHandler.sendMessage(msg); sHandler.sendMessageDelayed(msg,18);
} }
public void destroy() { public void destroy() {
......
...@@ -31,7 +31,11 @@ public class MyApplication extends FlutterApplication { ...@@ -31,7 +31,11 @@ public class MyApplication extends FlutterApplication {
*/ */
@Override @Override
public Activity getMainActivity() { public Activity getMainActivity() {
return MainActivity.sRef.get(); if (MainActivity.sRef != null) {
return MainActivity.sRef.get();
}
return null;
} }
@Override @Override
......
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