Commit c1152ecf authored by justin's avatar justin

PluginsRegister 不再对外暴露,需要手动注册插件请使用 ...

PluginsRegister 不再对外暴露,需要手动注册插件请使用  FlutterBoost.instance().engineProvider().getPlugins().add(new FlutterPlugin());
parent 3359959d
......@@ -25,7 +25,6 @@ public class FlutterBoost {
private FlutterViewContainerManager mManager;
private FlutterEngine mEngine;
private Activity mCurrentActiveActivity;
private PluginRegistry mRegistry;
private boolean mEnterActivityCreate =false;
static FlutterBoost sInstance = null;
......@@ -64,11 +63,6 @@ public class FlutterBoost {
mCurrentActiveActivity = activity;
if (mPlatform.whenEngineStart() == ConfigBuilder.ANY_ACTIVITY_CREATED) {
doInitialFlutter();
boostPluginRegistry();
}
if (mPlatform.whenEngineStart() == ConfigBuilder.IMMEDIATELY) {
boostPluginRegistry();
}
}
......@@ -182,17 +176,9 @@ public class FlutterBoost {
);
flutterEngine.getDartExecutor().executeDartEntrypoint(entrypoint);
mRegistry = new BoostPluginRegistry(createEngine());
}
public void boostPluginRegistry(){
if(mRegistry!=null&& !mRegistry.hasPlugin("boostPluginRegistry")){
mPlatform.registerPlugins(mRegistry);
mRegistry.registrarFor("boostPluginRegistry");
}
}
public static class ConfigBuilder {
......@@ -323,9 +309,6 @@ public class FlutterBoost {
return mManager.findContainerById(id);
}
public PluginRegistry getPluginRegistry() {
return mRegistry;
}
private FlutterEngine createEngine() {
if (mEngine == null) {
......@@ -355,7 +338,6 @@ public class FlutterBoost {
mPlatform.lifecycleListener.onEngineDestroy();
}
mEngine = null;
mRegistry = null;
mCurrentActiveActivity = null;
}
......@@ -372,9 +354,4 @@ public class FlutterBoost {
}
public interface BoostPluginsRegister {
void registerPlugins(PluginRegistry mRegistry);
}
}
......@@ -11,6 +11,20 @@ import java.util.Map;
import io.flutter.embedding.android.FlutterView;
import io.flutter.plugin.common.PluginRegistry;
/**
* 插件注册方式 不在使用老的注册方式
*
* AndroidManifest.xml 中必须要添加 flutterEmbedding 版本设置
* <meta-data android:name="flutterEmbedding"
* android:value="2">
* </meta-data>
*
* GeneratedPluginRegistrant 会自动生成 新的插件方式 
*
* 插件注册方式请使用
* FlutterBoost.instance().engineProvider().getPlugins().add(new FlutterPlugin());
* GeneratedPluginRegistrant.registerWith(),是在engine 创建后马上执行,放射形式调用
*/
public abstract class Platform {
public abstract Application getApplication();
......@@ -28,7 +42,6 @@ public abstract class Platform {
public FlutterBoost.BoostLifecycleListener lifecycleListener;
public FlutterBoost.BoostPluginsRegister pluginsRegister;
public void closeContainer(IContainerRecord record, Map<String, Object> result, Map<String, Object> exts) {
if (record == null) return;
......@@ -37,22 +50,4 @@ public abstract class Platform {
}
public void registerPlugins(PluginRegistry mRegistry) {
if(pluginsRegister!=null){
pluginsRegister.registerPlugins(mRegistry);
}else{
try {
Class clz = Class.forName("io.flutter.plugins.GeneratedPluginRegistrant");
Method method = clz.getDeclaredMethod("registerWith", PluginRegistry.class);
method.invoke(null, mRegistry);
} catch (Throwable t) {
Log.i("flutterboost.platform",t.toString());
}
}
if (lifecycleListener!= null) {
lifecycleListener.onPluginsRegistered();
}
}
}
......@@ -20,7 +20,6 @@ import java.util.HashMap;
import java.util.Map;
import com.idlefish.flutterboost.BoostPluginRegistry;
import com.idlefish.flutterboost.FlutterBoost;
import com.idlefish.flutterboost.Utils;
import com.idlefish.flutterboost.XFlutterView;
......@@ -83,7 +82,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer
ensureAlive();
if (FlutterBoost.instance().platform().whenEngineStart() == FlutterBoost.ConfigBuilder.FLUTTER_ACTIVITY_CREATED) {
FlutterBoost.instance().doInitialFlutter();
FlutterBoost.instance().boostPluginRegistry();
}
// When "retain instance" is true, the FlutterEngine will survive configuration
// changes. Therefore, we create a new one only if one does not already exist.
......@@ -176,14 +174,13 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer
ensureAlive();
flutterEngine.getLifecycleChannel().appIsResumed();
BoostPluginRegistry registry = (BoostPluginRegistry) FlutterBoost.instance().getPluginRegistry();
ActivityPluginBinding binding = registry.getRegistrarAggregate().getActivityPluginBinding();
if (binding != null && (binding.getActivity() != this.host.getActivity())) {
flutterEngine.getActivityControlSurface().attachToActivity(
host.getActivity(),
host.getLifecycle()
);
}
}
......@@ -217,17 +214,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer
mSyncer.onDestroy();
ensureAlive();
BoostPluginRegistry registry = (BoostPluginRegistry) FlutterBoost.instance().getPluginRegistry();
if (registry != null) {
ActivityPluginBinding binding = registry.getRegistrarAggregate().getActivityPluginBinding();
if (binding != null && (binding.getActivity() == this.host.getActivity())) {
registry.getRegistrarAggregate().onDetachedFromActivityForConfigChanges();
flutterEngine.getActivityControlSurface().detachFromActivityForConfigChanges();
}
}
flutterView.release();
}
......
......@@ -10,6 +10,7 @@ import java.util.Map;
import com.idlefish.flutterboost.interfaces.INativeRouter;
import io.flutter.embedding.android.FlutterView;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.GeneratedPluginRegistrant;
......@@ -62,7 +63,11 @@ public class MyApplication extends Application {
// </meta-data>
// GeneratedPluginRegistrant 会自动生成 新的插件方式 
//
// 插件注册方式请使用
// FlutterBoost.instance().engineProvider().getPlugins().add(new FlutterPlugin());
// GeneratedPluginRegistrant.registerWith(),是在engine 创建后马上执行,放射形式调用
//
Platform platform= new FlutterBoost
.ConfigBuilder(this,router)
.isDebug(true)
......@@ -70,7 +75,6 @@ public class MyApplication extends Application {
.renderMode(FlutterView.RenderMode.texture)
.lifecycleListener(boostLifecycleListener)
.build();
FlutterBoost.instance().init(platform);
......
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