Commit ac3bc276 authored by shaode.lsd's avatar shaode.lsd Committed by justin

pick from support banch f3aff2af

parent c2f75ac5
...@@ -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
...@@ -28,8 +28,8 @@ public class XPlatformPlugin { ...@@ -28,8 +28,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;
...@@ -95,26 +95,25 @@ public class XPlatformPlugin { ...@@ -95,26 +95,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;
}
}
...@@ -230,7 +230,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer ...@@ -230,7 +230,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;
} }
......
...@@ -14,13 +14,11 @@ import androidx.fragment.app.Fragment; ...@@ -14,13 +14,11 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
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;
...@@ -469,8 +467,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm ...@@ -469,8 +467,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