Android: rectify class visibility and cleanup for child windows support

* Make classes that don't need to be public as package private
* Remove dead code that serves no purpose now.
* Use lambdas when needed.
* Use @UsedFromNativeCode for methods called from native code.

Change-Id: Ie34eec079366fb3ef048e0f49e03f507cdf90e97
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
bb10
Assam Boudjelthia 2023-12-23 11:27:31 +02:00
parent 7d9d1220f3
commit 89937077da
8 changed files with 20 additions and 42 deletions

View File

@ -3,7 +3,7 @@
package org.qtproject.qt.android;
@UsedFromNativeCode
public interface QtAccessibilityInterface {
interface QtAccessibilityInterface {
default void initializeAccessibility() { }
default void notifyLocationChange(int viewId) { }
default void notifyObjectHide(int viewId, int parentId) { }

View File

@ -9,7 +9,6 @@ import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.Rect;
@ -42,7 +41,7 @@ class QtActivityDelegate extends QtActivityDelegateBase
private boolean m_backendsRegistered = false;
private View m_dummyView = null;
private HashMap<Integer, View> m_nativeViews = new HashMap<Integer, View>();
private final HashMap<Integer, View> m_nativeViews = new HashMap<>();
private QtAccessibilityDelegate m_accessibilityDelegate = null;
QtActivityDelegate(Activity activity)
@ -473,7 +472,8 @@ class QtActivityDelegate extends QtActivityDelegateBase
QtNative.runAction(() -> {
if (m_nativeViews.containsKey(id)) {
View view = m_nativeViews.get(id);
view.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
if (view != null)
view.setLayoutParams(new QtLayout.LayoutParams(w, h, x, y));
} else {
Log.e(QtTAG, "View " + id + " not found!");
}

View File

@ -428,10 +428,6 @@ class QtNative
public static native boolean updateNativeActivity();
// application methods
// surface methods
public static native void setSurface(int id, Object surface);
// surface methods
// window methods
public static native void updateWindow();
// window methods

View File

@ -16,11 +16,8 @@ import android.view.Surface;
A layout which corresponds to one Activity, i.e. is the root layout where the top level window
and handles orientation changes.
*/
public class QtRootLayout extends QtLayout
class QtRootLayout extends QtLayout
{
private int m_activityDisplayRotation = -1;
private int m_ownDisplayRotation = -1;
private int m_nativeOrientation = -1;
private int m_previousRotation = -1;
public QtRootLayout(Context context)
@ -28,21 +25,6 @@ public class QtRootLayout extends QtLayout
super(context);
}
public void setActivityDisplayRotation(int rotation)
{
m_activityDisplayRotation = rotation;
}
public void setNativeOrientation(int orientation)
{
m_nativeOrientation = orientation;
}
public int displayRotation()
{
return m_ownDisplayRotation;
}
@Override
protected void onSizeChanged (int w, int h, int oldw, int oldh)
{

View File

@ -14,7 +14,7 @@ import android.view.SurfaceView;
@SuppressLint("ViewConstructor")
class QtSurface extends SurfaceView implements SurfaceHolder.Callback
{
private QtSurfaceInterface m_surfaceCallback;
private final QtSurfaceInterface m_surfaceCallback;
public QtSurface(Context context, QtSurfaceInterface surfaceCallback, boolean onTop, int imageDepth)
{

View File

@ -6,8 +6,7 @@ package org.qtproject.qt.android;
import android.view.Surface;
public interface QtSurfaceInterface
interface QtSurfaceInterface
{
void onSurfaceChanged(Surface surface);
}

View File

@ -5,15 +5,14 @@
package org.qtproject.qt.android;
import android.content.Context;
import android.graphics.PixelFormat;
import android.graphics.SurfaceTexture;
import android.util.Log;
import android.view.Surface;
import android.view.TextureView;
public class QtTextureView extends TextureView implements TextureView.SurfaceTextureListener
class QtTextureView extends TextureView implements TextureView.SurfaceTextureListener
{
private QtSurfaceInterface m_surfaceCallback;
private final QtSurfaceInterface m_surfaceCallback;
private boolean m_staysOnTop;
private Surface m_surface;

View File

@ -6,7 +6,6 @@ package org.qtproject.qt.android;
import android.content.Context;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.util.Log;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
@ -14,11 +13,9 @@ import android.view.ViewGroup;
import java.util.HashMap;
class QtWindow extends QtLayout implements QtSurfaceInterface {
private final static String TAG = "QtWindow";
private View m_surfaceContainer;
private View m_nativeView;
private HashMap<Integer, QtWindow> m_childWindows = new HashMap<Integer, QtWindow>();
private final HashMap<Integer, QtWindow> m_childWindows = new HashMap<>();
private QtWindow m_parentWindow;
private GestureDetector m_gestureDetector;
private final QtEditText m_editText;
@ -40,6 +37,7 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
QtNative.runAction(() -> {
m_gestureDetector =
new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public void onLongPress(MotionEvent event) {
QtInputDelegate.longPress(getId(), (int) event.getX(), (int) event.getY());
}
@ -48,6 +46,7 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
});
}
@UsedFromNativeCode
void setVisible(boolean visible) {
QtNative.runAction(() -> {
if (visible)
@ -86,12 +85,14 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
return QtInputDelegate.sendGenericMotionEvent(event, getId());
}
@UsedFromNativeCode
public void removeWindow()
{
if (m_parentWindow != null)
m_parentWindow.removeChildWindow(getId());
}
@UsedFromNativeCode
public void createSurface(final boolean onTop,
final int x, final int y, final int w, final int h,
final int imageDepth, final boolean isOpaque,
@ -117,6 +118,7 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
});
}
@UsedFromNativeCode
public void destroySurface()
{
QtNative.runAction(()-> {
@ -127,6 +129,7 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
}, false);
}
@UsedFromNativeCode
public void setGeometry(final int x, final int y, final int w, final int h)
{
QtNative.runAction(()-> {
@ -151,6 +154,7 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
});
}
@UsedFromNativeCode
public void setNativeView(final View view,
final int x, final int y, final int w, final int h)
{
@ -166,6 +170,7 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
});
}
@UsedFromNativeCode
public void bringChildToFront(int id)
{
QtNative.runAction(()-> {
@ -177,6 +182,7 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
});
}
@UsedFromNativeCode
public void bringChildToBack(int id) {
QtNative.runAction(()-> {
View view = m_childWindows.get(id);
@ -186,6 +192,7 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
});
}
@UsedFromNativeCode
public void removeNativeView()
{
QtNative.runAction(()-> {
@ -208,9 +215,4 @@ class QtWindow extends QtLayout implements QtSurfaceInterface {
if (m_parentWindow != null)
m_parentWindow.addChildWindow(this);
}
QtWindow parent()
{
return m_parentWindow;
}
}