mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 21:55:10 +00:00
Add gyro switch and mouse buttons
This commit is contained in:
committed by
Albert Vaca Cintora
parent
81fe7adba5
commit
c22453afca
@@ -18,6 +18,15 @@
|
||||
android:orientation="vertical"
|
||||
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
|
||||
style="@android:style/TextAppearance.Medium"
|
||||
android:layout_width="match_parent"
|
||||
@@ -27,12 +36,39 @@
|
||||
android:padding="12dip"
|
||||
android:text="@string/mousepad_info" />
|
||||
|
||||
<view
|
||||
<org.kde.kdeconnect.Plugins.MousePadPlugin.KeyListenerView
|
||||
android:id="@+id/keyListener"
|
||||
class="org.kde.kdeconnect.Plugins.MousePadPlugin.KeyListenerView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="68dp"
|
||||
android:orientation="horizontal"
|
||||
android:layout_alignParentBottom="true">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/mouse_click_left"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="3"
|
||||
style="@style/KdeConnectButton.IconButton" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/mouse_click_middle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
style="@style/KdeConnectButton.IconButton.Secondary" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/mouse_click_right"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="3"
|
||||
style="@style/KdeConnectButton.IconButton" />
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
@@ -13,14 +13,5 @@
|
||||
android:icon="@drawable/ic_edit_note_24dp"
|
||||
android:title="@string/open_compose_send"
|
||||
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>
|
||||
|
@@ -28,8 +28,8 @@ import java.util.List;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.google.android.material.materialswitch.MaterialSwitch;
|
||||
import org.kde.kdeconnect.BackgroundService;
|
||||
import org.kde.kdeconnect.UserInterface.ThemeUtil;
|
||||
import org.kde.kdeconnect_tp.R;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -140,8 +140,17 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
||||
} else {
|
||||
scrollDirection = 1;
|
||||
}
|
||||
if ((prefs.getBoolean(getString(R.string.gyro_mouse_enabled), false)) && (mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null)) {
|
||||
allowGyro = true;
|
||||
boolean isGyroPrefEnabled = prefs.getBoolean(getString(R.string.gyro_mouse_enabled), false);
|
||||
MaterialSwitch gyroSwitch = findViewById(R.id.gyro_mouse_switch);
|
||||
if (mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null) {
|
||||
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),
|
||||
getString(R.string.mousepad_default_single));
|
||||
@@ -185,6 +194,10 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
||||
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();
|
||||
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
|
||||
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
||||
@@ -202,7 +215,7 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
if (allowGyro == true && gyroEnabled == false) {
|
||||
if (allowGyro && !gyroEnabled) {
|
||||
mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
|
||||
gyroEnabled = true;
|
||||
}
|
||||
@@ -211,7 +224,7 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
if (gyroEnabled == true) {
|
||||
if (gyroEnabled) {
|
||||
mSensorManager.unregisterListener(this);
|
||||
gyroEnabled = false;
|
||||
}
|
||||
@@ -219,7 +232,7 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
||||
}
|
||||
|
||||
@Override protected void onStop() {
|
||||
if (gyroEnabled == true) {
|
||||
if (gyroEnabled) {
|
||||
mSensorManager.unregisterListener(this);
|
||||
gyroEnabled = false;
|
||||
}
|
||||
@@ -236,13 +249,7 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
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_show_keyboard) {
|
||||
if (id == R.id.menu_show_keyboard) {
|
||||
BackgroundService.RunWithPlugin(this, deviceId, MousePadPlugin.class, plugin -> {
|
||||
if (plugin.isKeyboardEnabled()) {
|
||||
showKeyboard();
|
||||
@@ -474,5 +481,16 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
||||
super.onBackPressed();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user