Example usage for android.view MenuItem collapseActionView

List of usage examples for android.view MenuItem collapseActionView

Introduction

In this page you can find the example usage for android.view MenuItem collapseActionView.

Prototype

public boolean collapseActionView();

Source Link

Document

Collapse the action view associated with this menu item.

Usage

From source file:com.balch.android.app.framework.TemplateActivity.java

public void hideProgress() {
    if (this.optionsMenu != null) {
        MenuItem menuItem = this.optionsMenu.findItem(R.id.action_bar_menu_refresh);
        menuItem.collapseActionView();
        menuItem.setActionView(null);//from  www  .j  a  va  2s  . c  o m
    }
}

From source file:com.kccomy.orgar.ui.files.FileListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    MenuItem search = menu.findItem(R.id.action_search_file);
    search.collapseActionView();

    searchView = (SearchView) search.getActionView();
    // Don't cover App Label
    searchView.setMaxWidth(600);//from w ww . j a va  2s .com
    searchView.setIconified(true);
    searchView.setIconifiedByDefault(true);
    // set input text color
    SearchView.SearchAutoComplete textView = (SearchView.SearchAutoComplete) searchView
            .findViewById(R.id.search_src_text);
    textView.setTextColor(getResources().getColor(R.color.colorPrimaryDark));

    searchView.setOnSearchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showRecentSearchView();
            fab.hide();
        }
    });

    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            showFileListView();
            fab.show();
            return false;
        }
    });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            recentAdapter.addItem(query);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!TextUtils.isEmpty(newText)) {
                showSearchResultView();
                presenter.processQuery(fileAdapter.getFiles(), newText);
            } else {
                showRecentSearchView();
            }
            return false;
        }
    });

    super.onPrepareOptionsMenu(menu);
}

From source file:at.wada811.android.library.demos.loader.LoaderListActivity.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void initSearchView(final MenuItem menuItem) {
    if (AndroidUtils.isMoreThanBuildVersion(Build.VERSION_CODES.ICE_CREAM_SANDWICH)) {
        final SearchView searchView = (SearchView) menuItem.getActionView();
        searchView.setOnQueryTextListener(new OnQueryTextListener() {
            @Override/*w w  w. j a  va2 s.c  o  m*/
            public boolean onQueryTextSubmit(String query) {
                mLoaderListFragment.init();
                mLoaderListFragment.searchImageWithKeyword(query);
                menuItem.collapseActionView();
                getActionBar().setTitle(query);
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
        searchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (!hasFocus) {
                    menuItem.collapseActionView();
                }
            }
        });
    }
}

From source file:app.cloud9.com.cloud9.NoticeBoard.java

@Override
public boolean onSearchRequested() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        MenuItem mi = mMenu.findItem(R.id.search_notice);
        if (mi.isActionViewExpanded()) {
            mi.collapseActionView();
        } else {//from   w ww. ja v a  2  s .c  om
            mi.expandActionView();
        }
    } else {
        //onOptionsItemSelected(mMenu.findItem(R.id.search));
    }
    return super.onSearchRequested();
}

From source file:fr.cph.chicago.activity.MainActivity.java

/**
 * Stop animation in menu//from  w  ww .  j a v  a 2s .  com
 */
public final void stopRefreshAnimation() {
    if (mMenu != null) {
        MenuItem refreshMenuItem = mMenu.findItem(R.id.action_refresh);
        refreshMenuItem.collapseActionView();
        refreshMenuItem.setActionView(null);
    }
}

From source file:com.xengar.android.booksearch.ui.BookListActivity.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.menu_book_list, menu);
    final MenuItem searchItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*  ww w  . jav  a2  s . c  o m*/
        public boolean onQueryTextSubmit(String query) {
            // Fetch the data remotely
            fetchBooks(query);
            // Reset SearchView
            searchView.clearFocus();
            searchView.setQuery("", false);
            searchView.setIconified(true);
            searchItem.collapseActionView();
            // Set activity title to search query
            BookListActivity.this.setTitle(query);
            return true;
        }

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

From source file:de.dreier.mytargets.features.training.standardround.StandardRoundListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.search, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);
    ImageView closeButton = (ImageView) searchView.findViewById(R.id.search_close_btn);
    // Set on click listener
    closeButton.setOnClickListener(v -> {
        EditText et = (EditText) searchView.findViewById(R.id.search_src_text);
        et.setText("");
        searchView.setQuery("", false);
        searchView.onActionViewCollapsed();
        searchItem.collapseActionView();
    });/*from w  w  w  .  jav  a  2s. co m*/
}

From source file:com.phicdy.mycuration.ui.TopActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final MenuItem searchMenuItem = menu.findItem(R.id.search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        @Override/*from  w w  w .  j  a v  a 2s.c  o m*/
        public void onFocusChange(View view, boolean queryTextFocused) {
            if (!queryTextFocused) {
                searchMenuItem.collapseActionView();
                searchView.setQuery("", false);
            }
        }
    });
    SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete) searchView
            .findViewById(android.support.v7.appcompat.R.id.search_src_text);
    searchAutoComplete.setTextColor(getResources().getColor(R.color.text_primary));
    searchAutoComplete.setHintTextColor(getResources().getColor(R.color.text_primary));
    return true;
}

From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java

@Override
public void onBackPressed() {
    if (actionModeEnabled) {
        actionMode.finish();// www  .j av a2 s.c  o  m
    } else if (menu != null) {
        MenuItem searchItem = menu.findItem(R.id.search_button);
        SearchView searchView = (SearchView) searchItem.getActionView();
        if (!searchView.isIconified()) {
            searchItem.collapseActionView();
        } else {
            super.onBackPressed();
        }
    }
}

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 .ja  va2s .  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;
}