本文整理了Java中android.view.KeyEvent
类的一些代码示例,展示了KeyEvent
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyEvent
类的具体详情如下:
包路径:android.view.KeyEvent
类名称:KeyEvent
暂无
代码示例来源:origin: cSploit/android
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
mOutput.append(Html.fromHtml("<font color=\"red\">" + mInput.getText().toString() + "</font>\n"));
mSession.addCommand(mInput.getText().toString(), mReceiver);
return true;
}
return false;
}
});
代码示例来源:origin: stackoverflow.com
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (Integer.parseInt(android.os.Build.VERSION.SDK) > 5
&& keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0) {
Log.d("CDA", "onKeyDown Called");
onBackPressed();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
Log.d("CDA", "onBackPressed Called");
Intent setIntent = new Intent(Intent.ACTION_MAIN);
setIntent.addCategory(Intent.CATEGORY_HOME);
setIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(setIntent);
}
代码示例来源:origin: smuyyh/BookReader
@Override
public boolean deleteSurroundingText(int beforeLength, int afterLength) {
// magic: in latest Android, deleteSurroundingText(1, 0) will be called for backspace
if (beforeLength == 1 && afterLength == 0) {
// backspace
return sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL))
&& sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL));
}
return super.deleteSurroundingText(beforeLength, afterLength);
}
}
代码示例来源:origin: jdamcd/android-crop
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
event.startTracking();
return true;
}
return super.onKeyDown(keyCode, event);
}
代码示例来源:origin: k9mail/k-9
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
boolean ret = false;
if (KeyEvent.ACTION_DOWN == event.getAction()) {
ret = onCustomKeyDown(event.getKeyCode(), event);
}
if (!ret) {
ret = super.dispatchKeyEvent(event);
}
return ret;
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testVolumeNavigation() {
Intent intent = new Intent();
WebItem webItem = new TestWebItem() {
@Override
public String getUrl() {
return "http://example.com";
}
@Override
public String getId() {
return "1";
}
};
intent.putExtra(ItemActivity.EXTRA_ITEM, webItem);
controller = Robolectric.buildActivity(ItemActivity.class, intent);
controller.create().start().resume().visible();
activity = controller.get();
activity.onKeyDown(KeyEvent.KEYCODE_VOLUME_UP,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP));
verify(keyDelegate).setScrollable(any(Scrollable.class), any(AppBarLayout.class));
verify(keyDelegate).onKeyDown(anyInt(), any(KeyEvent.class));
activity.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP,
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP));
verify(keyDelegate).onKeyUp(anyInt(), any(KeyEvent.class));
activity.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_UP,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP));
verify(keyDelegate).onKeyLongPress(anyInt(), any(KeyEvent.class));
}
代码示例来源:origin: wallabag/android-app
private static PendingIntent generateActionIntent(Context context, int mediaKeyEvent)
{
Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
intent.setPackage(context.getPackageName());
intent.putExtra(Intent.EXTRA_KEY_EVENT,
new KeyEvent(KeyEvent.ACTION_DOWN, mediaKeyEvent));
return PendingIntent.getBroadcast(context, mediaKeyEvent, intent, 0);
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
searchClear.setOnClickListener(v -> {
if (DEBUG) Log.d(TAG, "onClick() called with: v = [" + v + "]");
if (TextUtils.isEmpty(searchEditText.getText())) {
NavigationHelper.gotoMainFragment(getFragmentManager());
return;
searchEditText.setText("");
suggestionListAdapter.setItems(new ArrayList<>());
showKeyboardSearch();
searchEditText.setOnClickListener(v -> {
if (DEBUG) Log.d(TAG, "onClick() called with: v = [" + v + "]");
if (isSuggestionsEnabled && errorPanelRoot.getVisibility() != View.VISIBLE) {
&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER
|| event.getAction() == EditorInfo.IME_ACTION_SEARCH)) {
search(searchEditText.getText().toString(), new String[0], "");
return true;
代码示例来源:origin: stackoverflow.com
final EditText edittext = (EditText) findViewById(R.id.edittext);
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
Toast.makeText(HelloFormStuff.this, edittext.getText(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
代码示例来源:origin: aa112901/remusic
@Override
public void onReceive(final Context context, final Intent intent) {
final String intentAction = intent.getAction();
if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
if (true)
startService(context, MediaService.CMDPAUSE);
} else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event == null) {
return;
final int keycode = event.getKeyCode();
final int action = event.getAction();
final long eventtime = event.getEventTime();
} else if (event.getRepeatCount() == 0) {
代码示例来源:origin: huangfangyi/YiChat
private void editTextDelete(EditText editText) {
if (!TextUtils.isEmpty(editText.getText())) {
KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
editText.dispatchKeyEvent(event);
}
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
finish();
}
return true;
}
}
return super.onKeyDown(keyCode, event);
}
代码示例来源:origin: libgdx/libgdx
@Override
public boolean onKeyDown (int keyCode, KeyEvent event) {
Log.d("Test", "down keycode: " + event.getKeyCode());
return super.onKeyDown(keyCode, event);
}
代码示例来源:origin: fookwood/Launcher3
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
// If this is a back key, propagate the key back to the listener
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
if (mBackKeyListener != null) {
return mBackKeyListener.onBackKey();
}
return false;
}
return super.onKeyPreIme(keyCode, event);
}
}
代码示例来源:origin: Neamar/KISS
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP)
if (mEditorListener != null && mEditorListener.onEditorAction(this, android.R.id.closeButton, event))
return true;
return super.onKeyPreIme(keyCode, event);
}
}
代码示例来源:origin: seven332/EhViewer
@Override
protected boolean handleMovementKey(TextView widget, Spannable buffer, int keyCode,
int movementMetaState, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
if (KeyEvent.metaStateHasNoModifiers(movementMetaState)) {
if (event.getAction() == KeyEvent.ACTION_DOWN &&
event.getRepeatCount() == 0 && action(CLICK, widget, buffer)) {
return true;
}
}
break;
}
return super.handleMovementKey(widget, buffer, keyCode, movementMetaState, event);
}
代码示例来源:origin: layerhq/Atlas-Android
/**
* Works with hardware keyboard
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_DEL && getText().length() == 0) {
if (mListener != null) return mListener.onEmptyDel(EmptyDelEditText.this);
}
return super.onKeyUp(keyCode, event);
}
代码示例来源:origin: chat-sdk/chat-sdk-android
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// if enter is pressed start calculating
if(delegate != null) {
delegate.get().startTyping();
}
if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
int editTextLineCount = ((EditText) v).getLineCount();
if (editTextLineCount >= getResources().getInteger(R.integer.chat_sdk_max_message_lines))
return true;
}
return false;
}
代码示例来源:origin: CooLoongWu/CoolChat
@Override
public boolean dispatchKeyEventPreIme(KeyEvent event) {
if (event.getAction() == KeyEvent.KEYCODE_SOFT_LEFT) {
LogUtils.e("dispatchKeyEventPreIme", "按下了返回键");
if (mOnCancelInputLayout != null) {
mOnCancelInputLayout.onCancelInputLayout();
}
return false;
}
return super.dispatchKeyEventPreIme(event);
}
代码示例来源:origin: stackoverflow.com
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
// do something on back.
return true;
}
return super.onKeyDown(keyCode, event);
}
内容来源于网络,如有侵权,请联系作者删除!