Fields Summary |
---|
private static final String | TAG |
private static final boolean | SHOW_AUTOMATIC_ICON |
private static final float | BRIGHTNESS_ADJ_RESOLUTION{@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 final int | mMinimumBacklight |
private final int | mMaximumBacklight |
private final android.content.Context | mContext |
private final android.widget.ImageView | mIcon |
private final ToggleSlider | mControl |
private final boolean | mAutomaticAvailable |
private final android.os.IPowerManager | mPower |
private final CurrentUserTracker | mUserTracker |
private final android.os.Handler | mHandler |
private final BrightnessObserver | mBrightnessObserver |
private ArrayList | mChangeCallbacks |
private boolean | mAutomatic |
private boolean | mListening |
private boolean | mExternalChange |
Methods Summary |
---|
public void | addStateChangedCallback(com.android.systemui.settings.BrightnessController$BrightnessStateChangeCallback cb)
mChangeCallbacks.add(cb);
|
public void | onChanged(ToggleSlider view, boolean tracking, boolean automatic, int value)
updateIcon(mAutomatic);
if (mExternalChange) return;
if (!mAutomatic) {
final int val = value + mMinimumBacklight;
setBrightness(val);
if (!tracking) {
AsyncTask.execute(new Runnable() {
public void run() {
Settings.System.putIntForUser(mContext.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS, val,
UserHandle.USER_CURRENT);
}
});
}
} else {
final float adj = value / (BRIGHTNESS_ADJ_RESOLUTION / 2f) - 1;
setBrightnessAdj(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) {
cb.onBrightnessLevelChanged();
}
|
public void | onInit(ToggleSlider control)
// Do nothing
|
public void | registerCallbacks()
if (mListening) {
return;
}
mBrightnessObserver.startObserving();
mUserTracker.startTracking();
// Update the slider and mode before attaching the listener so we don't
// receive the onChanged notifications for the initial values.
updateMode();
updateSlider();
mControl.setOnChangedListener(this);
mListening = true;
|
public boolean | removeStateChangedCallback(com.android.systemui.settings.BrightnessController$BrightnessStateChangeCallback cb)
return mChangeCallbacks.remove(cb);
|
private void | setBrightness(int brightness)
try {
mPower.setTemporaryScreenBrightnessSettingOverride(brightness);
} catch (RemoteException ex) {
}
|
private void | setBrightnessAdj(float adj)
try {
mPower.setTemporaryScreenAutoBrightnessAdjustmentSettingOverride(adj);
} catch (RemoteException ex) {
}
|
private void | setMode(int mode)
Settings.System.putIntForUser(mContext.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE, mode,
mUserTracker.getCurrentUserId());
|
public void | unregisterCallbacks()Unregister all call backs, both to and from the controller
if (!mListening) {
return;
}
mBrightnessObserver.stopObserving();
mUserTracker.stopTracking();
mControl.setOnChangedListener(null);
mListening = false;
|
private void | updateIcon(boolean automatic)
if (mIcon != null) {
mIcon.setImageResource(automatic && SHOW_AUTOMATIC_ICON ?
com.android.systemui.R.drawable.ic_qs_brightness_auto_on :
com.android.systemui.R.drawable.ic_qs_brightness_auto_off);
}
|
private void | updateMode()Fetch the brightness mode from the system settings and update the icon
if (mAutomaticAvailable) {
int automatic;
automatic = Settings.System.getIntForUser(mContext.getContentResolver(),
Settings.System.SCREEN_BRIGHTNESS_MODE,
Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
UserHandle.USER_CURRENT);
mAutomatic = automatic != Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL;
updateIcon(mAutomatic);
} else {
mControl.setChecked(false);
updateIcon(false /*automatic*/);
}
|
private void | updateSlider()Fetch the brightness from the system settings and update the slider
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, mMaximumBacklight,
UserHandle.USER_CURRENT);
mControl.setMax(mMaximumBacklight - mMinimumBacklight);
mControl.setValue(value - mMinimumBacklight);
}
|