本文整理汇总了Java中android.view.KeyEvent.getMetaState方法的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.getMetaState方法的具体用法?Java KeyEvent.getMetaState怎么用?Java KeyEvent.getMetaState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.getMetaState方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findItemsWithShortcutForKey
import android.view.KeyEvent; //导入方法依赖的package包/类
void findItemsWithShortcutForKey(List<MenuItemImpl> items, int keyCode, KeyEvent event) {
boolean qwerty = isQwertyMode();
int metaState = event.getMetaState();
KeyData possibleChars = new KeyData();
if (event.getKeyData(possibleChars) || keyCode == 67) {
int N = this.mItems.size();
for (int i = 0; i < N; i++) {
MenuItemImpl item = (MenuItemImpl) this.mItems.get(i);
if (item.hasSubMenu()) {
((MenuBuilder) item.getSubMenu()).findItemsWithShortcutForKey(items, keyCode, event);
}
char shortcutChar = qwerty ? item.getAlphabeticShortcut() : item.getNumericShortcut();
if ((metaState & 5) == 0 && shortcutChar != '\u0000' && ((shortcutChar == possibleChars.meta[0] || shortcutChar == possibleChars.meta[2] || (qwerty && shortcutChar == '\b' && keyCode == 67)) && item.isEnabled())) {
items.add(item);
}
}
}
}
示例2: findItemWithShortcutForKey
import android.view.KeyEvent; //导入方法依赖的package包/类
MenuItemImpl findItemWithShortcutForKey(int keyCode, KeyEvent event) {
ArrayList<MenuItemImpl> items = this.mTempShortcutItemList;
items.clear();
findItemsWithShortcutForKey(items, keyCode, event);
if (items.isEmpty()) {
return null;
}
int metaState = event.getMetaState();
KeyData possibleChars = new KeyData();
event.getKeyData(possibleChars);
int size = items.size();
if (size == 1) {
return (MenuItemImpl) items.get(0);
}
boolean qwerty = isQwertyMode();
for (int i = 0; i < size; i++) {
MenuItemImpl item = (MenuItemImpl) items.get(i);
char shortcutChar = qwerty ? item.getAlphabeticShortcut() : item.getNumericShortcut();
if ((shortcutChar == possibleChars.meta[0] && (metaState & 2) == 0) || ((shortcutChar == possibleChars.meta[2] && (metaState & 2) != 0) || (qwerty && shortcutChar == '\b' && keyCode == 67))) {
return item;
}
}
return null;
}
示例3: onKeyDown
import android.view.KeyEvent; //导入方法依赖的package包/类
public void onKeyDown(@Nonnull final KeyEvent keyEvent) {
if (DEBUG) {
Log.d(TAG, "EmojiHotKeys.onKeyDown() - " + mName + " - considering " + keyEvent);
}
final Pair<Integer, Integer> key =
Pair.create(keyEvent.getKeyCode(), keyEvent.getMetaState());
if (mKeySet.contains(key)) {
if (DEBUG) {
Log.d(TAG, "EmojiHotKeys.onKeyDown() - " + mName + " - enabling action");
}
mCanFire = true;
mMetaState = keyEvent.getMetaState();
} else if (mCanFire) {
if (DEBUG) {
Log.d(TAG, "EmojiHotKeys.onKeyDown() - " + mName + " - disabling action");
}
mCanFire = false;
}
}
示例4: findItemsWithShortcutForKey
import android.view.KeyEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
void findItemsWithShortcutForKey(List<MenuItemImpl> items, int keyCode, KeyEvent event) {
final boolean qwerty = isQwertyMode();
final int metaState = event.getMetaState();
final KeyCharacterMap.KeyData possibleChars = new KeyCharacterMap.KeyData();
// Get the chars associated with the keyCode (i.e using any chording combo)
final boolean isKeyCodeMapped = event.getKeyData(possibleChars);
// The delete key is not mapped to '\b' so we treat it specially
if (!isKeyCodeMapped && (keyCode != KeyEvent.KEYCODE_DEL)) {
return;
}
// Look for an item whose shortcut is this key.
final int N = mItems.size();
for (int i = 0; i < N; i++) {
MenuItemImpl item = mItems.get(i);
if (item.hasSubMenu()) {
((MenuBuilder)item.getSubMenu()).findItemsWithShortcutForKey(items, keyCode, event);
}
final char shortcutChar = qwerty ? item.getAlphabeticShortcut() : item.getNumericShortcut();
if (((metaState & (KeyEvent.META_SHIFT_ON | KeyEvent.META_SYM_ON)) == 0) &&
(shortcutChar != 0) &&
(shortcutChar == possibleChars.meta[0]
|| shortcutChar == possibleChars.meta[2]
|| (qwerty && shortcutChar == '\b' &&
keyCode == KeyEvent.KEYCODE_DEL)) &&
item.isEnabled()) {
items.add(item);
}
}
}
示例5: findItemWithShortcutForKey
import android.view.KeyEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
MenuItemImpl findItemWithShortcutForKey(int keyCode, KeyEvent event) {
// Get all items that can be associated directly or indirectly with the keyCode
ArrayList<MenuItemImpl> items = mTempShortcutItemList;
items.clear();
findItemsWithShortcutForKey(items, keyCode, event);
if (items.isEmpty()) {
return null;
}
final int metaState = event.getMetaState();
final KeyCharacterMap.KeyData possibleChars = new KeyCharacterMap.KeyData();
// Get the chars associated with the keyCode (i.e using any chording combo)
event.getKeyData(possibleChars);
// If we have only one element, we can safely returns it
final int size = items.size();
if (size == 1) {
return items.get(0);
}
final boolean qwerty = isQwertyMode();
// If we found more than one item associated with the key,
// we have to return the exact match
for (int i = 0; i < size; i++) {
final MenuItemImpl item = items.get(i);
final char shortcutChar = qwerty ? item.getAlphabeticShortcut() :
item.getNumericShortcut();
if ((shortcutChar == possibleChars.meta[0] &&
(metaState & KeyEvent.META_ALT_ON) == 0)
|| (shortcutChar == possibleChars.meta[2] &&
(metaState & KeyEvent.META_ALT_ON) != 0)
|| (qwerty && shortcutChar == '\b' &&
keyCode == KeyEvent.KEYCODE_DEL)) {
return item;
}
}
return null;
}
示例6: onKeyUp
import android.view.KeyEvent; //导入方法依赖的package包/类
public void onKeyUp(@Nonnull final KeyEvent keyEvent) {
if (DEBUG) {
Log.d(TAG, "EmojiHotKeys.onKeyUp() - " + mName + " - considering " + keyEvent);
}
final int keyCode = keyEvent.getKeyCode();
int metaState = keyEvent.getMetaState();
if (KeyEvent.isModifierKey(keyCode)) {
// Try restoring meta stat in case the released key was a modifier.
// I am sure one can come up with scenarios to break this, but it
// seems to work well in practice.
metaState |= mMetaState;
}
final Pair<Integer, Integer> key = Pair.create(keyCode, metaState);
if (mKeySet.contains(key)) {
if (mCanFire) {
if (!keyEvent.isCanceled()) {
if (DEBUG) {
Log.d(TAG, "EmojiHotKeys.onKeyUp() - " + mName + " - firing action");
}
action();
} else {
// This key up event was a part of key combinations and
// should be ignored.
if (DEBUG) {
Log.d(TAG, "EmojiHotKeys.onKeyUp() - " + mName + " - canceled, ignoring action");
}
}
mCanFire = false;
}
}
if (mCanFire) {
if (DEBUG) {
Log.d(TAG, "EmojiHotKeys.onKeyUp() - " + mName + " - disabling action");
}
mCanFire = false;
}
}
示例7: onKeyDown
import android.view.KeyEvent; //导入方法依赖的package包/类
/**
* Use this to monitor key events being delivered to the application.
* We get first crack at them, and can either resume them or let them
* continue to the app.
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Log.v("SpartacusRex","SOFT : onKeyDown "+ keyCode+" "+event.getMetaState());
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
// The InputMethodService already takes care of the back
// key for us, to dismiss the input method if it is shown.
// However, our keyboard could be showing a pop-up window
// that back should dismiss, so we first allow it to do that.
if (event.getRepeatCount() == 0 && mInputView != null) {
if (mInputView.handleBack()) {
return true;
}
}
break;
case KeyEvent.KEYCODE_DEL:
// Special handling of the delete key: if we currently are
// composing text for the user, we want to modify that instead
// of let the application to the delete itself.
if (mComposing.length() > 0) {
onKey(Keyboard.KEYCODE_DELETE, null);
return true;
}
break;
case KeyEvent.KEYCODE_ENTER:
// Let the underlying text editor always handle these.
return false;
default:
// For all other keys, if we want to do transformations on
// text being entered with a hard keyboard, we need to process
// it and do the appropriate action.
if (PROCESS_HARD_KEYS) {
if (keyCode == KeyEvent.KEYCODE_SPACE
&& (event.getMetaState() & KeyEvent.META_ALT_ON) != 0) {
// A silly example: in our input method, Alt+Space
// is a shortcut for 'android' in lower case.
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
// First, tell the editor that it is no longer in the
// shift state, since we are consuming this.
ic.clearMetaKeyStates(KeyEvent.META_ALT_ON);
keyDownUp(KeyEvent.KEYCODE_A);
keyDownUp(KeyEvent.KEYCODE_N);
keyDownUp(KeyEvent.KEYCODE_D);
keyDownUp(KeyEvent.KEYCODE_R);
keyDownUp(KeyEvent.KEYCODE_O);
keyDownUp(KeyEvent.KEYCODE_I);
keyDownUp(KeyEvent.KEYCODE_D);
// And we consume this event.
return true;
}
}
if (mPredictionOn && translateKeyDown(keyCode, event)) {
return true;
}
}
}
return super.onKeyDown(keyCode, event);
}
示例8: onKeyDown
import android.view.KeyEvent; //导入方法依赖的package包/类
@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;
}