Search in sources :

Example 61 with KeyCharacterMap

use of android.view.KeyCharacterMap in project android_frameworks_base by ResurrectionRemix.

the class Input method sendText.

/**
     * Convert the characters of string text into key event's and send to
     * device.
     *
     * @param text is a string of characters you want to input to the device.
     */
private void sendText(int source, String text) {
    StringBuffer buff = new StringBuffer(text);
    boolean escapeFlag = false;
    for (int i = 0; i < buff.length(); i++) {
        if (escapeFlag) {
            escapeFlag = false;
            if (buff.charAt(i) == 's') {
                buff.setCharAt(i, ' ');
                buff.deleteCharAt(--i);
            }
        }
        if (buff.charAt(i) == '%') {
            escapeFlag = true;
        }
    }
    char[] chars = buff.toString().toCharArray();
    KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
    KeyEvent[] events = kcm.getEvents(chars);
    for (int i = 0; i < events.length; i++) {
        KeyEvent e = events[i];
        if (source != e.getSource()) {
            e.setSource(source);
        }
        injectKeyEvent(e);
    }
}
Also used : KeyEvent(android.view.KeyEvent) KeyCharacterMap(android.view.KeyCharacterMap)

Example 62 with KeyCharacterMap

use of android.view.KeyCharacterMap in project HoloEverywhere by Prototik.

the class TimePickerDialog method getAmOrPmKeyCode.

/**
     * Get the keycode value for AM and PM in the current language.
     */
private int getAmOrPmKeyCode(int amOrPm) {
    // Cache the codes.
    if (mAmKeyCode == -1 || mPmKeyCode == -1) {
        // Find the first character in the AM/PM text that is unique.
        KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
        char amChar;
        char pmChar;
        for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
            amChar = mAmText.toLowerCase(Locale.getDefault()).charAt(i);
            pmChar = mPmText.toLowerCase(Locale.getDefault()).charAt(i);
            if (amChar != pmChar) {
                KeyEvent[] events = kcm.getEvents(new char[] { amChar, pmChar });
                // There should be 4 events: a down and up for both AM and PM.
                if (events != null && events.length == 4) {
                    mAmKeyCode = events[0].getKeyCode();
                    mPmKeyCode = events[2].getKeyCode();
                } else {
                    Log.e(TAG, "Unable to find keycodes for AM and PM.");
                }
                break;
            }
        }
    }
    if (amOrPm == AM) {
        return mAmKeyCode;
    } else if (amOrPm == PM) {
        return mPmKeyCode;
    }
    return -1;
}
Also used : KeyEvent(android.view.KeyEvent) KeyCharacterMap(android.view.KeyCharacterMap)

Example 63 with KeyCharacterMap

use of android.view.KeyCharacterMap in project android_frameworks_base by crdroidandroid.

the class ToolbarActionBar method onKeyShortcut.

@Override
public boolean onKeyShortcut(int keyCode, KeyEvent event) {
    Menu menu = mDecorToolbar.getMenu();
    if (menu != null) {
        final KeyCharacterMap kmap = KeyCharacterMap.load(event != null ? event.getDeviceId() : KeyCharacterMap.VIRTUAL_KEYBOARD);
        menu.setQwertyMode(kmap.getKeyboardType() != KeyCharacterMap.NUMERIC);
        menu.performShortcut(keyCode, event, 0);
    }
    // keyboard shortcuts.
    return true;
}
Also used : Menu(android.view.Menu) KeyCharacterMap(android.view.KeyCharacterMap)

Example 64 with KeyCharacterMap

use of android.view.KeyCharacterMap in project android_frameworks_base by crdroidandroid.

the class TextKeyListener method getKeyListener.

private KeyListener getKeyListener(KeyEvent event) {
    KeyCharacterMap kmap = event.getKeyCharacterMap();
    int kind = kmap.getKeyboardType();
    if (kind == KeyCharacterMap.ALPHA) {
        return QwertyKeyListener.getInstance(mAutoText, mAutoCap);
    } else if (kind == KeyCharacterMap.NUMERIC) {
        return MultiTapKeyListener.getInstance(mAutoText, mAutoCap);
    } else if (kind == KeyCharacterMap.FULL || kind == KeyCharacterMap.SPECIAL_FUNCTION) {
        // these applications should be modified to use KeyCharacterMap.VIRTUAL_KEYBOARD.
        return QwertyKeyListener.getInstanceForFullKeyboard();
    }
    return NullKeyListener.getInstance();
}
Also used : KeyCharacterMap(android.view.KeyCharacterMap)

Example 65 with KeyCharacterMap

use of android.view.KeyCharacterMap in project android_frameworks_base by crdroidandroid.

the class Input method sendText.

/**
     * Convert the characters of string text into key event's and send to
     * device.
     *
     * @param text is a string of characters you want to input to the device.
     */
private void sendText(int source, String text) {
    StringBuffer buff = new StringBuffer(text);
    boolean escapeFlag = false;
    for (int i = 0; i < buff.length(); i++) {
        if (escapeFlag) {
            escapeFlag = false;
            if (buff.charAt(i) == 's') {
                buff.setCharAt(i, ' ');
                buff.deleteCharAt(--i);
            }
        }
        if (buff.charAt(i) == '%') {
            escapeFlag = true;
        }
    }
    char[] chars = buff.toString().toCharArray();
    KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
    KeyEvent[] events = kcm.getEvents(chars);
    for (int i = 0; i < events.length; i++) {
        KeyEvent e = events[i];
        if (source != e.getSource()) {
            e.setSource(source);
        }
        injectKeyEvent(e);
    }
}
Also used : KeyEvent(android.view.KeyEvent) KeyCharacterMap(android.view.KeyCharacterMap)

Aggregations

KeyCharacterMap (android.view.KeyCharacterMap)66 KeyEvent (android.view.KeyEvent)35 Instrumentation (android.app.Instrumentation)6 ActivityNotFoundException (android.content.ActivityNotFoundException)5 Intent (android.content.Intent)5 RemoteException (android.os.RemoteException)5 IWindowManager (android.view.IWindowManager)5 FallbackAction (android.view.KeyCharacterMap.FallbackAction)5 Menu (android.view.Menu)5 WindowManager (android.view.WindowManager)5 LayoutParams (android.view.WindowManager.LayoutParams)4 IStatusBarService (com.android.internal.statusbar.IStatusBarService)4 IDeviceIdleController (android.os.IDeviceIdleController)3 RecognizerIntent (android.speech.RecognizerIntent)3 LargeTest (android.test.suitebuilder.annotation.LargeTest)3 IShortcutService (com.android.internal.policy.IShortcutService)3 ContentResolver (android.content.ContentResolver)2 View (android.view.View)2 ITelephony (com.android.internal.telephony.ITelephony)2 SuppressLint (android.annotation.SuppressLint)1