Example usage for android.view KeyCharacterMap VIRTUAL_KEYBOARD

List of usage examples for android.view KeyCharacterMap VIRTUAL_KEYBOARD

Introduction

In this page you can find the example usage for android.view KeyCharacterMap VIRTUAL_KEYBOARD.

Prototype

int VIRTUAL_KEYBOARD

To view the source code for android.view KeyCharacterMap VIRTUAL_KEYBOARD.

Click Source Link

Document

The id of a generic virtual keyboard with a full layout that can be used to synthesize key events.

Usage

From source file:io.trigger.forge.android.modules.keyboard.API.java

private static Runnable typeString(final EditText webTextView, final String text) {
    return new Runnable() {
        @Override//from   w  w w  .j a  v  a2s  .  c o  m
        public void run() {
            webTextView.dispatchKeyEvent(
                    new KeyEvent(SystemClock.uptimeMillis(), text, KeyCharacterMap.VIRTUAL_KEYBOARD, 0));
        }
    };
}

From source file:android.support.v7.app.ToolbarActionBar.java

@Override
public boolean onKeyShortcut(int keyCode, KeyEvent ev) {
    Menu menu = getMenu();//from ww  w  .j  av  a 2 s .c om
    if (menu != null) {
        final KeyCharacterMap kmap = KeyCharacterMap
                .load(ev != null ? ev.getDeviceId() : KeyCharacterMap.VIRTUAL_KEYBOARD);
        menu.setQwertyMode(kmap.getKeyboardType() != KeyCharacterMap.NUMERIC);
        menu.performShortcut(keyCode, ev, 0);
    }
    // This action bar always returns true for handling keyboard shortcuts.
    // This will block the window from preparing a temporary panel to handle
    // keyboard shortcuts.
    return true;
}

From source file:com.actionbarsherlock.internal.ActionBarSherlockCompat.java

private boolean preparePanel() {
    // Already prepared (isPrepared will be reset to false later)
    if (mMenuIsPrepared) {
        return true;
    }//from   www .  ja va2s .  co m

    // 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();

    // Restore action view state before we prepare. This gives apps
    // 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;
}

From source file:com.gcloud.gaadi.ui.sleepbot.datetimepicker.time.TimePickerDialog.java

/**
 * Get the keycode value for AM and PM in the current language.
 *//*  www  . ja  va 2  s.co m*/
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 {
                    GCLog.e("Unable to find keycodes for AM and PM.");
                }
                break;
            }
        }
    }
    if (amOrPm == AM) {
        return mAmKeyCode;
    } else if (amOrPm == PM) {
        return mPmKeyCode;
    }

    return -1;
}

From source file:cn.fulldroid.lib.datetimepicker.time.TimePickerDialog.java

/**
 * Get the keycode value for AM and PM in the current language.
 *///from   w ww .j  av a2s  .  c  o  m
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;
}

From source file:com.azuyo.happybeing.fourmob.timepicker.TimePickerDialog.java

/**
 * Get the keycode value for AM and PM in the current language.
 *//*from  w  ww .j  a va2s  .  com*/
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;
}

From source file:com.philliphsu.bottomsheetpickers.time.grid.GridTimePickerDialog.java

/**
 * Get the keycode value for AM and PM in the current language.
 *///from   ww  w .jav a  2s .c  om
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 == HALF_DAY_1) {
        return mAmKeyCode;
    } else if (amOrPm == HALF_DAY_2) {
        return mPmKeyCode;
    }

    return -1;
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.SublimeTimePicker.java

/**
 * Get the keycode value for AM and PM in the current language.
 *///from   w w  w . j  ava 2  s.  co  m
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.
        final KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
        final CharSequence amText = mAmText.toLowerCase(mCurrentLocale);
        final CharSequence pmText = mPmText.toLowerCase(mCurrentLocale);
        final int N = Math.min(amText.length(), pmText.length());
        for (int i = 0; i < N; i++) {
            final char amChar = amText.charAt(i);
            final char pmChar = pmText.charAt(i);
            if (amChar != pmChar) {
                // There should be 4 events: a down and up for both AM and PM.
                final KeyEvent[] events = kcm.getEvents(new char[] { amChar, pmChar });
                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;
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

private boolean preparePanel(PanelFeatureState st, KeyEvent event) {
    if (isDestroyed()) {
        return false;
    }//from   w w  w.  ja  v a  2s.  c  o m

    // Already prepared (isPrepared will be reset to false later)
    if (st.isPrepared) {
        return true;
    }

    if ((mPreparedPanel != null) && (mPreparedPanel != st)) {
        // Another Panel is prepared and possibly open, so close it
        closePanel(mPreparedPanel, false);
    }

    final Window.Callback cb = getWindowCallback();

    if (cb != null) {
        st.createdPanelView = cb.onCreatePanelView(st.featureId);
    }

    final boolean isActionBarMenu = (st.featureId == FEATURE_OPTIONS_PANEL
            || st.featureId == FEATURE_ACTION_BAR);

    if (isActionBarMenu && mDecorContentParent != null) {
        // Enforce ordering guarantees around events so that the action bar never
        // dispatches menu-related events before the panel is prepared.
        mDecorContentParent.setMenuPrepared();
    }

    if (st.createdPanelView == null) {
        // Init the panel state's menu--return false if init failed
        if (st.menu == null || st.refreshMenuContent) {
            if (st.menu == null) {
                if (!initializePanelMenu(st) || (st.menu == null)) {
                    return false;
                }
            }

            if (isActionBarMenu && mDecorContentParent != null) {
                if (mActionMenuPresenterCallback == null) {
                    mActionMenuPresenterCallback = new ActionMenuPresenterCallback();
                }
                mDecorContentParent.setMenu(st.menu, mActionMenuPresenterCallback);
            }

            // Creating the panel menu will involve a lot of manipulation;
            // don't dispatch change events to presenters until we're done.
            st.menu.stopDispatchingItemsChanged();
            if (!cb.onCreatePanelMenu(st.featureId, st.menu)) {
                // Ditch the menu created above
                st.setMenu(null);

                if (isActionBarMenu && mDecorContentParent != null) {
                    // Don't show it in the action bar either
                    mDecorContentParent.setMenu(null, mActionMenuPresenterCallback);
                }

                return false;
            }

            st.refreshMenuContent = false;
        }

        // Preparing the panel menu can involve a lot of manipulation;
        // don't dispatch change events to presenters until we're done.
        st.menu.stopDispatchingItemsChanged();

        // Restore action view state before we prepare. This gives apps
        // an opportunity to override frozen/restored state in onPrepare.
        if (st.frozenActionViewState != null) {
            st.menu.restoreActionViewStates(st.frozenActionViewState);
            st.frozenActionViewState = null;
        }

        // Callback and return if the callback does not want to show the menu
        if (!cb.onPreparePanel(FEATURE_OPTIONS_PANEL, st.createdPanelView, st.menu)) {
            if (isActionBarMenu && mDecorContentParent != null) {
                // The app didn't want to show the menu for now but it still exists.
                // Clear it out of the action bar.
                mDecorContentParent.setMenu(null, mActionMenuPresenterCallback);
            }
            st.menu.startDispatchingItemsChanged();
            return false;
        }

        // Set the proper keymap
        KeyCharacterMap kmap = KeyCharacterMap
                .load(event != null ? event.getDeviceId() : KeyCharacterMap.VIRTUAL_KEYBOARD);
        st.qwertyMode = kmap.getKeyboardType() != KeyCharacterMap.NUMERIC;
        st.menu.setQwertyMode(st.qwertyMode);
        st.menu.startDispatchingItemsChanged();
    }

    // Set other state
    st.isPrepared = true;
    st.isHandled = false;
    mPreparedPanel = st;

    return true;
}

From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java

private boolean preparePanel(PanelFeatureState st, KeyEvent event) {
    if (isDestroyed()) {
        return false;
    }//from ww  w  . ja  v  a2s .c o  m

    // Already prepared (isPrepared will be reset to false later)
    if (st.isPrepared) {
        return true;
    }

    if ((mPreparedPanel != null) && (mPreparedPanel != st)) {
        // Another Panel is prepared and possibly open, so close it
        closePanel(mPreparedPanel, false);
    }

    final Window.Callback cb = getWindowCallback();

    if (cb != null) {
        st.createdPanelView = cb.onCreatePanelView(st.featureId);
    }

    final boolean isActionBarMenu = (st.featureId == FEATURE_OPTIONS_PANEL
            || st.featureId == FEATURE_SUPPORT_ACTION_BAR);

    if (isActionBarMenu && mDecorContentParent != null) {
        // Enforce ordering guarantees around events so that the action bar never
        // dispatches menu-related events before the panel is prepared.
        mDecorContentParent.setMenuPrepared();
    }

    if (st.createdPanelView == null
            && (!isActionBarMenu || !(peekSupportActionBar() instanceof ToolbarActionBar))) {
        // Since ToolbarActionBar handles the list options menu itself, we only want to
        // init this menu panel if we're not using a TAB.
        if (st.menu == null || st.refreshMenuContent) {
            if (st.menu == null) {
                if (!initializePanelMenu(st) || (st.menu == null)) {
                    return false;
                }
            }

            if (isActionBarMenu && mDecorContentParent != null) {
                if (mActionMenuPresenterCallback == null) {
                    mActionMenuPresenterCallback = new ActionMenuPresenterCallback();
                }
                mDecorContentParent.setMenu(st.menu, mActionMenuPresenterCallback);
            }

            // Creating the panel menu will involve a lot of manipulation;
            // don't dispatch change events to presenters until we're done.
            st.menu.stopDispatchingItemsChanged();
            if (!cb.onCreatePanelMenu(st.featureId, st.menu)) {
                // Ditch the menu created above
                st.setMenu(null);

                if (isActionBarMenu && mDecorContentParent != null) {
                    // Don't show it in the action bar either
                    mDecorContentParent.setMenu(null, mActionMenuPresenterCallback);
                }

                return false;
            }

            st.refreshMenuContent = false;
        }

        // Preparing the panel menu can involve a lot of manipulation;
        // don't dispatch change events to presenters until we're done.
        st.menu.stopDispatchingItemsChanged();

        // Restore action view state before we prepare. This gives apps
        // an opportunity to override frozen/restored state in onPrepare.
        if (st.frozenActionViewState != null) {
            st.menu.restoreActionViewStates(st.frozenActionViewState);
            st.frozenActionViewState = null;
        }

        // Callback and return if the callback does not want to show the menu
        if (!cb.onPreparePanel(FEATURE_OPTIONS_PANEL, st.createdPanelView, st.menu)) {
            if (isActionBarMenu && mDecorContentParent != null) {
                // The app didn't want to show the menu for now but it still exists.
                // Clear it out of the action bar.
                mDecorContentParent.setMenu(null, mActionMenuPresenterCallback);
            }
            st.menu.startDispatchingItemsChanged();
            return false;
        }

        // Set the proper keymap
        KeyCharacterMap kmap = KeyCharacterMap
                .load(event != null ? event.getDeviceId() : KeyCharacterMap.VIRTUAL_KEYBOARD);
        st.qwertyMode = kmap.getKeyboardType() != KeyCharacterMap.NUMERIC;
        st.menu.setQwertyMode(st.qwertyMode);
        st.menu.startDispatchingItemsChanged();
    }

    // Set other state
    st.isPrepared = true;
    st.isHandled = false;
    mPreparedPanel = st;

    return true;
}