Java Code Examples for android.view.KeyEvent#KEYCODE_ENTER

The following examples show how to use android.view.KeyEvent#KEYCODE_ENTER . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChipsView.java    From android-material-chips with Apache License 2.0 6 votes vote down vote up
@Override
public boolean sendKeyEvent(KeyEvent event) {
    if (mEditText.length() == 0) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
                selectOrDeleteLastChip();
                return true;
            }
        }
    }
    if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
        mEditText.append("\n");
        return true;
    }

    return super.sendKeyEvent(event);
}
 
Example 2
Source File: BrowserActivity.java    From JumpGo with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public boolean onEditorAction(TextView arg0, int actionId, KeyEvent arg2) {
    // hide the keyboard and search the web when the enter key
    // button is pressed
    if (actionId == EditorInfo.IME_ACTION_GO || actionId == EditorInfo.IME_ACTION_DONE
        || actionId == EditorInfo.IME_ACTION_NEXT
        || actionId == EditorInfo.IME_ACTION_SEND
        || actionId == EditorInfo.IME_ACTION_SEARCH
        || (arg2.getAction() == KeyEvent.KEYCODE_ENTER)) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(mSearch.getWindowToken(), 0);
        searchTheWeb(mSearch.getText().toString());
        final LightningView currentView = mTabsManager.getCurrentTab();
        if (currentView != null) {
            currentView.requestFocus();
        }
        return true;
    }
    return false;
}
 
Example 3
Source File: KeyEventUtils.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public static boolean isKeyboardFocusEvent(int keyCode){
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_DPAD_LEFT:
        case KeyEvent.KEYCODE_DPAD_RIGHT:
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_CAPS_LOCK:
        case KeyEvent.KEYCODE_ESCAPE:
        case KeyEvent.KEYCODE_BACK:
            return true;
        default:
            return false;
    }
}
 
Example 4
Source File: SearchScreenOverlay.java    From talkback with Apache License 2.0 6 votes vote down vote up
private boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
  switch (keyCode) {
    case (KeyEvent.KEYCODE_BACK):
      hide();
      return true;
    case (KeyEvent.KEYCODE_ENTER):
      // TODO: Add test cases for this.
      if (!keywordEditText.isFocused()) {
        return false;
      }

      if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
        performSearch();
      }
      return true;
    default:
      return false;
  }
}
 
Example 5
Source File: AbsHListView.java    From Klyph with MIT License 6 votes vote down vote up
@Override
public boolean onKeyUp( int keyCode, KeyEvent event ) {
	switch ( keyCode ) {
		case KeyEvent.KEYCODE_DPAD_CENTER:
		case KeyEvent.KEYCODE_ENTER:
			if ( !isEnabled() ) {
				return true;
			}
			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 );
}
 
Example 6
Source File: FindToolbar.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_F3
            || (keyCode == KeyEvent.KEYCODE_G && event.isCtrlPressed())) {
        mFindToolbar.startFinding(!event.isShiftPressed());
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 7
Source File: NumberPickerButton.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
            || (keyCode == KeyEvent.KEYCODE_ENTER)) {
        cancelLongpress();
    }
    return super.onKeyUp(keyCode, event);
}
 
Example 8
Source File: ChangeSeedPasswordDialog.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
@OnEditorAction(R.id.password_new_confirm)
public boolean onPasswordNewConfirmEditorAction(int actionId, KeyEvent event) {
    if ((actionId == EditorInfo.IME_ACTION_DONE)
            || ((event.getKeyCode() == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN))) {
        changeSeedPassword();
    }

    return true;
}
 
Example 9
Source File: MRLPanelFragment.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == EditorInfo.IME_ACTION_DONE ||
        keyCode == EditorInfo.IME_ACTION_GO ||
        event.getAction() == KeyEvent.ACTION_DOWN &&
        event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
        return processUri();
    }
    return false;
}
 
Example 10
Source File: AdbShell.java    From RemoteAdbShell with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_ENTER) {
		/* Just call the onEditorAction function to handle this for us */
		return onEditorAction((TextView)v, EditorInfo.IME_ACTION_DONE, event);
	}
	else {
		return false;
	}
}
 
Example 11
Source File: CustomEditText.java    From Android-WYSIWYG-Editor with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sendKeyEvent(KeyEvent event) {
   if(event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
        return super.sendKeyEvent(event);
    }else if(event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
       return super.sendKeyEvent(event);
   }
    return false;
}
 
Example 12
Source File: SearchBookContentsActivity.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(View view, int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
    launchSearch();
    return true;
  }
  return false;
}
 
Example 13
Source File: SearchActivity.java    From BmapLite with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEARCH || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
        mPage = 0;
        search();
        AppUtils.closeKeyboard(mEditSearch, this);
        return true;
    }
    return false;
}
 
Example 14
Source File: SearchView.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public boolean onKey(View v, int keyCode, KeyEvent event) {
    // guard against possible race conditions
    if (mSearchable == null) {
        return false;
    }

    if (DBG) {
        Log.d(LOG_TAG, "mTextListener.onKey(" + keyCode + "," + event + "), selection: "
                + mSearchSrcTextView.getListSelection());
    }

    // If a suggestion is selected, handle enter, search key, and action keys
    // as presses on the selected suggestion
    if (mSearchSrcTextView.isPopupShowing()
            && mSearchSrcTextView.getListSelection() != ListView.INVALID_POSITION) {
        return onSuggestionsKey(v, keyCode, event);
    }

    // If there is text in the query box, handle enter, and action keys
    // The search key is handled by the dialog's onKeyDown().
    if (!mSearchSrcTextView.isEmpty() && event.hasNoModifiers()) {
        if (event.getAction() == KeyEvent.ACTION_UP) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                v.cancelLongPress();

                // Launch as a regular search.
                launchQuerySearch(KeyEvent.KEYCODE_UNKNOWN, null, mSearchSrcTextView.getText()
                        .toString());
                return true;
            }
        }
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            SearchableInfo.ActionKeyInfo actionKey = mSearchable.findActionKey(keyCode);
            if ((actionKey != null) && (actionKey.getQueryActionMsg() != null)) {
                launchQuerySearch(keyCode, actionKey.getQueryActionMsg(), mSearchSrcTextView
                        .getText().toString());
                return true;
            }
        }
    }
    return false;
}
 
Example 15
Source File: ListPopupWindow.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Filter key down events. By forwarding key down events to this function,
 * views using non-modal ListPopupWindow can have it handle key selection of items.
 *
 * @param keyCode keyCode param passed to the host view's onKeyDown
 * @param event event param passed to the host view's onKeyDown
 * @return true if the event was handled, false if it was ignored.
 *
 * @see #setModal(boolean)
 * @see #onKeyUp(int, KeyEvent)
 */
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
    // when the drop down is shown, we drive it directly
    if (isShowing()) {
        // the key events are forwarded to the list in the drop down view
        // note that ListView handles space but we don't want that to happen
        // also if selection is not currently in the drop down, then don't
        // let center or enter presses go there since that would cause it
        // to select one of its items
        if (keyCode != KeyEvent.KEYCODE_SPACE
                && (mDropDownList.getSelectedItemPosition() >= 0
                        || !KeyEvent.isConfirmKey(keyCode))) {
            int curIndex = mDropDownList.getSelectedItemPosition();
            boolean consumed;

            final boolean below = !mPopup.isAboveAnchor();

            final ListAdapter adapter = mAdapter;

            boolean allEnabled;
            int firstItem = Integer.MAX_VALUE;
            int lastItem = Integer.MIN_VALUE;

            if (adapter != null) {
                allEnabled = adapter.areAllItemsEnabled();
                firstItem = allEnabled ? 0 :
                        mDropDownList.lookForSelectablePosition(0, true);
                lastItem = allEnabled ? adapter.getCount() - 1 :
                        mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false);
            }

            if ((below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex <= firstItem) ||
                    (!below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN && curIndex >= lastItem)) {
                // When the selection is at the top, we block the key
                // event to prevent focus from moving.
                clearListSelection();
                mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
                show();
                return true;
            } else {
                // WARNING: Please read the comment where mListSelectionHidden
                //          is declared
                mDropDownList.setListSelectionHidden(false);
            }

            consumed = mDropDownList.onKeyDown(keyCode, event);
            if (DEBUG) Log.v(TAG, "Key down: code=" + keyCode + " list consumed=" + consumed);

            if (consumed) {
                // If it handled the key event, then the user is
                // navigating in the list, so we should put it in front.
                mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
                // Here's a little trick we need to do to make sure that
                // the list view is actually showing its focus indicator,
                // by ensuring it has focus and getting its window out
                // of touch mode.
                mDropDownList.requestFocusFromTouch();
                show();

                switch (keyCode) {
                    // avoid passing the focus from the text view to the
                    // next component
                    case KeyEvent.KEYCODE_ENTER:
                    case KeyEvent.KEYCODE_DPAD_CENTER:
                    case KeyEvent.KEYCODE_DPAD_DOWN:
                    case KeyEvent.KEYCODE_DPAD_UP:
                        return true;
                }
            } else {
                if (below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
                    // when the selection is at the bottom, we block the
                    // event to avoid going to the next focusable widget
                    if (curIndex == lastItem) {
                        return true;
                    }
                } else if (!below && keyCode == KeyEvent.KEYCODE_DPAD_UP &&
                        curIndex == firstItem) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example 16
Source File: KeysInterpreter.java    From CodeEditor with Apache License 2.0 4 votes vote down vote up
private static boolean isNewline(KeyEvent event) {
	return (event.getKeyCode() == KeyEvent.KEYCODE_ENTER);
}
 
Example 17
Source File: TimePickerDialog.java    From DateTimepicker with Apache License 2.0 4 votes vote down vote up
/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        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());
        }
        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;
}
 
Example 18
Source File: SoftKeyboard.java    From AndroidKeyboard with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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.
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    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 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 = getCurrentInputConnection();
                    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);
}
 
Example 19
Source File: AppAdapter.java    From HgLauncher with GNU General Public License v3.0 4 votes vote down vote up
private static boolean isConfirmButton(KeyEvent event) {
    return event.getKeyCode() == KeyEvent.KEYCODE_ENTER;
}
 
Example 20
Source File: TwoWayGridView.java    From recent-images with MIT License 4 votes vote down vote up
private boolean commonKey(int keyCode, int count, KeyEvent event) {
	if (mAdapter == null) {
		return false;
	}

	if (mDataChanged) {
		layoutChildren();
	}

	boolean handled = false;
	int action = event.getAction();

	if (action != KeyEvent.ACTION_UP) {
		if (mSelectedPosition < 0) {
			switch (keyCode) {
			case KeyEvent.KEYCODE_DPAD_UP:
			case KeyEvent.KEYCODE_DPAD_DOWN:
			case KeyEvent.KEYCODE_DPAD_LEFT:
			case KeyEvent.KEYCODE_DPAD_RIGHT:
			case KeyEvent.KEYCODE_DPAD_CENTER:
			case KeyEvent.KEYCODE_SPACE:
			case KeyEvent.KEYCODE_ENTER:
				resurrectSelection();
				return true;
			}
		}

		switch (keyCode) {
		case KeyEvent.KEYCODE_DPAD_LEFT:
			if (!event.isAltPressed()) {
				handled = mGridBuilder.arrowScroll(FOCUS_LEFT);
			} else {
				handled = fullScroll(FOCUS_UP);
			}
			break;

		case KeyEvent.KEYCODE_DPAD_RIGHT:
			if (!event.isAltPressed()) {
				handled = mGridBuilder.arrowScroll(FOCUS_RIGHT);
			} else {
				handled = fullScroll(FOCUS_DOWN);
			}
			break;

		case KeyEvent.KEYCODE_DPAD_UP:
			if (!event.isAltPressed()) {
				handled = mGridBuilder.arrowScroll(FOCUS_UP);

			} else {
				handled = fullScroll(FOCUS_UP);
			}
			break;

		case KeyEvent.KEYCODE_DPAD_DOWN:
			if (!event.isAltPressed()) {
				handled = mGridBuilder.arrowScroll(FOCUS_DOWN);
			} else {
				handled = fullScroll(FOCUS_DOWN);
			}
			break;

		case KeyEvent.KEYCODE_DPAD_CENTER:
		case KeyEvent.KEYCODE_ENTER: {
			if (getChildCount() > 0 && event.getRepeatCount() == 0) {
				keyPressed();
			}

			return true;
		}

		case KeyEvent.KEYCODE_SPACE:
			//if (mPopup == null || !mPopup.isShowing()) {
			if (!event.isShiftPressed()) {
				handled = pageScroll(FOCUS_DOWN);
			} else {
				handled = pageScroll(FOCUS_UP);
			}
			//}
			break;
		}
	}

	//if (!handled) {
	//    handled = sendToTextFilter(keyCode, count, event);
	//}

	if (handled) {
		return true;
	} else {
		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:
			return false;
		}
	}
}