Commit 0e7d161c authored by Yacumima's avatar Yacumima

improve

parent c97e6421
...@@ -42,6 +42,6 @@ dependencies { ...@@ -42,6 +42,6 @@ dependencies {
ext { ext {
groupId = 'com.taobao.fleamarket' groupId = 'com.taobao.fleamarket'
artifactId = "FlutterBoost" artifactId = "FlutterBoostPlugin"
} }
...@@ -23,36 +23,23 @@ ...@@ -23,36 +23,23 @@
*/ */
package com.taobao.idlefish.flutterboost; package com.taobao.idlefish.flutterboost;
import android.app.Activity;
import android.content.Context; 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.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.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.FlutterMain;
import io.flutter.view.FlutterNativeView;
import io.flutter.view.FlutterView;
import io.flutter.view.TextureRegistry;
public class BoostEngineProvider implements IFlutterEngineProvider { public class BoostEngineProvider implements IFlutterEngineProvider {
static final BoostEngineProvider sInstance = new BoostEngineProvider(); private BoostFlutterEngine mEngine = null;
private BoostEngine mEngine = null; BoostEngineProvider() {
private BoostEngineProvider() {
} }
@Override @Override
public FlutterEngine createEngine(Context context) { public BoostFlutterEngine createEngine(Context context) {
Utils.assertCallOnMainThread(); Utils.assertCallOnMainThread();
...@@ -61,35 +48,25 @@ public class BoostEngineProvider implements IFlutterEngineProvider { ...@@ -61,35 +48,25 @@ public class BoostEngineProvider implements IFlutterEngineProvider {
FlutterMain.ensureInitializationComplete( FlutterMain.ensureInitializationComplete(
context.getApplicationContext(), flutterShellArgs.toArray()); context.getApplicationContext(), flutterShellArgs.toArray());
mEngine = new BoostEngine(context.getApplicationContext()); mEngine = new BoostFlutterEngine(context.getApplicationContext());
mEngine.startRun();
final IStateListener stateListener = FlutterBoostPlugin.sInstance.mStateListener;
if(stateListener != null) {
stateListener.onEngineCreated(mEngine);
}
} }
return mEngine; return mEngine;
} }
@Override @Override
public FlutterEngine tryGetEngine() { public BoostFlutterEngine tryGetEngine() {
return mEngine; return mEngine;
} }
public static class BoostEngine extends FlutterEngine { public static void assertEngineRunning(){
final Context mContext; final BoostFlutterEngine engine = FlutterBoostPlugin.singleton().engineProvider().tryGetEngine();
if(engine == null || !engine.isRunning()) {
public BoostEngine(@NonNull Context context) { throw new RuntimeException("engine is not running yet!");
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);
}
} }
} }
} }
...@@ -2,44 +2,116 @@ package com.taobao.idlefish.flutterboost; ...@@ -2,44 +2,116 @@ package com.taobao.idlefish.flutterboost;
import android.app.Activity; import android.app.Activity;
import android.content.Context; 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.app.FlutterPluginRegistry;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.PluginRegistry; import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.platform.PlatformViewRegistry; import io.flutter.plugin.platform.PlatformViewRegistry;
import io.flutter.view.FlutterMain;
import io.flutter.view.FlutterView; import io.flutter.view.FlutterView;
import io.flutter.view.TextureRegistry; import io.flutter.view.TextureRegistry;
public class BoostPluginRegistry extends FlutterPluginRegistry { 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()) {
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 BoostPluginRegistry getBoostPluginRegistry(){
return mBoostPluginRegistry;
}
public boolean isRunning(){
return getDartExecutor().isExecutingDart();
}
public class BoostPluginRegistry extends FlutterPluginRegistry {
private final FlutterEngine mEngine; private final FlutterEngine mEngine;
private final Activity mActivity;
public BoostPluginRegistry(FlutterEngine engine, Activity activity) { public BoostPluginRegistry(FlutterEngine engine, Context context) {
super(engine, activity); super(engine, context);
mEngine = engine; mEngine = engine;
mActivity = activity;
} }
public PluginRegistry.Registrar registrarFor(String pluginKey) { public PluginRegistry.Registrar registrarFor(String pluginKey) {
return new BoostRegistrar(mActivity,mEngine,super.registrarFor(pluginKey)); return new BoostRegistrar(mEngine,super.registrarFor(pluginKey));
}
} }
public static class BoostRegistrar implements PluginRegistry.Registrar { public class BoostRegistrar implements PluginRegistry.Registrar {
private final PluginRegistry.Registrar mRegistrar; private final PluginRegistry.Registrar mRegistrar;
private final FlutterEngine mEngine; private final FlutterEngine mEngine;
private final Activity mActivity;
BoostRegistrar(Activity activity, FlutterEngine engine, PluginRegistry.Registrar registrar) { BoostRegistrar(FlutterEngine engine, PluginRegistry.Registrar registrar) {
mRegistrar = registrar; mRegistrar = registrar;
mEngine = engine; mEngine = engine;
mActivity = activity;
} }
@Override @Override
public Activity activity() { 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 @Override
......
...@@ -26,22 +26,30 @@ package com.taobao.idlefish.flutterboost; ...@@ -26,22 +26,30 @@ package com.taobao.idlefish.flutterboost;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.view.ViewCompat;
import android.util.Log; import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; 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.LinkedList;
import java.util.List; import java.util.List;
import io.flutter.embedding.android.FlutterView; 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; import io.flutter.plugin.platform.PlatformPlugin;
public class BoostFlutterView extends FrameLayout { public class BoostFlutterView extends FrameLayout {
private FlutterEngine mFlutterEngine; private BoostFlutterEngine mFlutterEngine;
private FlutterView mFlutterView; private FlutterView mFlutterView;
...@@ -49,24 +57,35 @@ public class BoostFlutterView extends FrameLayout { ...@@ -49,24 +57,35 @@ public class BoostFlutterView extends FrameLayout {
private Bundle mArguments; private Bundle mArguments;
private BoostPluginRegistry mBoostPluginRegistry; private RenderingProgressCoverCreator mRenderingProgressCoverCreator;
private View mRenderingProgressCover;
private final List<OnFirstFrameRenderedListener> mFirstFrameRenderedListeners = new LinkedList<>(); 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 @Override
public void onFirstFrameRendered() { public void onFirstFrameRendered() {
if(mRenderingProgressCover != null && mRenderingProgressCover.getParent() != null) {
((ViewGroup)mRenderingProgressCover.getParent()).removeView(mRenderingProgressCover);
}
final Object[] listeners = mFirstFrameRenderedListeners.toArray(); final Object[] listeners = mFirstFrameRenderedListeners.toArray();
for (Object obj : listeners) { 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); super(context);
mFlutterEngine = engine; mFlutterEngine = engine;
mArguments = args; mArguments = args;
mRenderingProgressCoverCreator = creator;
init(); init();
} }
...@@ -85,14 +104,63 @@ public class BoostFlutterView extends FrameLayout { ...@@ -85,14 +104,63 @@ public class BoostFlutterView extends FrameLayout {
addView(mFlutterView, new FrameLayout.LayoutParams( addView(mFlutterView, new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 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); mFlutterView.addOnFirstFrameRenderedListener(mOnFirstFrameRenderedListener);
mBoostPluginRegistry = new BoostPluginRegistry(mFlutterEngine,(Activity)getContext()); mFlutterEngine.startRun((Activity)getContext());
FlutterBoostPlugin.platform().onRegisterPlugins(mBoostPluginRegistry);
final IStateListener stateListener = FlutterBoostPlugin.sInstance.mStateListener;
if(stateListener != null) {
stateListener.onFlutterViewInited(mFlutterEngine,this);
}
}
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 FlutterEngine createFlutterEngine(Context context) { protected BoostFlutterEngine createFlutterEngine(Context context) {
return BoostEngineProvider.sInstance.createEngine(context); return FlutterBoostPlugin.singleton().engineProvider().createEngine(context);
} }
public void addFirstFrameRendered(OnFirstFrameRenderedListener listener) { public void addFirstFrameRendered(OnFirstFrameRenderedListener listener) {
...@@ -119,6 +187,11 @@ public class BoostFlutterView extends FrameLayout { ...@@ -119,6 +187,11 @@ public class BoostFlutterView extends FrameLayout {
protected void onAttachedToWindow() { protected void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
mPlatformPlugin.onPostResume(); mPlatformPlugin.onPostResume();
ViewCompat.requestApplyInsets(this);
}
public BoostFlutterEngine getEngine(){
return mFlutterEngine;
} }
public void onResume() { public void onResume() {
...@@ -143,13 +216,32 @@ public class BoostFlutterView extends FrameLayout { ...@@ -143,13 +216,32 @@ public class BoostFlutterView extends FrameLayout {
public void onAttach() { public void onAttach() {
Debuger.log("BoostFlutterView onAttach"); Debuger.log("BoostFlutterView onAttach");
final IStateListener stateListener = FlutterBoostPlugin.sInstance.mStateListener;
if(stateListener != null) {
stateListener.beforeEngineAttach(mFlutterEngine,this);
}
mFlutterView.attachToFlutterEngine(mFlutterEngine); mFlutterView.attachToFlutterEngine(mFlutterEngine);
if(stateListener != null) {
stateListener.afterEngineAttached(mFlutterEngine,this);
}
} }
public void onDetach() { public void onDetach() {
Debuger.log("BoostFlutterView onDetach"); Debuger.log("BoostFlutterView onDetach");
if(mNeedSnapshotWhenDetach) {
//mFlutterView.
}
mFlutterView.removeOnFirstFrameRenderedListener(mOnFirstFrameRenderedListener); mFlutterView.removeOnFirstFrameRenderedListener(mOnFirstFrameRenderedListener);
final IStateListener stateListener = FlutterBoostPlugin.sInstance.mStateListener;
if(stateListener != null) {
stateListener.beforeEngineDetach(mFlutterEngine,this);
}
mFlutterView.detachFromFlutterEngine(); mFlutterView.detachFromFlutterEngine();
if(stateListener != null) {
stateListener.afterEngineDetached(mFlutterEngine,this);
}
} }
public void onDestroy() { public void onDestroy() {
...@@ -226,9 +318,10 @@ public class BoostFlutterView extends FrameLayout { ...@@ -226,9 +318,10 @@ public class BoostFlutterView extends FrameLayout {
public static class Builder { public static class Builder {
private Context context; private Context context;
private FlutterEngine engine; private BoostFlutterEngine engine;
private FlutterView.RenderMode renderMode; private FlutterView.RenderMode renderMode;
private FlutterView.TransparencyMode transparencyMode; private FlutterView.TransparencyMode transparencyMode;
private RenderingProgressCoverCreator renderingProgressCoverCreator;
public Builder(Context ctx) { public Builder(Context ctx) {
this.context = ctx; this.context = ctx;
...@@ -236,7 +329,7 @@ public class BoostFlutterView extends FrameLayout { ...@@ -236,7 +329,7 @@ public class BoostFlutterView extends FrameLayout {
transparencyMode = FlutterView.TransparencyMode.transparent; transparencyMode = FlutterView.TransparencyMode.transparent;
} }
public Builder flutterEngine(FlutterEngine engine) { public Builder flutterEngine(BoostFlutterEngine engine) {
this.engine = engine; this.engine = engine;
return this; return this;
} }
...@@ -247,6 +340,10 @@ public class BoostFlutterView extends FrameLayout { ...@@ -247,6 +340,10 @@ public class BoostFlutterView extends FrameLayout {
return this; return this;
} }
public Builder renderingProgressCoverCreator(RenderingProgressCoverCreator creator) {
this.renderingProgressCoverCreator = creator;
return this;
}
public Builder transparencyMode(FlutterView.TransparencyMode transparencyMode) { public Builder transparencyMode(FlutterView.TransparencyMode transparencyMode) {
this.transparencyMode = transparencyMode; this.transparencyMode = transparencyMode;
...@@ -258,7 +355,15 @@ public class BoostFlutterView extends FrameLayout { ...@@ -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_render_mode", renderMode != null ? renderMode.name() : FlutterView.RenderMode.surface.name());
args.putString("flutterview_transparency_mode", transparencyMode != null ? transparencyMode.name() : FlutterView.TransparencyMode.transparent.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 { ...@@ -66,6 +66,7 @@ public class ContainerRecord implements IContainerRecord {
@Override @Override
public void onCreate() { public void onCreate() {
Utils.assertCallOnMainThread(); Utils.assertCallOnMainThread();
BoostEngineProvider.assertEngineRunning();
if(mState != STATE_UNKNOW) { if(mState != STATE_UNKNOW) {
Debuger.exception("state error"); Debuger.exception("state error");
......
...@@ -60,7 +60,7 @@ public class Debuger { ...@@ -60,7 +60,7 @@ public class Debuger {
public static boolean isDebug(){ public static boolean isDebug(){
try { try {
return FlutterBoostPlugin.platform().isDebug(); return FlutterBoostPlugin.singleton().platform().isDebug();
}catch (Throwable t){ }catch (Throwable t){
return false; return false;
} }
......
...@@ -52,8 +52,6 @@ public class FlutterViewContainerManager implements IContainerManager { ...@@ -52,8 +52,6 @@ public class FlutterViewContainerManager implements IContainerManager {
public IOperateSyncer generateSyncer(IFlutterViewContainer container) { public IOperateSyncer generateSyncer(IFlutterViewContainer container) {
Utils.assertCallOnMainThread(); Utils.assertCallOnMainThread();
BoostEngineProvider.sInstance.createEngine(container.getContextActivity());
ContainerRecord record = new ContainerRecord(this, container); ContainerRecord record = new ContainerRecord(this, container);
if (mRecordMap.put(container, record) != null) { if (mRecordMap.put(container, record) != null) {
Debuger.exception("container:" + container.getContainerName() + " already exists!"); Debuger.exception("container:" + container.getContainerName() + " already exists!");
...@@ -64,7 +62,7 @@ public class FlutterViewContainerManager implements IContainerManager { ...@@ -64,7 +62,7 @@ public class FlutterViewContainerManager implements IContainerManager {
return record; return record;
} }
public void pushRecord(IContainerRecord record) { void pushRecord(IContainerRecord record) {
if(!mRecordMap.containsValue(record)) { if(!mRecordMap.containsValue(record)) {
Debuger.exception("invalid record!"); Debuger.exception("invalid record!");
} }
...@@ -72,13 +70,13 @@ public class FlutterViewContainerManager implements IContainerManager { ...@@ -72,13 +70,13 @@ public class FlutterViewContainerManager implements IContainerManager {
mRecordStack.push(record); mRecordStack.push(record);
} }
public void popRecord(IContainerRecord record) { void popRecord(IContainerRecord record) {
if(mRecordStack.peek() == record) { if(mRecordStack.peek() == record) {
mRecordStack.pop(); mRecordStack.pop();
} }
} }
public void removeRecord(IContainerRecord record) { void removeRecord(IContainerRecord record) {
mRecordStack.remove(record); mRecordStack.remove(record);
mRecordMap.remove(record.getContainer()); mRecordMap.remove(record.getContainer());
} }
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
package com.taobao.idlefish.flutterboost.NavigationService; package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin; import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.FlutterViewContainerManager;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -39,7 +38,7 @@ ...@@ -39,7 +38,7 @@
private boolean onCall(MessageResult<Boolean> result,String uniqueId,String pageName,Map params,Boolean animated){ 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); result.success(true);
return true; return true;
} }
......
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
package com.taobao.idlefish.flutterboost.NavigationService; package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
package com.taobao.idlefish.flutterboost.NavigationService; package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.Debuger;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin; import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -40,7 +39,7 @@ ...@@ -40,7 +39,7 @@
private boolean onCall(MessageResult<Boolean> result,String now,String old,Map params){ private boolean onCall(MessageResult<Boolean> result,String now,String old,Map params){
//Add your handler code here. //Add your handler code here.
FlutterBoostPlugin.containerManager().onShownContainerChanged(old,now); FlutterBoostPlugin.singleton().containerManager().onShownContainerChanged(old,now);
return true; return true;
} }
......
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
package com.taobao.idlefish.flutterboost.NavigationService; package com.taobao.idlefish.flutterboost.NavigationService;
import android.content.Context;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin; import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -44,7 +46,13 @@ ...@@ -44,7 +46,13 @@
requestCode = (int) params.get("requestCode"); 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){ if(result != null){
result.success(true); result.success(true);
......
...@@ -25,9 +25,7 @@ ...@@ -25,9 +25,7 @@
package com.taobao.idlefish.flutterboost.NavigationService; package com.taobao.idlefish.flutterboost.NavigationService;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin; 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.IContainerRecord;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -44,11 +42,11 @@ ...@@ -44,11 +42,11 @@
Map<String,Object> pageInfo = new HashMap<>(); Map<String,Object> pageInfo = new HashMap<>();
try { try {
IContainerRecord record = FlutterBoostPlugin IContainerRecord record = FlutterBoostPlugin.singleton()
.containerManager().getCurrentTopRecord(); .containerManager().getCurrentTopRecord();
if(record == null) { if(record == null) {
record = FlutterBoostPlugin.containerManager().getLastGenerateRecord(); record = FlutterBoostPlugin.singleton().containerManager().getLastGenerateRecord();
} }
pageInfo.put("name",record.getContainer().getContainerName()); 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 @@ ...@@ -24,9 +24,23 @@
package com.taobao.idlefish.flutterboost.containers; package com.taobao.idlefish.flutterboost.containers;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle; 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.BoostFlutterView;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin; import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer; import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
...@@ -35,25 +49,101 @@ import com.taobao.idlefish.flutterboost.interfaces.IOperateSyncer; ...@@ -35,25 +49,101 @@ import com.taobao.idlefish.flutterboost.interfaces.IOperateSyncer;
import java.util.HashMap; import java.util.HashMap;
import io.flutter.embedding.android.FlutterView; import io.flutter.embedding.android.FlutterView;
import io.flutter.plugin.platform.PlatformPlugin;
public abstract class BoostFlutterActivity extends Activity implements IFlutterViewContainer { public abstract class BoostFlutterActivity extends Activity implements IFlutterViewContainer {
private BoostFlutterView mFlutterView; protected BoostFlutterEngine mFlutterEngine;
private IOperateSyncer mSyncer; protected BoostFlutterView mFlutterView;
protected IOperateSyncer mSyncer;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
BoostFlutterView.Builder builder = new BoostFlutterView.Builder(this); configureWindowForTransparency();
mFlutterView = builder.renderMode(FlutterView.RenderMode.texture)
.transparencyMode(FlutterView.TransparencyMode.opaque) mSyncer = FlutterBoostPlugin.singleton().containerManager().generateSyncer(this);
.build();
mFlutterEngine = createFlutterEngine();
mFlutterView = createFlutterView(mFlutterEngine);
setContentView(mFlutterView); setContentView(mFlutterView);
mSyncer = FlutterBoostPlugin.containerManager().generateSyncer(this);
mSyncer.onCreate(); 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 @Override
......
...@@ -32,6 +32,7 @@ import android.view.LayoutInflater; ...@@ -32,6 +32,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.taobao.idlefish.flutterboost.BoostFlutterEngine;
import com.taobao.idlefish.flutterboost.BoostFlutterView; import com.taobao.idlefish.flutterboost.BoostFlutterView;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin; import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer; import com.taobao.idlefish.flutterboost.interfaces.IFlutterViewContainer;
...@@ -43,23 +44,36 @@ import io.flutter.embedding.android.FlutterView; ...@@ -43,23 +44,36 @@ import io.flutter.embedding.android.FlutterView;
abstract public class BoostFlutterFragment extends Fragment implements IFlutterViewContainer { abstract public class BoostFlutterFragment extends Fragment implements IFlutterViewContainer {
private BoostFlutterView mFlutterView; protected BoostFlutterEngine mFlutterEngine;
private IOperateSyncer mSyncer; protected BoostFlutterView mFlutterView;
protected IOperateSyncer mSyncer;
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
BoostFlutterView.Builder builder = new BoostFlutterView.Builder(getContextActivity()); mSyncer = FlutterBoostPlugin.singleton().containerManager().generateSyncer(this);
mFlutterView = builder.renderMode(FlutterView.RenderMode.texture)
.transparencyMode(FlutterView.TransparencyMode.opaque) mFlutterEngine = createFlutterEngine();
.build(); mFlutterView = createFlutterView(mFlutterEngine);
mSyncer = FlutterBoostPlugin.containerManager().generateSyncer(this);
mSyncer.onCreate(); mSyncer.onCreate();
return mFlutterView; 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 @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
......
...@@ -25,6 +25,7 @@ package com.taobao.idlefish.flutterboost.interfaces; ...@@ -25,6 +25,7 @@ package com.taobao.idlefish.flutterboost.interfaces;
import android.content.Context; import android.content.Context;
import com.taobao.idlefish.flutterboost.BoostFlutterEngine;
import com.taobao.idlefish.flutterboost.BoostFlutterView; import com.taobao.idlefish.flutterboost.BoostFlutterView;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
...@@ -38,11 +39,11 @@ public interface IFlutterEngineProvider { ...@@ -38,11 +39,11 @@ public interface IFlutterEngineProvider {
* @param context * @param context
* @return * @return
*/ */
FlutterEngine createEngine(Context context); BoostFlutterEngine createEngine(Context context);
/** /**
* may return null * may return null
* @return * @return
*/ */
FlutterEngine tryGetEngine(); BoostFlutterEngine tryGetEngine();
} }
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
*/ */
package com.taobao.idlefish.flutterboost.interfaces; package com.taobao.idlefish.flutterboost.interfaces;
import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
...@@ -36,6 +35,10 @@ import io.flutter.plugin.common.PluginRegistry; ...@@ -36,6 +35,10 @@ import io.flutter.plugin.common.PluginRegistry;
*/ */
public interface IPlatform { public interface IPlatform {
int IMMEDIATELY = 0; //立即启动引擎
int ANY_ACTIVITY_CREATED = 1; //当有任何Activity创建时,启动引擎
int LAZY = 2; //尽可能延后启动引擎(通常是首页Flutter页面加载时)
/** /**
* get current application * get current application
* @return * @return
...@@ -43,16 +46,16 @@ public interface IPlatform { ...@@ -43,16 +46,16 @@ public interface IPlatform {
Application getApplication(); Application getApplication();
/** /**
* register plugins * debug or not
* @return * @return
*/ */
void onRegisterPlugins(PluginRegistry registry); boolean isDebug();
/** /**
* debug or not * register plugins
* @return * @return
*/ */
boolean isDebug(); void onRegisterPlugins(PluginRegistry registry);
/** /**
* start a new activity from flutter page, you may need a page router with url * start a new activity from flutter page, you may need a page router with url
...@@ -65,8 +68,11 @@ public interface IPlatform { ...@@ -65,8 +68,11 @@ public interface IPlatform {
/** /**
* settings, no use
* @return * @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; package com.taobao.idlefish.flutterboostexample;
import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import io.flutter.plugin.platform.PlatformPlugin; import io.flutter.plugin.platform.PlatformPlugin;
public class FlutterFragmentPageActivity extends AppCompatActivity { public class FlutterFragmentPageActivity extends AppCompatActivity implements View.OnClickListener {
private FlutterFragment mFragment; private FlutterFragment mFragment;
private View mTab1;
private View mTab2;
private View mTab3;
private View mTab4;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_NO_TITLE); supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
...@@ -32,11 +39,49 @@ public class FlutterFragmentPageActivity extends AppCompatActivity { ...@@ -32,11 +39,49 @@ public class FlutterFragmentPageActivity extends AppCompatActivity {
setContentView(R.layout.flutter_fragment_page); 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() getSupportFragmentManager()
.beginTransaction() .beginTransaction()
.replace(R.id.fragment_stub,mFragment) .replace(R.id.fragment_stub,mFragment)
.commit(); .commit();
} }
@Override
protected void onResume() {
super.onResume();
mTab1.performClick();
}
} }
...@@ -15,7 +15,7 @@ public class FlutterPageActivity extends BoostFlutterActivity { ...@@ -15,7 +15,7 @@ public class FlutterPageActivity extends BoostFlutterActivity {
* 混合栈将会在flutter层根据这个名字,在注册的Route表中查找对应的Widget * 混合栈将会在flutter层根据这个名字,在注册的Route表中查找对应的Widget
* *
* 在flutter层有注册函数: * 在flutter层有注册函数:
* FlutterBoost.singleton.registerPageBuilders({ * FlutterBoostPlugin.singleton.registerPageBuilders({
* 'first': (pageName, params, _) => FirstRouteWidget(), * 'first': (pageName, params, _) => FirstRouteWidget(),
* 'second': (pageName, params, _) => SecondRouteWidget(), * 'second': (pageName, params, _) => SecondRouteWidget(),
* ... * ...
...@@ -34,7 +34,7 @@ public class FlutterPageActivity extends BoostFlutterActivity { ...@@ -34,7 +34,7 @@ public class FlutterPageActivity extends BoostFlutterActivity {
* 该方法返回的参数将会传递给上层的flutter对应的Widget * 该方法返回的参数将会传递给上层的flutter对应的Widget
* *
* 在flutter层有注册函数: * 在flutter层有注册函数:
* FlutterBoost.singleton.registerPageBuilders({ * FlutterBoostPlugin.singleton.registerPageBuilders({
* 'first': (pageName, params, _) => FirstRouteWidget(), * 'first': (pageName, params, _) => FirstRouteWidget(),
* 'second': (pageName, params, _) => SecondRouteWidget(), * 'second': (pageName, params, _) => SecondRouteWidget(),
* ... * ...
......
...@@ -6,8 +6,6 @@ import android.support.v7.app.AppCompatActivity; ...@@ -6,8 +6,6 @@ import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -52,7 +50,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ...@@ -52,7 +50,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
PageRouter.openPageByUrl(this, PageRouter.NATIVE_PAGE_URL , params); PageRouter.openPageByUrl(this, PageRouter.NATIVE_PAGE_URL , params);
} else if (v == mOpenFlutter) { } else if (v == mOpenFlutter) {
PageRouter.openPageByUrl(this, PageRouter.FLUTTER_PAGE_URL,params); PageRouter.openPageByUrl(this, PageRouter.FLUTTER_PAGE_URL,params);
FlutterBoostPlugin.onPageResult("result_id_100",new HashMap(),new HashMap());
} else if (v == mOpenFlutterFragment) { } else if (v == mOpenFlutterFragment) {
PageRouter.openPageByUrl(this, PageRouter.FLUTTER_FRAGMENT_PAGE_URL,params); PageRouter.openPageByUrl(this, PageRouter.FLUTTER_FRAGMENT_PAGE_URL,params);
} }
......
...@@ -3,9 +3,13 @@ package com.taobao.idlefish.flutterboostexample; ...@@ -3,9 +3,13 @@ package com.taobao.idlefish.flutterboostexample;
import android.app.Application; import android.app.Application;
import android.content.Context; 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.Debuger;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin; 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.IPlatform;
import com.taobao.idlefish.flutterboost.interfaces.IStateListener;
import java.util.Map; import java.util.Map;
...@@ -54,8 +58,8 @@ public class MyApplication extends FlutterApplication { ...@@ -54,8 +58,8 @@ public class MyApplication extends FlutterApplication {
} }
@Override @Override
public Map getSettings() { public int whenEngineStart() {
return null; return IMMEDIATELY;
} }
}); });
} }
......
...@@ -11,4 +11,47 @@ ...@@ -11,4 +11,47 @@
android:layout_weight="1" android:layout_weight="1"
android:id="@+id/fragment_stub"/> 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> </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