Commit abeb415e authored by justin's avatar justin Committed by GitHub

Merge pull request #851 from sdlu1992/task/task_v1.12.13_support_hotfixes

Task/task v1.12.13 support hotfixes
parents d90dc99b 7fcd70a9
......@@ -118,14 +118,20 @@ public class XPlatformPlugin {
}
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);
......@@ -147,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;
}
......@@ -159,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);
}
}
......@@ -205,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);
}
......@@ -216,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)
......@@ -265,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();
}
......@@ -299,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();
}
}
......@@ -22,6 +22,7 @@
* THE SOFTWARE.
*/
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'container_manager.dart';
import '../flutter_boost.dart';
import 'boost_page_route.dart';
......@@ -222,6 +223,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);
......
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