Example usage for android.view.inputmethod EditorInfo IME_ACTION_SEARCH

List of usage examples for android.view.inputmethod EditorInfo IME_ACTION_SEARCH

Introduction

In this page you can find the example usage for android.view.inputmethod EditorInfo IME_ACTION_SEARCH.

Prototype

int IME_ACTION_SEARCH

To view the source code for android.view.inputmethod EditorInfo IME_ACTION_SEARCH.

Click Source Link

Document

Bits of #IME_MASK_ACTION : the action key performs a "search" operation, taking the user to the results of searching for the text they have typed (in whatever context is appropriate).

Usage

From source file:org.thialfihar.android.apg.ui.ImportKeysServerFragment.java

/**
 * Inflate the layout for this fragment// ww  w  . ja  v a2s  . c  om
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.import_keys_server_fragment, container, false);

    mSearchButton = (BootstrapButton) view.findViewById(R.id.import_server_search);
    mQueryEditText = (EditText) view.findViewById(R.id.import_server_query);
    mServerSpinner = (Spinner) view.findViewById(R.id.import_server_spinner);

    // add keyservers to spinner
    mServerAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            Preferences.getPreferences(getActivity()).getKeyServers());
    mServerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mServerSpinner.setAdapter(mServerAdapter);
    if (mServerAdapter.getCount() > 0) {
        mServerSpinner.setSelection(0);
    } else {
        mSearchButton.setEnabled(false);
    }

    mSearchButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            String query = mQueryEditText.getText().toString();
            String keyServer = (String) mServerSpinner.getSelectedItem();
            search(query, keyServer);

            // close keyboard after pressing search
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mQueryEditText.getWindowToken(), 0);
        }
    });

    mQueryEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                String query = mQueryEditText.getText().toString();
                String keyServer = (String) mServerSpinner.getSelectedItem();
                search(query, keyServer);

                // Don't return true to let the keyboard close itself after pressing search
                // http://bit.ly/1n52gUM
                return false;
            }
            return false;
        }
    });

    return view;
}

From source file:com.battlelancer.seriesguide.ui.MoviesSearchFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_movies_search, container, false);
    ButterKnife.inject(this, v);

    // setup grid view
    resultsGridView.setEmptyView(emptyView);
    resultsGridView.setOnItemClickListener(this);

    // setup search box
    searchBox.setThreshold(1);//www.ja  va  2  s . c  om
    searchBox.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH
                    || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                search();
                return true;
            }
            return false;
        }
    });
    searchBox.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            ((AutoCompleteTextView) v).showDropDown();
        }
    });
    searchBox.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            search();
        }
    });
    // set in code as XML is overridden
    searchBox.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchBox.setInputType(EditorInfo.TYPE_CLASS_TEXT);

    // setup clear button
    clearButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            searchBox.setText(null);
            searchBox.requestFocus();
        }
    });

    setProgressVisible(false, false);

    return v;
}

From source file:org.sufficientlysecure.keychain.ui.ImportKeysCloudFragment.java

/**
 * Inflate the layout for this fragment/*w  w w . ja va 2  s  .  co  m*/
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.import_keys_cloud_fragment, container, false);

    mQueryEditText = (AutoCompleteTextView) view.findViewById(R.id.cloud_import_server_query);

    ContactHelper contactHelper = new ContactHelper(getActivity());
    List<String> namesAndEmails = contactHelper.getContactNames();
    namesAndEmails.addAll(contactHelper.getContactMails());
    mQueryEditText.setThreshold(3);
    mQueryEditText.setAdapter(
            new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, namesAndEmails));

    View searchButton = view.findViewById(R.id.cloud_import_server_search);
    searchButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            search(mQueryEditText.getText().toString());
        }
    });

    mQueryEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                search(mQueryEditText.getText().toString());

                // Don't return true to let the keyboard close itself after pressing search
                return false;
            }
            return false;
        }
    });

    View configButton = view.findViewById(R.id.cloud_import_server_config_button);
    configButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(mImportActivity, SettingsActivity.class);
            intent.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT,
                    SettingsActivity.CloudSearchPrefsFragment.class.getName());
            startActivity(intent);
        }
    });

    return view;
}

From source file:com.j_o.android.imdb_client.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mediaList = new ArrayList<Media>();
    mediaGrid = (GridView) findViewById(R.id.media_grid_view);
    editTxMediaSearch = (EditText) findViewById(R.id.edit_search_media);

    // Input filter that not allow special characters.
    InputFilter filter = new InputFilter() {
        @Override/*  w w w  .j  a v  a 2s.  c o m*/
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {

            if (source instanceof SpannableStringBuilder) {
                SpannableStringBuilder sourceAsSpannableBuilder = (SpannableStringBuilder) source;
                for (int i = end - 1; i >= start; i--) {
                    char currentChar = source.charAt(i);
                    if (!Character.isLetterOrDigit(currentChar) && !Character.isSpaceChar(currentChar)) {
                        sourceAsSpannableBuilder.delete(i, i + 1);
                    }
                }
                return source;
            } else {
                StringBuilder filteredStringBuilder = new StringBuilder();
                for (int i = 0; i < end; i++) {
                    char currentChar = source.charAt(i);
                    if (Character.isLetterOrDigit(currentChar) || Character.isSpaceChar(currentChar)) {
                        filteredStringBuilder.append(currentChar);
                    }
                }
                return filteredStringBuilder.toString();
            }
        }
    };
    editTxMediaSearch.setFilters(new InputFilter[] { filter });

    editTxMediaSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                new AskForMediaAsyncTaks().execute(editTxMediaSearch.getText().toString());
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(editTxMediaSearch.getWindowToken(), 0);
                return true;
            }
            return false;
        }

    });

}

From source file:org.sufficientlysecure.keychain.ui.ImportKeysServerFragment.java

/**
 * Inflate the layout for this fragment//from w w  w  .j av  a 2s. co m
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.import_keys_server_fragment, container, false);

    mSearchButton = (BootstrapButton) view.findViewById(R.id.import_server_search);
    mQueryEditText = (EditText) view.findViewById(R.id.import_server_query);
    mServerSpinner = (Spinner) view.findViewById(R.id.import_server_spinner);

    // add keyservers to spinner
    mServerAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            Preferences.getPreferences(getActivity()).getKeyServers());
    mServerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mServerSpinner.setAdapter(mServerAdapter);
    if (mServerAdapter.getCount() > 0) {
        mServerSpinner.setSelection(0);
    } else {
        mSearchButton.setEnabled(false);
    }

    mSearchButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            String query = mQueryEditText.getText().toString();
            String keyServer = (String) mServerSpinner.getSelectedItem();
            search(query, keyServer);

            // close keyboard after pressing search
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mQueryEditText.getWindowToken(), 0);
        }
    });

    mQueryEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                String query = mQueryEditText.getText().toString();
                String keyServer = (String) mServerSpinner.getSelectedItem();
                search(query, keyServer);

                // Don't return true to let the keyboard close itself after pressing search
                return false;
            }
            return false;
        }
    });

    return view;
}

From source file:net.olejon.mdapp.NasjonaleRetningslinjerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Input manager
    mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Layout/*from w  ww  .j a  v a 2 s . c o  m*/
    setContentView(R.layout.activity_nasjonale_retningslinjer);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.nasjonale_retningslinjer_toolbar);
    toolbar.setTitle(getString(R.string.nasjonale_retningslinjer_title));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbarSearchLayout = (LinearLayout) findViewById(R.id.nasjonale_retningslinjer_toolbar_search_layout);
    mToolbarSearchEditText = (EditText) findViewById(R.id.nasjonale_retningslinjer_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.nasjonale_retningslinjer_toolbar_clear_search);

    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mToolbarSearchEditText.setText("");
        }
    });

    // Progress bar
    mProgressBar = (ProgressBar) findViewById(R.id.nasjonale_retningslinjer_toolbar_progressbar);

    // Floating action button
    mFloatingActionButton = (FloatingActionButton) findViewById(R.id.nasjonale_retningslinjer_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);
            }
        }
    });

    // List
    mListView = (ListView) findViewById(R.id.nasjonale_retningslinjer_list);

    View listViewEmpty = findViewById(R.id.nasjonale_retningslinjer_list_empty);
    mListView.setEmptyView(listViewEmpty);

    View listViewHeader = getLayoutInflater().inflate(R.layout.activity_nasjonale_retningslinjer_list_subheader,
            mListView, false);
    mListView.addHeaderView(listViewHeader, null, false);
}

From source file:net.eledge.android.europeana.gui.activity.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    NewBlogNotification.cancel(this);

    PreferenceManager.setDefaultValues(this, R.xml.settings, false);

    searchController.suggestionPageSize = getResources().getInteger(R.integer.home_suggestions_pagesize);
    isLandscape = getResources().getBoolean(R.bool.home_support_landscape);

    mSuggestionsAdaptor = new SuggestionAdapter(this, new ArrayList<Item>());
    mGridViewSuggestions.setAdapter(mSuggestionsAdaptor);
    mGridViewSuggestions.setOnItemClickListener(this);

    mEditTextQuery.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override/*from   w  w w .ja v a 2s  . c o  m*/
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((actionId == EditorInfo.IME_ACTION_SEARCH) || (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
                performSearch(v.getText().toString());
                return true;
            }
            return false;
        }
    });
    mEditTextQuery.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.length() > 2) {
                if (mGridViewSuggestions.isShown()) {
                    mSuggestionsAdaptor.clear();
                    mSuggestionsAdaptor.notifyDataSetChanged();
                }
                searchController.suggestions(HomeActivity.this, s.toString());
            } else {
                onTaskFinished(null);
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // ignore
        }

        @Override
        public void afterTextChanged(Editable s) {
            // ignore
        }
    });

    mProfilesAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item);
    mSpinnerProfiles.setAdapter(mProfilesAdapter);

    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    if (mBlogFragment == null) {
        mBlogFragment = new HomeBlogFragment();
    }
    fragmentTransaction.replace(R.id.activity_home_fragment_blog, mBlogFragment);
    fragmentTransaction.commit();
}

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 w  w.  ja v  a 2  s .  c  o 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:com.dm.wallpaper.board.fragments.WallpaperSearchFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_wallpaper_search, menu);
    MenuItem search = menu.findItem(R.id.menu_search);
    int color = ColorHelper.getAttributeColor(getActivity(), R.attr.toolbar_icon);
    search.setIcon(DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_search, color));

    mSearchView = (SearchView) MenuItemCompat.getActionView(search);
    mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_SEARCH);
    mSearchView.setQueryHint(getActivity().getResources().getString(R.string.menu_search));
    mSearchView.setMaxWidth(Integer.MAX_VALUE);

    MenuItemCompat.expandActionView(search);
    mSearchView.setIconifiedByDefault(false);
    mSearchView.clearFocus();//from www . ja va2s.c o m

    ViewHelper.setSearchViewTextColor(mSearchView, color);
    ViewHelper.setSearchViewBackgroundColor(mSearchView, Color.TRANSPARENT);
    ViewHelper.setSearchViewCloseIcon(mSearchView, R.drawable.ic_toolbar_close);
    ViewHelper.setSearchViewSearchIcon(mSearchView, null);

    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String string) {
            filterSearch(string);
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String string) {
            mSearchView.clearFocus();
            return true;
        }
    });
}

From source file:org.gots.ui.HutActivity.java

private void displaySearchBox() {
    final EditText filter = (EditText) findViewById(R.id.edittextSearchFilter);
    filter.setText(currentFilter);//from w w w  .ja v  a  2 s . com

    filter.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable arg0) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            findViewById(R.id.clearSearchFilter)
                    .setBackground(getResources().getDrawable(R.drawable.ic_search));
            clearFilter = false;
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }
    });

    filter.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                performSearch(filter);
                EditText filter = (EditText) findViewById(R.id.edittextSearchFilter);
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(filter.getWindowToken(), 0);
                return true;
            }
            return false;
        }
    });
    ImageButton search = (ImageButton) findViewById(R.id.clearSearchFilter);
    search.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            performSearch(filter);
            EditText filter = (EditText) findViewById(R.id.edittextSearchFilter);
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(filter.getWindowToken(), 0);

            // EditText filter = (EditText) findViewById(R.id.edittextSearchFilter);
            // InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            // imm.hideSoftInputFromWindow(filter.getWindowToken(), 0);
        }

    });

}