Skip to content

Commit

Permalink
Fix: hide gyro if not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias-Boulay committed Nov 22, 2024
1 parent 383b3ed commit 19afab2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 19afab2

Please sign in to comment.