Commit 0e7d161c authored by Yacumima's avatar Yacumima

improve

parent c97e6421
......@@ -42,6 +42,6 @@ dependencies {
ext {
groupId = 'com.taobao.fleamarket'
artifactId = "FlutterBoost"
artifactId = "FlutterBoostPlugin"
}
......@@ -23,36 +23,23 @@
*/
package com.taobao.idlefish.flutterboost;
import android.app.Activity;
import android.content.Context;
import android.os.Looper;
import android.support.annotation.NonNull;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterEngineProvider;
import com.taobao.idlefish.flutterboost.interfaces.IStateListener;
import io.flutter.app.FlutterPluginRegistry;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.platform.PlatformViewRegistry;
import io.flutter.view.FlutterMain;
import io.flutter.view.FlutterNativeView;
import io.flutter.view.FlutterView;
import io.flutter.view.TextureRegistry;
public class BoostEngineProvider implements IFlutterEngineProvider {
static final BoostEngineProvider sInstance = new BoostEngineProvider();
private BoostFlutterEngine mEngine = null;
private BoostEngine mEngine = null;
private BoostEngineProvider() {
BoostEngineProvider() {
}
@Override
public FlutterEngine createEngine(Context context) {
public BoostFlutterEngine createEngine(Context context) {
Utils.assertCallOnMainThread();
......@@ -61,35 +48,25 @@ public class BoostEngineProvider implements IFlutterEngineProvider {
FlutterMain.ensureInitializationComplete(
context.getApplicationContext(), flutterShellArgs.toArray());
mEngine = new BoostEngine(context.getApplicationContext());
mEngine.startRun();
mEngine = new BoostFlutterEngine(context.getApplicationContext());
final IStateListener stateListener = FlutterBoostPlugin.sInstance.mStateListener;
if(stateListener != null) {
stateListener.onEngineCreated(mEngine);
}
}
return mEngine;
}
@Override
public FlutterEngine tryGetEngine() {
public BoostFlutterEngine tryGetEngine() {
return mEngine;
}
public static class BoostEngine extends FlutterEngine {
final Context mContext;
public BoostEngine(@NonNull Context context) {
super(context);
mContext = context;
}
public void startRun() {
if (!getDartExecutor().isExecutingDart()) {
getNavigationChannel().setInitialRoute("/");
DartExecutor.DartEntrypoint entryPoint = new DartExecutor.DartEntrypoint(
mContext.getResources().getAssets(),
FlutterMain.findAppBundlePath(mContext),
"main");
getDartExecutor().executeDartEntrypoint(entryPoint);
}
public static void assertEngineRunning(){
final BoostFlutterEngine engine = FlutterBoostPlugin.singleton().engineProvider().tryGetEngine();
if(engine == null || !engine.isRunning()) {
throw new RuntimeException("engine is not running yet!");
}
}
}
......@@ -2,44 +2,116 @@ package com.taobao.idlefish.flutterboost;
import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.taobao.idlefish.flutterboost.interfaces.IContainerRecord;
import com.taobao.idlefish.flutterboost.interfaces.IStateListener;
import java.lang.ref.WeakReference;
import io.flutter.app.FlutterPluginRegistry;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.platform.PlatformViewRegistry;
import io.flutter.view.FlutterMain;
import io.flutter.view.FlutterView;
import io.flutter.view.TextureRegistry;
public class BoostPluginRegistry extends FlutterPluginRegistry {
private final FlutterEngine mEngine;
private final Activity mActivity;
public class BoostFlutterEngine extends FlutterEngine {
protected final Context mContext;
protected final BoostPluginRegistry mBoostPluginRegistry;
protected WeakReference<Activity> mCurrentActivityRef;
public BoostFlutterEngine(@NonNull Context context) {
super(context);
mContext = context.getApplicationContext();
mBoostPluginRegistry = new BoostPluginRegistry(this,context);
}
public void startRun(@Nullable Activity activity) {
mCurrentActivityRef = new WeakReference<>(activity);
if (!getDartExecutor().isExecutingDart()) {
public BoostPluginRegistry(FlutterEngine engine, Activity activity) {
super(engine, activity);
mEngine = engine;
mActivity = activity;
Debuger.log("engine start running...");
getNavigationChannel().setInitialRoute("/");
DartExecutor.DartEntrypoint entryPoint = new DartExecutor.DartEntrypoint(
mContext.getResources().getAssets(),
FlutterMain.findAppBundlePath(mContext),
"main");
getDartExecutor().executeDartEntrypoint(entryPoint);
final IStateListener stateListener = FlutterBoostPlugin.sInstance.mStateListener;
if(stateListener != null) {
stateListener.onEngineStarted(this);
}
FlutterBoostPlugin.singleton().platform().onRegisterPlugins(mBoostPluginRegistry);
}
}
public PluginRegistry.Registrar registrarFor(String pluginKey) {
return new BoostRegistrar(mActivity,mEngine,super.registrarFor(pluginKey));
public BoostPluginRegistry getBoostPluginRegistry(){
return mBoostPluginRegistry;
}
public static class BoostRegistrar implements PluginRegistry.Registrar {
public boolean isRunning(){
return getDartExecutor().isExecutingDart();
}
public class BoostPluginRegistry extends FlutterPluginRegistry {
private final 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;
private final Activity mActivity;
BoostRegistrar(Activity activity, FlutterEngine engine, PluginRegistry.Registrar registrar) {
BoostRegistrar(FlutterEngine engine, PluginRegistry.Registrar registrar) {
mRegistrar = registrar;
mEngine = engine;
mActivity = activity;
}
@Override
public Activity activity() {
return mActivity;
Activity activity;
IContainerRecord record;
record = FlutterBoostPlugin.singleton().containerManager().getCurrentTopRecord();
if(record == null) {
record = FlutterBoostPlugin.singleton().containerManager().getLastGenerateRecord();
}
if(record == null){
activity = FlutterBoostPlugin.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
......
......@@ -26,22 +26,30 @@ package com.taobao.idlefish.flutterboost;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.view.ViewCompat;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.taobao.idlefish.flutterboost.interfaces.IStateListener;
import java.util.LinkedList;
import java.util.List;
import io.flutter.embedding.android.FlutterView;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener;
import io.flutter.plugin.platform.PlatformPlugin;
public class BoostFlutterView extends FrameLayout {
private FlutterEngine mFlutterEngine;
private BoostFlutterEngine mFlutterEngine;
private FlutterView mFlutterView;
......@@ -49,24 +57,35 @@ public class BoostFlutterView extends FrameLayout {
private Bundle mArguments;
private BoostPluginRegistry mBoostPluginRegistry;
private RenderingProgressCoverCreator mRenderingProgressCoverCreator;
private View mRenderingProgressCover;
private final List<OnFirstFrameRenderedListener> mFirstFrameRenderedListeners = new LinkedList<>();
private final OnFirstFrameRenderedListener mOnFirstFrameRenderedListener = new OnFirstFrameRenderedListener() {
private boolean mNeedSnapshotWhenDetach = true;
private ImageView mSnapshot;
private final io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener mOnFirstFrameRenderedListener =
new io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener() {
@Override
public void onFirstFrameRendered() {
if(mRenderingProgressCover != null && mRenderingProgressCover.getParent() != null) {
((ViewGroup)mRenderingProgressCover.getParent()).removeView(mRenderingProgressCover);
}
final Object[] listeners = mFirstFrameRenderedListeners.toArray();
for (Object obj : listeners) {
((OnFirstFrameRenderedListener) obj).onFirstFrameRendered();
((OnFirstFrameRenderedListener) obj).onFirstFrameRendered(BoostFlutterView.this);
}
}
};
public BoostFlutterView(Context context, FlutterEngine engine, Bundle args) {
public BoostFlutterView(Context context, BoostFlutterEngine engine, Bundle args, RenderingProgressCoverCreator creator) {
super(context);
mFlutterEngine = engine;
mArguments = args;
mRenderingProgressCoverCreator = creator;
init();
}
......@@ -85,14 +104,63 @@ public class BoostFlutterView extends FrameLayout {
addView(mFlutterView, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
if(mRenderingProgressCoverCreator != null) {
mRenderingProgressCover = mRenderingProgressCoverCreator
.createRenderingProgressCover(getContext());
}else{
mRenderingProgressCover = createRenderingProgressCorver();
}
if(mRenderingProgressCover != null) {
addView(mRenderingProgressCover, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
mSnapshot = new ImageView(getContext());
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
params.gravity = Gravity.CENTER;
mSnapshot.setLayoutParams(params);
mFlutterView.addOnFirstFrameRenderedListener(mOnFirstFrameRenderedListener);
mBoostPluginRegistry = new BoostPluginRegistry(mFlutterEngine,(Activity)getContext());
FlutterBoostPlugin.platform().onRegisterPlugins(mBoostPluginRegistry);
mFlutterEngine.startRun((Activity)getContext());
final IStateListener stateListener = FlutterBoostPlugin.sInstance.mStateListener;
if(stateListener != null) {
stateListener.onFlutterViewInited(mFlutterEngine,this);
}
}
protected FlutterEngine createFlutterEngine(Context context) {
return BoostEngineProvider.sInstance.createEngine(context);
protected View createRenderingProgressCorver(){
FrameLayout frameLayout = new FrameLayout(getContext());
frameLayout.setBackgroundColor(Color.WHITE);
LinearLayout linearLayout = new LinearLayout(getContext());
linearLayout.setOrientation(LinearLayout.VERTICAL);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER;
frameLayout.addView(linearLayout,layoutParams);
ProgressBar progressBar = new ProgressBar(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER_HORIZONTAL;
linearLayout.addView(progressBar,params);
TextView textView = new TextView(getContext());
params = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER_HORIZONTAL;
textView.setText("Frame Rendering...");
linearLayout.addView(textView,params);
return frameLayout;
}
protected BoostFlutterEngine createFlutterEngine(Context context) {
return FlutterBoostPlugin.singleton().engineProvider().createEngine(context);
}
public void addFirstFrameRendered(OnFirstFrameRenderedListener listener) {
......@@ -119,6 +187,11 @@ public class BoostFlutterView extends FrameLayout {
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mPlatformPlugin.onPostResume();
ViewCompat.requestApplyInsets(this);
}
public BoostFlutterEngine getEngine(){
return mFlutterEngine;
}
public void onResume() {
......@@ -143,13 +216,32 @@ public class BoostFlutterView extends FrameLayout {
public void onAttach() {
Debuger.log("BoostFlutterView onAttach");
final IStateListener stateListener = FlutterBoostPlugin.sInstance.mStateListener;
if(stateListener != null) {
stateListener.beforeEngineAttach(mFlutterEngine,this);
}
mFlutterView.attachToFlutterEngine(mFlutterEngine);
if(stateListener != null) {
stateListener.afterEngineAttached(mFlutterEngine,this);
}
}
public void onDetach() {
Debuger.log("BoostFlutterView onDetach");
if(mNeedSnapshotWhenDetach) {
//mFlutterView.
}
mFlutterView.removeOnFirstFrameRenderedListener(mOnFirstFrameRenderedListener);
final IStateListener stateListener = FlutterBoostPlugin.sInstance.mStateListener;
if(stateListener != null) {
stateListener.beforeEngineDetach(mFlutterEngine,this);
}
mFlutterView.detachFromFlutterEngine();
if(stateListener != null) {
stateListener.afterEngineDetached(mFlutterEngine,this);
}
}
public void onDestroy() {
......@@ -226,9 +318,10 @@ public class BoostFlutterView extends FrameLayout {
public static class Builder {
private Context context;
private FlutterEngine engine;
private BoostFlutterEngine engine;
private FlutterView.RenderMode renderMode;
private FlutterView.TransparencyMode transparencyMode;
private RenderingProgressCoverCreator renderingProgressCoverCreator;
public Builder(Context ctx) {
this.context = ctx;
......@@ -236,7 +329,7 @@ public class BoostFlutterView extends FrameLayout {
transparencyMode = FlutterView.TransparencyMode.transparent;
}
public Builder flutterEngine(FlutterEngine engine) {
public Builder flutterEngine(BoostFlutterEngine engine) {
this.engine = engine;
return this;
}
......@@ -247,6 +340,10 @@ public class BoostFlutterView extends FrameLayout {
return this;
}
public Builder renderingProgressCoverCreator(RenderingProgressCoverCreator creator) {
this.renderingProgressCoverCreator = creator;
return this;
}
public Builder transparencyMode(FlutterView.TransparencyMode transparencyMode) {
this.transparencyMode = transparencyMode;
......@@ -258,7 +355,15 @@ public class BoostFlutterView extends FrameLayout {
args.putString("flutterview_render_mode", renderMode != null ? renderMode.name() : FlutterView.RenderMode.surface.name());
args.putString("flutterview_transparency_mode", transparencyMode != null ? transparencyMode.name() : FlutterView.TransparencyMode.transparent.name());
return new BoostFlutterView(context, engine, args);
return new BoostFlutterView(context, engine, args,renderingProgressCoverCreator);
}
}
public interface OnFirstFrameRenderedListener {
void onFirstFrameRendered(BoostFlutterView view);
}
public interface RenderingProgressCoverCreator {
View createRenderingProgressCover(Context context);
}
}
......@@ -66,6 +66,7 @@ public class ContainerRecord implements IContainerRecord {
@Override
public void onCreate() {
Utils.assertCallOnMainThread();
BoostEngineProvider.assertEngineRunning();
if(mState != STATE_UNKNOW) {
Debuger.exception("state error");
......
......@@ -60,7 +60,7 @@ public class Debuger {
public static boolean isDebug(){
try {
return FlutterBoostPlugin.platform().isDebug();
return FlutterBoostPlugin.singleton().platform().isDebug();
}catch (Throwable t){
return false;
}
......
......@@ -25,96 +25,68 @@ package com.taobao.idlefish.flutterboost;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import com.alibaba.fastjson.JSON;
import com.taobao.idlefish.flutterboost.NavigationService.NavigationService;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
import com.taobao.idlefish.flutterboost.loader.ServiceLoader;
import com.taobao.idlefish.flutterboost.interfaces.IContainerManager;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterEngineProvider;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
import com.taobao.idlefish.flutterboost.interfaces.IPlatform;
import com.taobao.idlefish.flutterboost.interfaces.IStateListener;
import com.taobao.idlefish.flutterboost.loader.ServiceLoader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;
public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Application.ActivityLifecycleCallbacks {
public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler {
private static FlutterBoostPlugin sInstance = null;
private static int kRid = 0;
static FlutterBoostPlugin sInstance = null;
public static synchronized void init(IPlatform platform) {
if (sInstance == null) {
sInstance = new FlutterBoostPlugin(platform);
platform.getApplication().registerActivityLifecycleCallbacks(sInstance);
ServiceLoader.load();
}
}
public static void registerWith(PluginRegistry.Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_boost");
channel.setMethodCallHandler(sInstance);
}
public static IFlutterEngineProvider engineProvider() {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet");
if (platform.whenEngineStart() == IPlatform.IMMEDIATELY) {
sInstance.mEngineProvider
.createEngine(platform.getApplication())
.startRun(null);
}
return BoostEngineProvider.sInstance;
}
public static IContainerManager containerManager() {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet");
}
return sInstance.mManager;
}
public static IPlatform platform() {
public static FlutterBoostPlugin singleton() {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet");
}
return sInstance.mPlatform;
return sInstance;
}
public static Activity currentActivity() {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet");
}
return sInstance.mCurrentActiveActivity;
public static void registerWith(PluginRegistry.Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "flutter_boost");
channel.setMethodCallHandler(singleton());
}
private final IPlatform mPlatform;
private final IContainerManager mManager;
private final PageResultMediator mMediator;
private final IFlutterEngineProvider mEngineProvider;
IStateListener mStateListener;
private Activity mCurrentActiveActivity;
private FlutterBoostPlugin(IPlatform platform) {
mPlatform = platform;
mManager = new FlutterViewContainerManager();
mMediator = new PageResultMediator();
}
public IFlutterViewContainer findContainerById(String id) {
return mManager.findContainerById(id);
mEngineProvider = new BoostEngineProvider();
platform.getApplication().registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks());
}
@Override
......@@ -126,139 +98,114 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
}
}
public static void openPage(Context context, String url, final Map params, int requestCode) {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet!");
}
Context ctx = context;
if (ctx == null) {
ctx = currentActivity();
public IFlutterEngineProvider engineProvider() {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet");
}
if (ctx == null) {
ctx = sInstance.mPlatform.getApplication();
}
sInstance.mPlatform.startActivity(ctx, url ,params, requestCode);
return sInstance.mEngineProvider;
}
public static void openPage(Context context, String url, final Map params, int requestCode,PageResultHandler handler) {
if(handler != null){
String rid = createResultId();
sInstance.mMediator.setHandler(rid,handler);
params.put("result_id",rid);
public IContainerManager containerManager() {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet");
}
openPage(context,url,params,requestCode);
}
private static String createResultId(){
kRid += 2;
return "result_id_" + kRid;
return sInstance.mManager;
}
public static void onPageResult(String key , Map resultData, Map params){
public IPlatform platform() {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet!");
throw new RuntimeException("FlutterBoostPlugin not init yet");
}
sInstance.mMediator.onPageResult(key,resultData,params);
return sInstance.mPlatform;
}
public static void setHandler(String key, PageResultHandler handler) {
public Activity currentActivity() {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet!");
throw new RuntimeException("FlutterBoostPlugin not init yet");
}
sInstance.mMediator.setHandler(key, handler);
return sInstance.mCurrentActiveActivity;
}
public static void removeHandler(String key) {
if (sInstance == null) {
throw new RuntimeException("FlutterBoostPlugin not init yet!");
}
sInstance.mMediator.removeHandler(key);
public IFlutterViewContainer findContainerById(String id) {
return mManager.findContainerById(id);
}
public void setStateListener(@Nullable IStateListener listener){
mStateListener = listener;
}
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
class ActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
if (platform().whenEngineStart() == IPlatform.ANY_ACTIVITY_CREATED) {
sInstance.mEngineProvider
.createEngine(activity)
.startRun(activity);
}
}
}
@Override
public void onActivityStarted(Activity activity) {
if (mCurrentActiveActivity == null) {
Debuger.log("Application entry foreground");
@Override
public void onActivityStarted(Activity activity) {
if (mCurrentActiveActivity == null) {
Debuger.log("Application entry foreground");
if (BoostEngineProvider.sInstance.tryGetEngine() != null) {
Map<String, String> map = new HashMap<>();
map.put("type", "foreground");
NavigationService.getService().emitEvent(map);
if (mEngineProvider.tryGetEngine() != null) {
Map<String, String> map = new HashMap<>();
map.put("type", "foreground");
NavigationService.getService().emitEvent(map);
}
}
mCurrentActiveActivity = activity;
}
mCurrentActiveActivity = activity;
}
@Override
public void onActivityResumed(Activity activity) {
mCurrentActiveActivity = activity;
}
@Override
public void onActivityResumed(Activity activity) {
mCurrentActiveActivity = activity;
}
@Override
public void onActivityPaused(Activity activity) {
@Override
public void onActivityPaused(Activity activity) {
}
}
@Override
public void onActivityStopped(Activity activity) {
if (mCurrentActiveActivity == activity) {
Debuger.log("Application entry background");
if (BoostEngineProvider.sInstance.tryGetEngine() != null) {
Map<String, String> map = new HashMap<>();
map.put("type", "background");
NavigationService.getService().emitEvent(map);
@Override
public void onActivityStopped(Activity activity) {
if (mCurrentActiveActivity == activity) {
Debuger.log("Application entry background");
if (mEngineProvider.tryGetEngine() != null) {
Map<String, String> map = new HashMap<>();
map.put("type", "background");
NavigationService.getService().emitEvent(map);
}
mCurrentActiveActivity = null;
}
mCurrentActiveActivity = null;
}
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
}
@Override
public void onActivityDestroyed(Activity activity) {
if (mCurrentActiveActivity == activity) {
Debuger.log("Application entry background");
if (BoostEngineProvider.sInstance.tryGetEngine() != null) {
Map<String, String> map = new HashMap<>();
map.put("type", "background");
NavigationService.getService().emitEvent(map);
}
mCurrentActiveActivity = null;
}
@Override
public void onActivityDestroyed(Activity activity) {
if (mCurrentActiveActivity == activity) {
Debuger.log("Application entry background");
//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();
// }
// }
// }
if (mEngineProvider.tryGetEngine() != null) {
Map<String, String> map = new HashMap<>();
map.put("type", "background");
NavigationService.getService().emitEvent(map);
}
mCurrentActiveActivity = null;
}
}
}
public static void setBoostResult(Activity activity, HashMap result) {
......@@ -268,16 +215,6 @@ public class FlutterBoostPlugin implements MethodChannel.MethodCallHandler, Appl
}
activity.setResult(Activity.RESULT_OK, intent);
}
// public static void onBoostResult(IFlutterViewContainer container, int requestCode, int resultCode, Intent intent) {
// Map map = new HashMap();
// if (intent != null) {
// map.put("result", intent.getSerializableExtra(IFlutterViewContainer.RESULT_KEY));
// }
// map.put("requestCode", requestCode);
// map.put("responseCode", resultCode);
// containerManager().onContainerResult(container, map);
// }
}
......@@ -52,8 +52,6 @@ public class FlutterViewContainerManager implements IContainerManager {
public IOperateSyncer generateSyncer(IFlutterViewContainer container) {
Utils.assertCallOnMainThread();
BoostEngineProvider.sInstance.createEngine(container.getContextActivity());
ContainerRecord record = new ContainerRecord(this, container);
if (mRecordMap.put(container, record) != null) {
Debuger.exception("container:" + container.getContainerName() + " already exists!");
......@@ -64,7 +62,7 @@ public class FlutterViewContainerManager implements IContainerManager {
return record;
}
public void pushRecord(IContainerRecord record) {
void pushRecord(IContainerRecord record) {
if(!mRecordMap.containsValue(record)) {
Debuger.exception("invalid record!");
}
......@@ -72,13 +70,13 @@ public class FlutterViewContainerManager implements IContainerManager {
mRecordStack.push(record);
}
public void popRecord(IContainerRecord record) {
void popRecord(IContainerRecord record) {
if(mRecordStack.peek() == record) {
mRecordStack.pop();
}
}
public void removeRecord(IContainerRecord record) {
void removeRecord(IContainerRecord record) {
mRecordStack.remove(record);
mRecordMap.remove(record.getContainer());
}
......
......@@ -25,7 +25,6 @@
package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.FlutterViewContainerManager;
import java.util.ArrayList;
import java.util.List;
......@@ -39,7 +38,7 @@
private boolean onCall(MessageResult<Boolean> result,String uniqueId,String pageName,Map params,Boolean animated){
FlutterBoostPlugin.containerManager().closeContainer(uniqueId,null);
FlutterBoostPlugin.singleton().containerManager().closeContainer(uniqueId,null);
result.success(true);
return true;
}
......
......@@ -24,8 +24,6 @@
package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......
......@@ -24,7 +24,6 @@
package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.Debuger;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import java.util.ArrayList;
......@@ -40,7 +39,7 @@
private boolean onCall(MessageResult<Boolean> result,String now,String old,Map params){
//Add your handler code here.
FlutterBoostPlugin.containerManager().onShownContainerChanged(old,now);
FlutterBoostPlugin.singleton().containerManager().onShownContainerChanged(old,now);
return true;
}
......
......@@ -24,6 +24,8 @@
package com.taobao.idlefish.flutterboost.NavigationService;
import android.content.Context;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import java.util.ArrayList;
......@@ -44,7 +46,13 @@
requestCode = (int) params.get("requestCode");
}
FlutterBoostPlugin.openPage(null,pageName,params,0);
Context ctx = FlutterBoostPlugin.singleton().currentActivity();
if (ctx == null) {
ctx = FlutterBoostPlugin.singleton().platform().getApplication();
}
FlutterBoostPlugin.singleton().platform().startActivity(ctx, pageName ,params, requestCode);
if(result != null){
result.success(true);
......
......@@ -25,9 +25,7 @@
package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.FlutterViewContainerManager;
import com.taobao.idlefish.flutterboost.interfaces.IContainerRecord;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -44,11 +42,11 @@
Map<String,Object> pageInfo = new HashMap<>();
try {
IContainerRecord record = FlutterBoostPlugin
IContainerRecord record = FlutterBoostPlugin.singleton()
.containerManager().getCurrentTopRecord();
if(record == null) {
record = FlutterBoostPlugin.containerManager().getLastGenerateRecord();
record = FlutterBoostPlugin.singleton().containerManager().getLastGenerateRecord();
}
pageInfo.put("name",record.getContainer().getContainerName());
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost;
import java.util.Map;
public interface PageResultHandler {
void onResult(String key , Map resultData);
}
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Alibaba Group
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.taobao.idlefish.flutterboost;
import com.taobao.idlefish.flutterboost.NavigationService.NavigationService;
import java.util.HashMap;
import java.util.Map;
import fleamarket.taobao.com.xservicekit.handler.MessageResult;
class PageResultMediator {
private Map<String,PageResultHandler> _handlers = new HashMap<>();
void onPageResult(String key , Map resultData,Map params){
if(key == null) return;
if(_handlers.containsKey(key)){
_handlers.get(key).onResult(key,resultData);
_handlers.remove(key);
}else{
if(params == null || !params.containsKey("forward")){
if(params == null){
params = new HashMap();
}
params.put("forward",1);
NavigationService.onNativePageResult(new MessageResult<Boolean>() {
@Override
public void success(Boolean var1) {
}
@Override
public void error(String var1, String var2, Object var3) {
}
@Override
public void notImplemented() {
}
},key,key,resultData,params);
}else{
int forward = (Integer) params.get("forward");
params.put("forward",++forward);
if(forward <= 2){
NavigationService.onNativePageResult(new MessageResult<Boolean>() {
@Override
public void success(Boolean var1) {
}
@Override
public void error(String var1, String var2, Object var3) {
}
@Override
public void notImplemented() {
}
},key,key,resultData,params);
}
}
}
}
void setHandler(String key, PageResultHandler handler){
if(key == null || handler == null) return;
_handlers.put(key,handler);
}
void removeHandler(String key){
if(key == null) return;;
_handlers.remove(key);
}
}
package com.taobao.idlefish.flutterboost;
import com.taobao.idlefish.flutterboost.interfaces.IStateListener;
public class StateListener implements IStateListener {
@Override
public void onEngineCreated(BoostFlutterEngine engine) {
Debuger.log(">>onEngineCreated");
}
@Override
public void onEngineStarted(BoostFlutterEngine engine) {
Debuger.log(">>onEngineStarted");
}
@Override
public void onFlutterViewInited(BoostFlutterEngine engine, BoostFlutterView flutterView) {
Debuger.log(">>onFlutterViewInited");
}
@Override
public void beforeEngineAttach(BoostFlutterEngine engine, BoostFlutterView flutterView) {
Debuger.log(">>beforeEngineAttach");
}
@Override
public void afterEngineAttached(BoostFlutterEngine engine, BoostFlutterView flutterView) {
Debuger.log(">>afterEngineAttached");
}
@Override
public void beforeEngineDetach(BoostFlutterEngine engine, BoostFlutterView flutterView) {
Debuger.log(">>beforeEngineDetach");
}
@Override
public void afterEngineDetached(BoostFlutterEngine engine, BoostFlutterView flutterView) {
Debuger.log(">>afterEngineDetached");
}
}
......@@ -24,9 +24,23 @@
package com.taobao.idlefish.flutterboost.containers;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.taobao.idlefish.flutterboost.BoostFlutterEngine;
import com.taobao.idlefish.flutterboost.BoostFlutterView;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
......@@ -35,25 +49,101 @@ import com.taobao.idlefish.flutterboost.interfaces.IOperateSyncer;
import java.util.HashMap;
import io.flutter.embedding.android.FlutterView;
import io.flutter.plugin.platform.PlatformPlugin;
public abstract class BoostFlutterActivity extends Activity implements IFlutterViewContainer {
private BoostFlutterView mFlutterView;
private IOperateSyncer mSyncer;
protected BoostFlutterEngine mFlutterEngine;
protected BoostFlutterView mFlutterView;
protected IOperateSyncer mSyncer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BoostFlutterView.Builder builder = new BoostFlutterView.Builder(this);
mFlutterView = builder.renderMode(FlutterView.RenderMode.texture)
.transparencyMode(FlutterView.TransparencyMode.opaque)
.build();
configureWindowForTransparency();
mSyncer = FlutterBoostPlugin.singleton().containerManager().generateSyncer(this);
mFlutterEngine = createFlutterEngine();
mFlutterView = createFlutterView(mFlutterEngine);
setContentView(mFlutterView);
mSyncer = FlutterBoostPlugin.containerManager().generateSyncer(this);
mSyncer.onCreate();
configureStatusBarForFullscreenFlutterExperience();
}
protected void configureWindowForTransparency() {
if (isBackgroundTransparent()) {
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
);
}
}
protected void configureStatusBarForFullscreenFlutterExperience() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(0x40000000);
window.getDecorView().setSystemUiVisibility(PlatformPlugin.DEFAULT_SYSTEM_UI);
}
}
protected BoostFlutterEngine createFlutterEngine(){
return FlutterBoostPlugin.singleton().engineProvider().createEngine(this);
}
protected BoostFlutterView createFlutterView(BoostFlutterEngine engine){
BoostFlutterView.Builder builder = new BoostFlutterView.Builder(this);
return builder.flutterEngine(engine)
.renderMode(FlutterView.RenderMode.texture)
.transparencyMode(isBackgroundTransparent() ?
FlutterView.TransparencyMode.transparent :
FlutterView.TransparencyMode.opaque)
.renderingProgressCoverCreator(new BoostFlutterView.RenderingProgressCoverCreator() {
@Override
public View createRenderingProgressCover(Context context) {
return BoostFlutterActivity.this.createRenderingProgressCover();
}
})
.build();
}
protected boolean isBackgroundTransparent(){
return false;
}
protected View createRenderingProgressCover(){
FrameLayout frameLayout = new FrameLayout(this);
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER;
frameLayout.addView(linearLayout,layoutParams);
ProgressBar progressBar = new ProgressBar(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER_HORIZONTAL;
linearLayout.addView(progressBar,params);
TextView textView = new TextView(this);
params = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER_HORIZONTAL;
textView.setText("Frame Rendering...");
linearLayout.addView(textView,params);
return frameLayout;
}
@Override
......
......@@ -32,6 +32,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.taobao.idlefish.flutterboost.BoostFlutterEngine;
import com.taobao.idlefish.flutterboost.BoostFlutterView;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
......@@ -43,23 +44,36 @@ import io.flutter.embedding.android.FlutterView;
abstract public class BoostFlutterFragment extends Fragment implements IFlutterViewContainer {
private BoostFlutterView mFlutterView;
private IOperateSyncer mSyncer;
protected BoostFlutterEngine mFlutterEngine;
protected BoostFlutterView mFlutterView;
protected IOperateSyncer mSyncer;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
BoostFlutterView.Builder builder = new BoostFlutterView.Builder(getContextActivity());
mFlutterView = builder.renderMode(FlutterView.RenderMode.texture)
.transparencyMode(FlutterView.TransparencyMode.opaque)
.build();
mSyncer = FlutterBoostPlugin.singleton().containerManager().generateSyncer(this);
mFlutterEngine = createFlutterEngine();
mFlutterView = createFlutterView(mFlutterEngine);
mSyncer = FlutterBoostPlugin.containerManager().generateSyncer(this);
mSyncer.onCreate();
return mFlutterView;
}
protected BoostFlutterEngine createFlutterEngine(){
return FlutterBoostPlugin.singleton().engineProvider().createEngine(getContext());
}
protected BoostFlutterView createFlutterView(BoostFlutterEngine engine){
BoostFlutterView.Builder builder = new BoostFlutterView.Builder(getContextActivity());
return builder.flutterEngine(engine)
.renderMode(FlutterView.RenderMode.texture)
.transparencyMode(FlutterView.TransparencyMode.opaque)
.build();
}
@Override
public void onResume() {
super.onResume();
......
......@@ -25,6 +25,7 @@ package com.taobao.idlefish.flutterboost.interfaces;
import android.content.Context;
import com.taobao.idlefish.flutterboost.BoostFlutterEngine;
import com.taobao.idlefish.flutterboost.BoostFlutterView;
import io.flutter.embedding.engine.FlutterEngine;
......@@ -38,11 +39,11 @@ public interface IFlutterEngineProvider {
* @param context
* @return
*/
FlutterEngine createEngine(Context context);
BoostFlutterEngine createEngine(Context context);
/**
* may return null
* @return
*/
FlutterEngine tryGetEngine();
BoostFlutterEngine tryGetEngine();
}
......@@ -23,7 +23,6 @@
*/
package com.taobao.idlefish.flutterboost.interfaces;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
......@@ -36,6 +35,10 @@ import io.flutter.plugin.common.PluginRegistry;
*/
public interface IPlatform {
int IMMEDIATELY = 0; //立即启动引擎
int ANY_ACTIVITY_CREATED = 1; //当有任何Activity创建时,启动引擎
int LAZY = 2; //尽可能延后启动引擎(通常是首页Flutter页面加载时)
/**
* get current application
* @return
......@@ -43,16 +46,16 @@ public interface IPlatform {
Application getApplication();
/**
* register plugins
* debug or not
* @return
*/
void onRegisterPlugins(PluginRegistry registry);
boolean isDebug();
/**
* debug or not
* register plugins
* @return
*/
boolean isDebug();
void onRegisterPlugins(PluginRegistry registry);
/**
* start a new activity from flutter page, you may need a page router with url
......@@ -65,8 +68,11 @@ public interface IPlatform {
/**
* settings, no use
* @return
*
* IMMEDIATELY //立即
* ANY_ACTIVITY_CREATED //当有任何Activity创建的时候
* LAZY //懒加载,尽可能延后
*/
Map getSettings();
int whenEngineStart();
}
package com.taobao.idlefish.flutterboost.interfaces;
import com.taobao.idlefish.flutterboost.BoostFlutterEngine;
import com.taobao.idlefish.flutterboost.BoostFlutterView;
public interface IStateListener {
void onEngineCreated(BoostFlutterEngine engine);
void onEngineStarted(BoostFlutterEngine engine);
void onFlutterViewInited(BoostFlutterEngine engine, BoostFlutterView flutterView);
void beforeEngineAttach(BoostFlutterEngine engine, BoostFlutterView flutterView);
void afterEngineAttached(BoostFlutterEngine engine, BoostFlutterView flutterView);
void beforeEngineDetach(BoostFlutterEngine engine, BoostFlutterView flutterView);
void afterEngineDetached(BoostFlutterEngine engine, BoostFlutterView flutterView);
}
package com.taobao.idlefish.flutterboostexample;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import io.flutter.plugin.platform.PlatformPlugin;
public class FlutterFragmentPageActivity extends AppCompatActivity {
public class FlutterFragmentPageActivity extends AppCompatActivity implements View.OnClickListener {
private FlutterFragment mFragment;
private View mTab1;
private View mTab2;
private View mTab3;
private View mTab4;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
......@@ -32,11 +39,49 @@ public class FlutterFragmentPageActivity extends AppCompatActivity {
setContentView(R.layout.flutter_fragment_page);
mFragment = FlutterFragment.instance("hello");
mTab1 = findViewById(R.id.tab1);
mTab2 = findViewById(R.id.tab2);
mTab3 = findViewById(R.id.tab3);
mTab4 = findViewById(R.id.tab4);
mTab1.setOnClickListener(this);
mTab2.setOnClickListener(this);
mTab3.setOnClickListener(this);
mTab4.setOnClickListener(this);
}
@Override
public void onClick(View v) {
mTab1.setBackgroundColor(Color.WHITE);
mTab2.setBackgroundColor(Color.WHITE);
mTab3.setBackgroundColor(Color.WHITE);
mTab4.setBackgroundColor(Color.WHITE);
if(mTab1 == v) {
mTab1.setBackgroundColor(Color.YELLOW);
mFragment = FlutterFragment.instance("tab1");
}else if(mTab2 == v) {
mTab2.setBackgroundColor(Color.YELLOW);
mFragment = FlutterFragment.instance("tab2");
}else if(mTab3 == v) {
mTab3.setBackgroundColor(Color.YELLOW);
mFragment = FlutterFragment.instance("tab3");
}else{
mTab4.setBackgroundColor(Color.YELLOW);
mFragment = FlutterFragment.instance("tab4");
}
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_stub,mFragment)
.commit();
}
@Override
protected void onResume() {
super.onResume();
mTab1.performClick();
}
}
......@@ -15,7 +15,7 @@ public class FlutterPageActivity extends BoostFlutterActivity {
* 混合栈将会在flutter层根据这个名字,在注册的Route表中查找对应的Widget
*
* 在flutter层有注册函数:
* FlutterBoost.singleton.registerPageBuilders({
* FlutterBoostPlugin.singleton.registerPageBuilders({
* 'first': (pageName, params, _) => FirstRouteWidget(),
* 'second': (pageName, params, _) => SecondRouteWidget(),
* ...
......@@ -34,7 +34,7 @@ public class FlutterPageActivity extends BoostFlutterActivity {
* 该方法返回的参数将会传递给上层的flutter对应的Widget
*
* 在flutter层有注册函数:
* FlutterBoost.singleton.registerPageBuilders({
* FlutterBoostPlugin.singleton.registerPageBuilders({
* 'first': (pageName, params, _) => FirstRouteWidget(),
* 'second': (pageName, params, _) => SecondRouteWidget(),
* ...
......
......@@ -6,8 +6,6 @@ import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
......@@ -52,7 +50,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
PageRouter.openPageByUrl(this, PageRouter.NATIVE_PAGE_URL , params);
} else if (v == mOpenFlutter) {
PageRouter.openPageByUrl(this, PageRouter.FLUTTER_PAGE_URL,params);
FlutterBoostPlugin.onPageResult("result_id_100",new HashMap(),new HashMap());
} else if (v == mOpenFlutterFragment) {
PageRouter.openPageByUrl(this, PageRouter.FLUTTER_FRAGMENT_PAGE_URL,params);
}
......
......@@ -3,9 +3,13 @@ package com.taobao.idlefish.flutterboostexample;
import android.app.Application;
import android.content.Context;
import com.taobao.idlefish.flutterboost.BoostFlutterEngine;
import com.taobao.idlefish.flutterboost.BoostFlutterView;
import com.taobao.idlefish.flutterboost.Debuger;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.StateListener;
import com.taobao.idlefish.flutterboost.interfaces.IPlatform;
import com.taobao.idlefish.flutterboost.interfaces.IStateListener;
import java.util.Map;
......@@ -54,8 +58,8 @@ public class MyApplication extends FlutterApplication {
}
@Override
public Map getSettings() {
return null;
public int whenEngineStart() {
return IMMEDIATELY;
}
});
}
......
......@@ -11,4 +11,47 @@
android:layout_weight="1"
android:id="@+id/fragment_stub"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="56dp"
android:text="tab1"
android:id="@+id/tab1"
android:gravity="center"
android:textColor="@android:color/background_dark"
android:layout_weight="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="56dp"
android:text="tab2"
android:id="@+id/tab2"
android:gravity="center"
android:textColor="@android:color/background_dark"
android:layout_weight="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="56dp"
android:text="tab3"
android:id="@+id/tab3"
android:gravity="center"
android:textColor="@android:color/background_dark"
android:layout_weight="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="56dp"
android:text="tab4"
android:id="@+id/tab4"
android:gravity="center"
android:textColor="@android:color/background_dark"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
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