public BrightnessSlider(Context context) {
    mContext = context;
    mView = View.inflate(mContext, R.layout.brightness_slider, null);

    mControl = (ToggleSlider) mView.findViewById(R.id.brightness);

    mScreenBrightnessDim =
        mContext
            .getResources()
            .getInteger(com.android.internal.R.integer.config_screenBrightnessDim);

    boolean automaticAvailable =
        context
            .getResources()
            .getBoolean(com.android.internal.R.bool.config_automatic_brightness_available);
    mPower = IPowerManager.Stub.asInterface(ServiceManager.getService("power"));

    if (automaticAvailable) {
      int automatic;
      try {
        automatic =
            Settings.System.getInt(
                mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE);
      } catch (SettingNotFoundException snfe) {
        automatic = 0;
      }
      mControl.setChecked(automatic != 0);
    } else {
      mControl.setChecked(false);
      // control.hideToggle();
    }

    int value;
    try {
      value =
          Settings.System.getInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
    } catch (SettingNotFoundException ex) {
      value = MAXIMUM_BACKLIGHT;
    }

    mControl.setMax(MAXIMUM_BACKLIGHT - mScreenBrightnessDim);
    mControl.setValue(value - mScreenBrightnessDim);

    mControl.setOnChangedListener(this);

    SettingsObserver so = new SettingsObserver(new Handler());
    so.observe();
  }
  private void updateValues() {
    int automatic;
    mSystemChange = true;
    try {
      automatic =
          Settings.System.getInt(
              mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE);
      mControl.setChecked(automatic != 0);

      mControl.setValue(
          Settings.System.getInt(mContext.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS));

    } catch (SettingNotFoundException e) {
    }
    mSystemChange = false;
  }