mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 06:05:12 +00:00
Added Triple and Double finger gestures.
For right and middle clicking. REVIEW: 119072
This commit is contained in:
@@ -12,8 +12,7 @@ import org.kde.kdeconnect.BackgroundService;
|
|||||||
import org.kde.kdeconnect.Device;
|
import org.kde.kdeconnect.Device;
|
||||||
import org.kde.kdeconnect_tp.R;
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
public class MousePadActivity extends Activity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
|
public class MousePadActivity extends Activity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener, MousePadGestureDetector.OnGestureListener {
|
||||||
|
|
||||||
private final static float MinDistanceToSendScroll = 2.5f;
|
private final static float MinDistanceToSendScroll = 2.5f;
|
||||||
|
|
||||||
private float mPrevX;
|
private float mPrevX;
|
||||||
@@ -29,12 +28,15 @@ public class MousePadActivity extends Activity implements GestureDetector.OnGest
|
|||||||
|
|
||||||
private GestureDetector mDetector;
|
private GestureDetector mDetector;
|
||||||
|
|
||||||
|
private MousePadGestureDetector mMousePadGestureDetector;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_mousepad);
|
setContentView(R.layout.activity_mousepad);
|
||||||
deviceId = getIntent().getStringExtra("deviceId");
|
deviceId = getIntent().getStringExtra("deviceId");
|
||||||
mDetector = new GestureDetector(this, this);
|
mDetector = new GestureDetector(this, this);
|
||||||
|
mMousePadGestureDetector = new MousePadGestureDetector(this, this);
|
||||||
mDetector.setOnDoubleTapListener(this);
|
mDetector.setOnDoubleTapListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,33 +51,22 @@ public class MousePadActivity extends Activity implements GestureDetector.OnGest
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.menu_right_click:
|
case R.id.menu_right_click:
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
sendRightClick();
|
||||||
@Override
|
return true;
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
|
||||||
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
|
|
||||||
if (mousePadPlugin == null) return;
|
|
||||||
mousePadPlugin.sendRightClick();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case R.id.menu_middle_click:
|
case R.id.menu_middle_click:
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
sendMiddleClick();
|
||||||
@Override
|
return true;
|
||||||
public void onServiceStart(BackgroundService service) {
|
default:
|
||||||
Device device = service.getDevice(deviceId);
|
return super.onOptionsItemSelected(item);
|
||||||
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
|
|
||||||
if (mousePadPlugin == null) return;
|
|
||||||
mousePadPlugin.sendMiddleClick();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
if (mMousePadGestureDetector.onTouchEvent(event)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if ( mDetector.onTouchEvent(event) ) {
|
if ( mDetector.onTouchEvent(event) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -201,4 +192,40 @@ public class MousePadActivity extends Activity implements GestureDetector.OnGest
|
|||||||
public boolean onDoubleTapEvent(MotionEvent e) {
|
public boolean onDoubleTapEvent(MotionEvent e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTripleFingerTap(MotionEvent ev) {
|
||||||
|
sendMiddleClick();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onDoubleFingerTap(MotionEvent ev) {
|
||||||
|
sendRightClick();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMiddleClick() {
|
||||||
|
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
||||||
|
@Override
|
||||||
|
public void onServiceStart(BackgroundService service) {
|
||||||
|
Device device = service.getDevice(deviceId);
|
||||||
|
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
|
||||||
|
if (mousePadPlugin == null) return;
|
||||||
|
mousePadPlugin.sendMiddleClick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendRightClick() {
|
||||||
|
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
||||||
|
@Override
|
||||||
|
public void onServiceStart(BackgroundService service) {
|
||||||
|
Device device = service.getDevice(deviceId);
|
||||||
|
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
|
||||||
|
if (mousePadPlugin == null) return;
|
||||||
|
mousePadPlugin.sendRightClick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,59 @@
|
|||||||
|
package org.kde.kdeconnect.Plugins.MousePadPlugin;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.ViewConfiguration;
|
||||||
|
|
||||||
|
|
||||||
|
public class MousePadGestureDetector {
|
||||||
|
|
||||||
|
private static final int TAP_TIMEOUT = ViewConfiguration.getTapTimeout() + 100;
|
||||||
|
private OnGestureListener mGestureListener;
|
||||||
|
|
||||||
|
private Context mCtx;
|
||||||
|
|
||||||
|
private long mFirstDownTime = 0;
|
||||||
|
|
||||||
|
private boolean mIsGestureHandled;
|
||||||
|
|
||||||
|
public interface OnGestureListener {
|
||||||
|
|
||||||
|
boolean onTripleFingerTap(MotionEvent ev);
|
||||||
|
|
||||||
|
boolean onDoubleFingerTap(MotionEvent ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MousePadGestureDetector(Context ctx, OnGestureListener gestureListener) {
|
||||||
|
if (gestureListener == null) {
|
||||||
|
throw new IllegalArgumentException("gestureListener cannot be null");
|
||||||
|
}
|
||||||
|
mGestureListener = gestureListener;
|
||||||
|
mCtx = ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
int action = event.getAction();
|
||||||
|
switch (action & MotionEvent.ACTION_MASK) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
mIsGestureHandled = false;
|
||||||
|
mFirstDownTime = event.getEventTime();
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_POINTER_UP:
|
||||||
|
int count = event.getPointerCount();
|
||||||
|
if (event.getEventTime() - mFirstDownTime <= TAP_TIMEOUT) {
|
||||||
|
if (count == 3) {
|
||||||
|
if (!mIsGestureHandled) {
|
||||||
|
mIsGestureHandled = mGestureListener.onTripleFingerTap(event);
|
||||||
|
}
|
||||||
|
} else if (count == 2) {
|
||||||
|
if (!mIsGestureHandled) {
|
||||||
|
mIsGestureHandled = mGestureListener.onDoubleFingerTap(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mFirstDownTime = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return mIsGestureHandled;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user