List of usage examples for android.view.inputmethod EditorInfo IME_ACTION_SEARCH
int IME_ACTION_SEARCH
To view the source code for android.view.inputmethod EditorInfo IME_ACTION_SEARCH.
Click Source Link
From source file:com.amazon.android.tv.tenfoot.ui.fragments.ContentSearchFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = super.onCreateView(inflater, container, savedInstanceState); if (view != null) { // Set background color and drawable. view.setBackgroundColor(ContextCompat.getColor(getActivity(), android.R.color.transparent)); view.setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.search_background)); final SearchBar searchBar = (SearchBar) view.findViewById(R.id.lb_search_bar); if (searchBar != null) { // Set the left margin of the search bar. ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) searchBar .getLayoutParams();/* w w w . jav a 2 s . c o m*/ layoutParams.setMarginStart((int) getResources().getDimension(R.dimen.search_bar_margin_left)); searchBar.setLayoutParams(layoutParams); // Move the search bar items next to the search icon. RelativeLayout searchBarItems = (RelativeLayout) searchBar.findViewById(R.id.lb_search_bar_items); if (searchBarItems != null) { RelativeLayout.LayoutParams searchBarItemsLayoutParams = (RelativeLayout.LayoutParams) searchBarItems .getLayoutParams(); searchBarItemsLayoutParams.setMarginStart( (int) getResources().getDimension(R.dimen.search_bar_items_margin_left)); searchBarItems.setLayoutParams(searchBarItemsLayoutParams); // Set the search bar items background selector. searchBarItems.setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.search_edit_text_bg_color_selector)); } // Set speech orb icon. mSpeechOrbView = (SpeechOrbView) searchBar.findViewById(R.id.lb_search_bar_speech_orb); if (mSpeechOrbView != null) { mSpeechOrbView.setOrbIcon(ContextCompat.getDrawable(getActivity(), R.drawable.search_icon)); } final SearchEditText searchEditText = (SearchEditText) searchBar .findViewById(R.id.lb_search_text_editor); if (searchEditText != null) { mSearchEditText = searchEditText; // Handle keyboard being dismissed to prevent focus going to SearchOrb // If user presses back from keyboard, you don't get KeyboardDismissListener // so handle that here. searchEditText.setOnEditorActionListener((textView, actionId, keyEvent) -> { // Track search if keyboard is closed with IME_ACTION_PREVIOUS or // if IME_ACTION_SEARCH occurs. if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_PREVIOUS) { if (mQuery != null) { AnalyticsHelper.trackSearchQuery(mQuery); } } if (actionId == EditorInfo.IME_ACTION_PREVIOUS) { // Prevent highlighting SearchOrb mSpeechOrbView.setFocusable(false); mSpeechOrbView.clearFocus(); // If there are results allow first result to be selected if (mHasResults) { mSearchEditText.clearFocus(); } // Hide keyboard since we are handling the action if (isAdded()) { // Ensure we are added before calling getActivity InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); if (inputManager != null) { inputManager.hideSoftInputFromWindow( getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } else { Log.e(TAG, "Cannot find activity, can't dismiss keyboard"); // Couldn't handle action. // Will expose other focus issues potentially. return false; } // No more processing of this action. return true; } // Someone else needs to handle this action. return false; }); // Override the dismiss listener to get around keyboard issue where dismissing // keyboard takes user into first search result's // content_details_activity_layout page. searchEditText.setOnKeyboardDismissListener(() -> { // If search returns results, focus on the first item in the result list. // If search doesn't have results, this will focus on searchEditText again. mSpeechOrbView.setFocusable(false); mSpeechOrbView.clearFocus(); // We don't need to clearFocus on SearchEditText here, the first // result will be selected already. }); } } } return view; }
From source file:com.sft.fragment.CoachsFragment1.java
private void initData() { searchCoach.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchCoach.setOnEditorActionListener(new OnEditorActionListener() { @Override/*w ww .j a v a 2 s. co m*/ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { // ?? ((InputMethodManager) searchCoach.getContext().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); // ? LogUtil.print("?"); coachname = searchCoach.getText().toString().trim(); searchcoach(true); return true; } return false; } }); }
From source file:ru.moscow.tuzlukov.sergey.weatherlog.SettingsActivity.java
@Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { onClick(v);//w w w . j a v a2 s .com return true; } return false; }
From source file:pl.ipebk.tabi.presentation.ui.search.SearchActivity.java
private void prepareSearch(String searchText, boolean showKeyboard) { if (currentSearch != null && !currentSearch.equals("")) { showClearButton();/* ww w . j a v a 2 s . c o m*/ if (isFullySearched) { presenter.deepSearchForText(currentSearch); } else { presenter.quickSearchForText(currentSearch); } } else { hideClearButton(); } PublishSubject<Integer> textChangeSubject = PublishSubject.create(); textChangeSubject.asObservable().subscribe(i -> { Timber.d("Text can now be searched"); }); if (searchText != null) { currentSearch = searchText; if (searchText.equals("")) { hideClearButton(); } else { showClearButton(); } presenter.startInitialSearchForText(searchText); } if (showKeyboard) { showKeyboard(); } else { hideKeyboard(); } textChangesSubscription = RxTextView.textChanges(searchEditText).skipUntil(textChangeSubject) .debounce(300, TimeUnit.MILLISECONDS).map(CharSequence::toString) .doOnNext(presenter::quickSearchForText).doOnNext(text -> currentSearch = text) .observeOn(AndroidSchedulers.mainThread()).subscribe(text -> { if (text != null && !text.equals("")) { showClearButton(); } else { hideClearButton(); } }, ex -> Timber.e(ex, "Text subscription fail")); editorActionSubscription = RxTextView.editorActionEvents(searchEditText) .filter(event -> event.actionId() == EditorInfo.IME_ACTION_SEARCH).subscribe(e -> { presenter.deepSearchForText(searchEditText.getText().toString()); }, ex -> Timber.e(ex, "Text search click fail")); presenter.refreshSearch(); // makes sure subscription for text changes is no fired too soon textChangeSubject.onNext(1); }
From source file:mroza.forms.ChooseProgramActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { this.menu = menu; getMenuInflater().inflate(R.menu.choose_program_menu, menu); //Associate programs_searchable configuration with the SearchView SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); android.support.v7.widget.SearchView searchView = (android.support.v7.widget.SearchView) menu .findItem(R.id.action_search).getActionView(); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); EditText searchPlate = (EditText) searchView .findViewById(android.support.v7.appcompat.R.id.search_src_text); searchPlate.setImeOptions(EditorInfo.IME_ACTION_SEARCH); searchPlate.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override/*from ww w . ja v a 2 s . co m*/ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { //On search or enter clicked if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_NULL) { if (v.getText().toString().equals("")) { refreshChildTableList(); clearSearchField(); clearFilters(true); enableShowAllButton(false); } } return false; } }); restoreSavedFilters(); return true; }
From source file:com.eugene.fithealthmaingit.UI.ChooseAddMealSearchFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_search_add_item_fatsecret, container, false); // Change the notification bar color if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window w = getActivity().getWindow(); w.setStatusBarColor(getResources().getColor(R.color.light_grey)); }// w w w .j a va 2s . c om // Get MealType (snack, breakfast, lunch, dinner) Bundle extras = getActivity().getIntent().getExtras(); if (extras != null) { mealType = extras.getString(Globals.MEAL_TYPE); } // Initialize FatSecretSearchMethod mFatSecretSearch = new FatSecretSearchMethod(); mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swiperefresh); mSwipeRefreshLayout.setColorSchemeResources(R.color.primary, R.color.red, R.color.primary_dark); mSwipeRefreshLayout.setProgressViewOffset(true, Equations.dpToPx(getActivity(), 0), Equations.dpToPx(getActivity(), 112)); mSwipeRefreshLayout.setEnabled(false); mEtSearch = (EditText) v.findViewById(R.id.etSearch); // LogQuickSearch adapter to add items that have not been saved already mRecentLogAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all()); // List for adding items to the mItem = new ArrayList<>(); // Set to prevent duplicates being saved in LogQuickSearch set = new HashSet<>(); /** * set mListViewSearchResults adapter to SearchAdapterItemResult */ llSearch = (LinearLayout) v.findViewById(R.id.llSearch); listSearch = (ListView) v.findViewById(R.id.listSearch); searchLine = v.findViewById(R.id.searchLine); logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all()); mEtSearchAdapter = new SearchAdapterItemResult(getActivity(), mItem); mListViewSearchResults = (ListView) v.findViewById(R.id.listView); ViewGroup header = (ViewGroup) inflater.inflate(R.layout.list_search_header, mListViewSearchResults, false); mListViewSearchResults.addHeaderView(header, null, false); mListViewSearchResults.setAdapter(mEtSearchAdapter); mListViewSearchResults.setOnScrollListener(this); mListViewSearchResults.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent i = new Intent(getActivity(), SaveSearchAddItemActivityMain.class); i.putExtra(Globals.MEAL_TYPE, mealType); i.putExtra(Globals.MEAL_ID, mItem.get(position - 1).getID()); i.putExtra(Globals.MEAL_BRAND, mItem.get(position - 1).getBrand()); i.putExtra(Globals.MEAL_FAVORITE, "false"); startActivity(i); } }); // Toolbar mToolbarSearch = (Toolbar) v.findViewById(R.id.toolbar_search); mToolbarSearch.inflateMenu(R.menu.menu_search); mToolbarSearch.setNavigationIcon(R.mipmap.ic_arrow_back_grey); mToolbarSearch.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getActivity().getSupportFragmentManager().popBackStack(); } }); mToolbarSearch.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { if (menuItem.getItemId() == R.id.action_clear) { mEtSearch.setText(""); } if (menuItem.getItemId() == R.id.action_voice) { promptSpeechInput(); } return false; } }); mEtSearch.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 (mEtSearch.getText().toString().length() >= 1) { mToolbarSearch.getMenu().clear(); mToolbarSearch.inflateMenu(R.menu.menu_search_clear); logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.FilterByName(mEtSearch.getText().toString())); listSearch.setAdapter(logQuickSearchAdapter); } else { mToolbarSearch.getMenu().clear(); mToolbarSearch.inflateMenu(R.menu.menu_search); logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all()); listSearch.setAdapter(logQuickSearchAdapter); } mItem.clear(); updateListView(); } @Override public void afterTextChanged(Editable s) { } }); // Quick Search Clicked, start search based on list Item clicked from last fragment Bundle extrasFromRecentCliced = this.getArguments(); if (extrasFromRecentCliced != null) { String mealName = extrasFromRecentCliced.getString("MealName"); if (mealName != null) { mEtSearch.setText(mealName); mToolbarSearch.getMenu().clear(); mToolbarSearch.inflateMenu(R.menu.menu_search_clear); searchFood(mealName, 0); } } else { mEtSearch.requestFocus(); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); } /** * Handles softKeyboard search icon being clicked */ mEtSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mEtSearch.getWindowToken(), 0); listSearch.setVisibility(View.GONE); searchLine.setVisibility(View.GONE); searchFood(mEtSearch.getText().toString(), 0); mItem.clear(); mEtSearchAdapter.notifyDataSetChanged(); mEtSearch.clearFocus(); return true; } return false; } }); listSearch.setAdapter(logQuickSearchAdapter); listSearch.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { LogQuickSearch logQuickSearch = logQuickSearchAdapter.getItem(position); mEtSearch.setText(logQuickSearch.getName()); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mEtSearch.getWindowToken(), 0); listSearch.setVisibility(View.GONE); searchLine.setVisibility(View.GONE); searchFood(logQuickSearch.getName(), 0); mItem.clear(); mEtSearchAdapter.notifyDataSetChanged(); mEtSearch.clearFocus(); } }); updateListView(); return v; }
From source file:monakhv.android.samlib.AuthorListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onCreate(savedInstanceState); emptyText = (TextView) getActivity().findViewById(R.id.id_empty_text); sql = new AuthorController(getActivity()); setEmptyText(R.string.no_authors);//ww w . jav a2 s . c o m getListView().setEmptyView(emptyText); registerForContextMenu(getListView()); getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); //getListView().setSelector(R.drawable.author_item_bg); getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectedAuthorPosition = position; Cursor c = (Cursor) adapter.getItem(position); mCallbacks.onAuthorSelected(c.getInt(c.getColumnIndex(SQLController.COL_ID))); Log.i(DEBUG_TAG, "position: " + position + " view: " + view.getId() + " --- " + View.NO_ID); selectView(view); } }); setDivider(getListView()); EditText editText = (EditText) getActivity().findViewById(R.id.addUrlText); editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { mCallbacks.addAuthorFromText(); return true; } return false; } }); getListView().setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { detector.onTouchEvent(event); return false; } }); }
From source file:info.hl.mediam.GroupsActivity.java
private void OnClickListeners() { mBtnSearchGroups.setOnClickListener(new OnClickListener() { @Override/*from w w w. j a v a 2s . c o m*/ public void onClick(View v) { CenterSearch groupSearch = new CenterSearch(); groupSearch.setName(mEtSearchGroups.getText().toString()); new SearchGroupsAsync(GroupsActivity.this).execute(groupSearch); } }); mEtSearchGroups.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { CenterSearch groupSearch = new CenterSearch(); groupSearch.setName(mEtSearchGroups.getText().toString()); new SearchGroupsAsync(GroupsActivity.this).execute(groupSearch); return true; } return false; } }); }
From source file:cs.man.ac.uk.tavernamobile.fragments.SearchResultFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { // remove menu added by previous fragment for (int i = 1; i < menu.size(); i++) { menu.removeItem(menu.getItem(i).getItemId()); }/* w ww .j a v a 2 s . com*/ parentActivity.getMenuInflater().inflate(R.menu.search_results_screen, menu); LinearLayout searchView = (LinearLayout) menu.findItem(R.id.search_results_search).getActionView(); final EditText query = (EditText) searchView.getChildAt(0); query.requestFocus(); query.setOnEditorActionListener(new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { searchQuery = query.getText().toString(); search(searchQuery); return true; } return false; } }); ImageButton searchButton = (ImageButton) searchView.getChildAt(1); searchButton.setOnClickListener(new android.view.View.OnClickListener() { public void onClick(android.view.View v) { searchQuery = query.getText().toString(); search(searchQuery); } }); super.onPrepareOptionsMenu(menu); }
From source file:com.cloverstudio.spika.GroupsActivity.java
private void OnClickListeners() { mBtnSearchGroups.setOnClickListener(new OnClickListener() { @Override/*from w w w. j a v a 2s .c om*/ public void onClick(View v) { GroupSearch groupSearch = new GroupSearch(); groupSearch.setName(mEtSearchGroups.getText().toString()); new SearchGroupsAsync(GroupsActivity.this).execute(groupSearch); } }); mEtSearchGroups.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { GroupSearch groupSearch = new GroupSearch(); groupSearch.setName(mEtSearchGroups.getText().toString()); new SearchGroupsAsync(GroupsActivity.this).execute(groupSearch); return true; } return false; } }); }