FileDocCategorySizeDatePackage
SeekBarPreference.javaAPI DocAndroid 5.1 API7820Thu Mar 12 22:22:10 GMT 2015android.preference

SeekBarPreference

public class SeekBarPreference extends Preference implements android.widget.SeekBar.OnSeekBarChangeListener
hide

Fields Summary
private int
mProgress
private int
mMax
private boolean
mTrackingTouch
Constructors Summary
public SeekBarPreference(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)

        super(context, attrs, defStyleAttr, defStyleRes);

        TypedArray a = context.obtainStyledAttributes(
                attrs, com.android.internal.R.styleable.ProgressBar, defStyleAttr, defStyleRes);
        setMax(a.getInt(com.android.internal.R.styleable.ProgressBar_max, mMax));
        a.recycle();

        a = context.obtainStyledAttributes(attrs,
                com.android.internal.R.styleable.SeekBarPreference, defStyleAttr, defStyleRes);
        final int layoutResId = a.getResourceId(
                com.android.internal.R.styleable.SeekBarPreference_layout,
                com.android.internal.R.layout.preference_widget_seekbar);
        a.recycle();

        setLayoutResource(layoutResId);
    
public SeekBarPreference(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)

        this(context, attrs, defStyleAttr, 0);
    
public SeekBarPreference(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, com.android.internal.R.attr.seekBarPreferenceStyle);
    
public SeekBarPreference(android.content.Context context)

        this(context, null);
    
Methods Summary
public intgetProgress()

        return mProgress;
    
public java.lang.CharSequencegetSummary()

        return null;
    
protected voidonBindView(android.view.View view)

        super.onBindView(view);
        SeekBar seekBar = (SeekBar) view.findViewById(
                com.android.internal.R.id.seekbar);
        seekBar.setOnSeekBarChangeListener(this);
        seekBar.setMax(mMax);
        seekBar.setProgress(mProgress);
        seekBar.setEnabled(isEnabled());
    
protected java.lang.ObjectonGetDefaultValue(android.content.res.TypedArray a, int index)

        return a.getInt(index, 0);
    
public booleanonKey(android.view.View v, int keyCode, android.view.KeyEvent event)

        if (event.getAction() != KeyEvent.ACTION_UP) {
            if (keyCode == KeyEvent.KEYCODE_PLUS
                    || keyCode == KeyEvent.KEYCODE_EQUALS) {
                setProgress(getProgress() + 1);
                return true;
            }
            if (keyCode == KeyEvent.KEYCODE_MINUS) {
                setProgress(getProgress() - 1);
                return true;
            }
        }
        return false;
    
public voidonProgressChanged(android.widget.SeekBar seekBar, int progress, boolean fromUser)

        if (fromUser && !mTrackingTouch) {
            syncProgress(seekBar);
        }
    
protected voidonRestoreInstanceState(android.os.Parcelable state)

        if (!state.getClass().equals(SavedState.class)) {
            // Didn't save state for us in onSaveInstanceState
            super.onRestoreInstanceState(state);
            return;
        }

        // Restore the instance state
        SavedState myState = (SavedState) state;
        super.onRestoreInstanceState(myState.getSuperState());
        mProgress = myState.progress;
        mMax = myState.max;
        notifyChanged();
    
protected android.os.ParcelableonSaveInstanceState()

        /*
         * Suppose a client uses this preference type without persisting. We
         * must save the instance state so it is able to, for example, survive
         * orientation changes.
         */

        final Parcelable superState = super.onSaveInstanceState();
        if (isPersistent()) {
            // No need to save instance state since it's persistent
            return superState;
        }

        // Save the instance state
        final SavedState myState = new SavedState(superState);
        myState.progress = mProgress;
        myState.max = mMax;
        return myState;
    
protected voidonSetInitialValue(boolean restoreValue, java.lang.Object defaultValue)

        setProgress(restoreValue ? getPersistedInt(mProgress)
                : (Integer) defaultValue);
    
public voidonStartTrackingTouch(android.widget.SeekBar seekBar)

        mTrackingTouch = true;
    
public voidonStopTrackingTouch(android.widget.SeekBar seekBar)

        mTrackingTouch = false;
        if (seekBar.getProgress() != mProgress) {
            syncProgress(seekBar);
        }
    
public voidsetMax(int max)

        if (max != mMax) {
            mMax = max;
            notifyChanged();
        }
    
public voidsetProgress(int progress)

        setProgress(progress, true);
    
private voidsetProgress(int progress, boolean notifyChanged)

        if (progress > mMax) {
            progress = mMax;
        }
        if (progress < 0) {
            progress = 0;
        }
        if (progress != mProgress) {
            mProgress = progress;
            persistInt(progress);
            if (notifyChanged) {
                notifyChanged();
            }
        }
    
voidsyncProgress(android.widget.SeekBar seekBar)
Persist the seekBar's progress value if callChangeListener returns true, otherwise set the seekBar's progress to the stored value

        int progress = seekBar.getProgress();
        if (progress != mProgress) {
            if (callChangeListener(progress)) {
                setProgress(progress, false);
            } else {
                seekBar.setProgress(mProgress);
            }
        }