(Bar t, int color, int luminance)
| 194 | } |
| 195 | |
| 196 | private void setBarColor(Bar t, int color, int luminance) { |
| 197 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | Window window = ((Activity) this.getContext()).getWindow(); |
| 202 | |
| 203 | int insetsMask; |
| 204 | int viewMask; |
| 205 | |
| 206 | switch (t) { |
| 207 | case STATUS: |
| 208 | insetsMask = WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS; |
| 209 | viewMask = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 210 | window.setStatusBarColor(color); |
| 211 | break; |
| 212 | case NAVIGATION: |
| 213 | insetsMask = WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS; |
| 214 | viewMask = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR; |
| 215 | window.setNavigationBarColor(color); |
| 216 | break; |
| 217 | default: |
| 218 | throw new RuntimeException("invalid bar type"); |
| 219 | } |
| 220 | |
| 221 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { |
| 222 | return; |
| 223 | } |
| 224 | |
| 225 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { |
| 226 | int flags = this.getSystemUiVisibility(); |
| 227 | if (luminance > 128) { |
| 228 | flags |= viewMask; |
| 229 | } else { |
| 230 | flags &= ~viewMask; |
| 231 | } |
| 232 | this.setSystemUiVisibility(flags); |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | WindowInsetsController insetsController = window.getInsetsController(); |
| 237 | if (insetsController == null) { |
| 238 | return; |
| 239 | } |
| 240 | if (luminance > 128) { |
| 241 | insetsController.setSystemBarsAppearance(insetsMask, insetsMask); |
| 242 | } else { |
| 243 | insetsController.setSystemBarsAppearance(0, insetsMask); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | private void setStatusColor(int color, int luminance) { |
| 248 | this.setBarColor(Bar.STATUS, color, luminance); |
no outgoing calls
no test coverage detected