Skip to content

Commit 115284b

Browse files
Christopher TateAndroid (Google) Code Review
authored andcommitted
Merge "Support volume-changed sounds on master-volume-only configs" into ics-aah
2 parents 03f2fb3 + c4b78d2 commit 115284b

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

core/java/android/view/VolumePanel.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ public class VolumePanel extends Handler implements OnSeekBarChangeListener, Vie
103103
private boolean mShowCombinedVolumes;
104104
private boolean mVoiceCapable;
105105

106+
// True if we want to play tones on the system stream when the master stream is specified.
107+
private final boolean mPlayMasterStreamTones;
108+
106109
/** Dialog containing all the sliders */
107110
private final Dialog mDialog;
108111
/** Dialog's content view */
@@ -275,6 +278,13 @@ public void onDismiss(DialogInterface dialog) {
275278
mMoreButton.setOnClickListener(this);
276279
}
277280

281+
boolean masterVolumeOnly = context.getResources().getBoolean(
282+
com.android.internal.R.bool.config_useMasterVolume);
283+
boolean masterVolumeKeySounds = mContext.getResources().getBoolean(
284+
com.android.internal.R.bool.config_useVolumeKeySounds);
285+
286+
mPlayMasterStreamTones = masterVolumeOnly && masterVolumeKeySounds;
287+
278288
listenToRingerMode();
279289
}
280290

@@ -657,7 +667,16 @@ protected void onVibrate() {
657667
* Lock on this VolumePanel instance as long as you use the returned ToneGenerator.
658668
*/
659669
private ToneGenerator getOrCreateToneGenerator(int streamType) {
660-
if (streamType == STREAM_MASTER) return null;
670+
if (streamType == STREAM_MASTER) {
671+
// For devices that use the master volume setting only but still want to
672+
// play a volume-changed tone, direct the master volume pseudostream to
673+
// the system stream's tone generator.
674+
if (mPlayMasterStreamTones) {
675+
streamType = AudioManager.STREAM_SYSTEM;
676+
} else {
677+
return null;
678+
}
679+
}
661680
synchronized (this) {
662681
if (mToneGenerators[streamType] == null) {
663682
try {

media/java/android/media/AudioManager.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,6 @@ public void handleKeyDown(KeyEvent event, int stream) {
460460
* responsive to the user.
461461
*/
462462
int flags = FLAG_SHOW_UI | FLAG_VIBRATE;
463-
// if there is no volume key-up sound, apply the new volume immediately
464-
if (!mUseVolumeKeySounds) flags |= FLAG_PLAY_SOUND;
465463

466464
if (mUseMasterVolume) {
467465
adjustMasterVolume(
@@ -508,9 +506,7 @@ public void handleKeyUp(KeyEvent event, int stream) {
508506
*/
509507
if (mUseVolumeKeySounds) {
510508
if (mUseMasterVolume) {
511-
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
512-
adjustMasterVolume(ADJUST_SAME, FLAG_PLAY_SOUND);
513-
}
509+
adjustMasterVolume(ADJUST_SAME, FLAG_PLAY_SOUND);
514510
} else {
515511
int flags = FLAG_PLAY_SOUND;
516512
if (mVolumeControlStream != -1) {

0 commit comments

Comments
 (0)