2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-22 01:51:47 +00:00

Update MousePadActivity to support doubletap drag

This MR is a continuation of !439 , which changes the default 
behavior of the remote mouse plugin's drag and drop trigger
to be a double-tap to drag, and adds a new SwitchPreference
that toggles between the old (hold to drag) and new behavior.
This commit is contained in:
Mhammad Alloush 2024-08-21 18:52:24 +00:00 committed by Albert Vaca Cintora
parent ab1b1f7ecc
commit 5f18cb571d
3 changed files with 33 additions and 10 deletions

View File

@ -85,6 +85,7 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
<string name="mousepad_scroll_sensitivity_title">Scroll sensitivity</string>
<string name="gyro_mouse_enabled" translatable="false">gyro_mouse_enabled</string>
<string name="mousepad_mouse_buttons_enabled_pref" translatable="false">mouse_buttons_enabled</string>
<string name="mousepad_doubletap_drag_enabled_pref" translatable="false">doubletap_drag_enabled</string>
<string name="gyro_mouse_enabled_title">Enable gyroscope mouse</string>
<string name="gyro_mouse_sensitivity_title">Gyroscope sensitivity</string>
<string name="gyro_mouse_sensitivity" translatable="false">gyro_mouse_sensitivity</string>
@ -513,6 +514,8 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
<string name="send_compose">Send</string>
<string name="compose_send_title">Compose send</string>
<string name="open_compose_send">Compose text</string>
<string name="double_tap_to_drag">Double tap to drag</string>
<string name="hold_to_drag">Hold to drag</string>
<string name="about_kde_about"><![CDATA[
<h1>About</h1>

View File

@ -90,6 +90,15 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
android:key="@string/mousepad_mouse_buttons_enabled_pref"
android:title="@string/mousepad_mouse_buttons_title" />
<SwitchPreference
android:id="@+id/mousepad_double_tap_drag_enabled_pref"
android:defaultValue="true"
android:key="@string/mousepad_doubletap_drag_enabled_pref"
android:title="Drag and drop behavior"
android:summaryOn="@string/double_tap_to_drag"
android:summaryOff="@string/hold_to_drag"
/>
<org.kde.kdeconnect.Helpers.LongSummaryPreferenceCategory
android:key="@string/sendkeystrokes_pref_category"

View File

@ -13,6 +13,7 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.HapticFeedbackConstants;
import android.view.Menu;
@ -55,6 +56,7 @@ public class MousePadActivity
private double scrollCoefficient = 1.0;
private boolean allowGyro = false;
private boolean gyroEnabled = false;
private boolean doubleTapDragEnabled = false;
private int gyroscopeSensitivity = 100;
private boolean isScrolling = false;
private float accumulatedDistanceY = 0;
@ -376,14 +378,16 @@ public class MousePadActivity
@Override
public void onLongPress(MotionEvent e) {
getWindow().getDecorView().performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
if (plugin == null) {
finish();
return;
}
plugin.sendSingleHold();
dragging = true;
if (!doubleTapDragEnabled) {
getWindow().getDecorView().performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
MousePadPlugin plugin = KdeConnect.getInstance().getDevicePlugin(deviceId, MousePadPlugin.class);
if (plugin == null) {
finish();
return;
}
plugin.sendSingleHold();
dragging = true;
}
}
@Override
@ -415,13 +419,18 @@ public class MousePadActivity
finish();
return true;
}
plugin.sendDoubleClick();
if (doubleTapDragEnabled) {
plugin.sendSingleHold();
dragging = true;
} else {
plugin.sendDoubleClick();
}
return true;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
return false;
return true;
}
@Override
@ -578,6 +587,8 @@ public class MousePadActivity
findViewById(R.id.mouse_buttons).setVisibility(View.GONE);
}
doubleTapDragEnabled = prefs.getBoolean(getString(R.string.mousepad_doubletap_drag_enabled_pref), true);
prefsApplied = true;
}