1 /* 2 * Copyright (C) 2017 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.car.settings.display; 18 19 import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE; 20 import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC; 21 import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL; 22 23 import android.content.Context; 24 import android.provider.Settings; 25 import android.support.v7.widget.RecyclerView; 26 27 import com.android.car.settings.R; 28 29 import com.android.car.settings.common.ToggleLineItem; 30 31 /** 32 * A LineItem that displays and sets display auto brightness setting. 33 */ 34 class AutoBrightnessLineItem extends ToggleLineItem { 35 private final Context mContext; 36 37 public AutoBrightnessLineItem(Context context) { 38 super(context.getText(R.string.auto_brightness_title)); 39 mContext = context; 40 } 41 42 @Override 43 public void onClick(boolean isChecked) { 44 Settings.System.putInt(mContext.getContentResolver(), SCREEN_BRIGHTNESS_MODE, 45 isChecked ? SCREEN_BRIGHTNESS_MODE_MANUAL : SCREEN_BRIGHTNESS_MODE_AUTOMATIC); 46 } 47 48 @Override 49 public boolean isChecked() { 50 int brightnessMode = Settings.System.getInt(mContext.getContentResolver(), 51 SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL); 52 return brightnessMode != SCREEN_BRIGHTNESS_MODE_MANUAL; 53 } 54 55 @Override 56 public CharSequence getDesc() { 57 return mContext.getText(R.string.auto_brightness_summary); 58 } 59 60 @Override 61 public void bindViewHolder(ToggleLineItemViewHolder holder) { 62 super.bindViewHolder(holder); 63 holder.itemView.setEnabled(isEnabled()); 64 } 65 66 public boolean isEnabled() { 67 return mContext.getResources().getBoolean( 68 com.android.internal.R.bool.config_automatic_brightness_available); 69 } 70 } 71