Example usage for android.media AudioManager FX_KEYPRESS_SPACEBAR

List of usage examples for android.media AudioManager FX_KEYPRESS_SPACEBAR

Introduction

In this page you can find the example usage for android.media AudioManager FX_KEYPRESS_SPACEBAR.

Prototype

int FX_KEYPRESS_SPACEBAR

To view the source code for android.media AudioManager FX_KEYPRESS_SPACEBAR.

Click Source Link

Document

IME spacebar keypress sound

Usage

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

public void onPress(int primaryCode) {
    super.onPress(primaryCode);
    InputConnection ic = getCurrentInputConnection();
    if (mVibrationDuration > 0 && primaryCode != 0 && mVibrator != null) {
        try {/*w  ww.j  ava  2 s .  c  o m*/
            mVibrator.vibrate(mVibrationDuration);
        } catch (Exception e) {
            Logger.w(TAG, "Failed to interact with vibrator! Disabling for now.");
            mVibrationDuration = 0;
        }
    }

    if (primaryCode == KeyCodes.SHIFT) {
        mShiftKeyState.onPress();
        handleShift();
    } else {
        mShiftKeyState.onOtherKeyPressed();
    }

    if (primaryCode == KeyCodes.CTRL) {
        mControlKeyState.onPress();
        handleControl();
        sendKeyDown(ic, 113); // KeyEvent.KEYCODE_CTRL_LEFT (API 11 and up)
    } else {
        mControlKeyState.onOtherKeyPressed();
    }

    if (mSoundOn && (!mSilentMode) && primaryCode != 0) {
        final int keyFX;
        switch (primaryCode) {
        case 13:
        case KeyCodes.ENTER:
            keyFX = AudioManager.FX_KEYPRESS_RETURN;
            break;
        case KeyCodes.DELETE:
            keyFX = AudioManager.FX_KEYPRESS_DELETE;
            break;
        case KeyCodes.SPACE:
            keyFX = AudioManager.FX_KEYPRESS_SPACEBAR;
            break;
        default:
            keyFX = AudioManager.FX_KEY_CLICK;
        }
        final float fxVolume;
        // creating scoop to make sure volume and maxVolume
        // are not used
        {
            final int volume;
            final int maxVolume;
            if (mSoundVolume > 0) {
                volume = mSoundVolume;
                maxVolume = 100;
                fxVolume = ((float) volume) / ((float) maxVolume);
            } else {
                fxVolume = -1.0f;
            }

        }

        mAudioManager.playSoundEffect(keyFX, fxVolume);
    }
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

private void playKeyClick(int primaryCode) {
    // if mAudioManager is null, we don't have the ringer state yet
    // mAudioManager will be set by updateRingerMode
    if (mAudioManager == null) {
        if (mKeyboardSwitcher.getInputView() != null) {
            updateRingerMode();//  w w w.  j ava 2 s  .c  om
        }
    }
    if (mSoundOn && !mSilentMode) {
        // FIXME: Volume and enable should come from UI settings
        // FIXME: These should be triggered after auto-repeat logic
        int sound = AudioManager.FX_KEYPRESS_STANDARD;
        switch (primaryCode) {
        case Keyboard.KEYCODE_DELETE:
            sound = AudioManager.FX_KEYPRESS_DELETE;
            break;
        case ASCII_ENTER:
            sound = AudioManager.FX_KEYPRESS_RETURN;
            break;
        case ASCII_SPACE:
            sound = AudioManager.FX_KEYPRESS_SPACEBAR;
            break;
        }
        mAudioManager.playSoundEffect(sound, getKeyClickVolume());
    }
}