MotoActions: Don't show preference for non existing sensor
authorMichael W <baddaemon87@gmail.com>
Tue, 29 Dec 2020 17:33:35 +0000 (18:33 +0100)
committerMichael W <baddaemon87@gmail.com>
Tue, 29 Dec 2020 17:33:35 +0000 (18:33 +0100)
* Looks like some variants don't have a CameraActivationSensor, so let's
  remove the preference as the user's choice won't have an effect anyway

Change-Id: I7d157a992a6cb9ee333752772bc5e3b647b614f2

MotoActions/src/org/lineageos/settings/device/ActionsPreferenceFragment.java
MotoActions/src/org/lineageos/settings/device/actions/CameraActivationSensor.java

index 8a75fc25fb4f471e670794cec503b88d2619e38b..38cf260557909d035e790485609699fbb530bf95 100644 (file)
@@ -20,20 +20,31 @@ package org.lineageos.settings.device;
 import android.app.ActionBar;
 import android.os.Bundle;
 import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
 import androidx.preference.PreferenceFragment;
 import androidx.preference.SwitchPreference;
 import android.text.TextUtils;
 import android.view.MenuItem;
 
+import org.lineageos.settings.device.actions.CameraActivationSensor;
+
 import java.io.File;
 
 public class ActionsPreferenceFragment extends PreferenceFragment {
 
+    private final String KEY_ACTIONS_CATEGORY = "actions_key";
+    private final String KEY_GESTURE_CAMERA_ACTION = "gesture_camera_action";
+
     @Override
     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
         addPreferencesFromResource(R.xml.actions_panel);
         final ActionBar actionBar = getActivity().getActionBar();
         actionBar.setDisplayHomeAsUpEnabled(true);
+
+        if (!CameraActivationSensor.hasSensor(getContext())) {
+            PreferenceCategory category = findPreference(KEY_ACTIONS_CATEGORY);
+            category.removePreferenceRecursively(KEY_GESTURE_CAMERA_ACTION);
+        }
     }
 
     @Override
index 4c0199a1d72a2020d14df3a8e76d66d789911f58..2d8062b98739f511dc4f8c77e5d45a879e3d3191 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2015 The CyanogenMod Project
- * Copyright (c) 2017 The LineageOS Project
+ * Copyright (c) 2017-2020 The LineageOS Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ package org.lineageos.settings.device.actions;
 
 import java.util.List;
 
+import android.content.Context;
 import android.hardware.Sensor;
 import android.hardware.SensorEvent;
 import android.hardware.SensorEventListener;
@@ -67,4 +68,9 @@ public class CameraActivationSensor implements SensorEventListener, UpdatedState
     @Override
     public void onAccuracyChanged(Sensor sensor, int accuracy) {
     }
+
+    public static boolean hasSensor(Context context) {
+        SensorHelper sensorHelper = new SensorHelper(context);
+        return sensorHelper.getCameraActivationSensor() != null;
+    }
 }