MotoActions: Don't show preference for non existing sensor

* 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
This commit is contained in:
Michael W 2020-12-29 18:33:35 +01:00
parent 9ccc54c3d2
commit 3cffd7470f
2 changed files with 18 additions and 1 deletions

View 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

View 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;
}
}