mirror of
https://github.com/Tencent/QMUI_Android.git
synced 2026-10-17 04:31:16 +08:00
only use official method to set status bar mode for flyme 7+
This commit is contained in:
@@ -136,7 +136,7 @@ public class QMUIDeviceHelper {
|
||||
return "v9".equals(sMiuiVersionName);
|
||||
}
|
||||
|
||||
public static boolean isFlymeLowerThan8() {
|
||||
public static boolean isFlymeLowerThan(int checkVersion) {
|
||||
boolean isLower = false;
|
||||
if (sFlymeVersionName != null && !sFlymeVersionName.equals("")) {
|
||||
Pattern pattern = Pattern.compile("(\\d+\\.){2}\\d");
|
||||
@@ -146,7 +146,7 @@ public class QMUIDeviceHelper {
|
||||
if (versionString != null && !versionString.equals("")) {
|
||||
String[] version = versionString.split("\\.");
|
||||
if (version.length >= 1) {
|
||||
if (Integer.parseInt(version[0]) < 8) {
|
||||
if (Integer.parseInt(version[0]) < checkVersion) {
|
||||
isLower = true;
|
||||
}
|
||||
}
|
||||
@@ -157,37 +157,6 @@ public class QMUIDeviceHelper {
|
||||
return isMeizu() && isLower;
|
||||
}
|
||||
|
||||
public static boolean isFlymeVersionHigher5_2_4() {
|
||||
boolean isHigher = true;
|
||||
if (sFlymeVersionName != null && !sFlymeVersionName.equals("")) {
|
||||
Pattern pattern = Pattern.compile("(\\d+\\.){2}\\d");
|
||||
Matcher matcher = pattern.matcher(sFlymeVersionName);
|
||||
if (matcher.find()) {
|
||||
String versionString = matcher.group();
|
||||
if (versionString != null && !versionString.equals("")) {
|
||||
String[] version = versionString.split("\\.");
|
||||
if (version.length == 3) {
|
||||
int majorVersion = Integer.parseInt(version[0]);
|
||||
if (majorVersion < 5) {
|
||||
isHigher = false;
|
||||
} else if (majorVersion == 5) {
|
||||
int minorVersion = Integer.parseInt(version[1]);
|
||||
if (minorVersion < 2) {
|
||||
isHigher = false;
|
||||
} else if (minorVersion == 2) {
|
||||
int patchVersion = Integer.parseInt(version[2]);
|
||||
if (patchVersion < 4) {
|
||||
isHigher = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return isMeizu() && isHigher;
|
||||
}
|
||||
|
||||
public static boolean isMeizu() {
|
||||
return isPhone(MEIZUBOARD) || isFlyme();
|
||||
|
||||
@@ -89,7 +89,7 @@ public class QMUIStatusBarHelper {
|
||||
|
||||
// 小米和魅族4.4 以上版本支持沉浸式
|
||||
// 小米 Android 6.0 ,开发版 7.7.13 及以后版本设置黑色字体又需要 clear FLAG_TRANSLUCENT_STATUS, 因此还原为官方模式
|
||||
if (QMUIDeviceHelper.isFlymeLowerThan8() || (QMUIDeviceHelper.isMIUI() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M)) {
|
||||
if (QMUIDeviceHelper.isFlymeLowerThan(8) || (QMUIDeviceHelper.isMIUI() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M)) {
|
||||
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
|
||||
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
return;
|
||||
@@ -328,29 +328,35 @@ public class QMUIStatusBarHelper {
|
||||
public static boolean FlymeSetStatusBarLightMode(Window window, boolean light) {
|
||||
boolean result = false;
|
||||
if (window != null) {
|
||||
// flyme 在 6.2.0.0A 支持了 Android 官方的实现方案,旧的方案失效
|
||||
|
||||
Android6SetStatusBarLightMode(window, light);
|
||||
|
||||
try {
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
Field darkFlag = WindowManager.LayoutParams.class
|
||||
.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
|
||||
Field meizuFlags = WindowManager.LayoutParams.class
|
||||
.getDeclaredField("meizuFlags");
|
||||
darkFlag.setAccessible(true);
|
||||
meizuFlags.setAccessible(true);
|
||||
int bit = darkFlag.getInt(null);
|
||||
int value = meizuFlags.getInt(lp);
|
||||
if (light) {
|
||||
value |= bit;
|
||||
} else {
|
||||
value &= ~bit;
|
||||
}
|
||||
meizuFlags.setInt(lp, value);
|
||||
window.setAttributes(lp);
|
||||
result = true;
|
||||
} catch (Exception ignored) {
|
||||
// flyme 在 6.2.0.0A 支持了 Android 官方的实现方案,旧的方案失效
|
||||
// 高版本调用这个出现不可预期的 Bug,官方文档也没有给出完整的高低版本兼容方案
|
||||
if(QMUIDeviceHelper.isFlymeLowerThan(7)){
|
||||
try {
|
||||
WindowManager.LayoutParams lp = window.getAttributes();
|
||||
Field darkFlag = WindowManager.LayoutParams.class
|
||||
.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
|
||||
Field meizuFlags = WindowManager.LayoutParams.class
|
||||
.getDeclaredField("meizuFlags");
|
||||
darkFlag.setAccessible(true);
|
||||
meizuFlags.setAccessible(true);
|
||||
int bit = darkFlag.getInt(null);
|
||||
int value = meizuFlags.getInt(lp);
|
||||
if (light) {
|
||||
value |= bit;
|
||||
} else {
|
||||
value &= ~bit;
|
||||
}
|
||||
meizuFlags.setInt(lp, value);
|
||||
window.setAttributes(lp);
|
||||
result = true;
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}else{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user