【AOSP】Android AOSP 输入法使用时在屏幕旋转的时候发生声音

追踪Code,发现在屏幕发生旋转的时候,会触发以下的方法:

android/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java

@Override
    public void onTabChanged(final String tabId) {
        Log.i("Leif","EmojiPalettesView----->onTabChanged");
        AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
                Constants.CODE_UNSPECIFIED, this);
        final int categoryId = mEmojiCategory.getCategoryId(tabId);
        setCurrentCategoryId(categoryId, false /* force */);
        updateEmojiCategoryPageIdView();
    }
    

android/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/AudioAndHapticFeedbackManager.java
 

public void performHapticAndAudioFeedback(final int code,
            final View viewToPerformHapticFeedbackOn) {
        Log.i("Leif","performHapticAndAudioFeedback--------->");
        performHapticFeedback(viewToPerformHapticFeedbackOn);
        performAudioFeedback(code);
    }
    
    public void performAudioFeedback(final int code) {
        // if mAudioManager is null, we can't play a sound anyway, so return
        if (mAudioManager == null) {
            return;
        }
        if (!mSoundOn) {
            return;
        }
        final int sound;
        switch (code) {
        case Constants.CODE_DELETE:
            sound = AudioManager.FX_KEYPRESS_DELETE;
            break;
        case Constants.CODE_ENTER:
            sound = AudioManager.FX_KEYPRESS_RETURN;
            break;
        case Constants.CODE_SPACE:
            sound = AudioManager.FX_KEYPRESS_SPACEBAR;
            break;
        default:
            sound = AudioManager.FX_KEYPRESS_STANDARD;
            break;
        }
        Log.i("Leif","performAudioFeedback-------->sound: "+sound);
        mAudioManager.playSoundEffect(sound, mSettingsValues.mKeypressSoundVolume);
    }

如果想让其不发声,可以mark 掉onTabChanged中的这个方法调用:
 

 AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
                Constants.CODE_UNSPECIFIED, this);
Class之间简单的调用关系:
LatinIME->KeyboardSwitcher->EmojiPalettesView->AudioAndHapticFeedbackManager

你可能感兴趣的:(Android,应用,android)