Commit 8cf66572 authored by justin's avatar justin

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

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