diff options
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt/android/QtLayout.java')
-rw-r--r-- | src/android/jar/src/org/qtproject/qt/android/QtLayout.java | 123 |
1 files changed, 30 insertions, 93 deletions
diff --git a/src/android/jar/src/org/qtproject/qt/android/QtLayout.java b/src/android/jar/src/org/qtproject/qt/android/QtLayout.java index a65df48a17..aedc845014 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtLayout.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtLayout.java @@ -1,60 +1,24 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Android port of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2023 The Qt Company Ltd. +// Copyright (C) 2012 BogDan Vatra <bogdan@kde.org> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only package org.qtproject.qt.android; import android.app.Activity; import android.content.Context; +import android.os.Build; import android.util.AttributeSet; import android.util.DisplayMetrics; +import android.view.Display; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import android.view.WindowInsets; -public class QtLayout extends ViewGroup -{ - private Runnable m_startApplicationRunnable; - public QtLayout(Context context, Runnable startRunnable) +class QtLayout extends ViewGroup { + + public QtLayout(Context context) { super(context); - m_startApplicationRunnable = startRunnable; } public QtLayout(Context context, AttributeSet attrs) @@ -68,41 +32,6 @@ public class QtLayout extends ViewGroup } @Override - protected void onSizeChanged (int w, int h, int oldw, int oldh) - { - WindowInsets insets = getRootWindowInsets(); - - DisplayMetrics realMetrics = new DisplayMetrics(); - ((Activity) getContext()).getWindowManager().getDefaultDisplay().getRealMetrics(realMetrics); - - boolean isFullScreenView = h == realMetrics.heightPixels; - - int insetLeft = isFullScreenView ? insets.getSystemWindowInsetLeft() : 0; - int insetTop = isFullScreenView ? insets.getSystemWindowInsetTop() : 0; - int insetRight = isFullScreenView ? insets.getSystemWindowInsetRight() : 0; - int insetBottom = isFullScreenView ? insets.getSystemWindowInsetBottom() : 0; - - int usableAreaWidth = w - insetLeft - insetRight; - int usableAreaHeight = h - insetTop - insetBottom; - - QtNative.setApplicationDisplayMetrics(realMetrics.widthPixels, - realMetrics.heightPixels, - insetLeft, - insetTop, - usableAreaWidth, - usableAreaHeight, - realMetrics.xdpi, - realMetrics.ydpi, - realMetrics.scaledDensity, - realMetrics.density); - - if (m_startApplicationRunnable != null) { - m_startApplicationRunnable.run(); - m_startApplicationRunnable = null; - } - } - - @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int count = getChildCount(); @@ -120,11 +49,15 @@ public class QtLayout extends ViewGroup int childRight; int childBottom; - QtLayout.LayoutParams lp - = (QtLayout.LayoutParams) child.getLayoutParams(); - - childRight = lp.x + child.getMeasuredWidth(); - childBottom = lp.y + child.getMeasuredHeight(); + if (child.getLayoutParams() instanceof QtLayout.LayoutParams) { + QtLayout.LayoutParams lp + = (QtLayout.LayoutParams) child.getLayoutParams(); + childRight = lp.x + child.getMeasuredWidth(); + childBottom = lp.y + child.getMeasuredHeight(); + } else { + childRight = child.getMeasuredWidth(); + childBottom = child.getMeasuredHeight(); + } maxWidth = Math.max(maxWidth, childRight); maxHeight = Math.max(maxHeight, childBottom); @@ -158,7 +91,6 @@ public class QtLayout extends ViewGroup protected void onLayout(boolean changed, int l, int t, int r, int b) { int count = getChildCount(); - for (int i = 0; i < count; i++) { View child = getChildAt(i); if (child.getVisibility() != GONE) { @@ -167,10 +99,11 @@ public class QtLayout extends ViewGroup int childLeft = lp.x; int childTop = lp.y; - child.layout(childLeft, childTop, - childLeft + child.getMeasuredWidth(), - childTop + child.getMeasuredHeight()); - + int childRight = (lp.width == ViewGroup.LayoutParams.MATCH_PARENT) ? + r - l : childLeft + child.getMeasuredWidth(); + int childBottom = (lp.height == ViewGroup.LayoutParams.MATCH_PARENT) ? + b - t : childTop + child.getMeasuredHeight(); + child.layout(childLeft, childTop, childRight, childBottom); } } } @@ -190,8 +123,7 @@ public class QtLayout extends ViewGroup /** * Per-child layout information associated with AbsoluteLayout. - * See - * {@link android.R.styleable#AbsoluteLayout_Layout Absolute Layout Attributes} + * See {android.R.styleable#AbsoluteLayout_Layout Absolute Layout Attributes} * for a list of all child view attributes that this class supports. */ public static class LayoutParams extends ViewGroup.LayoutParams @@ -223,6 +155,11 @@ public class QtLayout extends ViewGroup this.y = y; } + public LayoutParams(int width, int height) + { + super(width, height); + } + /** * {@inheritDoc} */ @@ -248,7 +185,7 @@ public class QtLayout extends ViewGroup /** * set the layout params on a child view. - * + * <p> * Note: This function adds the child view if it's not in the * layout already. */ |