这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.view.GestureDetector;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;

Expand All @@ -13,6 +14,8 @@ public interface Listener {

boolean onDoubleTap(MotionEvent e);

boolean onDoubleTapEvent(MotionEvent e);

boolean onScroll(MotionEvent e2, float dx, float dy);

boolean onFling(MotionEvent e, float velocityX, float velocityY);
Expand All @@ -29,7 +32,6 @@ public interface Listener {
private final GestureDetector mGestureDetector;
private final ScaleGestureDetector mScaleDetector;
final Listener mListener;
boolean isAfterLongPress;

public GestureAndScaleRecognizer(Context context, Listener listener) {
mListener = listener;
Expand All @@ -53,13 +55,13 @@ public boolean onDown(MotionEvent e) {
@Override
public void onLongPress(MotionEvent e) {
mListener.onLongPress(e);
isAfterLongPress = true;
}
}, null, true /* ignoreMultitouch */);

mGestureDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
mListener.onUp(e);
return mListener.onSingleTapUp(e);
}

Expand All @@ -70,7 +72,20 @@ public boolean onDoubleTap(MotionEvent e) {

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return true;
// 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)) {
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
mGestureDetector.setIsLongpressEnabled(false);
break;
case MotionEvent.ACTION_UP:
mGestureDetector.setIsLongpressEnabled(true);
break;
}
return mListener.onDoubleTapEvent(e);
}
return false;
}
});

Expand All @@ -85,23 +100,12 @@ public boolean onScale(ScaleGestureDetector detector) {
return mListener.onScale(detector.getFocusX(), detector.getFocusY(), detector.getScaleFactor());
}
});
mScaleDetector.setQuickScaleEnabled(false);
}

public void onTouchEvent(MotionEvent event) {
mGestureDetector.onTouchEvent(event);
mScaleDetector.onTouchEvent(event);
switch (event.getAction()) {
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;
}
}

public boolean isInProgress() {
Expand Down
37 changes: 35 additions & 2 deletions terminal-view/src/main/java/com/termux/view/TerminalView.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,41 @@ public boolean onDown(float x, float y) {

@Override
public boolean onDoubleTap(MotionEvent e) {
// Do not treat is as a single confirmed tap - it may be followed by zoom.
return false;
// Now double tap and drag has been treated as a MOUSE_LEFT_BUTTON_MOVED event.
return true;
}

private float dragStartX, dragStartY;
private boolean dragged;

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
if (mEmulator.isMouseTrackingActive() && !e.isFromSource(InputDevice.SOURCE_MOUSE)) {
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
dragStartX = e.getX();
dragStartY = e.getY();
dragged = false;
sendMouseEventCode(e, TerminalEmulator.MOUSE_LEFT_BUTTON, true);
break;
case MotionEvent.ACTION_UP:
if (!dragged) {
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() - dragStartX) >= mRenderer.mFontWidth || Math.abs(e.getY() - dragStartY) >= mRenderer.mFontLineSpacing) {
dragStartX = e.getX();
dragStartY = e.getY();
dragged = true;
sendMouseEventCode(e, TerminalEmulator.MOUSE_LEFT_BUTTON_MOVED, true);
}
break;
}
}
return true;
}

@Override
Expand Down