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()))
42 int[]
attrs =
new int[] { android.R.attr.windowLayoutInDisplayCutoutMode };
45 return ta.getInt(0, WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT);
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 decor.
post(() -> decor.requestApplyInsets());
95 @SuppressWarnings(
"deprecation")
96 private static
void setTransparentSystemBars(Activity activity,
boolean transparent)
102 if (isEdgeToEdgeEnforced(activity))
106 window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
107 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
108 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
111 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
118 int statusBarColor =
window.getStatusBarColor();
119 int transparentStatusBar = statusBarColor & 0x00FFFFFF;
120 window.setStatusBarColor(transparentStatusBar);
122 int navigationBarColor =
window.getNavigationBarColor();
123 int semiTransparentNavigationBar = navigationBarColor & 0x7FFFFFFF;
124 window.setNavigationBarColor(semiTransparentNavigationBar);
128 int defaultStatusBarColor = getThemeDefaultStatusBarColor(activity);
129 window.setStatusBarColor(defaultStatusBarColor);
131 int defaultNavigationBarColor = getThemeDefaultNavigationBarColor(activity);
132 window.setNavigationBarColor(defaultNavigationBarColor);
137 static void showExpanded(Activity activity)
143 final View decor =
window.getDecorView();
144 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
145 setDecorFitsSystemWindows(
window,
false);
146 WindowInsetsController ctrl =
window.getInsetsController();
148 ctrl.show(WindowInsets.Type.systemBars());
149 ctrl.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_DEFAULT);
152 @SuppressWarnings(
"deprecation")
153 int
flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
154 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
155 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
156 setSystemUiVisibility(decor,
flags);
159 setTransparentSystemBars(activity, true);
160 useCutoutShortEdges(
window, true);
162 decor.
post(() -> decor.requestApplyInsets());
166 public static
void showFullScreen(Activity activity)
172 final View decor =
window.getDecorView();
173 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
174 setDecorFitsSystemWindows(window, false);
175 WindowInsetsController ctrl = window.getInsetsController();
177 ctrl.hide(WindowInsets.Type.systemBars());
178 ctrl.setSystemBarsBehavior(
179 WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
182 @SuppressWarnings(
"deprecation")
183 int
flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
184 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
185 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
186 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
187 | View.SYSTEM_UI_FLAG_FULLSCREEN
188 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
189 setSystemUiVisibility(decor,
flags);
192 useCutoutShortEdges(
window, true);
194 decor.
post(() -> decor.requestApplyInsets());
202 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM)
205 final int targetSdk =
context.getApplicationInfo().targetSdkVersion;
206 if (targetSdk < Build.VERSION_CODES.VANILLA_ICE_CREAM)
208 if (targetSdk > Build.VERSION_CODES.VANILLA_ICE_CREAM)
212 int[]
attrs =
new int[] { android.R.attr.windowOptOutEdgeToEdgeEnforcement };
213 TypedArray ta =
context.getTheme().obtainStyledAttributes(
attrs);
215 return !ta.getBoolean(0, false);
221 static boolean isFullScreen(Activity activity)
227 final View decor =
window.getDecorView();
228 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
229 WindowInsetsController controller =
window.getInsetsController();
230 if (controller !=
null) {
231 final int behavior = controller.getSystemBarsBehavior();
232 return behavior == WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;
234 }
else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.R) {
235 WindowInsets insets = decor.getRootWindowInsets();
237 return !insets.isVisible(WindowInsets.Type.statusBars());
239 @SuppressWarnings(
"deprecation")
240 int
flags = decor.getSystemUiVisibility();
241 @SuppressWarnings(
"deprecation")
242 int immersiveMask = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
249 static
boolean isExpandedClientArea(Activity activity)
251 if (isEdgeToEdgeEnforced(activity))
254 @SuppressWarnings(
"deprecation")
255 int statusBarColor = activity.getWindow().getStatusBarColor();
258 int statusBarAlpha = statusBarColor >>> 24;
259 return statusBarAlpha != 0xFF;
262 static
boolean decorFitsSystemWindows(Activity activity)
264 return !isFullScreen(activity) && !isExpandedClientArea(activity);
267 private static native
void applySystemUiNative();
273 static void applySystemUi()
275 if (QtNative.getStateDetails().isStarted)
276 applySystemUiNative();
282 @SuppressWarnings (
"deprecation")
283 private static
void setSystemUiVisibility(View decorView,
int flags)
285 decorView.setSystemUiVisibility(
flags);
292 static void setStatusBarColorHint(Activity activity,
boolean isLight)
295 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
296 WindowInsetsController controller =
window.getInsetsController();
297 if (controller !=
null) {
298 int lightStatusBarMask = WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS;
299 int appearance = isLight ? lightStatusBarMask : 0;
300 controller.setSystemBarsAppearance(appearance, lightStatusBarMask);
303 @SuppressWarnings(
"deprecation")
304 int currentFlags =
window.getDecorView().getSystemUiVisibility();
305 @SuppressWarnings(
"deprecation")
306 int lightStatusBarMask = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
307 int appearance = isLight
308 ? currentFlags | lightStatusBarMask
309 : currentFlags & ~lightStatusBarMask;
310 setSystemUiVisibility(
window.getDecorView(), appearance);
318 static
void setNavigationBarColorHint(Activity activity,
boolean isLight)
321 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
322 WindowInsetsController controller = window.getInsetsController();
323 if (controller != null) {
324 int lightNavigationBarMask = WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
325 int appearance = isLight ? lightNavigationBarMask : 0;
326 controller.setSystemBarsAppearance(appearance, lightNavigationBarMask);
329 @SuppressWarnings(
"deprecation")
330 int currentFlags =
window.getDecorView().getSystemUiVisibility();
331 @SuppressWarnings(
"deprecation")
332 int lightNavigationBarMask = View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
333 int appearance = isLight
334 ? currentFlags | lightNavigationBarMask
335 : currentFlags & ~lightNavigationBarMask;
336 setSystemUiVisibility(
window.getDecorView(), appearance);
343 Resources resources =
activity.getResources();
344 TypedValue tv =
new TypedValue();
346 if (theme.resolveAttribute(
attribute, tv,
true)) {
347 if (tv.resourceId != 0)
348 return resources.getColor(tv.resourceId, theme);
349 if (tv.type >= TypedValue.TYPE_FIRST_COLOR_INT && tv.type <= TypedValue.TYPE_LAST_COLOR_INT)
356 @SuppressWarnings(
"deprecation")
357 static
int getThemeDefaultStatusBarColor(Activity activity)
359 if (isEdgeToEdgeEnforced(activity))
361 return resolveColorAttribute(activity, android.R.attr.statusBarColor);
364 @SuppressWarnings(
"deprecation")
365 static
int getThemeDefaultNavigationBarColor(Activity activity)
367 if (isEdgeToEdgeEnforced(activity))
369 return resolveColorAttribute(activity, android.R.attr.navigationBarColor);
372 static void enableSystemBarsBackgroundDrawing(
Window window)
375 window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
376 @SuppressWarnings(
"deprecation")
377 final
int translucentFlags = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
378 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
379 window.clearFlags(translucentFlags);
382 @SuppressWarnings(
"deprecation")
385 if (isEdgeToEdgeEnforced(
window.getContext()))
390 @SuppressWarnings(
"deprecation")
393 if (isEdgeToEdgeEnforced(
window.getContext()))
static const QString context()
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
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]