当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent.KEYCODE_UNKNOWN属性代码示例

本文整理汇总了Java中android.view.KeyEvent.KEYCODE_UNKNOWN属性的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.KEYCODE_UNKNOWN属性的具体用法?Java KeyEvent.KEYCODE_UNKNOWN怎么用?Java KeyEvent.KEYCODE_UNKNOWN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.view.KeyEvent的用法示例。


在下文中一共展示了KeyEvent.KEYCODE_UNKNOWN属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendKeyEvent

public void sendKeyEvent(final KeyEvent keyEvent) {
    if (DEBUG_BATCH_NESTING) checkBatchEdit();
    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
        if (DEBUG_PREVIOUS_TEXT) checkConsistencyForDebug();
        // This method is only called for enter or backspace when speaking to old applications
        // (target SDK <= 15 (Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)), or for digits.
        // When talking to new applications we never use this method because it's inherently
        // racy and has unpredictable results, but for backward compatibility we continue
        // sending the key events for only Enter and Backspace because some applications
        // mistakenly catch them to do some stuff.
        switch (keyEvent.getKeyCode()) {
        case KeyEvent.KEYCODE_ENTER:
            mCommittedTextBeforeComposingText.append("\n");
            mExpectedSelStart += 1;
            mExpectedSelEnd = mExpectedSelStart;
            break;
        case KeyEvent.KEYCODE_DEL:
            if (0 == mComposingText.length()) {
                if (mCommittedTextBeforeComposingText.length() > 0) {
                    mCommittedTextBeforeComposingText.delete(
                            mCommittedTextBeforeComposingText.length() - 1,
                            mCommittedTextBeforeComposingText.length());
                }
            } else {
                mComposingText.delete(mComposingText.length() - 1, mComposingText.length());
            }
            if (mExpectedSelStart > 0 && mExpectedSelStart == mExpectedSelEnd) {
                // TODO: Handle surrogate pairs.
                mExpectedSelStart -= 1;
            }
            mExpectedSelEnd = mExpectedSelStart;
            break;
        case KeyEvent.KEYCODE_UNKNOWN:
            if (null != keyEvent.getCharacters()) {
                mCommittedTextBeforeComposingText.append(keyEvent.getCharacters());
                mExpectedSelStart += keyEvent.getCharacters().length();
                mExpectedSelEnd = mExpectedSelStart;
            }
            break;
        default:
            final String text = StringUtils.newSingleCodePointString(keyEvent.getUnicodeChar());
            mCommittedTextBeforeComposingText.append(text);
            mExpectedSelStart += text.length();
            mExpectedSelEnd = mExpectedSelStart;
            break;
        }
    }
    if (isConnected()) {
        mIC.sendKeyEvent(keyEvent);
    }
}
 
开发者ID:rkkr,项目名称:simple-keyboard,代码行数:51,代码来源:RichInputConnection.java

示例2: createIntent

/**
 * Constructs an intent from the given information and the search dialog state.
 *
 * @param action Intent action.
 * @param data Intent data, or <code>null</code>.
 * @param extraData Data for {@link SearchManager#EXTRA_DATA_KEY} or <code>null</code>.
 * @param query Intent query, or <code>null</code>.
 * @param actionKey The key code of the action key that was pressed,
 *        or {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg The message for the action key that was pressed,
 *        or <code>null</code> if none.
 * @return The intent.
 */
private Intent createIntent(String action, Uri data, String extraData, String query,
                                                        int actionKey, String actionMsg) {
    // Now build the Intent
    Intent intent = new Intent(action);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    // We need CLEAR_TOP to avoid reusing an old task that has other activities
    // on top of the one we want. We don't want to do this in in-app search though,
    // as it can be destructive to the activity stack.
    if (data != null) {
        intent.setData(data);
    }
    intent.putExtra(SearchManager.USER_QUERY, mUserQuery);
    if (query != null) {
        intent.putExtra(SearchManager.QUERY, query);
    }
    if (extraData != null) {
        intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData);
    }
    if (mAppSearchData != null) {
        intent.putExtra(SearchManager.APP_DATA, mAppSearchData);
    }
    if (actionKey != KeyEvent.KEYCODE_UNKNOWN) {
        intent.putExtra(SearchManager.ACTION_KEY, actionKey);
        intent.putExtra(SearchManager.ACTION_MSG, actionMsg);
    }
    intent.setComponent(mSearchable.getSearchActivity());
    return intent;
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:41,代码来源:SearchView.java

示例3: onKey

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    // Work-around for spurious key event from IME, bug #1639445
    if(action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    if(keyEvent.getUnicodeChar() == '=') {
        if(action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if(keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP && keyCode != KeyEvent.KEYCODE_DPAD_DOWN
            && keyCode != KeyEvent.KEYCODE_ENTER) {
        if(keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        return false;
    }

    /*
     * We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the
     * DOWN event isn't received, only the UP. So the workaround is to act
     * on UP... http://b/issue?id=1022478
     */

    if(action == KeyEvent.ACTION_UP) {
        switch(keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}
 
开发者ID:gigabytedevelopers,项目名称:CalcMate,代码行数:49,代码来源:EventListener.java

示例4: onKeyDown

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (LOG_KEY_EVENTS)
        Log.i(EmulatorDebug.LOG_TAG, "onKeyDown(keyCode=" + keyCode + ", isSystem()=" + event.isSystem() + ", event=" + event + ")");
    if (mEmulator == null) return true;

    if (mClient.onKeyDown(keyCode, event, mTermSession)) {
        invalidate();
        return true;
    } else if (event.isSystem() && (!mClient.shouldBackButtonBeMappedToEscape() || keyCode != KeyEvent.KEYCODE_BACK)) {
        return super.onKeyDown(keyCode, event);
    } else if (event.getAction() == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        mTermSession.write(event.getCharacters());
        return true;
    }

    final int metaState = event.getMetaState();
    final boolean controlDownFromEvent = event.isCtrlPressed();
    final boolean leftAltDownFromEvent = (metaState & KeyEvent.META_ALT_LEFT_ON) != 0;
    final boolean rightAltDownFromEvent = (metaState & KeyEvent.META_ALT_RIGHT_ON) != 0;

    int keyMod = 0;
    if (controlDownFromEvent) keyMod |= KeyHandler.KEYMOD_CTRL;
    if (event.isAltPressed()) keyMod |= KeyHandler.KEYMOD_ALT;
    if (event.isShiftPressed()) keyMod |= KeyHandler.KEYMOD_SHIFT;
    if (handleKeyCode(keyCode, keyMod)) {
        if (LOG_KEY_EVENTS) Log.i(EmulatorDebug.LOG_TAG, "handleKeyCode() took key event");
        return true;
    }

    // Clear Ctrl since we handle that ourselves:
    int bitsToClear = KeyEvent.META_CTRL_MASK;
    if (rightAltDownFromEvent) {
        // Let right Alt/Alt Gr be used to compose characters.
    } else {
        // Use left alt to send to terminal (e.g. Left Alt+B to jump back a word), so remove:
        bitsToClear |= KeyEvent.META_ALT_ON | KeyEvent.META_ALT_LEFT_ON;
    }
    int effectiveMetaState = event.getMetaState() & ~bitsToClear;

    int result = event.getUnicodeChar(effectiveMetaState);
    if (LOG_KEY_EVENTS)
        Log.i(EmulatorDebug.LOG_TAG, "KeyEvent#getUnicodeChar(" + effectiveMetaState + ") returned: " + result);
    if (result == 0) {
        return true;
    }

    int oldCombiningAccent = mCombiningAccent;
    if ((result & KeyCharacterMap.COMBINING_ACCENT) != 0) {
        // If entered combining accent previously, write it out:
        if (mCombiningAccent != 0)
            inputCodePoint(mCombiningAccent, controlDownFromEvent, leftAltDownFromEvent);
        mCombiningAccent = result & KeyCharacterMap.COMBINING_ACCENT_MASK;
    } else {
        if (mCombiningAccent != 0) {
            int combinedChar = KeyCharacterMap.getDeadChar(mCombiningAccent, result);
            if (combinedChar > 0) result = combinedChar;
            mCombiningAccent = 0;
        }
        inputCodePoint(result, controlDownFromEvent, leftAltDownFromEvent);
    }

    if (mCombiningAccent != oldCombiningAccent) invalidate();

    if (onAutoCompleteListener != null) {
        if (event.isPrintingKey()) {
            char printingChar = (char) event.getUnicodeChar(metaState);
            if (printingChar != '\b') {
                // ASCII chars
                onAutoCompleteListener.onCompletionRequired(new String(new char[]{printingChar}));
            }
        }
    }

    return true;
}
 
开发者ID:NeoTerm,项目名称:NeoTerm,代码行数:76,代码来源:TerminalView.java


注:本文中的android.view.KeyEvent.KEYCODE_UNKNOWN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。