mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 14:15:14 +00:00
Add separate sensitivity for gyroscope in plugin MousePad
This commit is contained in:
@@ -73,6 +73,9 @@
|
||||
<string name="mousepad_scroll_direction_title">Reverse Scrolling Direction</string>
|
||||
<string name="mousepad_scroll_direction" translatable="false">mousepad_scroll_direction</string>
|
||||
<string name="gyro_mouse_enabled" translatable="false">gyro_mouse_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>
|
||||
<string-array name="mousepad_tap_entries">
|
||||
<item>Left click</item>
|
||||
<item>Right click</item>
|
||||
|
@@ -1,89 +1,96 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:keep="@xml/mousepadplugin_preferences">
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:keep="@xml/mousepadplugin_preferences">
|
||||
|
||||
<ListPreference
|
||||
android:id="@+id/mousepad_single_tap_preference"
|
||||
android:defaultValue="@string/mousepad_default_single"
|
||||
android:entries="@array/mousepad_tap_entries"
|
||||
android:entryValues="@array/mousepad_tap_values"
|
||||
android:key="@string/mousepad_single_tap_key"
|
||||
android:summary="%s"
|
||||
android:title="@string/mousepad_single_tap_settings_title" />
|
||||
android:id="@+id/mousepad_single_tap_preference"
|
||||
android:defaultValue="@string/mousepad_default_single"
|
||||
android:entries="@array/mousepad_tap_entries"
|
||||
android:entryValues="@array/mousepad_tap_values"
|
||||
android:key="@string/mousepad_single_tap_key"
|
||||
android:summary="%s"
|
||||
android:title="@string/mousepad_single_tap_settings_title" />
|
||||
|
||||
<ListPreference
|
||||
android:id="@+id/mousepad_double_tap_preference"
|
||||
android:defaultValue="@string/mousepad_default_double"
|
||||
android:entries="@array/mousepad_tap_entries"
|
||||
android:entryValues="@array/mousepad_tap_values"
|
||||
android:key="@string/mousepad_double_tap_key"
|
||||
android:summary="%s"
|
||||
android:title="@string/mousepad_double_tap_settings_title" />
|
||||
android:id="@+id/mousepad_double_tap_preference"
|
||||
android:defaultValue="@string/mousepad_default_double"
|
||||
android:entries="@array/mousepad_tap_entries"
|
||||
android:entryValues="@array/mousepad_tap_values"
|
||||
android:key="@string/mousepad_double_tap_key"
|
||||
android:summary="%s"
|
||||
android:title="@string/mousepad_double_tap_settings_title" />
|
||||
|
||||
<ListPreference
|
||||
android:id="@+id/mousepad_triple_tap_preference"
|
||||
android:defaultValue="@string/mousepad_default_triple"
|
||||
android:entries="@array/mousepad_tap_entries"
|
||||
android:entryValues="@array/mousepad_tap_values"
|
||||
android:key="@string/mousepad_triple_tap_key"
|
||||
android:summary="%s"
|
||||
android:title="@string/mousepad_triple_tap_settings_title" />
|
||||
android:id="@+id/mousepad_triple_tap_preference"
|
||||
android:defaultValue="@string/mousepad_default_triple"
|
||||
android:entries="@array/mousepad_tap_entries"
|
||||
android:entryValues="@array/mousepad_tap_values"
|
||||
android:key="@string/mousepad_triple_tap_key"
|
||||
android:summary="%s"
|
||||
android:title="@string/mousepad_triple_tap_settings_title" />
|
||||
|
||||
<ListPreference
|
||||
android:id="@+id/mousepad_sensitivity_preference"
|
||||
android:defaultValue="@string/mousepad_default_sensitivity"
|
||||
android:entries="@array/mousepad_sensitivity_entries"
|
||||
android:entryValues="@array/mousepad_sensitivity_values"
|
||||
android:key="@string/mousepad_sensitivity_key"
|
||||
android:summary="%s"
|
||||
android:title="@string/mousepad_sensitivity_settings_title" />
|
||||
android:id="@+id/mousepad_sensitivity_preference"
|
||||
android:defaultValue="@string/mousepad_default_sensitivity"
|
||||
android:entries="@array/mousepad_sensitivity_entries"
|
||||
android:entryValues="@array/mousepad_sensitivity_values"
|
||||
android:key="@string/mousepad_sensitivity_key"
|
||||
android:summary="%s"
|
||||
android:title="@string/mousepad_sensitivity_settings_title" />
|
||||
|
||||
<ListPreference
|
||||
android:id="@+id/mousepad_acceleration_profile_preference"
|
||||
android:defaultValue="@string/mousepad_default_acceleration_profile"
|
||||
android:entries="@array/mousepad_acceleration_profile_entries"
|
||||
android:entryValues="@array/mousepad_acceleration_profile_values"
|
||||
android:key="@string/mousepad_acceleration_profile_key"
|
||||
android:summary="%s"
|
||||
android:title="@string/mousepad_acceleration_profile_settings_title" />
|
||||
android:id="@+id/mousepad_acceleration_profile_preference"
|
||||
android:defaultValue="@string/mousepad_default_acceleration_profile"
|
||||
android:entries="@array/mousepad_acceleration_profile_entries"
|
||||
android:entryValues="@array/mousepad_acceleration_profile_values"
|
||||
android:key="@string/mousepad_acceleration_profile_key"
|
||||
android:summary="%s"
|
||||
android:title="@string/mousepad_acceleration_profile_settings_title" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:id="@+id/mousepad_scroll_preference"
|
||||
android:defaultValue="false"
|
||||
android:key="@string/mousepad_scroll_direction"
|
||||
android:title="@string/mousepad_scroll_direction_title" />
|
||||
android:id="@+id/mousepad_scroll_preference"
|
||||
android:defaultValue="false"
|
||||
android:key="@string/mousepad_scroll_direction"
|
||||
android:title="@string/mousepad_scroll_direction_title" />
|
||||
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:id="@+id/gyro_mouse_enabled"
|
||||
android:defaultValue="false"
|
||||
android:key="@string/gyro_mouse_enabled"
|
||||
android:title="Gyro mouse" />
|
||||
android:id="@+id/gyro_mouse_enabled"
|
||||
android:defaultValue="false"
|
||||
android:key="@string/gyro_mouse_enabled"
|
||||
android:title="@string/gyro_mouse_enabled_title"/>
|
||||
|
||||
<SeekBarPreference
|
||||
android:id="@+id/mousepad_gyro_sensitivity"
|
||||
android:defaultValue="false"
|
||||
android:key="@string/gyro_mouse_sensitivity"
|
||||
android:title="@string/gyro_mouse_sensitivity_title" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
|
||||
<org.kde.kdeconnect.Helpers.LongSummaryPreferenceCategory
|
||||
android:key="@string/sendkeystrokes_pref_category"
|
||||
android:summary="@string/sendkeystrokes_pref_category_summary"
|
||||
android:title="@string/sendkeystrokes_pref_category_title">
|
||||
android:key="@string/sendkeystrokes_pref_category"
|
||||
android:summary="@string/sendkeystrokes_pref_category_summary"
|
||||
android:title="@string/sendkeystrokes_pref_category_title">
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:id="@+id/pref_keystrokes_enable"
|
||||
android:defaultValue="true"
|
||||
android:key="@string/pref_sendkeystrokes_enabled"
|
||||
android:title="@string/sendkeystrokes_pref_enabled"
|
||||
android:summary="@string/sendkeystrokes_pref_enabled_summary"
|
||||
/>
|
||||
android:id="@+id/pref_keystrokes_enable"
|
||||
android:defaultValue="true"
|
||||
android:key="@string/pref_sendkeystrokes_enabled"
|
||||
android:title="@string/sendkeystrokes_pref_enabled"
|
||||
android:summary="@string/sendkeystrokes_pref_enabled_summary"
|
||||
/>
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:id="@+id/pref_send_safe_text_immediately"
|
||||
android:defaultValue="true"
|
||||
android:key="@string/pref_send_safe_text_immediately"
|
||||
android:title="@string/sendkeystrokes_safe_text_enabled"
|
||||
android:summary="@string/sendkeystrokes_safe_text_enabled_summary"
|
||||
/>
|
||||
android:id="@+id/pref_send_safe_text_immediately"
|
||||
android:defaultValue="true"
|
||||
android:key="@string/pref_send_safe_text_immediately"
|
||||
android:title="@string/sendkeystrokes_safe_text_enabled"
|
||||
android:summary="@string/sendkeystrokes_safe_text_enabled_summary"
|
||||
/>
|
||||
|
||||
</org.kde.kdeconnect.Helpers.LongSummaryPreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
@@ -50,6 +50,7 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
||||
private int scrollDirection = 1;
|
||||
private boolean allowGyro = false;
|
||||
private boolean gyroEnabled = false;
|
||||
private int gyroscopeSensitivity = 100;
|
||||
private boolean isScrolling = false;
|
||||
private float accumulatedDistanceY = 0;
|
||||
|
||||
@@ -89,26 +90,26 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
float[] values = event.values;
|
||||
|
||||
float X = -values[2] * 70 * mCurrentSensitivity * displayDpiMultiplier;
|
||||
float Y = -values[0] * 70 * mCurrentSensitivity * displayDpiMultiplier;
|
||||
float X = -values[2] * 70 * (gyroscopeSensitivity/100.0f);
|
||||
float Y = -values[0] * 70 * (gyroscopeSensitivity/100.0f);
|
||||
|
||||
if (X < 0.25 && X > -0.25) {
|
||||
X = 0;
|
||||
} else {
|
||||
X = X * mCurrentSensitivity * displayDpiMultiplier;
|
||||
X = X * (gyroscopeSensitivity/100.0f);
|
||||
}
|
||||
|
||||
if (Y < 0.25 && Y > -0.25) {
|
||||
Y = 0;
|
||||
} else {
|
||||
Y = Y * mCurrentSensitivity * displayDpiMultiplier;
|
||||
Y = Y * (gyroscopeSensitivity/100.0f);
|
||||
}
|
||||
|
||||
final float nX = X;
|
||||
final float nY = Y;
|
||||
|
||||
BackgroundService.RunWithPlugin(this, deviceId, MousePadPlugin.class, plugin -> {
|
||||
plugin.sendMouseDelta(nX, nY);
|
||||
plugin.sendMouseDelta(nX, nY);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -143,7 +144,9 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
||||
}
|
||||
if ((prefs.getBoolean(getString(R.string.gyro_mouse_enabled), false)) && (mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null)) {
|
||||
allowGyro = true;
|
||||
gyroscopeSensitivity = prefs.getInt(getString(R.string.gyro_mouse_sensitivity),100);
|
||||
}
|
||||
|
||||
String singleTapSetting = prefs.getString(getString(R.string.mousepad_single_tap_key),
|
||||
getString(R.string.mousepad_default_single));
|
||||
String doubleTapSetting = prefs.getString(getString(R.string.mousepad_double_tap_key),
|
||||
@@ -476,4 +479,3 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user