4package org.qtproject.qt.android;
6import android.content.Context;
7import android.os.Bundle;
8import android.util.DisplayMetrics;
9import android.view.LayoutInflater;
10import android.view.View;
11import android.widget.LinearLayout;
12import android.widget.ImageView;
13import android.content.res.TypedArray;
14import android.graphics.drawable.Drawable;
15import android.view.MotionEvent;
16import android.widget.PopupWindow;
17import android.app.Activity;
18import android.util.TypedValue;
19import android.view.ViewTreeObserver;
22class CursorView
extends ImageView
26 private float m_offsetX;
27 private float m_offsetY;
28 private boolean m_pressed =
false;
36 public void adjusted(
int dx,
int dy) {
42 public boolean onTouchEvent(MotionEvent ev) {
43 switch (ev.getActionMasked()) {
44 case MotionEvent.ACTION_DOWN: {
45 m_offsetX = ev.getRawX();
46 m_offsetY = ev.getRawY() + getHeight() / 2;
51 case MotionEvent.ACTION_MOVE: {
54 mHandle.updatePosition(Math.round(ev.getRawX() - m_offsetX),
55 Math.round(ev.getRawY() - m_offsetY));
59 case MotionEvent.ACTION_UP:
60 case MotionEvent.ACTION_CANCEL:
70public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
72 private View m_layout =
null;
73 private CursorView m_cursorView =
null;
74 private PopupWindow m_popup =
null;
77 private Activity m_activity;
78 private int m_posX = 0;
79 private int m_posY = 0;
83 private boolean m_rtl;
87 m_activity = activity;
91 DisplayMetrics
metrics = activity.getResources().getDisplayMetrics();
92 m_yShift = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 1
f,
metrics);
93 tolerance = Math.min(1, (
int)(m_yShift / 2
f));
94 m_lastX = m_lastY = -1 - tolerance;
98 private boolean initOverlay(){
101 Context
context = m_layout.getContext();
102 int[]
attrs = {m_attr};
103 TypedArray
a =
context.getTheme().obtainStyledAttributes(
attrs);
106 m_cursorView =
new CursorView(
context,
this);
107 m_cursorView.setImageDrawable(drawable);
109 m_popup =
new PopupWindow(
context,
null, android.R.attr.textSelectHandleWindowStyle);
110 m_popup.setSplitTouchEnabled(
true);
111 m_popup.setClippingEnabled(
false);
112 m_popup.setContentView(m_cursorView);
113 m_popup.setWidth(drawable.getIntrinsicWidth());
114 m_popup.setHeight(drawable.getIntrinsicHeight());
116 m_layout.getViewTreeObserver().addOnPreDrawListener(
this);
125 final int[] layoutLocation =
new int[2];
126 m_layout.getLocationOnScreen(layoutLocation);
129 final int[] activityLocation =
new int[2];
130 final int[] activityLocationInWindow =
new int[2];
131 m_activity.getWindow().getDecorView().getLocationOnScreen(activityLocation);
132 m_activity.getWindow().getDecorView().getLocationInWindow(activityLocationInWindow);
134 int x2 =
x + layoutLocation[0] - activityLocation[0];
135 int y2 =
y + layoutLocation[1] + m_yShift + (activityLocationInWindow[1] - activityLocation[1]);
138 x2 -= m_popup.getWidth() / 2 ;
139 }
else if ((m_id ==
QtNative.
IdLeftHandle && !m_rtl) || (m_id == QtNative.IdRightHandle && m_rtl)) {
140 x2 -= m_popup.getWidth() * 3 / 4;
142 x2 -= m_popup.getWidth() / 4;
145 if (m_popup.isShowing()) {
146 m_popup.update(
x2,
y2, -1, -1);
147 m_cursorView.adjusted(
x - m_posX,
y - m_posY);
149 m_popup.showAtLocation(m_layout, 0,
x2,
y2);
160 m_cursorView.getLocationOnScreen(
location);
161 return location[1] + m_cursorView.getHeight();
165 if (m_popup !=
null) {
172 return m_cursorView.getDrawable().getIntrinsicWidth();
178 if (Math.abs(m_lastX -
x) > tolerance || Math.abs(m_lastY -
y) > tolerance) {
190 if (m_popup !=
null && m_popup.isShowing())
void updatePosition(int x, int y)
void setPosition(final int x, final int y)
CursorHandle(Activity activity, View layout, int id, int attr, boolean rtl)
static final int IdCursorHandle
static final int IdLeftHandle
static native void handleLocationChanged(int id, int x, int y)
static struct AttrInfo attrs[]
n void setPosition(void) \n\
GLuint64 GLenum void * handle
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLsizei GLenum const void GLuint GLsizei GLfloat * metrics
GLfixed GLfixed GLfixed y2