diff options
author | Mike Lockwood <lockwood@google.com> | 2012-02-09 11:24:10 -0800 |
---|---|---|
committer | Mike Lockwood <lockwood@google.com> | 2012-02-10 15:58:07 -0800 |
commit | 9760647dd0ee67e7c20f3e9d661d2006b1df0b54 (patch) | |
tree | ae6a0e0e3961c8a13c69cbbf89abd4bc43f529b9 /media | |
parent | c199e2c7e0f8895273fdd912c5c88495a8b30e35 (diff) | |
download | frameworks_base-9760647dd0ee67e7c20f3e9d661d2006b1df0b54.zip frameworks_base-9760647dd0ee67e7c20f3e9d661d2006b1df0b54.tar.gz frameworks_base-9760647dd0ee67e7c20f3e9d661d2006b1df0b54.tar.bz2 |
Add support for non-linear ramping of master volume adjustment
Bug: 5472584
Change-Id: I1227007d1563eca739fb78b6d9595febc04a3f03
Signed-off-by: Mike Lockwood <lockwood@google.com>
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/AudioService.java | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 23060aa..eae03be 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -137,10 +137,6 @@ public class AudioService extends IAudioService.Stub { // Timeout for connection to bluetooth headset service private static final int BT_HEADSET_CNCT_TIMEOUT_MS = 3000; - // Amount to raise/lower master volume - // FIXME - this should probably be in a resource - private static final float MASTER_VOLUME_INCREMENT = 0.05f; - /** @see AudioSystemThread */ private AudioSystemThread mAudioSystemThread; /** @see AudioHandler */ @@ -286,6 +282,8 @@ public class AudioService extends IAudioService.Stub { // True if we have master volume support private final boolean mUseMasterVolume; + private final int[] mMasterVolumeRamp; + // List of binder death handlers for setMode() client processes. // The last process to have called setMode() is at the top of the list. private final ArrayList <SetModeDeathHandler> mSetModeDeathHandlers = new ArrayList <SetModeDeathHandler>(); @@ -416,6 +414,9 @@ public class AudioService extends IAudioService.Stub { mUseMasterVolume = context.getResources().getBoolean( com.android.internal.R.bool.config_useMasterVolume); restoreMasterVolume(); + + mMasterVolumeRamp = context.getResources().getIntArray( + com.android.internal.R.array.config_masterVolumeRamp); } private void createAudioSystemThread() { @@ -620,19 +621,27 @@ public class AudioService extends IAudioService.Stub { /** @see AudioManager#adjustMasterVolume(int) */ public void adjustMasterVolume(int direction, int flags) { ensureValidDirection(direction); - - float volume = AudioSystem.getMasterVolume(); - if (volume >= 0.0) { - // get current master volume adjusted to 0 to 100 + int volume = Math.round(AudioSystem.getMasterVolume() * MAX_MASTER_VOLUME); + int delta = 0; + for (int i = 0; i < mMasterVolumeRamp.length; i += 2) { + int testVolume = mMasterVolumeRamp[i]; + int testDelta = mMasterVolumeRamp[i + 1]; if (direction == AudioManager.ADJUST_RAISE) { - volume += MASTER_VOLUME_INCREMENT; - if (volume > 1.0f) volume = 1.0f; + if (volume >= testVolume) { + delta = testDelta; + } else { + break; + } } else if (direction == AudioManager.ADJUST_LOWER) { - volume -= MASTER_VOLUME_INCREMENT; - if (volume < 0.0f) volume = 0.0f; + if (volume - testDelta >= testVolume) { + delta = -testDelta; + } else { + break; + } } - doSetMasterVolume(volume, flags); } +// Log.d(TAG, "adjustMasterVolume volume: " + volume + " delta: " + delta + " direction: " + direction); + setMasterVolume(volume + delta, flags); } /** @see AudioManager#setStreamVolume(int, int, int) */ @@ -805,6 +814,11 @@ public class AudioService extends IAudioService.Stub { } public void setMasterVolume(int volume, int flags) { + if (volume < 0) { + volume = 0; + } else if (volume > MAX_MASTER_VOLUME) { + volume = MAX_MASTER_VOLUME; + } doSetMasterVolume((float)volume / MAX_MASTER_VOLUME, flags); } |