4package org.qtproject.qt.android;
6import android.content.Context;
7import android.view.GestureDetector;
8import android.view.MotionEvent;
9import android.util.Log;
10import android.view.Surface;
11import android.view.View;
12import android.view.ViewGroup;
14import java.util.HashMap;
16class QtWindow
extends QtLayout implements QtSurfaceInterface {
17 private final static String TAG =
"QtWindow";
19 private View m_surfaceContainer;
20 private View m_nativeView;
21 private HashMap<Integer, QtWindow> m_childWindows =
new HashMap<Integer, QtWindow>();
22 private QtWindow m_parentWindow;
23 private GestureDetector m_gestureDetector;
24 private final QtEditText m_editText;
26 private static native
void setSurface(
int windowId, Surface surface);
27 static native
void windowFocusChanged(
boolean hasFocus,
int id);
29 public QtWindow(Context
context, QtWindow parentWindow, QtInputDelegate delegate)
33 m_editText =
new QtEditText(
context, delegate);
34 setParent(parentWindow);
35 setFocusableInTouchMode(
true);
36 addView(m_editText,
new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
37 ViewGroup.LayoutParams.MATCH_PARENT));
39 QtNative.runAction(() -> {
41 new GestureDetector(
context,
new GestureDetector.SimpleOnGestureListener() {
42 public void onLongPress(MotionEvent event) {
43 QtInputDelegate.longPress(getId(), (int) event.getX(), (int) event.getY());
46 m_gestureDetector.setIsLongpressEnabled(
true);
50 void setVisible(
boolean visible) {
51 QtNative.runAction(() -> {
53 setVisibility(
View.VISIBLE);
55 setVisibility(
View.INVISIBLE);
60 public void onSurfaceChanged(Surface surface)
62 setSurface(getId(), surface);
66 public boolean onTouchEvent(MotionEvent
event)
68 m_editText.requestFocus();
69 event.setLocation(
event.getX() + getX(),
event.getY() + getY());
70 QtInputDelegate.sendTouchEvent(
event, getId());
71 m_gestureDetector.onTouchEvent(
event);
76 public boolean onTrackballEvent(MotionEvent
event)
78 QtInputDelegate.sendTrackballEvent(
event, getId());
83 public boolean onGenericMotionEvent(MotionEvent
event)
85 return QtInputDelegate.sendGenericMotionEvent(
event, getId());
88 public void removeWindow()
90 if (m_parentWindow !=
null)
91 m_parentWindow.removeChildWindow(getId());
94 public void createSurface(
final boolean onTop,
95 final int x,
final int y,
final int w,
final int h,
96 final int imageDepth,
final boolean isOpaque,
97 final int surfaceContainerType)
99 QtNative.runAction(()-> {
100 if (m_surfaceContainer !=
null)
101 removeView(m_surfaceContainer);
103 setLayoutParams(
new QtLayout.LayoutParams(
w,
h,
x,
y));
104 if (surfaceContainerType == 0) {
105 m_surfaceContainer =
new QtSurface(getContext(), QtWindow.this,
108 m_surfaceContainer =
new QtTextureView(getContext(), QtWindow.this, isOpaque);
110 m_surfaceContainer.setLayoutParams(
new QtLayout.LayoutParams(
111 ViewGroup.LayoutParams.MATCH_PARENT,
112 ViewGroup.LayoutParams.MATCH_PARENT));
115 addView(m_surfaceContainer, 0);
119 public void destroySurface()
121 QtNative.runAction(()-> {
122 if (m_surfaceContainer !=
null) {
123 removeView(m_surfaceContainer);
124 m_surfaceContainer =
null;
129 public void setGeometry(
final int x,
final int y,
final int w,
final int h)
131 QtNative.runAction(()-> {
132 if (getContext() instanceof QtActivityBase)
133 setLayoutParams(
new QtLayout.LayoutParams(
w,
h,
x,
y));
137 public void addChildWindow(QtWindow
window)
139 QtNative.runAction(()-> {
141 addView(
window, getChildCount());
145 public void removeChildWindow(
int id)
147 QtNative.runAction(()-> {
148 if (m_childWindows.containsKey(
id))
149 removeView(m_childWindows.remove(
id));
153 public void setNativeView(
final View view,
154 final int x,
final int y,
final int w,
final int h)
156 QtNative.runAction(()-> {
157 if (m_nativeView !=
null)
158 removeView(m_nativeView);
161 QtWindow.this.setLayoutParams(
new QtLayout.LayoutParams(
w,
h,
x,
y));
162 m_nativeView.setLayoutParams(
new QtLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
163 ViewGroup.LayoutParams.MATCH_PARENT));
164 addView(m_nativeView);
168 public void bringChildToFront(
int id)
170 QtNative.runAction(()-> {
173 if (getChildCount() > 0)
174 moveChild(
view, getChildCount() - 1);
179 public void bringChildToBack(
int id) {
180 QtNative.runAction(()-> {
188 public void removeNativeView()
190 QtNative.runAction(()-> {
191 if (m_nativeView !=
null) {
192 removeView(m_nativeView);
200 if (m_parentWindow == parentWindow)
203 if (m_parentWindow !=
null)
204 m_parentWindow.removeChildWindow(getId());
206 m_parentWindow = parentWindow;
207 if (m_parentWindow !=
null)
208 m_parentWindow.addChildWindow(
this);
213 return m_parentWindow;
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLfloat GLfloat GLfloat GLfloat h
static bool onTop(QWaylandQuickShellSurfaceItem *surf)
file setParent(multiPart)