Commit 50baf018 authored by yangwu.jia's avatar yangwu.jia

code fomat

parent 903b9f7a
......@@ -7,7 +7,6 @@ import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import com.idlefish.flutterboost.interfaces.*;
import io.flutter.Log;
import io.flutter.embedding.android.FlutterView;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs;
......@@ -29,15 +28,16 @@ public class FlutterBoost {
private PluginRegistry mRegistry;
static FlutterBoost sInstance = null;
private long FlutterPostFrameCallTime=0;
private long FlutterPostFrameCallTime = 0;
public long getFlutterPostFrameCallTime(){
public long getFlutterPostFrameCallTime() {
return FlutterPostFrameCallTime;
}
public void setFlutterPostFrameCallTime(long FlutterPostFrameCallTime){
this.FlutterPostFrameCallTime=FlutterPostFrameCallTime;
public void setFlutterPostFrameCallTime(long FlutterPostFrameCallTime) {
this.FlutterPostFrameCallTime = FlutterPostFrameCallTime;
}
public static FlutterBoost instance() {
if (sInstance == null) {
sInstance = new FlutterBoost();
......@@ -51,19 +51,13 @@ public class FlutterBoost {
mPlatform = platform;
mManager = new FlutterViewContainerManager();
platform.getApplication().registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
Log.e("bbbb1", "xxxxx");
mCurrentActiveActivity=activity;
mCurrentActiveActivity = activity;
if (mPlatform.whenEngineStart() == ConfigBuilder.ANY_ACTIVITY_CREATED) {
Log.e("bbbb2", "xxxxx");
doInitialFlutter();
}
}
......@@ -131,33 +125,24 @@ public class FlutterBoost {
}
}
public void doInitialFlutter() {
if(mEngine!=null) return;
if (mEngine != null) return;
FlutterEngine flutterEngine = createEngine();
if(mPlatform.lifecycleListener!=null){
if (mPlatform.lifecycleListener != null) {
mPlatform.lifecycleListener.onEngineCreated();
}
if (flutterEngine.getDartExecutor().isExecutingDart()) {
// No warning is logged because this situation will happen on every config
// change if the developer does not choose to retain the Fragment instance.
// So this is expected behavior in many cases.
return;
}
// The engine needs to receive the Flutter app's initial route before executing any
// Dart code to ensure that the initial route arrives in time to be applied.
if (mPlatform.initialRoute() != null) {
flutterEngine.getNavigationChannel().setInitialRoute(mPlatform.initialRoute());
}
// Configure the Dart entrypoint and execute it.
DartExecutor.DartEntrypoint entrypoint = new DartExecutor.DartEntrypoint(
FlutterMain.findAppBundlePath(),
"main"
......@@ -225,19 +210,21 @@ public class FlutterBoost {
return this;
}
public ConfigBuilder whenEngineStart( int whenEngineStart) {
public ConfigBuilder whenEngineStart(int whenEngineStart) {
this.whenEngineStart = whenEngineStart;
return this;
}
public ConfigBuilder whenEngineDestory( int whenEngineDestory) {
public ConfigBuilder whenEngineDestory(int whenEngineDestory) {
this.whenEngineDestory = whenEngineDestory;
return this;
}
public ConfigBuilder lifecycleListener( BoostLifecycleListener lifecycleListener) {
public ConfigBuilder lifecycleListener(BoostLifecycleListener lifecycleListener) {
this.lifecycleListener = lifecycleListener;
return this;
}
public Platform build() {
Platform platform = new Platform() {
......@@ -275,7 +262,7 @@ public class FlutterBoost {
}
};
platform.lifecycleListener=this.lifecycleListener;
platform.lifecycleListener = this.lifecycleListener;
return platform;
......@@ -303,11 +290,11 @@ public class FlutterBoost {
return mManager.findContainerById(id);
}
public PluginRegistry getPluginRegistry(){
public PluginRegistry getPluginRegistry() {
return mRegistry;
}
private FlutterEngine createEngine(){
private FlutterEngine createEngine() {
if (mEngine == null) {
FlutterMain.startInitialization(mPlatform.getApplication());
......@@ -331,7 +318,7 @@ public class FlutterBoost {
throw new RuntimeException(t);
}
if(mPlatform.lifecycleListener!=null){
if (mPlatform.lifecycleListener != null) {
mPlatform.lifecycleListener.onPluginsRegistered();
}
......@@ -343,22 +330,24 @@ public class FlutterBoost {
}
public void boostDestroy(){
if(mEngine!=null){
public void boostDestroy() {
if (mEngine != null) {
mEngine.destroy();
}
if(mPlatform.lifecycleListener!=null){
if (mPlatform.lifecycleListener != null) {
mPlatform.lifecycleListener.onEngineDestroy();
}
mEngine=null;
mRegistry=null;
mCurrentActiveActivity=null;
mEngine = null;
mRegistry = null;
mCurrentActiveActivity = null;
}
public interface BoostLifecycleListener {
void onEngineCreated();
void onPluginsRegistered();
void onEngineDestroy();
}
......
......@@ -46,13 +46,6 @@ public class FlutterBoostPlugin {
a.onChannelRegistered(sInstance);
}
// if (NewFlutterBoost.instance() != null) {
// final IStateListener stateListener = NewFlutterBoost.instance().mStateListener;
// if (stateListener != null) {
// stateListener.onChannelRegistered(registrar, sInstance);
// }
// }
sActions.clear();
}
......
......@@ -15,6 +15,7 @@ public abstract class Platform {
public abstract void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts);
public abstract int whenEngineStart();
public abstract int whenEngineDestroy();
public abstract FlutterView.RenderMode renderMode();
......@@ -32,7 +33,4 @@ public abstract class Platform {
}
}
......@@ -73,27 +73,23 @@ public class BoostFlutterActivity extends Activity
private Map params = new HashMap();
protected NewEngineIntentBuilder(@NonNull Class<? extends BoostFlutterActivity> activityClass) {
this.activityClass = activityClass;
}
public NewEngineIntentBuilder url (@NonNull String url) {
public NewEngineIntentBuilder url(@NonNull String url) {
this.url = url;
return this;
}
public NewEngineIntentBuilder params (@NonNull Map params) {
public NewEngineIntentBuilder params(@NonNull Map params) {
this.params = params;
return this;
}
public NewEngineIntentBuilder backgroundMode(@NonNull BackgroundMode backgroundMode) {
this.backgroundMode = backgroundMode.name();
return this;
......@@ -102,7 +98,7 @@ public class BoostFlutterActivity extends Activity
public Intent build(@NonNull Context context) {
SerializableMap serializableMap=new SerializableMap();
SerializableMap serializableMap = new SerializableMap();
serializableMap.setMap(params);
return new Intent(context, activityClass)
......@@ -115,7 +111,7 @@ public class BoostFlutterActivity extends Activity
public static class SerializableMap implements Serializable {
private Map<String,Object> map;
private Map<String, Object> map;
public Map<String, Object> getMap() {
return map;
......@@ -173,7 +169,7 @@ public class BoostFlutterActivity extends Activity
public SplashScreen provideSplashScreen() {
Drawable manifestSplashDrawable = getSplashScreenFromManifest();
if (manifestSplashDrawable != null) {
return new DrawableSplashScreen(manifestSplashDrawable, ImageView.ScaleType.CENTER,500L);
return new DrawableSplashScreen(manifestSplashDrawable, ImageView.ScaleType.CENTER, 500L);
} else {
return null;
}
......@@ -244,7 +240,7 @@ public class BoostFlutterActivity extends Activity
}
protected XFlutterView getFlutterView(){
protected XFlutterView getFlutterView() {
return delegate.getFlutterView();
}
......@@ -370,7 +366,6 @@ public class BoostFlutterActivity extends Activity
}
/**
* Returns true if Flutter is running in "debug mode", and false otherwise.
* <p>
......@@ -470,9 +465,6 @@ public class BoostFlutterActivity extends Activity
}
@Override
public String getContainerUrl() {
if (getIntent().hasExtra(EXTRA_URL)) {
......@@ -486,11 +478,11 @@ public class BoostFlutterActivity extends Activity
public Map getContainerUrlParams() {
if (getIntent().hasExtra(EXTRA_PARAMS)) {
SerializableMap serializableMap= (SerializableMap)getIntent().getSerializableExtra(EXTRA_PARAMS);
SerializableMap serializableMap = (SerializableMap) getIntent().getSerializableExtra(EXTRA_PARAMS);
return serializableMap.getMap();
}
Map<String,String> params = new HashMap<>();
Map<String, String> params = new HashMap<>();
return params;
}
......
......@@ -58,8 +58,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
protected IOperateSyncer mSyncer;
FlutterActivityAndFragmentDelegate(@NonNull Host host) {
this.host = host;
}
......@@ -77,7 +75,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
return flutterEngine;
}
XFlutterView getFlutterView(){
XFlutterView getFlutterView() {
return flutterView;
}
......@@ -107,8 +105,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
}
private void setupFlutterEngine() {
Log.d(TAG, "Setting up FlutterEngine.");
......@@ -172,7 +168,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
}
void onResume() {
mSyncer.onAppear();
......@@ -180,9 +175,9 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
ensureAlive();
flutterEngine.getLifecycleChannel().appIsResumed();
BoostPluginRegistry registry= (BoostPluginRegistry) FlutterBoost.instance().getPluginRegistry();
ActivityPluginBinding binding=registry.getRegistrarAggregate().getActivityPluginBinding();
if(binding!=null&&(binding.getActivity()!=this.host.getActivity())){
BoostPluginRegistry registry = (BoostPluginRegistry) FlutterBoost.instance().getPluginRegistry();
ActivityPluginBinding binding = registry.getRegistrarAggregate().getActivityPluginBinding();
if (binding != null && (binding.getActivity() != this.host.getActivity())) {
flutterEngine.getActivityControlSurface().attachToActivity(
host.getActivity(),
host.getLifecycle()
......@@ -195,7 +190,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
void onPostResume() {
Log.v(TAG, "onPostResume()");
ensureAlive();
Utils.setStatusBarLightMode(host.getActivity(),true);
Utils.setStatusBarLightMode(host.getActivity(), true);
}
......@@ -221,9 +216,9 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
mSyncer.onDestroy();
ensureAlive();
BoostPluginRegistry registry= (BoostPluginRegistry) FlutterBoost.instance().getPluginRegistry();
ActivityPluginBinding binding=registry.getRegistrarAggregate().getActivityPluginBinding();
if(binding!=null&&(binding.getActivity()==this.host.getActivity())){
BoostPluginRegistry registry = (BoostPluginRegistry) FlutterBoost.instance().getPluginRegistry();
ActivityPluginBinding binding = registry.getRegistrarAggregate().getActivityPluginBinding();
if (binding != null && (binding.getActivity() == this.host.getActivity())) {
registry.getRegistrarAggregate().onDetachedFromActivityForConfigChanges();
flutterEngine.getActivityControlSurface().detachFromActivityForConfigChanges();
......@@ -237,7 +232,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
ensureAlive();
// Null out the platformPlugin to avoid a possible retain cycle between the plugin, this Fragment,
// and this Fragment's Activity.
if (platformPlugin != null) {
......@@ -287,16 +281,16 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
void onActivityResult(int requestCode, int resultCode, Intent data) {
mSyncer.onActivityResult(requestCode,resultCode,data);
Map<String,Object> result = null;
if(data != null) {
mSyncer.onActivityResult(requestCode, resultCode, data);
Map<String, Object> result = null;
if (data != null) {
Serializable rlt = data.getSerializableExtra(RESULT_KEY);
if(rlt instanceof Map) {
result = (Map<String,Object>)rlt;
if (rlt instanceof Map) {
result = (Map<String, Object>) rlt;
}
}
mSyncer.onContainerResult(requestCode,resultCode,result);
mSyncer.onContainerResult(requestCode, resultCode, result);
ensureAlive();
......@@ -360,7 +354,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
@Override
public Activity getContextActivity() {
return (Activity)this.host.getActivity();
return (Activity) this.host.getActivity();
}
@Override
......@@ -371,10 +365,10 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
@Override
public void finishContainer(Map<String, Object> result) {
if(result != null) {
setBoostResult(this.host.getActivity(),new HashMap<>(result));
if (result != null) {
setBoostResult(this.host.getActivity(), new HashMap<>(result));
this.host.getActivity().finish();
}else{
} else {
this.host.getActivity().finish();
}
......@@ -382,7 +376,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
}
public void setBoostResult(Activity activity, HashMap result) {
Intent intent = new Intent();
if (result != null) {
......@@ -390,6 +383,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
}
activity.setResult(Activity.RESULT_OK, intent);
}
@Override
public String getContainerUrl() {
return this.host.getContainerUrl();
......@@ -486,12 +480,9 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
boolean shouldAttachEngineToActivity();
String getContainerUrl();
String getContainerUrl() ;
Map getContainerUrlParams() ;
Map getContainerUrlParams();
}
......
......@@ -115,6 +115,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
private boolean shouldAttachEngineToActivity = true;
private String url = "";
private Map params = new HashMap();
/**
* Constructs a {@code NewEngineFragmentBuilder} that is configured to construct an instance of
* {@code NewFlutterFragment}.
......@@ -132,7 +133,6 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
}
/**
* Any special configuration arguments for the Flutter engine
*/
......@@ -155,16 +155,18 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
this.renderMode = renderMode;
return this;
}
public NewEngineFragmentBuilder url (@NonNull String url) {
public NewEngineFragmentBuilder url(@NonNull String url) {
this.url = url;
return this;
}
public NewEngineFragmentBuilder params (@NonNull Map params) {
public NewEngineFragmentBuilder params(@NonNull Map params) {
this.params = params;
return this;
}
/**
* Support a {@link FlutterView.TransparencyMode#transparent} background within {@link FlutterView},
* or force an {@link FlutterView.TransparencyMode#opaque} background.
......@@ -178,7 +180,6 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
}
@NonNull
protected Bundle createArgs() {
Bundle args = new Bundle();
......@@ -188,7 +189,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
args.putStringArray(ARG_FLUTTER_INITIALIZATION_ARGS, shellArgs.toArray());
}
BoostFlutterActivity.SerializableMap serializableMap=new BoostFlutterActivity.SerializableMap();
BoostFlutterActivity.SerializableMap serializableMap = new BoostFlutterActivity.SerializableMap();
serializableMap.setMap(params);
args.putString(EXTRA_URL, url);
......@@ -232,7 +233,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
private FlutterActivityAndFragmentDelegate delegate;
protected XFlutterView getFlutterView(){
protected XFlutterView getFlutterView() {
return delegate.getFlutterView();
}
......@@ -492,8 +493,6 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
}
@Override
public String getContainerUrl() {
......@@ -505,7 +504,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
@Override
public Map getContainerUrlParams() {
BoostFlutterActivity.SerializableMap serializableMap= (BoostFlutterActivity.SerializableMap) getArguments().getSerializable(EXTRA_PARAMS);
BoostFlutterActivity.SerializableMap serializableMap = (BoostFlutterActivity.SerializableMap) getArguments().getSerializable(EXTRA_PARAMS);
return serializableMap.getMap();
}
......
......@@ -49,8 +49,6 @@ public class FlutterSplashView extends FrameLayout {
@Override
public void onFlutterEngineAttachedToFlutterView(@NonNull FlutterEngine engine) {
flutterView.removeFlutterEngineAttachmentListener(this);
// displayFlutterViewWithSplash(flutterView, splashScreen);
// splashScreenTransitionNeededNow();
}
@Override
......@@ -60,15 +58,16 @@ public class FlutterSplashView extends FrameLayout {
@NonNull
private final OnFirstFrameRenderedListener onFirstFrameRenderedListener = new OnFirstFrameRenderedListener() {
int i=0;
int i = 0;
@Override
public void onFirstFrameRendered() {
if(FlutterBoost.instance().platform().whenEngineStart()== FlutterBoost.ConfigBuilder.FLUTTER_ACTIVITY_CREATED){
long now=new Date().getTime();
long flutterPostFrameCallTime= FlutterBoost.instance().getFlutterPostFrameCallTime();
if (FlutterBoost.instance().platform().whenEngineStart() == FlutterBoost.ConfigBuilder.FLUTTER_ACTIVITY_CREATED) {
long now = new Date().getTime();
long flutterPostFrameCallTime = FlutterBoost.instance().getFlutterPostFrameCallTime();
if(flutterPostFrameCallTime!=0&& (now-flutterPostFrameCallTime)>800){
if (flutterPostFrameCallTime != 0 && (now - flutterPostFrameCallTime) > 800) {
if (splashScreen != null) {
transitionToFlutter();
}
......@@ -83,17 +82,13 @@ public class FlutterSplashView extends FrameLayout {
}, 200);
}else{
} else {
if (splashScreen != null) {
transitionToFlutter();
}
}
}
};
......@@ -155,79 +150,9 @@ public class FlutterSplashView extends FrameLayout {
splashScreenView.setBackgroundColor(Color.WHITE);
addView(this.splashScreenView);
flutterView.addOnFirstFrameRenderedListener(onFirstFrameRenderedListener);
// if (splashScreen != null) {
// if (this.isSplashScreenNeededNow()) {
// Log.v(TAG, "Showing splash screen UI.");
// this.splashScreenView = splashScreen.createSplashView(this.getContext(), this.splashScreenState);
// this.addView(this.splashScreenView);
// flutterView.addOnFirstFrameRenderedListener(this.onFirstFrameRenderedListener);
// } else if (this.isSplashScreenTransitionNeededNow()) {
// Log.v(TAG, "Showing an immediate splash transition to Flutter due to previously interrupted transition.");
// this.splashScreenView = splashScreen.createSplashView(this.getContext(), this.splashScreenState);
// this.addView(this.splashScreenView);
// this.transitionToFlutter();
// } else if (!flutterView.isAttachedToFlutterEngine()) {
// Log.v(TAG, "FlutterView is not yet attached to a FlutterEngine. Showing nothing until a FlutterEngine is attached.");
// flutterView.addFlutterEngineAttachmentListener(this.flutterEngineAttachmentListener);
// }
// }
}
}
/**
* Returns true if current conditions require a splash UI to be displayed.
* <p>
* This method does not evaluate whether a previously interrupted splash transition needs
* to resume. See {@link #isSplashScreenTransitionNeededNow()} to answer that question.
*/
private boolean isSplashScreenNeededNow() {
return flutterView != null
&& flutterView.isAttachedToFlutterEngine()
&& !flutterView.hasRenderedFirstFrame()
&& !hasSplashCompleted();
}
/**
* Returns true if a previous splash transition was interrupted by recreation, e.g., an
* orientation change, and that previous transition should be resumed.
* <p>
* Not all splash screens are capable of remembering their transition progress. In those
* cases, this method will return false even if a previous visual transition was
* interrupted.
*/
private boolean isSplashScreenTransitionNeededNow() {
return flutterView != null
&& flutterView.isAttachedToFlutterEngine()
&& splashScreen != null
&& splashScreen.doesSplashViewRememberItsTransition()
&& wasPreviousSplashTransitionInterrupted();
}
/**
* Returns true if a splash screen was transitioning to a Flutter experience and was then
* interrupted, e.g., by an Android configuration change. Returns false otherwise.
* <p>
* Invoking this method expects that a {@code flutterView} exists and it is attached to a
* {@code FlutterEngine}.
*/
private boolean wasPreviousSplashTransitionInterrupted() {
if (flutterView == null) {
throw new IllegalStateException("Cannot determine if previous splash transition was " +
"interrupted when no FlutterView is set.");
}
if (!flutterView.isAttachedToFlutterEngine()) {
throw new IllegalStateException("Cannot determine if previous splash transition was "
+ "interrupted when no FlutterEngine is attached to our FlutterView. This question "
+ "depends on an isolate ID to differentiate Flutter experiences.");
}
return flutterView.hasRenderedFirstFrame() && !hasSplashCompleted();
}
/**
* Returns true if a splash UI for a specific Flutter experience has already completed.
......@@ -271,37 +196,6 @@ public class FlutterSplashView extends FrameLayout {
splashScreen.transitionToFlutter(onTransitionComplete);
}
public static class SavedState extends BaseSavedState {
public static Creator CREATOR = new Creator() {
public FlutterSplashView.SavedState createFromParcel(Parcel source) {
return new FlutterSplashView.SavedState(source);
}
public FlutterSplashView.SavedState[] newArray(int size) {
return new FlutterSplashView.SavedState[size];
}
};
private String previousCompletedSplashIsolate;
private Bundle splashScreenState;
SavedState(Parcelable superState) {
super(superState);
}
SavedState(Parcel source) {
super(source);
this.previousCompletedSplashIsolate = source.readString();
this.splashScreenState = source.readBundle(this.getClass().getClassLoader());
}
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeString(this.previousCompletedSplashIsolate);
out.writeBundle(this.splashScreenState);
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
......
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