1.Main menu->Settings->Sound->Enable "Touch sounds"
2.Main menu->Settings->Display->Brightness->Mark&Unmark "Adapt to lighting conditions"
3.Check the phone sound.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Actual result:
The phone will not feedback touch sounds when tap "Adapt to lighting conditions" in Brightness.
code:
BrightnessDialog.java (base\packages\systemui\src\com\android\systemui\settings)
quick_settings_brightness_dialog.xml:
<CheckBox android:id="@+id/brightness_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/brightness_adapt_checkbox_information"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_marginTop="6dip"
/>
View.java
public boolean performClick() { sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); ListenerInfo li = mListenerInfo; if (li != null && li.mOnClickListener != null) { playSoundEffect(SoundEffectConstants.CLICK); li.mOnClickListener.onClick(this); return true; } return false; }
touch 声音是View playSoundEffect() 发出的。 但是View的onClickListener 沒有設置的話, performClick() 是不會調用playSoundEffect()的。
因为Brightness 的dialog的Checkbox 没有设置onClickListener , 所以click的时候没有声音。
所以只要给checkBox 设置个一onClickListener 就会有touch sound了。
同理测试一个Button 如果没有设置onClickListener, click时也不会有touch sound。
另外:
ViewRootImpl.java
public void playSoundEffect(int effectId) { checkThread(); if (mMediaDisabled) { return; } try { final AudioManager audioManager = getAudioManager(); switch (effectId) { case SoundEffectConstants.CLICK: audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK); return;
AudioManager.java
public void playSoundEffect(int effectType) { if (effectType < 0 || effectType >= NUM_SOUND_EFFECTS) { return; } if (!querySoundEffectsEnabled()) { return; } IAudioService service = getService(); try { service.playSoundEffect(effectType); } catch (RemoteException e) { Log.e(TAG, "Dead object in playSoundEffect"+e); } } private boolean querySoundEffectsEnabled() { return Settings.System.getInt(mContext.getContentResolver(), Settings.System.SOUND_EFFECTS_ENABLED, 0) != 0; }
//当settings 的touch sounds 关闭后,就没有click的声音了。