mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-29 05:07:40 +00:00
Merge branch 'kdeconnect-android-mouse_pad_prefs_fix'
This commit is contained in:
commit
c250d2c674
@ -75,6 +75,9 @@
|
|||||||
<string name="mousepad_scroll_direction" translatable="false">mousepad_scroll_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" translatable="false">gyro_mouse_enabled</string>
|
||||||
<string name="mousepad_mouse_buttons_enabled_pref" translatable="false">mouse_buttons_enabled</string>
|
<string name="mousepad_mouse_buttons_enabled_pref" translatable="false">mouse_buttons_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">
|
<string-array name="mousepad_tap_entries">
|
||||||
<item>Left click</item>
|
<item>Left click</item>
|
||||||
<item>Right click</item>
|
<item>Right click</item>
|
||||||
|
@ -61,7 +61,14 @@
|
|||||||
android:id="@+id/gyro_mouse_enabled"
|
android:id="@+id/gyro_mouse_enabled"
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="@string/gyro_mouse_enabled"
|
android:key="@string/gyro_mouse_enabled"
|
||||||
android:title="Gyro mouse" />
|
android:title="@string/gyro_mouse_enabled_title" />
|
||||||
|
|
||||||
|
<SeekBarPreference
|
||||||
|
android:id="@+id/mousepad_gyro_sensitivity"
|
||||||
|
android:defaultValue="100"
|
||||||
|
android:key="@string/gyro_mouse_sensitivity"
|
||||||
|
android:title="@string/gyro_mouse_sensitivity_title"
|
||||||
|
android:layout_width="wrap_content" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:id="@+id/mousepad_mouse_buttons_enabled_pref"
|
android:id="@+id/mousepad_mouse_buttons_enabled_pref"
|
||||||
|
@ -33,7 +33,13 @@ import org.kde.kdeconnect_tp.R;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class MousePadActivity extends AppCompatActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener, MousePadGestureDetector.OnGestureListener, SensorEventListener {
|
public class MousePadActivity
|
||||||
|
extends AppCompatActivity
|
||||||
|
implements GestureDetector.OnGestureListener,
|
||||||
|
GestureDetector.OnDoubleTapListener,
|
||||||
|
MousePadGestureDetector.OnGestureListener,
|
||||||
|
SensorEventListener,
|
||||||
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
private String deviceId;
|
private String deviceId;
|
||||||
|
|
||||||
private final static float MinDistanceToSendScroll = 2.5f; // touch gesture scroll
|
private final static float MinDistanceToSendScroll = 2.5f; // touch gesture scroll
|
||||||
@ -49,6 +55,7 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
private int scrollDirection = 1;
|
private int scrollDirection = 1;
|
||||||
private boolean allowGyro = false;
|
private boolean allowGyro = false;
|
||||||
private boolean gyroEnabled = false;
|
private boolean gyroEnabled = false;
|
||||||
|
private int gyroscopeSensitivity = 100;
|
||||||
private boolean isScrolling = false;
|
private boolean isScrolling = false;
|
||||||
private float accumulatedDistanceY = 0;
|
private float accumulatedDistanceY = 0;
|
||||||
|
|
||||||
@ -63,6 +70,8 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
|
|
||||||
private SharedPreferences prefs = null;
|
private SharedPreferences prefs = null;
|
||||||
|
|
||||||
|
private boolean prefsApplied = false;
|
||||||
|
|
||||||
enum ClickType {
|
enum ClickType {
|
||||||
LEFT, RIGHT, MIDDLE, NONE;
|
LEFT, RIGHT, MIDDLE, NONE;
|
||||||
|
|
||||||
@ -90,27 +99,25 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
public void onSensorChanged(SensorEvent event) {
|
public void onSensorChanged(SensorEvent event) {
|
||||||
float[] values = event.values;
|
float[] values = event.values;
|
||||||
|
|
||||||
float X = -values[2] * 70 * mCurrentSensitivity * displayDpiMultiplier;
|
float X = -values[2] * 70 * (gyroscopeSensitivity/100.0f);
|
||||||
float Y = -values[0] * 70 * mCurrentSensitivity * displayDpiMultiplier;
|
float Y = -values[0] * 70 * (gyroscopeSensitivity/100.0f);
|
||||||
|
|
||||||
if (X < 0.25 && X > -0.25) {
|
if (X < 0.25 && X > -0.25) {
|
||||||
X = 0;
|
X = 0;
|
||||||
} else {
|
} else {
|
||||||
X = X * mCurrentSensitivity * displayDpiMultiplier;
|
X = X * (gyroscopeSensitivity/100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Y < 0.25 && Y > -0.25) {
|
if (Y < 0.25 && Y > -0.25) {
|
||||||
Y = 0;
|
Y = 0;
|
||||||
} else {
|
} else {
|
||||||
Y = Y * mCurrentSensitivity * displayDpiMultiplier;
|
Y = Y * (gyroscopeSensitivity/100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
final float nX = X;
|
final float nX = X;
|
||||||
final float nY = Y;
|
final float nY = Y;
|
||||||
|
|
||||||
BackgroundService.RunWithPlugin(this, deviceId, MousePadPlugin.class, plugin -> {
|
BackgroundService.RunWithPlugin(this, deviceId, MousePadPlugin.class, plugin -> plugin.sendMouseDelta(nX, nY));
|
||||||
plugin.sendMouseDelta(nX, nY);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -123,6 +130,10 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
|
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
|
||||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||||
|
|
||||||
|
findViewById(R.id.mouse_click_left).setOnClickListener(v -> sendLeftClick());
|
||||||
|
findViewById(R.id.mouse_click_middle).setOnClickListener(v -> sendMiddleClick());
|
||||||
|
findViewById(R.id.mouse_click_right).setOnClickListener(v -> sendRightClick());
|
||||||
|
|
||||||
deviceId = getIntent().getStringExtra("deviceId");
|
deviceId = getIntent().getStringExtra("deviceId");
|
||||||
|
|
||||||
getWindow().getDecorView().setHapticFeedbackEnabled(true);
|
getWindow().getDecorView().setHapticFeedbackEnabled(true);
|
||||||
@ -136,57 +147,13 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
keyListenerView.setDeviceId(deviceId);
|
keyListenerView.setDeviceId(deviceId);
|
||||||
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
if (prefs.getBoolean(getString(R.string.mousepad_scroll_direction), false)) {
|
applyPrefs();
|
||||||
scrollDirection = -1;
|
|
||||||
} else {
|
|
||||||
scrollDirection = 1;
|
|
||||||
}
|
|
||||||
if (mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null
|
|
||||||
&& prefs.getBoolean(getString(R.string.gyro_mouse_enabled), false)) {
|
|
||||||
allowGyro = true;
|
|
||||||
}
|
|
||||||
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),
|
|
||||||
getString(R.string.mousepad_default_double));
|
|
||||||
String tripleTapSetting = prefs.getString(getString(R.string.mousepad_triple_tap_key),
|
|
||||||
getString(R.string.mousepad_default_triple));
|
|
||||||
String sensitivitySetting = prefs.getString(getString(R.string.mousepad_sensitivity_key),
|
|
||||||
getString(R.string.mousepad_default_sensitivity));
|
|
||||||
|
|
||||||
String accelerationProfileName = prefs.getString(getString(R.string.mousepad_acceleration_profile_key),
|
|
||||||
getString(R.string.mousepad_default_acceleration_profile));
|
|
||||||
|
|
||||||
mPointerAccelerationProfile = PointerAccelerationProfileFactory.getProfileWithName(accelerationProfileName);
|
|
||||||
|
|
||||||
singleTapAction = ClickType.fromString(singleTapSetting);
|
|
||||||
doubleTapAction = ClickType.fromString(doubleTapSetting);
|
|
||||||
tripleTapAction = ClickType.fromString(tripleTapSetting);
|
|
||||||
|
|
||||||
//Technically xdpi and ydpi should be handled separately,
|
//Technically xdpi and ydpi should be handled separately,
|
||||||
//but since ydpi is usually almost equal to xdpi, only xdpi is used for the multiplier.
|
//but since ydpi is usually almost equal to xdpi, only xdpi is used for the multiplier.
|
||||||
displayDpiMultiplier = StandardDpi / getResources().getDisplayMetrics().xdpi;
|
displayDpiMultiplier = StandardDpi / getResources().getDisplayMetrics().xdpi;
|
||||||
switch (sensitivitySetting) {
|
|
||||||
case "slowest":
|
|
||||||
mCurrentSensitivity = 0.2f;
|
|
||||||
break;
|
|
||||||
case "aboveSlowest":
|
|
||||||
mCurrentSensitivity = 0.5f;
|
|
||||||
break;
|
|
||||||
case "default":
|
|
||||||
mCurrentSensitivity = 1.0f;
|
|
||||||
break;
|
|
||||||
case "aboveDefault":
|
|
||||||
mCurrentSensitivity = 1.5f;
|
|
||||||
break;
|
|
||||||
case "fastest":
|
|
||||||
mCurrentSensitivity = 2.0f;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
mCurrentSensitivity = 1.0f;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final View decorView = getWindow().getDecorView();
|
final View decorView = getWindow().getDecorView();
|
||||||
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
|
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
|
||||||
@ -205,19 +172,13 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
|
applyPrefs();
|
||||||
|
|
||||||
if (allowGyro && !gyroEnabled) {
|
if (allowGyro && !gyroEnabled) {
|
||||||
mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
|
mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
|
||||||
gyroEnabled = true;
|
gyroEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefs.getBoolean(getString(R.string.mousepad_mouse_buttons_enabled_pref), true)) {
|
|
||||||
findViewById(R.id.mouse_buttons).setVisibility(View.VISIBLE);
|
|
||||||
findViewById(R.id.mouse_click_left).setOnClickListener(v -> sendLeftClick());
|
|
||||||
findViewById(R.id.mouse_click_middle).setOnClickListener(v -> sendMiddleClick());
|
|
||||||
findViewById(R.id.mouse_click_right).setOnClickListener(v -> sendRightClick());
|
|
||||||
} else {
|
|
||||||
findViewById(R.id.mouse_buttons).setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
invalidateMenu();
|
invalidateMenu();
|
||||||
|
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@ -232,7 +193,8 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onStop() {
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
if (gyroEnabled) {
|
if (gyroEnabled) {
|
||||||
mSensorManager.unregisterListener(this);
|
mSensorManager.unregisterListener(this);
|
||||||
gyroEnabled = false;
|
gyroEnabled = false;
|
||||||
@ -240,6 +202,12 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
prefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
@ -465,6 +433,11 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
if (prefsApplied) prefsApplied = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void sendLeftClick() {
|
private void sendLeftClick() {
|
||||||
BackgroundService.RunWithPlugin(this, deviceId, MousePadPlugin.class, MousePadPlugin::sendLeftClick);
|
BackgroundService.RunWithPlugin(this, deviceId, MousePadPlugin.class, MousePadPlugin::sendLeftClick);
|
||||||
@ -495,6 +468,70 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void applyPrefs() {
|
||||||
|
if (prefsApplied) return;
|
||||||
|
|
||||||
|
if (prefs.getBoolean(getString(R.string.mousepad_scroll_direction), false)) {
|
||||||
|
scrollDirection = -1;
|
||||||
|
} else {
|
||||||
|
scrollDirection = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
allowGyro = isGyroSensorAvailable() && prefs.getBoolean(getString(R.string.gyro_mouse_enabled), false);
|
||||||
|
if (allowGyro) 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),
|
||||||
|
getString(R.string.mousepad_default_double));
|
||||||
|
String tripleTapSetting = prefs.getString(getString(R.string.mousepad_triple_tap_key),
|
||||||
|
getString(R.string.mousepad_default_triple));
|
||||||
|
String sensitivitySetting = prefs.getString(getString(R.string.mousepad_sensitivity_key),
|
||||||
|
getString(R.string.mousepad_default_sensitivity));
|
||||||
|
|
||||||
|
String accelerationProfileName = prefs.getString(getString(R.string.mousepad_acceleration_profile_key),
|
||||||
|
getString(R.string.mousepad_default_acceleration_profile));
|
||||||
|
|
||||||
|
mPointerAccelerationProfile = PointerAccelerationProfileFactory.getProfileWithName(accelerationProfileName);
|
||||||
|
|
||||||
|
singleTapAction = ClickType.fromString(singleTapSetting);
|
||||||
|
doubleTapAction = ClickType.fromString(doubleTapSetting);
|
||||||
|
tripleTapAction = ClickType.fromString(tripleTapSetting);
|
||||||
|
|
||||||
|
switch (sensitivitySetting) {
|
||||||
|
case "slowest":
|
||||||
|
mCurrentSensitivity = 0.2f;
|
||||||
|
break;
|
||||||
|
case "aboveSlowest":
|
||||||
|
mCurrentSensitivity = 0.5f;
|
||||||
|
break;
|
||||||
|
case "default":
|
||||||
|
mCurrentSensitivity = 1.0f;
|
||||||
|
break;
|
||||||
|
case "aboveDefault":
|
||||||
|
mCurrentSensitivity = 1.5f;
|
||||||
|
break;
|
||||||
|
case "fastest":
|
||||||
|
mCurrentSensitivity = 2.0f;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mCurrentSensitivity = 1.0f;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefs.getBoolean(getString(R.string.mousepad_mouse_buttons_enabled_pref), true)) {
|
||||||
|
findViewById(R.id.mouse_buttons).setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
findViewById(R.id.mouse_buttons).setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
prefsApplied = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isGyroSensorAvailable() {
|
||||||
|
return mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSupportNavigateUp() {
|
public boolean onSupportNavigateUp() {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user