summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/DisplaySettings.java
diff options
context:
space:
mode:
authorAdrian Roos <roosa@google.com>2014-05-13 17:00:46 +0200
committerAdrian Roos <roosa@google.com>2014-05-14 14:03:35 +0200
commit244e8ce7ab1a893f0e463c270aba111537a1f161 (patch)
tree0a03f18bdfee794e93274679f66706b7ac9244ad /src/com/android/settings/DisplaySettings.java
parent5659e6deed6f171f21038b574f15b5f80204aa62 (diff)
downloadpackages_apps_Settings-244e8ce7ab1a893f0e463c270aba111537a1f161.tar.gz
packages_apps_Settings-244e8ce7ab1a893f0e463c270aba111537a1f161.tar.bz2
packages_apps_Settings-244e8ce7ab1a893f0e463c270aba111537a1f161.zip
A better auto brightness
Bug: 14927472 Change-Id: I122e1218dd0072c979a59bdafd3e0b6f4eec99ab
Diffstat (limited to 'src/com/android/settings/DisplaySettings.java')
-rw-r--r--src/com/android/settings/DisplaySettings.java30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index afe5b6819..3bf7cce16 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -16,6 +16,9 @@
package com.android.settings;
+import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE;
+import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
+import static android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
import android.app.ActivityManagerNative;
@@ -25,7 +28,6 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
-import android.database.ContentObserver;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
@@ -35,7 +37,6 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen;
import android.provider.Settings;
-import android.provider.Settings.SettingNotFoundException;
import android.util.Log;
import java.util.ArrayList;
@@ -50,6 +51,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
private static final String KEY_SCREEN_TIMEOUT = "screen_timeout";
private static final String KEY_FONT_SIZE = "font_size";
private static final String KEY_SCREEN_SAVER = "screensaver";
+ private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness";
private static final int DLG_GLOBAL_CHANGE_WARNING = 1;
@@ -60,6 +62,7 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
private ListPreference mScreenTimeoutPreference;
private Preference mScreenSaverPreference;
+ private CheckBoxPreference mAutoBrightnessPreference;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -86,6 +89,15 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
mFontSizePref = (WarnedListPreference) findPreference(KEY_FONT_SIZE);
mFontSizePref.setOnPreferenceChangeListener(this);
mFontSizePref.setOnPreferenceClickListener(this);
+
+ boolean automaticBrightnessAvailable = getResources().getBoolean(
+ com.android.internal.R.bool.config_automatic_brightness_available);
+ if (automaticBrightnessAvailable) {
+ mAutoBrightnessPreference = (CheckBoxPreference) findPreference(KEY_AUTO_BRIGHTNESS);
+ mAutoBrightnessPreference.setOnPreferenceChangeListener(this);
+ } else {
+ removePreference(KEY_AUTO_BRIGHTNESS);
+ }
}
private void updateTimeoutPreferenceDescription(long currentTimeout) {
@@ -189,7 +201,6 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
@Override
public void onResume() {
super.onResume();
-
updateState();
}
@@ -210,6 +221,13 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
private void updateState() {
readFontSizePreference(mFontSizePref);
updateScreenSaverSummary();
+
+ // Update auto brightness if it is available.
+ if (mAutoBrightnessPreference != null) {
+ int brightnessMode = Settings.System.getInt(getContentResolver(),
+ SCREEN_BRIGHTNESS_MODE, SCREEN_BRIGHTNESS_MODE_MANUAL);
+ mAutoBrightnessPreference.setChecked(brightnessMode != SCREEN_BRIGHTNESS_MODE_MANUAL);
+ }
}
private void updateScreenSaverSummary() {
@@ -248,7 +266,11 @@ public class DisplaySettings extends SettingsPreferenceFragment implements
if (KEY_FONT_SIZE.equals(key)) {
writeFontSizePreference(objValue);
}
-
+ if (preference == mAutoBrightnessPreference) {
+ boolean auto = (Boolean) objValue;
+ Settings.System.putInt(getContentResolver(), SCREEN_BRIGHTNESS_MODE,
+ auto ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : SCREEN_BRIGHTNESS_MODE_MANUAL);
+ }
return true;
}