mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 10:45:23 +08:00
Improve motion event handling after long press
When mouse reporting is enabled, do not send mouse events on up after a long press, since that causes e.g. the cursor to move in vim when lifting the finger after long pressing for the menu.
This commit is contained in:
@@ -6,7 +6,7 @@ import android.view.MotionEvent;
|
|||||||
import android.view.ScaleGestureDetector;
|
import android.view.ScaleGestureDetector;
|
||||||
|
|
||||||
/** A combination of {@link GestureDetector} and {@link ScaleGestureDetector}. */
|
/** A combination of {@link GestureDetector} and {@link ScaleGestureDetector}. */
|
||||||
public class GestureAndScaleRecognizer {
|
public final class GestureAndScaleRecognizer {
|
||||||
|
|
||||||
public interface Listener {
|
public interface Listener {
|
||||||
boolean onSingleTapUp(MotionEvent e);
|
boolean onSingleTapUp(MotionEvent e);
|
||||||
@@ -29,6 +29,7 @@ public class GestureAndScaleRecognizer {
|
|||||||
private final GestureDetector mGestureDetector;
|
private final GestureDetector mGestureDetector;
|
||||||
private final ScaleGestureDetector mScaleDetector;
|
private final ScaleGestureDetector mScaleDetector;
|
||||||
final Listener mListener;
|
final Listener mListener;
|
||||||
|
boolean isAfterLongPress;
|
||||||
|
|
||||||
public GestureAndScaleRecognizer(Context context, Listener listener) {
|
public GestureAndScaleRecognizer(Context context, Listener listener) {
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
@@ -52,6 +53,7 @@ public class GestureAndScaleRecognizer {
|
|||||||
@Override
|
@Override
|
||||||
public void onLongPress(MotionEvent e) {
|
public void onLongPress(MotionEvent e) {
|
||||||
mListener.onLongPress(e);
|
mListener.onLongPress(e);
|
||||||
|
isAfterLongPress = true;
|
||||||
}
|
}
|
||||||
}, null, true /* ignoreMultitouch */);
|
}, null, true /* ignoreMultitouch */);
|
||||||
|
|
||||||
@@ -88,8 +90,17 @@ public class GestureAndScaleRecognizer {
|
|||||||
public void onTouchEvent(MotionEvent event) {
|
public void onTouchEvent(MotionEvent event) {
|
||||||
mGestureDetector.onTouchEvent(event);
|
mGestureDetector.onTouchEvent(event);
|
||||||
mScaleDetector.onTouchEvent(event);
|
mScaleDetector.onTouchEvent(event);
|
||||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
switch (event.getAction()) {
|
||||||
mListener.onUp(event);
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
isAfterLongPress = false;
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
if (!isAfterLongPress) {
|
||||||
|
// This behaviour is desired when in e.g. vim with mouse events, where we do not
|
||||||
|
// want to move the cursor when lifting finger after a long press.
|
||||||
|
mListener.onUp(event);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,4 +108,4 @@ public class GestureAndScaleRecognizer {
|
|||||||
return mScaleDetector.isInProgress();
|
return mScaleDetector.isInProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user