List of usage examples for android.view KeyEvent KEYCODE_ENTER
int KEYCODE_ENTER
To view the source code for android.view KeyEvent KEYCODE_ENTER.
Click Source Link
From source file:com.appunite.list.ListView.java
private boolean commonKey(int keyCode, int count, KeyEvent event) { if (mAdapter == null || !mIsAttached) { return false; }// www. j a va2s . co m if (mDataChanged) { layoutChildren(); } boolean handled = false; int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_UP)) { handled = true; } else { break; } } } } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_DOWN)) { handled = true; } else { break; } } } } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_DPAD_LEFT: if (KeyEventCompat.hasNoModifiers(event)) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (KeyEventCompat.hasNoModifiers(event)) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) { keyPressed(); handled = true; } } break; case KeyEvent.KEYCODE_SPACE: if (mPopup == null || !mPopup.isShowing()) { if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } handled = true; } break; case KeyEvent.KEYCODE_PAGE_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_PAGE_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_MOVE_HOME: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_MOVE_END: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_TAB: // XXX Sometimes it is useful to be able to TAB through the items in // a ListView sequentially. Unfortunately this can create an // asymmetry in TAB navigation order unless the list selection // always reverts to the top or bottom when receiving TAB focus from // another widget. Leaving this behavior disabled for now but // perhaps it should be configurable (and more comprehensive). if (false) { if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_DOWN); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_UP); } } break; } } if (handled) { return true; } if (sendToTextFilter(keyCode, count, event)) { return true; } switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: return super.onKeyUp(keyCode, event); case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: // shouldn't happen return false; } }
From source file:com.tct.mail.ui.ConversationViewFragment.java
@Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) { mOriginalKeyedView = view;/*from w w w . ja v a2 s . c om*/ } if (mOriginalKeyedView != null) { final int id = mOriginalKeyedView.getId(); final boolean isActionUp = keyEvent.getAction() == KeyEvent.ACTION_UP; final boolean isLeft = keyCode == KeyEvent.KEYCODE_DPAD_LEFT; final boolean isRight = keyCode == KeyEvent.KEYCODE_DPAD_RIGHT; 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 = mConversationContainer.shouldNavigateAway(id, isLeft, isTwoPaneLand); if (mNavigationController.onInterceptKeyFromCV(keyCode, keyEvent, navigateAway)) { return true; } // If controller didn't handle the event, check directional interception. if ((isLeft || isRight) && mConversationContainer.shouldInterceptLeftRightEvents(id, isLeft, isRight, 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 int position = mConversationContainer.getViewPosition(mOriginalKeyedView); final View next = mConversationContainer.getNextOverlayView(position, isDown); if (next != null) { if (isActionUp) { next.requestFocus(); // Make sure that v is in view final int[] coords = new int[2]; next.getLocationOnScreen(coords); final int bottom = coords[1] + next.getHeight(); if (bottom > mMaxScreenHeight) { mWebView.scrollBy(0, bottom - mMaxScreenHeight); } else if (coords[1] < mTopOfVisibleScreen) { mWebView.scrollBy(0, coords[1] - mTopOfVisibleScreen); } } return true; } else { // Special case two end points // Start is marked as index 1 because we are currently not allowing focus on // conversation view header. if ((position == mConversationContainer.getOverlayCount() - 1 && isDown) || (position == 1 && isUp)) { mTopmostOverlay.requestFocus(); // Scroll to the the top if we hit the first item if (isUp) { mWebView.scrollTo(0, 0); } return true; } } } // Finally we handle the special keys if (keyCode == KeyEvent.KEYCODE_BACK && id != R.id.conversation_topmost_overlay) { if (isActionUp) { mTopmostOverlay.requestFocus(); } //TS: wenggangjin 2014-11-21 EMAIL BUGFIX_845619 MOD_S // return true; return false; //TS: wenggangjin 2014-11-21 EMAIL BUGFIX_845619 MOD_E } else if (keyCode == KeyEvent.KEYCODE_ENTER && id == R.id.conversation_topmost_overlay) { if (isActionUp) { mConversationContainer.focusFirstMessageHeader(); mWebView.scrollTo(0, 0); } return true; } } return false; }
From source file:com.zhongsou.souyue.ui.HListView.java
@TargetApi(11) private boolean commonKey(int keyCode, int count, KeyEvent event) { if (mAdapter == null || !mIsAttached) { return false; }/*from ww w .j a va 2 s. co m*/ if (mDataChanged) { layoutChildren(); } if (android.os.Build.VERSION.SDK_INT < 11) { return false; } boolean handled = false; int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_UP)) { handled = true; } else { break; } } } } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_DOWN)) { handled = true; } else { break; } } } } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_DPAD_LEFT: if (event.hasNoModifiers()) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (event.hasNoModifiers()) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded(); if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) { keyPressed(); handled = true; } } break; case KeyEvent.KEYCODE_SPACE: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } handled = true; break; case KeyEvent.KEYCODE_PAGE_UP: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_PAGE_DOWN: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_MOVE_HOME: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_MOVE_END: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_TAB: break; } } if (handled) { return true; } switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: return super.onKeyUp(keyCode, event); case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: // shouldn't happen return false; } }
From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java
@TargetApi(11) private boolean commonKey(int keyCode, int count, KeyEvent event) { if (mAdapter == null || !mIsAttached) { return false; }/* ww w .j a va2 s. c o m*/ if (mDataChanged) { layoutChildren(); } if (android.os.Build.VERSION.SDK_INT < 11) { return false; } boolean handled = false; int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_LEFT: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_UP)) { handled = true; } else { break; } } } } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_DOWN)) { handled = true; } else { break; } } } } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_DPAD_UP: if (event.hasNoModifiers()) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (event.hasNoModifiers()) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_DOWN); } break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded(); if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) { keyPressed(); handled = true; } } break; case KeyEvent.KEYCODE_SPACE: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } handled = true; break; case KeyEvent.KEYCODE_PAGE_UP: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_PAGE_DOWN: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (event.hasModifiers(KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_MOVE_HOME: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_MOVE_END: if (event.hasNoModifiers()) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_TAB: break; } } if (handled) { return true; } switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: return super.onKeyUp(keyCode, event); case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: // shouldn't happen return false; } }
From source file:org.petero.droidfish.DroidFish.java
private final Dialog selectMoveDialog() { setAutoMode(AutoMode.OFF);/*from ww w . ja v a 2 s. co m*/ View content = View.inflate(this, R.layout.select_move_number, null); final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(content); builder.setTitle(R.string.goto_move); final EditText moveNrView = (EditText) content.findViewById(R.id.selmove_number); moveNrView.setText("1"); final Runnable gotoMove = new Runnable() { public void run() { try { int moveNr = Integer.parseInt(moveNrView.getText().toString()); ctrl.gotoMove(moveNr); } catch (NumberFormatException nfe) { Toast.makeText(getApplicationContext(), R.string.invalid_number_format, Toast.LENGTH_SHORT) .show(); } } }; builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { gotoMove.run(); } }); builder.setNegativeButton(R.string.cancel, null); final AlertDialog dialog = builder.create(); moveNrView.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { gotoMove.run(); dialog.cancel(); return true; } return false; } }); return dialog; }
From source file:org.mdc.chess.MDChess.java
private void selectPgnSaveNewFileDialog() { setAutoMode(AutoMode.OFF);/*from w w w. j a v a2 s .c o m*/ View content = View.inflate(this, R.layout.create_pgn_file, null); final EditText fileNameView = (EditText) content.findViewById(R.id.create_pgn_filename); final TextInputLayout fileNameWrapper = (TextInputLayout) content .findViewById(R.id.create_pgn_filename_wrapper); fileNameWrapper.setHint(content.getResources().getString(R.string.filename)); fileNameView.setText(""); final Runnable savePGN = new Runnable() { public void run() { String pgnFile = fileNameView.getText().toString(); if ((pgnFile.length() > 0) && !pgnFile.contains(".")) { pgnFile += ".pgn"; } String sep = File.separator; String pathName = Environment.getExternalStorageDirectory() + sep + pgnDir + sep + pgnFile; savePGNToFile(pathName); } }; new MaterialDialog.Builder(this).title(R.string.select_pgn_file_save).customView(content, true) .positiveText(android.R.string.ok).negativeText(R.string.cancel) .onPositive(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { savePGN.run(); } }).onNegative(new MaterialDialog.SingleButtonCallback() { @Override public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) { } }).show(); fileNameView.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { savePGN.run(); return true; } return false; } }); }
From source file:com.aliasapps.seq.scroller.TwoWayView.java
private boolean handleKeyEvent(int keyCode, int count, KeyEvent event) { if (mAdapter == null || !mIsAttached) { return false; }// ww w.j a v a 2s . co m if (mDataChanged) { layoutChildren(); } boolean handled = false; final int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: if (mIsVertical) { handled = handleKeyScroll(event, count, View.FOCUS_UP); } else if (KeyEventCompat.hasNoModifiers(event)) { handled = handleFocusWithinItem(View.FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: { if (mIsVertical) { handled = handleKeyScroll(event, count, View.FOCUS_DOWN); } else if (KeyEventCompat.hasNoModifiers(event)) { handled = handleFocusWithinItem(View.FOCUS_DOWN); } break; } case KeyEvent.KEYCODE_DPAD_LEFT: if (!mIsVertical) { handled = handleKeyScroll(event, count, View.FOCUS_LEFT); } else if (KeyEventCompat.hasNoModifiers(event)) { handled = handleFocusWithinItem(View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (!mIsVertical) { handled = handleKeyScroll(event, count, View.FOCUS_RIGHT); } else if (KeyEventCompat.hasNoModifiers(event)) { handled = handleFocusWithinItem(View.FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) { keyPressed(); handled = true; } } break; case KeyEvent.KEYCODE_SPACE: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT); } handled = true; break; case KeyEvent.KEYCODE_PAGE_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_PAGE_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_MOVE_HOME: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_UP : View.FOCUS_LEFT); } break; case KeyEvent.KEYCODE_MOVE_END: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(mIsVertical ? View.FOCUS_DOWN : View.FOCUS_RIGHT); } break; } } if (handled) { return true; } switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: if (!isEnabled()) { return true; } if (isClickable() && isPressed() && mSelectedPosition >= 0 && mAdapter != null && mSelectedPosition < mAdapter.getCount()) { final View child = getChildAt(mSelectedPosition - mFirstPosition); if (child != null) { performItemClick(child, mSelectedPosition, mSelectedRowId); child.setPressed(false); } setPressed(false); return true; } return false; case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: return false; } }
From source file:com.appunite.list.AbsHorizontalListView.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (!isEnabled()) { return true; }/*w w w .j a v a 2s. c om*/ if (isClickable() && isPressed() && mSelectedPosition >= 0 && mAdapter != null && mSelectedPosition < mAdapter.getCount()) { final View view = getChildAt(mSelectedPosition - mFirstPosition); if (view != null) { performItemClick(view, mSelectedPosition, mSelectedColId); view.setPressed(false); } setPressed(false); return true; } break; } return super.onKeyUp(keyCode, event); }
From source file:org.petero.droidfish.DroidFish.java
private final Dialog selectPgnSaveNewFileDialog() { setAutoMode(AutoMode.OFF);/* w w w . j av a 2 s .c om*/ View content = View.inflate(this, R.layout.create_pgn_file, null); final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(content); builder.setTitle(R.string.select_pgn_file_save); final EditText fileNameView = (EditText) content.findViewById(R.id.create_pgn_filename); fileNameView.setText(""); final Runnable savePGN = new Runnable() { public void run() { String pgnFile = fileNameView.getText().toString(); if ((pgnFile.length() > 0) && !pgnFile.contains(".")) pgnFile += ".pgn"; String sep = File.separator; String pathName = Environment.getExternalStorageDirectory() + sep + pgnDir + sep + pgnFile; savePGNToFile(pathName, false); } }; builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { savePGN.run(); } }); builder.setNegativeButton(R.string.cancel, null); final Dialog dialog = builder.create(); fileNameView.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { savePGN.run(); dialog.cancel(); return true; } return false; } }); return dialog; }
From source file:com.appunite.list.AbsListView.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (!isEnabled()) { return true; }/*from w w w . ja va 2s. co m*/ if (isClickable() && isPressed() && mSelectedPosition >= 0 && mAdapter != null && mSelectedPosition < mAdapter.getCount()) { final View view = getChildAt(mSelectedPosition - mFirstPosition); if (view != null) { performItemClick(view, mSelectedPosition, mSelectedRowId); view.setPressed(false); } setPressed(false); return true; } break; } return super.onKeyUp(keyCode, event); }