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

Unverified Commit cf1504cb authored by Cédric Bellegarde's avatar Cédric Bellegarde Committed by Michael Bestas
Browse files

Settings: Add preference for one shot auto-brightness

Author: Eamon Powell <eamonpowell@outlook.com>
Date:   Sat Aug 28 13:17:21 2021 +1000

    fixup! Settings: Add preference for one shot auto-brightness

    * Strings belong in cm_strings.xml
    * Fix inconsistent capitalization in comments
    * Fix missing & unnecessary newlines

    Change-Id: I9c2c6b8a68ec921ab69a7d3ee19e907c58533823

Author: Eamon Powell <eamonpowell@outlook.com>
Date:   Thu Aug 26 18:22:15 2021 +1000

    Settings: Adjust one shot auto-brightness strings

    The current strings provided are confusing and lack
    clarity regarding what the feature actually does.

    Change-Id: If87fad1e163131e7b9a070f6866f7d564e368cca

Change-Id: I57f11ad4e8fc47b2ff2c771e61920780e359815f
parent ed998963
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -107,6 +107,10 @@
    <string name="app_notification_sound_timeout_value_15_minutes">10 minutes</string>
    <string name="app_notification_sound_timeout_value_30_minutes">30 minutes</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>
+11 −0
Original line number Diff line number Diff line
@@ -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"
+65 −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 {

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