mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 09:58:08 +00:00
Add mouse buttons setting
This commit is contained in:
parent
c22453afca
commit
b52fc8c3ec
11
res/drawable/ic_settings_24dp.xml
Normal file
11
res/drawable/ic_settings_24dp.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<vector
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M555,880L405,880Q390,880 379,870Q368,860 366,845L354,752Q341,747 329.5,740Q318,733 307,725L220,761Q206,766 192,762Q178,758 170,745L96,616Q88,603 91,588Q94,573 106,564L181,507Q180,500 180,493.5Q180,487 180,480Q180,473 180,466.5Q180,460 181,453L106,396Q94,387 91,372Q88,357 96,344L170,215Q177,201 191.5,197.5Q206,194 220,199L307,235Q318,227 330,220Q342,213 354,208L366,115Q368,100 379,90Q390,80 405,80L555,80Q570,80 581,90Q592,100 594,115L606,208Q619,213 630.5,220Q642,227 653,235L740,199Q754,194 768,198Q782,202 790,215L864,344Q872,357 869,372Q866,387 854,396L779,453Q780,460 780,466.5Q780,473 780,480Q780,487 780,493.5Q780,500 778,507L853,564Q865,573 868,588Q871,603 863,616L789,744Q781,757 766.5,761.5Q752,766 738,761L653,725Q642,733 630,740Q618,747 606,752L594,845Q592,860 581,870Q570,880 555,880ZM482,620Q540,620 581,579Q622,538 622,480Q622,422 581,381Q540,340 482,340Q423,340 382.5,381Q342,422 342,480Q342,538 382.5,579Q423,620 482,620Z"/>
|
||||||
|
</vector>
|
10
res/drawable/left_click_48dp.xml
Normal file
10
res/drawable/left_click_48dp.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="48dp"
|
||||||
|
android:height="48dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M468,720Q372,715 306,646Q240,577 240,480Q240,380 310,310Q380,240 480,240Q577,240 646,306Q715,372 720,469L657,449Q646,385 597,342.5Q548,300 480,300Q405,300 352.5,352.5Q300,405 300,480Q300,547 342.5,596.5Q385,646 449,657L468,720ZM821,900L650,729L600,880L480,480L880,600L729,650L900,821L821,900Z"/>
|
||||||
|
</vector>
|
10
res/drawable/right_click_48dp.xml
Normal file
10
res/drawable/right_click_48dp.xml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="48dp"
|
||||||
|
android:height="48dp"
|
||||||
|
android:viewportWidth="960"
|
||||||
|
android:viewportHeight="960"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M492,720L511,657Q575,646 617.5,596.5Q660,547 660,480Q660,405 607.5,352.5Q555,300 480,300Q412,300 363,342.5Q314,385 303,449L240,469Q245,372 314,306Q383,240 480,240Q580,240 650,310Q720,380 720,480Q720,577 654,646Q588,715 492,720ZM139,900L60,821L231,650L80,600L480,480L360,880L310,729L139,900Z"/>
|
||||||
|
</vector>
|
@ -18,15 +18,6 @@
|
|||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
<com.google.android.material.materialswitch.MaterialSwitch
|
|
||||||
android:id="@+id/gyro_mouse_switch"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:textAppearance="?attr/textAppearanceLabelMedium"
|
|
||||||
android:paddingHorizontal="@dimen/activity_horizontal_margin"
|
|
||||||
android:text="Gyro mouse" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@android:style/TextAppearance.Medium"
|
style="@android:style/TextAppearance.Medium"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -39,11 +30,13 @@
|
|||||||
<org.kde.kdeconnect.Plugins.MousePadPlugin.KeyListenerView
|
<org.kde.kdeconnect.Plugins.MousePadPlugin.KeyListenerView
|
||||||
android:id="@+id/keyListener"
|
android:id="@+id/keyListener"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_above="@id/mouse_buttons"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:id="@+id/mouse_buttons"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="68dp"
|
android:layout_height="70dp"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_alignParentBottom="true">
|
android:layout_alignParentBottom="true">
|
||||||
|
|
||||||
@ -52,6 +45,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="3"
|
android:layout_weight="3"
|
||||||
|
app:icon="@drawable/left_click_48dp"
|
||||||
style="@style/KdeConnectButton.IconButton" />
|
style="@style/KdeConnectButton.IconButton" />
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
@ -66,9 +60,9 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="3"
|
android:layout_weight="3"
|
||||||
|
app:icon="@drawable/right_click_48dp"
|
||||||
style="@style/KdeConnectButton.IconButton" />
|
style="@style/KdeConnectButton.IconButton" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@ -6,12 +6,31 @@
|
|||||||
android:id="@+id/menu_show_keyboard"
|
android:id="@+id/menu_show_keyboard"
|
||||||
android:icon="@drawable/ic_action_keyboard_24dp"
|
android:icon="@drawable/ic_action_keyboard_24dp"
|
||||||
android:title="@string/show_keyboard"
|
android:title="@string/show_keyboard"
|
||||||
|
kdeconnect:iconTint="?colorOnBackground"
|
||||||
kdeconnect:showAsAction="ifRoom" />
|
kdeconnect:showAsAction="ifRoom" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_open_compose_send"
|
android:id="@+id/menu_open_compose_send"
|
||||||
android:icon="@drawable/ic_edit_note_24dp"
|
android:icon="@drawable/ic_edit_note_24dp"
|
||||||
android:title="@string/open_compose_send"
|
android:title="@string/open_compose_send"
|
||||||
|
kdeconnect:iconTint="?colorOnBackground"
|
||||||
kdeconnect:showAsAction="ifRoom" />
|
kdeconnect:showAsAction="ifRoom" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_open_mousepad_settings"
|
||||||
|
android:title="@string/device_menu_plugins"
|
||||||
|
android:icon="@drawable/ic_settings_24dp"
|
||||||
|
kdeconnect:iconTint="?colorOnBackground"
|
||||||
|
kdeconnect:showAsAction="ifRoom"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_right_click"
|
||||||
|
android:title="@string/right_click"
|
||||||
|
kdeconnect:showAsAction="never" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_middle_click"
|
||||||
|
android:title="@string/middle_click"
|
||||||
|
kdeconnect:showAsAction="never" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
<string name="mousepad_double_tap_settings_title">Set two finger tap action</string>
|
<string name="mousepad_double_tap_settings_title">Set two finger tap action</string>
|
||||||
<string name="mousepad_triple_tap_settings_title">Set three finger tap action</string>
|
<string name="mousepad_triple_tap_settings_title">Set three finger tap action</string>
|
||||||
<string name="mousepad_sensitivity_settings_title">Set touchpad sensitivity</string>
|
<string name="mousepad_sensitivity_settings_title">Set touchpad sensitivity</string>
|
||||||
|
<string name="mousepad_mouse_buttons_title">Show mouse buttons</string>
|
||||||
<string name="mousepad_acceleration_profile_settings_title">Set pointer acceleration</string>
|
<string name="mousepad_acceleration_profile_settings_title">Set pointer acceleration</string>
|
||||||
<string name="mousepad_single_tap_key" translatable="false">mousepad_single_tap_key</string>
|
<string name="mousepad_single_tap_key" translatable="false">mousepad_single_tap_key</string>
|
||||||
<string name="mousepad_double_tap_key" translatable="false">mousepad_double_tap_key</string>
|
<string name="mousepad_double_tap_key" translatable="false">mousepad_double_tap_key</string>
|
||||||
@ -73,6 +74,7 @@
|
|||||||
<string name="mousepad_scroll_direction_title">Reverse Scrolling Direction</string>
|
<string name="mousepad_scroll_direction_title">Reverse Scrolling Direction</string>
|
||||||
<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-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>
|
||||||
|
@ -63,6 +63,12 @@
|
|||||||
android:key="@string/gyro_mouse_enabled"
|
android:key="@string/gyro_mouse_enabled"
|
||||||
android:title="Gyro mouse" />
|
android:title="Gyro mouse" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:id="@+id/mousepad_mouse_buttons_enabled_pref"
|
||||||
|
android:defaultValue="true"
|
||||||
|
android:key="@string/mousepad_mouse_buttons_enabled_pref"
|
||||||
|
android:title="@string/mousepad_mouse_buttons_title" />
|
||||||
|
|
||||||
|
|
||||||
<org.kde.kdeconnect.Helpers.LongSummaryPreferenceCategory
|
<org.kde.kdeconnect.Helpers.LongSummaryPreferenceCategory
|
||||||
android:key="@string/sendkeystrokes_pref_category"
|
android:key="@string/sendkeystrokes_pref_category"
|
||||||
|
@ -9,7 +9,6 @@ package org.kde.kdeconnect.Plugins.MousePadPlugin;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.view.GestureDetector;
|
import android.view.GestureDetector;
|
||||||
import android.view.HapticFeedbackConstants;
|
import android.view.HapticFeedbackConstants;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -23,13 +22,13 @@ import android.hardware.Sensor;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import com.google.android.material.materialswitch.MaterialSwitch;
|
import androidx.preference.PreferenceManager;
|
||||||
import org.kde.kdeconnect.BackgroundService;
|
import org.kde.kdeconnect.BackgroundService;
|
||||||
|
import org.kde.kdeconnect.UserInterface.PluginSettingsActivity;
|
||||||
import org.kde.kdeconnect_tp.R;
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -62,6 +61,8 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
|
|
||||||
private KeyListenerView keyListenerView;
|
private KeyListenerView keyListenerView;
|
||||||
|
|
||||||
|
private SharedPreferences prefs = null;
|
||||||
|
|
||||||
enum ClickType {
|
enum ClickType {
|
||||||
LEFT, RIGHT, MIDDLE, NONE;
|
LEFT, RIGHT, MIDDLE, NONE;
|
||||||
|
|
||||||
@ -134,23 +135,16 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
keyListenerView = findViewById(R.id.keyListener);
|
keyListenerView = findViewById(R.id.keyListener);
|
||||||
keyListenerView.setDeviceId(deviceId);
|
keyListenerView.setDeviceId(deviceId);
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
if (prefs.getBoolean(getString(R.string.mousepad_scroll_direction), false)) {
|
if (prefs.getBoolean(getString(R.string.mousepad_scroll_direction), false)) {
|
||||||
scrollDirection = -1;
|
scrollDirection = -1;
|
||||||
} else {
|
} else {
|
||||||
scrollDirection = 1;
|
scrollDirection = 1;
|
||||||
}
|
}
|
||||||
boolean isGyroPrefEnabled = prefs.getBoolean(getString(R.string.gyro_mouse_enabled), false);
|
if (mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null
|
||||||
MaterialSwitch gyroSwitch = findViewById(R.id.gyro_mouse_switch);
|
&& prefs.getBoolean(getString(R.string.gyro_mouse_enabled), false)) {
|
||||||
if (mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null) {
|
allowGyro = true;
|
||||||
if (isGyroPrefEnabled) allowGyro = true;
|
|
||||||
gyroSwitch.setChecked(isGyroPrefEnabled);
|
|
||||||
gyroSwitch.setOnCheckedChangeListener((v, checked) -> {
|
|
||||||
setAllowGyro(checked);
|
|
||||||
prefs.edit().putBoolean(getString(R.string.gyro_mouse_enabled), checked).apply();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
gyroSwitch.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
String singleTapSetting = prefs.getString(getString(R.string.mousepad_single_tap_key),
|
String singleTapSetting = prefs.getString(getString(R.string.mousepad_single_tap_key),
|
||||||
getString(R.string.mousepad_default_single));
|
getString(R.string.mousepad_default_single));
|
||||||
@ -194,10 +188,6 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
|
||||||
|
|
||||||
final View decorView = getWindow().getDecorView();
|
final View decorView = getWindow().getDecorView();
|
||||||
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
|
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
|
||||||
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
||||||
@ -219,6 +209,17 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
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();
|
||||||
|
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,13 +244,31 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
MenuInflater inflater = getMenuInflater();
|
MenuInflater inflater = getMenuInflater();
|
||||||
inflater.inflate(R.menu.menu_mousepad, menu);
|
inflater.inflate(R.menu.menu_mousepad, menu);
|
||||||
|
|
||||||
|
boolean mouseButtonsEnabled = prefs
|
||||||
|
.getBoolean(getString(R.string.mousepad_mouse_buttons_enabled_pref), true);
|
||||||
|
menu.findItem(R.id.menu_right_click).setVisible(!mouseButtonsEnabled);
|
||||||
|
menu.findItem(R.id.menu_middle_click).setVisible(!mouseButtonsEnabled);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
if (id == R.id.menu_show_keyboard) {
|
if (id == R.id.menu_right_click) {
|
||||||
|
sendRightClick();
|
||||||
|
return true;
|
||||||
|
} else if (id == R.id.menu_middle_click) {
|
||||||
|
sendMiddleClick();
|
||||||
|
return true;
|
||||||
|
} else if (id == R.id.menu_open_mousepad_settings) {
|
||||||
|
Intent intent = new Intent(this, PluginSettingsActivity.class)
|
||||||
|
.putExtra(PluginSettingsActivity.EXTRA_DEVICE_ID, deviceId)
|
||||||
|
.putExtra(PluginSettingsActivity.EXTRA_PLUGIN_KEY, MousePadPlugin.class.getSimpleName());
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
|
} else if (id == R.id.menu_show_keyboard) {
|
||||||
BackgroundService.RunWithPlugin(this, deviceId, MousePadPlugin.class, plugin -> {
|
BackgroundService.RunWithPlugin(this, deviceId, MousePadPlugin.class, plugin -> {
|
||||||
if (plugin.isKeyboardEnabled()) {
|
if (plugin.isKeyboardEnabled()) {
|
||||||
showKeyboard();
|
showKeyboard();
|
||||||
@ -481,16 +500,5 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAllowGyro(Boolean enabled) {
|
|
||||||
if (allowGyro == enabled) return;
|
|
||||||
if (enabled) {
|
|
||||||
mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
|
|
||||||
} else {
|
|
||||||
mSensorManager.unregisterListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE));
|
|
||||||
}
|
|
||||||
allowGyro = enabled;
|
|
||||||
gyroEnabled = enabled;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user