4package org.qtproject.qt.android;
6import android.app.Activity;
7import android.content.Context;
8import android.content.res.Resources;
9import android.content.res.TypedArray;
10import android.os.Build;
11import android.view.View;
12import android.view.WindowInsets;
13import android.view.WindowManager;
14import android.view.WindowInsetsController;
15import android.view.Window;
17import android.graphics.Color;
18import android.util.TypedValue;
19import android.content.res.Resources.Theme;
21class QtWindowInsetsController
27 @SuppressWarnings (
"deprecation")
30 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
32 if (isEdgeToEdgeEnforced(
window.getContext()))
40 private static int themeCutoutMode(
Context context)
42 int[] attrs =
new int[] { android.R.attr.windowLayoutInDisplayCutoutMode };
45 return ta.getInt(0, WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT);
51 private static void useCutoutShortEdges(Window
window,
boolean enabled)
56 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
57 WindowManager.LayoutParams layoutParams =
window.getAttributes();
58 layoutParams.layoutInDisplayCutoutMode =
enabled
59 ? WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
60 : themeCutoutMode(
window.getContext());
61 window.setAttributes(layoutParams);
66 static void showNormal(Activity activity)
72 final View decor =
window.getDecorView();
73 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
74 setDecorFitsSystemWindows(
window,
true);
75 WindowInsetsController ctrl =
window.getInsetsController();
77 ctrl.show(WindowInsets.Type.systemBars());
78 ctrl.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_DEFAULT);
81 @SuppressWarnings(
"deprecation")
82 int
flags = View.SYSTEM_UI_FLAG_VISIBLE;
83 setSystemUiVisibility(decor,
flags);
86 setTransparentSystemBars(activity, false);
87 useCutoutShortEdges(
window, false);
89 QtRootLayout root = QtRootLayout.findIn(activity);
91 root.setContentInsetEnabled(true);
93 decor.
post(() -> decor.requestApplyInsets());
99 @SuppressWarnings(
"deprecation")
100 private static
void setTransparentSystemBars(Activity activity,
boolean transparent)
106 if (isEdgeToEdgeEnforced(activity))
110 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
111 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
112 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
115 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
122 int statusBarColor =
window.getStatusBarColor();
123 int transparentStatusBar = statusBarColor & 0x00FFFFFF;
124 window.setStatusBarColor(transparentStatusBar);
126 int navigationBarColor =
window.getNavigationBarColor();
127 int semiTransparentNavigationBar = navigationBarColor & 0x7FFFFFFF;
128 window.setNavigationBarColor(semiTransparentNavigationBar);
132 int defaultStatusBarColor = getThemeDefaultStatusBarColor(activity);
133 window.setStatusBarColor(defaultStatusBarColor);
135 int defaultNavigationBarColor = getThemeDefaultNavigationBarColor(activity);
136 window.setNavigationBarColor(defaultNavigationBarColor);
141 static void showExpanded(Activity activity)
147 final View decor =
window.getDecorView();
148 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
149 setDecorFitsSystemWindows(
window,
false);
150 WindowInsetsController ctrl =
window.getInsetsController();
152 ctrl.show(WindowInsets.Type.systemBars());
153 ctrl.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_DEFAULT);
156 @SuppressWarnings(
"deprecation")
157 int
flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
158 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
159 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
160 setSystemUiVisibility(decor,
flags);
163 setTransparentSystemBars(activity, true);
164 useCutoutShortEdges(
window, true);
166 QtRootLayout root = QtRootLayout.findIn(activity);
168 root.setContentInsetEnabled(false);
170 decor.
post(() -> decor.requestApplyInsets());
174 public static
void showFullScreen(Activity activity)
180 final View decor =
window.getDecorView();
181 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
182 setDecorFitsSystemWindows(window, false);
183 WindowInsetsController ctrl = window.getInsetsController();
185 ctrl.hide(WindowInsets.Type.systemBars());
186 ctrl.setSystemBarsBehavior(
187 WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
190 @SuppressWarnings(
"deprecation")
191 int
flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
192 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
193 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
194 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
195 | View.SYSTEM_UI_FLAG_FULLSCREEN
196 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
197 setSystemUiVisibility(decor,
flags);
200 useCutoutShortEdges(
window, true);
202 QtRootLayout root = QtRootLayout.findIn(activity);
204 root.setContentInsetEnabled(false);
206 decor.
post(() -> decor.requestApplyInsets());
213 static
boolean isEdgeToEdgeEnforced(
Context context) {
214 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM)
217 final int targetSdk =
context.getApplicationInfo().targetSdkVersion;
218 if (targetSdk < Build.VERSION_CODES.VANILLA_ICE_CREAM)
220 if (targetSdk > Build.VERSION_CODES.VANILLA_ICE_CREAM)
224 int[] attrs =
new int[] { android.R.attr.windowOptOutEdgeToEdgeEnforcement };
225 TypedArray ta =
context.getTheme().obtainStyledAttributes(attrs);
227 return !ta.getBoolean(0, false);
233 static boolean isFullScreen(Activity activity)
239 final View decor =
window.getDecorView();
240 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
241 WindowInsetsController controller =
window.getInsetsController();
242 if (controller !=
null) {
243 final int behavior = controller.getSystemBarsBehavior();
244 return behavior == WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;
246 }
else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
247 WindowInsets insets = decor.getRootWindowInsets();
249 return !insets.isVisible(WindowInsets.Type.statusBars());
251 @SuppressWarnings(
"deprecation")
252 int
flags = decor.getSystemUiVisibility();
253 @SuppressWarnings(
"deprecation")
254 int immersiveMask = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
261 static
boolean isExpandedClientArea(Activity activity)
263 if (isEdgeToEdgeEnforced(activity))
266 @SuppressWarnings(
"deprecation")
267 int statusBarColor = activity.getWindow().getStatusBarColor();
270 int statusBarAlpha = statusBarColor >>> 24;
271 return statusBarAlpha != 0xFF;
274 static
boolean decorFitsSystemWindows(Activity activity)
276 return !isFullScreen(activity) && !isExpandedClientArea(activity);
279 private static native
void applySystemUiNative();
285 static void applySystemUi()
287 if (QtNative.getStateDetails().isStarted)
288 applySystemUiNative();
294 @SuppressWarnings (
"deprecation")
295 private static
void setSystemUiVisibility(View decorView,
int flags)
297 decorView.setSystemUiVisibility(
flags);
304 static void setStatusBarColorHint(Activity activity,
boolean isLight)
307 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
308 WindowInsetsController controller =
window.getInsetsController();
309 if (controller !=
null) {
310 int lightStatusBarMask = WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
311 int appearance = isLight ? lightStatusBarMask : 0;
312 controller.setSystemBarsAppearance(appearance, lightStatusBarMask);
315 @SuppressWarnings(
"deprecation")
316 int currentFlags =
window.getDecorView().getSystemUiVisibility();
317 @SuppressWarnings(
"deprecation")
318 int lightStatusBarMask = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
319 int appearance = isLight
320 ? currentFlags | lightStatusBarMask
321 : currentFlags & ~lightStatusBarMask;
322 setSystemUiVisibility(
window.getDecorView(), appearance);
330 static
void setNavigationBarColorHint(Activity activity,
boolean isLight)
333 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
334 WindowInsetsController controller = window.getInsetsController();
335 if (controller != null) {
336 int lightNavigationBarMask = WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
337 int appearance = isLight ? lightNavigationBarMask : 0;
338 controller.setSystemBarsAppearance(appearance, lightNavigationBarMask);
341 @SuppressWarnings(
"deprecation")
342 int currentFlags =
window.getDecorView().getSystemUiVisibility();
343 @SuppressWarnings(
"deprecation")
344 int lightNavigationBarMask = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
345 int appearance = isLight
346 ? currentFlags | lightNavigationBarMask
347 : currentFlags & ~lightNavigationBarMask;
348 setSystemUiVisibility(
window.getDecorView(), appearance);
355 Resources resources =
activity.getResources();
356 TypedValue tv =
new TypedValue();
358 if (theme.resolveAttribute(
attribute, tv,
true)) {
359 if (tv.resourceId != 0)
360 return resources.getColor(tv.resourceId, theme);
361 if (tv.type >= TypedValue.TYPE_FIRST_COLOR_INT && tv.type <= TypedValue.TYPE_LAST_COLOR_INT)
368 @SuppressWarnings(
"deprecation")
369 static
int getThemeDefaultStatusBarColor(Activity activity)
371 if (isEdgeToEdgeEnforced(activity))
373 return resolveColorAttribute(activity, android.R.attr.statusBarColor);
376 @SuppressWarnings(
"deprecation")
377 static
int getThemeDefaultNavigationBarColor(Activity activity)
379 if (isEdgeToEdgeEnforced(activity))
381 return resolveColorAttribute(activity, android.R.attr.navigationBarColor);
384 static void enableSystemBarsBackgroundDrawing(Window
window)
387 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
388 @SuppressWarnings(
"deprecation")
389 final
int translucentFlags = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
390 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
391 window.clearFlags(translucentFlags);
394 @SuppressWarnings(
"deprecation")
395 static
void setStatusBarColor(Window
window,
int color)
397 if (isEdgeToEdgeEnforced(
window.getContext()))
402 @SuppressWarnings(
"deprecation")
403 static
void setNavigationBarColor(Window
window,
int color)
405 if (isEdgeToEdgeEnforced(
window.getContext()))
Napi::TypedArray TypedArray
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
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]