am f96901f8: Merge "Add support for non-linear ramping of master volume adjustment"
* commit 'f96901f8ccf7e5bdb05bb22ca1b522c381f05043': Add support for non-linear ramping of master volume adjustment
This commit is contained in:
@@ -65,6 +65,17 @@
|
||||
master volume stream and nothing else . -->
|
||||
<bool name="config_useMasterVolume">false</bool>
|
||||
|
||||
<!-- Array of integer pairs controlling the rate at which the master volume changes
|
||||
in response to volume up and down key events.
|
||||
The first integer of each pair is compared against the current master volume
|
||||
(in range 0 to 100).
|
||||
The last pair with first integer <= the current volume is chosen,
|
||||
and the second integer of the pair indicates the amount to increase the master volume
|
||||
when volume up is pressed. -->
|
||||
<integer-array name="config_masterVolumeRamp">
|
||||
<item>0</item> <item>5</item> <!-- default: always increase volume by 5% -->
|
||||
</integer-array>
|
||||
|
||||
<!-- Flag indicating whether the AUDIO_BECOMING_NOISY notification should
|
||||
be sent during an change to the audio output device. -->
|
||||
<bool name="config_sendAudioBecomingNoisy">true</bool>
|
||||
|
||||
@@ -862,6 +862,7 @@
|
||||
<java-symbol type="array" name="preloaded_drawables" />
|
||||
<java-symbol type="array" name="special_locale_codes" />
|
||||
<java-symbol type="array" name="special_locale_names" />
|
||||
<java-symbol type="array" name="config_masterVolumeRamp" />
|
||||
|
||||
<java-symbol type="drawable" name="default_wallpaper" />
|
||||
<java-symbol type="drawable" name="ic_suggestions_add" />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user