Search in sources :

Example 1 with KeyCharacterMap

use of android.view.KeyCharacterMap in project cw-omnibus by commonsguy.

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

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

the class PhoneWindow method preparePanel.

/**
     * Prepares the panel to either be opened or chorded. This creates the Menu
     * instance for the panel and populates it via the Activity callbacks.
     *
     * @param st The panel state to prepare.
     * @param event The event that triggered the preparing of the panel.
     * @return Whether the panel was prepared. If the panel should not be shown,
     *         returns false.
     */
public final boolean preparePanel(PanelFeatureState st, KeyEvent event) {
    if (isDestroyed()) {
        return false;
    }
    // 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 Callback cb = getCallback();
    if (cb != null) {
        st.createdPanelView = cb.onCreatePanelView(st.featureId);
    }
    final boolean isActionBarMenu = (st.featureId == FEATURE_OPTIONS_PANEL || st.featureId == FEATURE_ACTION_BAR);
    if (isActionBarMenu && mActionBar != null) {
        // Enforce ordering guarantees around events so that the action bar never
        // dispatches menu-related events before the panel is prepared.
        mActionBar.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 && mActionBar != null) {
                if (mActionMenuPresenterCallback == null) {
                    mActionMenuPresenterCallback = new ActionMenuPresenterCallback();
                }
                mActionBar.setMenu(st.menu, mActionMenuPresenterCallback);
            }
            // 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.
            st.menu.stopDispatchingItemsChanged();
            if ((cb == null) || !cb.onCreatePanelMenu(st.featureId, st.menu)) {
                // Ditch the menu created above
                st.setMenu(null);
                if (isActionBarMenu && mActionBar != null) {
                    // Don't show it in the action bar either
                    mActionBar.setMenu(null, mActionMenuPresenterCallback);
                }
                return false;
            }
            st.refreshMenuContent = 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.
        st.menu.stopDispatchingItemsChanged();
        // an opportunity to override frozen/restored state in onPrepare.
        if (st.frozenActionViewState != null) {
            st.menu.restoreActionViewStates(st.frozenActionViewState);
            st.frozenActionViewState = null;
        }
        if (!cb.onPreparePanel(st.featureId, st.createdPanelView, st.menu)) {
            if (isActionBarMenu && mActionBar != null) {
                // The app didn't want to show the menu for now but it still exists.
                // Clear it out of the action bar.
                mActionBar.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;
}
Also used : KeyCharacterMap(android.view.KeyCharacterMap)

Example 3 with KeyCharacterMap

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

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

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

the class PhoneWindow method preparePanel.

/**
     * Prepares the panel to either be opened or chorded. This creates the Menu
     * instance for the panel and populates it via the Activity callbacks.
     *
     * @param st The panel state to prepare.
     * @param event The event that triggered the preparing of the panel.
     * @return Whether the panel was prepared. If the panel should not be shown,
     *         returns false.
     */
public final boolean preparePanel(PanelFeatureState st, KeyEvent event) {
    if (isDestroyed()) {
        return false;
    }
    // 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 Callback cb = getCallback();
    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);
            }
            // 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.
            st.menu.stopDispatchingItemsChanged();
            if ((cb == null) || !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;
        }
        // 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.
        st.menu.stopDispatchingItemsChanged();
        // an opportunity to override frozen/restored state in onPrepare.
        if (st.frozenActionViewState != null) {
            st.menu.restoreActionViewStates(st.frozenActionViewState);
            st.frozenActionViewState = null;
        }
        if (!cb.onPreparePanel(st.featureId, 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;
}
Also used : KeyCharacterMap(android.view.KeyCharacterMap)

Example 5 with KeyCharacterMap

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

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)

Aggregations

KeyCharacterMap (android.view.KeyCharacterMap)72 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