• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 package com.android.car.settings.quicksettings;
17 
18 import static android.provider.Settings.System.SCREEN_BRIGHTNESS;
19 
20 import android.content.Context;
21 import android.provider.Settings;
22 import android.widget.SeekBar;
23 
24 import com.android.car.settings.common.Logger;
25 
26 /**
27  * A slider to adjust the brightness of the screen
28  */
29 public class BrightnessTile implements QuickSettingGridAdapter.SeekbarTile {
30     private static final Logger LOG = new Logger(BrightnessTile.class);
31     private static final int MAX_BRIGHTNESS = 255;
32     private final Context mContext;
33 
BrightnessTile(Context context)34     public BrightnessTile(Context context) {
35         mContext = context;
36     }
37 
38     @Override
onStartTrackingTouch(SeekBar seekBar)39     public void onStartTrackingTouch(SeekBar seekBar) {
40         // don't care
41     }
42 
43     @Override
onStopTrackingTouch(SeekBar seekBar)44     public void onStopTrackingTouch(SeekBar seekBar) {
45         // don't care
46     }
47 
48     @Override
onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)49     public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
50         Settings.System.putInt(mContext.getContentResolver(), SCREEN_BRIGHTNESS, progress);
51     }
52 
53     @Override
getMax()54     public int getMax() {
55         return MAX_BRIGHTNESS;
56     }
57 
58     @Override
stop()59     public void stop() {
60         // nothing to do.
61     }
62 
63     @Override
getCurrent()64     public int getCurrent() {
65         int currentBrightness = 0;
66         try {
67             currentBrightness = Settings.System.getInt(mContext.getContentResolver(),
68                     SCREEN_BRIGHTNESS);
69         } catch (Settings.SettingNotFoundException e) {
70             LOG.w("Can't find setting for SCREEN_BRIGHTNESS.");
71         }
72         return currentBrightness;
73     }
74 }
75