* commit 'c2543e8f4e6c80ec506a72f96108b672b9fb4049': Fix issue #6603152: User-adjustable autobrightness broken?
This commit is contained in:
@@ -47,6 +47,8 @@ public class BrightnessPreference extends SeekBarDialogPreference implements
|
|||||||
private boolean mAutomaticAvailable;
|
private boolean mAutomaticAvailable;
|
||||||
private boolean mAutomaticMode;
|
private boolean mAutomaticMode;
|
||||||
|
|
||||||
|
private int mCurBrightness = -1;
|
||||||
|
|
||||||
private boolean mRestoredOldState;
|
private boolean mRestoredOldState;
|
||||||
|
|
||||||
// Backlight range is from 0 - 255. Need to make sure that user
|
// Backlight range is from 0 - 255. Need to make sure that user
|
||||||
@@ -60,6 +62,7 @@ public class BrightnessPreference extends SeekBarDialogPreference implements
|
|||||||
private ContentObserver mBrightnessObserver = new ContentObserver(new Handler()) {
|
private ContentObserver mBrightnessObserver = new ContentObserver(new Handler()) {
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange) {
|
public void onChange(boolean selfChange) {
|
||||||
|
mCurBrightness = -1;
|
||||||
onBrightnessChanged();
|
onBrightnessChanged();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -135,6 +138,7 @@ public class BrightnessPreference extends SeekBarDialogPreference implements
|
|||||||
: Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
: Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
|
||||||
mSeekBar.setProgress(getBrightness());
|
mSeekBar.setProgress(getBrightness());
|
||||||
mSeekBar.setEnabled(!mAutomaticMode);
|
mSeekBar.setEnabled(!mAutomaticMode);
|
||||||
|
setBrightness(mSeekBar.getProgress(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getBrightness() {
|
private int getBrightness() {
|
||||||
@@ -145,8 +149,12 @@ public class BrightnessPreference extends SeekBarDialogPreference implements
|
|||||||
Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0);
|
Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ, 0);
|
||||||
brightness = (brightness+1)/2;
|
brightness = (brightness+1)/2;
|
||||||
} else {
|
} else {
|
||||||
brightness = Settings.System.getInt(getContext().getContentResolver(),
|
if (mCurBrightness < 0) {
|
||||||
Settings.System.SCREEN_BRIGHTNESS, 100);
|
brightness = Settings.System.getInt(getContext().getContentResolver(),
|
||||||
|
Settings.System.SCREEN_BRIGHTNESS, 100);
|
||||||
|
} else {
|
||||||
|
brightness = mCurBrightness;
|
||||||
|
}
|
||||||
brightness = (brightness - mScreenBrightnessDim)
|
brightness = (brightness - mScreenBrightnessDim)
|
||||||
/ (MAXIMUM_BACKLIGHT - mScreenBrightnessDim);
|
/ (MAXIMUM_BACKLIGHT - mScreenBrightnessDim);
|
||||||
}
|
}
|
||||||
@@ -199,6 +207,7 @@ public class BrightnessPreference extends SeekBarDialogPreference implements
|
|||||||
}
|
}
|
||||||
setBrightness(mOldBrightness, false);
|
setBrightness(mOldBrightness, false);
|
||||||
mRestoredOldState = true;
|
mRestoredOldState = true;
|
||||||
|
mCurBrightness = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBrightness(int brightness, boolean write) {
|
private void setBrightness(int brightness, boolean write) {
|
||||||
@@ -229,9 +238,12 @@ public class BrightnessPreference extends SeekBarDialogPreference implements
|
|||||||
power.setBacklightBrightness(brightness);
|
power.setBacklightBrightness(brightness);
|
||||||
}
|
}
|
||||||
if (write) {
|
if (write) {
|
||||||
|
mCurBrightness = -1;
|
||||||
final ContentResolver resolver = getContext().getContentResolver();
|
final ContentResolver resolver = getContext().getContentResolver();
|
||||||
Settings.System.putInt(resolver,
|
Settings.System.putInt(resolver,
|
||||||
Settings.System.SCREEN_BRIGHTNESS, brightness);
|
Settings.System.SCREEN_BRIGHTNESS, brightness);
|
||||||
|
} else {
|
||||||
|
mCurBrightness = brightness;
|
||||||
}
|
}
|
||||||
} catch (RemoteException doe) {
|
} catch (RemoteException doe) {
|
||||||
}
|
}
|
||||||
@@ -255,6 +267,7 @@ public class BrightnessPreference extends SeekBarDialogPreference implements
|
|||||||
myState.progress = mSeekBar.getProgress();
|
myState.progress = mSeekBar.getProgress();
|
||||||
myState.oldAutomatic = mOldAutomatic == 1;
|
myState.oldAutomatic = mOldAutomatic == 1;
|
||||||
myState.oldProgress = mOldBrightness;
|
myState.oldProgress = mOldBrightness;
|
||||||
|
myState.curBrightness = mCurBrightness;
|
||||||
|
|
||||||
// Restore the old state when the activity or dialog is being paused
|
// Restore the old state when the activity or dialog is being paused
|
||||||
restoreOldState();
|
restoreOldState();
|
||||||
@@ -275,6 +288,7 @@ public class BrightnessPreference extends SeekBarDialogPreference implements
|
|||||||
mOldAutomatic = myState.oldAutomatic ? 1 : 0;
|
mOldAutomatic = myState.oldAutomatic ? 1 : 0;
|
||||||
setMode(myState.automatic ? 1 : 0);
|
setMode(myState.automatic ? 1 : 0);
|
||||||
setBrightness(myState.progress, false);
|
setBrightness(myState.progress, false);
|
||||||
|
mCurBrightness = myState.curBrightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SavedState extends BaseSavedState {
|
private static class SavedState extends BaseSavedState {
|
||||||
@@ -283,6 +297,7 @@ public class BrightnessPreference extends SeekBarDialogPreference implements
|
|||||||
boolean oldAutomatic;
|
boolean oldAutomatic;
|
||||||
int progress;
|
int progress;
|
||||||
int oldProgress;
|
int oldProgress;
|
||||||
|
int curBrightness;
|
||||||
|
|
||||||
public SavedState(Parcel source) {
|
public SavedState(Parcel source) {
|
||||||
super(source);
|
super(source);
|
||||||
@@ -290,6 +305,7 @@ public class BrightnessPreference extends SeekBarDialogPreference implements
|
|||||||
progress = source.readInt();
|
progress = source.readInt();
|
||||||
oldAutomatic = source.readInt() == 1;
|
oldAutomatic = source.readInt() == 1;
|
||||||
oldProgress = source.readInt();
|
oldProgress = source.readInt();
|
||||||
|
curBrightness = source.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -299,6 +315,7 @@ public class BrightnessPreference extends SeekBarDialogPreference implements
|
|||||||
dest.writeInt(progress);
|
dest.writeInt(progress);
|
||||||
dest.writeInt(oldAutomatic ? 1 : 0);
|
dest.writeInt(oldAutomatic ? 1 : 0);
|
||||||
dest.writeInt(oldProgress);
|
dest.writeInt(oldProgress);
|
||||||
|
dest.writeInt(curBrightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SavedState(Parcelable superState) {
|
public SavedState(Parcelable superState) {
|
||||||
|
Reference in New Issue
Block a user