List of usage examples for android.view KeyEvent KEYCODE_SEARCH
int KEYCODE_SEARCH
To view the source code for android.view KeyEvent KEYCODE_SEARCH.
Click Source Link
From source file:com.nononsenseapps.notepad.MainActivity.java
/** * If the user has a search button, ideally he should be able to use it. * Expand the search provider in that case *//*from w w w . j av a 2 s. com*/ @TargetApi(14) @Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_SEARCH: // Ignore this in HC because it will crash there if (getResources().getBoolean(R.bool.atLeast14)) { NotesListFragment list = getLeftFragment(); if (list != null && list.mSearchItem != null) { list.mSearchItem.expandActionView(); } else if (list != null) { onSearchRequested(); } } return true; case KeyEvent.KEYCODE_BACK: // Exit app finish(); return true; } return false; }
From source file:com.nachiket.titan.LibraryActivity.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (mSearchBoxVisible) { mTextFilter.setText(""); setSearchBoxVisible(false);//from www . j a va 2s .co m } else { Limiter limiter = mPagerAdapter.getCurrentLimiter(); if (limiter != null && limiter.type != MediaUtils.TYPE_FILE) { int pos = -1; switch (limiter.type) { case MediaUtils.TYPE_ALBUM: setLimiter(MediaUtils.TYPE_ARTIST, limiter.data.toString()); pos = mPagerAdapter.mAlbumsPosition; break; case MediaUtils.TYPE_ARTIST: mPagerAdapter.clearLimiter(MediaUtils.TYPE_ARTIST); pos = mPagerAdapter.mArtistsPosition; break; case MediaUtils.TYPE_GENRE: mPagerAdapter.clearLimiter(MediaUtils.TYPE_GENRE); pos = mPagerAdapter.mGenresPosition; break; } if (pos == -1) { updateLimiterViews(); } else { mViewPager.setCurrentItem(pos); } } else { finish(); } } break; case KeyEvent.KEYCODE_SEARCH: setSearchBoxVisible(!mSearchBoxVisible); break; default: return false; } return true; }
From source file:org.mozilla.gecko.AwesomeBar.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // This method is called only if the key event was not handled // by any of the views, which usually means the edit box lost focus if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_SEARCH || keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KeyEvent.KEYCODE_DPAD_DOWN || keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { return super.onKeyDown(keyCode, event); } else {//from w w w.ja v a 2 s . co m int selStart = -1; int selEnd = -1; if (mText.hasSelection()) { selStart = mText.getSelectionStart(); selEnd = mText.getSelectionEnd(); } // Return focus to the edit box, and dispatch the event to it mText.requestFocusFromTouch(); if (selStart >= 0) { // Restore the selection, which gets lost due to the focus switch mText.setSelection(selStart, selEnd); } mText.dispatchKeyEvent(event); return true; } }
From source file:br.com.bioscada.apps.biotracks.MarkerListActivity.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH && searchMenuItem != null) { if (ApiAdapterFactory.getApiAdapter().handleSearchKey(searchMenuItem)) { return true; }//from w ww .j a v a2 s .c o m } return super.onKeyUp(keyCode, event); }
From source file:de.uni.stuttgart.informatik.ToureNPlaner.UI.Activities.MapScreen.MapScreen.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH) { if (search != null) { MenuItemCompat.expandActionView(search); }//from w w w . java 2 s . c o m return true; } return super.onKeyUp(keyCode, event); }
From source file:aarddict.android.ArticleViewActivity.java
public boolean onKeyLongPress(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH) { finish();/* w w w .j a va2 s .co m*/ return true; } return super.onKeyLongPress(keyCode, event); }
From source file:in.shick.diode.threads.ThreadsListActivity.java
/** * http://stackoverflow.com/questions/2257963/android-how-to-show-dialog-to-confirm-user-wishes-to-exit-activity *///from w w w . ja v a2 s .c om @Override public boolean onKeyDown(int keyCode, KeyEvent event) { //Handle the back button if (mSettings.isConfirmQuitOrLogout() && keyCode == KeyEvent.KEYCODE_BACK && isTaskRoot()) { //Ask the user if they want to quit new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())) .setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.quit) .setMessage(R.string.really_quit) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //Stop the activity finish(); } }).setNegativeButton(R.string.no, null).show(); return true; } //if the search button is pressed else if (keyCode == KeyEvent.KEYCODE_SEARCH) { //start activity startActivityForResult(new Intent(this, RedditSearchActivity.class), Constants.ACTIVITY_SEARCH_REDDIT); return true; } else { return super.onKeyDown(keyCode, event); } }
From source file:org.telegram.ui.ActionBar.ActionBarMenuItem.java
public ActionBarMenuItem setIsSearchField(boolean value) { if (parentMenu == null) { return this; }/*w w w . j a va 2 s.com*/ if (value && searchContainer == null) { searchContainer = new FrameLayout(getContext()); parentMenu.addView(searchContainer, 0); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) searchContainer.getLayoutParams(); layoutParams.weight = 1; layoutParams.width = 0; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.leftMargin = AndroidUtilities.dp(6); searchContainer.setLayoutParams(layoutParams); searchContainer.setVisibility(GONE); searchField = new EditText(getContext()); searchField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); searchField.setHintTextColor(0x88ffffff); searchField.setTextColor(0xffffffff); searchField.setSingleLine(true); searchField.setBackgroundResource(0); searchField.setPadding(0, 0, 0, 0); int inputType = searchField.getInputType() | EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS; searchField.setInputType(inputType); searchField.setCustomSelectionActionModeCallback(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public void onDestroyActionMode(ActionMode mode) { } public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } }); searchField.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (/*actionId == EditorInfo.IME_ACTION_SEARCH || */event != null && (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) { AndroidUtilities.hideKeyboard(searchField); if (listener != null) { listener.onSearchPressed(searchField); } } return false; } }); searchField.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (listener != null) { listener.onTextChanged(searchField); } if (clearButton != null) { clearButton.setAlpha(s == null || s.length() == 0 ? 0.6f : 1.0f); } } @Override public void afterTextChanged(Editable s) { } }); try { Field mCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes"); mCursorDrawableRes.setAccessible(true); mCursorDrawableRes.set(searchField, R.drawable.search_carret); } catch (Exception e) { //nothing to do } searchField.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_SEARCH); searchField.setTextIsSelectable(false); searchContainer.addView(searchField); FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) searchField.getLayoutParams(); layoutParams2.width = LayoutHelper.MATCH_PARENT; layoutParams2.gravity = Gravity.CENTER_VERTICAL; layoutParams2.height = AndroidUtilities.dp(36); layoutParams2.rightMargin = AndroidUtilities.dp(48); searchField.setLayoutParams(layoutParams2); clearButton = new ImageView(getContext()); clearButton.setImageResource(R.drawable.ic_close_white); clearButton.setScaleType(ImageView.ScaleType.CENTER); clearButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { searchField.setText(""); searchField.requestFocus(); AndroidUtilities.showKeyboard(searchField); } }); searchContainer.addView(clearButton); layoutParams2 = (FrameLayout.LayoutParams) clearButton.getLayoutParams(); layoutParams2.width = AndroidUtilities.dp(48); layoutParams2.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT; layoutParams2.height = LayoutHelper.MATCH_PARENT; clearButton.setLayoutParams(layoutParams2); } isSearchField = value; return this; }
From source file:net.olejon.mdapp.MainActivity.java
@Override public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_SEARCH) { mSearchEditText.requestFocus();/*from w ww .ja v a2s . c o m*/ mInputMethodManager.showSoftInput(mSearchEditText, 0); return true; } return super.onKeyUp(keyCode, event); }
From source file:com.ninetwozero.battlelog.fragments.ForumThreadFragment.java
public boolean onKeyDown(int keyCode) { // Hotkeys/*from w w w . j a v a 2 s. c o m*/ if (keyCode == KeyEvent.KEYCODE_BACK) { if (slidingDrawer.isOpened()) { slidingDrawer.animateClose(); return true; } else { return false; } } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { startActivity(new Intent(context, ForumSearchActivity.class)); return true; } return false; }