Skip to content

Commit

Permalink
add overload method for QMUIStatusBarHelper.translucent
Browse files Browse the repository at this point in the history
  • Loading branch information
cgspine committed Aug 10, 2018
1 parent 593440e commit 7cf130b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
38 changes: 25 additions & 13 deletions qmui/src/main/java/com/qmuiteam/qmui/util/QMUIStatusBarHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ public class QMUIStatusBarHelper {
private static Integer sTransparentValue;

public static void translucent(Activity activity) {
translucent(activity, 0x40000000);
translucent(activity.getWindow());
}

private static boolean supportTranslucent() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
// Essential Phone 在 Android 8 之前沉浸式做得不全,系统不从状态栏顶部开始布局却会下发 WindowInsets
&& !(QMUIDeviceHelper.isEssentialPhone() && Build.VERSION.SDK_INT < Build.VERSION_CODES.O);
public static void translucent(Window window) {
translucent(window, 0x40000000);
}

/**
Expand All @@ -50,25 +48,25 @@ private static boolean supportTranslucent() {
*
* @param activity 需要被设置沉浸式状态栏的 Activity。
*/
@TargetApi(19)
public static void translucent(Activity activity, @ColorInt int colorOn5x) {
translucent(activity.getWindow(), colorOn5x);
}

@TargetApi(19)
public static void translucent(Window window, @ColorInt int colorOn5x) {
if (!supportTranslucent()) {
// 版本小于4.4,绝对不考虑沉浸式
return;
}
Window window = activity.getWindow();
// 小米和魅族4.4 以上版本支持沉浸式
if (QMUIDeviceHelper.isMeizu() || QMUIDeviceHelper.isMIUI()) {
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
return;
}

if(QMUINotchHelper.isNotchOfficialSupport()){
WindowManager.LayoutParams params = window.getAttributes();
params.layoutInDisplayCutoutMode = WindowManager.LayoutParams
.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
window.setAttributes(params);
if (QMUINotchHelper.isNotchOfficialSupport()) {
handleDisplayCutoutMode(window);
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down Expand Up @@ -103,6 +101,20 @@ public static void translucent(Activity activity, @ColorInt int colorOn5x) {
}
}

@TargetApi(28)
private static void handleDisplayCutoutMode(Window window) {
WindowManager.LayoutParams params = window.getAttributes();
params.layoutInDisplayCutoutMode = WindowManager.LayoutParams
.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
window.setAttributes(params);
}

private static boolean supportTranslucent() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
// Essential Phone 在 Android 8 之前沉浸式做得不全,系统不从状态栏顶部开始布局却会下发 WindowInsets
&& !(QMUIDeviceHelper.isEssentialPhone() && Build.VERSION.SDK_INT < Build.VERSION_CODES.O);
}

/**
* 设置状态栏黑色字体图标,
* 支持 4.4 以上版本 MIUI 和 Flyme,以及 6.0 以上版本的其他 Android
Expand Down Expand Up @@ -252,7 +264,7 @@ public static boolean MIUISetStatusBarLightMode(Window window, boolean light) {
* 见小米开发文档说明:https://dev.mi.com/console/doc/detail?pId=1159
*/
private static boolean isMIUICustomStatusBarLightModeImpl() {
if (QMUIDeviceHelper.isMIUIV9() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M){
if (QMUIDeviceHelper.isMIUIV9() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
}
return QMUIDeviceHelper.isMIUIV5() || QMUIDeviceHelper.isMIUIV6() ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private void initTabs() {
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// changeToFullScreen();
changeToFullScreen();
}

private void changeToFullScreen() {
Expand Down
7 changes: 0 additions & 7 deletions qmuidemo/src/main/res/layout/fragment_notch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
android:text="安全区域\nTODO vivo 显示与亮度-第三方应用显示比例\nTODO OPPO 设置-显示-应用全屏显示-凹形区域显示控制"
android:textColor="@color/qmui_config_color_white"
android:textSize="16sp"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="40dp"
android:padding="24dp"/>
</com.qmuiteam.qmui.widget.QMUINotchConsumeLayout>


Expand Down

0 comments on commit 7cf130b

Please sign in to comment.