Android touch sound

Step:
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的声音了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值