diff options
author | Danny Baumann <dannybaumann@web.de> | 2013-02-14 13:22:58 +0100 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2013-02-15 09:25:13 +0100 |
commit | de94ee593d191dbb8987552382a6ba56921279fc (patch) | |
tree | d26d154ab77748f07a729cd577f8f43ffc2fe8b1 | |
parent | eb7a665c4621999bf2711f16c5a37af35b156546 (diff) | |
download | packages_apps_settings-de94ee593d191dbb8987552382a6ba56921279fc.zip packages_apps_settings-de94ee593d191dbb8987552382a6ba56921279fc.tar.gz packages_apps_settings-de94ee593d191dbb8987552382a6ba56921279fc.tar.bz2 |
Some post-merge cleanup for automatic brightness adjustment
- Remove some unused strings
- Use (device-dependant) minimum brightness level (as calculated by
DisplayPowerController) as '0%' instead of the actual value 0.
Change-Id: I79123d2421c9ab35fa0f1808d82d785463e8fbaa
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/com/android/settings/cyanogenmod/AutoBrightnessCustomizeDialog.java | 35 |
2 files changed, 26 insertions, 11 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml index a6d5c92..c4b5ab0 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -5150,8 +5150,6 @@ <string name="auto_brightness_brightness_format"><xliff:g id="percent">%s</xliff:g>%%</string> <string name="auto_brightness_adjust_button">Adjust</string> <string name="auto_brightness_reset_button">Reset</string> - <string name="auto_brightness_remove_button">Remove</string> - <string name="auto_brightness_add_line">Add line</string> <string name="auto_brightness_lux_dialog_title">Ambient brightness range</string> <string name="auto_brightness_split_dialog_title">Split brightness level</string> <string name="auto_brightness_start_lux">Range start (lux)</string> diff --git a/src/com/android/settings/cyanogenmod/AutoBrightnessCustomizeDialog.java b/src/com/android/settings/cyanogenmod/AutoBrightnessCustomizeDialog.java index f97ecbf..3f93afc 100644 --- a/src/com/android/settings/cyanogenmod/AutoBrightnessCustomizeDialog.java +++ b/src/com/android/settings/cyanogenmod/AutoBrightnessCustomizeDialog.java @@ -56,6 +56,7 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog }; private SettingRowAdapter mAdapter; + private int mMinLevel; private boolean mIsDefault; private SensorEventListener mLightSensorListener = new SensorEventListener() { @@ -92,6 +93,9 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); + PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); + mMinLevel = pm.getMinimumAbsoluteScreenBrightness(); + mSensorLevel = (TextView) view.findViewById(R.id.light_sensor_value); mBrightnessLevel = (TextView) view.findViewById(R.id.current_brightness); @@ -453,6 +457,16 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog mAdapter.notifyDataSetChanged(); } + private int brightnessToProgress(int brightness) { + brightness -= mMinLevel; + return brightness * 100; + } + + private float progressToBrightness(int progress) { + float brightness = (float) progress / 100F; + return brightness + mMinLevel; + } + @Override public View getView(int position, View convertView, ViewGroup parent) { final Holder holder; @@ -466,7 +480,7 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog holder.percent = (TextView) convertView.findViewById(R.id.backlight_percent); convertView.setTag(holder); - holder.backlight.setMax(100 * PowerManager.BRIGHTNESS_ON); + holder.backlight.setMax(brightnessToProgress(PowerManager.BRIGHTNESS_ON)); holder.backlight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { private boolean mIsDragging = false; @@ -481,9 +495,12 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { int pos = (Integer) seekBar.getTag(); if (fromUser) { - int minValue = (pos == 0) ? 0 : getItem(pos - 1).backlight * 100; + int minValue = pos == 0 + ? 0 + : brightnessToProgress(getItem(pos - 1).backlight); int maxValue = isLastItem(pos) - ? seekBar.getMax() : getItem(pos + 1).backlight * 100; + ? seekBar.getMax() + : brightnessToProgress(getItem(pos + 1).backlight); if (progress < minValue) { seekBar.setProgress(minValue); @@ -493,21 +510,21 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog return; } - getItem(pos).backlight = (progress + 50) / 100; + getItem(pos).backlight = Math.round(progressToBrightness(progress)); mIsDefault = false; } if (mIsDragging) { - final float brightness = (float) progress / seekBar.getMax(); - updateBrightness(brightness); + float brightness = progressToBrightness(progress); + updateBrightness(brightness / PowerManager.BRIGHTNESS_ON); } holder.updatePercent(); } @Override public void onStartTrackingTouch(SeekBar seekBar) { - final float brightness = (float) seekBar.getProgress() / seekBar.getMax(); - updateBrightness(brightness); + float brightness = progressToBrightness(seekBar.getProgress()); + updateBrightness(brightness / PowerManager.BRIGHTNESS_ON); mIsDragging = true; } @Override @@ -527,7 +544,7 @@ public class AutoBrightnessCustomizeDialog extends AlertDialog String.valueOf(row.luxFrom), to)); holder.backlight.setTag(position); - holder.backlight.setProgress(100 * row.backlight); + holder.backlight.setProgress(brightnessToProgress(row.backlight)); holder.updatePercent(); return convertView; |