Code example for SeekBar

Methods: getProgresssetVisibility

0
 
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        setBrightnessMode(isChecked ? Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC
                : Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
        if (!isChecked) {
            setBrightness(mSeekBar.getProgress()); // + mScreenBrightnessDim);
        } 
    } 
 
    private int getBrightness(int defaultValue) {
        return this.brightness;
    } 
 
    public int getBrightnessMode(int defaultValue) {
        return this.brightnessMode;
    } 
 
    @Override 
    protected void onDialogClosed(boolean positiveResult) {
        super.onDialogClosed(positiveResult);
 
        if (positiveResult) {
        	// Settings are already set 
        	//this.setBrightness(mSeekBar.getProgress()); 
        	//this.setBrightnessMode(mCheckBox.isChecked() ? Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC : Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); 
        	 
        	// Persist 
        	this.savePreference();
        } else { 
            restoreOldState(); 
        } 
    } 
 
    private void restoreOldState() { 
        if (mRestoredOldState) return;
 
        if (mAutomaticAvailable) {
            setBrightnessMode(mOldAutomatic);
        } 
        if (!mAutomaticAvailable || mOldAutomatic == 0) {
            setBrightness(mOldBrightness);
        } 
        mRestoredOldState = true;
    } 
 
    public void setBrightness(int brightness) {
    	this.brightness = brightness;
    } 
     
    /** 
     * Save brightness mode and brightness to single string preference. 
     */ 
    private void savePreference() { 
    	String setting = String.format("%s:%s", this.getBrightnessMode(0), this.getBrightness());
    	if (callChangeListener(setting)) {
    		persistString(setting);
    	} 
	} 
 
    /** 
     * Load brightness mode and brightness from preference. 
     * @throws InvalidPreferencesFormatException 
     */ 
    private void loadPreference() throws InvalidPreferencesFormatException { 
    	String current = getPersistedString(Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL + ":255");
    	 
    	this.setBrightnessMode(getBrightnessMode(current));
    	this.setBrightness(getBrightness(current));
	} 
 
    /** 
     * Get brightness from preference string. 
     * @param preference 
     * @return 
     * @throws InvalidPreferencesFormatException 
     */ 
    public static int getBrightness(String preference) throws InvalidPreferencesFormatException {
    	String[] values = preference.split(":");
    	if (values.length != 2) {
    		throw new InvalidPreferencesFormatException(preference);
    	} 
    	 
    	return Integer.parseInt(values[1]);
    } 
 
    /** 
     * Get brightness mode from preference string. 
     * @param preference 
     * @return 
     * @throws InvalidPreferencesFormatException 
     */ 
    public static int getBrightnessMode(String preference) throws InvalidPreferencesFormatException {
    	String[] values = preference.split(":");
    	if (values.length != 2) {
    		throw new InvalidPreferencesFormatException(preference);
    	} 
    	 
    	return Integer.parseInt(values[0]);
    } 
     
	public int getBrightness() { 
    	return this.brightness;
    } 
 
    public void setBrightnessMode(int mode) {
        if (mode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
            mSeekBar.setVisibility(View.GONE);
        } else { 
            mSeekBar.setVisibility(View.VISIBLE);
        } 
        this.brightnessMode = mode;
    }