That fuck shit the fascists are using
1package org.tm.archive.util;
2
3import android.app.Activity;
4import android.content.Context;
5import android.graphics.Rect;
6import android.os.Build;
7import android.view.View;
8import android.view.Window;
9import android.view.WindowManager;
10
11import androidx.annotation.ColorInt;
12import androidx.annotation.NonNull;
13
14public final class WindowUtil {
15
16 private WindowUtil() {
17 }
18
19 public static void initializeScreenshotSecurity(@NonNull Context context, @NonNull Window window) {
20 if (TextSecurePreferences.isScreenSecurityEnabled(context)) {
21 window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
22 } else {
23 window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
24 }
25 }
26
27 public static void setLightNavigationBarFromTheme(@NonNull Activity activity) {
28 if (Build.VERSION.SDK_INT < 27) return;
29
30 final boolean isLightNavigationBar = ThemeUtil.getThemedBoolean(activity, android.R.attr.windowLightNavigationBar);
31
32 if (isLightNavigationBar) setLightNavigationBar(activity.getWindow());
33 else clearLightNavigationBar(activity.getWindow());
34 }
35
36 public static void clearLightNavigationBar(@NonNull Window window) {
37 if (Build.VERSION.SDK_INT < 27) return;
38
39 clearSystemUiFlags(window, View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
40 }
41
42 public static void setLightNavigationBar(@NonNull Window window) {
43 if (Build.VERSION.SDK_INT < 27) return;
44
45 setSystemUiFlags(window, View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
46 }
47
48 public static void setNavigationBarColor(@NonNull Activity activity, @ColorInt int color) {
49 setNavigationBarColor(activity, activity.getWindow(), color);
50 }
51
52 public static void setNavigationBarColor(@NonNull Context context, @NonNull Window window, @ColorInt int color) {
53 if (Build.VERSION.SDK_INT < 27) {
54 window.setNavigationBarColor(ThemeUtil.getThemedColor(context, android.R.attr.navigationBarColor));
55 } else {
56 window.setNavigationBarColor(color);
57 }
58 }
59
60 public static void setLightStatusBarFromTheme(@NonNull Activity activity) {
61 if (Build.VERSION.SDK_INT < 23) return;
62
63 final boolean isLightStatusBar = ThemeUtil.getThemedBoolean(activity, android.R.attr.windowLightStatusBar);
64
65 if (isLightStatusBar) setLightStatusBar(activity.getWindow());
66 else clearLightStatusBar(activity.getWindow());
67 }
68
69 public static void clearLightStatusBar(@NonNull Window window) {
70 if (Build.VERSION.SDK_INT < 23) return;
71
72 clearSystemUiFlags(window, View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
73 }
74
75 public static void setLightStatusBar(@NonNull Window window) {
76 if (Build.VERSION.SDK_INT < 23) return;
77
78 setSystemUiFlags(window, View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
79 }
80
81 public static void setStatusBarColor(@NonNull Window window, @ColorInt int color) {
82 window.setStatusBarColor(color);
83 }
84
85 public static int getStatusBarColor(@NonNull Window window) {
86 return window.getStatusBarColor();
87 }
88
89 /**
90 * A sort of roundabout way of determining if the status bar is present by seeing if there's a
91 * vertical window offset.
92 */
93 public static boolean isStatusBarPresent(@NonNull Window window) {
94 Rect rectangle = new Rect();
95 window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
96 return rectangle.top > 0;
97 }
98
99 private static void clearSystemUiFlags(@NonNull Window window, int flags) {
100 View view = window.getDecorView();
101 int uiFlags = view.getSystemUiVisibility();
102
103 uiFlags &= ~flags;
104 view.setSystemUiVisibility(uiFlags);
105 }
106
107 private static void setSystemUiFlags(@NonNull Window window, int flags) {
108 View view = window.getDecorView();
109 int uiFlags = view.getSystemUiVisibility();
110
111 uiFlags |= flags;
112 view.setSystemUiVisibility(uiFlags);
113 }
114}