Search in sources :

Example 26 with KeyCharacterMap

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

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

use of android.view.KeyCharacterMap in project AisenWeiBo by wangdan.

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

use of android.view.KeyCharacterMap in project remote-desktop-clients by iiordanov.

the class RemoteKeyboard method sendUnicodeChar.

/**
 * Tries to convert a unicode character to a KeyEvent and if successful sends with keyEvent().
 * @param unicodeChar
 * @param metaState
 */
public boolean sendUnicodeChar(char unicodeChar) {
    KeyCharacterMap fullKmap = KeyCharacterMap.load(KeyCharacterMap.FULL);
    KeyCharacterMap virtualKmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
    char[] s = new char[1];
    s[0] = unicodeChar;
    KeyEvent[] events = fullKmap.getEvents(s);
    // Failing with the FULL keymap, try the VIRTUAL_KEYBOARD one.
    if (events == null) {
        events = virtualKmap.getEvents(s);
    }
    boolean result = false;
    if (events != null) {
        for (int i = 0; i < events.length; i++) {
            KeyEvent evt = events[i];
            keyEvent(evt.getKeyCode(), evt);
            result = true;
        }
    } else {
        android.util.Log.e("RemoteKeyboard", "Could not use any keymap to generate KeyEvent for unicode: " + unicodeChar);
    }
    return result;
}
Also used : KeyEvent(android.view.KeyEvent) KeyCharacterMap(android.view.KeyCharacterMap)

Example 29 with KeyCharacterMap

use of android.view.KeyCharacterMap in project Libraries-for-Android-Developers by eoecn.

the class ActionBarSherlockCompat method preparePanel.

// /////////////////////////////////////////////////////////////////////////
// Menu callback lifecycle and creation
// /////////////////////////////////////////////////////////////////////////
private boolean preparePanel() {
    // Already prepared (isPrepared will be reset to false later)
    if (mMenuIsPrepared) {
        return true;
    }
    // Init the panel state's menu--return false if init failed
    if (mMenu == null || mMenuRefreshContent) {
        if (mMenu == null) {
            if (!initializePanelMenu() || (mMenu == null)) {
                return false;
            }
        }
        if (wActionBar != null) {
            wActionBar.setMenu(mMenu, this);
        }
        // Call callback, and return if it doesn't want to display menu.
        // Creating the panel menu will involve a lot of manipulation;
        // don't dispatch change events to presenters until we're done.
        mMenu.stopDispatchingItemsChanged();
        if (!callbackCreateOptionsMenu(mMenu)) {
            // Ditch the menu created above
            mMenu = null;
            if (wActionBar != null) {
                // Don't show it in the action bar either
                wActionBar.setMenu(null, this);
            }
            return false;
        }
        mMenuRefreshContent = false;
    }
    // Callback and return if the callback does not want to show the menu
    // Preparing the panel menu can involve a lot of manipulation;
    // don't dispatch change events to presenters until we're done.
    mMenu.stopDispatchingItemsChanged();
    // an opportunity to override frozen/restored state in onPrepare.
    if (mMenuFrozenActionViewState != null) {
        mMenu.restoreActionViewStates(mMenuFrozenActionViewState);
        mMenuFrozenActionViewState = null;
    }
    if (!callbackPrepareOptionsMenu(mMenu)) {
        if (wActionBar != null) {
            // The app didn't want to show the menu for now but it still exists.
            // Clear it out of the action bar.
            wActionBar.setMenu(null, this);
        }
        mMenu.startDispatchingItemsChanged();
        return false;
    }
    // Set the proper keymap
    KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
    mMenu.setQwertyMode(kmap.getKeyboardType() != KeyCharacterMap.NUMERIC);
    mMenu.startDispatchingItemsChanged();
    // Set other state
    mMenuIsPrepared = true;
    return true;
}
Also used : KeyCharacterMap(android.view.KeyCharacterMap)

Example 30 with KeyCharacterMap

use of android.view.KeyCharacterMap in project MaterialDateTimePicker by wdullaer.

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(mLocale).charAt(i);
            pmChar = mPmText.toLowerCase(mLocale).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)

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