VolumePreferencepublic class VolumePreference extends SeekBarDialogPreference implements PreferenceManager.OnActivityStopListener, View.OnKeyListener, SeekBarVolumizer.Callback
Fields Summary |
---|
static final String | TAG | private int | mStreamType | private SeekBarVolumizer | mSeekBarVolumizerMay be null if the dialog isn't visible. |
Constructors Summary |
---|
public VolumePreference(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)
super(context, attrs, defStyleAttr, defStyleRes);
final TypedArray a = context.obtainStyledAttributes(attrs,
com.android.internal.R.styleable.VolumePreference, defStyleAttr, defStyleRes);
mStreamType = a.getInt(android.R.styleable.VolumePreference_streamType, 0);
a.recycle();
| public VolumePreference(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)
this(context, attrs, defStyleAttr, 0);
| public VolumePreference(android.content.Context context, android.util.AttributeSet attrs)
this(context, attrs, com.android.internal.R.attr.dialogPreferenceStyle);
|
Methods Summary |
---|
private void | cleanup()Do clean up. This can be called multiple times!
getPreferenceManager().unregisterOnActivityStopListener(this);
if (mSeekBarVolumizer != null) {
Dialog dialog = getDialog();
if (dialog != null && dialog.isShowing()) {
View view = dialog.getWindow().getDecorView()
.findViewById(com.android.internal.R.id.seekbar);
if (view != null) view.setOnKeyListener(null);
// Stopped while dialog was showing, revert changes
mSeekBarVolumizer.revertVolume();
}
mSeekBarVolumizer.stop();
mSeekBarVolumizer = null;
}
| public void | onActivityStop()
if (mSeekBarVolumizer != null) {
mSeekBarVolumizer.stopSample();
}
| protected void | onBindDialogView(android.view.View view)
super.onBindDialogView(view);
final SeekBar seekBar = (SeekBar) view.findViewById(com.android.internal.R.id.seekbar);
mSeekBarVolumizer = new SeekBarVolumizer(getContext(), mStreamType, null, this);
mSeekBarVolumizer.start();
mSeekBarVolumizer.setSeekBar(seekBar);
getPreferenceManager().registerOnActivityStopListener(this);
// grab focus and key events so that pressing the volume buttons in the
// dialog doesn't also show the normal volume adjust toast.
view.setOnKeyListener(this);
view.setFocusableInTouchMode(true);
view.requestFocus();
| protected void | onDialogClosed(boolean positiveResult)
super.onDialogClosed(positiveResult);
if (!positiveResult && mSeekBarVolumizer != null) {
mSeekBarVolumizer.revertVolume();
}
cleanup();
| public boolean | onKey(android.view.View v, int keyCode, android.view.KeyEvent event)
// If key arrives immediately after the activity has been cleaned up.
if (mSeekBarVolumizer == null) return true;
boolean isdown = (event.getAction() == KeyEvent.ACTION_DOWN);
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (isdown) {
mSeekBarVolumizer.changeVolumeBy(-1);
}
return true;
case KeyEvent.KEYCODE_VOLUME_UP:
if (isdown) {
mSeekBarVolumizer.changeVolumeBy(1);
}
return true;
case KeyEvent.KEYCODE_VOLUME_MUTE:
if (isdown) {
mSeekBarVolumizer.muteVolume();
}
return true;
default:
return false;
}
| public void | onMuted(boolean muted)
// noop
| public void | onProgressChanged(android.widget.SeekBar seekBar, int progress, boolean fromTouch)
// noop
| protected void | onRestoreInstanceState(android.os.Parcelable state)
if (state == null || !state.getClass().equals(SavedState.class)) {
// Didn't save state for us in onSaveInstanceState
super.onRestoreInstanceState(state);
return;
}
SavedState myState = (SavedState) state;
super.onRestoreInstanceState(myState.getSuperState());
if (mSeekBarVolumizer != null) {
mSeekBarVolumizer.onRestoreInstanceState(myState.getVolumeStore());
}
| public void | onSampleStarting(SeekBarVolumizer volumizer)
if (mSeekBarVolumizer != null && volumizer != mSeekBarVolumizer) {
mSeekBarVolumizer.stopSample();
}
| protected android.os.Parcelable | onSaveInstanceState()
final Parcelable superState = super.onSaveInstanceState();
if (isPersistent()) {
// No need to save instance state since it's persistent
return superState;
}
final SavedState myState = new SavedState(superState);
if (mSeekBarVolumizer != null) {
mSeekBarVolumizer.onSaveInstanceState(myState.getVolumeStore());
}
return myState;
| public void | setStreamType(int streamType)
mStreamType = streamType;
|
|