Move selection handles 1mm down
This way the user will not cover with his finger the text with the cursor/selection. Set the tolerance to 0.5mm which is less then the width of the thinnest letters (e.g. i, I, l) Change-Id: Ia5d50bd3f4fe79c89d01b3d7f5e5c22e94e8158b Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
This commit is contained in:
parent
626b33dca1
commit
b1fb4f8261
@ -51,6 +51,7 @@ import android.graphics.drawable.Drawable;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.PopupWindow;
|
||||
import android.app.Activity;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ViewTreeObserver;
|
||||
|
||||
/* This view represents one of the handle (selection or cursor handle) */
|
||||
@ -58,8 +59,8 @@ class CursorView extends ImageView
|
||||
{
|
||||
private CursorHandle mHandle;
|
||||
// The coordinare which where clicked
|
||||
private int m_offsetX;
|
||||
private int m_offsetY;
|
||||
private float m_offsetX;
|
||||
private float m_offsetY;
|
||||
|
||||
CursorView (Context context, CursorHandle handle) {
|
||||
super(context);
|
||||
@ -76,20 +77,18 @@ class CursorView extends ImageView
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
switch (ev.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN: {
|
||||
m_offsetX = Math.round(ev.getRawX());
|
||||
m_offsetY = Math.round(ev.getRawY());
|
||||
m_offsetX = ev.getRawX();
|
||||
m_offsetY = ev.getRawY() + getHeight() / 2;
|
||||
break;
|
||||
}
|
||||
|
||||
case MotionEvent.ACTION_MOVE: {
|
||||
mHandle.updatePosition(Math.round(ev.getRawX()) - m_offsetX,
|
||||
Math.round(ev.getRawY()) - m_offsetY);
|
||||
mHandle.updatePosition(Math.round(ev.getRawX() - m_offsetX),
|
||||
Math.round(ev.getRawY() - m_offsetY));
|
||||
break;
|
||||
}
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
break;
|
||||
}
|
||||
@ -113,6 +112,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
|
||||
private int m_lastY;
|
||||
int tolerance;
|
||||
private boolean m_rtl;
|
||||
int m_yShift;
|
||||
|
||||
public CursorHandle(Activity activity, View layout, int id, int attr, boolean rtl) {
|
||||
m_activity = activity;
|
||||
@ -121,7 +121,8 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
|
||||
m_layout = layout;
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
tolerance = Math.round(2 * metrics.density);
|
||||
m_yShift = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 1f, metrics);
|
||||
tolerance = Math.min(1, (int)(m_yShift / 2f));
|
||||
m_lastX = m_lastY = -1 - tolerance;
|
||||
m_rtl = rtl;
|
||||
}
|
||||
@ -158,7 +159,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
|
||||
m_layout.getLocationOnScreen(location);
|
||||
|
||||
int x2 = x + location[0];
|
||||
int y2 = y + location[1];
|
||||
int y2 = y + location[1] + m_yShift;
|
||||
|
||||
if (m_id == QtNative.IdCursorHandle) {
|
||||
x2 -= m_cursorView.getWidth() / 2 ;
|
||||
@ -187,6 +188,7 @@ public class CursorHandle implements ViewTreeObserver.OnPreDrawListener
|
||||
|
||||
// The handle was dragged by a given relative position
|
||||
public void updatePosition(int x, int y) {
|
||||
y -= m_yShift;
|
||||
if (Math.abs(m_lastX - x) > tolerance || Math.abs(m_lastY - y) > tolerance) {
|
||||
QtNative.handleLocationChanged(m_id, x + m_posX, y + m_posY);
|
||||
m_lastX = x;
|
||||
|
Loading…
x
Reference in New Issue
Block a user