Example usage for android.widget SearchView setIconifiedByDefault

List of usage examples for android.widget SearchView setIconifiedByDefault

Introduction

In this page you can find the example usage for android.widget SearchView setIconifiedByDefault.

Prototype

public void setIconifiedByDefault(boolean iconified) 

Source Link

Document

Sets the default or resting state of the search field.

Usage

From source file:itcr.gitsnes.MainActivity.java

/**
 *  Methods inflate menu options panel/*ww w.ja  va 2 s.c  om*/
 *  Params:
 *      - [menu]
 *  Returns:
 *      - State of building [true]
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    /* Inflate the menu; this adds items to the action bar if it is present. */
    getMenuInflater().inflate(R.menu.main, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    if (null != searchView) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
    }

    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        public boolean onQueryTextChange(String newText) {
            // this is your adapter that will be filtered
            // Log.i("log_tag",newText);

            return true;
        }

        public boolean onQueryTextSubmit(String query) {
            Log.i("log_tag", query);

            MasterGames new_fragment = new MasterGames(json_arr);
            new_fragment.setQname(query);

            RelativeLayout rl = (RelativeLayout) findViewById(R.id.mainback);
            rl.setBackgroundColor(Color.parseColor("#009f28"));
            authButton.setVisibility(View.INVISIBLE);

            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.placeholder, new_fragment);
            transaction.addToBackStack(null);
            transaction.commit();

            return true;

        }
    };

    searchView.setOnQueryTextListener(queryTextListener);

    return super.onCreateOptionsMenu(menu);
}

From source file:de.tap.easy_xkcd.Activities.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    searchMenuItem = menu.findItem(R.id.action_search);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*from  w  w w .j a  va2  s . c  om*/
        public boolean onQueryTextSubmit(String query) {
            MenuItem searchMenuItem = getSearchMenuItem();
            searchMenuItem.collapseActionView();
            searchView.setQuery("", false);
            //Hide Keyboard
            View view = MainActivity.this.getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(view, 0);
            }
            searchView.requestFocus();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            return true;
        }
    });
    if (prefHelper.hideDonate())
        menu.findItem(R.id.action_donate).setVisible(false);
    return true;
}

From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.display_map, menu);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
        searchView.setQueryHint("part of repeater callsign");

        SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() {

            @Override//from   w w  w.  j ava 2  s  .  co m
            public boolean onQueryTextSubmit(String searchText) {

                adapter.getFilter().filter(searchText);
                Log.d("MYRepeater", "search: " + searchText);
                adapter.notifyDataSetChanged();
                return true;
            }

            @Override
            public boolean onQueryTextChange(String searchText) {
                // TODO Auto-generated method stub
                adapter.getFilter().filter(searchText);
                adapter.notifyDataSetChanged();
                return true;
            }
        };

        searchView.setOnQueryTextListener(textChangeListener);
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:at.ac.tuwien.detlef.activities.MainActivity.java

/**
 * Get the {@link SearchView} and set the {@link SearchableInfo}
 * configuration for the {@link EpisodeListFragment#getFilter() episode
 * keyword filter}./*from   w w  w.j  a  va  2  s.  c  om*/
 */
private void setSearchManager() {
    String tmptag = "searchmanager";
    Log.d(tmptag, "setSearchManager()");

    if (menu.findItem(R.id.menu_search) == null) {
        Log.d(tmptag, "is null");
        return;
    }

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

    SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);
    searchView.setOnQueryTextListener(new EpisodeSearchQueryTextListener(getEpisodeListFragment()));
}

From source file:com.cypress.cysmart.CommonFragments.ProfileScanningFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();// ww w.j  a  v  a2 s. c o m
    inflater.inflate(R.menu.global, menu);
    MenuItem item = menu.findItem(R.id.graph);
    MenuItem log = menu.findItem(R.id.log);
    final MenuItem searchMenuItem = menu.findItem(R.id.search);
    item.setVisible(false);
    log.setVisible(true);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setIconifiedByDefault(false);
    SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            // this is your adapter that will be filtered

            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            if (searchMenuItem != null) {
                searchMenuItem.collapseActionView();
                // this is your adapter that will be filtered
                if (mLeDeviceListAdapter != null) {
                    searchEnabled = true;
                    searchDeviceList(query);
                }
            }
            return false;

        }
    };
    searchView.setOnQueryTextListener(textChangeListener);
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean queryTextFocused) {
            if (!queryTextFocused) {
                searchMenuItem.collapseActionView();
                searchView.setQuery("", false);
            }
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

@Override
public boolean onCreateOptionsMenu(@NotNull final Menu menu) {
    MenuInflater inflater = getMenuInflater();
    if (m_app.isDarkActionbar()) {
        inflater.inflate(R.menu.main, menu);
    } else {/*w  w w.  j  ava  2  s . co  m*/
        inflater.inflate(R.menu.main_light, menu);
    }

    if (!m_app.fileStoreCanSync()) {
        MenuItem mItem = menu.findItem(R.id.sync);
        mItem.setVisible(false);
    }
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    searchView.setIconifiedByDefault(false);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        public boolean m_ignoreSearchChangeCallback;

        @Override
        public boolean onQueryTextSubmit(String query) {
            // Stupid searchview code will call onQueryTextChange callback
            // When the actionView collapse and the textview is reset
            // ugly global hack around this
            m_ignoreSearchChangeCallback = true;
            menu.findItem(R.id.search).collapseActionView();
            m_ignoreSearchChangeCallback = false;
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!m_ignoreSearchChangeCallback) {
                if (mFilter == null) {
                    mFilter = new ActiveFilter();
                }
                mFilter.setSearch(newText);
                mFilter.saveInPrefs(TodoApplication.getPrefs());
                if (m_adapter != null) {
                    m_adapter.setFilteredTasks();
                }
            }
            return true;
        }
    });
    this.options_menu = menu;
    return super.onCreateOptionsMenu(menu);
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    if (inflater != null && PrivacyService.checkClient()) {
        // Inflate menu
        inflater.inflate(R.menu.main, menu);

        // Searchable
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));
        if (searchView != null) {
            searchView.setIconifiedByDefault(false);

            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override/*from   w  w w .jav a2 s. com*/
                public boolean onQueryTextChange(String newText) {
                    searchQuery = newText;
                    applyFilter();
                    return true;
                }

                @Override
                public boolean onQueryTextSubmit(String query) {
                    searchQuery = query;
                    applyFilter();
                    return true;
                }
            });
            searchView.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    searchQuery = "";
                    applyFilter();
                    return true;
                }
            });
        }

        return true;
    } else
        return false;
}