Skip to content

Commit dd91a92

Browse files
authored
修复当Status Bar隐藏时使用控件检查描边出现偏移的问题
1 parent c2723fd commit dd91a92

File tree

1 file changed

+46
-1
lines changed
  • Android/doraemonkit/src/main/java/com/didichuxing/doraemonkit/util

1 file changed

+46
-1
lines changed

Android/doraemonkit/src/main/java/com/didichuxing/doraemonkit/util/UIUtils.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.didichuxing.doraemonkit.util;
22

3+
import android.app.Activity;
34
import android.content.Context;
45
import android.content.res.Resources;
56
import android.graphics.Rect;
67
import android.support.annotation.AnyRes;
78
import android.util.DisplayMetrics;
9+
import android.util.TypedValue;
810
import android.view.Display;
911
import android.view.View;
12+
import android.view.Window;
1013
import android.view.WindowManager;
1114

1215
import java.lang.reflect.Method;
@@ -91,12 +94,54 @@ public static Rect getViewRect(View view) {
9194
int[] locations = new int[2];
9295
view.getLocationOnScreen(locations);
9396
rect.left = locations[0];
94-
rect.top = locations[1] - UIUtils.getStatusBarHeight(view.getContext());
97+
rect.top = locations[1];
98+
if (!checkStatusBarVisible(view.getContext())) {
99+
rect.top-=UIUtils.getStatusBarHeight(view.getContext());
100+
}
95101
rect.right = rect.left + view.getWidth();
96102
rect.bottom = rect.top + view.getHeight();
97103
return rect;
98104
}
99105

106+
public static boolean checkStatusBarVisible(Context context){
107+
return checkFullScreenByTheme(context)|| checkFullScreenByCode(context)|| checkFullScreenByCode2(context);
108+
}
109+
110+
public static boolean checkFullScreenByTheme(Context context){
111+
Resources.Theme theme=context.getTheme();
112+
if (theme!=null){
113+
TypedValue typedValue=new TypedValue();
114+
boolean result= theme.resolveAttribute(android.R.attr.windowFullscreen,typedValue,false);
115+
if (result){
116+
typedValue.coerceToString();
117+
if (typedValue.type== TypedValue.TYPE_INT_BOOLEAN){
118+
return typedValue.data!=0;
119+
}
120+
}
121+
}
122+
return false;
123+
}
124+
125+
public static boolean checkFullScreenByCode(Context context){
126+
if (context instanceof Activity) {
127+
Window window = ((Activity) context).getWindow();
128+
if (window != null) {
129+
View decorView = window.getDecorView();
130+
if (decorView != null) {
131+
return (decorView.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_FULLSCREEN) == View.SYSTEM_UI_FLAG_FULLSCREEN;
132+
}
133+
}
134+
}
135+
return false;
136+
}
137+
public static boolean checkFullScreenByCode2(Context context){
138+
if (context instanceof Activity){
139+
return (((Activity)context).getWindow().getAttributes().flags&WindowManager.LayoutParams.FLAG_FULLSCREEN)==WindowManager.LayoutParams.FLAG_FULLSCREEN;
140+
}
141+
return false;
142+
}
143+
144+
100145
public static String getIdText(View view) {
101146
final int id = view.getId();
102147
StringBuilder out = new StringBuilder();

0 commit comments

Comments
 (0)