Skip to content

Commit 384dae5

Browse files
author
zhangzhun
committed
update: 优化Android P兼容性
1 parent 11d4e6b commit 384dae5

File tree

5 files changed

+41
-38
lines changed

5 files changed

+41
-38
lines changed

.idea/modules.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

notchtools/src/main/java/notchtools/geek/com/notchtools/NotchTools.java

+23-22
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ public int getStatusHeight(Window window) {
121121
return NotchStatusBarUtils.getStatusBarHeight(window.getContext());
122122
}
123123

124+
/**
125+
* 是否显示底部导航栏
126+
* @return
127+
*/
128+
public NotchTools showNavigation(boolean showNavigation) {
129+
NotchStatusBarUtils.sShowNavigation = showNavigation;
130+
return this;
131+
}
132+
133+
134+
124135
/**
125136
* 全屏显示,但是不占用刘海屏区域(在刘海的下方显示内容)
126137
*/
@@ -133,17 +144,12 @@ public void fullScreenDontUseStatus(Activity activity) {
133144
*/
134145
@Override
135146
public void fullScreenDontUseStatus(final Activity activity, final OnNotchCallBack notchCallBack) {
136-
ThreadUtils.post2UI(new Runnable() {
137-
@Override
138-
public void run() {
139-
if (notchScreenSupport == null) {
140-
checkScreenSupportInit(activity.getWindow());
141-
}
142-
if (notchScreenSupport != null) {
143-
notchScreenSupport.fullScreenDontUseStatus(activity, notchCallBack);
144-
}
145-
}
146-
});
147+
if (notchScreenSupport == null) {
148+
checkScreenSupportInit(activity.getWindow());
149+
}
150+
if (notchScreenSupport != null) {
151+
notchScreenSupport.fullScreenDontUseStatus(activity, notchCallBack);
152+
}
147153
}
148154

149155
public void fullScreenDontUseStatusForPortrait(Activity activity) {
@@ -183,17 +189,12 @@ public void fullScreenUseStatus(Activity activity) {
183189

184190
@Override
185191
public void fullScreenUseStatus(final Activity activity, final OnNotchCallBack notchCallBack) {
186-
ThreadUtils.post2UI(new Runnable() {
187-
@Override
188-
public void run() {
189-
if (notchScreenSupport == null) {
190-
checkScreenSupportInit(activity.getWindow());
191-
}
192-
if (notchScreenSupport != null) {
193-
notchScreenSupport.fullScreenUseStatus(activity, notchCallBack);
194-
}
195-
}
196-
});
192+
if (notchScreenSupport == null) {
193+
checkScreenSupportInit(activity.getWindow());
194+
}
195+
if (notchScreenSupport != null) {
196+
notchScreenSupport.fullScreenUseStatus(activity, notchCallBack);
197+
}
197198

198199
}
199200

notchtools/src/main/java/notchtools/geek/com/notchtools/core/AbsNotchScreenSupport.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public int getStatusHeight(Window window) {
2626

2727
@Override
2828
public void fullScreenDontUseStatus(Activity activity, OnNotchCallBack notchCallBack) {
29+
NotchStatusBarUtils.setFullScreenWithSystemUi(activity.getWindow(), false);
2930
onBindCallBackWithNotchProperty(activity, notchCallBack);
30-
NotchStatusBarUtils.setFullScreenWithSystemUi(activity.getWindow(), true);
3131
}
3232

3333
@Override
@@ -42,8 +42,8 @@ public void fullScreenDontUseStatusForLandscape(Activity activity, OnNotchCallBa
4242

4343
@Override
4444
public void fullScreenUseStatus(Activity activity, OnNotchCallBack notchCallBack) {
45+
NotchStatusBarUtils.setFullScreenWithSystemUi(activity.getWindow(), false);
4546
onBindCallBackWithNotchProperty(activity, getNotchHeight(activity.getWindow()), notchCallBack);
46-
NotchStatusBarUtils.setFullScreenWithSystemUi(activity.getWindow(), true);
4747
}
4848

4949
protected void onBindCallBackWithNotchProperty(Activity activity, OnNotchCallBack notchCallBack) {

notchtools/src/main/java/notchtools/geek/com/notchtools/helper/NotchStatusBarUtils.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
public class NotchStatusBarUtils {
1919

2020
private static int statusBarHeight = -1;
21+
public static boolean sShowNavigation;
2122

2223
/**
2324
* 获取状态栏高度
@@ -51,10 +52,11 @@ public static void setFullScreenWithSystemUi(final Window window, boolean setLis
5152

5253
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
5354
systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
54-
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
55-
56-
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
57-
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
55+
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
56+
if (!sShowNavigation) {
57+
systemUiVisibility |=View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
58+
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
59+
}
5860
}
5961

6062
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

notchtools/src/main/java/notchtools/geek/com/notchtools/phone/PVersionNotchScreen.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,18 @@ public int getNotchHeight(Window window) {
5959
@Override
6060
public void fullScreenDontUseStatus(Activity activity, OnNotchCallBack notchCallBack) {
6161
super.fullScreenDontUseStatus(activity, notchCallBack);
62-
if (isNotchScreen(activity.getWindow())) {
63-
WindowManager.LayoutParams attributes = activity.getWindow().getAttributes();
64-
attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
65-
activity.getWindow().setAttributes(attributes);
66-
}
62+
WindowManager.LayoutParams attributes = activity.getWindow().getAttributes();
63+
attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
64+
activity.getWindow().setAttributes(attributes);
65+
NotchStatusBarUtils.setFakeNotchView(activity.getWindow());
6766
}
6867

6968
@RequiresApi(api = 28)
7069
@Override
7170
public void fullScreenUseStatus(Activity activity, OnNotchCallBack notchCallBack) {
7271
super.fullScreenUseStatus(activity, notchCallBack);
73-
if (isNotchScreen(activity.getWindow())) {
74-
WindowManager.LayoutParams attributes = activity.getWindow().getAttributes();
75-
attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
76-
activity.getWindow().setAttributes(attributes);
77-
}
72+
WindowManager.LayoutParams attributes = activity.getWindow().getAttributes();
73+
attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
74+
activity.getWindow().setAttributes(attributes);
7875
}
7976
}

0 commit comments

Comments
 (0)