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; 20 21 import android.content.Context; 22 import android.provider.Settings; 23 import android.util.Log; 24 25 import com.android.car.settings.R; 26 import com.android.car.settings.common.SeekbarLineItem; 27 28 /** 29 * A LineItem that displays and sets display brightness. 30 */ 31 class BrightnessLineItem extends SeekbarLineItem { 32 private static final String TAG = "BrightnessLineItem"; 33 private static final int MAX_BRIGHTNESS = 255; 34 35 private final Context mContext; 36 37 public BrightnessLineItem(Context context) { 38 super(context.getText(R.string.brightness)); 39 mContext = context; 40 } 41 42 @Override 43 public int getSeekbarValue() { 44 int currentBrightness = 0; 45 try { 46 currentBrightness = Settings.System.getInt(mContext.getContentResolver(), 47 SCREEN_BRIGHTNESS); 48 } catch (Settings.SettingNotFoundException e) { 49 Log.w(TAG, "Can't find setting for SCREEN_BRIGHTNESS."); 50 } 51 return currentBrightness; 52 } 53 54 @Override 55 public int getMaxSeekbarValue() { 56 return MAX_BRIGHTNESS; 57 } 58 59 @Override 60 public void onSeekbarChanged(int progress) { 61 Settings.System.putInt(mContext.getContentResolver(), SCREEN_BRIGHTNESS, progress); 62 } 63 } 64