Commit ca458344 authored by justin's avatar justin

Merge branch 'task/task_v1.12.13_support_hotfixes' into task/task_v1.22

# Conflicts:
#	android/src/main/java/com/idlefish/flutterboost/FlutterBoost.java
#	lib/flutter_boost.dart
parents 1301ef67 fe722b1a
...@@ -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
...@@ -21,7 +21,9 @@ import io.flutter.plugin.common.PluginRegistry; ...@@ -21,7 +21,9 @@ import io.flutter.plugin.common.PluginRegistry;
import io.flutter.view.FlutterMain; import io.flutter.view.FlutterMain;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
public class FlutterBoost { public class FlutterBoost {
...@@ -216,6 +218,8 @@ public class FlutterBoost { ...@@ -216,6 +218,8 @@ public class FlutterBoost {
private INativeRouter router = null; private INativeRouter router = null;
private List<String> shellArgs;
private BoostLifecycleListener lifecycleListener; private BoostLifecycleListener lifecycleListener;
private FlutterEngineProvider flutterEngineProvider = null; private FlutterEngineProvider flutterEngineProvider = null;
...@@ -253,7 +257,6 @@ public class FlutterBoost { ...@@ -253,7 +257,6 @@ public class FlutterBoost {
return this; return this;
} }
public ConfigBuilder lifecycleListener(BoostLifecycleListener lifecycleListener) { public ConfigBuilder lifecycleListener(BoostLifecycleListener lifecycleListener) {
this.lifecycleListener = lifecycleListener; this.lifecycleListener = lifecycleListener;
return this; return this;
...@@ -264,6 +267,11 @@ public class FlutterBoost { ...@@ -264,6 +267,11 @@ public class FlutterBoost {
return this; return this;
} }
public ConfigBuilder shellArgs(List<String> shellArgs) {
this.shellArgs = shellArgs;
return this;
}
public Platform build() { public Platform build() {
Platform platform = new Platform() { Platform platform = new Platform() {
...@@ -296,6 +304,10 @@ public class FlutterBoost { ...@@ -296,6 +304,10 @@ public class FlutterBoost {
return ConfigBuilder.this.renderMode; return ConfigBuilder.this.renderMode;
} }
public List<String> shellArgs() {
return ConfigBuilder.this.shellArgs;
}
public FlutterEngineProvider flutterEngineProvider() { public FlutterEngineProvider flutterEngineProvider() {
return flutterEngineProvider; return flutterEngineProvider;
} }
...@@ -332,7 +344,7 @@ public class FlutterBoost { ...@@ -332,7 +344,7 @@ public class FlutterBoost {
if (mEngine == null) { if (mEngine == null) {
FlutterMain.startInitialization(mPlatform.getApplication()); FlutterMain.startInitialization(mPlatform.getApplication());
FlutterShellArgs flutterShellArgs = new FlutterShellArgs(new String[0]); FlutterShellArgs flutterShellArgs = new FlutterShellArgs(mPlatform.shellArgs() != null ? mPlatform.shellArgs() : Arrays.asList(new String[0]));
FlutterMain.ensureInitializationComplete( FlutterMain.ensureInitializationComplete(
mPlatform.getApplication().getApplicationContext(), flutterShellArgs.toArray()); mPlatform.getApplication().getApplicationContext(), flutterShellArgs.toArray());
if (mPlatform.flutterEngineProvider() != null) { if (mPlatform.flutterEngineProvider() != null) {
...@@ -344,8 +356,8 @@ public class FlutterBoost { ...@@ -344,8 +356,8 @@ public class FlutterBoost {
} }
// registerPlugins(mEngine); // registerPlugins(mEngine);
mRegistry = new BoostPluginRegistry(createEngine()); // mRegistry = new BoostPluginRegistry(createEngine());
mPlatform.registerPlugins(mRegistry); // mPlatform.registerPlugins(mRegistry);
} }
return mEngine; return mEngine;
......
...@@ -6,6 +6,7 @@ import android.util.Log; ...@@ -6,6 +6,7 @@ import android.util.Log;
import com.idlefish.flutterboost.interfaces.IContainerRecord; import com.idlefish.flutterboost.interfaces.IContainerRecord;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List;
import java.util.Map; import java.util.Map;
import io.flutter.embedding.android.FlutterEngineProvider; import io.flutter.embedding.android.FlutterEngineProvider;
...@@ -42,8 +43,9 @@ public abstract class Platform { ...@@ -42,8 +43,9 @@ public abstract class Platform {
public abstract String initialRoute(); public abstract String initialRoute();
public FlutterBoost.BoostLifecycleListener lifecycleListener; public abstract List<String> shellArgs();
public FlutterBoost.BoostLifecycleListener lifecycleListener;
public void closeContainer(IContainerRecord record, Map<String, Object> result, Map<String, Object> exts) { public void closeContainer(IContainerRecord record, Map<String, Object> result, Map<String, Object> exts) {
if (record == null) return; if (record == null) return;
......
...@@ -96,37 +96,42 @@ public class XPlatformPlugin { ...@@ -96,37 +96,42 @@ 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) {
if (getActivity() == null) {
return;
}
if (soundType == PlatformChannel.SoundType.CLICK) { if (soundType == PlatformChannel.SoundType.CLICK) {
View view = activity.getWindow().getDecorView(); View view = getActivity().getWindow().getDecorView();
view.playSoundEffect(SoundEffectConstants.CLICK); view.playSoundEffect(SoundEffectConstants.CLICK);
} }
} }
private void vibrateHapticFeedback(PlatformChannel.HapticFeedbackType feedbackType) { private void vibrateHapticFeedback(PlatformChannel.HapticFeedbackType feedbackType) {
View view = activity.getWindow().getDecorView(); if (getActivity() == null) {
return;
}
View view = getActivity().getWindow().getDecorView();
switch (feedbackType) { switch (feedbackType) {
case STANDARD: case STANDARD:
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
...@@ -148,11 +153,17 @@ public class XPlatformPlugin { ...@@ -148,11 +153,17 @@ public class XPlatformPlugin {
} }
private void setSystemChromePreferredOrientations(int androidOrientation) { private void setSystemChromePreferredOrientations(int androidOrientation) {
activity.setRequestedOrientation(androidOrientation); if (getActivity() == null) {
return;
}
getActivity().setRequestedOrientation(androidOrientation);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void setSystemChromeApplicationSwitcherDescription(PlatformChannel.AppSwitcherDescription description) { private void setSystemChromeApplicationSwitcherDescription(PlatformChannel.AppSwitcherDescription description) {
if (getActivity() == null) {
return;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return; return;
} }
...@@ -160,11 +171,12 @@ public class XPlatformPlugin { ...@@ -160,11 +171,12 @@ public class XPlatformPlugin {
// Linter refuses to believe we're only executing this code in API 28 unless we use distinct if blocks and // Linter refuses to believe we're only executing this code in API 28 unless we use distinct if blocks and
// hardcode the API 28 constant. // hardcode the API 28 constant.
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P && Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P && Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
activity.setTaskDescription(new ActivityManager.TaskDescription(description.label, /*icon=*/ null, description.color)); getActivity().setTaskDescription(new ActivityManager.TaskDescription(description.label, /*icon=*/ null, description.color));
} }
if (Build.VERSION.SDK_INT >= 28) { if (Build.VERSION.SDK_INT >= 28) {
ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(description.label, 0, description.color); ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(description.label, 0, description.color);
activity.setTaskDescription(taskDescription); getActivity().setTaskDescription(taskDescription);
} }
} }
...@@ -206,7 +218,10 @@ public class XPlatformPlugin { ...@@ -206,7 +218,10 @@ public class XPlatformPlugin {
* {@code PlatformPlugin}. * {@code PlatformPlugin}.
*/ */
public void updateSystemUiOverlays(){ public void updateSystemUiOverlays(){
activity.getWindow().getDecorView().setSystemUiVisibility(mEnabledOverlays); if (getActivity() == null) {
return;
}
getActivity().getWindow().getDecorView().setSystemUiVisibility(mEnabledOverlays);
if (currentTheme != null) { if (currentTheme != null) {
setSystemChromeSystemUIOverlayStyle(currentTheme); setSystemChromeSystemUIOverlayStyle(currentTheme);
} }
...@@ -217,7 +232,10 @@ public class XPlatformPlugin { ...@@ -217,7 +232,10 @@ public class XPlatformPlugin {
} }
private void setSystemChromeSystemUIOverlayStyle(PlatformChannel.SystemChromeStyle systemChromeStyle) { private void setSystemChromeSystemUIOverlayStyle(PlatformChannel.SystemChromeStyle systemChromeStyle) {
Window window = activity.getWindow(); if (getActivity() == null) {
return;
}
Window window = getActivity().getWindow();
View view = window.getDecorView(); View view = window.getDecorView();
int flags = view.getSystemUiVisibility(); int flags = view.getSystemUiVisibility();
// You can change the navigation bar color (including translucent colors) // You can change the navigation bar color (including translucent colors)
...@@ -266,32 +284,44 @@ public class XPlatformPlugin { ...@@ -266,32 +284,44 @@ public class XPlatformPlugin {
} }
private void popSystemNavigator() { private void popSystemNavigator() {
activity.finish(); if (getActivity() == null) {
return;
}
getActivity().finish();
} }
private CharSequence getClipboardData(PlatformChannel.ClipboardContentFormat format) { private CharSequence getClipboardData(PlatformChannel.ClipboardContentFormat format) {
ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); if (getActivity() == null) {
return null;
}
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = clipboard.getPrimaryClip(); ClipData clip = clipboard.getPrimaryClip();
if (clip == null) if (clip == null)
return null; return null;
if (format == null || format == PlatformChannel.ClipboardContentFormat.PLAIN_TEXT) { if (format == null || format == PlatformChannel.ClipboardContentFormat.PLAIN_TEXT) {
return clip.getItemAt(0).coerceToText(activity); return clip.getItemAt(0).coerceToText(getActivity());
} }
return null; return null;
} }
private void setClipboardData(String text) { private void setClipboardData(String text) {
ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); if (getActivity() == null) {
return;
}
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("text label?", text); ClipData clip = ClipData.newPlainText("text label?", text);
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
} }
private List<Rect> getSystemGestureExclusionRects() { private List<Rect> getSystemGestureExclusionRects() {
if (getActivity() == null) {
return null;
}
if (Build.VERSION.SDK_INT >= 29) { if (Build.VERSION.SDK_INT >= 29) {
Window window = activity.getWindow(); Window window = getActivity().getWindow();
View view = window.getDecorView(); View view = window.getDecorView();
return view.getSystemGestureExclusionRects(); return view.getSystemGestureExclusionRects();
} }
...@@ -300,13 +330,23 @@ public class XPlatformPlugin { ...@@ -300,13 +330,23 @@ public class XPlatformPlugin {
} }
private void setSystemGestureExclusionRects(ArrayList<Rect> rects) { private void setSystemGestureExclusionRects(ArrayList<Rect> rects) {
if (getActivity() == null) {
return;
}
if (Build.VERSION.SDK_INT < 29) { if (Build.VERSION.SDK_INT < 29) {
return; return;
} }
Window window = activity.getWindow(); Window window = getActivity().getWindow();
View view = window.getDecorView(); View view = window.getDecorView();
view.setSystemGestureExclusionRects(rects); view.setSystemGestureExclusionRects(rects);
} }
@Nullable
private Activity getActivity() {
if (activity != null) {
return activity;
}
return FlutterBoost.instance().currentActivity();
}
} }
...@@ -58,6 +58,7 @@ public class BoostFlutterActivity extends Activity ...@@ -58,6 +58,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);
...@@ -445,8 +446,8 @@ public class BoostFlutterActivity extends Activity ...@@ -445,8 +446,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;
}
}
...@@ -231,7 +231,7 @@ public class FlutterActivityAndFragmentDelegate implements IFlutterViewContainer ...@@ -231,7 +231,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());
} }
/** /**
......
...@@ -60,8 +60,8 @@ ...@@ -60,8 +60,8 @@
android:theme="@style/Theme.AppCompat" android:theme="@style/Theme.AppCompat"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:windowSoftInputMode="adjustResize"/> android:windowSoftInputMode="adjustResize"/>
<!--<meta-data android:name="flutterEmbedding"--> <meta-data android:name="flutterEmbedding"
<!--android:value="2">--> android:value="2">
<!--</meta-data>--> </meta-data>
</application> </application>
</manifest> </manifest>
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'container_manager.dart'; import 'container_manager.dart';
import '../flutter_boost.dart'; import '../flutter_boost.dart';
import 'boost_page_route.dart'; import 'boost_page_route.dart';
...@@ -246,6 +247,8 @@ class BoostContainerState extends NavigatorState { ...@@ -246,6 +247,8 @@ class BoostContainerState extends NavigatorState {
routerHistory.add(route); routerHistory.add(route);
// 复用XPlatformPlugin后,每次进入页面时都需要在这里反复通知Native更新Theme
SystemChrome.restoreSystemUIOverlays();
if (FlutterBoost.containerManager.postPushRoute != null) { if (FlutterBoost.containerManager.postPushRoute != null) {
FlutterBoost.containerManager FlutterBoost.containerManager
.postPushRoute(name, uniqueId, params, newRoute ?? route, future); .postPushRoute(name, uniqueId, params, newRoute ?? route, future);
......
...@@ -282,10 +282,23 @@ class FlutterBoost { ...@@ -282,10 +282,23 @@ class FlutterBoost {
BoostContainerLifeCycleObserver observer) => BoostContainerLifeCycleObserver observer) =>
_observersHolder.addObserver<BoostContainerLifeCycleObserver>(observer); _observersHolder.addObserver<BoostContainerLifeCycleObserver>(observer);
///unregister for Container changed callbacks
void removeContainerObserver(BoostContainerObserver observer) =>
_observersHolder.removeObserver<BoostContainerObserver>(observer);
///unregister for Container lifecycle callbacks
void removeBoostContainerLifeCycleObserver(
BoostContainerLifeCycleObserver observer) =>
_observersHolder.removeObserver<BoostContainerLifeCycleObserver>(observer);
///register callbacks for Navigators push & pop ///register callbacks for Navigators push & pop
void addBoostNavigatorObserver(NavigatorObserver observer) => void addBoostNavigatorObserver(NavigatorObserver observer) =>
ContainerNavigatorObserver.boostObservers.add(observer); ContainerNavigatorObserver.boostObservers.add(observer);
///unregister callbacks for Navigators push & pop
void removeBoostNavigatorObserver(NavigatorObserver observer) =>
ContainerNavigatorObserver.boostObservers.remove(observer);
BoostRouteSettings getBoostRouteSettings(Route route) { BoostRouteSettings getBoostRouteSettings(Route route) {
return GlobalRouteSettingsManager.instance.getSettings(route); return GlobalRouteSettingsManager.instance.getSettings(route);
} }
......
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