本文整理汇总了Java中android.view.KeyEvent类的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent类的具体用法?Java KeyEvent怎么用?Java KeyEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyEvent类属于android.view包,在下文中一共展示了KeyEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onKeyDown
import android.view.KeyEvent; //导入依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
// Don't allow this value to go to 0. It shuts the screen off.
if (minBrightness > 1) {
minBrightness -= 1;
updateDisplay();
Util.setActivityBrightness(getWindow(), minBrightness);
}
return true;
case KeyEvent.KEYCODE_VOLUME_UP:
if (minBrightness < 255) {
minBrightness += 1;
updateDisplay();
Util.setActivityBrightness(getWindow(), minBrightness);
}
return true;
default:
return super.onKeyDown(keyCode, event);
}
}
示例2: onKeyDown
import android.view.KeyEvent; //导入依赖的package包/类
/**
* 顶部焦点获取
*
* @param keyCode
* @param event
* @return
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean focusFlag = false;
for (View v : mViews) {
if (v.isFocused()) {
focusFlag = true;
}
}
Log.d(TAG, "code:" + keyCode + " flag:" + focusFlag);
if (focusFlag) {
if (KeyEvent.KEYCODE_DPAD_LEFT == keyCode) {
if (mCurrentIndex > 0) {
mViews[--mCurrentIndex].requestFocus();
}
return true;
} else if (KeyEvent.KEYCODE_DPAD_RIGHT == keyCode) {
if (mCurrentIndex < 2) {
mViews[++mCurrentIndex].requestFocus();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
示例3: onKey
import android.view.KeyEvent; //导入依赖的package包/类
@Override
public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection() ;
playclick(primaryCode);
switch (primaryCode) {
case Keyboard.KEYCODE_DELETE:
ic.deleteSurroundingText(1, 0);
break;
case Keyboard.KEYCODE_SHIFT:
caps = !caps;
keyboard.setShifted(caps);
kv.invalidateAllKeys();
break;
case Keyboard.KEYCODE_DONE:
ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
break;
default:
char code = (char) primaryCode;
if(Character.isLetter(code) && caps) {
code = Character.toUpperCase(code);
}
ic.commitText(String.valueOf(code), 1);
break;
}
}
示例4: onReceive
import android.view.KeyEvent; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
String reason = intent.getStringExtra(SYSTEM_REASON);
if (TextUtils.equals(reason, SYSTEM_HOME_KEY)) {
//表示按了home键,程序到了后台
if (currentKeyCode==KeyEvent.KEYCODE_HOME && isLongPressedHome){
isLongPressedHome=false;
return;
}
}else if(TextUtils.equals(reason, SYSTEM_HOME_KEY_LONG)){
//表示长按home键,显示最近使用的程序列表
if (currentKeyCode==KeyEvent.KEYCODE_APP_SWITCH && isLongPressedRecent){
isLongPressedRecent=false;
return;
}
}else {
return;
}
refreshViewState(false);
}
}
示例5: setButtonPlumbedToJs
import android.view.KeyEvent; //导入依赖的package包/类
@Override
public void setButtonPlumbedToJs(int keyCode, boolean override) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
case KeyEvent.KEYCODE_VOLUME_UP:
case KeyEvent.KEYCODE_BACK:
case KeyEvent.KEYCODE_MENU:
// TODO: Why are search and menu buttons handled separately?
if (override) {
boundKeyCodes.add(keyCode);
} else {
boundKeyCodes.remove(keyCode);
}
return;
default:
throw new IllegalArgumentException("Unsupported keycode: " + keyCode);
}
}
示例6: run
import android.view.KeyEvent; //导入依赖的package包/类
@Override
public void run() {
try {
int data = peripheralDevice.getTouched();
for (int i = 0; i < Mpr121.NB_ELECTRODES; i++) {
if ((data & (1 << i)) != 0) {
if (!inputStatus[i]) {
Log.d(TAG, "#" + i + " touched");
inputStatus[i] = true;
emitInputEvents(keycodes[i], KeyEvent.ACTION_DOWN);
}
} else {
if (inputStatus[i]) {
Log.d(TAG, "#" + i + " released");
inputStatus[i] = false;
emitInputEvents(keycodes[i], KeyEvent.ACTION_UP);
}
}
}
} catch (IOException e) {
Log.e(TAG, "Error getting data from peripheral device", e);
} finally {
inputHandler.postDelayed(this, SOFTWAREPOLL_DELAY_MS);
}
}
示例7: challengePressBackAndQuit
import android.view.KeyEvent; //导入依赖的package包/类
@Test
public void challengePressBackAndQuit() {
onView(withId(R.id.search)).perform(click());
onView(isRoot()).perform(waitForMatch(withId(R.id.empty_layout), UI_TEST_TIMEOUT));
onView(isAssignableFrom(EditText.class)).perform(typeText("R"), pressKey(KeyEvent.KEYCODE_ENTER));
tryIsDisplayed(withText("Runnest IHL"), UI_TEST_TIMEOUT);
onView(withText("Runnest IHL")).perform(click());
//Create challenge
onView(isRoot()).perform(waitForMatch(withId(R.id.main_layout), UI_TEST_TIMEOUT));
onView(withText(R.string.challenge)).perform(click());
tryIsDisplayed(withId(R.id.define_challenge), UI_TEST_TIMEOUT);
onView(withId(R.id.customize_positive_btn)).perform(click());
//Wait
Espresso.pressBack();
tryIsDisplayed(withId(android.R.id.button1), UI_TEST_TIMEOUT);
onView(withText(R.string.quit)).perform(click());
}
示例8: onKeyUp
import android.view.KeyEvent; //导入依赖的package包/类
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
PlaybackOverlayFragment playbackOverlayFragment = (PlaybackOverlayFragment) getFragmentManager().findFragmentById(R.id.playback_controls_fragment);
switch (keyCode) {
case KeyEvent.KEYCODE_MEDIA_PLAY:
playbackOverlayFragment.togglePlayback(false);
return true;
case KeyEvent.KEYCODE_MEDIA_PAUSE:
playbackOverlayFragment.togglePlayback(false);
return true;
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
if (mPlaybackState == LeanbackPlaybackState.PLAYING) {
playbackOverlayFragment.togglePlayback(false);
} else {
playbackOverlayFragment.togglePlayback(true);
}
return true;
default:
return super.onKeyUp(keyCode, event);
}
}
示例9: 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;
}
示例10: dispatchKeyEventInFullScreen
import android.view.KeyEvent; //导入依赖的package包/类
public boolean dispatchKeyEventInFullScreen(KeyEvent event) {
if (event == null) return false;
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_BACK:
if (EmoticonsKeyboardUtils.isFullScreen((Activity) getContext()) && mLayoutKVML.isShown()) {
reset();
return true;
}
default:
if (event.getAction() == KeyEvent.ACTION_DOWN) {
boolean isFocused;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
isFocused = mIMLayout.getETChat().getShowSoftInputOnFocus();
} else {
isFocused = mIMLayout.getETChat().isFocused();
}
if (isFocused)
mIMLayout.getETChat().onKeyDown(event.getKeyCode(), event);
}
}
return false;
}
示例11: onKeyDown
import android.view.KeyEvent; //导入依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
if (mWebView.getUrl().equals(INDEXURL)) {
if (System.currentTimeMillis() - exitTime > 2000) {
CommonUtils.showToast(this, getString(R.string.w_exit_app));
exitTime = System.currentTimeMillis();
} else {
for (int i = 0; i < MyApplication.list.size(); i++) {
MyApplication.list.get(i).finish();
}
}
} else {
mWebView.goBack();
}
}
return true;
}
示例12: onKeyUp
import android.view.KeyEvent; //导入依赖的package包/类
public boolean onKeyUp(int keyCode, KeyEvent event) {
boolean ret = false;
switch (keyCode) {
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
case KeyEvent.KEYCODE_MEDIA_NEXT:
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
// if (isChild() == true) {
// final VideoBrowserActivity parent = (VideoBrowserActivity)
// getParent();
// parent.launchGlobalResume();
// }
ret = true;
}
// if (!ret)
// ret = super.onKeyUp(keyCode, event);
return ret;
}
示例13: onKeyDown
import android.view.KeyEvent; //导入依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
//TODO: Should we reverse the keys for RTL? The framework's SeekBar does NOT....
boolean handled = false;
if (isEnabled()) {
int progress = getAnimatedProgress();
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
handled = true;
if (progress <= mMin) break;
animateSetProgress(progress - mKeyProgressIncrement);
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
handled = true;
if (progress >= mMax) break;
animateSetProgress(progress + mKeyProgressIncrement);
break;
}
}
return handled || super.onKeyDown(keyCode, event);
}
示例14: onKey
import android.view.KeyEvent; //导入依赖的package包/类
@Override
public final boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
return onKeyDown(keyCode, event);
}
return false;
}
示例15: onKeyDown
import android.view.KeyEvent; //导入依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
// if (!mDelegation.onTurnBack()) return true;
break;
}
return super.onKeyDown(keyCode, event);
}