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

pluginsRegister modify

parent dd5de6ac
...@@ -150,7 +150,7 @@ public class FlutterBoost { ...@@ -150,7 +150,7 @@ public class FlutterBoost {
flutterEngine.getDartExecutor().executeDartEntrypoint(entrypoint); flutterEngine.getDartExecutor().executeDartEntrypoint(entrypoint);
mRegistry = new BoostPluginRegistry(createEngine()); mRegistry = new BoostPluginRegistry(createEngine());
registerPlugins(); mPlatform.registerPlugins(mRegistry);
} }
...@@ -185,6 +185,10 @@ public class FlutterBoost { ...@@ -185,6 +185,10 @@ public class FlutterBoost {
private BoostLifecycleListener lifecycleListener; private BoostLifecycleListener lifecycleListener;
private BoostPluginsRegister boostPluginsRegister;
public ConfigBuilder(Application app, INativeRouter router) { public ConfigBuilder(Application app, INativeRouter router) {
this.router = router; this.router = router;
this.mApp = app; this.mApp = app;
...@@ -224,7 +228,10 @@ public class FlutterBoost { ...@@ -224,7 +228,10 @@ public class FlutterBoost {
this.lifecycleListener = lifecycleListener; this.lifecycleListener = lifecycleListener;
return this; return this;
} }
public ConfigBuilder pluginsRegister(BoostPluginsRegister boostPluginsRegister) {
this.boostPluginsRegister = boostPluginsRegister;
return this;
}
public Platform build() { public Platform build() {
Platform platform = new Platform() { Platform platform = new Platform() {
...@@ -263,7 +270,7 @@ public class FlutterBoost { ...@@ -263,7 +270,7 @@ public class FlutterBoost {
}; };
platform.lifecycleListener = this.lifecycleListener; platform.lifecycleListener = this.lifecycleListener;
platform.pluginsRegister=this.boostPluginsRegister;
return platform; return platform;
} }
...@@ -309,22 +316,6 @@ public class FlutterBoost { ...@@ -309,22 +316,6 @@ public class FlutterBoost {
} }
private void registerPlugins() {
try {
Class clz = Class.forName("io.flutter.plugins.GeneratedPluginRegistrant");
Method method = clz.getDeclaredMethod("registerWith", PluginRegistry.class);
method.invoke(null, mRegistry);
} catch (Throwable t) {
throw new RuntimeException(t);
}
if (mPlatform.lifecycleListener != null) {
mPlatform.lifecycleListener.onPluginsRegistered();
}
}
public FlutterEngine engineProvider() { public FlutterEngine engineProvider() {
return mEngine; return mEngine;
} }
...@@ -351,4 +342,10 @@ public class FlutterBoost { ...@@ -351,4 +342,10 @@ public class FlutterBoost {
void onEngineDestroy(); void onEngineDestroy();
} }
public interface BoostPluginsRegister {
void registerPlugins(PluginRegistry mRegistry);
}
} }
...@@ -4,9 +4,11 @@ import android.app.Application; ...@@ -4,9 +4,11 @@ import android.app.Application;
import android.content.Context; import android.content.Context;
import com.idlefish.flutterboost.interfaces.IContainerRecord; import com.idlefish.flutterboost.interfaces.IContainerRecord;
import java.lang.reflect.Method;
import java.util.Map; import java.util.Map;
import io.flutter.embedding.android.FlutterView; import io.flutter.embedding.android.FlutterView;
import io.flutter.plugin.common.PluginRegistry;
public abstract class Platform { public abstract class Platform {
...@@ -26,6 +28,8 @@ public abstract class Platform { ...@@ -26,6 +28,8 @@ 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;
...@@ -33,4 +37,21 @@ public abstract class Platform { ...@@ -33,4 +37,21 @@ public abstract class Platform {
} }
public void registerPlugins(PluginRegistry mRegistry) {
try {
Class clz = Class.forName("io.flutter.plugins.GeneratedPluginRegistrant");
Method method = clz.getDeclaredMethod("registerWith", PluginRegistry.class);
method.invoke(null, mRegistry);
} catch (Throwable t) {
throw new RuntimeException(t);
}
if(pluginsRegister!=null){
pluginsRegister.registerPlugins(mRegistry);
}
if (lifecycleListener!= null) {
lifecycleListener.onPluginsRegistered();
}
}
} }
...@@ -11,6 +11,8 @@ import java.util.Map; ...@@ -11,6 +11,8 @@ 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.plugin.common.MethodChannel; import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MyApplication extends Application { public class MyApplication extends Application {
...@@ -18,6 +20,7 @@ public class MyApplication extends Application { ...@@ -18,6 +20,7 @@ public class MyApplication extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
INativeRouter router =new INativeRouter() { 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) {
...@@ -27,31 +30,21 @@ public class MyApplication extends Application { ...@@ -27,31 +30,21 @@ public class MyApplication extends Application {
}; };
FlutterBoost.BoostLifecycleListener lifecycleListener= new FlutterBoost.BoostLifecycleListener() { FlutterBoost.BoostPluginsRegister pluginsRegister= new FlutterBoost.BoostPluginsRegister(){
@Override
public void onEngineCreated() {
}
@Override
public void onPluginsRegistered() {
MethodChannel mMethodChannel = new MethodChannel( FlutterBoost.instance().engineProvider().getDartExecutor(), "methodChannel");
Log.e("MyApplication","MethodChannel create");
TextPlatformViewPlugin.register(FlutterBoost.instance().getPluginRegistry().registrarFor("TextPlatformViewPlugin"));
}
@Override @Override
public void onEngineDestroy() { public void registerPlugins(PluginRegistry mRegistry) {
GeneratedPluginRegistrant.registerWith(mRegistry);
TextPlatformViewPlugin.register(mRegistry.registrarFor("TextPlatformViewPlugin"));
} }
}; };
Platform platform= new FlutterBoost Platform platform= new FlutterBoost
.ConfigBuilder(this,router) .ConfigBuilder(this,router)
.isDebug(true) .isDebug(true)
.whenEngineStart(FlutterBoost.ConfigBuilder.ANY_ACTIVITY_CREATED) .whenEngineStart(FlutterBoost.ConfigBuilder.ANY_ACTIVITY_CREATED)
.renderMode(FlutterView.RenderMode.texture) .renderMode(FlutterView.RenderMode.texture)
.lifecycleListener(lifecycleListener) .pluginsRegister(pluginsRegister)
.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