SeekBarPreferencepublic class SeekBarPreference extends Preference implements android.widget.SeekBar.OnSeekBarChangeListener
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 int | getProgress()
return mProgress;
| public java.lang.CharSequence | getSummary()
return null;
| protected void | onBindView(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.Object | onGetDefaultValue(android.content.res.TypedArray a, int index)
return a.getInt(index, 0);
| public boolean | onKey(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 void | onProgressChanged(android.widget.SeekBar seekBar, int progress, boolean fromUser)
if (fromUser && !mTrackingTouch) {
syncProgress(seekBar);
}
| protected void | onRestoreInstanceState(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.Parcelable | onSaveInstanceState()
/*
* 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 void | onSetInitialValue(boolean restoreValue, java.lang.Object defaultValue)
setProgress(restoreValue ? getPersistedInt(mProgress)
: (Integer) defaultValue);
| public void | onStartTrackingTouch(android.widget.SeekBar seekBar)
mTrackingTouch = true;
| public void | onStopTrackingTouch(android.widget.SeekBar seekBar)
mTrackingTouch = false;
if (seekBar.getProgress() != mProgress) {
syncProgress(seekBar);
}
| public void | setMax(int max)
if (max != mMax) {
mMax = max;
notifyChanged();
}
| public void | setProgress(int progress)
setProgress(progress, true);
| private void | setProgress(int progress, boolean notifyChanged)
if (progress > mMax) {
progress = mMax;
}
if (progress < 0) {
progress = 0;
}
if (progress != mProgress) {
mProgress = progress;
persistInt(progress);
if (notifyChanged) {
notifyChanged();
}
}
| void | syncProgress(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);
}
}
|
|