1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.settings.display; 18 19 import android.content.Context; 20 import android.widget.CompoundButton; 21 import android.widget.CompoundButton.OnCheckedChangeListener; 22 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.widget.SettingsMainSwitchPreference; 26 27 /** 28 * Controller that updates the adaptive brightness. 29 */ 30 public class AutoBrightnessDetailPreferenceController extends 31 AutoBrightnessPreferenceController implements OnCheckedChangeListener { 32 AutoBrightnessDetailPreferenceController(Context context, String key)33 public AutoBrightnessDetailPreferenceController(Context context, String key) { 34 super(context, key); 35 } 36 37 @Override 38 @AvailabilityStatus getAvailabilityStatus()39 public int getAvailabilityStatus() { 40 return mContext.getResources().getBoolean( 41 com.android.internal.R.bool.config_automatic_brightness_available) 42 ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 43 } 44 45 @Override isPublicSlice()46 public boolean isPublicSlice() { 47 return true; 48 } 49 50 @Override displayPreference(PreferenceScreen screen)51 public void displayPreference(PreferenceScreen screen) { 52 super.displayPreference(screen); 53 54 SettingsMainSwitchPreference pref = (SettingsMainSwitchPreference) screen.findPreference( 55 getPreferenceKey()); 56 pref.addOnSwitchChangeListener(this); 57 pref.setChecked(isChecked()); 58 } 59 60 @Override onCheckedChanged(CompoundButton buttonView, boolean isChecked)61 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 62 if (isChecked != isChecked()) { 63 setChecked(isChecked); 64 } 65 } 66 } 67