mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 05:37:43 +00:00
Added Triple and Double finger gestures.
For right and middle clicking. REVIEW: 119072
This commit is contained in:
parent
47790a710a
commit
3b750c78ab
@ -12,8 +12,7 @@ import org.kde.kdeconnect.BackgroundService;
|
||||
import org.kde.kdeconnect.Device;
|
||||
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 float mPrevX;
|
||||
@ -29,12 +28,15 @@ public class MousePadActivity extends Activity implements GestureDetector.OnGest
|
||||
|
||||
private GestureDetector mDetector;
|
||||
|
||||
private MousePadGestureDetector mMousePadGestureDetector;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_mousepad);
|
||||
deviceId = getIntent().getStringExtra("deviceId");
|
||||
mDetector = new GestureDetector(this, this);
|
||||
mMousePadGestureDetector = new MousePadGestureDetector(this, this);
|
||||
mDetector.setOnDoubleTapListener(this);
|
||||
}
|
||||
|
||||
@ -49,33 +51,22 @@ public class MousePadActivity extends Activity implements GestureDetector.OnGest
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_right_click:
|
||||
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();
|
||||
}
|
||||
});
|
||||
break;
|
||||
sendRightClick();
|
||||
return true;
|
||||
case R.id.menu_middle_click:
|
||||
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();
|
||||
}
|
||||
});
|
||||
break;
|
||||
sendMiddleClick();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (mMousePadGestureDetector.onTouchEvent(event)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( mDetector.onTouchEvent(event) ) {
|
||||
return true;
|
||||
}
|
||||
@ -201,4 +192,40 @@ public class MousePadActivity extends Activity implements GestureDetector.OnGest
|
||||
public boolean onDoubleTapEvent(MotionEvent e) {
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user