List of usage examples for android.view KeyEvent KEYCODE_DPAD_DOWN
int KEYCODE_DPAD_DOWN
To view the source code for android.view KeyEvent KEYCODE_DPAD_DOWN.
Click Source Link
From source file:com.undatech.opaque.RemoteCanvasActivity.java
/** * Initializes the on-screen keys for meta keys and arrow keys. *//*w w w. j a va2 s. c o m*/ private void initializeOnScreenKeys() { layoutKeys = (RelativeLayout) findViewById(R.id.layoutKeys); keyStow = (ImageButton) findViewById(R.id.keyStow); setKeyStowDrawableAndVisibility(); keyStow.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (layoutKeys.getVisibility() == View.VISIBLE) { extraKeysHidden = true; setExtraKeysVisibility(View.GONE, false); } else { extraKeysHidden = false; setExtraKeysVisibility(View.VISIBLE, true); } layoutKeys.offsetTopAndBottom(prevBottomOffset); setKeyStowDrawableAndVisibility(); } }); // Define action of tab key and meta keys. keyTab = (ImageButton) findViewById(R.id.keyTab); keyTab.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_TAB; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyTab.setImageResource(R.drawable.tabon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyTab.setImageResource(R.drawable.taboff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyEsc = (ImageButton) findViewById(R.id.keyEsc); keyEsc.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = 111; /* KEYCODE_ESCAPE */ if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyEsc.setImageResource(R.drawable.escon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyEsc.setImageResource(R.drawable.escoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyCtrl = (ImageButton) findViewById(R.id.keyCtrl); keyCtrl.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenCtrlToggle(); keyCtrlToggled = false; if (on) keyCtrl.setImageResource(R.drawable.ctrlon); else keyCtrl.setImageResource(R.drawable.ctrloff); } }); keyCtrl.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { myVibrator.vibrate(Constants.SHORT_VIBRATION); boolean on = canvas.getKeyboard().onScreenCtrlToggle(); keyCtrlToggled = true; if (on) keyCtrl.setImageResource(R.drawable.ctrlon); else keyCtrl.setImageResource(R.drawable.ctrloff); return true; } }); keySuper = (ImageButton) findViewById(R.id.keySuper); keySuper.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenSuperToggle(); keySuperToggled = false; if (on) keySuper.setImageResource(R.drawable.superon); else keySuper.setImageResource(R.drawable.superoff); } }); keySuper.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { myVibrator.vibrate(Constants.SHORT_VIBRATION); boolean on = canvas.getKeyboard().onScreenSuperToggle(); keySuperToggled = true; if (on) keySuper.setImageResource(R.drawable.superon); else keySuper.setImageResource(R.drawable.superoff); return true; } }); keyAlt = (ImageButton) findViewById(R.id.keyAlt); keyAlt.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenAltToggle(); keyAltToggled = false; if (on) keyAlt.setImageResource(R.drawable.alton); else keyAlt.setImageResource(R.drawable.altoff); } }); keyAlt.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { myVibrator.vibrate(Constants.SHORT_VIBRATION); boolean on = canvas.getKeyboard().onScreenAltToggle(); keyAltToggled = true; if (on) keyAlt.setImageResource(R.drawable.alton); else keyAlt.setImageResource(R.drawable.altoff); return true; } }); keyShift = (ImageButton) findViewById(R.id.keyShift); keyShift.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenShiftToggle(); keyShiftToggled = false; if (on) keyShift.setImageResource(R.drawable.shifton); else keyShift.setImageResource(R.drawable.shiftoff); } }); keyShift.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { myVibrator.vibrate(Constants.SHORT_VIBRATION); boolean on = canvas.getKeyboard().onScreenShiftToggle(); keyShiftToggled = true; if (on) keyShift.setImageResource(R.drawable.shifton); else keyShift.setImageResource(R.drawable.shiftoff); return true; } }); // Define action of arrow keys. keyUp = (ImageButton) findViewById(R.id.keyUpArrow); keyUp.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_UP; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyUp.setImageResource(R.drawable.upon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyUp.setImageResource(R.drawable.upoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyDown = (ImageButton) findViewById(R.id.keyDownArrow); keyDown.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_DOWN; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyDown.setImageResource(R.drawable.downon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyDown.setImageResource(R.drawable.downoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyLeft = (ImageButton) findViewById(R.id.keyLeftArrow); keyLeft.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_LEFT; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyLeft.setImageResource(R.drawable.lefton); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyLeft.setImageResource(R.drawable.leftoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyRight = (ImageButton) findViewById(R.id.keyRightArrow); keyRight.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_RIGHT; if (e.getAction() == MotionEvent.ACTION_DOWN) { myVibrator.vibrate(Constants.SHORT_VIBRATION); keyRight.setImageResource(R.drawable.righton); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyRight.setImageResource(R.drawable.rightoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); }
From source file:net.evendanan.android.thumbremote.ui.RemoteUiActivity.java
/** * Handler an android keypress and send it to boxee if appropriate. */// w w w . j av a2 s.co m @Override public boolean onKeyDown(final int keyCode, final KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (RemoteApplication.getConfig().getHandleBack()) { Log.d(TAG, "Will handle back"); if (mBoundService != null) mBoundService.remoteBack(); return true; } else { Log.d(TAG, "Will NOT handle back"); return super.onKeyDown(keyCode, event); } case KeyEvent.KEYCODE_DPAD_CENTER: if (mBoundService != null) mBoundService.remoteSelect(); return true; case KeyEvent.KEYCODE_DPAD_DOWN: if (mBoundService != null) mBoundService.remoteDown(); return true; case KeyEvent.KEYCODE_DPAD_UP: if (mBoundService != null) mBoundService.remoteUp(); return true; case KeyEvent.KEYCODE_DPAD_LEFT: if (mBoundService != null) mBoundService.remoteLeft(); return true; case KeyEvent.KEYCODE_DPAD_RIGHT: if (mBoundService != null) mBoundService.remoteRight(); return true; case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: final int volumeFactor = (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) ? -1 : 1; final int volumeOffset = (volumeFactor * RemoteApplication.getConfig().getVolumeStep()); if (mBoundService != null) mBoundService.remoteVolumeOffset(volumeOffset); return true; case KeyEvent.KEYCODE_DEL: if (mBoundService != null) mBoundService.remoteKeypress((char) 8); return true; default: final char unicodeChar = (char) event.getUnicodeChar(); // Log.d(TAG, "Unicode is " + ((char)unicodeChar)); if (Character.isLetterOrDigit(unicodeChar) || msPunctuation.contains(unicodeChar)) { // Log.d(TAG, "handling " + ((char)unicodeChar)); if (mBoundService != null) mBoundService.remoteKeypress(unicodeChar); return true; } else { return super.onKeyDown(keyCode, event); } } }
From source file:org.peterbaldwin.vlcremote.app.PlaybackActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { int c = event.getUnicodeChar(); if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { if (mVolumeLevel != VOLUME_LEVEL_UNKNOWN) { setVolume(mVolumeLevel + 20); } else {//from w w w .ja va2s . c o m mMediaServer.status().command.volumeUp(); } return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { if (mVolumeLevel != VOLUME_LEVEL_UNKNOWN) { setVolume(mVolumeLevel - 20); } else { mMediaServer.status().command.volumeDown(); } return true; } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { if (event.isAltPressed()) { mMediaServer.status().command.seek(Uri.encode("-".concat(Preferences.get(this).getSeekTime()))); return true; } else if (event.isShiftPressed()) { mMediaServer.status().command.seek(Uri.encode("-3")); return true; } else { mMediaServer.status().command.key("nav-left"); return true; } } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { if (event.isAltPressed()) { mMediaServer.status().command.seek(Uri.encode("+".concat(Preferences.get(this).getSeekTime()))); return true; } else if (event.isShiftPressed()) { mMediaServer.status().command.seek(Uri.encode("+3")); return true; } else { mMediaServer.status().command.key("nav-right"); return true; } } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { mMediaServer.status().command.key("nav-up"); return true; } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { mMediaServer.status().command.key("nav-down"); return true; } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { mMediaServer.status().command.key("nav-activate"); return true; } else if (c == ' ') { mMediaServer.status().command.playback.pause(); return true; } else if (c == 's') { mMediaServer.status().command.playback.stop(); return true; } else if (c == 'p') { mMediaServer.status().command.playback.previous(); return true; } else if (c == 'n') { mMediaServer.status().command.playback.next(); return true; } else if (c == '+') { // TODO: Play faster return super.onKeyDown(keyCode, event); } else if (c == '-') { // TODO: Play slower return super.onKeyDown(keyCode, event); } else if (c == 'f') { mMediaServer.status().command.fullscreen(); return true; } else if (c == 'm') { mute(); return true; } else { return super.onKeyDown(keyCode, event); } }
From source file:com.owen.tvrecyclerview.widget.TvRecyclerView.java
/** * keycode?Direction// ww w .j av a 2 s.c o m * @param keyCode * @return */ private int keyCode2Direction(int keyCode) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_DOWN: return FOCUS_DOWN; case KeyEvent.KEYCODE_DPAD_RIGHT: return FOCUS_RIGHT; case KeyEvent.KEYCODE_DPAD_LEFT: return FOCUS_LEFT; case KeyEvent.KEYCODE_DPAD_UP: return FOCUS_UP; default: return -1; } }
From source file:com.iiordanov.runsoft.bVNC.RemoteCanvasActivity.java
/** * Initializes the on-screen keys for meta keys and arrow keys. *///from www . ja v a2 s . c o m private void initializeOnScreenKeys() { layoutKeys = (RelativeLayout) findViewById(R.id.layoutKeys); keyStow = (ImageButton) findViewById(R.id.keyStow); setKeyStowDrawableAndVisibility(); keyStow.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (layoutKeys.getVisibility() == View.VISIBLE) { extraKeysHidden = true; setExtraKeysVisibility(View.GONE, false); } else { extraKeysHidden = false; setExtraKeysVisibility(View.VISIBLE, true); } layoutKeys.offsetTopAndBottom(prevBottomOffset); setKeyStowDrawableAndVisibility(); } }); // Define action of tab key and meta keys. keyTab = (ImageButton) findViewById(R.id.keyTab); keyTab.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_TAB; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyTab.setImageResource(R.drawable.tabon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyTab.setImageResource(R.drawable.taboff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyEsc = (ImageButton) findViewById(R.id.keyEsc); keyEsc.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = 111; /* KEYCODE_ESCAPE */ if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyEsc.setImageResource(R.drawable.escon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyEsc.setImageResource(R.drawable.escoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyCtrl = (ImageButton) findViewById(R.id.keyCtrl); keyCtrl.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenCtrlToggle(); keyCtrlToggled = false; if (on) keyCtrl.setImageResource(R.drawable.ctrlon); else keyCtrl.setImageResource(R.drawable.ctrloff); } }); keyCtrl.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); boolean on = canvas.getKeyboard().onScreenCtrlToggle(); keyCtrlToggled = true; if (on) keyCtrl.setImageResource(R.drawable.ctrlon); else keyCtrl.setImageResource(R.drawable.ctrloff); return true; } }); keySuper = (ImageButton) findViewById(R.id.keySuper); keySuper.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenSuperToggle(); keySuperToggled = false; if (on) keySuper.setImageResource(R.drawable.superon); else keySuper.setImageResource(R.drawable.superoff); } }); keySuper.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); boolean on = canvas.getKeyboard().onScreenSuperToggle(); keySuperToggled = true; if (on) keySuper.setImageResource(R.drawable.superon); else keySuper.setImageResource(R.drawable.superoff); return true; } }); keypad = (HangulKeypad) findViewById(R.id.hangul_keypad); keypad.setVncKeyboard(canvas); keypad.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { btnChatShowToggle.setVisibility(View.VISIBLE); keypad.setVisibility(View.GONE); keypad.setTag(""); keyKor.setVisibility(View.VISIBLE); if (v.getId() == R.id.key_show_eng) { InputMethodManager inputMgr = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); inputMgr.toggleSoftInput(0, 0); } } }); //TODO keyKor = (Button) findViewById(R.id.keyKor); keyKor.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { String toggle = (String) keypad.getTag(); if (TextUtils.isEmpty(toggle)) { InputMethodManager inputMgr = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); inputMgr.hideSoftInputFromWindow(btnChatShowToggle.getWindowToken(), 0); new Handler().postDelayed(new Runnable() { @Override public void run() { canvas.getKeyboard().processLocalKeyEvent(144, new KeyEvent(144, 0)); keyKor.setVisibility(View.GONE); keypad.setVisibility(View.VISIBLE); keypad.setTag("1"); } }, 500); } else { keyKor.setVisibility(View.VISIBLE); btnChatShowToggle.setVisibility(View.VISIBLE); keypad.setVisibility(View.GONE); keypad.setTag(""); } } }); keyAlt = (ImageButton) findViewById(R.id.keyAlt); keyAlt.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenAltToggle(); keyAltToggled = false; if (on) keyAlt.setImageResource(R.drawable.alton); else keyAlt.setImageResource(R.drawable.altoff); } }); keyAlt.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); boolean on = canvas.getKeyboard().onScreenAltToggle(); keyAltToggled = true; if (on) keyAlt.setImageResource(R.drawable.alton); else keyAlt.setImageResource(R.drawable.altoff); return true; } }); keyShift = (ImageButton) findViewById(R.id.keyShift); keyShift.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { boolean on = canvas.getKeyboard().onScreenShiftToggle(); keyShiftToggled = false; if (on) keyShift.setImageResource(R.drawable.shifton); else keyShift.setImageResource(R.drawable.shiftoff); } }); keyShift.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View arg0) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); boolean on = canvas.getKeyboard().onScreenShiftToggle(); keyShiftToggled = true; if (on) keyShift.setImageResource(R.drawable.shifton); else keyShift.setImageResource(R.drawable.shiftoff); return true; } }); // vncCanvas.sendMetaKey(MetaKeyBean.keyArrowLeft); // Define action of arrow keys. keyUp = (ImageButton) findViewById(R.id.keyUpArrow); keyUp.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_UP; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyUp.setImageResource(R.drawable.upon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyUp.setImageResource(R.drawable.upoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyDown = (ImageButton) findViewById(R.id.keyDownArrow); keyDown.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_DOWN; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyDown.setImageResource(R.drawable.downon); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyDown.setImageResource(R.drawable.downoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyLeft = (ImageButton) findViewById(R.id.keyLeftArrow); keyLeft.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_LEFT; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyLeft.setImageResource(R.drawable.lefton); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyLeft.setImageResource(R.drawable.leftoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); keyRight = (ImageButton) findViewById(R.id.keyRightArrow); keyRight.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent e) { RemoteKeyboard k = canvas.getKeyboard(); int key = KeyEvent.KEYCODE_DPAD_RIGHT; if (e.getAction() == MotionEvent.ACTION_DOWN) { BCFactory.getInstance().getBCHaptic().performLongPressHaptic(canvas); keyRight.setImageResource(R.drawable.righton); k.repeatKeyEvent(key, new KeyEvent(e.getAction(), key)); return true; } else if (e.getAction() == MotionEvent.ACTION_UP) { keyRight.setImageResource(R.drawable.rightoff); resetOnScreenKeys(0); k.stopRepeatingKeyEvent(); return true; } return false; } }); }
From source file:com.android.mail.ui.ConversationListFragment.java
@Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { if (view instanceof SwipeableListView) { SwipeableListView list = (SwipeableListView) view; // Don't need to handle ENTER because it's auto-handled as a "click". if (KeyboardUtils.isKeycodeDirectionEnd(keyCode, ViewUtils.isViewRtl(list))) { if (keyEvent.getAction() == KeyEvent.ACTION_UP) { if (mKeyInitiatedFromList) { int currentPos = list.getSelectedItemPosition(); if (currentPos < 0) { // Find the activated item if the focused item is non-existent. // This can happen when the user transitions from touch mode. currentPos = list.getCheckedItemPosition(); }//from w w w .jav a2 s. com if (currentPos >= 0) { // We don't use onListItemSelected because right arrow should always // view the conversation even in CAB/no_sender_image mode. viewConversation(currentPos); commitDestructiveActions( Utils.useTabletUI(mActivity.getActivityContext().getResources())); } } mKeyInitiatedFromList = false; } else if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) { mKeyInitiatedFromList = true; } return true; } else if ((keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) && keyEvent.getAction() == KeyEvent.ACTION_UP) { final int position = list.getSelectedItemPosition(); if (position >= 0) { final Object item = getAnimatedAdapter().getItem(position); if (item != null && item instanceof ConversationCursor) { final Conversation conv = ((ConversationCursor) item).getConversation(); mCallbacks.onConversationFocused(conv); } } } } return false; }
From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) private void processJoystickInput(MotionEvent event, int historyPos) { float hatX = 0.0f; InputDevice.MotionRange range = event.getDevice().getMotionRange(MotionEvent.AXIS_HAT_X, event.getSource()); if (range != null) { if (historyPos >= 0) { hatX = InputDeviceState.ProcessAxis(range, event.getHistoricalAxisValue(MotionEvent.AXIS_HAT_X, historyPos)); } else {// w w w. j a v a 2 s . c o m hatX = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_HAT_X)); } } float hatY = 0.0f; range = event.getDevice().getMotionRange(MotionEvent.AXIS_HAT_Y, event.getSource()); if (range != null) { if (historyPos >= 0) { hatY = InputDeviceState.ProcessAxis(range, event.getHistoricalAxisValue(MotionEvent.AXIS_HAT_Y, historyPos)); } else { hatY = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_HAT_Y)); } } float joyX = 0.0f; range = event.getDevice().getMotionRange(MotionEvent.AXIS_X, event.getSource()); if (range != null) { if (historyPos >= 0) { joyX = InputDeviceState.ProcessAxis(range, event.getHistoricalAxisValue(MotionEvent.AXIS_X, historyPos)); } else { joyX = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_X)); } } float joyY = 0.0f; range = event.getDevice().getMotionRange(MotionEvent.AXIS_Y, event.getSource()); if (range != null) { if (historyPos >= 0) { joyY = InputDeviceState.ProcessAxis(range, event.getHistoricalAxisValue(MotionEvent.AXIS_Y, historyPos)); } else { joyY = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_Y)); } } float joy2X = 0.0f; range = event.getDevice().getMotionRange(MotionEvent.AXIS_Z, event.getSource()); if (range != null) { if (historyPos >= 0) { joy2X = InputDeviceState.ProcessAxis(range, event.getHistoricalAxisValue(MotionEvent.AXIS_Z, historyPos)); } else { joy2X = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_Z)); } } float joy2Y = 0.0f; range = event.getDevice().getMotionRange(MotionEvent.AXIS_RZ, event.getSource()); if (range != null) { if (historyPos >= 0) { joy2Y = InputDeviceState.ProcessAxis(range, event.getHistoricalAxisValue(MotionEvent.AXIS_RZ, historyPos)); } else { joy2Y = InputDeviceState.ProcessAxis(range, event.getAxisValue(MotionEvent.AXIS_RZ)); } } if (mAnalogStickPref == 0) { mMouseThread.setCoord( (int) ((Math.abs(joyX * 32.0f) > DEADZONE) ? (-joyX * 32.0f * mMouseSensitivityX) : 0), (int) ((Math.abs(joyY * 32.0f) > DEADZONE) ? (-joyY * 32.0f * mMouseSensitivityY) : 0)); DosBoxControl.nativeJoystick((int) ((joy2X * 256.0f) + mJoyCenterX), (int) ((joy2Y * 256.0f) + mJoyCenterY), ACTION_MOVE, -1); } else { mMouseThread.setCoord( (int) ((Math.abs(joy2X * 32.0f) > DEADZONE) ? (-joy2X * 32.0f * mMouseSensitivityX) : 0), (int) ((Math.abs(joy2Y * 32.0f) > DEADZONE) ? (-joy2Y * 32.0f * mMouseSensitivityY) : 0)); DosBoxControl.nativeJoystick((int) ((joyX * 256.0f) + mJoyCenterX), (int) ((joyY * 256.0f) + mJoyCenterY), ACTION_MOVE, -1); } // Handle all other keyevents int value = 0; int tKeyCode = MAP_NONE; if (hatX < 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_LEFT); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, true, mModifierCtrl, mModifierAlt, mModifierShift); } } hatXlast = hatX; } else if (hatX > 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_RIGHT); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, true, mModifierCtrl, mModifierAlt, mModifierShift); } } hatXlast = hatX; } else { // released if (hatX != hatXlast) { if (hatXlast < 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_LEFT); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_LEFT)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, false, mModifierCtrl, mModifierAlt, mModifierShift); } } } else if (hatXlast > 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_RIGHT); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_RIGHT)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, false, mModifierCtrl, mModifierAlt, mModifierShift); } } } } hatXlast = hatX; } if (hatY < 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_UP); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_UP)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, true, mModifierCtrl, mModifierAlt, mModifierShift); } } hatYlast = hatY; } else if (hatY > 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_DOWN); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_DOWN)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, true, mModifierCtrl, mModifierAlt, mModifierShift); } } hatYlast = hatY; } else { // released if (hatY != hatYlast) { if (hatYlast < 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_UP); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_UP)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, false, mModifierCtrl, mModifierAlt, mModifierShift); } } } else if (hatYlast > 0) { value = customMap.get(KeyEvent.KEYCODE_DPAD_DOWN); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_DOWN)); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, false, mModifierCtrl, mModifierAlt, mModifierShift); } } } } hatYlast = hatY; } }
From source file:android.support.v7.widget.ListPopupWindow.java
/** * Filter key down events. By forwarding key down events to this function, * views using non-modal ListPopupWindow can have it handle key selection of items. * * @param keyCode keyCode param passed to the host view's onKeyDown * @param event event param passed to the host view's onKeyDown * @return true if the event was handled, false if it was ignored. * * @see #setModal(boolean)/*from ww w. ja va 2 s . co m*/ */ public boolean onKeyDown(int keyCode, KeyEvent event) { // when the drop down is shown, we drive it directly if (isShowing()) { // the key events are forwarded to the list in the drop down view // note that ListView handles space but we don't want that to happen // also if selection is not currently in the drop down, then don't // let center or enter presses go there since that would cause it // to select one of its items if (keyCode != KeyEvent.KEYCODE_SPACE && (mDropDownList.getSelectedItemPosition() >= 0 || !isConfirmKey(keyCode))) { int curIndex = mDropDownList.getSelectedItemPosition(); boolean consumed; final boolean below = !mPopup.isAboveAnchor(); final ListAdapter adapter = mAdapter; boolean allEnabled; int firstItem = Integer.MAX_VALUE; int lastItem = Integer.MIN_VALUE; if (adapter != null) { allEnabled = adapter.areAllItemsEnabled(); firstItem = allEnabled ? 0 : mDropDownList.lookForSelectablePosition(0, true); lastItem = allEnabled ? adapter.getCount() - 1 : mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false); } if ((below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex <= firstItem) || (!below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN && curIndex >= lastItem)) { // When the selection is at the top, we block the key // event to prevent focus from moving. clearListSelection(); mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); show(); return true; } else { // WARNING: Please read the comment where mListSelectionHidden // is declared mDropDownList.mListSelectionHidden = false; } consumed = mDropDownList.onKeyDown(keyCode, event); if (DEBUG) Log.v(TAG, "Key down: code=" + keyCode + " list consumed=" + consumed); if (consumed) { // If it handled the key event, then the user is // navigating in the list, so we should put it in front. mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); // Here's a little trick we need to do to make sure that // the list view is actually showing its focus indicator, // by ensuring it has focus and getting its window out // of touch mode. mDropDownList.requestFocusFromTouch(); show(); switch (keyCode) { // avoid passing the focus from the text view to the // next component case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_UP: return true; } } else { if (below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { // when the selection is at the bottom, we block the // event to avoid going to the next focusable widget if (curIndex == lastItem) { return true; } } else if (!below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex == firstItem) { return true; } } } } return false; }
From source file:com.github.shareme.gwsmaterialuikit.library.material.widget.ListPopupWindow.java
/** * Filter key down events. By forwarding key down events to this function, * views using non-modal ListPopupWindow can have it handle key selection of items. * * @param keyCode keyCode param passed to the host view's onKeyDown * @param event event param passed to the host view's onKeyDown * @return true if the event was handled, false if it was ignored. * * @see #setModal(boolean)//w w w .j a v a 2s . c om */ public boolean onKeyDown(int keyCode, KeyEvent event) { // when the drop down is shown, we drive it directly if (isShowing()) { // the key events are forwarded to the list in the drop down view // note that ListView handles space but we don't want that to happen // also if selection is not currently in the drop down, then don't // let center or enter presses go there since that would cause it // to select one of its items if (keyCode != KeyEvent.KEYCODE_SPACE && (mDropDownList.getSelectedItemPosition() >= 0 || !isConfirmKey(keyCode))) { int curIndex = mDropDownList.getSelectedItemPosition(); boolean consumed; final boolean below = !mPopup.isAboveAnchor(); final ListAdapter adapter = mAdapter; boolean allEnabled; int firstItem = Integer.MAX_VALUE; int lastItem = Integer.MIN_VALUE; if (adapter != null) { allEnabled = adapter.areAllItemsEnabled(); firstItem = allEnabled ? 0 : mDropDownList.lookForSelectablePosition(0, true); lastItem = allEnabled ? adapter.getCount() - 1 : mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false); } if ((below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex <= firstItem) || (!below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN && curIndex >= lastItem)) { // When the selection is at the top, we block the key // event to prevent focus from moving. clearListSelection(); mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); show(); return true; } else { // WARNING: Please read the comment where mListSelectionHidden // is declared mDropDownList.mListSelectionHidden = false; } consumed = mDropDownList.onKeyDown(keyCode, event); if (DEBUG) Timber.v("Key down: code=" + keyCode + " list consumed=" + consumed); if (consumed) { // If it handled the key event, then the user is // navigating in the list, so we should put it in front. mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); // Here's a little trick we need to do to make sure that // the list view is actually showing its focus indicator, // by ensuring it has focus and getting its window out // of touch mode. mDropDownList.requestFocusFromTouch(); show(); switch (keyCode) { // avoid passing the focus from the text view to the // next component case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_UP: return true; } } else { if (below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { // when the selection is at the bottom, we block the // event to avoid going to the next focusable widget if (curIndex == lastItem) { return true; } } else if (!below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex == firstItem) { return true; } } } } return false; }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testPendingSmoothScrollAndRemove() throws Throwable { mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_linear); intent.putExtra(GridActivity.EXTRA_REQUEST_FOCUS_ONLAYOUT, true); int[] items = new int[100]; for (int i = 0; i < items.length; i++) { items[i] = 630 + (int) (Math.random() * 100); }/*from w ww .ja v a 2 s .c o m*/ intent.putExtra(GridActivity.EXTRA_ITEMS, items); intent.putExtra(GridActivity.EXTRA_STAGGERED, true); mOrientation = BaseGridView.VERTICAL; mNumRows = 1; initActivity(intent); mGridView.setSelectedPositionSmooth(0); waitForScrollIdle(mVerifyLayout); assertTrue(mGridView.getChildAt(0).hasFocus()); // Pressing lots of key to make sure smooth scroller is running for (int i = 0; i < 20; i++) { sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); } Thread.sleep(100); assertTrue(mGridView.getLayoutManager().isSmoothScrolling()); final int removeIndex = mGridView.getChildCount() - 1; runTestOnUiThread(new Runnable() { public void run() { mActivity.removeItems(removeIndex, 1); } }); Thread.sleep(20); // wait for layout assertFalse("removing the index of attached child should kill smooth scroller", mGridView.getLayoutManager().isSmoothScrolling()); waitForTransientStateGone(null); waitForScrollIdle(); int focusIndex = mGridView.getSelectedPosition(); int leftEdge = mGridView.getLayoutManager().findViewByPosition(focusIndex).getLeft(); runTestOnUiThread(new Runnable() { public void run() { mGridView.requestLayout(); } }); waitForTransientStateGone(null); waitForScrollIdle(); assertEquals(leftEdge, mGridView.getLayoutManager().findViewByPosition(focusIndex).getLeft()); }