5package org.qtproject.qt.android;
7import android.content.Context;
8import android.os.Bundle;
9import android.util.Log;
10import android.view.LayoutInflater;
11import android.view.View;
12import android.widget.LinearLayout;
13import android.widget.ImageView;
14import android.content.res.TypedArray;
15import android.graphics.drawable.Drawable;
16import android.view.MotionEvent;
17import android.widget.PopupWindow;
18import android.app.Activity;
19import android.view.ViewTreeObserver;
20import android.view.View.OnClickListener;
21import android.view.ViewGroup.LayoutParams;
22import android.view.ViewGroup;
26public class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayoutChangeListener,
29 private View m_layout =
null;
31 private PopupWindow m_popup =
null;
32 private Activity m_activity;
35 private int m_buttons;
42 m_activity = activity;
44 m_view.addOnLayoutChangeListener(
this);
49 private void initOverlay()
54 Context
context = m_layout.getContext();
55 m_popup =
new PopupWindow(
context,
null, android.R.attr.textSelectHandleWindowStyle);
56 m_popup.setSplitTouchEnabled(
true);
57 m_popup.setClippingEnabled(
false);
58 m_popup.setContentView(m_view);
59 m_popup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
60 m_popup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
62 m_layout.getViewTreeObserver().addOnPreDrawListener(
this);
72 final int[] layoutLocation =
new int[2];
73 m_layout.getLocationOnScreen(layoutLocation);
76 final int[] activityLocation =
new int[2];
77 final int[] activityLocationInWindow =
new int[2];
78 m_activity.getWindow().getDecorView().getLocationOnScreen(activityLocation);
79 m_activity.getWindow().getDecorView().getLocationInWindow(activityLocationInWindow);
81 int x2 =
x + layoutLocation[0] - activityLocation[0];
82 int y2 =
y + layoutLocation[1] + (activityLocationInWindow[1] - activityLocation[1]);
84 x2 -= m_view.getWidth() / 2 ;
86 y2 -= m_view.getHeight();
88 if (cursorHandle !=
null) {
90 }
else if (leftSelectionHandle !=
null && rightSelectionHandle !=
null) {
91 y2 = Math.max(leftSelectionHandle.
bottom(), rightSelectionHandle.
bottom());
93 m_layout.requestLayout();
97 if (m_layout.getWidth() <
x + m_view.getWidth() / 2)
98 x2 = m_layout.getWidth() - m_view.getWidth();
103 if (m_popup.isShowing())
104 m_popup.update(
x2,
y2, -1, -1);
106 m_popup.showAtLocation(m_layout, 0,
x2,
y2);
111 m_cursorHandle = cursorHandle;
112 m_leftSelectionHandle = leftSelectionHandle;
113 m_rightSelectionHandle = rightSelectionHandle;
117 if (m_popup !=
null) {
128 if (m_popup !=
null && m_popup.isShowing())
129 setPosition(m_posX, m_posY,
m_buttons, m_cursorHandle, m_leftSelectionHandle, m_rightSelectionHandle);
136 int oldLeft,
int oldTop,
int oldRight,
int oldBottom)
139 m_popup !=
null && m_popup.isShowing())
140 setPosition(m_posX, m_posY,
m_buttons, m_cursorHandle, m_leftSelectionHandle, m_rightSelectionHandle);
147 QtNativeInputConnection.cut();
150 QtNativeInputConnection.copy();
153 QtNativeInputConnection.paste();
155 case R.string.selectAll:
156 QtNativeInputConnection.selectAll();
void updateButtons(int buttonsLayout)
EditPopupMenu(Activity activity, View layout)
void contextButtonClicked(int buttonId)
void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom)
void setPosition(final int x, final int y, final int buttons, CursorHandle cursorHandle, CursorHandle leftSelectionHandle, CursorHandle rightSelectionHandle)
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