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.munger.passwordkeeper.view.ImportFileFragment.java
/** * get references to important components, setup the event handlers *///from w w w . j a v a 2 s. co m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //get component references root = (RelativeLayout) inflater.inflate(R.layout.fragment_importfile, container, false); upButton = (ImageButton) root.findViewById(R.id.import_uplevelbtn); reloadButton = (ImageButton) root.findViewById(R.id.import_refreshbtn); pathInput = (EditText) root.findViewById(R.id.import_pathinput); directoryList = (ListView) root.findViewById(R.id.import_filelist); if (currentDir != null) { populateViews(); } //setup event listeners //move to the previous directory upButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { navigateUp(); } }); //reload the directory list view reloadButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { populateViews(); } }); //set the current working directory and reload if the path is manually inputted pathInput.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { nextDir = pathInput.getText().toString(); populateViews(); return true; } return false; } }); return root; }
From source file:org.deviceconnect.android.deviceplugin.hue.activity.fragment.HueFragment04.java
/** * Edit serial.//from w ww .j a v a 2 s . co m */ private void editSerial() { final EditText editText = new EditText(getActivity()); editText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { InputMethodManager inputMethodManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0); return true; } return false; } }); AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.frag04_serial_number_title) .setMessage(R.string.frag04_serial_number_message).setView(editText) .setPositiveButton(R.string.frag04_serial_ok, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int whichButton) { String serial = editText.getText().toString(); searchLightManually(serial); } }).setNegativeButton(R.string.frag04_serial_cancel, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int whichButton) { } }).show(); final Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE); positiveButton.setEnabled(false); // Input limit of the serial number InputFilter inputFilter = new InputFilter() { @Override public CharSequence filter(final CharSequence source, final int start, final int end, final Spanned dest, final int dstart, final int dend) { if (source.toString().matches("[0-9a-fA-F]+")) { return source; } else { return ""; } } }; InputFilter[] filters = new InputFilter[] { inputFilter, new InputFilter.LengthFilter(6) }; editText.setFilters(filters); editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(final CharSequence s, final int start, final int count, final int after) { } @Override public void onTextChanged(final CharSequence s, final int start, final int before, final int count) { positiveButton.setEnabled(editText.length() == 6); } @Override public void afterTextChanged(final Editable s) { } }); editText.setHint(R.string.frag04_serial_number_hint); }
From source file:com.concavenp.artistrymuse.fragments.SearchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View mainView = inflater.inflate(R.layout.fragment_search, container, false); // The search text the user will input mSearchEditText = mainView.findViewById(R.id.search_editText); mSearchEditText.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override/*from w ww . j av a 2 s . co m*/ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((actionId == EditorInfo.IME_ACTION_SEARCH) || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { performSearch(); return true; } return false; } }); mSearchEditText.setOnTouchListener(new View.OnTouchListener() { @SuppressWarnings("unused") @Override public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { // Check the layout direction to support LTR or RTL if (ViewCompat.getLayoutDirection(mSearchEditText) == ViewCompat.LAYOUT_DIRECTION_LTR) { if (event.getRawX() >= (mSearchEditText.getRight() - mSearchEditText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { performSearch(); return true; } } else { if (event.getRawX() <= (mSearchEditText.getLeft() + mSearchEditText.getCompoundDrawables()[DRAWABLE_LEFT].getBounds().width())) { performSearch(); return true; } } } return false; } }); // Save off the flipper for use in deciding which view to show mFlipper = mainView.findViewById(R.id.fragment_search_ViewFlipper); // Get the ViewPager and set it's PagerAdapter so that it can display items ViewPager mViewPager = mainView.findViewById(R.id.search_results_viewpager); mSearchPagerAdapter = new SearchFragmentPagerAdapter(this, getChildFragmentManager()); mViewPager.setAdapter(mSearchPagerAdapter); mViewPager.setOffscreenPageLimit(mSearchPagerAdapter.getCount()); // Give the TabLayout the ViewPager TabLayout mTabLayout = mainView.findViewById(R.id.search_tabs); mTabLayout.setupWithViewPager(mViewPager); mFlipper.setDisplayedChild( mFlipper.indexOfChild(mFlipper.findViewById(R.id.fragment_search_no_search_Flipper))); return mainView; }
From source file:fr.ippon.android.opendata.android.AbstractParkingListFragment.java
private void configureSearchField(RelativeLayout r) { final AbstractParkingListFragment loaderCallBack = this; searchField = (EditText) r.findViewById(R.id.searchField); if (TextUtils.isEmpty(searchField.getText())) searchField.setText(searchHint); searchField.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // hide the keyboard InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(searchField.getWindowToken(), 0); // Perform action on key press boolean okSearch = !TextUtils.isEmpty(searchField.getText()) && !searchHint.equals(searchField.getText()); queryText = okSearch ? searchField.getText().toString() : null; Log.d(TAG, "query: " + queryText); hasSearched = true;/*from w w w .j a v a 2 s . co m*/ getLoaderManager().restartLoader(0, null, loaderCallBack); if (queryText == null) { searchField.setText(searchHint); } return true; } return false; } }); // afichage d'une croix dans l'edit text pour effacer le texte saisie final Drawable x = getResources().getDrawable(R.drawable.ic_cancel); x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight()); searchField.setCompoundDrawables(null, null, x, null); searchField.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && searchHint.equals(searchField.getText().toString())) { searchField.setText(""); } if (searchField.getCompoundDrawables()[2] == null) { // cross is not being shown so no need to handle return false; } if (event.getAction() != MotionEvent.ACTION_DOWN) { // only respond to the down type return false; } if (event.getX() > searchField.getMeasuredWidth() - searchField.getPaddingRight() - x.getIntrinsicWidth()) { searchField.setText(""); return true; } else { return false; } } }); }
From source file:com.stoutner.privacybrowser.CreateHomeScreenShortcut.java
@Override @NonNull// w w w. j a va2 s . co m public Dialog onCreateDialog(Bundle savedInstanceState) { // Create a drawable version of the favorite icon. Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIcon); // Use AlertDialog.Builder to create the AlertDialog AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); LayoutInflater customDialogInflater = getActivity().getLayoutInflater(); alertDialogBuilder.setTitle(R.string.shortcut_name); alertDialogBuilder.setIcon(favoriteIconDrawable); alertDialogBuilder.setView(customDialogInflater.inflate(R.layout.create_home_screen_shortcut_dialog, null)); alertDialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { buttonListener.onCreateHomeScreenShortcutCancel(CreateHomeScreenShortcut.this); } }); alertDialogBuilder.setPositiveButton(R.string.create, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { buttonListener.onCreateHomeScreenShortcutCreate(CreateHomeScreenShortcut.this); } }); // Assign the alertDialogBuilder to an AlertDialog. final AlertDialog alertDialog = alertDialogBuilder.create(); // Show the keyboard when the dialog is displayed on the screen. alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); // We need to show alertDialog before we can setOnKeyListener below. alertDialog.show(); EditText shortcutNameEditText = (EditText) alertDialog.findViewById(R.id.shortcutNameEditText); // Allow the "enter" key on the keyboard to create the shortcut. shortcutNameEditText.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button, select the PositiveButton "Create". if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Trigger the create listener. buttonListener.onCreateHomeScreenShortcutCreate(CreateHomeScreenShortcut.this); // Manually dismiss alertDialog. alertDialog.dismiss(); // Consume the event. return true; } else { // If any other key was pressed, do not consume the event. return false; } } }); // onCreateDialog requires the return of an AlertDialog. return alertDialog; }
From source file:com.openerp.base.account.AccountFragment.java
@SuppressLint("DefaultLocale") @Override// ww w . j ava 2s .c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { setHasOptionsMenu(true); this.context = getActivity(); // Inflate the layout for this fragment rootView = inflater.inflate(R.layout.fragment_account, container, false); scope = new AppScope(this); rootView.findViewById(R.id.edtServerURL).requestFocus(); getActivity().setTitle(R.string.title_setup_account); chkSecureConnection = (CheckBox) rootView.findViewById(R.id.chkIsSecureConnection); edtServerUrl = (EditText) rootView.findViewById(R.id.edtServerURL); chkSecureConnection.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { String serverUrl = edtServerUrl.getText().toString().toLowerCase(); if (chkSecureConnection.isChecked()) { serverUrl = serverUrl.replace("http://", ""); serverUrl = serverUrl.replace("https://", ""); serverUrl = "https://" + serverUrl; } else { serverUrl = serverUrl.replace("https://", ""); serverUrl = serverUrl.replace("http://", ""); } edtServerUrl.setText(serverUrl); edtServerUrl.setSelection(edtServerUrl.length()); } }); edtServerUrl.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { goNext(); } return false; } }); return rootView; }
From source file:com.battlelancer.seriesguide.ui.FixGetGlueCheckInActivity.java
private void setupViews() { mHeaderView = getLayoutInflater().inflate(R.layout.getglue_header, null); mSelectedValue = (TextView) mHeaderView.findViewById(R.id.textViewSelectedShowValue); mFooterView = getLayoutInflater().inflate(R.layout.getglue_footer, null); mSearchBox = (EditText) mFooterView.findViewById(R.id.editTextGetGlueSearch); mSearchBox.setOnKeyListener(new OnKeyListener() { @Override/*from w ww . j a v a2 s. com*/ public boolean onKey(View v, int keyCode, KeyEvent event) { // we only want to react to down events if (event.getAction() != KeyEvent.ACTION_DOWN) { return false; } if (keyCode == KeyEvent.KEYCODE_ENTER) { onSearch(mSearchBox.getText().toString()); return true; } else { return false; } } }); mFooterView.findViewById(R.id.buttonShowSearch).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { v.setVisibility(View.GONE); mSearchBox.setVisibility(View.VISIBLE); mSearchBox.requestFocus(); } }); findViewById(R.id.buttonDiscard).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(); } }); final Context context = this; mSaveButton = findViewById(R.id.buttonSaveSelection); mSaveButton.setEnabled(false); mSaveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // save new GetGlue object id CharSequence text = mSelectedValue.getText(); ShowTools.get(context).storeGetGlueId(Integer.valueOf(mShowId), text != null ? text.toString() : ""); finish(); } }); }
From source file:bbct.android.common.activity.BaseballCardDetails.java
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.card_details, container, false); ButterKnife.bind(this, view); final Activity activity = Objects.requireNonNull(getActivity()); String cardDetailsTitle = this.getString(R.string.card_details_title); String title = this.getString(R.string.bbct_title, cardDetailsTitle); activity.setTitle(title);//from w w w.j a va 2 s . com brandText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { Log.d(TAG, "onKey() in Brand TextView"); Log.d(TAG, "keyCode = " + keyCode); if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) { Log.d(TAG, "focus on Year"); yearText.requestFocus(); return true; } return false; } }); playerNameText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { Log.d(TAG, "onKey() in Player Name TextView"); Log.d(TAG, "keyCode = " + keyCode); if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) { Log.d(TAG, "focus on Team"); teamText.requestFocus(); return true; } return false; } }); teamText.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { Log.d(TAG, "onKey() in Team TextView"); Log.d(TAG, "keyCode = " + keyCode); if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_ENTER) { Log.d(TAG, "hide keyboard"); InputMethodManager imm = Objects.requireNonNull( (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)); imm.hideSoftInputFromWindow(teamText.getWindowToken(), 0); playerPositionSpinner.requestFocus(); return true; } return false; } }); createAdapters(activity); populateTextEdits(); return view; }
From source file:net.sourceforge.servestream.fragment.AddUrlFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mUrlEditText.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP) return false; if (keyCode != KeyEvent.KEYCODE_ENTER) return false; processUri();/*from ww w.java 2 s .co m*/ return true; } }); mCancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getActivity().finish(); } }); mConfirmButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { processUri(); } }); mSavePlaylistEntriesCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { mNicknameEditText.setEnabled(false); } else { mNicknameEditText.setEnabled(true); } } }); }
From source file:com.android.screenspeak.KeyboardSearchManager.java
@Override public boolean onKeyEvent(KeyEvent event) { // Only handle single-key events here. The KeyComboManager will pass us combos. if (event.getModifiers() != 0 || !mNodeSearch.isActive()) { return false; }//from ww w .j a va2 s .co m if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_ENTER: if (mHasNavigated || mNodeSearch.hasMatch()) { finishSearch(); mContext.getCursorController().clickCurrent(); } else { cancelSearch(); } return true; case KeyEvent.KEYCODE_DEL: resetHintTime(); final String queryText = mNodeSearch.getCurrentQuery(); if (queryText.isEmpty()) { cancelSearch(); } else { final String lastChar = queryText.substring(queryText.length() - 1); mNodeSearch.backspaceQueryText(); mSpeechController.speak(mContext.getString(R.string.template_text_removed, lastChar), SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null); } return true; case KeyEvent.KEYCODE_DPAD_UP: moveToEnd(NodeFocusFinder.SEARCH_BACKWARD); return true; case KeyEvent.KEYCODE_DPAD_LEFT: moveToNext(NodeFocusFinder.SEARCH_BACKWARD); return true; case KeyEvent.KEYCODE_DPAD_DOWN: moveToEnd(NodeFocusFinder.SEARCH_FORWARD); return true; case KeyEvent.KEYCODE_DPAD_RIGHT: moveToNext(NodeFocusFinder.SEARCH_FORWARD); return true; case KeyEvent.KEYCODE_SPACE: resetHintTime(); if (mNodeSearch.tryAddQueryText(" ")) { mSpeechController.speak(mContext.getString(R.string.symbol_space), SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null); } else { mContext.getFeedbackController().playAuditory(R.raw.complete); } return true; default: if (event.isPrintingKey()) { resetHintTime(); final String key = String.valueOf(event.getDisplayLabel()); if (mNodeSearch.tryAddQueryText(key)) { mSpeechController.speak(key.toLowerCase(), SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null); } else { mContext.getFeedbackController().playAuditory(R.raw.complete); } return true; } break; } } return false; }