summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src
diff options
context:
space:
mode:
authorAdrian Roos <roosa@google.com>2014-05-13 14:55:09 +0200
committerAdrian Roos <roosa@google.com>2014-05-14 10:32:08 +0000
commitdaf7d410fc97647f2b3ab4254f73c09c923018de (patch)
tree04a2c95f9b86673abf53fe4a6275b97cde06b210 /packages/SystemUI/src
parentda86f784b686ba00d9f797b8ee565629669080b9 (diff)
downloadframeworks_base-daf7d410fc97647f2b3ab4254f73c09c923018de.zip
frameworks_base-daf7d410fc97647f2b3ab4254f73c09c923018de.tar.gz
frameworks_base-daf7d410fc97647f2b3ab4254f73c09c923018de.tar.bz2
A better auto brightness
Bug: 14927472 Change-Id: I62d0695b7da16ffa7a27c465c3b6bc4b1515f9c0
Diffstat (limited to 'packages/SystemUI/src')
-rw-r--r--packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java77
1 files changed, 55 insertions, 22 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java b/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
index 1747e6e..c0a07e9 100644
--- a/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
+++ b/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
@@ -28,7 +28,6 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.provider.Settings;
-import android.provider.Settings.SettingNotFoundException;
import android.widget.ImageView;
import java.util.ArrayList;
@@ -36,6 +35,12 @@ import java.util.ArrayList;
public class BrightnessController implements ToggleSlider.Listener {
private static final String TAG = "StatusBar.BrightnessController";
+ /**
+ * {@link android.provider.Settings.System#SCREEN_AUTO_BRIGHTNESS_ADJ} uses the range [-1, 1].
+ * Using this factor, it is converted to [0, BRIGHTNESS_ADJ_RESOLUTION] for the SeekBar.
+ */
+ private static final float BRIGHTNESS_ADJ_RESOLUTION = 100;
+
private final int mMinimumBacklight;
private final int mMaximumBacklight;
@@ -51,6 +56,8 @@ public class BrightnessController implements ToggleSlider.Listener {
private ArrayList<BrightnessStateChangeCallback> mChangeCallbacks =
new ArrayList<BrightnessStateChangeCallback>();
+ private boolean mAutomatic;
+
public interface BrightnessStateChangeCallback {
public void onBrightnessLevelChanged();
}
@@ -62,6 +69,8 @@ public class BrightnessController implements ToggleSlider.Listener {
Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS_MODE);
private final Uri BRIGHTNESS_URI =
Settings.System.getUriFor(Settings.System.SCREEN_BRIGHTNESS);
+ private final Uri BRIGHTNESS_ADJ_URI =
+ Settings.System.getUriFor(Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ);
public BrightnessObserver(Handler handler) {
super(handler);
@@ -77,7 +86,10 @@ public class BrightnessController implements ToggleSlider.Listener {
if (selfChange) return;
if (BRIGHTNESS_MODE_URI.equals(uri)) {
updateMode();
- } else if (BRIGHTNESS_URI.equals(uri)) {
+ updateSlider();
+ } else if (BRIGHTNESS_URI.equals(uri) && !mAutomatic) {
+ updateSlider();
+ } else if (BRIGHTNESS_ADJ_URI.equals(uri) && mAutomatic) {
updateSlider();
} else {
updateMode();
@@ -97,6 +109,9 @@ public class BrightnessController implements ToggleSlider.Listener {
cr.registerContentObserver(
BRIGHTNESS_URI,
false, this, UserHandle.USER_ALL);
+ cr.registerContentObserver(
+ BRIGHTNESS_ADJ_URI,
+ false, this, UserHandle.USER_ALL);
}
public void stopObserving() {
@@ -163,10 +178,8 @@ public class BrightnessController implements ToggleSlider.Listener {
}
public void onChanged(ToggleSlider view, boolean tracking, boolean automatic, int value) {
- setMode(automatic ? Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC
- : Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
- updateIcon(automatic);
- if (!automatic) {
+ updateIcon(mAutomatic);
+ if (!mAutomatic) {
final int val = value + mMinimumBacklight;
setBrightness(val);
if (!tracking) {
@@ -178,6 +191,18 @@ public class BrightnessController implements ToggleSlider.Listener {
}
});
}
+ } else {
+ final float adj = value / (BRIGHTNESS_ADJ_RESOLUTION / 2f) - 1;
+ setBrignessAdj(adj);
+ if (!tracking) {
+ AsyncTask.execute(new Runnable() {
+ public void run() {
+ Settings.System.putFloatForUser(mContext.getContentResolver(),
+ Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, adj,
+ UserHandle.USER_CURRENT);
+ }
+ });
+ }
}
for (BrightnessStateChangeCallback cb : mChangeCallbacks) {
@@ -198,6 +223,13 @@ public class BrightnessController implements ToggleSlider.Listener {
}
}
+ private void setBrignessAdj(float adj) {
+ try {
+ mPower.setTemporaryScreenAutoBrightnessAdjustmentSettingOverride(adj);
+ } catch (RemoteException ex) {
+ }
+ }
+
private void updateIcon(boolean automatic) {
if (mIcon != null) {
mIcon.setImageResource(automatic ?
@@ -210,15 +242,12 @@ public class BrightnessController implements ToggleSlider.Listener {
private void updateMode() {
if (mAutomaticAvailable) {
int automatic;
- try {
- automatic = Settings.System.getIntForUser(mContext.getContentResolver(),
- Settings.System.SCREEN_BRIGHTNESS_MODE,
- UserHandle.USER_CURRENT);
- } catch (SettingNotFoundException snfe) {
- automatic = 0;
- }
- mControl.setChecked(automatic != 0);
- updateIcon(automatic != 0);
+ automatic = Settings.System.getIntForUser(mContext.getContentResolver(),
+ Settings.System.SCREEN_BRIGHTNESS_MODE,
+ Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
+ UserHandle.USER_CURRENT);
+ mAutomatic = automatic != 0;
+ updateIcon(mAutomatic);
} else {
mControl.setChecked(false);
updateIcon(false /*automatic*/);
@@ -227,16 +256,20 @@ public class BrightnessController implements ToggleSlider.Listener {
/** Fetch the brightness from the system settings and update the slider */
private void updateSlider() {
- int value;
- try {
+ if (mAutomatic) {
+ float value = Settings.System.getFloatForUser(mContext.getContentResolver(),
+ Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0,
+ UserHandle.USER_CURRENT);
+ mControl.setMax((int) BRIGHTNESS_ADJ_RESOLUTION);
+ mControl.setValue((int) ((value + 1) * BRIGHTNESS_ADJ_RESOLUTION / 2f));
+ } else {
+ int value;
value = Settings.System.getIntForUser(mContext.getContentResolver(),
- Settings.System.SCREEN_BRIGHTNESS,
+ Settings.System.SCREEN_BRIGHTNESS, mMaximumBacklight,
UserHandle.USER_CURRENT);
- } catch (SettingNotFoundException ex) {
- value = mMaximumBacklight;
+ mControl.setMax(mMaximumBacklight - mMinimumBacklight);
+ mControl.setValue(value - mMinimumBacklight);
}
- mControl.setMax(mMaximumBacklight - mMinimumBacklight);
- mControl.setValue(value - mMinimumBacklight);
}
}