diff options
author | Daniel Sandler <dsandler@google.com> | 2010-02-26 15:25:04 -0500 |
---|---|---|
committer | Daniel Sandler <dsandler@google.com> | 2010-02-26 21:01:59 -0500 |
commit | 58cf8299d3ef347e3fd154b1439f50e62f7ca8bf (patch) | |
tree | ed30365cf096f08f3d06da9228ec4cd8a2f812de /src/com/android/settings/SoundSettings.java | |
parent | c99cffbffcf38f0e6bf10c9ff541b1bb5180316e (diff) | |
download | packages_apps_settings-58cf8299d3ef347e3fd154b1439f50e62f7ca8bf.zip packages_apps_settings-58cf8299d3ef347e3fd154b1439f50e62f7ca8bf.tar.gz packages_apps_settings-58cf8299d3ef347e3fd154b1439f50e62f7ca8bf.tar.bz2 |
Support new vibrate/silent behavior.
The updated settings tree looks like this:
[ ] Silent mode (unchanged)
[ ] Allow vibration in silent mode (new)
Phone vibrate: (changed from boolean)
( ) Always
( ) Only in silent mode
( ) Never
See change I14cf91b0 for explanation & framework support.
Change-Id: I22ba7bcfa5ddf4e545800083c6e80fb655f211e5
Diffstat (limited to 'src/com/android/settings/SoundSettings.java')
-rw-r--r-- | src/com/android/settings/SoundSettings.java | 81 |
1 files changed, 55 insertions, 26 deletions
diff --git a/src/com/android/settings/SoundSettings.java b/src/com/android/settings/SoundSettings.java index 2070519..c7bfe71 100644 --- a/src/com/android/settings/SoundSettings.java +++ b/src/com/android/settings/SoundSettings.java @@ -49,6 +49,7 @@ public class SoundSettings extends PreferenceActivity implements private static final String KEY_SILENT = "silent"; private static final String KEY_VIBRATE = "vibrate"; + private static final String KEY_VIBRATE_IN_SILENT = "vibrate_in_silent"; private static final String KEY_DTMF_TONE = "dtmf_tone"; private static final String KEY_SOUND_EFFECTS = "sound_effects"; private static final String KEY_HAPTIC_FEEDBACK = "haptic_feedback"; @@ -66,7 +67,8 @@ public class SoundSettings extends PreferenceActivity implements * Otherwise, it will adjust the normal ringer mode's ring or ring+vibrate * setting. */ - private CheckBoxPreference mVibrate; + private ListPreference mPhoneVibrate; + private CheckBoxPreference mVibrateInSilent; private CheckBoxPreference mDtmfTone; private CheckBoxPreference mSoundEffects; private CheckBoxPreference mHapticFeedback; @@ -103,7 +105,8 @@ public class SoundSettings extends PreferenceActivity implements mSilent = (CheckBoxPreference) findPreference(KEY_SILENT); - mVibrate = (CheckBoxPreference) findPreference(KEY_VIBRATE); + mPhoneVibrate = (ListPreference) findPreference(KEY_VIBRATE); + mVibrateInSilent = (CheckBoxPreference) findPreference(KEY_VIBRATE_IN_SILENT); mDtmfTone = (CheckBoxPreference) findPreference(KEY_DTMF_TONE); mDtmfTone.setPersistent(false); mDtmfTone.setChecked(Settings.System.getInt(resolver, @@ -164,8 +167,13 @@ public class SoundSettings extends PreferenceActivity implements unregisterReceiver(mReceiver); } + // updateState in fact updates the UI to reflect the system state private void updateState(boolean force) { final int ringerMode = mAudioManager.getRingerMode(); + + // NB: in the UI we now simply call this "silent mode". A separate + // setting controls whether we're in RINGER_MODE_SILENT or + // RINGER_MODE_VIBRATE. final boolean silentOrVibrateMode = ringerMode != AudioManager.RINGER_MODE_NORMAL; @@ -173,15 +181,18 @@ public class SoundSettings extends PreferenceActivity implements mSilent.setChecked(silentOrVibrateMode); } - boolean vibrateSetting; - if (silentOrVibrateMode) { - vibrateSetting = ringerMode == AudioManager.RINGER_MODE_VIBRATE; - } else { - vibrateSetting = mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER) - == AudioManager.VIBRATE_SETTING_ON; - } - if (vibrateSetting != mVibrate.isChecked() || force) { - mVibrate.setChecked(vibrateSetting); + mVibrateInSilent.setEnabled(silentOrVibrateMode); + mVibrateInSilent.setChecked(Settings.System.getInt( + getContentResolver(), + Settings.System.VIBRATE_IN_SILENT, + 1) == 1); + + // Control phone vibe independent of silent mode + String phoneVibrateSetting = String.valueOf( + mAudioManager.getVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER)); + + if (! phoneVibrateSetting.equals(mPhoneVibrate.getValue()) || force) { + mPhoneVibrate.setValue(phoneVibrateSetting); } int silentModeStreams = Settings.System.getInt(getContentResolver(), @@ -193,23 +204,41 @@ public class SoundSettings extends PreferenceActivity implements } - private void setRingerMode(boolean silent, boolean vibrate) { - if (silent) { - mAudioManager.setRingerMode(vibrate ? AudioManager.RINGER_MODE_VIBRATE : - AudioManager.RINGER_MODE_SILENT); - } else { - mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); - mAudioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER, - vibrate ? AudioManager.VIBRATE_SETTING_ON - : AudioManager.VIBRATE_SETTING_OFF); - } - } - @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { - if (preference == mSilent || preference == mVibrate) { - setRingerMode(mSilent.isChecked(), mVibrate.isChecked()); - if (preference == mSilent) updateState(false); + if (preference == mSilent) { + if (mSilent.isChecked()) { + boolean vibeInSilent = mVibrateInSilent.isChecked(); + mAudioManager.setRingerMode( + vibeInSilent ? AudioManager.RINGER_MODE_VIBRATE + : AudioManager.RINGER_MODE_SILENT); + } else { + mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); + } + updateState(false); + } else if (preference == mPhoneVibrate) { + int vibeSetting = new Integer(mPhoneVibrate.getValue()).intValue(); + switch (vibeSetting) { + case AudioManager.VIBRATE_SETTING_ON: + case AudioManager.VIBRATE_SETTING_OFF: + case AudioManager.VIBRATE_SETTING_ONLY_SILENT: + mAudioManager.setVibrateSetting( + AudioManager.VIBRATE_TYPE_RINGER, + vibeSetting); + updateState(false); + break; + } + } else if (preference == mVibrateInSilent) { + boolean vibeInSilent = mVibrateInSilent.isChecked(); + Settings.System.putInt(getContentResolver(), + Settings.System.VIBRATE_IN_SILENT, + vibeInSilent ? 1 : 0); + int ringerMode = mAudioManager.getRingerMode(); + if (ringerMode != AudioManager.RINGER_MODE_NORMAL) { + mAudioManager.setRingerMode(vibeInSilent + ? AudioManager.RINGER_MODE_VIBRATE + : AudioManager.RINGER_MODE_SILENT); + } } else if (preference == mDtmfTone) { Settings.System.putInt(getContentResolver(), Settings.System.DTMF_TONE_WHEN_DIALING, mDtmfTone.isChecked() ? 1 : 0); |