Settings: Add preference for resetting auto brightness adjustment

Change-Id: Iec214a30b1cfe3885b94cfd7c69fe60bc93372a1
Signed-off-by: LibXZR <i@xzr.moe>
This commit is contained in:
LibXZR
2022-06-28 20:01:42 +08:00
committed by Joey
parent 740006bf7c
commit 344fcbbe73
3 changed files with 71 additions and 0 deletions

View File

@@ -360,4 +360,9 @@
<string name="adaptive_playback_timeout_5_min_summary">On (5 minutes)</string>
<string name="adaptive_playback_timeout_10_min">10 minutes</string>
<string name="adaptive_playback_timeout_10_min_summary">On (10 minutes)</string>
<!-- Reset auto brightness adjustment -->
<string name="reset_auto_brightness_adjustment_title">Reset preference</string>
<string name="reset_auto_brightness_adjustment_summary">Let the system forget your brightness preference and reset it to the default one</string>
<string name="reset_auto_brightness_adjustment_done">Auto brightness preference has been reset</string>
</resources>

View File

@@ -43,6 +43,12 @@
settings:userRestriction="no_config_brightness"
settings:allowDividerAbove="true" />
<Preference
android:key="reset_auto_brightness_adjustment"
android:title="@string/reset_auto_brightness_adjustment_title"
android:summary="@string/reset_auto_brightness_adjustment_summary"
settings:controller="com.android.settings.display.ResetAutoBrightnessAdjustmentPreferenceController"/>
<com.android.settingslib.widget.FooterPreference
android:key="auto_brightness_footer"
android:title="@string/auto_brightness_description"

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2022 Project Kaleidoscope
*
* 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 static android.provider.Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ;
import android.content.Context;
import android.provider.Settings;
import android.widget.Toast;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.R;
public class ResetAutoBrightnessAdjustmentPreferenceController extends
BasePreferenceController implements Preference.OnPreferenceClickListener {
public ResetAutoBrightnessAdjustmentPreferenceController(Context context, String key) {
super(context, key);
}
@Override
@AvailabilityStatus
public int getAvailabilityStatus() {
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_automatic_brightness_available)
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
screen.findPreference(getPreferenceKey()).setOnPreferenceClickListener(this);
}
@Override
public boolean onPreferenceClick(Preference preference) {
Settings.System.putFloat(mContext.getContentResolver(), SCREEN_AUTO_BRIGHTNESS_ADJ, 0f);
Toast.makeText(mContext, mContext.getString(
R.string.reset_auto_brightness_adjustment_done),
Toast.LENGTH_SHORT).show();
return true;
}
}