Commit 73317284 authored by nightfallsad's avatar nightfallsad Committed by GitHub

Merge pull request #1 from alibaba/feature/flutter_1.9_androidx_upgrade

update fork
parents ddcb94a1 2a03cb50
......@@ -2,9 +2,11 @@ package com.idlefish.flutterboost;
import android.app.Activity;
import android.content.Context;
import android.support.annotation.Nullable;
import com.idlefish.flutterboost.interfaces.IContainerRecord;
import io.flutter.app.FlutterPluginRegistry;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.platform.PlatformViewRegistry;
......@@ -13,23 +15,24 @@ import io.flutter.view.TextureRegistry;
import java.lang.ref.WeakReference;
public class BoostPluginRegistry extends FlutterPluginRegistry {
public class BoostPluginRegistry extends ShimPluginRegistry {
protected WeakReference<Activity> mCurrentActivityRef;
private FlutterEngine mEngine;
private Context mContext;
public BoostPluginRegistry(FlutterEngine engine, Context context) {
super(engine, context);
super(engine);
mEngine = engine;
mContext=context;
}
public PluginRegistry.Registrar registrarFor(String pluginKey) {
return new BoostRegistrar(mEngine, super.registrarFor(pluginKey));
}
public void currentActivity(@Nullable Activity activity) {
mCurrentActivityRef = new WeakReference<>(activity);
}
public class BoostRegistrar implements PluginRegistry.Registrar {
......@@ -70,12 +73,12 @@ public class BoostPluginRegistry extends FlutterPluginRegistry {
@Override
public Context context() {
return mRegistrar.context();
return BoostPluginRegistry.this.mContext;
}
@Override
public Context activeContext() {
return mRegistrar.activeContext();
return BoostPluginRegistry.this.mContext;
}
@Override
......@@ -90,7 +93,7 @@ public class BoostPluginRegistry extends FlutterPluginRegistry {
@Override
public PlatformViewRegistry platformViewRegistry() {
return mRegistrar.platformViewRegistry();
return mEngine.getPlatformViewsController().getRegistry();
}
@Override
......
......@@ -23,7 +23,7 @@ public class NewFlutterBoost {
private FlutterViewContainerManager mManager;
private Activity mCurrentActiveActivity;
private BoostPluginRegistry mRegistry;
static NewFlutterBoost sInstance = null;
......@@ -40,10 +40,9 @@ public class NewFlutterBoost {
mPlatform = platform;
mManager = new FlutterViewContainerManager();
if (mPlatform.whenEngineStart() == ConfigBuilder.IMMEDIATELY) {
doInitialFlutterViewRun(mPlatform);
}
mRegistry = new BoostPluginRegistry(this.engineProvider(),
mPlatform.getApplication());
platform.getApplication().registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
......@@ -53,8 +52,8 @@ public class NewFlutterBoost {
if (mPlatform.whenEngineStart() == ConfigBuilder.ANY_ACTIVITY_CREATED) {
Log.e("bbbb2", "xxxxx");
doInitialFlutterViewRun(mPlatform);
mRegistry.currentActivity(activity);
doInitialFlutterViewRun(mPlatform,mRegistry);
}
}
......@@ -116,15 +115,16 @@ public class NewFlutterBoost {
}
});
if (mPlatform.whenEngineStart() == ConfigBuilder.IMMEDIATELY) {
doInitialFlutterViewRun(mPlatform,mRegistry);
}
BoostPluginRegistry registry = new BoostPluginRegistry(this.engineProvider(),
mPlatform.getApplication());
mPlatform.registerPlugins(registry);
}
private void doInitialFlutterViewRun(Platform platform) {
private void doInitialFlutterViewRun(Platform platform,BoostPluginRegistry registry) {
// Don't attempt to start a FlutterEngine if we're using a cached FlutterEngine.
// if (host.getCachedEngineId() != null) {
// return;
......@@ -137,8 +137,8 @@ public class NewFlutterBoost {
// So this is expected behavior in many cases.
return;
}
platform.registerPlugins(registry);
Log.e("bbbb3", "xxxxx");
// 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 (platform.initialRoute() != null) {
......@@ -268,5 +268,7 @@ public class NewFlutterBoost {
return mManager.findContainerById(id);
}
public BoostPluginRegistry getPluginRegistry(){
return mRegistry;
}
}
......@@ -686,7 +686,7 @@ public class XFlutterView extends FrameLayout {
resolveMemoryLeaks();
// Instruct our FlutterRenderer that we are no longer interested in being its RenderSurface.
FlutterRenderer flutterRenderer = flutterEngine.getRenderer();
didRenderFirstFrame = false;
// didRenderFirstFrame = false;
flutterRenderer.removeOnFirstFrameRenderedListener(onFirstFrameRenderedListener);
flutterRenderer.detachFromRenderSurface();
flutterEngine = null;
......
......@@ -28,7 +28,6 @@ import io.flutter.app.FlutterActivity;
import io.flutter.embedding.android.*;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.embedding.engine.renderer.OnFirstFrameRenderedListener;
import io.flutter.plugin.platform.PlatformPlugin;
import io.flutter.view.FlutterMain;
......@@ -56,15 +55,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
protected IOperateSyncer mSyncer;
@NonNull
private final OnFirstFrameRenderedListener onFirstFrameRenderedListener = new OnFirstFrameRenderedListener() {
@Override
public void onFirstFrameRendered() {
if(host!=null){
host.onFirstFrameRendered();
}
}
};
FlutterActivityAndFragmentDelegate(@NonNull Host host) {
this.host = host;
......@@ -171,7 +162,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
ensureAlive();
flutterView = new XFlutterView(host.getActivity(), NewFlutterBoost.instance().platform().renderMode(), host.getTransparencyMode());
flutterView.addOnFirstFrameRenderedListener(onFirstFrameRenderedListener);
flutterSplashView = new FlutterSplashView(host.getContext());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
......@@ -247,7 +237,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
mSyncer.onDestroy();
ensureAlive();
flutterView.removeOnFirstFrameRenderedListener(onFirstFrameRenderedListener);
}
......@@ -512,11 +501,6 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContaine
*/
boolean shouldAttachEngineToActivity();
/**
* Invoked by this delegate when its {@link FlutterView} has rendered its first Flutter
* frame.
*/
void onFirstFrameRendered();
void finishContainer(Map<String, Object> result) ;
......
......@@ -39,6 +39,8 @@ public class FlutterSplashView extends FrameLayout {
@Nullable
private String previousCompletedSplashIsolate;
private boolean hasRendered=false;
@NonNull
private final FlutterView.FlutterEngineAttachmentListener flutterEngineAttachmentListener = new FlutterView.FlutterEngineAttachmentListener() {
@Override
......@@ -57,8 +59,9 @@ public class FlutterSplashView extends FrameLayout {
private final OnFirstFrameRenderedListener onFirstFrameRenderedListener = new OnFirstFrameRenderedListener() {
@Override
public void onFirstFrameRendered() {
if (splashScreen != null) {
if (splashScreen != null&&!hasRendered) {
transitionToFlutter();
hasRendered=true;
}
}
};
......
......@@ -466,14 +466,6 @@ public class NewBoostFlutterActivity extends Activity
return true;
}
@Override
public void onFirstFrameRendered() {
}
......
......@@ -232,20 +232,6 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
// implementation for details about why it exists.
private FlutterActivityAndFragmentDelegate delegate;
private final OnFirstFrameRenderedListener onFirstFrameRenderedListener = new OnFirstFrameRenderedListener() {
@Override
public void onFirstFrameRendered() {
// Notify our subclasses that the first frame has been rendered.
NewFlutterFragment.this.onFirstFrameRendered();
// Notify our owning Activity that the first frame has been rendered.
FragmentActivity fragmentActivity = getActivity();
if (fragmentActivity instanceof OnFirstFrameRenderedListener) {
OnFirstFrameRenderedListener activityAsListener = (OnFirstFrameRenderedListener) fragmentActivity;
activityAsListener.onFirstFrameRendered();
}
}
};
public NewFlutterFragment() {
// Ensure that we at least have an empty Bundle of arguments so that we don't
......@@ -502,24 +488,6 @@ public class NewFlutterFragment extends Fragment implements FlutterActivityAndFr
return getArguments().getBoolean(ARG_SHOULD_ATTACH_ENGINE_TO_ACTIVITY);
}
/**
* Invoked after the {@link FlutterView} within this {@code NewFlutterFragment} renders its first
* frame.
* <p>
* This method forwards {@code onFirstFrameRendered()} to its attached {@code Activity}, if
* the attached {@code Activity} implements {@link OnFirstFrameRenderedListener}.
* <p>
* Subclasses that override this method must call through to the {@code super} method.
* <p>
* Used by this {@code NewFlutterFragment}'s {@link FlutterActivityAndFragmentDelegate.Host}
*/
@Override
public void onFirstFrameRendered() {
FragmentActivity attachedActivity = getActivity();
if (attachedActivity instanceof OnFirstFrameRenderedListener) {
((OnFirstFrameRenderedListener) attachedActivity).onFirstFrameRendered();
}
}
@Override
public void finishContainer(Map<String, Object> result) {
......
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