Settings: Add preference for one shot auto-brightness

Co-authored-by: Eamon Powell <eamonpowell@outlook.com>
Change-Id: I57f11ad4e8fc47b2ff2c771e61920780e359815f
This commit is contained in:
Cédric Bellegarde 2021-05-14 00:57:09 +02:00 committed by Michael Bestas
parent 43cd6795ab
commit 9b58b0c001
No known key found for this signature in database
3 changed files with 80 additions and 0 deletions

View file

@ -96,6 +96,10 @@
<string name="show_navbar_hint_title">Navigation hint</string>
<string name="show_navbar_hint_summary">Show navigation hint bar at the bottom of the screen</string>
<!-- One shot automatic brightness -->
<string name="auto_brightness_one_shot_title">One shot auto-brightness</string>
<string name="auto_brightness_one_shot_summary">Brightness adjustment will only occur at the moment the screen is turned on</string>
<!-- Per-app data restrictions -->
<string name="data_usage_app_restrict_all">Allow network access</string>
<string name="data_usage_app_restrict_all_summary">Enable network usage</string>

View file

@ -32,6 +32,17 @@
settings:userRestriction="no_config_brightness"
settings:controller="com.android.settings.display.AutoBrightnessDetailPreferenceController"/>
<com.android.settingslib.RestrictedSwitchPreference
android:key="auto_brightness_one_shot"
android:title="@string/auto_brightness_one_shot_title"
android:summary="@string/auto_brightness_one_shot_summary"
android:dependency="auto_brightness"
settings:keywords="@string/keywords_display_auto_brightness"
settings:controller="com.android.settings.display.AutoBrightnessOneShotPreferenceController"
settings:useAdminDisabledSummary="true"
settings:userRestriction="no_config_brightness"
settings:allowDividerAbove="true" />
<com.android.settingslib.widget.FooterPreference
android:key="auto_brightness_footer"
android:title="@string/auto_brightness_description"

View file

@ -0,0 +1,65 @@
/*
* Copyright (C) 2021 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.display;
import android.content.Context;
import lineageos.providers.LineageSettings;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class AutoBrightnessOneShotPreferenceController extends TogglePreferenceController {
public AutoBrightnessOneShotPreferenceController(Context context, String key) {
super(context, key);
}
@Override
public boolean isChecked() {
return LineageSettings.System.getInt(mContext.getContentResolver(),
LineageSettings.System.AUTO_BRIGHTNESS_ONE_SHOT, 0) == 1;
}
@Override
public boolean setChecked(boolean isChecked) {
LineageSettings.System.putInt(mContext.getContentResolver(),
LineageSettings.System.AUTO_BRIGHTNESS_ONE_SHOT, isChecked ? 1 : 0);
return true;
}
@Override
@AvailabilityStatus
public int getAvailabilityStatus() {
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_automatic_brightness_available)
? AVAILABLE_UNSEARCHABLE
: UNSUPPORTED_ON_DEVICE;
}
@Override
public CharSequence getSummary() {
return mContext.getText(isChecked()
? R.string.auto_brightness_summary_on
: R.string.auto_brightness_summary_off);
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_display;
}
}