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
example/android/app/.project
example/android/.project
flutter_boost
.flutter-plugins-dependencies
......@@ -21,7 +21,9 @@ import io.flutter.plugin.common.PluginRegistry;
import io.flutter.view.FlutterMain;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class FlutterBoost {
......@@ -216,6 +218,8 @@ public class FlutterBoost {
private INativeRouter router = null;
private List<String> shellArgs;
private BoostLifecycleListener lifecycleListener;
private FlutterEngineProvider flutterEngineProvider = null;
......@@ -253,7 +257,6 @@ public class FlutterBoost {
return this;
}
public ConfigBuilder lifecycleListener(BoostLifecycleListener lifecycleListener) {
this.lifecycleListener = lifecycleListener;
return this;
......@@ -264,6 +267,11 @@ public class FlutterBoost {
return this;
}
public ConfigBuilder shellArgs(List<String> shellArgs) {
this.shellArgs = shellArgs;
return this;
}
public Platform build() {
Platform platform = new Platform() {
......@@ -296,6 +304,10 @@ public class FlutterBoost {
return ConfigBuilder.this.renderMode;
}
public List<String> shellArgs() {
return ConfigBuilder.this.shellArgs;
}
public FlutterEngineProvider flutterEngineProvider() {
return flutterEngineProvider;
}
......@@ -332,7 +344,7 @@ public class FlutterBoost {
if (mEngine == null) {
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(
mPlatform.getApplication().getApplicationContext(), flutterShellArgs.toArray());
if (mPlatform.flutterEngineProvider() != null) {
......@@ -344,8 +356,8 @@ public class FlutterBoost {
}
// registerPlugins(mEngine);
mRegistry = new BoostPluginRegistry(createEngine());
mPlatform.registerPlugins(mRegistry);
// mRegistry = new BoostPluginRegistry(createEngine());
// mPlatform.registerPlugins(mRegistry);
}
return mEngine;
......
......@@ -6,6 +6,7 @@ import android.util.Log;
import com.idlefish.flutterboost.interfaces.IContainerRecord;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import io.flutter.embedding.android.FlutterEngineProvider;
......@@ -42,8 +43,9 @@ public abstract class Platform {
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) {
if (record == null) return;
......
......@@ -96,37 +96,42 @@ public class XPlatformPlugin {
}
};
public XPlatformPlugin( PlatformChannel platformChannel) {
public XPlatformPlugin(PlatformChannel platformChannel) {
this.platformChannel = platformChannel;
this.platformChannel.setPlatformMessageHandler(mPlatformMessageHandler);
mEnabledOverlays = DEFAULT_SYSTEM_UI;
}
public void attachToActivity(Activity activity ){
this.activity = activity;
this.platformChannel.setPlatformMessageHandler(mPlatformMessageHandler);
}
/**
* Releases all resources held by this {@code PlatformPlugin}.
* <p>
* Do not invoke any methods on a {@code PlatformPlugin} after invoking this method.
*/
public void detachActivity() {
this.activity=null;
this.mPlatformMessageHandler=null;
public void detachActivity(Activity activity) {
if (activity == this.activity) {
this.activity = null;
}
}
private void playSystemSound(PlatformChannel.SoundType soundType) {
if (getActivity() == null) {
return;
}
if (soundType == PlatformChannel.SoundType.CLICK) {
View view = activity.getWindow().getDecorView();
View view = getActivity().getWindow().getDecorView();
view.playSoundEffect(SoundEffectConstants.CLICK);
}
}
private void vibrateHapticFeedback(PlatformChannel.HapticFeedbackType feedbackType) {
View view = activity.getWindow().getDecorView();
if (getActivity() == null) {
return;
}
View view = getActivity().getWindow().getDecorView();
switch (feedbackType) {
case STANDARD:
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
......@@ -148,11 +153,17 @@ public class XPlatformPlugin {
}
private void setSystemChromePreferredOrientations(int androidOrientation) {
activity.setRequestedOrientation(androidOrientation);
if (getActivity() == null) {
return;
}
getActivity().setRequestedOrientation(androidOrientation);
}
@SuppressWarnings("deprecation")
private void setSystemChromeApplicationSwitcherDescription(PlatformChannel.AppSwitcherDescription description) {
if (getActivity() == null) {
return;
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return;
}
......@@ -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
// hardcode the API 28 constant.
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) {
ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(description.label, 0, description.color);
activity.setTaskDescription(taskDescription);
getActivity().setTaskDescription(taskDescription);
}
}
......@@ -206,7 +218,10 @@ public class XPlatformPlugin {
* {@code PlatformPlugin}.
*/
public void updateSystemUiOverlays(){
activity.getWindow().getDecorView().setSystemUiVisibility(mEnabledOverlays);
if (getActivity() == null) {
return;
}
getActivity().getWindow().getDecorView().setSystemUiVisibility(mEnabledOverlays);
if (currentTheme != null) {
setSystemChromeSystemUIOverlayStyle(currentTheme);
}
......@@ -217,7 +232,10 @@ public class XPlatformPlugin {
}
private void setSystemChromeSystemUIOverlayStyle(PlatformChannel.SystemChromeStyle systemChromeStyle) {
Window window = activity.getWindow();
if (getActivity() == null) {
return;
}
Window window = getActivity().getWindow();
View view = window.getDecorView();
int flags = view.getSystemUiVisibility();
// You can change the navigation bar color (including translucent colors)
......@@ -266,32 +284,44 @@ public class XPlatformPlugin {
}
private void popSystemNavigator() {
activity.finish();
if (getActivity() == null) {
return;
}
getActivity().finish();
}
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();
if (clip == null)
return null;
if (format == null || format == PlatformChannel.ClipboardContentFormat.PLAIN_TEXT) {
return clip.getItemAt(0).coerceToText(activity);
return clip.getItemAt(0).coerceToText(getActivity());
}
return null;
}
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);
clipboard.setPrimaryClip(clip);
}
private List<Rect> getSystemGestureExclusionRects() {
if (getActivity() == null) {
return null;
}
if (Build.VERSION.SDK_INT >= 29) {
Window window = activity.getWindow();
Window window = getActivity().getWindow();
View view = window.getDecorView();
return view.getSystemGestureExclusionRects();
}
......@@ -300,13 +330,23 @@ public class XPlatformPlugin {
}
private void setSystemGestureExclusionRects(ArrayList<Rect> rects) {
if (getActivity() == null) {
return;
}
if (Build.VERSION.SDK_INT < 29) {
return;
}
Window window = activity.getWindow();
Window window = getActivity().getWindow();
View view = window.getDecorView();
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
// Default configuration.
protected static final String DEFAULT_BACKGROUND_MODE = BackgroundMode.opaque.name();
private static XPlatformPlugin sXPlatformPlugin;
public static Intent createDefaultIntent(@NonNull Context launchContext) {
return withNewEngine().build(launchContext);
......@@ -445,8 +446,8 @@ public class BoostFlutterActivity extends Activity
@Nullable
@Override
public XPlatformPlugin providePlatformPlugin( @NonNull FlutterEngine flutterEngine) {
return new XPlatformPlugin( flutterEngine.getPlatformChannel());
public XPlatformPlugin providePlatformPlugin(@NonNull FlutterEngine flutterEngine) {
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
// Null out the platformPlugin to avoid a possible retain cycle between the plugin, this Fragment,
// and this Fragment's Activity.
if (platformPlugin != null) {
platformPlugin.detachActivity();
platformPlugin.detachActivity(getContextActivity());
platformPlugin = null;
}
......
......@@ -2,8 +2,6 @@ package com.idlefish.flutterboost.containers;
import android.app.Activity;
import android.arch.lifecycle.Lifecycle;
import android.graphics.Color;
import android.view.*;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
......@@ -17,13 +15,11 @@ import android.view.View;
import android.view.ViewGroup;
import com.idlefish.flutterboost.FlutterBoost;
import com.idlefish.flutterboost.Utils;
import com.idlefish.flutterboost.XFlutterView;
import com.idlefish.flutterboost.XPlatformPlugin;
import io.flutter.embedding.android.*;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.FlutterShellArgs;
import io.flutter.plugin.platform.PlatformPlugin;
import java.util.HashMap;
import java.util.Map;
......@@ -472,8 +468,7 @@ public class FlutterFragment extends Fragment implements FlutterActivityAndFragm
@Nullable
@Override
public XPlatformPlugin providePlatformPlugin( @NonNull FlutterEngine flutterEngine) {
return new XPlatformPlugin(flutterEngine.getPlatformChannel());
return BoostViewUtils.getPlatformPlugin(flutterEngine.getPlatformChannel());
}
/**
......
......@@ -60,8 +60,8 @@
android:theme="@style/Theme.AppCompat"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:windowSoftInputMode="adjustResize"/>
<!--<meta-data android:name="flutterEmbedding"-->
<!--android:value="2">-->
<!--</meta-data>-->
<meta-data android:name="flutterEmbedding"
android:value="2">
</meta-data>
</application>
</manifest>
......@@ -24,6 +24,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'container_manager.dart';
import '../flutter_boost.dart';
import 'boost_page_route.dart';
......@@ -246,6 +247,8 @@ class BoostContainerState extends NavigatorState {
routerHistory.add(route);
// 复用XPlatformPlugin后,每次进入页面时都需要在这里反复通知Native更新Theme
SystemChrome.restoreSystemUIOverlays();
if (FlutterBoost.containerManager.postPushRoute != null) {
FlutterBoost.containerManager
.postPushRoute(name, uniqueId, params, newRoute ?? route, future);
......
......@@ -282,10 +282,23 @@ class FlutterBoost {
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
void addBoostNavigatorObserver(NavigatorObserver observer) =>
ContainerNavigatorObserver.boostObservers.add(observer);
///unregister callbacks for Navigators push & pop
void removeBoostNavigatorObserver(NavigatorObserver observer) =>
ContainerNavigatorObserver.boostObservers.remove(observer);
BoostRouteSettings getBoostRouteSettings(Route 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