Example usage for android.media AudioManager FX_KEYPRESS_RETURN

List of usage examples for android.media AudioManager FX_KEYPRESS_RETURN

Introduction

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

Prototype

int FX_KEYPRESS_RETURN

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

Click Source Link

Document

IME return_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 {//from w  w w.  j  av a 2s . c  om
            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();/*from   w ww.j a v  a2  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());
    }
}