|
1 | 1 | package com.didichuxing.doraemonkit.util; |
2 | 2 |
|
| 3 | +import android.app.Activity; |
3 | 4 | import android.content.Context; |
4 | 5 | import android.content.res.Resources; |
5 | 6 | import android.graphics.Rect; |
6 | 7 | import android.support.annotation.AnyRes; |
7 | 8 | import android.util.DisplayMetrics; |
| 9 | +import android.util.TypedValue; |
8 | 10 | import android.view.Display; |
9 | 11 | import android.view.View; |
| 12 | +import android.view.Window; |
10 | 13 | import android.view.WindowManager; |
11 | 14 |
|
12 | 15 | import java.lang.reflect.Method; |
@@ -91,12 +94,54 @@ public static Rect getViewRect(View view) { |
91 | 94 | int[] locations = new int[2]; |
92 | 95 | view.getLocationOnScreen(locations); |
93 | 96 | 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 | + } |
95 | 101 | rect.right = rect.left + view.getWidth(); |
96 | 102 | rect.bottom = rect.top + view.getHeight(); |
97 | 103 | return rect; |
98 | 104 | } |
99 | 105 |
|
| 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 | + |
100 | 145 | public static String getIdText(View view) { |
101 | 146 | final int id = view.getId(); |
102 | 147 | StringBuilder out = new StringBuilder(); |
|
0 commit comments