List of usage examples for android.view KeyEvent ACTION_DOWN
int ACTION_DOWN
To view the source code for android.view KeyEvent ACTION_DOWN.
Click Source Link
From source file:org.mklab.mikity.android.SettingsFragment.java
/** * {@inheritDoc}/*from w w w . j a va 2 s. c o m*/ */ public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { final InputMethodManager inputMethodManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0); saveEnvironment(); return true; } return false; }
From source file:ui.GalleryFileActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { addImage();/*from w w w .j a v a2s. c om*/ } return super.onKeyDown(keyCode, event); }
From source file:com.hippo.widget.BothScrollView.java
/** * 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.//from ww w . ja v a 2 s . co m * * @param event The key event to execute. * @return Return true if the event was handled, else false. */ public boolean executeKeyEvent(KeyEvent event) { mTempRect.setEmpty(); if (!canScrollHorizontally()) { if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) { View currentFocused = findFocus(); if (currentFocused == this) { currentFocused = null; } View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_RIGHT); return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_RIGHT); } return false; } if (!canScrollVertically()) { if (isFocused() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) { View currentFocused = findFocus(); if (currentFocused == this) { currentFocused = null; } View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN); return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN); } return false; } boolean handled = false; if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_LEFT: if (!event.isAltPressed()) { handled = arrowScrollHorizontally(View.FOCUS_LEFT); } else { handled = fullScroll(View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (!event.isAltPressed()) { handled = arrowScrollHorizontally(View.FOCUS_RIGHT); } else { handled = fullScroll(View.FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_UP: if (!event.isAltPressed()) { handled = arrowScrollVertically(View.FOCUS_UP); } else { handled = fullScroll(View.FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (!event.isAltPressed()) { handled = arrowScrollVertically(View.FOCUS_DOWN); } else { handled = fullScroll(View.FOCUS_DOWN); } break; case KeyEvent.KEYCODE_SPACE: if (event.isCtrlPressed()) { pageScroll(event.isShiftPressed() ? View.FOCUS_LEFT : View.FOCUS_RIGHT); } else { pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN); } break; } } return handled; }
From source file:org.retroshare.android.ConversationFragment.java
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { boolean enterPressed = (event.getAction() == KeyEvent.ACTION_DOWN) & (event.getKeyCode() == KeyEvent.KEYCODE_ENTER); if (enterPressed) sendChatMsg(null);/*from w ww .j a va2 s. c o m*/ return enterPressed; }
From source file:com.android.tv.settings.accessories.AddAccessoryActivity.java
private void sendKeyEvent(int keyCode, boolean down) { InputManager iMgr = (InputManager) getSystemService(INPUT_SERVICE); if (iMgr != null) { long time = SystemClock.uptimeMillis(); KeyEvent evt = new KeyEvent(time, time, down ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP, keyCode, 0); iMgr.injectInputEvent(evt, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC); }// www . j a va 2 s . c o m }
From source file:com.example.android.mediarouter.player.MainActivity.java
public boolean handleMediaKey(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: { Log.d(TAG, "Received Play/Pause event from RemoteControlClient"); mPaused = !mPaused;/*from w ww .ja v a2 s .c o m*/ if (mPaused) { mSessionManager.pause(); } else { mSessionManager.resume(); } return true; } case KeyEvent.KEYCODE_MEDIA_PLAY: { Log.d(TAG, "Received Play event from RemoteControlClient"); if (mPaused) { mPaused = false; mSessionManager.resume(); } return true; } case KeyEvent.KEYCODE_MEDIA_PAUSE: { Log.d(TAG, "Received Pause event from RemoteControlClient"); if (!mPaused) { mPaused = true; mSessionManager.pause(); } return true; } case KeyEvent.KEYCODE_MEDIA_STOP: { Log.d(TAG, "Received Stop event from RemoteControlClient"); mPaused = false; mSessionManager.stop(); return true; } default: break; } } return false; }
From source file:org.ligi.gobandroid_hd.ui.GoActivity.java
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { final Cell ensuredTouchPosition = interaction_scope.getEnsuredTouchPosition(); final BoardCell boardCell = getGame().getCalcBoard().getCell(ensuredTouchPosition); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (boardCell.up != null) { interaction_scope.touch_position = boardCell.up; } else { return false; }//from ww w. ja va 2s. c o m break; case KeyEvent.KEYCODE_DPAD_LEFT: if (boardCell.left != null) { interaction_scope.touch_position = boardCell.left; } else { return false; } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (boardCell.down != null) { interaction_scope.touch_position = boardCell.down; } else { return false; } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (boardCell.right != null) { interaction_scope.touch_position = boardCell.right; } else { return false; } break; case KeyEvent.KEYCODE_DPAD_CENTER: doMoveWithUIFeedback(boardCell); break; default: return false; } go_board.postInvalidate(); refreshZoomFragment(); return true; } return false; }
From source file:org.telegram.ui.Components.NumberPicker.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { final int keyCode = event.getKeyCode(); switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: removeAllCallbacks();//from ww w . j a va 2 s . c o m break; case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_UP: 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); }
From source file:com.dldzkj.app.renxing.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) { if ((System.currentTimeMillis() - exitTime) > 2000) { Toast.makeText(getApplicationContext(), "??", Toast.LENGTH_SHORT).show(); exitTime = System.currentTimeMillis(); } else {/*from ww w .jav a 2 s .com*/ System.exit(0); finish(); } return true; } return super.onKeyDown(keyCode, event); }
From source file:com.actionbarsherlock.internal.ActionBarSherlockCompat.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (DEBUG)//from w ww. jav a2 s.c om Log.d(TAG, "[dispatchKeyEvent] event: " + event); final int keyCode = event.getKeyCode(); // Not handled by the view hierarchy, does the action bar want it // to cancel out of something special? if (keyCode == KeyEvent.KEYCODE_BACK) { final int action = event.getAction(); // Back cancels action modes first. if (mActionMode != null) { if (action == KeyEvent.ACTION_UP) { mActionMode.finish(); } if (DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning true"); return true; } // Next collapse any expanded action views. if (wActionBar != null && wActionBar.hasExpandedActionView()) { if (action == KeyEvent.ACTION_UP) { wActionBar.collapseActionView(); } if (DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning true"); return true; } } boolean result = false; if (keyCode == KeyEvent.KEYCODE_MENU && isReservingOverflow()) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.isLongPress()) { mMenuKeyIsLongPress = true; } else if (event.getAction() == KeyEvent.ACTION_UP) { if (!mMenuKeyIsLongPress) { if (mActionMode == null && wActionBar != null) { if (wActionBar.isOverflowMenuShowing()) { wActionBar.hideOverflowMenu(); } else { wActionBar.showOverflowMenu(); } } result = true; } mMenuKeyIsLongPress = false; } } if (DEBUG) Log.d(TAG, "[dispatchKeyEvent] returning " + result); return result; }