• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
AutoBrightnessLineItem(Context context)37     public AutoBrightnessLineItem(Context context) {
38         super(context.getText(R.string.auto_brightness_title));
39         mContext = context;
40     }
41 
42     @Override
onClick(boolean isChecked)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
isChecked()49     public boolean isChecked() {
50         if (!isEnabled()) {
51             return false;
52         }
53         int brightnessMode = Settings.System.getInt(mContext.getContentResolver(),
54                 SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);
55         return brightnessMode != SCREEN_BRIGHTNESS_MODE_MANUAL;
56     }
57 
58     @Override
getDesc()59     public CharSequence getDesc() {
60         return mContext.getText(R.string.auto_brightness_summary);
61     }
62 
63     @Override
bindViewHolder(ToggleLineItemViewHolder holder)64     public void bindViewHolder(ToggleLineItemViewHolder holder) {
65         super.bindViewHolder(holder);
66         boolean enabled = isEnabled();
67         holder.titleView.setEnabled(enabled);
68         holder.descView.setEnabled(enabled);
69         holder.toggle.setEnabled(enabled);
70         holder.itemView.setEnabled(enabled);
71     }
72 
73     @Override
isEnabled()74     public boolean isEnabled() {
75         return mContext.getResources().getBoolean(
76                 com.android.internal.R.bool.config_automatic_brightness_available);
77     }
78 
79     @Override
isExpandable()80     public boolean isExpandable() {
81         return false;
82     }
83 }
84