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的声音了。


更多相关文章

  1. android EditText设置不可写
  2. android“设置”里的版本号
  3. 关于Android(安卓)Studio3.2新建项目Android(安卓)resource link
  4. 在Fragment中设置控件点击方法,执行失败。
  5. Android(安卓)闹钟管理类的使用
  6. Android设置通知栏/状态栏透明改变通知栏颜色和app最上部分颜色
  7. android 设置中划线 下划线等
  8. Andorid Dialog 示例【慢慢更新】
  9. android图表ichartjs

随机推荐

  1. android的service
  2. Android自动化测试之MonkeyRunner之Monke
  3. [Android][HTC]HTC Android Reboot Comma
  4. 在 Android Emulator 中开发 LKM 程序
  5. Android uses-permission权限
  6. android实现进度条ProgressDialog
  7. android gridview setOnItemClickListene
  8. Android文件存储
  9. Android 结束进程的方法
  10. openGL 简单demo