Search in sources :

Example 11 with SearchView

use of android.widget.SearchView in project sbt-android by scala-android.

the class SearchActivity method setNoResultsVisibility.

private void setNoResultsVisibility(int visibility) {
    if (visibility == View.VISIBLE) {
        if (noResults == null) {
            noResults = (BaselineGridTextView) ((ViewStub) findViewById(R.id.stub_no_search_results)).inflate();
            noResults.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    searchView.setQuery("", false);
                    searchView.requestFocus();
                    ImeUtils.showIme(searchView);
                }
            });
        }
        String message = String.format(getString(R.string.no_search_results), searchView.getQuery().toString());
        SpannableStringBuilder ssb = new SpannableStringBuilder(message);
        ssb.setSpan(new StyleSpan(Typeface.ITALIC), message.indexOf('“') + 1, message.length() - 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        noResults.setText(ssb);
    }
    if (noResults != null) {
        noResults.setVisibility(visibility);
    }
}
Also used : ViewStub(android.view.ViewStub) StyleSpan(android.text.style.StyleSpan) View(android.view.View) SearchView(android.widget.SearchView) BaselineGridTextView(io.plaidapp.ui.widget.BaselineGridTextView) RecyclerView(android.support.v7.widget.RecyclerView) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 12 with SearchView

use of android.widget.SearchView in project MGit by maks.

the class RepoListActivity method configSearchAction.

public void configSearchAction(MenuItem searchItem) {
    SearchView searchView = (SearchView) searchItem.getActionView();
    if (searchView == null)
        return;
    SearchListener searchListener = new SearchListener();
    MenuItemCompat.setOnActionExpandListener(searchItem, searchListener);
    searchView.setIconifiedByDefault(true);
    searchView.setOnQueryTextListener(searchListener);
}
Also used : SearchView(android.widget.SearchView)

Example 13 with SearchView

use of android.widget.SearchView in project MGit by maks.

the class ViewFileActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.view_file, menu);
    if (mActivityMode == TAG_MODE_SSH_KEY) {
        menu.removeItem(R.id.action_edit);
        menu.removeItem(R.id.action_edit_in_other_app);
        menu.removeItem(R.id.action_choose_language);
    } else {
        menu.removeItem(R.id.action_copy_all);
    }
    if (mActivityMode != TAG_MODE_SSH_KEY) {
        MenuItem mi = menu.findItem(R.id.action_edit);
        setSaveStatus(mi);
        mi.setVisible(mCurrentTab == FILE_FRAGMENT_INDEX);
        mi = menu.findItem(R.id.action_edit_in_other_app);
        mi.setVisible(mCurrentTab == FILE_FRAGMENT_INDEX);
        mi = menu.findItem(R.id.action_choose_language);
        mi.setVisible(mCurrentTab == FILE_FRAGMENT_INDEX);
    }
    if (mRepo != null) {
        MenuItem searchItem = menu.findItem(R.id.action_search);
        MenuItemCompat.setOnActionExpandListener(searchItem, mTabItemPagerAdapter);
        SearchView searchView = (SearchView) searchItem.getActionView();
        if (searchView != null) {
            searchView.setIconifiedByDefault(true);
            searchView.setOnQueryTextListener(mTabItemPagerAdapter);
        }
        searchItem.setVisible(mCurrentTab == COMMITS_FRAGMENT_INDEX);
    } else {
        menu.removeItem(R.id.action_search);
    }
    return true;
}
Also used : SearchView(android.widget.SearchView) MenuItem(android.view.MenuItem)

Example 14 with SearchView

use of android.widget.SearchView in project OpenBikeSharing by bparmentier.

the class BikeNetworksListActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.bike_networks_list, menu);
    SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            return false;
        }

        @Override
        public // TODO: avoid redundancy
        boolean onQueryTextChange(String s) {
            if (bikeNetworks == null) {
                return false;
            }
            searchedBikeNetworks = new ArrayList<>();
            for (BikeNetworkInfo network : bikeNetworks) {
                if (network.getName().toLowerCase().contains(s.toLowerCase()) || network.getLocation().getCity().toLowerCase().contains(s.toLowerCase())) {
                    searchedBikeNetworks.add(network);
                }
            }
            bikeNetworksListAdapter = new BikeNetworksListAdapter(BikeNetworksListActivity.this, android.R.layout.simple_expandable_list_item_2, android.R.id.text1, searchedBikeNetworks);
            listView.setAdapter(bikeNetworksListAdapter);
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(BikeNetworksListActivity.this);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString(PREF_KEY_NETWORK_ID, searchedBikeNetworks.get(position).getId());
                    editor.putString(PREF_KEY_NETWORK_NAME, searchedBikeNetworks.get(position).getName());
                    editor.putString(PREF_KEY_NETWORK_CITY, searchedBikeNetworks.get(position).getLocation().getCity());
                    editor.putLong(PREF_KEY_NETWORK_LATITUDE, Double.doubleToRawLongBits(searchedBikeNetworks.get(position).getLocation().getLatitude()));
                    editor.putLong(PREF_KEY_NETWORK_LONGITUDE, Double.doubleToRawLongBits(searchedBikeNetworks.get(position).getLocation().getLongitude()));
                    editor.apply();
                    Toast.makeText(BikeNetworksListActivity.this, searchedBikeNetworks.get(position).getName() + " (" + searchedBikeNetworks.get(position).getLocation().getCity() + ") " + getString(R.string.network_selected), Toast.LENGTH_SHORT).show();
                    Intent resultIntent = new Intent();
                    resultIntent.putExtra(KEY_NETWORK_ID, searchedBikeNetworks.get(position).getId());
                    if (getParent() == null) {
                        setResult(Activity.RESULT_OK, resultIntent);
                    } else {
                        getParent().setResult(Activity.RESULT_OK, resultIntent);
                    }
                    finish();
                }
            });
            return true;
        }
    });
    return true;
}
Also used : SearchManager(android.app.SearchManager) SharedPreferences(android.content.SharedPreferences) BikeNetworkInfo(be.brunoparmentier.openbikesharing.app.models.BikeNetworkInfo) ArrayList(java.util.ArrayList) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(android.widget.SearchView) ListView(android.widget.ListView) SearchView(android.widget.SearchView) BikeNetworksListAdapter(be.brunoparmentier.openbikesharing.app.adapters.BikeNetworksListAdapter) AdapterView(android.widget.AdapterView)

Example 15 with SearchView

use of android.widget.SearchView in project android_packages_apps_Settings by DirtyUnicorns.

the class SearchFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.search_panel, container, false);
    mResultsRecyclerView = view.findViewById(R.id.list_results);
    mResultsRecyclerView.setAdapter(mSearchAdapter);
    mResultsRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mResultsRecyclerView.addOnScrollListener(mScrollListener);
    mNoResultsView = view.findViewById(R.id.no_results_layout);
    Toolbar toolbar = view.findViewById(R.id.search_toolbar);
    getActivity().setActionBar(toolbar);
    getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
    mSearchView = toolbar.findViewById(R.id.search_view);
    mSearchView.setQuery(mQuery, false);
    mSearchView.setOnQueryTextListener(this);
    mSearchView.requestFocus();
    // Updating internal views inside SearchView was the easiest way to get this too look right.
    // Instead of grabbing the TextView directly, we grab it as a view and do an instanceof
    // check. This ensures if we return, say, a LinearLayout in the tests, they won't fail.
    View searchText = mSearchView.findViewById(com.android.internal.R.id.search_src_text);
    if (searchText instanceof TextView) {
        TextView searchTextView = (TextView) searchText;
        searchTextView.setTextColor(getContext().getColorStateList(com.android.internal.R.color.text_color_primary));
        searchTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.search_bar_text_size));
    }
    View editFrame = mSearchView.findViewById(com.android.internal.R.id.search_edit_frame);
    if (editFrame != null) {
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) editFrame.getLayoutParams();
        params.setMarginStart(0);
        editFrame.setLayoutParams(params);
    }
    ActionBarShadowController.attachToRecyclerView(view.findViewById(R.id.search_bar_container), getLifecycle(), mResultsRecyclerView);
    return view;
}
Also used : ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) SearchView(android.widget.SearchView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Toolbar(android.widget.Toolbar)

Aggregations

SearchView (android.widget.SearchView)67 View (android.view.View)35 TextView (android.widget.TextView)30 MenuItem (android.view.MenuItem)26 ImageView (android.widget.ImageView)16 ListView (android.widget.ListView)15 AdapterView (android.widget.AdapterView)14 RecyclerView (android.support.v7.widget.RecyclerView)13 SearchManager (android.app.SearchManager)11 Activity (android.app.Activity)7 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 SettingsActivity (com.android.settings.SettingsActivity)7 ViewGroup (android.view.ViewGroup)6 Toolbar (android.widget.Toolbar)6 Intent (android.content.Intent)4 MenuInflater (android.view.MenuInflater)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 Nullable (android.support.annotation.Nullable)3 FragmentActivity (android.support.v4.app.FragmentActivity)3 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)3