Android: Change QtWindow Runnables to lambdas

Pick-to: 6.7
Change-Id: I19a3e0a0a035a49965d7643db3ebdb72de95a3a9
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Tinja Paavoseppä 2024-02-07 11:12:11 +02:00
parent 1f2570976e
commit 46c2d587b0

View File

@ -88,90 +88,72 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
final int imageDepth, final boolean isOpaque,
final int surfaceContainerType) // TODO constant for type
{
QtNative.runAction(new Runnable() {
@Override
public void run() {
if (m_surfaceContainer != null)
removeView(m_surfaceContainer);
QtNative.runAction(()-> {
if (m_surfaceContainer != null)
removeView(m_surfaceContainer);
setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
if (surfaceContainerType == 0) {
m_surfaceContainer = new QtSurface(getContext(), QtWindow.this,
onTop, imageDepth);
} else {
m_surfaceContainer = new QtTextureView(getContext(), QtWindow.this, isOpaque);
}
m_surfaceContainer.setLayoutParams(new QtLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
// The surface container of this window will be added as the first of the stack.
// All other views are stacked based on the order they are created.
addView(m_surfaceContainer, 0);
setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
if (surfaceContainerType == 0) {
m_surfaceContainer = new QtSurface(getContext(), QtWindow.this,
onTop, imageDepth);
} else {
m_surfaceContainer = new QtTextureView(getContext(), QtWindow.this, isOpaque);
}
m_surfaceContainer.setLayoutParams(new QtLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
// The surface container of this window will be added as the first of the stack.
// All other views are stacked based on the order they are created.
addView(m_surfaceContainer, 0);
});
}
public void destroySurface()
{
QtNative.runAction(new Runnable() {
@Override
public void run() {
if (m_surfaceContainer != null) {
removeView(m_surfaceContainer);
m_surfaceContainer = null;
}
QtNative.runAction(()-> {
if (m_surfaceContainer != null) {
removeView(m_surfaceContainer);
m_surfaceContainer = null;
}
});
}
public void setGeometry(final int x, final int y, final int w, final int h)
{
QtNative.runAction(new Runnable() {
@Override
public void run() {
if (getContext() instanceof QtActivityBase)
setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
}
QtNative.runAction(()-> {
if (getContext() instanceof QtActivityBase)
setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
});
}
public void addChildWindow(QtWindow window)
{
QtNative.runAction(new Runnable() {
@Override
public void run() {
m_childWindows.put(window.getId(), window);
addView(window, getChildCount());
}
QtNative.runAction(()-> {
m_childWindows.put(window.getId(), window);
addView(window, getChildCount());
});
}
public void removeChildWindow(int id)
{
QtNative.runAction(new Runnable() {
@Override
public void run() {
if (m_childWindows.containsKey(id))
removeView(m_childWindows.remove(id));
}
QtNative.runAction(()-> {
if (m_childWindows.containsKey(id))
removeView(m_childWindows.remove(id));
});
}
public void setNativeView(final View view,
final int x, final int y, final int w, final int h)
{
QtNative.runAction(new Runnable() {
@Override
public void run() {
if (m_nativeView != null)
removeView(m_nativeView);
QtNative.runAction(()-> {
if (m_nativeView != null)
removeView(m_nativeView);
m_nativeView = view;
QtWindow.this.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
m_nativeView.setLayoutParams(new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
addView(m_nativeView);
}
m_nativeView = view;
QtWindow.this.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
m_nativeView.setLayoutParams(new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
addView(m_nativeView);
});
}
@ -187,26 +169,20 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
}
public void bringChildToBack(int id) {
QtNative.runAction(new Runnable() {
@Override
public void run() {
View view = m_childWindows.get(id);
if (view != null) {
moveChild(view, 0);
}
QtNative.runAction(()-> {
View view = m_childWindows.get(id);
if (view != null) {
moveChild(view, 0);
}
});
}
public void removeNativeView()
{
QtNative.runAction(new Runnable() {
@Override
public void run() {
if (m_nativeView != null) {
removeView(m_nativeView);
m_nativeView = null;
}
QtNative.runAction(()-> {
if (m_nativeView != null) {
removeView(m_nativeView);
m_nativeView = null;
}
});
}