Simplification of sound settings (A4)

Change-Id: I0c6e207bae1e08c45a95b3479e1d67228d696792
main
Jean Chalard 2012-03-07 12:43:20 +09:00
parent 2651b17fc4
commit bdbb22bb33
1 changed files with 8 additions and 12 deletions

View File

@ -46,10 +46,9 @@ public class AudioAndHapticFeedbackManager extends BroadcastReceiver {
mLatinIme = latinIme; mLatinIme = latinIme;
mSettingsValues = settingsValues; mSettingsValues = settingsValues;
mKeyboardSwitcher = keyboardSwitcher; mKeyboardSwitcher = keyboardSwitcher;
mSoundOn = false;
mVibrator = VibratorCompatWrapper.getInstance(mLatinIme); mVibrator = VibratorCompatWrapper.getInstance(mLatinIme);
mAudioManager = (AudioManager) mLatinIme.getSystemService(Context.AUDIO_SERVICE); mAudioManager = (AudioManager) mLatinIme.getSystemService(Context.AUDIO_SERVICE);
updateRingerMode(); mSoundOn = reevaluateIfSoundIsOn();
} }
public void hapticAndAudioFeedback(final int primaryCode) { public void hapticAndAudioFeedback(final int primaryCode) {
@ -57,23 +56,18 @@ public class AudioAndHapticFeedbackManager extends BroadcastReceiver {
playKeyClick(primaryCode); playKeyClick(primaryCode);
} }
private boolean isSoundOn() { private boolean reevaluateIfSoundIsOn() {
return mSettingsValues.mSoundOn && mSoundOn;
}
// update flags for silent mode
private void updateRingerMode() {
if (!mSettingsValues.mSoundOn || mAudioManager == null) { if (!mSettingsValues.mSoundOn || mAudioManager == null) {
mSoundOn = false; return false;
} else { } else {
mSoundOn = (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL); return mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL;
} }
} }
private void playKeyClick(int primaryCode) { private void playKeyClick(int primaryCode) {
// if mAudioManager is null, we can't play a sound anyway, so return // if mAudioManager is null, we can't play a sound anyway, so return
if (mAudioManager == null) return; if (mAudioManager == null) return;
if (isSoundOn()) { if (mSoundOn) {
final int sound; final int sound;
switch (primaryCode) { switch (primaryCode) {
case Keyboard.CODE_DELETE: case Keyboard.CODE_DELETE:
@ -114,8 +108,10 @@ public class AudioAndHapticFeedbackManager extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
final String action = intent.getAction(); final String action = intent.getAction();
// The following test is supposedly useless since we only listen for the ringer event.
// Still, it's a good safety measure.
if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) { if (action.equals(AudioManager.RINGER_MODE_CHANGED_ACTION)) {
updateRingerMode(); mSoundOn = reevaluateIfSoundIsOn();
} }
} }
} }