Feature: Regard double tap as mouse move event
This commit is contained in:
parent
768f7714ce
commit
80d0034e4c
@ -153,6 +153,10 @@
|
||||
<meta-data
|
||||
android:name="com.sec.android.support.multiwindow"
|
||||
android:value="true" />
|
||||
|
||||
<meta-data
|
||||
android:name="com.lge.support.SPLIT_WINDOW"
|
||||
android:value="true" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -2,6 +2,7 @@ package io.neoterm.frontend.terminal
|
||||
|
||||
import android.content.Context
|
||||
import android.view.GestureDetector
|
||||
import android.view.InputDevice
|
||||
import android.view.MotionEvent
|
||||
import android.view.ScaleGestureDetector
|
||||
|
||||
@ -13,6 +14,10 @@ internal class GestureAndScaleRecognizer(context: Context, val mListener: Listen
|
||||
|
||||
fun onDoubleTap(e: MotionEvent): Boolean
|
||||
|
||||
// For treating double tap as MOUSE_LEFT_BUTTON_MOVED event
|
||||
// e.g in vim, we can change window size with fingers moving.
|
||||
fun onDoubleTapEvent(e: MotionEvent): Boolean
|
||||
|
||||
fun onScroll(e2: MotionEvent, dx: Float, dy: Float): Boolean
|
||||
|
||||
fun onFling(e: MotionEvent, velocityX: Float, velocityY: Float): Boolean
|
||||
@ -53,6 +58,10 @@ internal class GestureAndScaleRecognizer(context: Context, val mListener: Listen
|
||||
|
||||
mGestureDetector.setOnDoubleTapListener(object : GestureDetector.OnDoubleTapListener {
|
||||
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
||||
// For treating double tap as MOUSE_LEFT_BUTTON_MOVED event
|
||||
// e.g in vim, we can change window size with fingers moving.
|
||||
mListener.onUp(e)
|
||||
|
||||
return mListener.onSingleTapUp(e)
|
||||
}
|
||||
|
||||
@ -61,7 +70,21 @@ internal class GestureAndScaleRecognizer(context: Context, val mListener: Listen
|
||||
}
|
||||
|
||||
override fun onDoubleTapEvent(e: MotionEvent): Boolean {
|
||||
return true
|
||||
// For treating double tap as MOUSE_LEFT_BUTTON_MOVED event
|
||||
// e.g in vim, we can change window size with fingers moving.
|
||||
|
||||
// Disable triggering long press which will prevent further double tap motion from
|
||||
// receiving, e.g. when you double tap and drag downwards slowly.
|
||||
if (!e.isFromSource(InputDevice.SOURCE_MOUSE)) {
|
||||
when (e.action) {
|
||||
MotionEvent.ACTION_DOWN ->
|
||||
mGestureDetector.setIsLongpressEnabled(false)
|
||||
MotionEvent.ACTION_UP ->
|
||||
mGestureDetector.setIsLongpressEnabled(true)
|
||||
}
|
||||
return mListener.onDoubleTapEvent(e)
|
||||
}
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
@ -74,19 +97,26 @@ internal class GestureAndScaleRecognizer(context: Context, val mListener: Listen
|
||||
return mListener.onScale(detector.focusX, detector.focusY, detector.scaleFactor)
|
||||
}
|
||||
})
|
||||
|
||||
// For treating double tap as MOUSE_LEFT_BUTTON_MOVED event
|
||||
// e.g in vim, we can change window size with fingers moving.
|
||||
mScaleDetector.isQuickScaleEnabled = false;
|
||||
}
|
||||
|
||||
fun onTouchEvent(event: MotionEvent) {
|
||||
mGestureDetector.onTouchEvent(event)
|
||||
mScaleDetector.onTouchEvent(event)
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> isAfterLongPress = false
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// For treating double tap as MOUSE_LEFT_BUTTON_MOVED event
|
||||
// e.g in vim, we can change window size with fingers moving.
|
||||
// when (event.action) {
|
||||
// MotionEvent.ACTION_DOWN -> isAfterLongPress = false
|
||||
// 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)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
val isInProgress: Boolean
|
||||
|
@ -25,7 +25,6 @@ import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.BaseInputConnection;
|
||||
import android.view.inputmethod.CompletionInfo;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
import android.widget.Scroller;
|
||||
@ -111,7 +110,12 @@ public final class TerminalView extends View {
|
||||
private void commonInit(Context context) {
|
||||
mGestureRecognizer = new GestureAndScaleRecognizer(context, new GestureAndScaleRecognizer.Listener() {
|
||||
|
||||
boolean scrolledWithFinger;
|
||||
private boolean scrolledWithFinger;
|
||||
|
||||
// For treating double tap as MOUSE_LEFT_BUTTON_MOVED event
|
||||
// e.g in vim, we can change window size with fingers moving.
|
||||
private float doubleTapX, doubleTapY;
|
||||
private boolean draggedAfterDoubleTap;
|
||||
|
||||
@Override
|
||||
public boolean onUp(MotionEvent e) {
|
||||
@ -222,8 +226,45 @@ public final class TerminalView extends View {
|
||||
|
||||
@Override
|
||||
public boolean onDoubleTap(MotionEvent e) {
|
||||
// Do not treat is as a single confirmed tap - it may be followed by zoom.
|
||||
return false;
|
||||
// Old behavior: Do not treat is as a single confirmed tap - it may be followed by zoom.
|
||||
|
||||
// For treating double tap as MOUSE_LEFT_BUTTON_MOVED event
|
||||
// e.g in vim, we can change window size with fingers moving.
|
||||
// Now double tap and drag has been treated as a MOUSE_LEFT_BUTTON_MOVED event.
|
||||
return true;
|
||||
}
|
||||
|
||||
// For treating double tap as MOUSE_LEFT_BUTTON_MOVED event
|
||||
// e.g in vim, we can change window size with fingers moving.
|
||||
@Override
|
||||
public boolean onDoubleTapEvent(MotionEvent e) {
|
||||
if (mEmulator.isMouseTrackingActive() && !e.isFromSource(InputDevice.SOURCE_MOUSE)) {
|
||||
switch (e.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
doubleTapX = e.getX();
|
||||
doubleTapY = e.getY();
|
||||
draggedAfterDoubleTap = false;
|
||||
sendMouseEventCode(e, TerminalEmulator.MOUSE_LEFT_BUTTON, true);
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (!draggedAfterDoubleTap) {
|
||||
sendMouseEventCode(e, TerminalEmulator.MOUSE_LEFT_BUTTON, false);
|
||||
sendMouseEventCode(e, TerminalEmulator.MOUSE_LEFT_BUTTON, true);
|
||||
}
|
||||
sendMouseEventCode(e, TerminalEmulator.MOUSE_LEFT_BUTTON, false);
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (Math.abs(e.getX() - doubleTapX) >= mRenderer.mFontWidth
|
||||
|| Math.abs(e.getY() - doubleTapY) >= mRenderer.mFontLineSpacing) {
|
||||
doubleTapX = e.getX();
|
||||
doubleTapY = e.getY();
|
||||
draggedAfterDoubleTap = true;
|
||||
sendMouseEventCode(e, TerminalEmulator.MOUSE_LEFT_BUTTON_MOVED, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user