Commit d9ac3683 authored by yangwu.jia's avatar yangwu.jia

Boost 1.9升级

parent 570f4acb
...@@ -26,6 +26,7 @@ android { ...@@ -26,6 +26,7 @@ android {
buildToolsVersion '27.0.3' buildToolsVersion '27.0.3'
defaultConfig { defaultConfig {
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 28
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
lintOptions { lintOptions {
...@@ -34,9 +35,11 @@ android { ...@@ -34,9 +35,11 @@ android {
} }
dependencies { dependencies {
implementation 'com.alibaba:fastjson:1.2.41' implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:26.1.0' implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support:support-v4:28.0.0'
implementation 'android.arch.lifecycle:common-java8:1.1.1'
} }
ext { ext {
......
...@@ -28,12 +28,13 @@ import android.content.Context; ...@@ -28,12 +28,13 @@ import android.content.Context;
import com.idlefish.flutterboost.interfaces.IFlutterEngineProvider; import com.idlefish.flutterboost.interfaces.IFlutterEngineProvider;
import com.idlefish.flutterboost.interfaces.IStateListener; import com.idlefish.flutterboost.interfaces.IStateListener;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs; import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.view.FlutterMain; import io.flutter.view.FlutterMain;
public class BoostEngineProvider implements IFlutterEngineProvider { public class BoostEngineProvider implements IFlutterEngineProvider {
private BoostFlutterEngine mEngine = null; private FlutterEngine mEngine = null;
public BoostEngineProvider() {} public BoostEngineProvider() {}
...@@ -43,7 +44,7 @@ public class BoostEngineProvider implements IFlutterEngineProvider { ...@@ -43,7 +44,7 @@ public class BoostEngineProvider implements IFlutterEngineProvider {
} }
@Override @Override
public BoostFlutterEngine provideEngine(Context context) { public FlutterEngine provideEngine(Context context) {
Utils.assertCallOnMainThread(); Utils.assertCallOnMainThread();
if (mEngine == null) { if (mEngine == null) {
...@@ -51,25 +52,25 @@ public class BoostEngineProvider implements IFlutterEngineProvider { ...@@ -51,25 +52,25 @@ public class BoostEngineProvider implements IFlutterEngineProvider {
FlutterMain.ensureInitializationComplete( FlutterMain.ensureInitializationComplete(
context.getApplicationContext(), flutterShellArgs.toArray()); context.getApplicationContext(), flutterShellArgs.toArray());
mEngine = createEngine(context.getApplicationContext()); mEngine = new FlutterEngine(context.getApplicationContext());
final IStateListener stateListener = FlutterBoost.sInstance.mStateListener; // final IStateListener stateListener = FlutterBoost.sInstance.mStateListener;
if(stateListener != null) { // if(stateListener != null) {
stateListener.onEngineCreated(mEngine); // stateListener.onEngineCreated(mEngine);
} // }
} }
return mEngine; return mEngine;
} }
@Override @Override
public BoostFlutterEngine tryGetEngine() { public FlutterEngine tryGetEngine() {
return mEngine; return mEngine;
} }
public static void assertEngineRunning(){ public static void assertEngineRunning(){
final BoostFlutterEngine engine = FlutterBoost.singleton().engineProvider().tryGetEngine(); final FlutterEngine engine = NewFlutterBoost.instance().engineProvider().tryGetEngine();
if(engine == null || !engine.isRunning()) { // if(engine == null || !engine.isRunning()) {
throw new RuntimeException("engine is not running yet!"); // throw new RuntimeException("engine is not running yet!");
} // }
} }
} }
...@@ -30,122 +30,114 @@ import io.flutter.view.FlutterView; ...@@ -30,122 +30,114 @@ import io.flutter.view.FlutterView;
import io.flutter.view.TextureRegistry; import io.flutter.view.TextureRegistry;
public class BoostFlutterEngine extends FlutterEngine { public class BoostFlutterEngine extends FlutterEngine {
protected final Context mContext;
protected final BoostPluginRegistry mBoostPluginRegistry;
protected final DartExecutor.DartEntrypoint mEntrypoint;
protected final String mInitRoute;
private final FakeRender mFakeRender;
protected WeakReference<Activity> mCurrentActivityRef; protected WeakReference<Activity> mCurrentActivityRef;
public BoostFlutterEngine(@NonNull Context context) { public BoostFlutterEngine(@NonNull Context context) {
this(context, null, null);
}
public BoostFlutterEngine(@NonNull Context context, DartExecutor.DartEntrypoint entrypoint, String initRoute) {
super(context); super(context);
mContext = context.getApplicationContext();
mBoostPluginRegistry = new BoostPluginRegistry(this, context);
if (entrypoint != null) {
mEntrypoint = entrypoint;
} else {
mEntrypoint = defaultDartEntrypoint(context);
}
if (initRoute != null) {
mInitRoute = initRoute;
} else {
mInitRoute = defaultInitialRoute(context);
}
FlutterJNI flutterJNI = null;
try {
Field field = FlutterEngine.class.getDeclaredField("flutterJNI");
field.setAccessible(true);
flutterJNI = (FlutterJNI) field.get(this);
} catch (Throwable t) {
try {
for(Field field:FlutterEngine.class.getDeclaredFields()) {
field.setAccessible(true);
Object o = field.get(this);
if(o instanceof FlutterJNI) {
flutterJNI = (FlutterJNI)o;
}
}
if(flutterJNI == null) {
throw new RuntimeException("FlutterJNI not found");
} }
}catch (Throwable it){
Debuger.exception(it);
}
}
mFakeRender = new FakeRender(flutterJNI);
}
public void startRun(@Nullable Activity activity) {
mCurrentActivityRef = new WeakReference<>(activity);
if (!getDartExecutor().isExecutingDart()) { // public BoostFlutterEngine(@NonNull Context context, DartExecutor.DartEntrypoint entrypoint, String initRoute) {
// super(context);
Debuger.log("engine start running..."); // mContext = context.getApplicationContext();
//// mBoostPluginRegistry = new BoostPluginRegistry(this, context);
getNavigationChannel().setInitialRoute(mInitRoute); //
getDartExecutor().executeDartEntrypoint(mEntrypoint); // if (entrypoint != null) {
// mEntrypoint = entrypoint;
final IStateListener stateListener = FlutterBoost.sInstance.mStateListener; // } else {
if (stateListener != null) { // mEntrypoint = defaultDartEntrypoint(context);
stateListener.onEngineStarted(this); // }
} //
// if (initRoute != null) {
FlutterBoost.singleton().platform().registerPlugins(mBoostPluginRegistry); // mInitRoute = initRoute;
// } else {
if(activity != null) { // mInitRoute = defaultInitialRoute(context);
FlutterRenderer.ViewportMetrics metrics = new FlutterRenderer.ViewportMetrics(); // }
metrics.devicePixelRatio = activity.getResources().getDisplayMetrics().density; //
final View decor = activity.getWindow().getDecorView(); // FlutterJNI flutterJNI = null;
if(decor != null) { // try {
metrics.width = decor.getWidth(); // Field field = FlutterEngine.class.getDeclaredField("flutterJNI");
metrics.height = decor.getHeight(); // field.setAccessible(true);
} //
// flutterJNI = (FlutterJNI) field.get(this);
if (metrics.width <= 0 || metrics.height <= 0) { // } catch (Throwable t) {
metrics.width = Utils.getMetricsWidth(activity); // try {
metrics.height = Utils.getMetricsHeight(activity); // for(Field field:FlutterEngine.class.getDeclaredFields()) {
} // field.setAccessible(true);
// Object o = field.get(this);
metrics.paddingTop = Utils.getStatusBarHeight(activity); //
metrics.paddingRight = 0; // if(o instanceof FlutterJNI) {
metrics.paddingBottom = 0; // flutterJNI = (FlutterJNI)o;
metrics.paddingLeft = 0; // }
metrics.viewInsetTop = 0; // }
metrics.viewInsetRight = 0; //
metrics.viewInsetBottom = 0; // if(flutterJNI == null) {
metrics.viewInsetLeft = 0; // throw new RuntimeException("FlutterJNI not found");
// }
getRenderer().setViewportMetrics(metrics); // }catch (Throwable it){
} // Debuger.exception(it);
} // }
} // }
// mFakeRender = new FakeRender(flutterJNI);
// }
// public void startRun(@Nullable Activity activity) {
// mCurrentActivityRef = new WeakReference<>(activity);
//
// if (!getDartExecutor().isExecutingDart()) {
//
// Debuger.log("engine start running...");
//
// getNavigationChannel().setInitialRoute(mInitRoute);
// getDartExecutor().executeDartEntrypoint(mEntrypoint);
//
// final IStateListener stateListener = FlutterBoost.sInstance.mStateListener;
// if (stateListener != null) {
// stateListener.onEngineStarted(this);
// }
//
//// FlutterBoost.singleton().platform().registerPlugins(mBoostPluginRegistry);
//
// if(activity != null) {
// FlutterRenderer.ViewportMetrics metrics = new FlutterRenderer.ViewportMetrics();
// metrics.devicePixelRatio = activity.getResources().getDisplayMetrics().density;
// final View decor = activity.getWindow().getDecorView();
// if(decor != null) {
// metrics.width = decor.getWidth();
// metrics.height = decor.getHeight();
// }
//
// if (metrics.width <= 0 || metrics.height <= 0) {
// metrics.width = Utils.getMetricsWidth(activity);
// metrics.height = Utils.getMetricsHeight(activity);
// }
//
// metrics.paddingTop = Utils.getStatusBarHeight(activity);
// metrics.paddingRight = 0;
// metrics.paddingBottom = 0;
// metrics.paddingLeft = 0;
// metrics.viewInsetTop = 0;
// metrics.viewInsetRight = 0;
// metrics.viewInsetBottom = 0;
// metrics.viewInsetLeft = 0;
//
// getRenderer().setViewportMetrics(metrics);
// }
// }
// }
protected DartExecutor.DartEntrypoint defaultDartEntrypoint(Context context) { protected DartExecutor.DartEntrypoint defaultDartEntrypoint(Context context) {
return new DartExecutor.DartEntrypoint( return DartExecutor.DartEntrypoint.createDefault();
context.getResources().getAssets(),
FlutterMain.findAppBundlePath(context),
"main");
} }
protected String defaultInitialRoute(Context context) { protected String defaultInitialRoute(Context context) {
return "/"; return "/";
} }
public BoostPluginRegistry getBoostPluginRegistry() { // public BoostPluginRegistry getBoostPluginRegistry() {
return mBoostPluginRegistry; // return mBoostPluginRegistry;
} // }
public boolean isRunning() { public boolean isRunning() {
return getDartExecutor().isExecutingDart(); return getDartExecutor().isExecutingDart();
...@@ -165,14 +157,14 @@ public class BoostFlutterEngine extends FlutterEngine { ...@@ -165,14 +157,14 @@ public class BoostFlutterEngine extends FlutterEngine {
} }
if (hit) { if (hit) {
return mFakeRender; return null;
} else { } else {
return super.getRenderer(); return super.getRenderer();
} }
} }
public class BoostPluginRegistry extends FlutterPluginRegistry { public class BoostPluginRegistry extends FlutterPluginRegistry {
private final FlutterEngine mEngine; private FlutterEngine mEngine;
public BoostPluginRegistry(FlutterEngine engine, Context context) { public BoostPluginRegistry(FlutterEngine engine, Context context) {
super(engine, context); super(engine, context);
......
...@@ -136,7 +136,7 @@ public class BoostFlutterView extends FrameLayout { ...@@ -136,7 +136,7 @@ public class BoostFlutterView extends FrameLayout {
mFlutterView.addOnFirstFrameRenderedListener(mOnFirstFrameRenderedListener); mFlutterView.addOnFirstFrameRenderedListener(mOnFirstFrameRenderedListener);
mFlutterEngine.startRun((Activity)getContext()); // mFlutterEngine.startRun((Activity)getContext());
final IStateListener stateListener = FlutterBoost.sInstance.mStateListener; final IStateListener stateListener = FlutterBoost.sInstance.mStateListener;
if(stateListener != null) { if(stateListener != null) {
...@@ -185,7 +185,8 @@ public class BoostFlutterView extends FrameLayout { ...@@ -185,7 +185,8 @@ public class BoostFlutterView extends FrameLayout {
} }
protected BoostFlutterEngine createFlutterEngine(Context context) { protected BoostFlutterEngine createFlutterEngine(Context context) {
return FlutterBoost.singleton().engineProvider().provideEngine(context); // return FlutterBoost.singleton().engineProvider().provideEngine(context);
return null;
} }
public void addFirstFrameRendered(OnFirstFrameRenderedListener listener) { public void addFirstFrameRendered(OnFirstFrameRenderedListener listener) {
...@@ -310,7 +311,7 @@ public class BoostFlutterView extends FrameLayout { ...@@ -310,7 +311,7 @@ public class BoostFlutterView extends FrameLayout {
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (mFlutterEngine != null) { if (mFlutterEngine != null) {
mFlutterEngine.getPluginRegistry().onRequestPermissionsResult(requestCode, permissions, grantResults); // mFlutterEngine.getPluginRegistry().onRequestPermissionsResult(requestCode, permissions, grantResults);
} else { } else {
Debuger.log("onRequestPermissionResult() invoked before BoostFlutterView was attached to an Activity."); Debuger.log("onRequestPermissionResult() invoked before BoostFlutterView was attached to an Activity.");
} }
...@@ -319,7 +320,7 @@ public class BoostFlutterView extends FrameLayout { ...@@ -319,7 +320,7 @@ public class BoostFlutterView extends FrameLayout {
public void onNewIntent(Intent intent) { public void onNewIntent(Intent intent) {
if (mFlutterEngine != null) { if (mFlutterEngine != null) {
mFlutterEngine.getPluginRegistry().onNewIntent(intent); // mFlutterEngine.getPluginRegistry().onNewIntent(intent);
} else { } else {
Debuger.log("onNewIntent() invoked before BoostFlutterView was attached to an Activity."); Debuger.log("onNewIntent() invoked before BoostFlutterView was attached to an Activity.");
} }
...@@ -328,7 +329,7 @@ public class BoostFlutterView extends FrameLayout { ...@@ -328,7 +329,7 @@ public class BoostFlutterView extends FrameLayout {
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (mFlutterEngine != null) { if (mFlutterEngine != null) {
mFlutterEngine.getPluginRegistry().onActivityResult(requestCode, resultCode, data); // mFlutterEngine.getPluginRegistry().onActivityResult(requestCode, resultCode, data);
} else { } else {
Debuger.log("onActivityResult() invoked before BoostFlutterView was attached to an Activity."); Debuger.log("onActivityResult() invoked before BoostFlutterView was attached to an Activity.");
} }
...@@ -336,7 +337,7 @@ public class BoostFlutterView extends FrameLayout { ...@@ -336,7 +337,7 @@ public class BoostFlutterView extends FrameLayout {
public void onUserLeaveHint() { public void onUserLeaveHint() {
if (mFlutterEngine != null) { if (mFlutterEngine != null) {
mFlutterEngine.getPluginRegistry().onUserLeaveHint(); // mFlutterEngine.getPluginRegistry().onUserLeaveHint();
} else { } else {
Debuger.log("onUserLeaveHint() invoked before BoostFlutterView was attached to an Activity."); Debuger.log("onUserLeaveHint() invoked before BoostFlutterView was attached to an Activity.");
} }
......
package com.idlefish.flutterboost;
import android.app.Activity;
import android.content.Context;
import com.idlefish.flutterboost.interfaces.IContainerRecord;
import io.flutter.app.FlutterPluginRegistry;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.platform.PlatformViewRegistry;
import io.flutter.view.FlutterView;
import io.flutter.view.TextureRegistry;
import java.lang.ref.WeakReference;
public class BoostPluginRegistry extends FlutterPluginRegistry {
protected WeakReference<Activity> mCurrentActivityRef;
private FlutterEngine mEngine;
public BoostPluginRegistry(FlutterEngine engine, Context context) {
super(engine, context);
mEngine = engine;
}
public PluginRegistry.Registrar registrarFor(String pluginKey) {
return new BoostRegistrar(mEngine, super.registrarFor(pluginKey));
}
public class BoostRegistrar implements PluginRegistry.Registrar {
private final PluginRegistry.Registrar mRegistrar;
private final FlutterEngine mEngine;
BoostRegistrar(FlutterEngine engine, PluginRegistry.Registrar registrar) {
mRegistrar = registrar;
mEngine = engine;
}
@Override
public Activity activity() {
Activity activity;
IContainerRecord record;
record = FlutterBoost.singleton().containerManager().getCurrentTopRecord();
if (record == null) {
record = FlutterBoost.singleton().containerManager().getLastGenerateRecord();
}
if (record == null) {
activity = FlutterBoost.singleton().currentActivity();
} else {
activity = record.getContainer().getContextActivity();
}
if (activity == null && mCurrentActivityRef != null) {
activity = mCurrentActivityRef.get();
}
if (activity == null) {
throw new RuntimeException("current has no valid Activity yet");
}
return activity;
}
@Override
public Context context() {
return mRegistrar.context();
}
@Override
public Context activeContext() {
return mRegistrar.activeContext();
}
@Override
public BinaryMessenger messenger() {
return mEngine.getDartExecutor();
}
@Override
public TextureRegistry textures() {
return mEngine.getRenderer();
}
@Override
public PlatformViewRegistry platformViewRegistry() {
return mRegistrar.platformViewRegistry();
}
@Override
public FlutterView view() {
throw new RuntimeException("should not use!!!");
}
@Override
public String lookupKeyForAsset(String s) {
return mRegistrar.lookupKeyForAsset(s);
}
@Override
public String lookupKeyForAsset(String s, String s1) {
return mRegistrar.lookupKeyForAsset(s, s1);
}
@Override
public PluginRegistry.Registrar publish(Object o) {
return mRegistrar.publish(o);
}
@Override
public PluginRegistry.Registrar addRequestPermissionsResultListener(PluginRegistry.RequestPermissionsResultListener requestPermissionsResultListener) {
return mRegistrar.addRequestPermissionsResultListener(requestPermissionsResultListener);
}
@Override
public PluginRegistry.Registrar addActivityResultListener(PluginRegistry.ActivityResultListener activityResultListener) {
return mRegistrar.addActivityResultListener(activityResultListener);
}
@Override
public PluginRegistry.Registrar addNewIntentListener(PluginRegistry.NewIntentListener newIntentListener) {
return mRegistrar.addNewIntentListener(newIntentListener);
}
@Override
public PluginRegistry.Registrar addUserLeaveHintListener(PluginRegistry.UserLeaveHintListener userLeaveHintListener) {
return mRegistrar.addUserLeaveHintListener(userLeaveHintListener);
}
@Override
public PluginRegistry.Registrar addViewDestroyListener(PluginRegistry.ViewDestroyListener viewDestroyListener) {
return mRegistrar.addViewDestroyListener(viewDestroyListener);
}
}
}
...@@ -76,7 +76,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -76,7 +76,7 @@ public class ContainerRecord implements IContainerRecord {
} }
mState = STATE_CREATED; mState = STATE_CREATED;
mContainer.getBoostFlutterView().onResume(); // mContainer.getBoostFlutterView().onResume();
mProxy.create(); mProxy.create();
} }
...@@ -129,15 +129,15 @@ public class ContainerRecord implements IContainerRecord { ...@@ -129,15 +129,15 @@ public class ContainerRecord implements IContainerRecord {
mProxy.destroy(); mProxy.destroy();
mContainer.getBoostFlutterView().onDestroy(); // mContainer.getBoostFlutterView().onDestroy();
mManager.removeRecord(this); mManager.removeRecord(this);
mManager.setContainerResult(this,-1,-1,null); mManager.setContainerResult(this,-1,-1,null);
if (!mManager.hasContainerAppear()) { if (!mManager.hasContainerAppear()) {
mContainer.getBoostFlutterView().onPause(); // mContainer.getBoostFlutterView().onPause();
mContainer.getBoostFlutterView().onStop(); // mContainer.getBoostFlutterView().onStop();
} }
} }
...@@ -154,45 +154,80 @@ public class ContainerRecord implements IContainerRecord { ...@@ -154,45 +154,80 @@ public class ContainerRecord implements IContainerRecord {
map.put("name", mContainer.getContainerUrl()); map.put("name", mContainer.getContainerUrl());
map.put("uniqueId", mUniqueId); map.put("uniqueId", mUniqueId);
FlutterBoost.singleton().channel().sendEvent("lifecycle", map); NewFlutterBoost.instance().channel().sendEvent("lifecycle", map);
mContainer.getBoostFlutterView().onBackPressed(); // mContainer.getBoostFlutterView().onBackPressed();
} }
@Override @Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
mContainer.getBoostFlutterView().onRequestPermissionsResult(requestCode, permissions, grantResults);
} }
@Override @Override
public void onNewIntent(Intent intent) { public void onNewIntent(Intent intent) {
mContainer.getBoostFlutterView().onNewIntent(intent);
} }
@Override @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onActivityResult(int requestCode, int resultCode, Intent data) {
mContainer.getBoostFlutterView().onActivityResult(requestCode, resultCode, data);
} }
@Override @Override
public void onContainerResult(int requestCode, int resultCode, Map<String, Object> result) { public void onContainerResult(int requestCode, int resultCode, Map<String, Object> result) {
mManager.setContainerResult(this, requestCode,resultCode, result);
} }
@Override @Override
public void onUserLeaveHint() { public void onUserLeaveHint() {
mContainer.getBoostFlutterView().onUserLeaveHint();
} }
@Override @Override
public void onTrimMemory(int level) { public void onTrimMemory(int level) {
mContainer.getBoostFlutterView().onTrimMemory(level);
} }
@Override @Override
public void onLowMemory() { public void onLowMemory() {
mContainer.getBoostFlutterView().onLowMemory();
} }
//
// @Override
// public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
// mContainer.getBoostFlutterView().onRequestPermissionsResult(requestCode, permissions, grantResults);
// }
//
// @Override
// public void onNewIntent(Intent intent) {
// mContainer.getBoostFlutterView().onNewIntent(intent);
// }
//
// @Override
// public void onActivityResult(int requestCode, int resultCode, Intent data) {
// mContainer.getBoostFlutterView().onActivityResult(requestCode, resultCode, data);
// }
//
// @Override
// public void onContainerResult(int requestCode, int resultCode, Map<String, Object> result) {
// mManager.setContainerResult(this, requestCode,resultCode, result);
// }
//
// @Override
// public void onUserLeaveHint() {
// mContainer.getBoostFlutterView().onUserLeaveHint();
// }
//
// @Override
// public void onTrimMemory(int level) {
// mContainer.getBoostFlutterView().onTrimMemory(level);
// }
//
// @Override
// public void onLowMemory() {
// mContainer.getBoostFlutterView().onLowMemory();
// }
private class MethodChannelProxy { private class MethodChannelProxy {
...@@ -252,7 +287,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -252,7 +287,7 @@ public class ContainerRecord implements IContainerRecord {
args.put("pageName", url); args.put("pageName", url);
args.put("params", params); args.put("params", params);
args.put("uniqueId", uniqueId); args.put("uniqueId", uniqueId);
FlutterBoost.singleton().channel().invokeMethod(method, args); NewFlutterBoost.instance().channel().invokeMethod(method, args);
} }
public void invokeChannelUnsafe(String method, String url, Map params, String uniqueId) { public void invokeChannelUnsafe(String method, String url, Map params, String uniqueId) {
...@@ -260,7 +295,7 @@ public class ContainerRecord implements IContainerRecord { ...@@ -260,7 +295,7 @@ public class ContainerRecord implements IContainerRecord {
args.put("pageName", url); args.put("pageName", url);
args.put("params", params); args.put("params", params);
args.put("uniqueId", uniqueId); args.put("uniqueId", uniqueId);
FlutterBoost.singleton().channel().invokeMethodUnsafe(method, args); NewFlutterBoost.instance().channel().invokeMethodUnsafe(method, args);
} }
} }
......
...@@ -51,11 +51,11 @@ public class FlutterBoost { ...@@ -51,11 +51,11 @@ public class FlutterBoost {
sInstance = new FlutterBoost(platform); sInstance = new FlutterBoost(platform);
} }
if (platform.whenEngineStart() == IPlatform.IMMEDIATELY) { // if (platform.whenEngineStart() == IPlatform.IMMEDIATELY) {
sInstance.mEngineProvider // sInstance.mEngineProvider
.provideEngine(platform.getApplication()) // .provideEngine(platform.getApplication())
.startRun(null); // .startRun(null);
} // }
} }
public static FlutterBoost singleton() { public static FlutterBoost singleton() {
...@@ -84,9 +84,9 @@ public class FlutterBoost { ...@@ -84,9 +84,9 @@ public class FlutterBoost {
mEngineProvider = provider; mEngineProvider = provider;
platform.getApplication().registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks()); platform.getApplication().registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks());
BoostChannel.addActionAfterRegistered(new BoostChannel.ActionAfterRegistered() { FlutterBoostPlugin.addActionAfterRegistered(new FlutterBoostPlugin.ActionAfterRegistered() {
@Override @Override
public void onChannelRegistered(BoostChannel channel) { public void onChannelRegistered(FlutterBoostPlugin channel) {
channel.addMethodCallHandler(new BoostMethodHandler()); channel.addMethodCallHandler(new BoostMethodHandler());
} }
}); });
...@@ -104,8 +104,8 @@ public class FlutterBoost { ...@@ -104,8 +104,8 @@ public class FlutterBoost {
return sInstance.mPlatform; return sInstance.mPlatform;
} }
public BoostChannel channel() { public FlutterBoostPlugin channel() {
return BoostChannel.singleton(); return FlutterBoostPlugin.singleton();
} }
public Activity currentActivity() { public Activity currentActivity() {
...@@ -124,9 +124,9 @@ public class FlutterBoost { ...@@ -124,9 +124,9 @@ public class FlutterBoost {
@Override @Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) { public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
if (platform().whenEngineStart() == IPlatform.ANY_ACTIVITY_CREATED) { if (platform().whenEngineStart() == IPlatform.ANY_ACTIVITY_CREATED) {
sInstance.mEngineProvider // sInstance.mEngineProvider
.provideEngine(activity) // .provideEngine(activity)
.startRun(activity); // .startRun(activity);
} }
} }
......
...@@ -111,9 +111,9 @@ public class FlutterViewContainerManager implements IContainerManager { ...@@ -111,9 +111,9 @@ public class FlutterViewContainerManager implements IContainerManager {
} }
void openContainer(String url, Map<String, Object> urlParams, Map<String, Object> exts,OnResult onResult) { void openContainer(String url, Map<String, Object> urlParams, Map<String, Object> exts,OnResult onResult) {
Context context = FlutterBoost.singleton().currentActivity(); Context context = NewFlutterBoost.instance().currentActivity();
if(context == null) { if(context == null) {
context = FlutterBoost.singleton().platform().getApplication(); context =NewFlutterBoost.instance().platform().getApplication();
} }
if(urlParams == null) { if(urlParams == null) {
...@@ -132,7 +132,7 @@ public class FlutterViewContainerManager implements IContainerManager { ...@@ -132,7 +132,7 @@ public class FlutterViewContainerManager implements IContainerManager {
mOnResults.put(uniqueId,onResult); mOnResults.put(uniqueId,onResult);
} }
FlutterBoost.singleton().platform().openContainer(context,url,urlParams,requestCode,exts); NewFlutterBoost.instance().platform().openContainer(context,url,urlParams,requestCode,exts);
} }
IContainerRecord closeContainer(String uniqueId, Map<String, Object> result,Map<String,Object> exts) { IContainerRecord closeContainer(String uniqueId, Map<String, Object> result,Map<String,Object> exts) {
...@@ -148,7 +148,7 @@ public class FlutterViewContainerManager implements IContainerManager { ...@@ -148,7 +148,7 @@ public class FlutterViewContainerManager implements IContainerManager {
Debuger.exception("closeContainer can not find uniqueId:" + uniqueId); Debuger.exception("closeContainer can not find uniqueId:" + uniqueId);
} }
FlutterBoost.singleton().platform().closeContainer(targetRecord,result,exts); NewFlutterBoost.instance().platform().closeContainer(targetRecord,result,exts);
return targetRecord; return targetRecord;
} }
......
package com.idlefish.flutterboost;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import com.idlefish.flutterboost.interfaces.*;
import io.flutter.app.FlutterPluginRegistry;
import io.flutter.embedding.engine.FlutterEngine;
import java.util.HashMap;
import java.util.Map;
public class NewFlutterBoost {
private Platform mPlatform;
private FlutterViewContainerManager mManager;
private IFlutterEngineProvider mEngineProvider;
private Activity mCurrentActiveActivity;
static NewFlutterBoost sInstance = null;
public static NewFlutterBoost instance() {
if (sInstance == null) {
sInstance = new NewFlutterBoost();
}
return sInstance;
}
public void init(Platform platform) {
mPlatform = platform;
mManager = new FlutterViewContainerManager();
mEngineProvider = platform.engineProvider();
platform.getApplication().registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
if (mPlatform.whenEngineStart() == IPlatform.ANY_ACTIVITY_CREATED) {
}
}
@Override
public void onActivityStarted(Activity activity) {
if (mCurrentActiveActivity == null) {
Debuger.log("Application entry foreground");
if (NewFlutterBoost.instance().engineProvider().tryGetEngine() != null) {
HashMap<String, String> map = new HashMap<>();
map.put("type", "foreground");
channel().sendEvent("lifecycle", map);
}
}
mCurrentActiveActivity = activity;
}
@Override
public void onActivityResumed(Activity activity) {
mCurrentActiveActivity = activity;
}
@Override
public void onActivityPaused(Activity activity) {
}
@Override
public void onActivityStopped(Activity activity) {
if (mCurrentActiveActivity == activity) {
Debuger.log("Application entry background");
if (mEngineProvider.tryGetEngine() != null) {
HashMap<String, String> map = new HashMap<>();
map.put("type", "background");
channel().sendEvent("lifecycle", map);
}
mCurrentActiveActivity = null;
}
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
}
@Override
public void onActivityDestroyed(Activity activity) {
if (mCurrentActiveActivity == activity) {
Debuger.log("Application entry background");
if (mEngineProvider.tryGetEngine() != null) {
HashMap<String, String> map = new HashMap<>();
map.put("type", "background");
channel().sendEvent("lifecycle", map);
}
mCurrentActiveActivity = null;
}
}
});
BoostPluginRegistry registry=new BoostPluginRegistry(this.engineProvider().provideEngine(mPlatform.getApplication()),
mPlatform.getApplication());
mPlatform.registerPlugins(registry);
}
public static class ConfigBuilder {
protected static final String DEFAULT_DART_ENTRYPOINT = "main";
protected static final String DEFAULT_INITIAL_ROUTE = "/";
private String dartEntrypoint = DEFAULT_DART_ENTRYPOINT;
private String initialRoute = DEFAULT_INITIAL_ROUTE;
private boolean isDebug = false;
private int whenEngineStart = 1;
private Application mApp;
private INativeRouter router = null;
public ConfigBuilder(Application app, INativeRouter router) {
this.router = router;
this.mApp = app;
}
public ConfigBuilder dartEntrypoint(@NonNull String dartEntrypoint) {
this.dartEntrypoint = dartEntrypoint;
return this;
}
public ConfigBuilder isDebug(boolean isDebug) {
this.isDebug = isDebug;
return this;
}
public ConfigBuilder whenEngineStart(@NonNull int whenEngineStart) {
this.whenEngineStart = whenEngineStart;
return this;
}
public Platform build() {
Platform platform = new Platform() {
@Override
public Application getApplication() {
return ConfigBuilder.this.mApp;
}
public boolean isDebug() {
return ConfigBuilder.this.isDebug;
}
@Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) {
router.openContainer(context, url, urlParams, requestCode, exts);
}
@Override
public IFlutterEngineProvider engineProvider() {
return new BoostEngineProvider();
}
public int whenEngineStart() {
return ConfigBuilder.this.whenEngineStart;
}
};
return platform;
}
}
public IFlutterEngineProvider engineProvider() {
return sInstance.mEngineProvider;
}
public IContainerManager containerManager() {
return sInstance.mManager;
}
public IPlatform platform() {
return sInstance.mPlatform;
}
public FlutterBoostPlugin channel() {
return FlutterBoostPlugin.singleton();
}
public Activity currentActivity() {
return sInstance.mCurrentActiveActivity;
}
public IFlutterViewContainer findContainerById(String id) {
return mManager.findContainerById(id);
}
}
...@@ -16,7 +16,7 @@ public class StateListener implements IStateListener { ...@@ -16,7 +16,7 @@ public class StateListener implements IStateListener {
} }
@Override @Override
public void onChannelRegistered(PluginRegistry.Registrar registrar, BoostChannel channel) { public void onChannelRegistered(PluginRegistry.Registrar registrar, FlutterBoostPlugin channel) {
Debuger.log(">>onFlutterViewInited"); Debuger.log(">>onFlutterViewInited");
} }
......
...@@ -449,7 +449,7 @@ public class XFlutterView extends FrameLayout { ...@@ -449,7 +449,7 @@ public class XFlutterView extends FrameLayout {
this.flutterEngine = flutterEngine; this.flutterEngine = flutterEngine;
// initialize PlatformViewsController // initialize PlatformViewsController
this.flutterEngine.getPluginRegistry().getPlatformViewsController().attach(getContext(),flutterEngine.getRenderer(),flutterEngine.getDartExecutor()); // this.flutterEngine.getPluginRegistry().getPlatformViewsController().attach(getContext(),flutterEngine.getRenderer(),flutterEngine.getDartExecutor());
// Instruct our FlutterRenderer that we are now its designated RenderSurface. // Instruct our FlutterRenderer that we are now its designated RenderSurface.
this.flutterEngine.getRenderer().attachToRenderSurface(renderSurface); this.flutterEngine.getRenderer().attachToRenderSurface(renderSurface);
...@@ -533,8 +533,8 @@ public class XFlutterView extends FrameLayout { ...@@ -533,8 +533,8 @@ public class XFlutterView extends FrameLayout {
Log.d(TAG, "Detaching from Flutter Engine"); Log.d(TAG, "Detaching from Flutter Engine");
// detach platformviews in page in case memory leak // detach platformviews in page in case memory leak
flutterEngine.getPluginRegistry().getPlatformViewsController().detach(); // flutterEngine.getPluginRegistry().getPlatformViewsController().detach();
flutterEngine.getPluginRegistry().getPlatformViewsController().onFlutterViewDestroyed(); // flutterEngine.getPluginRegistry().getPlatformViewsController().onFlutterViewDestroyed();
// Inform the Android framework that it should retrieve a new InputConnection // Inform the Android framework that it should retrieve a new InputConnection
// now that the engine is detached. The new InputConnection will be null, which // now that the engine is detached. The new InputConnection will be null, which
......
package com.idlefish.flutterboost; package com.idlefish.flutterboost;
import android.content.Context; import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.text.Editable; import android.text.Editable;
import android.text.InputType; import android.text.InputType;
import android.text.Selection; import android.text.Selection;
...@@ -59,6 +61,11 @@ public class XTextInputPlugin { ...@@ -59,6 +61,11 @@ public class XTextInputPlugin {
setTextInputClient(textInputClientId, configuration); setTextInputClient(textInputClientId, configuration);
} }
@Override
public void setPlatformViewClient(int i) {
}
@Override @Override
public void setEditingState(TextInputChannel.TextEditState editingState) { public void setEditingState(TextInputChannel.TextEditState editingState) {
setTextInputEditingState(mView, editingState); setTextInputEditingState(mView, editingState);
...@@ -206,6 +213,7 @@ public class XTextInputPlugin { ...@@ -206,6 +213,7 @@ public class XTextInputPlugin {
} }
} }
@RequiresApi(api = Build.VERSION_CODES.CUPCAKE)
private void setTextInputEditingState(View view, TextInputChannel.TextEditState state) { private void setTextInputEditingState(View view, TextInputChannel.TextEditState state) {
if (!mRestartInputPending && state.text.equals(mEditable.toString())) { if (!mRestartInputPending && state.text.equals(mEditable.toString())) {
applyStateToSelection(state); applyStateToSelection(state);
......
...@@ -117,7 +117,8 @@ public abstract class BoostFlutterActivity extends Activity implements IFlutterV ...@@ -117,7 +117,8 @@ public abstract class BoostFlutterActivity extends Activity implements IFlutterV
} }
protected BoostFlutterEngine createFlutterEngine(){ protected BoostFlutterEngine createFlutterEngine(){
return FlutterBoost.singleton().engineProvider().provideEngine(this); // return FlutterBoost.singleton().engineProvider().provideEngine(this);
return null;
} }
protected BoostFlutterView createFlutterView(BoostFlutterEngine engine){ protected BoostFlutterView createFlutterView(BoostFlutterEngine engine){
...@@ -247,10 +248,10 @@ public abstract class BoostFlutterActivity extends Activity implements IFlutterV ...@@ -247,10 +248,10 @@ public abstract class BoostFlutterActivity extends Activity implements IFlutterV
return this; return this;
} }
@Override // @Override
public BoostFlutterView getBoostFlutterView() { // public BoostFlutterView getBoostFlutterView() {
return mFlutterView; // return mFlutterView;
} // }
@Override @Override
public void finishContainer(Map<String,Object> result) { public void finishContainer(Map<String,Object> result) {
......
...@@ -9,6 +9,11 @@ import java.util.Map; ...@@ -9,6 +9,11 @@ import java.util.Map;
public class BoostFlutterDefaultActivity extends BoostFlutterActivity { public class BoostFlutterDefaultActivity extends BoostFlutterActivity {
@Override
public FlutterSplashView getBoostFlutterView() {
return null;
}
@Override @Override
public String getContainerUrl() { public String getContainerUrl() {
return getIntent().getStringExtra("url"); return getIntent().getStringExtra("url");
......
...@@ -67,7 +67,8 @@ abstract public class BoostFlutterFragment extends Fragment implements IFlutterV ...@@ -67,7 +67,8 @@ abstract public class BoostFlutterFragment extends Fragment implements IFlutterV
} }
protected BoostFlutterEngine createFlutterEngine(){ protected BoostFlutterEngine createFlutterEngine(){
return FlutterBoost.singleton().engineProvider().provideEngine(getContext()); // return FlutterBoost.singleton().engineProvider().provideEngine(getContext());
return null;
} }
protected BoostFlutterView createFlutterView(BoostFlutterEngine engine){ protected BoostFlutterView createFlutterView(BoostFlutterEngine engine){
...@@ -140,10 +141,10 @@ abstract public class BoostFlutterFragment extends Fragment implements IFlutterV ...@@ -140,10 +141,10 @@ abstract public class BoostFlutterFragment extends Fragment implements IFlutterV
return getActivity(); return getActivity();
} }
@Override // @Override
public BoostFlutterView getBoostFlutterView() { // public BoostFlutterView getBoostFlutterView() {
return mFlutterView; // return mFlutterView;
} // }
@Override @Override
public void finishContainer(Map<String,Object> result) { public void finishContainer(Map<String,Object> result) {
......
...@@ -26,6 +26,8 @@ package com.idlefish.flutterboost.interfaces; ...@@ -26,6 +26,8 @@ package com.idlefish.flutterboost.interfaces;
import android.content.Context; import android.content.Context;
import com.idlefish.flutterboost.BoostFlutterEngine; import com.idlefish.flutterboost.BoostFlutterEngine;
import io.flutter.embedding.engine.FlutterEngine;
/** /**
* a flutter engine provider * a flutter engine provider
*/ */
...@@ -36,18 +38,18 @@ public interface IFlutterEngineProvider { ...@@ -36,18 +38,18 @@ public interface IFlutterEngineProvider {
* @param context * @param context
* @return * @return
*/ */
BoostFlutterEngine createEngine(Context context); FlutterEngine createEngine(Context context);
/** /**
* provide a flutter engine * provide a flutter engine
* @param context * @param context
* @return * @return
*/ */
BoostFlutterEngine provideEngine(Context context); FlutterEngine provideEngine(Context context);
/** /**
* may return null * may return null
* @return * @return
*/ */
BoostFlutterEngine tryGetEngine(); FlutterEngine tryGetEngine();
} }
...@@ -26,6 +26,7 @@ package com.idlefish.flutterboost.interfaces; ...@@ -26,6 +26,7 @@ package com.idlefish.flutterboost.interfaces;
import android.app.Activity; import android.app.Activity;
import com.idlefish.flutterboost.BoostFlutterView; import com.idlefish.flutterboost.BoostFlutterView;
import com.idlefish.flutterboost.containers.FlutterSplashView;
import java.util.Map; import java.util.Map;
...@@ -41,7 +42,7 @@ public interface IFlutterViewContainer { ...@@ -41,7 +42,7 @@ public interface IFlutterViewContainer {
* provide a flutter view * provide a flutter view
* @return * @return
*/ */
BoostFlutterView getBoostFlutterView(); FlutterSplashView getBoostFlutterView();
/** /**
* call to destroy the container * call to destroy the container
......
package com.idlefish.flutterboost.interfaces;
import android.content.Context;
import java.util.Map;
public interface INativeRouter {
void openContainer(Context context, String url, Map<String,Object> urlParams, int requestCode, Map<String,Object> exts);
void closeContainer(IContainerRecord record, Map<String,Object> result, Map<String,Object> exts);
}
package com.idlefish.flutterboost.interfaces; package com.idlefish.flutterboost.interfaces;
import com.idlefish.flutterboost.BoostChannel; import com.idlefish.flutterboost.FlutterBoostPlugin;
import com.idlefish.flutterboost.BoostFlutterEngine; import com.idlefish.flutterboost.BoostFlutterEngine;
import com.idlefish.flutterboost.BoostFlutterView; import com.idlefish.flutterboost.BoostFlutterView;
...@@ -9,7 +9,7 @@ import io.flutter.plugin.common.PluginRegistry; ...@@ -9,7 +9,7 @@ import io.flutter.plugin.common.PluginRegistry;
public interface IStateListener { public interface IStateListener {
void onEngineCreated(BoostFlutterEngine engine); void onEngineCreated(BoostFlutterEngine engine);
void onEngineStarted(BoostFlutterEngine engine); void onEngineStarted(BoostFlutterEngine engine);
void onChannelRegistered(PluginRegistry.Registrar registrar, BoostChannel channel); void onChannelRegistered(PluginRegistry.Registrar registrar, FlutterBoostPlugin channel);
void onFlutterViewInited(BoostFlutterEngine engine, BoostFlutterView flutterView); void onFlutterViewInited(BoostFlutterEngine engine, BoostFlutterView flutterView);
void beforeEngineAttach(BoostFlutterEngine engine, BoostFlutterView flutterView); void beforeEngineAttach(BoostFlutterEngine engine, BoostFlutterView flutterView);
void afterEngineAttached(BoostFlutterEngine engine, BoostFlutterView flutterView); void afterEngineAttached(BoostFlutterEngine engine, BoostFlutterView flutterView);
......
...@@ -25,7 +25,7 @@ apply plugin: 'com.android.application' ...@@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android { android {
compileSdkVersion 26 compileSdkVersion 28
lintOptions { lintOptions {
disable 'InvalidPackage' disable 'InvalidPackage'
...@@ -35,7 +35,7 @@ android { ...@@ -35,7 +35,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.taobao.idlefish.flutterboostexample" applicationId "com.taobao.idlefish.flutterboostexample"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 26 targetSdkVersion 28
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
...@@ -58,6 +58,6 @@ dependencies { ...@@ -58,6 +58,6 @@ dependencies {
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:support-v4:26.1.0' implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:appcompat-v7:26.1.0'
} }
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.taobao.idlefish.flutterboostexample"> package="com.taobao.idlefish.flutterboostexample">
<!-- The INTERNET permission is required for development. Specifically, <!-- The INTERNET permission is required for development. Specifically,
...@@ -33,6 +34,10 @@ ...@@ -33,6 +34,10 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".FlutterPageActivity" android:name=".FlutterPageActivity"
android:theme="@style/Theme.AppCompat" android:theme="@style/Theme.AppCompat"
...@@ -40,6 +45,15 @@ ...@@ -40,6 +45,15 @@
android:hardwareAccelerated="true" android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"/> android:windowSoftInputMode="adjustResize"/>
<activity
android:name="com.idlefish.flutterboost.containers.NewBoostFlutterActivity"
android:theme="@style/Theme.AppCompat"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize" >
<!--<meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/avd_hide_password"/>-->
</activity>
<activity <activity
android:name=".FlutterFragmentPageActivity" android:name=".FlutterFragmentPageActivity"
android:theme="@style/Theme.AppCompat" android:theme="@style/Theme.AppCompat"
......
...@@ -4,6 +4,7 @@ import android.os.Bundle; ...@@ -4,6 +4,7 @@ import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.idlefish.flutterboost.containers.BoostFlutterFragment; import com.idlefish.flutterboost.containers.BoostFlutterFragment;
import com.idlefish.flutterboost.containers.FlutterSplashView;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -25,6 +26,11 @@ public class FlutterFragment extends BoostFlutterFragment { ...@@ -25,6 +26,11 @@ public class FlutterFragment extends BoostFlutterFragment {
super.setArguments(args); super.setArguments(args);
} }
@Override
public FlutterSplashView getBoostFlutterView() {
return null;
}
@Override @Override
public String getContainerUrl() { public String getContainerUrl() {
return "flutterFragment"; return "flutterFragment";
......
package com.taobao.idlefish.flutterboostexample; package com.taobao.idlefish.flutterboostexample;
import com.idlefish.flutterboost.containers.BoostFlutterActivity; import com.idlefish.flutterboost.containers.BoostFlutterActivity;
import com.idlefish.flutterboost.containers.FlutterSplashView;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class FlutterPageActivity extends BoostFlutterActivity { public class FlutterPageActivity extends BoostFlutterActivity {
@Override
public FlutterSplashView getBoostFlutterView() {
return null;
}
/** /**
* 该方法返回当前Activity在Flutter层对应的name, * 该方法返回当前Activity在Flutter层对应的name,
* 混合栈将会在flutter层根据这个名字,在注册的Route表中查找对应的Widget * 混合栈将会在flutter层根据这个名字,在注册的Route表中查找对应的Widget
......
...@@ -3,66 +3,74 @@ package com.taobao.idlefish.flutterboostexample; ...@@ -3,66 +3,74 @@ package com.taobao.idlefish.flutterboostexample;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import com.idlefish.flutterboost.BoostChannel; import com.idlefish.flutterboost.*;
import com.idlefish.flutterboost.BoostEngineProvider; import com.idlefish.flutterboost.interfaces.IContainerRecord;
import com.idlefish.flutterboost.BoostFlutterEngine;
import com.idlefish.flutterboost.FlutterBoost;
import com.idlefish.flutterboost.Platform;
import com.idlefish.flutterboost.interfaces.IFlutterEngineProvider; import com.idlefish.flutterboost.interfaces.IFlutterEngineProvider;
import java.util.Map; import java.util.Map;
import com.idlefish.flutterboost.interfaces.INativeRouter;
import io.flutter.app.FlutterApplication; import io.flutter.app.FlutterApplication;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.view.FlutterMain;
public class MyApplication extends FlutterApplication { public class MyApplication extends FlutterApplication {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
//
// FlutterBoost.init(new Platform() {
//
// @Override
// public Application getApplication() {
// return MyApplication.this;
// }
//
// @Override
// public boolean isDebug() {
// return true;
// }
//
// @Override
// public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) {
// PageRouter.openPageByUrl(context, url, urlParams, requestCode);
// }
//
// @Override
// public IFlutterEngineProvider engineProvider() {
// return new BoostEngineProvider() {
// @Override
// public BoostFlutterEngine createEngine(Context context) {
// return new BoostFlutterEngine(context);
// }
// };
// }
//
// @Override
// public int whenEngineStart() {
// return ANY_ACTIVITY_CREATED;
// }
// });
FlutterBoost.init(new Platform() { // FlutterBoostPlugin.addActionAfterRegistered(new FlutterBoostPlugin.ActionAfterRegistered() {
// @Override
// public void onChannelRegistered(FlutterBoostPlugin channel) {
// //platform view register should use FlutterPluginRegistry instread of BoostPluginRegistry
// TextPlatformViewPlugin.register(FlutterBoost.singleton().engineProvider().tryGetEngine().getPluginRegistry());
// }
// });
@Override
public Application getApplication() {
return MyApplication.this;
}
@Override
public boolean isDebug() {
return true;
}
INativeRouter router =new INativeRouter() {
@Override @Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) { public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) {
PageRouter.openPageByUrl(context, url, urlParams, requestCode); PageRouter.openPageByUrl(context,url, urlParams);
}
@Override
public IFlutterEngineProvider engineProvider() {
return new BoostEngineProvider() {
@Override
public BoostFlutterEngine createEngine(Context context) {
return new BoostFlutterEngine(context, new DartExecutor.DartEntrypoint(
context.getResources().getAssets(),
FlutterMain.findAppBundlePath(context),
"main"), "/");
}
};
} }
@Override @Override
public int whenEngineStart() { public void closeContainer(IContainerRecord record, Map<String, Object> result, Map<String, Object> exts) {
return ANY_ACTIVITY_CREATED;
}
});
BoostChannel.addActionAfterRegistered(new BoostChannel.ActionAfterRegistered() {
@Override
public void onChannelRegistered(BoostChannel channel) {
//platform view register should use FlutterPluginRegistry instread of BoostPluginRegistry
TextPlatformViewPlugin.register(FlutterBoost.singleton().engineProvider().tryGetEngine().getPluginRegistry());
} }
}); };
Platform platform= new NewFlutterBoost.ConfigBuilder(this,router).build();
NewFlutterBoost.instance().init(platform);
} }
} }
...@@ -3,6 +3,7 @@ package com.taobao.idlefish.flutterboostexample; ...@@ -3,6 +3,7 @@ package com.taobao.idlefish.flutterboostexample;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.text.TextUtils; import android.text.TextUtils;
import com.idlefish.flutterboost.containers.NewBoostFlutterActivity;
import java.util.Map; import java.util.Map;
...@@ -19,10 +20,11 @@ public class PageRouter { ...@@ -19,10 +20,11 @@ public class PageRouter {
public static boolean openPageByUrl(Context context, String url, Map params, int requestCode) { public static boolean openPageByUrl(Context context, String url, Map params, int requestCode) {
try { try {
if (url.startsWith(FLUTTER_PAGE_URL)) { if (url.startsWith(FLUTTER_PAGE_URL)) {
context.startActivity(new Intent(context, FlutterPageActivity.class));
context.startActivity( NewBoostFlutterActivity.createDefaultIntent(context));
return true; return true;
} else if (url.startsWith(FLUTTER_FRAGMENT_PAGE_URL)) { } else if (url.startsWith(FLUTTER_FRAGMENT_PAGE_URL)) {
context.startActivity(new Intent(context, FlutterFragmentPageActivity.class)); // context.startActivity(new Intent(context, FlutterFragmentPageActivity.class));
return true; return true;
} else if (url.startsWith(NATIVE_PAGE_URL)) { } else if (url.startsWith(NATIVE_PAGE_URL)) {
context.startActivity(new Intent(context, NativePageActivity.class)); context.startActivity(new Intent(context, NativePageActivity.class));
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
// //
#import "GeneratedPluginRegistrant.h" #import "GeneratedPluginRegistrant.h"
#import <flutter_boost/BoostChannel.h> #import <flutter_boost/FlutterBoostPlugin.h>
@implementation GeneratedPluginRegistrant @implementation GeneratedPluginRegistrant
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry { + (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
[BoostChannel registerWithRegistrar:[registry registrarForPlugin:@"BoostChannel"]]; [FlutterBoostPlugin registerWithRegistrar:[registry registrarForPlugin:@"FlutterBoostPlugin"]];
} }
@end @end
...@@ -36,7 +36,7 @@ class _MyAppState extends State<MyApp> { ...@@ -36,7 +36,7 @@ class _MyAppState extends State<MyApp> {
return MaterialApp( return MaterialApp(
title: 'Flutter Boost example', title: 'Flutter Boost example',
builder: FlutterBoost.init(postPush: _onRoutePushed), builder: FlutterBoost.init(postPush: _onRoutePushed),
home: Container()); home: FlutterRouteWidget());
} }
void _onRoutePushed( void _onRoutePushed(
......
...@@ -19,7 +19,7 @@ dependencies: ...@@ -19,7 +19,7 @@ dependencies:
flutter: flutter:
plugin: plugin:
androidPackage: com.idlefish.flutterboost androidPackage: com.idlefish.flutterboost
pluginClass: BoostChannel pluginClass: FlutterBoostPlugin
# To add assets to your plugin package, add an assets section, like this: # To add assets to your plugin package, add an assets section, like this:
# assets: # assets:
......
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