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:com.hellofyc.base.app.activity.BaseActivity.java
@Override public boolean dispatchKeyEvent(@NonNull KeyEvent event) { final int keyCode = event.getKeyCode(); if (keyCode == KeyEvent.KEYCODE_BACK) { if (mPressTwoExit && mIsHighPriority) { final int action = event.getAction(); if (action == KeyEvent.ACTION_UP) { pressBackToExit();/*from w ww . j a v a2 s .c o m*/ return true; } } } return super.dispatchKeyEvent(event); }
From source file:ch.luklanis.esscan.history.HistoryActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { PsDetailFragment oldFragment = (PsDetailFragment) getFragmentManager() .findFragmentById(R.id.ps_detail_container); if (oldFragment != null) { int error = oldFragment.save(); if (error > 0) { setCancelOkAlert(error, true); return true; }//from w w w. j a v a 2 s. co m } } return super.onKeyDown(keyCode, event); }
From source file:com.haibison.android.lockpattern.LockPatternFragment.java
public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && ACTION_COMPARE_PATTERN.equals(fa.getIntent().getAction())) { /*/*from w w w .j a va2 s . c o m*/ * Use getActivity() hook instead of onBackPressed(), because onBackPressed() * is not available in API 4. */ finishWithNegativeResult(fa.RESULT_CANCELED); return true; } return fa.onKeyDown(keyCode, event); }
From source file:com.CrestronXPanelApp.CrestronXPanelApp.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { if (event.getRepeatCount() == 0 && specialList.containsKey("sideup")) { sendDigitalListMessage(specialList.get("sideup"), 0); }//from w ww. jav a2 s . c o m return true; } if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { if (event.getRepeatCount() == 0 && specialList.containsKey("sidedown")) { sendDigitalListMessage(specialList.get("sidedown"), 0); } return true; } if (keyCode == KeyEvent.KEYCODE_BACK) { this.finish(); } return super.onKeyDown(keyCode, event); }
From source file:com.example.android.foodrecipes.app.RecipeDetailsFragment.java
private void removeCurrentRecipeFromFavorites() { String title = getActivity().getString(R.string.text_please_wait); String text = getActivity().getString(R.string.text_removing_from_favorites); final ProgressDialog dialog = ProgressDialog.show(getActivity(), title, text); dialog.show();/*from w w w .jav a 2 s . com*/ final AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { String where = RecipeContract.RecipeEntry.COLUMN_EXTERNAL_ID + "=?"; String[] selectionArgs = new String[] { String.valueOf(mRecipe.getExternalId()) }; getActivity().getContentResolver().delete(CONTENT_URI, where, selectionArgs); return null; } @Override protected void onPostExecute(Void aVoid) { dialog.dismiss(); Toast.makeText(getActivity(), getActivity().getString(R.string.recipe_removed_from_favorites), Toast.LENGTH_SHORT).show(); if (!mTwoPane) { // if we operate in the two pane mode we should not finish the activity as // we have only one activity, but with two fragments inside getActivity().finish(); } } }; dialog.setOnKeyListener(new Dialog.OnKeyListener() { @Override public boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { task.cancel(true); dialog.dismiss(); } return true; } }); task.execute(); }
From source file:com.olearyp.gusto.Expsetup.java
@Override public boolean onKeyDown(final int keyCode, final KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_BACK) { final String reboot_type = getSharedPreferences("serverState", Context.MODE_PRIVATE) .getString("serverState", "none"); if (reboot_type.equals(getString(R.string.reboot_manual_flash_required))) { rebootDialog(R.string.reboot_alert_title, R.string.reboot_reflash_msg, R.string.reboot_recovery, true).show();/*from w w w .ja v a 2 s . c om*/ return true; } else if (reboot_type.equals(getString(R.string.reboot_recovery_required))) { rebootDialog(R.string.reboot_alert_title, R.string.reboot_autoflash_msg, R.string.reboot_recovery, true).show(); return true; } else if (reboot_type.equals(getString(R.string.reboot_required))) { rebootDialog(R.string.reboot_alert_title, R.string.reboot_request_msg, R.string.reboot, true) .show(); return true; } } return super.onKeyDown(keyCode, event); }
From source file:com.njlabs.amrita.aid.aums.AumsActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { exitAums();/*from w w w. j a v a 2s. c o m*/ return true; } return super.onKeyDown(keyCode, event); }
From source file:com.safecell.AccountFormActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { Intent intent = new Intent(AccountFormActivity.this, TrialOrAlreadyAccountActivity.class); startActivity(intent);//from w w w .j ava 2s. com finish(); } return super.onKeyDown(keyCode, event); }
From source file:com.example.angel.parkpanda.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { switch (event.getAction()) { case KeyEvent.ACTION_DOWN: if (event.getDownTime() - lastPressedTime < PERIOD) { System.exit(0);/* www .ja v a 2 s . c o m*/ finish(); } else { Toast.makeText(getApplicationContext(), "Press again to exit.", Toast.LENGTH_SHORT).show(); lastPressedTime = event.getEventTime(); } return true; } } return false; }
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 w w w .j a v a2 s . c o 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; }