5package org.qtproject.qt.android;
7import android.app.Activity;
8import android.content.Context;
9import android.graphics.Point;
10import android.view.View;
11import android.view.ViewGroup;
12import android.view.ViewTreeObserver;
13import android.widget.PopupWindow;
16class EditPopupMenu
implements ViewTreeObserver.OnPreDrawListener,
View.OnLayoutChangeListener,
17 EditContextView.OnClickListener
19 private final View m_layout;
20 private final EditContextView m_view;
21 private PopupWindow m_popup =
null;
22 private final Activity m_activity;
25 private int m_buttons;
30 public EditPopupMenu(Activity activity,
View layout)
33 m_view =
new EditContextView(activity,
this);
34 m_view.addOnLayoutChangeListener(
this);
39 private void initOverlay()
44 Context
context = m_layout.getContext();
45 m_popup =
new PopupWindow(
context,
null, android.R.attr.textSelectHandleWindowStyle);
46 m_popup.setSplitTouchEnabled(
true);
47 m_popup.setClippingEnabled(
false);
48 m_popup.setContentView(m_view);
49 m_popup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
50 m_popup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
52 m_layout.getViewTreeObserver().addOnPreDrawListener(
this);
56 public void setPosition(
final int x,
final int y,
final int buttons,
61 m_view.updateButtons(buttons);
62 Point viewSize = m_view.getCalculatedSize();
64 final int[] layoutLocation =
new int[2];
65 m_layout.getLocationOnScreen(layoutLocation);
68 final int[] activityLocation =
new int[2];
69 final int[] activityLocationInWindow =
new int[2];
70 m_activity.getWindow().getDecorView().getLocationOnScreen(activityLocation);
71 m_activity.getWindow().getDecorView().getLocationInWindow(activityLocationInWindow);
73 int x2 =
x + layoutLocation[0] - activityLocation[0];
74 int y2 =
y + layoutLocation[1] + (activityLocationInWindow[1] - activityLocation[1]);
76 x2 -= viewSize.x / 2 ;
80 if (cursorHandle !=
null) {
81 y2 = cursorHandle.bottom();
82 }
else if (leftSelectionHandle !=
null && rightSelectionHandle !=
null) {
83 y2 = Math.max(leftSelectionHandle.bottom(), rightSelectionHandle.bottom());
85 m_layout.requestLayout();
89 if (m_layout.getWidth() <
x + viewSize.x / 2)
90 x2 = m_layout.getWidth() - viewSize.x;
95 if (m_popup.isShowing())
96 m_popup.update(
x2,
y2, -1, -1);
98 m_popup.showAtLocation(m_layout, 0,
x2,
y2);
103 m_cursorHandle = cursorHandle;
104 m_leftSelectionHandle = leftSelectionHandle;
105 m_rightSelectionHandle = rightSelectionHandle;
109 if (m_popup !=
null) {
116 public boolean onPreDraw() {
120 if (m_popup !=
null && m_popup.isShowing())
121 setPosition(m_posX, m_posY, m_buttons, m_cursorHandle, m_leftSelectionHandle, m_rightSelectionHandle);
128 int oldLeft,
int oldTop,
int oldRight,
int oldBottom)
131 m_popup !=
null && m_popup.isShowing())
132 setPosition(m_posX, m_posY, m_buttons, m_cursorHandle, m_leftSelectionHandle, m_rightSelectionHandle);
136 public void contextButtonClicked(
int buttonId) {
138 case android.R.string.cut:
139 QtNativeInputConnection.cut();
141 case android.R.string.copy:
142 QtNativeInputConnection.copy();
144 case android.R.string.paste:
145 QtNativeInputConnection.paste();
147 case android.R.string.selectAll:
148 QtNativeInputConnection.selectAll();
Q_CORE_EXPORT QtJniTypes::Activity activity()
Qt::MouseButtons m_buttons
n void setPosition(void) \n\
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLdouble GLdouble GLdouble GLdouble top
GLfixed GLfixed GLfixed y2