Search in sources :

Example 16 with KeyCharacterMap

use of android.view.KeyCharacterMap in project platform_frameworks_base by android.

the class PhoneWindowManager method dispatchUnhandledKey.

/** {@inheritDoc} */
@Override
public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
    // Note: This method is only called if the initial down was unhandled.
    if (DEBUG_INPUT) {
        Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() + ", flags=" + event.getFlags() + ", keyCode=" + event.getKeyCode() + ", scanCode=" + event.getScanCode() + ", metaState=" + event.getMetaState() + ", repeatCount=" + event.getRepeatCount() + ", policyFlags=" + policyFlags);
    }
    KeyEvent fallbackEvent = null;
    if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
        final KeyCharacterMap kcm = event.getKeyCharacterMap();
        final int keyCode = event.getKeyCode();
        final int metaState = event.getMetaState();
        final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0;
        // Check for fallback actions specified by the key character map.
        final FallbackAction fallbackAction;
        if (initialDown) {
            fallbackAction = kcm.getFallbackAction(keyCode, metaState);
        } else {
            fallbackAction = mFallbackActions.get(keyCode);
        }
        if (fallbackAction != null) {
            if (DEBUG_INPUT) {
                Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode + " metaState=" + Integer.toHexString(fallbackAction.metaState));
            }
            final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
            fallbackEvent = KeyEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), fallbackAction.keyCode, event.getRepeatCount(), fallbackAction.metaState, event.getDeviceId(), event.getScanCode(), flags, event.getSource(), null);
            if (!interceptFallback(win, fallbackEvent, policyFlags)) {
                fallbackEvent.recycle();
                fallbackEvent = null;
            }
            if (initialDown) {
                mFallbackActions.put(keyCode, fallbackAction);
            } else if (event.getAction() == KeyEvent.ACTION_UP) {
                mFallbackActions.remove(keyCode);
                fallbackAction.recycle();
            }
        }
    }
    if (DEBUG_INPUT) {
        if (fallbackEvent == null) {
            Slog.d(TAG, "No fallback.");
        } else {
            Slog.d(TAG, "Performing fallback: " + fallbackEvent);
        }
    }
    return fallbackEvent;
}
Also used : KeyEvent(android.view.KeyEvent) KeyCharacterMap(android.view.KeyCharacterMap) FallbackAction(android.view.KeyCharacterMap.FallbackAction)

Example 17 with KeyCharacterMap

use of android.view.KeyCharacterMap in project XobotOS by xamarin.

the class Instrumentation method sendStringSync.

/**
     * Sends the key events corresponding to the text to the app being
     * instrumented.
     * 
     * @param text The text to be sent. 
     */
public void sendStringSync(String text) {
    if (text == null) {
        return;
    }
    KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
    KeyEvent[] events = keyCharacterMap.getEvents(text.toCharArray());
    if (events != null) {
        for (int i = 0; i < events.length; i++) {
            sendKeySync(events[i]);
        }
    }
}
Also used : KeyEvent(android.view.KeyEvent) KeyCharacterMap(android.view.KeyCharacterMap)

Example 18 with KeyCharacterMap

use of android.view.KeyCharacterMap in project platform_frameworks_base by android.

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 19 with KeyCharacterMap

use of android.view.KeyCharacterMap in project platform_frameworks_base by android.

the class Instrumentation method sendStringSync.

/**
     * Sends the key events corresponding to the text to the app being
     * instrumented.
     * 
     * @param text The text to be sent. 
     */
public void sendStringSync(String text) {
    if (text == null) {
        return;
    }
    KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
    KeyEvent[] events = keyCharacterMap.getEvents(text.toCharArray());
    if (events != null) {
        for (int i = 0; i < events.length; i++) {
            // We have to change the time of an event before injecting it because
            // all KeyEvents returned by KeyCharacterMap.getEvents() have the same
            // time stamp and the system rejects too old events. Hence, it is
            // possible for an event to become stale before it is injected if it
            // takes too long to inject the preceding ones.
            sendKeySync(KeyEvent.changeTimeRepeat(events[i], SystemClock.uptimeMillis(), 0));
        }
    }
}
Also used : KeyEvent(android.view.KeyEvent) KeyCharacterMap(android.view.KeyCharacterMap)

Example 20 with KeyCharacterMap

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

the class KeyUtils method chordMenuKey.

/**
     * Simulates chording the menu key.
     * 
     * @param test The test case that is being run.
     * @param shortcutKey The shortcut key to tap while chording the menu key.
     */
public static void chordMenuKey(ActivityInstrumentationTestCase test, char shortcutKey) {
    final Instrumentation inst = test.getInstrumentation();
    final KeyEvent pushMenuKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MENU);
    final KeyCharacterMap keyCharMap = KeyCharacterMap.load(pushMenuKey.getDeviceId());
    final KeyEvent shortcutKeyEvent = keyCharMap.getEvents(new char[] { shortcutKey })[0];
    final int shortcutKeyCode = shortcutKeyEvent.getKeyCode();
    inst.sendKeySync(pushMenuKey);
    inst.sendKeySync(new KeyEvent(KeyEvent.ACTION_DOWN, shortcutKeyCode));
    inst.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, shortcutKeyCode));
    inst.sendKeySync(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU));
}
Also used : KeyEvent(android.view.KeyEvent) Instrumentation(android.app.Instrumentation) KeyCharacterMap(android.view.KeyCharacterMap)

Aggregations

KeyCharacterMap (android.view.KeyCharacterMap)71 KeyEvent (android.view.KeyEvent)39 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 SuppressLint (android.annotation.SuppressLint)2 ContentResolver (android.content.ContentResolver)2 View (android.view.View)2 ITelephony (com.android.internal.telephony.ITelephony)2