Methods Summary |
---|
public void | changeVolumeBy(int amount)
mSeekBar.incrementProgressBy(amount);
postSetVolume(mSeekBar.getProgress());
postStartSample();
mVolumeBeforeMute = -1;
|
public android.widget.SeekBar | getSeekBar()
return mSeekBar;
|
public boolean | handleMessage(android.os.Message msg)
switch (msg.what) {
case MSG_SET_STREAM_VOLUME:
mAudioManager.setStreamVolume(mStreamType, mLastProgress,
AudioManager.FLAG_SHOW_UI_WARNINGS);
break;
case MSG_START_SAMPLE:
onStartSample();
break;
case MSG_STOP_SAMPLE:
onStopSample();
break;
case MSG_INIT_SAMPLE:
onInitSample();
break;
default:
Log.e(TAG, "invalid SeekBarVolumizer message: "+msg.what);
}
return true;
|
private static boolean | isNotificationOrRing(int stream)
return stream == AudioManager.STREAM_RING || stream == AudioManager.STREAM_NOTIFICATION;
|
public boolean | isSamplePlaying()
return mRingtone != null && mRingtone.isPlaying();
|
public void | muteVolume()
if (mVolumeBeforeMute != -1) {
mSeekBar.setProgress(mVolumeBeforeMute);
postSetVolume(mVolumeBeforeMute);
postStartSample();
mVolumeBeforeMute = -1;
} else {
mVolumeBeforeMute = mSeekBar.getProgress();
mSeekBar.setProgress(0);
postStopSample();
postSetVolume(0);
}
|
private void | onInitSample()
mRingtone = RingtoneManager.getRingtone(mContext, mDefaultUri);
if (mRingtone != null) {
mRingtone.setStreamType(mStreamType);
}
|
public void | onProgressChanged(android.widget.SeekBar seekBar, int progress, boolean fromTouch)
if (fromTouch) {
postSetVolume(progress);
}
if (mCallback != null) {
mCallback.onProgressChanged(seekBar, progress, fromTouch);
}
|
public void | onRestoreInstanceState(android.preference.VolumePreference.VolumeStore volumeStore)
if (volumeStore.volume != -1) {
mOriginalStreamVolume = volumeStore.originalVolume;
mLastProgress = volumeStore.volume;
postSetVolume(mLastProgress);
}
|
public void | onSaveInstanceState(android.preference.VolumePreference.VolumeStore volumeStore)
if (mLastProgress >= 0) {
volumeStore.volume = mLastProgress;
volumeStore.originalVolume = mOriginalStreamVolume;
}
|
private void | onStartSample()
if (!isSamplePlaying()) {
if (mCallback != null) {
mCallback.onSampleStarting(this);
}
if (mRingtone != null) {
try {
mRingtone.play();
} catch (Throwable e) {
Log.w(TAG, "Error playing ringtone, stream " + mStreamType, e);
}
}
}
|
public void | onStartTrackingTouch(android.widget.SeekBar seekBar)
|
private void | onStopSample()
if (mRingtone != null) {
mRingtone.stop();
}
|
public void | onStopTrackingTouch(android.widget.SeekBar seekBar)
postStartSample();
|
private void | postSetVolume(int progress)
if (mHandler == null) return;
// Do the volume changing separately to give responsive UI
mLastProgress = progress;
mHandler.removeMessages(MSG_SET_STREAM_VOLUME);
mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_STREAM_VOLUME));
|
private void | postStartSample()
if (mHandler == null) return;
mHandler.removeMessages(MSG_START_SAMPLE);
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_START_SAMPLE),
isSamplePlaying() ? CHECK_RINGTONE_PLAYBACK_DELAY_MS : 0);
|
private void | postStopSample()
if (mHandler == null) return;
// remove pending delayed start messages
mHandler.removeMessages(MSG_START_SAMPLE);
mHandler.removeMessages(MSG_STOP_SAMPLE);
mHandler.sendMessage(mHandler.obtainMessage(MSG_STOP_SAMPLE));
|
public void | revertVolume()
mAudioManager.setStreamVolume(mStreamType, mOriginalStreamVolume, 0);
|
public void | setSeekBar(android.widget.SeekBar seekBar)
if (mSeekBar != null) {
mSeekBar.setOnSeekBarChangeListener(null);
}
mSeekBar = seekBar;
mSeekBar.setOnSeekBarChangeListener(null);
mSeekBar.setMax(mMaxStreamVolume);
updateSeekBar();
mSeekBar.setOnSeekBarChangeListener(this);
|
public void | start()
if (mHandler != null) return; // already started
HandlerThread thread = new HandlerThread(TAG + ".CallbackHandler");
thread.start();
mHandler = new Handler(thread.getLooper(), this);
mHandler.sendEmptyMessage(MSG_INIT_SAMPLE);
mVolumeObserver = new Observer(mHandler);
mContext.getContentResolver().registerContentObserver(
System.getUriFor(System.VOLUME_SETTINGS[mStreamType]),
false, mVolumeObserver);
mReceiver.setListening(true);
|
public void | startSample()
postStartSample();
|
public void | stop()
if (mHandler == null) return; // already stopped
postStopSample();
mContext.getContentResolver().unregisterContentObserver(mVolumeObserver);
mReceiver.setListening(false);
mSeekBar.setOnSeekBarChangeListener(null);
mHandler.getLooper().quitSafely();
mHandler = null;
mVolumeObserver = null;
|
public void | stopSample()
postStopSample();
|
protected void | updateSeekBar()
if (mNotificationOrRing && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
mSeekBar.setEnabled(true);
mSeekBar.setProgress(0);
} else if (mMuted) {
mSeekBar.setEnabled(false);
mSeekBar.setProgress(0);
} else {
mSeekBar.setEnabled(true);
mSeekBar.setProgress(mLastProgress > -1 ? mLastProgress : mOriginalStreamVolume);
}
|
private void | updateSlider()
if (mSeekBar != null && mAudioManager != null) {
final int volume = mAudioManager.getStreamVolume(mStreamType);
final boolean mute = mAudioManager.isStreamMute(mStreamType);
mUiHandler.postUpdateSlider(volume, mute);
}
|