Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QtRootLayout.java
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5package org.qtproject.qt.android;
6
7import android.app.Activity;
8import android.content.Context;
9import android.content.res.Configuration;
10import android.graphics.Insets;
11import android.view.View;
12import android.view.ViewGroup;
13import android.view.WindowInsets;
14
19class QtRootLayout extends QtLayout
20{
21 private static final int s_viewId = View.generateViewId();
22 private Insets m_safeAreaInsets = Insets.NONE;
23 private boolean m_insetContent = true;
24
25 QtRootLayout(Context context)
26 {
27 super(context, s_viewId);
28 }
29
30 static QtRootLayout findIn(Activity activity)
31 {
32 View root = activity.findViewById(s_viewId);
33 return root instanceof QtRootLayout ? (QtRootLayout)root : null;
34 }
35
37 public WindowInsets onApplyWindowInsets(WindowInsets insets)
38 {
39 if (QtWindowInsetsController.isEdgeToEdgeEnforced(getContext())) {
40 // Child insets can include the IME under adjustResize.
41 final WindowInsets rootInsets = getRootWindowInsets();
42 final int types = WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout();
43 m_safeAreaInsets = (rootInsets != null ? rootInsets : insets).getInsets(types);
44 }
45 updateMargins();
46 return super.onApplyWindowInsets(insets);
47 }
48
49 void setContentInsetEnabled(boolean enabled)
50 {
51 m_insetContent = enabled;
52 updateMargins();
53 }
54
55 private void updateMargins()
56 {
57 if (!QtWindowInsetsController.isEdgeToEdgeEnforced(getContext()))
58 return;
59
60 final ViewGroup.LayoutParams layoutParams = getLayoutParams();
61 if (!(layoutParams instanceof ViewGroup.MarginLayoutParams))
62 return;
63
64 // Inset only when Android overrides normal window geometry.
65 Insets margins = m_insetContent ? m_safeAreaInsets : Insets.NONE;
66 ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams)layoutParams;
67 final boolean leftMarginChanged = params.leftMargin != margins.left;
68 final boolean topMarginChanged = params.topMargin != margins.top;
69 final boolean rightMarginChanged = params.rightMargin != margins.right;
70 final boolean bottomMarginChanged = params.bottomMargin != margins.bottom;
71 if (!leftMarginChanged && !topMarginChanged && !rightMarginChanged && !bottomMarginChanged)
72 return;
73
74 params.setMargins(margins.left, margins.top, margins.right, margins.bottom);
75 setLayoutParams(params);
76 }
77
79 protected void onSizeChanged(int w, int h, int oldw, int oldh)
80 {
81 Activity activity = (Activity) getContext();
82 if (activity == null || (w == oldw && h == oldh))
83 return;
84
85 QtDisplayManager.handleLayoutSizeChanged(w, h);
86 }
87
89 public void onConfigurationChanged(Configuration configuration)
90 {
91 Activity activity = (Activity) getContext();
92 if (activity == null)
93 return;
94
95 // Post the orientation handling just in case the onSizeChanged() is
96 // called a bit late (QTBUG-94459).
97 QtNative.runAction(() -> {
98 QtDisplayManager.handleOrientationChange(activity);
99 });
100 }
101}
QPainter Context
Q_CORE_EXPORT QtJniTypes::Activity activity()
GLvoid ** params
GLsizei GLenum GLenum * types
GLfloat GLfloat GLfloat w
[0]
GLfloat GLfloat GLfloat GLfloat h
#define enabled