diff options
author | Danny Baumann <dannybaumann@web.de> | 2015-05-29 08:48:46 +0200 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2016-01-20 00:28:57 -0800 |
commit | 2238e8575b12053ace85f3f755afff0b26c54731 (patch) | |
tree | def6745e2acb5e304602c661740ff54fe44ab6db /src/com/android/settings/notification/IncreasingRingVolumePreference.java | |
parent | 7c09a30e92f700f012ce8fb82e5b751b72567ffe (diff) | |
download | packages_apps_Settings-2238e8575b12053ace85f3f755afff0b26c54731.zip packages_apps_Settings-2238e8575b12053ace85f3f755afff0b26c54731.tar.gz packages_apps_Settings-2238e8575b12053ace85f3f755afff0b26c54731.tar.bz2 |
Fix up increasing ring tone volume preview behaviour.
Change-Id: Ibe7fdf1ee7f0aa1c7c76052df69fa92e8b6a2ffd
Diffstat (limited to 'src/com/android/settings/notification/IncreasingRingVolumePreference.java')
-rw-r--r-- | src/com/android/settings/notification/IncreasingRingVolumePreference.java | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/com/android/settings/notification/IncreasingRingVolumePreference.java b/src/com/android/settings/notification/IncreasingRingVolumePreference.java index f613794..6b78bbe 100644 --- a/src/com/android/settings/notification/IncreasingRingVolumePreference.java +++ b/src/com/android/settings/notification/IncreasingRingVolumePreference.java @@ -18,6 +18,7 @@ package com.android.settings.notification; import android.content.ContentResolver; import android.content.Context; +import android.media.AudioAttributes; import android.media.AudioManager; import android.media.Ringtone; import android.media.RingtoneManager; @@ -59,6 +60,7 @@ public class IncreasingRingVolumePreference extends Preference implements private static final int MSG_START_SAMPLE = 1; private static final int MSG_STOP_SAMPLE = 2; private static final int MSG_INIT_SAMPLE = 3; + private static final int MSG_SET_VOLUME = 4; private static final int CHECK_RINGTONE_PLAYBACK_DELAY_MS = 1000; public IncreasingRingVolumePreference(Context context) { @@ -85,6 +87,10 @@ public class IncreasingRingVolumePreference extends Preference implements mCallback = callback; } + public void onActivityResume() { + initHandler(); + } + @Override public void onActivityStop() { if (mHandler != null) { @@ -98,7 +104,7 @@ public class IncreasingRingVolumePreference extends Preference implements public boolean handleMessage(Message msg) { switch (msg.what) { case MSG_START_SAMPLE: - onStartSample(); + onStartSample((float) msg.arg1 / 1000F); break; case MSG_STOP_SAMPLE: onStopSample(); @@ -106,6 +112,9 @@ public class IncreasingRingVolumePreference extends Preference implements case MSG_INIT_SAMPLE: onInitSample(); break; + case MSG_SET_VOLUME: + onSetVolume((float) msg.arg1 / 1000F); + break; } return true; } @@ -138,15 +147,12 @@ public class IncreasingRingVolumePreference extends Preference implements @Override public void onStartTrackingTouch(SeekBar seekBar) { - if (seekBar == mStartVolumeSeekBar && mCallback != null) { - mCallback.onStartingSample(); - } } @Override public void onStopTrackingTouch(SeekBar seekBar) { if (seekBar == mStartVolumeSeekBar) { - postStartSample(); + postStartSample(seekBar.getProgress()); } } @@ -161,7 +167,8 @@ public class IncreasingRingVolumePreference extends Preference implements mRampUpTimeValue.setText( Formatter.formatShortElapsedTime(getContext(), seconds * 1000)); if (fromTouch) { - CMSettings.System.putInt(cr, CMSettings.System.INCREASING_RING_RAMP_UP_TIME, seconds); + CMSettings.System.putInt(cr, + CMSettings.System.INCREASING_RING_RAMP_UP_TIME, seconds); } } } @@ -181,24 +188,45 @@ public class IncreasingRingVolumePreference extends Preference implements Settings.System.DEFAULT_RINGTONE_URI); if (mRingtone != null) { mRingtone.setStreamType(AudioManager.STREAM_RING); + mRingtone.setAudioAttributes( + new AudioAttributes.Builder(mRingtone.getAudioAttributes()) + .setFlags(AudioAttributes.FLAG_BYPASS_INTERRUPTION_POLICY | + AudioAttributes.FLAG_BYPASS_MUTE) + .build()); } } - private void postStartSample() { + private void postStartSample(int progress) { + boolean playing = isSamplePlaying(); mHandler.removeMessages(MSG_START_SAMPLE); - mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_START_SAMPLE), - isSamplePlaying() ? CHECK_RINGTONE_PLAYBACK_DELAY_MS : 0); + mHandler.removeMessages(MSG_SET_VOLUME); + mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_START_SAMPLE, progress, 0), + playing ? CHECK_RINGTONE_PLAYBACK_DELAY_MS : 0); + if (playing) { + mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_VOLUME, progress, 0)); + } } - private void onStartSample() { - if (!isSamplePlaying() && mRingtone != null) { + private void onStartSample(float volume) { + if (mRingtone == null) { + return; + } + if (!isSamplePlaying()) { + if (mCallback != null) { + mCallback.onStartingSample(); + } try { mRingtone.play(); } catch (Throwable e) { Log.w(TAG, "Error playing ringtone", e); } - mHandler.removeMessages(MSG_STOP_SAMPLE); - mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_STOP_SAMPLE), 2000); + } + mRingtone.setVolume(volume); + } + + private void onSetVolume(float volume) { + if (mRingtone != null) { + mRingtone.setVolume(volume); } } |