本文整理汇总了Java中android.view.KeyEvent.getKeyCode方法的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.getKeyCode方法的具体用法?Java KeyEvent.getKeyCode怎么用?Java KeyEvent.getKeyCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.getKeyCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeKeyEvent
import android.view.KeyEvent; //导入方法依赖的package包/类
/**
* 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.
*
* @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;
}
示例2: onKey
import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (mPopup == null || mPopup.getListView() == null) return false;
if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
event.startTracking();
v.getKeyDispatcherState().startTracking(event, this);
return true;
} else if (event.getAction() == KeyEvent.ACTION_UP) {
v.getKeyDispatcherState().handleUpEvent(event);
if (event.isTracking() && !event.isCanceled()) {
dismiss();
return true;
}
}
}
return false;
}
示例3: dispatchKeyEvent
import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
if (event.getRepeatCount() == 0 && (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_SPACE)) {
doPauseResume();
show(sDefaultTimeout);
if (mPauseButton != null)
mPauseButton.requestFocus();
return true;
} else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP) {
if (mPlayer.isPlaying()) {
mPlayer.pause();
updatePausePlay();
}
return true;
} else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) {
hide();
return true;
} else {
show(sDefaultTimeout);
}
return super.dispatchKeyEvent(event);
}
示例4: dispatchKeyEvent
import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
// 监测音量变化
if (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN
|| event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) {
int volume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
if (currentVolume != volume) {
currentVolume = volume;
volumeSeekBar.setProgress(currentVolume);
}
if (isPrepared) {
setLayoutVisibility(View.VISIBLE, true);
}
}
return super.dispatchKeyEvent(event);
}
示例5: executeKeyEvent
import android.view.KeyEvent; //导入方法依赖的package包/类
/**
* 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.
*
* @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;
}
示例6: sendKeyEvent
import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean sendKeyEvent(KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
if (event.getKeyCode() >= KeyEvent.KEYCODE_0
&& event.getKeyCode() <= KeyEvent.KEYCODE_9) {
char c = event.getKeyCharacterMap().getNumber(event.getKeyCode());
commitText(String.valueOf(c), 1);
} else if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
deleteSurroundingText(1, 0);
}
}
return super.sendKeyEvent(event);
}
示例7: dispatchKeyEvent
import android.view.KeyEvent; //导入方法依赖的package包/类
/**
* Called to process key events. You can override this to intercept all
* key events before they are dispatched to the window. Be sure to call
* this implementation for key events that should be handled normally.
*
* @param event The key event.
*
* @return boolean Return true if this event was consumed.
*/
public boolean dispatchKeyEvent(KeyEvent event) {
onUserInteraction();
// Let action bars open menus in response to the menu key prioritized over
// the window handling it
final int keyCode = event.getKeyCode();
if (keyCode == KeyEvent.KEYCODE_MENU &&
mActionBar != null && mActionBar.onMenuKeyEvent(event)) {
return true;
} else if (event.isCtrlPressed() &&
event.getUnicodeChar(event.getMetaState() & ~KeyEvent.META_CTRL_MASK) == '<') {
// Capture the Control-< and send focus to the ActionBar
final int action = event.getAction();
if (action == KeyEvent.ACTION_DOWN) {
final ActionBar actionBar = getActionBar();
if (actionBar != null && actionBar.isShowing() && actionBar.requestFocus()) {
mEatKeyUpEvent = true;
return true;
}
} else if (action == KeyEvent.ACTION_UP && mEatKeyUpEvent) {
mEatKeyUpEvent = false;
return true;
}
}
Window win = getWindow();
if (win.superDispatchKeyEvent(event)) {
return true;
}
View decor = mDecor;
if (decor == null) decor = win.getDecorView();
return event.dispatch(this, decor != null
? decor.getKeyDispatcherState() : null, this);
}
示例8: processDelKey
import android.view.KeyEvent; //导入方法依赖的package包/类
public boolean processDelKey(KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL
&& getText().length() == 0 && !toBeDeleted)
{
toBeDeleted = true;
if (formulaChangeIf != null)
{
formulaChangeIf.onDelete(this);
return true;
}
}
return false;
}
示例9: dispatchKeyEvent
import android.view.KeyEvent; //导入方法依赖的package包/类
public boolean dispatchKeyEvent(KeyEvent keyEvent) {
f.b("SecureWebView", "-->dispatchKeyEvent, is device support: " + a);
if (!a) {
return super.dispatchKeyEvent(keyEvent);
}
if (keyEvent.getAction() != 0) {
return super.dispatchKeyEvent(keyEvent);
}
switch (keyEvent.getKeyCode()) {
case 4:
return super.dispatchKeyEvent(keyEvent);
case 66:
return super.dispatchKeyEvent(keyEvent);
case 67:
a.b = true;
return super.dispatchKeyEvent(keyEvent);
default:
if (keyEvent.getUnicodeChar() == 0) {
return super.dispatchKeyEvent(keyEvent);
}
if (SecureJsInterface.isPWDEdit) {
int unicodeChar = keyEvent.getUnicodeChar();
if ((unicodeChar >= 33 && unicodeChar <= 95) || (unicodeChar >= 97 && unicodeChar <= 125)) {
this.b = new KeyEvent(0, 17);
return super.dispatchKeyEvent(this.b);
}
}
return super.dispatchKeyEvent(keyEvent);
}
}
示例10: dispatchKeyEvent
import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (tvCursorManager != null && tvCursorManager.isShowCursor() && !isIMEMode) {
if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN ||
event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP ||
event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT ||
event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT ||
event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER)
return tvCursorManager.onDpadClicked(event);
}
return super.dispatchKeyEvent(event);
}
示例11: onKeyDown
import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
finish();
}
return super.onKeyDown(keyCode, event);
}
示例12: executeKeyEvent
import android.view.KeyEvent; //导入方法依赖的package包/类
/**
* 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.
*
* @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;
}
示例13: executeKeyEvent
import android.view.KeyEvent; //导入方法依赖的package包/类
public boolean executeKeyEvent(KeyEvent event) {
this.mTempRect.setEmpty();
if (canScroll()) {
boolean handled = false;
if (event.getAction() == 0) {
switch (event.getKeyCode()) {
case 19:
if (!event.isAltPressed()) {
handled = arrowScroll(33);
break;
}
handled = fullScroll(33);
break;
case 20:
if (!event.isAltPressed()) {
handled = arrowScroll(130);
break;
}
handled = fullScroll(130);
break;
case 62:
pageScroll(event.isShiftPressed() ? 33 : 130);
break;
}
}
return handled;
} else if (!isFocused() || event.getKeyCode() == 4) {
return false;
} else {
View currentFocused = findFocus();
if (currentFocused == this) {
currentFocused = null;
}
View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, 130);
if (nextFocused == null || nextFocused == this || !nextFocused.requestFocus(130)) {
return false;
}
return true;
}
}
示例14: dispatchKeyEvent
import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
//判断是否是按返回键
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
L.i("我按了BACK键");
if (mView.getParent() != null) {
wm.removeView(mView);
}
return true;
}
return false;
}
示例15: dispatchKeyEvent
import android.view.KeyEvent; //导入方法依赖的package包/类
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
final int keyCode = event.getKeyCode();
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
removeAllCallbacks();
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
case KeyEvent.KEYCODE_DPAD_UP:
if (!mHasSelectorWheel) {
break;
}
switch (event.getAction()) {
case KeyEvent.ACTION_DOWN:
if (mWrapSelectorWheel || (keyCode == KeyEvent.KEYCODE_DPAD_DOWN)
? getValue() < getMaxValue() : getValue() > getMinValue()) {
requestFocus();
mLastHandledDownDpadKeyCode = keyCode;
removeAllCallbacks();
if (mFlingScroller.isFinished()) {
changeValueByOne(keyCode == KeyEvent.KEYCODE_DPAD_DOWN);
}
return true;
}
break;
case KeyEvent.ACTION_UP:
if (mLastHandledDownDpadKeyCode == keyCode) {
mLastHandledDownDpadKeyCode = -1;
return true;
}
break;
}
}
return super.dispatchKeyEvent(event);
}