Android(安卓)touch sound
16lz
2022-07-25
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
touch 声音是View playSoundEffect() 发出的。 但是View的onClickListener 沒有設置的話, performClick() 是不會調用playSoundEffect()的。
因为Brightness 的dialog的Checkbox 没有设置onClickListener , 所以click的时候没有声音。
所以只要给checkBox 设置个一onClickListener 就会有touch sound了。
同理测试一个Button 如果没有设置onClickListener, click时也不会有touch sound。
另外:
ViewRootImpl.java
AudioManager.java
//当settings 的touch sounds 关闭后,就没有click的声音了。
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的声音了。
更多相关文章
- android EditText设置不可写
- android“设置”里的版本号
- 关于Android(安卓)Studio3.2新建项目Android(安卓)resource link
- 在Fragment中设置控件点击方法,执行失败。
- Android(安卓)闹钟管理类的使用
- Android设置通知栏/状态栏透明改变通知栏颜色和app最上部分颜色
- android 设置中划线 下划线等
- Andorid Dialog 示例【慢慢更新】
- android图表ichartjs