Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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.os.Build;
10import android.util.DisplayMetrics;
11import android.view.Display;
12import android.content.res.Configuration;
13import android.view.Surface;
14
19public class QtRootLayout extends QtLayout
20{
21 private int m_activityDisplayRotation = -1;
22 private int m_ownDisplayRotation = -1;
23 private int m_nativeOrientation = -1;
24 private int m_previousRotation = -1;
25
26 public QtRootLayout(Context context)
27 {
28 super(context);
29 }
30
31 public void setActivityDisplayRotation(int rotation)
32 {
33 m_activityDisplayRotation = rotation;
34 }
35
36 public void setNativeOrientation(int orientation)
37 {
38 m_nativeOrientation = orientation;
39 }
40
41 public int displayRotation()
42 {
43 return m_ownDisplayRotation;
44 }
45
46 @Override
47 protected void onSizeChanged (int w, int h, int oldw, int oldh)
48 {
49 Activity activity = (Activity)getContext();
50 if (activity == null)
51 return;
52
53 DisplayMetrics realMetrics = new DisplayMetrics();
54 Display display = (Build.VERSION.SDK_INT < Build.VERSION_CODES.R)
55 ? activity.getWindowManager().getDefaultDisplay()
56 : activity.getDisplay();
57
58 if (display == null)
59 return;
60
61 display.getRealMetrics(realMetrics);
62 if ((realMetrics.widthPixels > realMetrics.heightPixels) != (w > h)) {
63 // This is an intermediate state during display rotation.
64 // The new size is still reported for old orientation, while
65 // realMetrics contain sizes for new orientation. Setting
66 // such parameters will produce inconsistent results, so
67 // we just skip them.
68 // We will have another onSizeChanged() with normal values
69 // a bit later.
70 return;
71 }
72 QtDisplayManager.setApplicationDisplayMetrics(activity, w, h);
73 QtDisplayManager.handleOrientationChanges(activity);
74 }
75
76 @Override
77 public void onConfigurationChanged(Configuration configuration)
78 {
79 Context context = getContext();
80 if (context instanceof Activity) {
81 Activity activity = (Activity)context;
82 //if orientation change is betwen invertedPortrait and portrait or
83 //invertedLandscape and landscape, we do not get sizeChanged callback.
84 int rotation = QtDisplayManager.getDisplayRotation(activity);
85 if (isSameSizeForOrientations(rotation, m_previousRotation))
86 QtDisplayManager.handleOrientationChanges(activity);
87 m_previousRotation = rotation;
88 }
89 }
90
91 public boolean isSameSizeForOrientations(int r1, int r2) {
92 return (r1 == r2) ||
93 (r1 == Surface.ROTATION_0 && r2 == Surface.ROTATION_180)
94 || (r1 == Surface.ROTATION_180 && r2 == Surface.ROTATION_0)
95 || (r1 == Surface.ROTATION_90 && r2 == Surface.ROTATION_270)
96 || (r1 == Surface.ROTATION_270 && r2 == Surface.ROTATION_90);
97 }
98}
void setNativeOrientation(int orientation)
void setActivityDisplayRotation(int rotation)
boolean isSameSizeForOrientations(int r1, int r2)
void onSizeChanged(int w, int h, int oldw, int oldh)
void onConfigurationChanged(Configuration configuration)
struct wl_display * display
Definition linuxdmabuf.h:41
static void * context
GLfloat GLfloat GLfloat w
[0]
GLfloat GLfloat GLfloat GLfloat h
QRect r1(100, 200, 11, 16)
[0]
QRect r2(QPoint(100, 200), QSize(11, 16))