Example usage for android.view KeyEvent KEYCODE_TAB

List of usage examples for android.view KeyEvent KEYCODE_TAB

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_TAB.

Prototype

int KEYCODE_TAB

To view the source code for android.view KeyEvent KEYCODE_TAB.

Click Source Link

Document

Key code constant: Tab key.

Usage

From source file:nu.yona.timepicker.time.TimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.//from   w  w w  .  j  ava  2  s. c o m
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        if (isCancelable())
            dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if (mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes(),
                    mTimePicker.getSeconds());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;

                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2
            || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8
            || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}

From source file:com.appunite.list.GridView.java

private boolean commonKey(int keyCode, int count, KeyEvent event) {
    if (mAdapter == null) {
        return false;
    }/*from w  w  w  .j a v a  2 s. co m*/

    if (mDataChanged) {
        layoutChildren();
    }

    boolean handled = false;
    int action = event.getAction();

    if (action != KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_LEFT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_RIGHT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_UP);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_DOWN);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded();
                if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) {
                    keyPressed();
                    handled = true;
                }
            }
            break;

        case KeyEvent.KEYCODE_SPACE:
            if (mPopup == null || !mPopup.isShowing()) {
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
                }
            }
            break;

        case KeyEvent.KEYCODE_PAGE_UP:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_HOME:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_END:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_TAB:
            // XXX Sometimes it is useful to be able to TAB through the items in
            //     a GridView sequentially.  Unfortunately this can create an
            //     asymmetry in TAB navigation order unless the list selection
            //     always reverts to the top or bottom when receiving TAB focus from
            //     another widget.  Leaving this behavior disabled for now but
            //     perhaps it should be configurable (and more comprehensive).
            if (false) {
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = resurrectSelectionIfNeeded() || sequenceScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = resurrectSelectionIfNeeded() || sequenceScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }

    if (handled) {
        return true;
    }

    if (sendToTextFilter(keyCode, count, event)) {
        return true;
    }

    switch (action) {
    case KeyEvent.ACTION_DOWN:
        return super.onKeyDown(keyCode, event);
    case KeyEvent.ACTION_UP:
        return super.onKeyUp(keyCode, event);
    case KeyEvent.ACTION_MULTIPLE:
        return super.onKeyMultiple(keyCode, count, event);
    default:
        return false;
    }
}

From source file:android.webkit.cts.WebViewTest.java

public void testRequestFocusNodeHref() throws Throwable {
    if (!NullWebViewUtils.isWebViewAvailable()) {
        return;/*  ww w.  j  a v a 2  s.  co m*/
    }
    startWebServer(false);
    String url1 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL1);
    String url2 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL2);
    final String links = "<DL><p><DT><A HREF=\"" + url1 + "\">HTML_URL1</A><DT><A HREF=\"" + url2
            + "\">HTML_URL2</A></DL><p>";
    mOnUiThread.loadDataAndWaitForCompletion("<html><body>" + links + "</body></html>", "text/html", null);
    getInstrumentation().waitForIdleSync();

    final HrefCheckHandler handler = new HrefCheckHandler(mWebView.getHandler().getLooper());
    final Message hrefMsg = new Message();
    hrefMsg.setTarget(handler);

    // focus on first link
    handler.reset();
    getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_TAB);
    mOnUiThread.requestFocusNodeHref(hrefMsg);
    new PollingCheck() {
        @Override
        protected boolean check() {
            boolean done = false;
            if (handler.hasCalledHandleMessage()) {
                if (handler.mResultUrl != null) {
                    done = true;
                } else {
                    handler.reset();
                    Message newMsg = new Message();
                    newMsg.setTarget(handler);
                    mOnUiThread.requestFocusNodeHref(newMsg);
                }
            }
            return done;
        }
    }.run();
    assertEquals(url1, handler.getResultUrl());

    // focus on second link
    handler.reset();
    final Message hrefMsg2 = new Message();
    hrefMsg2.setTarget(handler);
    getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_TAB);
    mOnUiThread.requestFocusNodeHref(hrefMsg2);
    new PollingCheck() {
        @Override
        protected boolean check() {
            boolean done = false;
            final String url2 = mWebServer.getAssetUrl(TestHtmlConstants.HTML_URL2);
            if (handler.hasCalledHandleMessage()) {
                if (handler.mResultUrl != null && handler.mResultUrl.equals(url2)) {
                    done = true;
                } else {
                    handler.reset();
                    Message newMsg = new Message();
                    newMsg.setTarget(handler);
                    mOnUiThread.requestFocusNodeHref(newMsg);
                }
            }
            return done;
        }
    }.run();
    assertEquals(url2, handler.getResultUrl());

    mOnUiThread.requestFocusNodeHref(null);
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

private void sendTab() {
    InputConnection ic = getCurrentInputConnection();
    if (ic == null)
        return;/*w ww .  j a  v  a2 s. c om*/
    boolean tabHack = isTerminalEmulation();

    // Note: tab and ^I don't work in ConnectBot, hackish workaround
    if (tabHack) {
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I));
    } else {
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_TAB));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_TAB));
    }
}

From source file:com.chenglong.muscle.ui.LazyViewPager.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.//from   w  w w. java 2 s .c  o  m
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and
                // FOCUS_BACKWARD
                // before Android 3.0. Ignore the include_tab key on those
                // devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }
    return handled;
}

From source file:beichen.douban.ui.view.LazyViewPager.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy./*from w  ww.  j a va 2 s . co  m*/
 * 
 * @param event
 *            The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and
                // FOCUS_BACKWARD
                // before Android 3.0. Ignore the tab key on those
                // devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }
    return handled;
}

From source file:cn.xiaowen.news.view.LazyViewPager.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.// w  w  w .  jav  a2s.  co m
 * 
 * @param event
 *            The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            handled = arrowScroll(FOCUS_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            handled = arrowScroll(FOCUS_RIGHT);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and
                // FOCUS_BACKWARD
                // before Android 3.0. Ignore the tab key on those devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }
    return handled;
}

From source file:com.tandong.sa.sherlock.widget.SearchView.java

/**
 * React to the user typing while in the suggestions list. First, check for
 * action keys. If not handled, try refocusing regular characters into the
 * EditText.//  w  w w.ja  v a2s  . co  m
 */
private boolean onSuggestionsKey(View v, int keyCode, KeyEvent event) {
    // guard against possible race conditions (late arrival after dismiss)
    if (mSearchable == null) {
        return false;
    }
    if (mSuggestionsAdapter == null) {
        return false;
    }
    if (event.getAction() == KeyEvent.ACTION_DOWN && KeyEventCompat.hasNoModifiers(event)) {
        // First, check for enter or search (both of which we'll treat as a
        // "click")
        if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_SEARCH
                || keyCode == KeyEvent.KEYCODE_TAB) {
            int position = mQueryTextView.getListSelection();
            return onItemClicked(position, KeyEvent.KEYCODE_UNKNOWN, null);
        }

        // Next, check for left/right moves, which we use to "return" the
        // user to the edit view
        if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
            // give "focus" to text editor, with cursor at the beginning if
            // left key, at end if right key
            // TODO: Reverse left/right for right-to-left languages, e.g.
            // Arabic
            int selPoint = (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) ? 0 : mQueryTextView.length();
            mQueryTextView.setSelection(selPoint);
            mQueryTextView.setListSelection(0);
            mQueryTextView.clearListSelection();
            ensureImeVisible(mQueryTextView, true);

            return true;
        }

        // Next, check for an "up and out" move
        if (keyCode == KeyEvent.KEYCODE_DPAD_UP && 0 == mQueryTextView.getListSelection()) {
            // TODO: restoreUserQuery();
            // let ACTV complete the move
            return false;
        }

        // Next, check for an "action key"
        // TODO SearchableInfo.ActionKeyInfo actionKey =
        // mSearchable.findActionKey(keyCode);
        // TODO if ((actionKey != null)
        // TODO && ((actionKey.getSuggestActionMsg() != null) || (actionKey
        // TODO .getSuggestActionMsgColumn() != null))) {
        // TODO // launch suggestion using action key column
        // TODO int position = mQueryTextView.getListSelection();
        // TODO if (position != ListView.INVALID_POSITION) {
        // TODO Cursor c = mSuggestionsAdapter.getCursor();
        // TODO if (c.moveToPosition(position)) {
        // TODO final String actionMsg = getActionKeyMessage(c, actionKey);
        // TODO if (actionMsg != null && (actionMsg.length() > 0)) {
        // TODO return onItemClicked(position, keyCode, actionMsg);
        // TODO }
        // TODO }
        // TODO }
        // TODO }
    }
    return false;
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

private void sendTab() {
    InputConnection ic = getCurrentInputConnection();
    boolean tabHack = isConnectbot() && mConnectbotTabHack;

    // FIXME: tab and ^I don't work in connectbot, hackish workaround
    if (tabHack) {
        if (mModAlt) {
            // send ESC prefix
            ic.commitText(Character.toString((char) 27), 1);
        }//from  w  w w  . j a  v a  2  s  .  c  o m
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I));
        ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I));
    } else {
        sendModifiedKeyDownUp(KeyEvent.KEYCODE_TAB);
    }
}

From source file:administrator.example.com.myscrollview.VerticalViewPager.java

/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.//from  w  w w .  j av a2 s. c  o  m
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_DPAD_UP:
            handled = arrowScroll(FOCUS_UP);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            handled = arrowScroll(FOCUS_DOWN);
            break;
        case KeyEvent.KEYCODE_TAB:
            if (Build.VERSION.SDK_INT >= 11) {
                // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                // before Android 3.0. Ignore the tab key on those devices.
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = arrowScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = arrowScroll(FOCUS_BACKWARD);
                } /* end of if */
            } /* end of if */
            break;
        } /* end of switch */
    } /* end of if */
    return handled;
}