From 19afab28f4393aec69d6ca77598c026d38556c8e Mon Sep 17 00:00:00 2001 From: Mathias-Boulay Date: Fri, 22 Nov 2024 20:12:57 +0100 Subject: [PATCH] Fix: hide gyro if not supported --- .../src/main/java/net/kdt/pojavlaunch/Tools.java | 7 +++++++ .../pojavlaunch/prefs/QuickSettingSideDialog.java | 13 ++++++++++++- .../screens/LauncherPreferenceControlFragment.java | 3 ++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java index 8800b863ce..e1ab76a1dd 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -19,6 +19,8 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.database.Cursor; +import android.hardware.Sensor; +import android.hardware.SensorManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -1285,4 +1287,9 @@ public static void releaseRenderersCache() { sCompatibleRenderers = null; System.gc(); } + + public static boolean deviceSupportsGyro(@NonNull Context context) { + return ((SensorManager)context.getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null; + + } } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/QuickSettingSideDialog.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/QuickSettingSideDialog.java index 18fd34a2c8..47ebb7a809 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/QuickSettingSideDialog.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/QuickSettingSideDialog.java @@ -48,7 +48,10 @@ public QuickSettingSideDialog(Context context, ViewGroup parent) { @Override protected void onInflate() { bindLayout(); - Tools.runOnUiThread(this::setupListeners); + Tools.runOnUiThread(() -> { + this.setupListeners(); + this.updateGyroCompatibility(); + }); } @Override @@ -187,6 +190,14 @@ private void updateGyroVisibility(boolean isEnabled) { mGyroSensitivityDisplayText.setVisibility(visibility); } + private void updateGyroCompatibility() { + boolean isGyroAvailable = Tools.deviceSupportsGyro(mDialogContent.getContext()); + if (!isGyroAvailable) { + mGyroSwitch.setVisibility(View.GONE); + updateGestureVisibility(false); + } + } + private void updateGestureVisibility(boolean isDisabled) { int visibility = isDisabled ? View.GONE : View.VISIBLE; mGestureDelayBar.setVisibility(visibility); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceControlFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceControlFragment.java index 6f9b5dd095..660f5411c7 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceControlFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceControlFragment.java @@ -9,6 +9,7 @@ import androidx.preference.PreferenceCategory; import net.kdt.pojavlaunch.R; +import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.prefs.CustomSeekBarPreference; import net.kdt.pojavlaunch.prefs.LauncherPreferences; @@ -62,7 +63,7 @@ public void onCreatePreferences(Bundle b, String str) { Context context = getContext(); if(context != null) { - mGyroAvailable = ((SensorManager)context.getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_GYROSCOPE) != null; + mGyroAvailable = Tools.deviceSupportsGyro(context); } PreferenceCategory gyroCategory = requirePreference("gyroCategory", PreferenceCategory.class);