Commit f3aff2af authored by shaode.lsd's avatar shaode.lsd

optimized:

  把XPlatformPlugin进行复用,解决了statusbar在多个activity中显示异常的问题。
parent 9b5285b2
...@@ -17,3 +17,4 @@ example/android/app/.classpath ...@@ -17,3 +17,4 @@ example/android/app/.classpath
example/android/app/.project example/android/app/.project
example/android/.project example/android/.project
flutter_boost flutter_boost
.flutter-plugins-dependencies
...@@ -29,8 +29,8 @@ public class XPlatformPlugin { ...@@ -29,8 +29,8 @@ public class XPlatformPlugin {
public static final int DEFAULT_SYSTEM_UI = View.SYSTEM_UI_FLAG_LAYOUT_STABLE public static final int DEFAULT_SYSTEM_UI = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
private Activity activity; private Activity activity;
private PlatformChannel platformChannel; private PlatformChannel platformChannel;
private PlatformChannel.SystemChromeStyle currentTheme; private PlatformChannel.SystemChromeStyle currentTheme;
private int mEnabledOverlays; private int mEnabledOverlays;
...@@ -96,26 +96,25 @@ public class XPlatformPlugin { ...@@ -96,26 +96,25 @@ public class XPlatformPlugin {
} }
}; };
public XPlatformPlugin( PlatformChannel platformChannel) { public XPlatformPlugin(PlatformChannel platformChannel) {
this.platformChannel = platformChannel; this.platformChannel = platformChannel;
this.platformChannel.setPlatformMessageHandler(mPlatformMessageHandler);
mEnabledOverlays = DEFAULT_SYSTEM_UI; mEnabledOverlays = DEFAULT_SYSTEM_UI;
} }
public void attachToActivity(Activity activity ){ public void attachToActivity(Activity activity ){
this.activity = activity; this.activity = activity;
this.platformChannel.setPlatformMessageHandler(mPlatformMessageHandler);
} }
/** /**
* Releases all resources held by this {@code PlatformPlugin}. * Releases all resources held by this {@code PlatformPlugin}.
* <p> * <p>
* Do not invoke any methods on a {@code PlatformPlugin} after invoking this method. * Do not invoke any methods on a {@code PlatformPlugin} after invoking this method.
*/ */
public void detachActivity() { public void detachActivity(Activity activity) {
this.activity=null; if (activity == this.activity) {
this.mPlatformMessageHandler=null; this.activity = null;
}
} }
private void playSystemSound(PlatformChannel.SoundType soundType) { private void playSystemSound(PlatformChannel.SoundType soundType) {
......
...@@ -56,6 +56,7 @@ public class BoostFlutterActivity extends Activity ...@@ -56,6 +56,7 @@ public class BoostFlutterActivity extends Activity
// Default configuration. // Default configuration.
protected static final String DEFAULT_BACKGROUND_MODE = BackgroundMode.opaque.name(); protected static final String DEFAULT_BACKGROUND_MODE = BackgroundMode.opaque.name();
private static XPlatformPlugin sXPlatformPlugin;
public static Intent createDefaultIntent(@NonNull Context launchContext) { public static Intent createDefaultIntent(@NonNull Context launchContext) {
return withNewEngine().build(launchContext); return withNewEngine().build(launchContext);
...@@ -440,8 +441,8 @@ public class BoostFlutterActivity extends Activity ...@@ -440,8 +441,8 @@ public class BoostFlutterActivity extends Activity
@Nullable @Nullable
@Override @Override
public XPlatformPlugin providePlatformPlugin( @NonNull FlutterEngine flutterEngine) { public XPlatformPlugin providePlatformPlugin(@NonNull FlutterEngine flutterEngine) {
return new XPlatformPlugin( flutterEngine.getPlatformChannel()); return BoostViewUtils.getPlatformPlugin(flutterEngine.getPlatformChannel());
} }
/** /**
......
package com.idlefish.flutterboost.containers;
import com.idlefish.flutterboost.XPlatformPlugin;
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
class BoostViewUtils {
private static volatile XPlatformPlugin mInstance;
private BoostViewUtils() {
}
public static XPlatformPlugin getPlatformPlugin(PlatformChannel channel) {
if (mInstance == null) {
synchronized (BoostViewUtils.class) {
if (mInstance == null) {
mInstance = new XPlatformPlugin(channel);
}
}
}
return mInstance;
}
}
...@@ -228,7 +228,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer ...@@ -228,7 +228,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer
// Null out the platformPlugin to avoid a possible retain cycle between the plugin, this Fragment, // Null out the platformPlugin to avoid a possible retain cycle between the plugin, this Fragment,
// and this Fragment's Activity. // and this Fragment's Activity.
if (platformPlugin != null) { if (platformPlugin != null) {
platformPlugin.detachActivity(); platformPlugin.detachActivity(getContextActivity());
platformPlugin = null; platformPlugin = null;
} }
......
...@@ -2,8 +2,6 @@ package com.idlefish.flutterboost.containers; ...@@ -2,8 +2,6 @@ package com.idlefish.flutterboost.containers;
import android.app.Activity; import android.app.Activity;
import android.arch.lifecycle.Lifecycle; import android.arch.lifecycle.Lifecycle;
import android.graphics.Color;
import android.view.*;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
...@@ -17,13 +15,11 @@ import android.view.View; ...@@ -17,13 +15,11 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.idlefish.flutterboost.FlutterBoost; import com.idlefish.flutterboost.FlutterBoost;
import com.idlefish.flutterboost.Utils;
import com.idlefish.flutterboost.XFlutterView; import com.idlefish.flutterboost.XFlutterView;
import com.idlefish.flutterboost.XPlatformPlugin; import com.idlefish.flutterboost.XPlatformPlugin;
import io.flutter.embedding.android.*; import io.flutter.embedding.android.*;
import io.flutter.embedding.engine.FlutterEngine; import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs; import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.plugin.platform.PlatformPlugin;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -472,8 +468,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -472,8 +468,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
@Nullable @Nullable
@Override @Override
public XPlatformPlugin providePlatformPlugin( @NonNull FlutterEngine flutterEngine) { public XPlatformPlugin providePlatformPlugin( @NonNull FlutterEngine flutterEngine) {
return new XPlatformPlugin(flutterEngine.getPlatformChannel()); return BoostViewUtils.getPlatformPlugin(flutterEngine.getPlatformChannel());
} }
/** /**
......
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