From b42f174cd5be2014ae74453ab2d09742cc83fc36 Mon Sep 17 00:00:00 2001 From: Soheil Armin Date: Tue, 20 Feb 2024 18:35:34 +0200 Subject: [PATCH] Android: Bring back QtActivityDelegate.insertNativeView() Temporarily bring back the QtActivityDelegate.insertNativeView() and QtActivityDelegate.setNativeViewGeometry() (replacement for setSurfaceGeometry()) as they are still in use by the ActivityView module of QtAndroidAutomotive. They have been removed by 0a92d881bb91d3ff14187e7838af1cad9ad1070c. Pick-to: 6.7 Change-Id: Ia00407d827ca9217c9f49df55b4cf7001ac9871a Reviewed-by: Assam Boudjelthia --- .../qt/android/QtActivityDelegate.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java index 482ad2abd58..717cd079a4f 100644 --- a/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt/android/QtActivityDelegate.java @@ -42,6 +42,7 @@ class QtActivityDelegate extends QtActivityDelegateBase private boolean m_splashScreenSticky = false; private View m_dummyView = null; + private HashMap m_nativeViews = new HashMap(); QtActivityDelegate(Activity activity) @@ -400,4 +401,44 @@ class QtActivityDelegate extends QtActivityDelegateBase m_activity.getWindow().setBackgroundDrawable(backgroundDrawable); } + + // TODO: QTBUG-122761 To be removed after QtAndroidAutomotive does not depend on it. + @UsedFromNativeCode + public void insertNativeView(int id, View view, int x, int y, int w, int h) + { + QtNative.runAction(()-> { + if (m_dummyView != null) { + m_layout.removeView(m_dummyView); + m_dummyView = null; + } + + if (m_nativeViews.containsKey(id)) + m_layout.removeView(m_nativeViews.remove(id)); + + if (w < 0 || h < 0) { + view.setLayoutParams(new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + } else { + view.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y)); + } + + view.setId(id); + m_layout.addView(view); + m_nativeViews.put(id, view); + }); + } + + // TODO: QTBUG-122761 To be removed after QtAndroidAutomotive does not depend on it. + @UsedFromNativeCode + public void setNativeViewGeometry(int id, int x, int y, int w, int h) + { + QtNative.runAction(() -> { + if (m_nativeViews.containsKey(id)) { + View view = m_nativeViews.get(id); + view.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y)); + } else { + Log.e(QtTAG, "View " + id + " not found!"); + } + }); + } }