diff options
author | Dan Murphy <D.Murphy@motorola.com> | 2009-08-27 15:05:23 -0500 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2009-09-14 21:42:56 -0400 |
commit | a096888f3c7e14723168c323f0ffdb2473adf5d3 (patch) | |
tree | f45604c84dd84f3774d2211f35c595c1570ec028 /src/com/android/settings/BrightnessPreference.java | |
parent | a3aaf19e09806f7e56c59621fc6c17e4429b2e6d (diff) | |
download | packages_apps_Settings-a096888f3c7e14723168c323f0ffdb2473adf5d3.zip packages_apps_Settings-a096888f3c7e14723168c323f0ffdb2473adf5d3.tar.gz packages_apps_Settings-a096888f3c7e14723168c323f0ffdb2473adf5d3.tar.bz2 |
apps/settings: Add auto/manual brightness control to Brightness settings
Add changes to have the ability to turn on and off the
automatic light sensing for the device. This is fully configurable
and is by default not present. Vendors should override the ALS setting
to enable the automatic lighting controls.
These changes will add a check box to the Brightness settings menu to give control
to the user to allow the device's display lighting to be controlled via the slide bar
or the auto lighting system.
If the user selects auto then the slide bar will become invisible. Manual mode
will present the slide bar to the user.
Change-Id: I512c9d5dd72ddd831b33eb8fcd4680e2fc7f786e
Signed-off-by: Dan Murphy <D.Murphy@motorola.com>
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'src/com/android/settings/BrightnessPreference.java')
-rw-r--r-- | src/com/android/settings/BrightnessPreference.java | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/com/android/settings/BrightnessPreference.java b/src/com/android/settings/BrightnessPreference.java index 9f55463..61d3cf9 100644 --- a/src/com/android/settings/BrightnessPreference.java +++ b/src/com/android/settings/BrightnessPreference.java @@ -26,16 +26,22 @@ import android.provider.Settings.SettingNotFoundException; import android.util.AttributeSet; import android.util.Log; import android.view.View; +import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.SeekBar; import java.util.Map; public class BrightnessPreference extends SeekBarPreference implements - SeekBar.OnSeekBarChangeListener { + SeekBar.OnSeekBarChangeListener, CheckBox.OnCheckedChangeListener { private SeekBar mSeekBar; + private CheckBox mCheckBox; private int mOldBrightness; + private int mOldAutomatic; + + private boolean mAutomaticAvailable; // Backlight range is from 0 - 255. Need to make sure that user // doesn't set the backlight to 0 and get stuck @@ -44,6 +50,11 @@ public class BrightnessPreference extends SeekBarPreference implements public BrightnessPreference(Context context, AttributeSet attrs) { super(context, attrs); + + mAutomaticAvailable = context.getResources().getBoolean( + com.android.internal.R.bool.config_automatic_brightness_available); + + setDialogLayoutResource(R.layout.preference_dialog_brightness); } @Override @@ -60,6 +71,20 @@ public class BrightnessPreference extends SeekBarPreference implements mOldBrightness = MAXIMUM_BACKLIGHT; } mSeekBar.setProgress(mOldBrightness - MINIMUM_BACKLIGHT); + + mCheckBox = (CheckBox)view.findViewById(R.id.automatic_mode); + if (mAutomaticAvailable) { + mCheckBox.setOnCheckedChangeListener(this); + try { + mOldAutomatic = Settings.System.getInt(getContext().getContentResolver(), + Settings.System.SCREEN_BRIGHTNESS_MODE); + } catch (SettingNotFoundException snfe) { + mOldAutomatic = 0; + } + mCheckBox.setChecked(mOldAutomatic != 0); + } else { + mCheckBox.setVisibility(View.GONE); + } } public void onProgressChanged(SeekBar seekBar, int progress, @@ -75,6 +100,13 @@ public class BrightnessPreference extends SeekBarPreference implements // NA } + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + setMode(isChecked ? 1 : 0); + if (!isChecked) { + setBrightness(mSeekBar.getProgress() + MINIMUM_BACKLIGHT); + } + } + @Override protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); @@ -83,8 +115,16 @@ public class BrightnessPreference extends SeekBarPreference implements Settings.System.putInt(getContext().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, mSeekBar.getProgress() + MINIMUM_BACKLIGHT); + if (mAutomaticAvailable) { + Settings.System.putInt(getContext().getContentResolver(), + Settings.System.SCREEN_BRIGHTNESS_MODE, + mCheckBox.isChecked() ? 1 : 0); + } } else { setBrightness(mOldBrightness); + if (mAutomaticAvailable) { + setMode(mOldAutomatic); + } } } @@ -99,5 +139,21 @@ public class BrightnessPreference extends SeekBarPreference implements } } + + private void setMode(int automatic) { + if (automatic != 0) { + mSeekBar.setVisibility(View.GONE); + } else { + mSeekBar.setVisibility(View.VISIBLE); + } + try { + IHardwareService hardware = IHardwareService.Stub.asInterface( + ServiceManager.getService("hardware")); + if (hardware != null) { + hardware.setAutoBrightness(automatic != 0); + } + } catch (RemoteException doe) { + } + } } |