List of usage examples for android.view KeyEvent KEYCODE_BACK
int KEYCODE_BACK
To view the source code for android.view KeyEvent KEYCODE_BACK.
Click Source Link
From source file:cgeo.geocaching.CacheListActivity.java
@Override public boolean onKeyDown(final int keyCode, final KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && adapter.isSelectMode()) { adapter.setSelectMode(false);//from w w w. j a v a 2 s . c o m return true; } return super.onKeyDown(keyCode, event); }
From source file:com.ccxt.whl.activity.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { moveTaskToBack(false);// w w w . j a va 2 s. co m return true; } return super.onKeyDown(keyCode, event); }
From source file:dev.memento.MementoBrowser.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebview.canGoBack()) { // Get the previous URL to update our internal copy WebBackForwardList list = mWebview.copyBackForwardList(); int curr = list.getCurrentIndex(); WebHistoryItem item = list.getItemAtIndex(curr - 1); Bitmap favicon = item.getFavicon(); if (favicon == null) Log.d(LOG_TAG, "No favicon in WebHistoryItem - null"); else// w w w. j a va 2s . co m Log.d(LOG_TAG, "WebHistoryItem favicon W = " + favicon.getWidth()); mOriginalUrl = item.getUrl(); Log.d(LOG_TAG, "GO BACK TO " + mOriginalUrl); mWebview.goBack(); return true; } return super.onKeyDown(keyCode, event); }
From source file:com.customdatepicker.time.TimePickerDialog.java
/** * For keyboard mode, processes key events. * @param keyCode the pressed key./*from ww w . j a v a 2 s .c om*/ * @return true if the key was successfully processed, false otherwise. */ private boolean processKeyUp(int keyCode) { if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) { if (isCancelable()) dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_TAB) { if (mInKbMode) { if (isTypedTimeFullyLegal()) { finishKbMode(true); } return true; } } else if (keyCode == KeyEvent.KEYCODE_ENTER) { if (mInKbMode) { if (!isTypedTimeFullyLegal()) { return true; } finishKbMode(false); } if (mCallback != null) { mCallback.onTimeSet(this, mTimePicker.getHours(), mTimePicker.getMinutes(), mTimePicker.getSeconds()); } dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_DEL) { if (mInKbMode) { if (!mTypedTimes.isEmpty()) { int deleted = deleteLastTypedKey(); String deletedKeyStr; if (deleted == getAmOrPmKeyCode(AM)) { deletedKeyStr = mAmText; } else if (deleted == getAmOrPmKeyCode(PM)) { deletedKeyStr = mPmText; } else { deletedKeyStr = String.format("%d", getValFromKeyCode(deleted)); } Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr)); updateDisplay(true); } } } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5 || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9 || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) { if (!mInKbMode) { if (mTimePicker == null) { // Something's wrong, because time picker should definitely not be null. Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null."); return true; } mTypedTimes.clear(); tryStartingKbMode(keyCode); return true; } // We're already in keyboard mode. if (addKeyIfLegal(keyCode)) { updateDisplay(false); } return true; } return false; }
From source file:com.android.mail.ui.ConversationViewFragment.java
@Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) { mOriginalKeyedView = view;/*from w ww .j a va 2 s .com*/ } if (mOriginalKeyedView != null) { final int id = mOriginalKeyedView.getId(); final boolean isRtl = ViewUtils.isViewRtl(mOriginalKeyedView); final boolean isActionUp = keyEvent.getAction() == KeyEvent.ACTION_UP; final boolean isStart = KeyboardUtils.isKeycodeDirectionStart(keyCode, isRtl); final boolean isEnd = KeyboardUtils.isKeycodeDirectionEnd(keyCode, isRtl); final boolean isUp = keyCode == KeyEvent.KEYCODE_DPAD_UP; final boolean isDown = keyCode == KeyEvent.KEYCODE_DPAD_DOWN; // First we run the event by the controller // We manually check if the view+direction combination should shift focus away from the // conversation view to the thread list in two-pane landscape mode. final boolean isTwoPaneLand = mNavigationController.isTwoPaneLandscape(); final boolean navigateAway = shouldNavigateAway(id, isStart, isTwoPaneLand); if (mNavigationController.onInterceptKeyFromCV(keyCode, keyEvent, navigateAway)) { return true; } // If controller didn't handle the event, check directional interception. if ((isStart || isEnd) && shouldInterceptLeftRightEvents(id, isStart, isEnd, isTwoPaneLand)) { return true; } else if (isUp || isDown) { // We don't do anything on up/down for overlay if (id == R.id.conversation_topmost_overlay) { return true; } // We manually handle up/down navigation through the overlay items because the // system's default isn't optimal for two-pane landscape since it's not a real list. final View next = mConversationContainer.getNextOverlayView(mOriginalKeyedView, isDown); if (next != null) { focusAndScrollToView(next); } else if (!isActionUp) { // Scroll in the direction of the arrow if next view isn't found. final int currentY = mWebView.getScrollY(); if (isUp && currentY > 0) { mWebView.scrollBy(0, -Math.min(currentY, DEFAULT_VERTICAL_SCROLL_DISTANCE_PX)); } else if (isDown) { final int webviewEnd = (int) (mWebView.getContentHeight() * mWebView.getScale()); final int currentEnd = currentY + mWebView.getHeight(); if (currentEnd < webviewEnd) { mWebView.scrollBy(0, Math.min(webviewEnd - currentEnd, DEFAULT_VERTICAL_SCROLL_DISTANCE_PX)); } } } return true; } // Finally we handle the special keys if (keyCode == KeyEvent.KEYCODE_BACK && id != R.id.conversation_topmost_overlay) { if (isActionUp) { mTopmostOverlay.requestFocus(); } return true; } else if (keyCode == KeyEvent.KEYCODE_ENTER && id == R.id.conversation_topmost_overlay) { if (isActionUp) { mWebView.scrollTo(0, 0); mConversationContainer.focusFirstMessageHeader(); } return true; } } return false; }
From source file:com.example.carsharing.ShortWayActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { Intent returnp = new Intent(ShortWayActivity.this, PersonalCenterActivity.class); returnp.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(returnp);/*from ww w. j av a2s . c om*/ return false; } else { return super.onKeyDown(keyCode, event); } }
From source file:com.speed.traquer.app.TraqComplaintTaxi.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { final AlertDialog.Builder alertBox = new AlertDialog.Builder(TraqComplaintTaxi.this); alertBox.setIcon(R.drawable.info_icon); alertBox.setCancelable(false);// w w w. j a v a 2 s. com alertBox.setTitle("Do you want to cancel complaint?"); alertBox.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { // finish used for destroyed activity easyTracker.send(MapBuilder .createEvent("Complaint", "Cancel Complaint (Yes)", "Complaint event", null).build()); NavUtils.navigateUpFromSameTask(TraqComplaintTaxi.this); } }); alertBox.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { easyTracker.send(MapBuilder .createEvent("Complaint", "Cancel Complaint (No)", "Complaint event", null).build()); dialog.cancel(); } }); alertBox.show(); } return super.onKeyDown(keyCode, event); }
From source file:com.instiwork.RegistrationFacebookActivity.java
public void dialogTermsUse() { View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.dialog_terms_use, null); mBottomSheetDialogTermsUse = new Dialog(RegistrationFacebookActivity.this, R.style.MaterialDialogSheet); mBottomSheetDialogTermsUse.setContentView(view); mBottomSheetDialogTermsUse.setCancelable(false); mBottomSheetDialogTermsUse.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBottomSheetDialogTermsUse.getWindow() .addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); mBottomSheetDialogTermsUse.getWindow().setStatusBarColor(Color.parseColor("#536942")); }/* www . j av a2s. c o m*/ mBottomSheetDialogTermsUse.getWindow().setGravity(Gravity.BOTTOM); mBottomSheetDialogTermsUse.show(); view.findViewById(R.id.back_me_dlog_payment).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mBottomSheetDialogTermsUse.dismiss(); } }); pBarTermsUse = (ProgressBar) view.findViewById(R.id.pbar_terms_use); // txtTermsUse = (RobotoLight) view.findViewById(R.id.txt_terms_use); webViewTermsUse = (WebView) view.findViewById(R.id.webv); webViewTermsUse.getSettings().setJavaScriptEnabled(true); webViewTermsUse.setVisibility(View.GONE); getTermsUse(InstiworkConstants.URL_DOMAIN + "Privacy_control"); mBottomSheetDialogTermsUse.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) if ((keyCode == KeyEvent.KEYCODE_BACK)) { mBottomSheetDialogTermsUse.dismiss(); return true; } return false; } }); }
From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java
private boolean handleKey(int keyCode, final KeyEvent event) { if (mDebug)/*from w w w . ja v a 2 s . co m*/ Log.d("DosBoxTurbo", "handleKey keyCode=" + keyCode); int tKeyCode = 0; // check for xperia play back case if (keyCode == KeyEvent.KEYCODE_BACK && event.isAltPressed()) { int backval = customMap.get(DosBoxPreferences.XPERIA_BACK_BUTTON); if (backval > 0) { // Special Sony XPeria Play case if (mEnableDpad) { // FIRE2 if ((mInputMode == INPUT_MODE_MOUSE) || (mInputMode == INPUT_MODE_REAL_MOUSE)) { DosBoxControl.nativeMouse(0, 0, 0, 0, (event.getAction() == KeyEvent.ACTION_DOWN) ? 0 : 1, BTN_B); } else if ((mInputMode == INPUT_MODE_JOYSTICK) || (mInputMode == INPUT_MODE_REAL_JOYSTICK)) { DosBoxControl.nativeJoystick(0, 0, (event.getAction() == KeyEvent.ACTION_DOWN) ? 0 : 1, BTN_B); } } else { // sony xperia play O (circle) button DosBoxControl.sendNativeKey(backval, (event.getAction() == KeyEvent.ACTION_DOWN), mModifierCtrl, mModifierAlt, mModifierShift); return true; // consume event } } return true; // consume event } // Handle all other keyevents int value = customMap.get(keyCode); if (value > 0) { // found a valid mapping tKeyCode = getMappedKeyCode(value, event); if (tKeyCode > MAP_NONE) { DosBoxControl.sendNativeKey(tKeyCode, (event.getAction() == KeyEvent.ACTION_DOWN), mModifierCtrl, mModifierAlt, mModifierShift); return true; // consume KeyEvent } else if (tKeyCode == MAP_EVENT_CONSUMED) { return true; } } if (keyCode == KeyEvent.KEYCODE_BACK) { // fishstix, allow remap of Android back button // catch no mapping if (event.getAction() == KeyEvent.ACTION_UP) { DBMenuSystem.doConfirmQuit(mParent); } return true; } switch (keyCode) { case KeyEvent.KEYCODE_UNKNOWN: break; default: boolean down = (event.getAction() == KeyEvent.ACTION_DOWN); if (mDebug) Log.d("DosBoxTurbo", "handleKey (default) keyCode=" + keyCode + " down=" + down); if (!down || (event.getRepeatCount() == 0)) { int unicode = event.getUnicodeChar(); // filter system generated keys, but not hardware keypresses if ((event.isAltPressed() || event.isShiftPressed()) && (unicode == 0) && ((event.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) == 0)) break; //fixed alt key problem for physical keyboard with only left alt if ((!mUseLeftAltOn) && (keyCode == KeyEvent.KEYCODE_ALT_LEFT)) { break; } if ((!mUseLeftAltOn) && (keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT)) { break; } if ((keyCode > 255) || (unicode > 255)) { //unknown keys break; } keyCode = keyCode | (unicode << 8); long diff = event.getEventTime() - event.getDownTime(); if (!down && (diff < 50)) { //simulate as long press if (mDebug) Log.d("DosBoxTurbo", "LongPress consumed keyCode=" + keyCode + " down=" + down); mKeyHandler.removeMessages(keyCode); mKeyHandler.sendEmptyMessageDelayed(keyCode, BUTTON_REPEAT_DELAY - diff); } else if (down && mKeyHandler.hasMessages(keyCode)) { if (mDebug) Log.d("DosBoxTurbo", "KeyUp consumed keyCode=" + keyCode + " down=" + down); //there is an key up in queue, should be repeated event } else { boolean result = DosBoxControl.sendNativeKey(keyCode, down, mModifierCtrl, mModifierAlt, mModifierShift); if (!down) { mModifierCtrl = false; mModifierAlt = false; mModifierShift = false; } return result; } } } return false; }
From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && hasVisibleDrawer()) { KeyEventCompat.startTracking(event); return true; }//from w w w. ja va 2s .c om return super.onKeyDown(keyCode, event); }