Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ffd86711 authored by Cédric Bellegarde's avatar Cédric Bellegarde Committed by Jan Altensen
Browse files

Settings: Add preference for one shot auto-brightness

Change-Id: I57f11ad4e8fc47b2ff2c771e61920780e359815f
parent 38fbd1a7
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2745,6 +2745,9 @@
    <string name="auto_brightness_disclaimer">Optimize brightness level for available light. When this feature is on, you can still adjust brightness temporarily.</string>
    <!-- Description about the feature adaptive brightness -->
    <string name="auto_brightness_description">Your screen brightness will automatically adjust to your environment and activities. You can move the slider manually to help adaptive brightness learn your preferences.</string>
    <!-- One shot automatic Brightness -->
    <string name="auto_brightness_one_shot_title">Only apply when screen is turned on</string>
    <string name="auto_brightness_one_shot_summary">Adjustment will occur one time</string>
    <!-- Display settings screen, display white balance settings title [CHAR LIMIT=30] -->
    <string name="display_white_balance_title">Display white balance</string>
+10 −0
Original line number Diff line number Diff line
@@ -35,6 +35,16 @@
        settings:keywords="@string/keywords_display_auto_brightness"
        settings:controller="com.android.settings.display.AutoBrightnessDetailPreferenceController"
        settings:useAdminDisabledSummary="true"
        settings:userRestriction="no_config_brightness" />

    <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" />

+63 −0
Original line number Diff line number Diff line
/*
 * 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 {

    private final String SYSTEM_KEY = "auto_brightness_one_shot";
    private final int DEFAULT_VALUE = 0;

    public AutoBrightnessOneShotPreferenceController(Context context, String key) {
        super(context, key);
    }

    @Override
    public boolean isChecked() {
        return LineageSettings.System.getInt(mContext.getContentResolver(),
                SYSTEM_KEY, DEFAULT_VALUE) != DEFAULT_VALUE;
    }

    @Override
    public boolean setChecked(boolean isChecked) {
        LineageSettings.System.putInt(mContext.getContentResolver(), SYSTEM_KEY,
                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);
    }
}