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


Java KeyEvent.getKeyCode方法代码示例

本文整理汇总了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;
}
 
开发者ID:ruiqiao2017,项目名称:Renrentou,代码行数:34,代码来源:XCCycleViewPager.java

示例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;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:20,代码来源:AppMenu.java

示例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);
}
 
开发者ID:Leavessilent,项目名称:QuanMinTV,代码行数:24,代码来源:MediaController.java

示例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);
}
 
开发者ID:lbbniu,项目名称:CCDownload,代码行数:19,代码来源:ADMediaPlayActivity.java

示例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;
}
 
开发者ID:ChenTianSaber,项目名称:DailyZhiHu,代码行数:34,代码来源:CustomViewAbove.java

示例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);
}
 
开发者ID:Onum,项目名称:EditCodeView,代码行数:14,代码来源:EditCodeInputConnection.java

示例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);
}
 
开发者ID:JessYanCoding,项目名称:ProgressManager,代码行数:44,代码来源:a.java

示例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;
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:15,代码来源:CustomEditText.java

示例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);
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:31,代码来源:c.java

示例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);
}
 
开发者ID:jasonhancn,项目名称:AndroidTVCursor,代码行数:13,代码来源:TvCursorActivity.java

示例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);
}
 
开发者ID:fengdongfei,项目名称:CXJPadProject,代码行数:8,代码来源:FineActivity.java

示例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;
}
 
开发者ID:HueToYou,项目名称:ChatExchange-old,代码行数:41,代码来源:CustomViewAbove.java

示例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;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:41,代码来源:NestedScrollView.java

示例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;
}
 
开发者ID:lijizhi,项目名称:studydemo,代码行数:13,代码来源:SmsService.java

示例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);
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:37,代码来源:NumberPicker.java


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