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:net.olejon.mdapp.ClinicalTrialsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Input manager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Layout//www . j av a 2s .c o m setContentView(R.layout.activity_clinicaltrials); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.clinicaltrials_toolbar); toolbar.setTitle(getString(R.string.clinicaltrials_title)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbarSearchLayout = (LinearLayout) findViewById(R.id.clinicaltrials_toolbar_search_layout); mToolbarSearchEditText = (EditText) findViewById(R.id.clinicaltrials_toolbar_search); mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) { mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0); search(mToolbarSearchEditText.getText().toString().trim()); return true; } return false; } }); ImageButton imageButton = (ImageButton) findViewById(R.id.clinicaltrials_toolbar_clear_search); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mToolbarSearchEditText.setText(""); } }); // List mListView = (ListView) findViewById(R.id.clinicaltrials_list); View listViewEmpty = findViewById(R.id.clinicaltrials_list_empty); mListView.setEmptyView(listViewEmpty); View listViewHeader = getLayoutInflater().inflate(R.layout.activity_clinicaltrials_list_subheader, mListView, false); mListView.addHeaderView(listViewHeader, null, false); // Floating action button mFloatingActionButton = (FloatingActionButton) findViewById(R.id.clinicaltrials_fab); mFloatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mToolbarSearchLayout.getVisibility() == View.VISIBLE) { mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0); search(mToolbarSearchEditText.getText().toString().trim()); } else { mToolbarSearchLayout.setVisibility(View.VISIBLE); mToolbarSearchEditText.requestFocus(); mInputMethodManager.showSoftInput(mToolbarSearchEditText, 0); } } }); }
From source file:org.whisperim.android.ui.ChatWindow.java
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN)) { Log.i("WhisperIM", "KeyCodeIntercepted: " + keyCode); if (messageBox_.getText().toString().equalsIgnoreCase("")) { return true; }/* w w w . j a va2s .co m*/ sendMessage(); return true; } return false; }
From source file:com.spoiledmilk.ibikecph.search.SearchAutocompleteActivity.java
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search_autocomplete_activiy); progressBar = (ProgressBar) findViewById(R.id.progressBar); progressBar.setVisibility(View.INVISIBLE); Bundle data = getIntent().getExtras(); if (data != null) { isA = data.getBoolean("isA", false); }//from w ww . j av a 2 s . c o m btnClose = (Button) findViewById(R.id.btnClose); btnClose.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { isClose = true; finishEditing(); } }); btnClear = (ImageButton) findViewById(R.id.btnClear); textSrch = (EditText) findViewById(R.id.textLocation); textSrch.addTextChangedListener(new MyTextWatcher()); textSrch.setImeActionLabel("Go", KeyEvent.KEYCODE_ENTER); textSrch.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER) { if (currentSelection == null && listSearch.getAdapter() != null && listSearch.getAdapter().getCount() > 0) { onItemClicked(0, false); } else if (currentSelection != null) { finishEditing(); } return true; } return false; } }); listSearch = (ListView) findViewById(R.id.listSearch); adapter = new AutocompleteAdapter(this, new ArrayList<SearchListItem>(), isA); listSearch.setAdapter(adapter); if (isA) { adapter.add(new CurrentLocation()); } listSearch.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long arg3) { onItemClicked(position, true); } }); if (data != null && data.containsKey("lastName")) { ArrayList<SearchListItem> listData = new ArrayList<SearchListItem>(); DB db = new DB(this); String reuseName = data.getString("lastName"); SearchListItem sli = db.getFavoriteByName(reuseName); if (sli != null) { listData.add(sli); } else { sli = db.getSearchHistoryByName(reuseName); if (sli != null) { listData.add(sli); } else { SharedPreferences prefs = getPreferences(MODE_PRIVATE); String nodeStr = prefs.getString("lastSearchItem", null); if (nodeStr != null) { JsonNode node = Util.stringToJsonNode(nodeStr); if (node != null) { sli = SearchListItem.instantiate(node); if (sli != null) { listData.add(sli); } } } } } db.close(); addr = AddressParser.parseAddressRegex(reuseName); adapter.updateListData(listData, AddressParser.addresWithoutNumber(reuseName), addr); textSrch.setText(reuseName); textSrch.setSelection(reuseName.length()); } }
From source file:com.mercandalli.android.apps.files.user.RegistrationFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_registration, container, false); this.mUsername = (EditText) rootView.findViewById(R.id.fragment_registration_username); this.mPassword = (EditText) rootView.findViewById(R.id.fragment_registration_password); ((CheckBox) rootView.findViewById(R.id.fragment_registration_auto_connection)) .setChecked(Config.isAutoConnection()); ((CheckBox) rootView.findViewById(R.id.fragment_registration_auto_connection)) .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override/* w ww .j a v a2s. c o m*/ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Config.setAutoConnection(getContext(), isChecked); } }); this.mUsername.setOnEditorActionListener(new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { RegistrationFragment.this.mPassword.requestFocus(); return true; } return false; } }); this.mPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { inscription(); return true; } return false; } }); return rootView; }
From source file:org.mozilla.gecko.home.PinSiteDialog.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mSearch = (EditText) view.findViewById(R.id.search); mSearch.addTextChangedListener(new TextWatcher() { @Override/*from w w w. j a va 2 s. c o m*/ public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { setSearchTerm(mSearch.getText().toString()); filter(mSearchTerm); } }); mSearch.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode != KeyEvent.KEYCODE_ENTER || mOnSiteSelectedListener == null) { return false; } // If the user manually entered a search term or URL, wrap the value in // a special URI until we can get a valid URL for this bookmark. final String text = mSearch.getText().toString().trim(); if (!TextUtils.isEmpty(text)) { final String url = StringUtils.encodeUserEnteredUrl(text); mOnSiteSelectedListener.onSiteSelected(url, text); dismiss(); } return true; } }); mSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { getDialog().getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); mList = (HomeListView) view.findViewById(R.id.list); mList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (mOnSiteSelectedListener != null) { final Cursor c = mAdapter.getCursor(); if (c == null || !c.moveToPosition(position)) { return; } final String url = c.getString(c.getColumnIndexOrThrow(URLColumns.URL)); final String title = c.getString(c.getColumnIndexOrThrow(URLColumns.TITLE)); mOnSiteSelectedListener.onSiteSelected(url, title); } // Dismiss the fragment and the dialog. dismiss(); } }); }
From source file:com.dmbstream.android.activity.SearchResultsActivity.java
@Override public boolean onKey(View view, int i, KeyEvent keyEvent) { switch (keyEvent.getKeyCode()) { case KeyEvent.KEYCODE_SEARCH: case KeyEvent.KEYCODE_ENTER: AnalyticsUtil.trackEvent(SearchResultsActivity.this, "SearchResults", "Enter", "Query", 0); search();//from w ww . j ava 2 s . c o m return true; } return false; }
From source file:net.olejon.mdapp.InteractionsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Intent// w w w . j a v a2 s. co m final Intent intent = getIntent(); final String searchString = (intent.getStringExtra("search") == null) ? "" : intent.getStringExtra("search").split(" ")[0]; // Input manager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); // Layout setContentView(R.layout.activity_interactions); // Toolbar final Toolbar toolbar = (Toolbar) findViewById(R.id.interactions_toolbar); toolbar.setTitle(getString(R.string.interactions_title)); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToolbarSearchLayout = (LinearLayout) findViewById(R.id.interactions_toolbar_search_layout); mToolbarSearchEditText = (EditText) findViewById(R.id.interactions_toolbar_search); mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) { mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0); search(mToolbarSearchEditText.getText().toString()); return true; } return false; } }); ImageButton imageButton = (ImageButton) findViewById(R.id.interactions_toolbar_clear_search); imageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mToolbarSearchEditText.setText(""); } }); if (!searchString.equals("")) { mToolbarSearchLayout.setVisibility(View.VISIBLE); mToolbarSearchEditText.setText(searchString + " "); mToolbarSearchEditText.setSelection(mToolbarSearchEditText.getText().length()); mTools.showToast(getString(R.string.interactions_search_other_medications_or_substances), 1); } // List mListView = (ListView) findViewById(R.id.interactions_list); View listViewEmpty = findViewById(R.id.interactions_list_empty); mListView.setEmptyView(listViewEmpty); View listViewHeader = getLayoutInflater().inflate(R.layout.activity_interactions_list_subheader, mListView, false); mListView.addHeaderView(listViewHeader, null, false); // Floating action button mFloatingActionButton = (FloatingActionButton) findViewById(R.id.interactions_fab); mFloatingActionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mToolbarSearchLayout.getVisibility() == View.VISIBLE) { mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0); search(mToolbarSearchEditText.getText().toString()); } else { mToolbarSearchLayout.setVisibility(View.VISIBLE); mToolbarSearchEditText.requestFocus(); mInputMethodManager.showSoftInput(mToolbarSearchEditText, 0); } } }); }
From source file:com.cybrosys.basic.EventListener.java
@Override public boolean onKey(View vwView, int keyCode, KeyEvent keyEvent) { int action = keyEvent.getAction(); if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT); return eat; }//from ww w.j a v a 2s. c o m if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) { return true; } if (keyEvent.getUnicodeChar() == '=') { if (action == KeyEvent.ACTION_UP) { mHandler.onEnter(); } return true; } if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) { return false; } if (action == KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: mHandler.onEnter(); break; case KeyEvent.KEYCODE_DPAD_UP: mHandler.onUp(); break; case KeyEvent.KEYCODE_DPAD_DOWN: mHandler.onDown(); break; } } return true; }
From source file:org.catrobat.catroid.ui.dialogs.TextDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_text_dialog, null); input = (EditText) dialogView.findViewById(R.id.dialog_text_edit_text); inputTitle = (TextView) dialogView.findViewById(R.id.dialog_text_text_view); if (getHint() != null) { input.setHint(getHint());//from w w w . ja v a 2s . c om } input.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (hasFocus) { getDialog().getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); initialize(); Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle()) .setNegativeButton(R.string.cancel_button, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dismiss(); } }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).create(); dialog.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { boolean okButtonResult = handleOkButton(); onOkButtonHandled(); if (okButtonResult) { dismiss(); } return okButtonResult; } return false; } }); dialog.setCanceledOnTouchOutside(true); dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE); buttonPositive.setEnabled(getPositiveButtonEnabled()); setPositiveButtonClickCustomListener(); InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT); initTextChangedListener(); } }); return dialog; }
From source file:com.android.example.github.ui.search.SearchFragment.java
private void initSearchInputListener() { binding.get().input.setOnEditorActionListener((v, actionId, event) -> { if (actionId == EditorInfo.IME_ACTION_SEARCH) { doSearch(v);/*from w w w. ja va 2 s .co m*/ return true; } return false; }); binding.get().input.setOnKeyListener((v, keyCode, event) -> { if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { doSearch(v); return true; } return false; }); }