本文整理了Java中android.view.KeyEvent.<init>()
方法的一些代码示例,展示了KeyEvent.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyEvent.<init>()
方法的具体详情如下:
包路径:android.view.KeyEvent
类名称:KeyEvent
方法名:<init>
暂无
代码示例来源:origin: rockerhieu/emojicon
public static void backspace(EditText editText) {
KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
editText.dispatchKeyEvent(event);
}
代码示例来源: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: robolectric/robolectric
public KeyEvent getDownEvent(char a) {
return new KeyEvent(
0,
0,
KeyEvent.ACTION_DOWN,
toCharKeyCode(a),
0,
getMetaState(a),
KeyCharacterMap.VIRTUAL_KEYBOARD,
0);
}
代码示例来源:origin: robolectric/robolectric
public KeyEvent getUpEvent(char a) {
return new KeyEvent(
0,
0,
KeyEvent.ACTION_UP,
toCharKeyCode(a),
0,
getMetaState(a),
KeyCharacterMap.VIRTUAL_KEYBOARD,
0);
}
代码示例来源:origin: k9mail/k-9
public void emulateShiftHeld() {
try {
KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
shiftPressEvent.dispatch(this, null, null);
Toast.makeText(getContext() , R.string.select_text_now, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Timber.e(e, "Exception in emulateShiftHeld()");
}
}
代码示例来源:origin: termux/termux-app
static void sendKey(View view, String keyName) {
TerminalView terminalView = view.findViewById(R.id.terminal_view);
if (keyCodesForString.containsKey(keyName)) {
int keyCode = keyCodesForString.get(keyName);
terminalView.onKeyDown(keyCode, new KeyEvent(KeyEvent.ACTION_UP, keyCode));
// view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode));
} else {
// not a control char
TerminalSession session = terminalView.getCurrentSession();
if (session != null)
session.write(keyName);
}
}
代码示例来源:origin: termux/termux-app
@Override
public boolean deleteSurroundingText(int leftLength, int rightLength) {
if (LOG_KEY_EVENTS) {
Log.i(EmulatorDebug.LOG_TAG, "IME: deleteSurroundingText(" + leftLength + ", " + rightLength + ")");
}
// The stock Samsung keyboard with 'Auto check spelling' enabled sends leftLength > 1.
KeyEvent deleteKey = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL);
for (int i = 0; i < leftLength; i++) sendKeyEvent(deleteKey);
return super.deleteSurroundingText(leftLength, rightLength);
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testOnKeyDown() {
assertTrue(delegate.onKeyDown(KeyEvent.KEYCODE_VOLUME_UP,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP)));
assertTrue(delegate.onKeyDown(KeyEvent.KEYCODE_VOLUME_DOWN,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_DOWN)));
assertFalse(delegate.onKeyDown(KeyEvent.KEYCODE_BACK,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)));
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testOnKeyLongPressDisabled() {
PreferenceManager.getDefaultSharedPreferences(activity)
.edit()
.putBoolean(activity.getString(R.string.pref_volume), false)
.apply();
assertFalse(delegate.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_UP,
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP)));
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testOnKeyUpDisabled() {
PreferenceManager.getDefaultSharedPreferences(activity)
.edit()
.putBoolean(activity.getString(R.string.pref_volume), false)
.apply();
assertFalse(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP,
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP)));
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testOnKeyDownDisabled() {
PreferenceManager.getDefaultSharedPreferences(activity)
.edit()
.putBoolean(activity.getString(R.string.pref_volume), false)
.apply();
assertFalse(delegate.onKeyDown(KeyEvent.KEYCODE_VOLUME_UP,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP)));
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testNoBinding() {
delegate.setScrollable(null, null);
assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_UP,
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP)));
assertTrue(delegate.onKeyUp(KeyEvent.KEYCODE_VOLUME_DOWN,
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_DOWN)));
assertTrue(delegate.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_UP,
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP)));
assertTrue(delegate.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_DOWN,
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_DOWN)));
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testInterceptBack() {
assertFalse(delegate.onKeyDown(KeyEvent.KEYCODE_BACK,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)));
delegate.setBackInterceptor(() -> true);
assertTrue(delegate.onKeyDown(KeyEvent.KEYCODE_BACK,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)));
delegate.setBackInterceptor(() -> false);
assertFalse(delegate.onKeyDown(KeyEvent.KEYCODE_BACK,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)));
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testOnKeyLongPress() {
assertFalse(delegate.onKeyLongPress(KeyEvent.KEYCODE_BACK,
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK)));
assertTrue(delegate.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_UP,
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_UP)));
verify(appBar).setExpanded(eq(true), anyBoolean());
verify(scrollable).scrollToTop();
assertTrue(delegate.onKeyLongPress(KeyEvent.KEYCODE_VOLUME_DOWN,
new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_VOLUME_DOWN)));
}
代码示例来源:origin: hidroh/materialistic
@Test
public void testVolumeNavigation() {
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: hidroh/materialistic
@Test
public void testVolumeNavigation() {
activity.onKeyDown(KeyEvent.KEYCODE_VOLUME_UP,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP));
verify(keyDelegate).setScrollable(any(Scrollable.class), any());
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: hidroh/materialistic
@Test
public void testVolumeNavigation() {
activity.onKeyDown(KeyEvent.KEYCODE_VOLUME_UP,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP));
verify(keyDelegate).setScrollable(any(Scrollable.class), any());
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: hidroh/materialistic
@Test
public void testBackPressed() {
activity.onItemSelected(new TestHnItem(1L) {
@NonNull
@Override
public String getType() {
return STORY_TYPE;
}
});
activity.onKeyDown(KeyEvent.KEYCODE_BACK,
new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
verify(keyDelegate).setBackInterceptor(any(KeyDelegate.BackInterceptor.class));
verify(keyDelegate).onKeyDown(anyInt(), any(KeyEvent.class));
}
代码示例来源:origin: robolectric/robolectric
@Test
public void canSetInputDeviceOnKeyEvent() throws Exception {
InputDevice myDevice = ShadowInputDevice.makeInputDeviceNamed("myDevice");
KeyEvent keyEvent = new KeyEvent(1, 2);
shadowOf(keyEvent).setDevice(myDevice);
assertThat(keyEvent.getDevice().getName()).isEqualTo("myDevice");
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void onKeyUp_callsOnBackPressedWhichFinishesTheActivity() throws Exception {
OnBackPressedActivity activity = buildActivity(OnBackPressedActivity.class).setup().get();
boolean downConsumed =
activity.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
boolean upConsumed =
activity.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK));
assertTrue(downConsumed);
assertTrue(upConsumed);
assertTrue(activity.onBackPressedCalled);
assertTrue(activity.isFinishing());
}
内容来源于网络,如有侵权,请联系作者删除!