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:org.kde.kdeconnect.Plugins.RemoteKeyboardPlugin.RemoteKeyboardPlugin.java
private boolean handleSpecialKey(int key, boolean shift, boolean ctrl, boolean alt) { int keyEvent = specialKeyMap.get(key, 0); if (keyEvent == 0) return false; InputConnection inputConn = RemoteKeyboardService.instance.getCurrentInputConnection(); // Log.d("RemoteKeyboardPlugin", "Handling special key " + key + " translated to " + keyEvent + " shift=" + shift + " ctrl=" + ctrl + " alt=" + alt); // special sequences: if (ctrl && (keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT)) { // Ctrl + right -> next word ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0); int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT); if (pos == -1) pos = currentTextLength(extractedText); else/* www . j a v a2 s . c o m*/ pos++; int startPos = pos; int endPos = pos; if (shift) { // Shift -> select word (otherwise jump) Pair<Integer, Integer> sel = currentSelection(extractedText); int cursor = currentCursorPos(extractedText); // Log.d("RemoteKeyboardPlugin", "Selection (to right): " + sel.first + " / " + sel.second + " cursor: " + cursor); startPos = cursor; if (sel.first < cursor || // active selection from left to right -> grow sel.first > sel.second) // active selection from right to left -> shrink startPos = sel.first; } inputConn.setSelection(startPos, endPos); } else if (ctrl && keyEvent == KeyEvent.KEYCODE_DPAD_LEFT) { // Ctrl + left -> previous word ExtractedText extractedText = inputConn.getExtractedText(new ExtractedTextRequest(), 0); int pos = getCharPos(extractedText, ' ', keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT); if (pos == -1) pos = 0; else pos++; int startPos = pos; int endPos = pos; if (shift) { Pair<Integer, Integer> sel = currentSelection(extractedText); int cursor = currentCursorPos(extractedText); // Log.d("RemoteKeyboardPlugin", "Selection (to left): " + sel.first + " / " + sel.second + " cursor: " + cursor); startPos = cursor; if (cursor < sel.first || // active selection from right to left -> grow sel.first < sel.second) // active selection from right to left -> shrink startPos = sel.first; } inputConn.setSelection(startPos, endPos); } else if (shift && (keyEvent == KeyEvent.KEYCODE_DPAD_LEFT || keyEvent == KeyEvent.KEYCODE_DPAD_RIGHT || keyEvent == KeyEvent.KEYCODE_DPAD_UP || keyEvent == KeyEvent.KEYCODE_DPAD_DOWN || keyEvent == KeyEvent.KEYCODE_MOVE_HOME || keyEvent == KeyEvent.KEYCODE_MOVE_END)) { // Shift + up/down/left/right/home/end long now = SystemClock.uptimeMillis(); inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0)); inputConn.sendKeyEvent( new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON)); inputConn.sendKeyEvent( new KeyEvent(now, now, KeyEvent.ACTION_UP, keyEvent, 0, KeyEvent.META_SHIFT_LEFT_ON)); inputConn.sendKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0)); } else if (keyEvent == KeyEvent.KEYCODE_NUMPAD_ENTER || keyEvent == KeyEvent.KEYCODE_ENTER) { // Enter key EditorInfo editorInfo = RemoteKeyboardService.instance.getCurrentInputEditorInfo(); // Log.d("RemoteKeyboardPlugin", "Enter: " + editorInfo.imeOptions); if (editorInfo != null && (((editorInfo.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0) || ctrl)) { // Ctrl+Return overrides IME_FLAG_NO_ENTER_ACTION (FIXME: make configurable?) // check for special DONE/GO/etc actions first: int[] actions = { EditorInfo.IME_ACTION_GO, EditorInfo.IME_ACTION_NEXT, EditorInfo.IME_ACTION_SEND, EditorInfo.IME_ACTION_SEARCH, EditorInfo.IME_ACTION_DONE }; // note: DONE should be last or we might hide the ime instead of "go" for (int i = 0; i < actions.length; i++) { if ((editorInfo.imeOptions & actions[i]) == actions[i]) { // Log.d("RemoteKeyboardPlugin", "Enter-action: " + actions[i]); inputConn.performEditorAction(actions[i]); return true; } } } else { // else: fall back to regular Enter-event: // Log.d("RemoteKeyboardPlugin", "Enter: normal keypress"); inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent)); inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent)); } } else { // default handling: inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyEvent)); inputConn.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyEvent)); } return true; }
From source file:com.justplay1.shoppist.features.search.widget.FloatingSearchView.java
private void setupViews() { searchContainer.setLayoutTransition(getDefaultLayoutTransition()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) searchContainer.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING); ViewUtils.setBackground(searchContainer, searchBackground); searchContainer.setMinimumHeight((int) searchBackground.getMinHeight()); searchContainer.setMinimumWidth((int) searchBackground.getMinWidth()); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.addItemDecoration(cardDecorator); recyclerView.setHasFixedSize(true);// ww w .j ava 2 s .c om recyclerView.setVisibility(View.INVISIBLE); backgroundDrawable = getBackground(); if (backgroundDrawable != null) { backgroundDrawable = backgroundDrawable.mutate(); } else { backgroundDrawable = new ColorDrawable(DEFAULT_BACKGROUND_COLOR); } ViewUtils.setBackground(this, backgroundDrawable); backgroundDrawable.setAlpha(0); navButtonView.setOnClickListener(v -> { if (navigationClickListener != null) navigationClickListener.onNavigationClick(); }); setOnTouchListener((v, event) -> { if (!isActivated()) return false; setActivated(false); return onContainerTouchClickListener == null || onContainerTouchClickListener.onTouch(v, event); }); searchInput.setOnFocusChangeListener((v, hasFocus) -> { if (hasFocus != isActivated()) setActivated(hasFocus); }); searchInput.setOnKeyListener((view, keyCode, keyEvent) -> { if (keyCode != KeyEvent.KEYCODE_ENTER) return false; setActivated(false); return true; }); }
From source file:website.openeng.anki.Reviewer.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { char keyPressed = (char) event.getUnicodeChar(); if (mAnswerField != null && !mAnswerField.isFocused()) { if (sDisplayAnswer) { if (keyPressed == '1') { answerCard(EASE_1);//from w w w . jav a 2 s . co m return true; } if (keyPressed == '2') { answerCard(EASE_2); return true; } if (keyPressed == '3') { answerCard(EASE_3); return true; } if (keyPressed == '4') { answerCard(EASE_4); return true; } if (keyCode == KeyEvent.KEYCODE_SPACE || keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER) { answerCard(getDefaultEase()); return true; } } if (keyPressed == 'e') { editCard(); return true; } if (keyPressed == '*') { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_MARK_CARD, mMarkCardHandler, new DeckTask.TaskData(mCurrentCard, 0)); return true; } if (keyPressed == '-') { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler, new DeckTask.TaskData(mCurrentCard, 4)); return true; } if (keyPressed == '=') { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler, new DeckTask.TaskData(mCurrentCard, 0)); return true; } if (keyPressed == '@') { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler, new DeckTask.TaskData(mCurrentCard, 1)); return true; } if (keyPressed == '!') { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler, new DeckTask.TaskData(mCurrentCard, 2)); return true; } if (keyPressed == 'r' || keyCode == KeyEvent.KEYCODE_F5) { playSounds(true); return true; } } return super.onKeyUp(keyCode, event); }
From source file:dev.memento.MainActivity.java
private void initUI() { mDateChosenButton = (Button) findViewById(R.id.dateChosen); mDateDisplayedView = (TextView) findViewById(R.id.dateDisplayed); mNowButton = (Button) findViewById(R.id.nowButton); mNowButton.setEnabled(false);//from w ww.j a v a2 s . co m mPageLoadingProgressBar = (ProgressBar) findViewById(R.id.pageLoadProgressBar); mPageLoadingProgressBar.setVisibility(View.GONE); mMementoProgressBar = (ProgressBar) findViewById(R.id.loadMementosProgressBar); mMementoProgressBar.setVisibility(View.GONE); mLocation = (AutoCompleteTextView) findViewById(R.id.locationEditText); // Load list of popular URLs so they are easier to enter String[] defaultSites = getResources().getStringArray(R.array.defaultWebsites); if (mLocationAdapter == null) mLocationAdapter = new LocationAutoCompleteAdapter(this, android.R.layout.simple_dropdown_item_1line, defaultSites); mLocation.setAdapter(mLocationAdapter); mLocation.setFocusableInTouchMode(true); mLocation.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { // Go to URL if user presses enter if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { String url = Utilities.fixUrl(mLocation.getText().toString()); if (Utilities.isArchiveUrl(url)) { // Don't do anything but load the URL if (Log.LOG) Log.d(LOG_TAG, "Loading archive URL " + url); } else if (Utilities.isValidUrl(url)) { // Always bounce to the present when the user types a URL mOriginalUrl = url; if (Log.LOG) Log.d(LOG_TAG, "Browsing to NOW " + url); mLocationAdapter.add(url); resetMementoButtons(); mCurrentMemento = null; // Clear since we are visiting a different page in the present mMementos.clear(); surfToUrl(mOriginalUrl); // Hide the virtual keyboard ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mLocation.getWindowToken(), 0); mWebview.requestFocus(); return true; } else { MainActivity.this.showToast("Please enter a valid URL."); // Put focus back in text box mHandler.postDelayed(new Runnable() { @Override public void run() { mLocation.requestFocus(); // Select all text mLocation.setSelection(0, mLocation.getText().length()); } }, 200); return true; } } return false; } }); mNextButton = (ImageButton) findViewById(R.id.next); setImageButtonEnabled(false, mNextButton, R.drawable.next_item); mNextButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Advance to next Memento Memento nextMemento = null; // This could happen if the index has not been set yet if (mMementos.getCurrentIndex() < 0) { int index = mMementos.getIndexByDate(mDateDisplayed); if (index < 0) { if (Log.LOG) Log.d(LOG_TAG, "Could not find Memento with date " + mDateDisplayed + " (" + mMementos.size() + " mementos). Try to find next another way."); // Try alternative way of getting the next memento nextMemento = mMementos.getNext(mDateDisplayed); } else { mMementos.setCurrentIndex(index); nextMemento = mMementos.getNext(); } } else { // Locate the next Memento in the list nextMemento = mMementos.getNext(); } if (nextMemento == null) { // This could happen if we got redirected to the memento and didn't know // it was the last memento, so the Next button was not disabled if (Log.LOG) Log.d(LOG_TAG, "Still could not find next Memento."); if (Log.LOG) Log.d(LOG_TAG, "Current index is " + mMementos.getCurrentIndex()); setImageButtonEnabled(false, mNextButton, R.drawable.next_item); } else { SimpleDateTime date = nextMemento.getDateTime(); //setChosenDate(nextMemento.getDateTime()); showToast("Time traveling to next Memento on " + date.dateFormatted()); if (Log.LOG) Log.d(LOG_TAG, "Going to next Memento on " + date); mDateDisplayed = date; mCurrentMemento = nextMemento; String redirectUrl = nextMemento.getUrl(); surfToUrl(redirectUrl); // Just in case it wasn't already enabled //mPreviousButton.setEnabled(true); MainActivity.this.setImageButtonEnabled(true, mPreviousButton, R.drawable.previous_item); // If this is the last memento, disable button if (mMementos.isLast(date)) setImageButtonEnabled(false, mNextButton, R.drawable.next_item); } } }); mPreviousButton = (ImageButton) findViewById(R.id.previous); setImageButtonEnabled(false, mPreviousButton, R.drawable.previous_item); mPreviousButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Advance to previous Memento Memento prevMemento = null; // This could happen if the index has not been set yet if (mMementos.getCurrentIndex() < 0) { int index = mMementos.getIndexByDate(mDateDisplayed); if (index < 0) { if (Log.LOG) Log.d(LOG_TAG, "Could not find Memento with date " + mDateDisplayed + " (" + mMementos.size() + " mementos). Try to find previous" + " another way."); // Try alternative way of getting the pervious memento prevMemento = mMementos.getPrevious(mDateDisplayed); } else { mMementos.setCurrentIndex(index); prevMemento = mMementos.getPrevious(); } } else { // Locate the prev Memento in the list prevMemento = mMementos.getPrevious(); } if (prevMemento == null) { if (Log.LOG) Log.d(LOG_TAG, "Still could not find previous Memento!"); if (Log.LOG) Log.d(LOG_TAG, "Current index is " + mMementos.getCurrentIndex()); setImageButtonEnabled(false, mPreviousButton, R.drawable.previous_item); } else { SimpleDateTime date = prevMemento.getDateTime(); showToast("Time traveling to previous Memento on " + date.dateFormatted()); if (Log.LOG) Log.d(LOG_TAG, "Going to previous Memento on " + date); mDateDisplayed = date; mCurrentMemento = prevMemento; String redirectUrl = prevMemento.getUrl(); surfToUrl(redirectUrl); // Just in case it wasn't already enabled setImageButtonEnabled(true, mNextButton, R.drawable.next_item); // If this is the first memento, disable button if (mMementos.isFirst(date)) setImageButtonEnabled(false, mPreviousButton, R.drawable.previous_item); } } }); // Idea to use placeholder and handle orientation changes ourself is from here: // http://www.devahead.com/blog/2012/01/preserving-the-state-of-an-android-webview-on-screen-orientation-change/ webViewPlaceholder = ((FrameLayout) findViewById(R.id.webViewPlaceholder)); if (mWebview == null) { mWebview = new WebView(this); mWebview.setLayoutParams( new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); mWebview.getSettings().setSupportZoom(true); mWebview.getSettings().setBuiltInZoomControls(true); mWebview.getSettings().setLoadWithOverviewMode(true); // Setting to true allows the zoom-in to work, but problems moving around. // Sometimes the underlying webview library also set faults and crashes the app // http://stackoverflow.com/questions/17187338/android-fatal-signal-11-sigsegv-in-webviewcorethre // Safer to leave off although zoom won't work. //mWebview.getSettings().setUseWideViewPort(true); mWebview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); mWebview.setScrollbarFadingEnabled(true); mWebview.getSettings().setLoadsImagesAutomatically(true); mWebview.getSettings().setJavaScriptEnabled(true); mWebview.setWebViewClient(new MementoWebViewClient()); mWebview.setWebChromeClient(new MementoWebChromClient()); mWebview.getSettings().setUserAgentString(mUserAgent); // Must be declared before favicons will be received // http://stackoverflow.com/questions/3462582/display-the-android-webviews-favicon WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath()); surfToUrl(mCurrentUrl); // Get focus away from location field mWebview.requestFocus(); } webViewPlaceholder.addView(mWebview); mWebview.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // Hide the virtual keyboard ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mLocation.getWindowToken(), 0); return false; } }); }
From source file:cz.maresmar.sfm.view.guide.WelcomeActivity.java
/** * Done key on software keyboard and back key behaviour *///ww w . j a va2 s. c o m @Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: // Done pressed tryToMoveToNextPage(); return true; case KeyEvent.KEYCODE_BACK: if (mViewPager.getCurrentItem() != 0) { //Return to previous fragment mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1, true); return true; } default: return super.onKeyUp(keyCode, event); } }
From source file:com.duy.pascal.ui.editor.view.CodeSuggestsEditText.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { boolean consumed = mPopup.onKeyUp(keyCode, event); if (consumed) { switch (keyCode) { // if the list accepts the key events and the key event // was a click, the text view gets the selected item // from the drop down as its content case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_TAB: if (event.hasNoModifiers()) { performCompletion();//from w ww.ja v a2s. c o m } return true; } } if (isPopupShowing() && keyCode == KeyEvent.KEYCODE_TAB && event.hasNoModifiers()) { performCompletion(); return true; } return super.onKeyUp(keyCode, event); }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragmentKoopman.java
/** * Trigger the autocomplete on enter on the erkennings- en sollicitatenummer search textviews * @param view the autocomplete textview * @param actionId the type of action/*from www.jav a 2 s .com*/ * @param event the type of keyevent */ @OnEditorAction({ R.id.search_erkenningsnummer, R.id.search_sollicitatienummer }) public boolean onAutoCompleteEnter(AutoCompleteTextView view, int actionId, KeyEvent event) { if (((event != null) && (event.getAction() == KeyEvent.ACTION_DOWN) && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { showDropdown(view); } return true; }
From source file:de.vanita5.twittnuker.fragment.support.DirectMessagesConversationFragment.java
@Override public boolean onEditorAction(final TextView view, final int actionId, final KeyEvent event) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_ENTER: { sendDirectMessage();//www.j av a 2 s .c om return true; } } return false; }
From source file:com.ichi2.anki.Reviewer.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { char keyPressed = (char) event.getUnicodeChar(); if (mAnswerField != null && !mAnswerField.isFocused()) { if (sDisplayAnswer) { if (keyPressed == '1') { answerCard(EASE_1);/*w w w .j a v a 2 s . c om*/ return true; } if (keyPressed == '2') { answerCard(EASE_2); return true; } if (keyPressed == '3') { answerCard(EASE_3); return true; } if (keyPressed == '4') { answerCard(EASE_4); return true; } if (keyCode == KeyEvent.KEYCODE_SPACE || keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER) { answerCard(getDefaultEase()); return true; } } if (keyPressed == 'e') { editCard(); return true; } if (keyPressed == '*') { onMark(mCurrentCard); refreshActionBar(); return true; } if (keyPressed == '-') { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler, new DeckTask.TaskData(mCurrentCard, 4)); return true; } if (keyPressed == '=') { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler, new DeckTask.TaskData(mCurrentCard, 0)); return true; } if (keyPressed == '@') { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler, new DeckTask.TaskData(mCurrentCard, 1)); return true; } if (keyPressed == '!') { DeckTask.launchDeckTask(DeckTask.TASK_TYPE_DISMISS_NOTE, mDismissCardHandler, new DeckTask.TaskData(mCurrentCard, 2)); return true; } if (keyPressed == 'r' || keyCode == KeyEvent.KEYCODE_F5) { playSounds(true); return true; } // different from Anki Desktop if (keyPressed == 'z') { undo(); return true; } } return super.onKeyUp(keyCode, event); }