Simplify audio management (A2)

There is little point in deferring loading for this. Getting the
service at startup time is not very expensive anyway, plus we
can avoid getting it in a later change if sound is off in settings.

Change-Id: I08d65467f245fa2f9f617eb23257c327b3115673
This commit is contained in:
Jean Chalard 2012-03-07 12:39:09 +09:00
parent 564496bad6
commit 793791cdf0

View file

@ -37,7 +37,7 @@ public class AudioAndHapticFeedbackManager extends BroadcastReceiver {
final private LatinIME mLatinIme;
final private SettingsValues mSettingsValues;
final private KeyboardSwitcher mKeyboardSwitcher;
private AudioManager mAudioManager;
final private AudioManager mAudioManager;
final private VibratorCompatWrapper mVibrator;
private boolean mSilentModeOn;
@ -48,6 +48,8 @@ public class AudioAndHapticFeedbackManager extends BroadcastReceiver {
mKeyboardSwitcher = keyboardSwitcher;
mSilentModeOn = true;
mVibrator = VibratorCompatWrapper.getInstance(mLatinIme);
mAudioManager = (AudioManager) mLatinIme.getSystemService(Context.AUDIO_SERVICE);
updateRingerMode();
}
public void hapticAndAudioFeedback(final int primaryCode) {
@ -61,21 +63,16 @@ public class AudioAndHapticFeedbackManager extends BroadcastReceiver {
// update flags for silent mode
private void updateRingerMode() {
if (mAudioManager == null) {
mAudioManager = (AudioManager) mLatinIme.getSystemService(Context.AUDIO_SERVICE);
if (mAudioManager == null) return;
if (!mSettingsValues.mSoundOn || mAudioManager == null) {
mSilentModeOn = true;
} else {
mSilentModeOn = (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL);
}
mSilentModeOn = (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL);
}
private void playKeyClick(int primaryCode) {
// if mAudioManager is null, we don't have the ringer state yet
// mAudioManager will be set by updateRingerMode
if (mAudioManager == null) {
if (mKeyboardSwitcher.getKeyboardView() != null) {
updateRingerMode();
}
}
// if mAudioManager is null, we can't play a sound anyway, so return
if (mAudioManager == null) return;
if (isSoundOn()) {
final int sound;
switch (primaryCode) {