Merge "Enable subclass of SeekBarVolumizer to provide a custom file for sample playback." into honeycomb
This commit is contained in:
@ -54,7 +54,7 @@ public class VolumePreference extends SeekBarPreference implements
|
||||
TypedArray a = context.obtainStyledAttributes(attrs,
|
||||
com.android.internal.R.styleable.VolumePreference, 0, 0);
|
||||
mStreamType = a.getInt(android.R.styleable.VolumePreference_streamType, 0);
|
||||
a.recycle();
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
public void setStreamType(int streamType) {
|
||||
@ -249,15 +249,19 @@ public class VolumePreference extends SeekBarPreference implements
|
||||
};
|
||||
|
||||
public SeekBarVolumizer(Context context, SeekBar seekBar, int streamType) {
|
||||
this(context, seekBar, streamType, null);
|
||||
}
|
||||
|
||||
public SeekBarVolumizer(Context context, SeekBar seekBar, int streamType, Uri defaultUri) {
|
||||
mContext = context;
|
||||
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
mStreamType = streamType;
|
||||
mSeekBar = seekBar;
|
||||
|
||||
initSeekBar(seekBar);
|
||||
|
||||
initSeekBar(seekBar, defaultUri);
|
||||
}
|
||||
|
||||
private void initSeekBar(SeekBar seekBar) {
|
||||
private void initSeekBar(SeekBar seekBar, Uri defaultUri) {
|
||||
seekBar.setMax(mAudioManager.getStreamMaxVolume(mStreamType));
|
||||
mOriginalStreamVolume = mAudioManager.getStreamVolume(mStreamType);
|
||||
seekBar.setProgress(mOriginalStreamVolume);
|
||||
@ -266,22 +270,24 @@ public class VolumePreference extends SeekBarPreference implements
|
||||
mContext.getContentResolver().registerContentObserver(
|
||||
System.getUriFor(System.VOLUME_SETTINGS[mStreamType]),
|
||||
false, mVolumeObserver);
|
||||
|
||||
Uri defaultUri = null;
|
||||
if (mStreamType == AudioManager.STREAM_RING) {
|
||||
defaultUri = Settings.System.DEFAULT_RINGTONE_URI;
|
||||
} else if (mStreamType == AudioManager.STREAM_NOTIFICATION) {
|
||||
defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
|
||||
} else {
|
||||
defaultUri = Settings.System.DEFAULT_ALARM_ALERT_URI;
|
||||
|
||||
if (defaultUri == null) {
|
||||
if (mStreamType == AudioManager.STREAM_RING) {
|
||||
defaultUri = Settings.System.DEFAULT_RINGTONE_URI;
|
||||
} else if (mStreamType == AudioManager.STREAM_NOTIFICATION) {
|
||||
defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
|
||||
} else {
|
||||
defaultUri = Settings.System.DEFAULT_ALARM_ALERT_URI;
|
||||
}
|
||||
}
|
||||
|
||||
mRingtone = RingtoneManager.getRingtone(mContext, defaultUri);
|
||||
|
||||
if (mRingtone != null) {
|
||||
mRingtone.setStreamType(mStreamType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void stop() {
|
||||
stopSample();
|
||||
mContext.getContentResolver().unregisterContentObserver(mVolumeObserver);
|
||||
@ -312,18 +318,24 @@ public class VolumePreference extends SeekBarPreference implements
|
||||
}
|
||||
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
if (mRingtone != null && !mRingtone.isPlaying()) {
|
||||
sample();
|
||||
if (!isSamplePlaying()) {
|
||||
startSample();
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
mAudioManager.setStreamVolume(mStreamType, mLastProgress, 0);
|
||||
}
|
||||
|
||||
private void sample() {
|
||||
|
||||
public boolean isSamplePlaying() {
|
||||
return mRingtone != null && mRingtone.isPlaying();
|
||||
}
|
||||
|
||||
public void startSample() {
|
||||
onSampleStarting(this);
|
||||
mRingtone.play();
|
||||
if (mRingtone != null) {
|
||||
mRingtone.play();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopSample() {
|
||||
@ -338,8 +350,8 @@ public class VolumePreference extends SeekBarPreference implements
|
||||
|
||||
public void changeVolumeBy(int amount) {
|
||||
mSeekBar.incrementProgressBy(amount);
|
||||
if (mRingtone != null && !mRingtone.isPlaying()) {
|
||||
sample();
|
||||
if (!isSamplePlaying()) {
|
||||
startSample();
|
||||
}
|
||||
postSetVolume(mSeekBar.getProgress());
|
||||
mVolumeBeforeMute = -1;
|
||||
@ -348,7 +360,7 @@ public class VolumePreference extends SeekBarPreference implements
|
||||
public void muteVolume() {
|
||||
if (mVolumeBeforeMute != -1) {
|
||||
mSeekBar.setProgress(mVolumeBeforeMute);
|
||||
sample();
|
||||
startSample();
|
||||
postSetVolume(mVolumeBeforeMute);
|
||||
mVolumeBeforeMute = -1;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user