Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7bae4325 authored by Justin Ho's avatar Justin Ho Committed by Android (Google) Code Review
Browse files

Merge "Enable subclass of SeekBarVolumizer to provide a custom file for sample...

Merge "Enable subclass of SeekBarVolumizer to provide a custom file for sample playback." into honeycomb
parents 0a909a12 998127c8
Loading
Loading
Loading
Loading
+33 −21
Original line number Diff line number Diff line
@@ -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);
@@ -267,7 +271,7 @@ public class VolumePreference extends SeekBarPreference implements
                    System.getUriFor(System.VOLUME_SETTINGS[mStreamType]),
                    false, mVolumeObserver);

            Uri defaultUri = null;
            if (defaultUri == null) {
                if (mStreamType == AudioManager.STREAM_RING) {
                    defaultUri = Settings.System.DEFAULT_RINGTONE_URI;
                } else if (mStreamType == AudioManager.STREAM_NOTIFICATION) {
@@ -275,8 +279,10 @@ public class VolumePreference extends SeekBarPreference implements
                } else {
                    defaultUri = Settings.System.DEFAULT_ALARM_ALERT_URI;
                }
            }

            mRingtone = RingtoneManager.getRingtone(mContext, defaultUri);

            if (mRingtone != null) {
                mRingtone.setStreamType(mStreamType);
            }
@@ -312,8 +318,8 @@ public class VolumePreference extends SeekBarPreference implements
        }

        public void onStopTrackingTouch(SeekBar seekBar) {
            if (mRingtone != null && !mRingtone.isPlaying()) {
                sample();
            if (!isSamplePlaying()) {
                startSample();
            }
        }
        
@@ -321,10 +327,16 @@ public class VolumePreference extends SeekBarPreference implements
            mAudioManager.setStreamVolume(mStreamType, mLastProgress, 0);
        }

        private void sample() {
        public boolean isSamplePlaying() {
            return mRingtone != null && mRingtone.isPlaying();
        }

        public void startSample() {
            onSampleStarting(this);
            if (mRingtone != null) {
                mRingtone.play();
            }
        }
    
        public void stopSample() {
            if (mRingtone != null) {
@@ -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 {