(转)设置静音和振动
静音和振动都属于来电后的动作.所以在设置静音和振动时都只是设置一些标识,并往数据库写入相应标识.
文件:packages/apps/settings/src/com/Android/settings/SoundAndDisplaySettings.Java
java代码:
- private CheckBoxPreference mSilent;
- private CheckBoxPreference mVibrate;
- 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);
- }
- }
- public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
- if (preference == mSilent || preference == mVibrate) {
- setRingerMode(mSilent.isChecked(), mVibrate.isChecked());
- if (preference == mSilent) updateState(false);
- }
静音和振动是复选框按钮,两个中有一个发生变化时调用setRingerMode对状态进行设置;如下状态描术:
RINGER_MODE_SILENT 静音,且无振动
RINGER_MODE_VIBRATE 静音,但有振动
RINGER_MODE_NORMAL 正常声音,振动开关由setVibrateSetting决定.
铃响模式的设置是通过mAudioManager(音频管理器)来实现的.