4package org.qtproject.qt.android;
6import android.app.Activity;
7import android.content.res.Resources;
8import android.content.res.TypedArray;
9import android.os.Build;
10import android.view.View;
11import android.view.WindowInsets;
12import android.view.WindowManager;
13import android.view.WindowInsetsController;
14import android.view.Window;
16import android.graphics.Color;
17import android.util.TypedValue;
18import android.content.res.Resources.Theme;
20class QtWindowInsetsController
25 @SuppressWarnings (
"deprecation")
28 final int sdk = Build.VERSION.SDK_INT;
29 if (sdk < Build.VERSION_CODES.R || sdk > Build.VERSION_CODES.VANILLA_ICE_CREAM)
39 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
40 WindowManager.LayoutParams layoutParams =
window.getAttributes();
41 layoutParams.layoutInDisplayCutoutMode =
enabled
42 ? WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
43 : WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
44 window.setAttributes(layoutParams);
49 static void showNormal(Activity activity)
55 final View decor =
window.getDecorView();
56 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
57 setDecorFitsSystemWindows(
window,
true);
58 WindowInsetsController ctrl =
window.getInsetsController();
60 ctrl.show(WindowInsets.Type.systemBars());
61 ctrl.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_DEFAULT);
64 @SuppressWarnings(
"deprecation")
65 int
flags = View.SYSTEM_UI_FLAG_VISIBLE;
66 setSystemUiVisibility(decor,
flags);
69 setTransparentSystemBars(activity, false);
70 useCutoutShortEdges(
window, false);
72 decor.
post(() -> decor.requestApplyInsets());
78 @SuppressWarnings(
"deprecation")
79 private static
void setTransparentSystemBars(Activity activity,
boolean transparent)
85 if (edgeToEdgeEnabled(activity))
89 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
90 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
91 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
94 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
101 int statusBarColor =
window.getStatusBarColor();
102 int transparentStatusBar = statusBarColor & 0x00FFFFFF;
103 window.setStatusBarColor(transparentStatusBar);
105 int navigationBarColor =
window.getNavigationBarColor();
106 int semiTransparentNavigationBar = navigationBarColor & 0x7FFFFFFF;
107 window.setNavigationBarColor(semiTransparentNavigationBar);
111 int defaultStatusBarColor = getThemeDefaultStatusBarColor(activity);
112 window.setStatusBarColor(defaultStatusBarColor);
114 int defaultNavigationBarColor = getThemeDefaultNavigationBarColor(activity);
115 window.setNavigationBarColor(defaultNavigationBarColor);
120 static void showExpanded(Activity activity)
126 final View decor =
window.getDecorView();
127 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
128 setDecorFitsSystemWindows(
window,
false);
129 WindowInsetsController ctrl =
window.getInsetsController();
131 ctrl.show(WindowInsets.Type.systemBars());
132 ctrl.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_DEFAULT);
135 @SuppressWarnings(
"deprecation")
136 int
flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
137 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
138 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
139 setSystemUiVisibility(decor,
flags);
142 setTransparentSystemBars(activity, true);
143 useCutoutShortEdges(
window, true);
145 decor.
post(() -> decor.requestApplyInsets());
149 public static
void showFullScreen(Activity activity)
155 final View decor =
window.getDecorView();
156 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
157 setDecorFitsSystemWindows(window, false);
158 WindowInsetsController ctrl = window.getInsetsController();
160 ctrl.hide(WindowInsets.Type.systemBars());
161 ctrl.setSystemBarsBehavior(
162 WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
165 @SuppressWarnings(
"deprecation")
166 int
flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
167 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
168 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
169 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
170 | View.SYSTEM_UI_FLAG_FULLSCREEN
171 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
172 setSystemUiVisibility(decor,
flags);
175 useCutoutShortEdges(
window, true);
177 decor.
post(() -> decor.requestApplyInsets());
180 private static
boolean edgeToEdgeEnabled(Activity activity) {
181 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.VANILLA_ICE_CREAM)
183 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM)
185 int[]
attrs =
new int[] { android.R.attr.windowOptOutEdgeToEdgeEnforcement };
186 TypedArray ta =
activity.getTheme().obtainStyledAttributes(
attrs);
188 return !ta.getBoolean(0, false);
194 static boolean isFullScreen(Activity activity)
200 final View decor =
window.getDecorView();
201 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
202 WindowInsets insets =
activity.getWindow().getDecorView().getRootWindowInsets();
204 return !insets.isVisible(WindowInsets.Type.statusBars());
206 @SuppressWarnings(
"deprecation")
207 int
flags = decor.getSystemUiVisibility();
208 @SuppressWarnings(
"deprecation")
209 int immersiveMask = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
216 static
boolean isExpandedClientArea(Activity activity)
218 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
219 return edgeToEdgeEnabled(activity);
221 @SuppressWarnings(
"deprecation")
222 int statusBarColor = activity.getWindow().getStatusBarColor();
225 int statusBarAlpha = statusBarColor >>> 24;
226 return statusBarAlpha != 0xFF;
229 static
boolean decorFitsSystemWindows(Activity activity)
231 return !isFullScreen(activity) && !isExpandedClientArea(activity);
234 static void restoreFullScreenVisibility(Activity activity)
236 if (isFullScreen(activity))
237 showFullScreen(activity);
243 @SuppressWarnings (
"deprecation")
244 private static
void setSystemUiVisibility(View decorView,
int flags)
246 decorView.setSystemUiVisibility(
flags);
253 static void setStatusBarColorHint(Activity activity,
boolean isLight)
256 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
257 WindowInsetsController controller =
window.getInsetsController();
258 if (controller !=
null) {
259 int lightStatusBarMask = WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
260 int appearance = isLight ? lightStatusBarMask : 0;
261 controller.setSystemBarsAppearance(appearance, lightStatusBarMask);
264 @SuppressWarnings(
"deprecation")
265 int currentFlags =
window.getDecorView().getSystemUiVisibility();
266 @SuppressWarnings(
"deprecation")
267 int lightStatusBarMask = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
268 int appearance = isLight
269 ? currentFlags | lightStatusBarMask
270 : currentFlags & ~lightStatusBarMask;
271 setSystemUiVisibility(
window.getDecorView(), appearance);
279 static
void setNavigationBarColorHint(Activity activity,
boolean isLight)
282 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
283 WindowInsetsController controller = window.getInsetsController();
284 if (controller != null) {
285 int lightNavigationBarMask = WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
286 int appearance = isLight ? lightNavigationBarMask : 0;
287 controller.setSystemBarsAppearance(appearance, lightNavigationBarMask);
290 @SuppressWarnings(
"deprecation")
291 int currentFlags =
window.getDecorView().getSystemUiVisibility();
292 @SuppressWarnings(
"deprecation")
293 int lightNavigationBarMask = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
294 int appearance = isLight
295 ? currentFlags | lightNavigationBarMask
296 : currentFlags & ~lightNavigationBarMask;
297 setSystemUiVisibility(
window.getDecorView(), appearance);
304 Resources resources =
activity.getResources();
305 TypedValue tv =
new TypedValue();
307 if (theme.resolveAttribute(
attribute, tv,
true)) {
308 if (tv.resourceId != 0)
309 return resources.getColor(tv.resourceId, theme);
310 if (tv.type >= TypedValue.TYPE_FIRST_COLOR_INT && tv.type <= TypedValue.TYPE_LAST_COLOR_INT)
317 @SuppressWarnings(
"deprecation")
318 static
int getThemeDefaultStatusBarColor(Activity activity)
320 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
322 return resolveColorAttribute(activity, android.R.attr.statusBarColor);
325 @SuppressWarnings(
"deprecation")
326 static
int getThemeDefaultNavigationBarColor(Activity activity)
328 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
330 return resolveColorAttribute(activity, android.R.attr.navigationBarColor);
333 static void enableSystemBarsBackgroundDrawing(
Window window)
336 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
337 @SuppressWarnings(
"deprecation")
338 final
int translucentFlags = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
339 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
340 window.clearFlags(translucentFlags);
343 @SuppressWarnings(
"deprecation")
346 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
351 @SuppressWarnings(
"deprecation")
354 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM)
Q_CORE_EXPORT QtJniTypes::Activity activity()
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage return
static struct AttrInfo attrs[]
EGLOutputLayerEXT EGLint attribute
GLuint color
[setDefaultFactory]
manager post(request, myJson, this, [this](QRestReply &reply) { if(!reply.isSuccess()) { } if(std::optional json=reply.readJson()) { } })
if(foo.startsWith("("+type+") 0x")) ... QString hello("hello")
[0]