Commit 3c4a70e6 authored by Yacumima's avatar Yacumima

Merge branch 'develop'

parents 4168880a 388d0a3c
...@@ -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 {
...@@ -115,7 +117,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -115,7 +117,7 @@ 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);
} }
...@@ -147,7 +149,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -147,7 +149,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
} }
//Handling page result. //Handling page result.
if (sInstance.needResult(params)){ if (sInstance.needResult(params)) {
sInstance.mMediator.setHandler(url, new PageResultHandler() { sInstance.mMediator.setHandler(url, new PageResultHandler() {
@Override @Override
public void onResult(String key, Map resultData) { public void onResult(String key, Map resultData) {
...@@ -166,7 +168,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -166,7 +168,7 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
public void notImplemented() { public void notImplemented() {
//Doing nothing now. //Doing nothing now.
} }
},"no use",key,resultData,params); }, "no use", key, resultData, params);
} }
}); });
} }
...@@ -174,37 +176,37 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -174,37 +176,37 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
sInstance.mPlatform.startActivity(ctx, concatUrl(url, params), requestCode); sInstance.mPlatform.startActivity(ctx, concatUrl(url, params), requestCode);
} }
private Boolean needResult(Map params){ private Boolean needResult(Map params) {
if(params == null) return false; if (params == null) return false;
final String key = "needResult"; final String key = "needResult";
if(params.containsKey(key)){ if (params.containsKey(key)) {
if(params.get(key) instanceof Boolean){ if (params.get(key) instanceof Boolean) {
return (Boolean) params.get(key); return (Boolean) params.get(key);
} }
} }
return false; return false;
} }
public static void onPageResult(String key , Map resultData){ public static void onPageResult(String key, Map resultData) {
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); sInstance.mMediator.onPageResult(key, resultData);
} }
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!");
} }
...@@ -246,10 +248,12 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -246,10 +248,12 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
if (mCurrentActiveActivity == null) { if (mCurrentActiveActivity == null) {
Debuger.log("Application entry foreground"); Debuger.log("Application entry foreground");
if (mViewProvider.tryGetFlutterView() != 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); NavigationService.getService().emitEvent(map);
} }
}
mCurrentActiveActivity = activity; mCurrentActiveActivity = activity;
} }
...@@ -268,9 +272,11 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -268,9 +272,11 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
if (mCurrentActiveActivity == activity) { if (mCurrentActiveActivity == activity) {
Debuger.log("Application entry background"); Debuger.log("Application entry background");
if (mViewProvider.tryGetFlutterView() != 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); NavigationService.getService().emitEvent(map);
}
mCurrentActiveActivity = null; mCurrentActiveActivity = null;
} }
} }
...@@ -285,29 +291,44 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl ...@@ -285,29 +291,44 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
if (mCurrentActiveActivity == activity) { if (mCurrentActiveActivity == activity) {
Debuger.log("Application entry background"); Debuger.log("Application entry background");
if (mViewProvider.tryGetFlutterView() != 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); 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);
} }
} }
......
...@@ -31,9 +31,13 @@ public class MyApplication extends FlutterApplication { ...@@ -31,9 +31,13 @@ public class MyApplication extends FlutterApplication {
*/ */
@Override @Override
public Activity getMainActivity() { public Activity getMainActivity() {
if (MainActivity.sRef != null) {
return MainActivity.sRef.get(); return MainActivity.sRef.get();
} }
return null;
}
@Override @Override
public boolean isDebug() { public boolean isDebug() {
return true; return true;
......
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