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.adafruit.bluefruit.le.connect.app.MainActivity.java
private void showStatusDialog(boolean show, int stringId) { if (show) {/*from ww w .java 2s . com*/ // Remove if a previous dialog was open (maybe because was clicked 2 times really quick) if (mConnectingDialog != null) { mConnectingDialog.cancel(); } AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(stringId); // Show dialog mConnectingDialog = builder.create(); mConnectingDialog.setCanceledOnTouchOutside(false); mConnectingDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { mBleManager.disconnect(); mConnectingDialog.cancel(); } return true; } }); mConnectingDialog.show(); } else { if (mConnectingDialog != null) { mConnectingDialog.cancel(); } } }
From source file:com.ruesga.rview.fragments.EditorFragment.java
@Override public boolean onKeyDown(int keycode, KeyEvent e) { switch (keycode) { case KeyEvent.KEYCODE_BACK: if (mBinding.editor.isDirty()) { readFileContent(this::performCancelEdit); return true; } else if (mIsDirty) { performCancelEdit();//from ww w. j a v a 2 s . c om return true; } } return false; }
From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK && keyCode != KeyEvent.KEYCODE_VOLUME_UP && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE && keyCode != KeyEvent.KEYCODE_MENU && keyCode != KeyEvent.KEYCODE_CALL && keyCode != KeyEvent.KEYCODE_ENDCALL; if (isInPlaybackState() && isKeyCodeSupported && mMediaController != null) { if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) { if (mMediaPlayer.isPlaying()) { pause();/* w ww . ja v a 2 s . c o m*/ mMediaController.show(); } else { start(); mMediaController.hide(); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) { if (!mMediaPlayer.isPlaying()) { start(); mMediaController.hide(); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) { if (mMediaPlayer.isPlaying()) { pause(); mMediaController.show(); } return true; } else { toggleMediaControlsVisibility(); } } return super.onKeyDown(keyCode, event); }
From source file:com.example.android.bluepayandroidsdk.MainActivity.java
private void showTopDialog(String strTitle) { hideTopDialog();/*w w w.ja v a2 s . c o m*/ if (dlgTopShow == null) dlgTopShow = new UniMagTopDialog(this); try { Window win = dlgTopShow.getWindow(); win.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND); dlgTopShow.setTitle("Initializing Device..."); dlgTopShow.setContentView(R.layout.dlgtopview); TextView myTV = (TextView) dlgTopShow.findViewById(R.id.TView_Info); myTV.setText(popupDialogMsg); dlgTopShow.setOnKeyListener(new DialogInterface.OnKeyListener() { public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { return false; } return true; } }); dlgTopShow.show(); } catch (Exception ex) { ex.printStackTrace(); dlgTopShow = null; } }
From source file:com.IntimateCarCare.MainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // ??// www . j a v a 2 s .c o m if (keyCode == KeyEvent.KEYCODE_BACK) { CustomDialog.Builder builder = new CustomDialog.Builder(MainActivity.this); builder.setMessage("??"); builder.setPositiveButton("", new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.dismiss(); HashMap<String, String> idtakjson = new UserEntity().getIdTaken(MainActivity.this); new HttpTask(exitCallback, MyURL.EXIT, MainActivity.this).execute(idtakjson); } }); builder.setNegativeButton("?", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.dismiss(); } }); builder.create().show(); } return false; }
From source file:com.example.android.bluepayandroidsdk.MainActivity.java
private void showErrorDialog(String strTitle) { hideTopDialog();/*from w w w.j ava 2s . c o m*/ if (dlgError == null) dlgError = new UniMagTopDialog(this); try { Window win = dlgError.getWindow(); win.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_BLUR_BEHIND); dlgError.setTitle("ERROR"); dlgError.setContentView(R.layout.dlgtopview); TextView myTV = (TextView) dlgError.findViewById(R.id.TView_Info); myTV.setText("There was an error when swiping the card."); dlgError.setOnKeyListener(new DialogInterface.OnKeyListener() { public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { return false; } return true; } }); dlgError.show(); } catch (Exception ex) { ex.printStackTrace(); dlgError = null; } }
From source file:com.phonegap.DroidGap.java
/** * Called when a key is pressed./*from w w w. j a v a 2s . c om*/ * * @param keyCode * @param event */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // If back key if (keyCode == KeyEvent.KEYCODE_BACK) { // If back key is bound, then send event to JavaScript if (mKey.isBound()) { this.appView.loadUrl("javascript:document.keyEvent.backTrigger()"); } // If not bound else { // Go to previous page in webview if it is possible to go back if (this.appView.canGoBack()) { this.appView.goBack(); } // If not, then invoke behavior of super class else { return super.onKeyDown(keyCode, event); } } } // If menu key else if (keyCode == KeyEvent.KEYCODE_MENU) { appView.loadUrl("javascript:keyEvent.menuTrigger()"); } // If search key else if (keyCode == KeyEvent.KEYCODE_SEARCH) { appView.loadUrl("javascript:keyEvent.searchTrigger()"); } return false; }
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Use this to monitor key events being delivered to the application. * We get first crack at them, and can either resume them or let them * continue to the app.//from ww w.jav a 2 s . c o m */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { //event. //Log.i("OnKeyDown", "Keycode: "+keyCode); switch (keyCode) { case KeyEvent.KEYCODE_BACK: // The InputMethodService already takes care of the back // key for us, to dismiss the input method if it is shown. // However, our keyboard could be showing a pop-up window // that back should dismiss, so we first allow it to do that. if (event.getRepeatCount() == 0 && mInputView != null) { if (mInputView.handleBack()) { return true; } } break; case KeyEvent.KEYCODE_DEL: // Special handling of the delete key: if we currently are // composing text for the user, we want to modify that instead // of let the application to the delete itself. if (mComposing.length() > 0) { onKey(Keyboard.KEYCODE_DELETE, null); return true; } break; case -2: //123 button //Log.i("KeyDown", "Keycode: "+keyCode); event.startTracking(); return true; case KeyEvent.KEYCODE_ENTER: // Let the underlying text editor always handle these. return false; default: // For all other keys, if we want to do transformations on // text being entered with a hard keyboard, we need to process // it and do the appropriate action. if (PROCESS_HARD_KEYS) { if (keyCode == KeyEvent.KEYCODE_SPACE && (event.getMetaState() & KeyEvent.META_ALT_ON) != 0) { // A silly example: in our input method, Alt+Space // is a shortcut for 'android' in lower case. //InputConnection ic = ic; if (ic != null) { // First, tell the editor that it is no longer in the // shift state, since we are consuming this. ic.clearMetaKeyStates(KeyEvent.META_ALT_ON); keyDownUp(KeyEvent.KEYCODE_A); keyDownUp(KeyEvent.KEYCODE_N); keyDownUp(KeyEvent.KEYCODE_D); keyDownUp(KeyEvent.KEYCODE_R); keyDownUp(KeyEvent.KEYCODE_O); keyDownUp(KeyEvent.KEYCODE_I); keyDownUp(KeyEvent.KEYCODE_D); // And we consume this event. return true; } } if (mPredictionOn && translateKeyDown(keyCode, event)) { return true; } } } return super.onKeyDown(keyCode, event); }
From source file:com.borax12.materialdaterangepicker.single.time.TimePickerDialog.java
/** * For keyboard mode, processes key events. * @param keyCode the pressed key./* w w w .ja v a2 s . c o m*/ * @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(mTimePicker, 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:android.support.v7ox.app.AppCompatDelegateImplV7.java
boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_MENU: onKeyUpPanel(Window.FEATURE_OPTIONS_PANEL, event); return true; case KeyEvent.KEYCODE_BACK: final boolean wasLongPressBackDown = mLongPressBackDown; mLongPressBackDown = false;// w w w .ja v a 2 s . c o m PanelFeatureState st = getPanelState(Window.FEATURE_OPTIONS_PANEL, false); if (st != null && st.isOpen) { if (!wasLongPressBackDown) { // Certain devices allow opening the options menu via a long press of the // back button. We should only close the open options menu if it wasn't // opened via a long press gesture. closePanel(st, true); } return true; } if (onBackPressed()) { return true; } break; } return false; }