Example usage for android.view MenuItem getActionView

List of usage examples for android.view MenuItem getActionView

Introduction

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

Prototype

public View getActionView();

Source Link

Document

Returns the currently set action view for this menu item.

Usage

From source file:org.wheelmap.android.activity.MainMultiPaneActivity.java

public boolean onOptionItemClicked(int id, View v, MenuItem item) {

    switch (id) {
    case R.id.menu_search:
        if (mWorkerFragment.isSearchMode()) {
            mWorkerFragment.setSearchMode(false);
            mWorkerFragment.requestUpdate(null);
        } else {//from w w w.  jav  a 2  s  .  c  om
            showSearch();
        }
        return true;
    case R.id.menu_filter_kategorie:
        showFilterCategories();
        return true;
    case R.id.menu_filter:
    case R.id.menu_wc:
        View anchor = v;
        if (anchor == null) {
            anchor = item.getActionView();
        }
        showFilterSettings(item, v, anchor);
        return true;
    case R.id.menu_about:
        showInfo();
        return true;
    case R.id.menu_new_poi:
        createNewPoi();
        return true;
    case android.R.id.home:
        finish();
        return true;
    case R.id.menu_login:
        showAccount();
        return true;
    case R.id.menu_news:
        showNews();
        return true;
    default:
        return false;
    }
}

From source file:co.tinode.tindroid.ContactsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.menu_contacts, menu);

    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // Retrieves the system search manager service
    final SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);

    // Retrieves the SearchView from the search menu item
    final SearchView searchView = (SearchView) searchItem.getActionView();
    // searchView.setFocusable(true);

    // Assign searchable info to SearchView
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

    // Set listeners for SearchView
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*from w  ww  .  j av a2 s .c  o  m*/
        public boolean onQueryTextSubmit(String queryText) {
            // Nothing needs to happen when the user submits the search string
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // Called when the action bar search text has changed.  Updates
            // the search filter, and restarts the loader to do a new query
            // using the new search string.
            String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

            // Don't do anything if the filter is empty
            if (mSearchTerm == null && newFilter == null) {
                return true;
            }

            // Don't do anything if the new filter is the same as the current filter
            if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                return true;
            }

            // Updates current filter to new filter
            mSearchTerm = newFilter;

            // Restarts the loader. This triggers onCreateLoader(), which builds the
            // necessary content Uri from mSearchTerm.
            getLoaderManager().restartLoader(ContactsQuery.CORE_QUERY_ID, null, mContactsLoaderCallback);
            return true;
        }
    });

    MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem menuItem) {
            Log.d(TAG, "EXPAND onMenuItemActionCollapse");
            searchView.setIconified(false);
            searchView.requestFocusFromTouch();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem menuItem) {
            Log.d(TAG, "COLLAPSE onMenuItemActionCollapse");
            searchView.clearFocus();
            // When the user collapses the SearchView the current search string is
            // cleared and the loader restarted.
            if (!TextUtils.isEmpty(mSearchTerm)) {
                onSelectionCleared();
            }
            mSearchTerm = null;
            getLoaderManager().restartLoader(ContactsQuery.CORE_QUERY_ID, null, mContactsLoaderCallback);
            return true;
        }
    });

    if (mSearchTerm != null) {
        // If search term is already set here then this fragment is
        // being restored from a saved state and the search menu item
        // needs to be expanded and populated again.

        // Stores the search term (as it will be wiped out by
        // onQueryTextChange() when the menu item is expanded).
        final String savedSearchTerm = mSearchTerm;

        // Expands the search menu item
        searchItem.expandActionView();

        // Sets the SearchView to the previous search string
        searchView.setQuery(savedSearchTerm, false);
    }
}

From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.activity, menu);

    // Actions are always visible when showing as dialog
    if (mShowAsDialog) {
        for (int i = 0; i < menu.size(); i++) {
            menu.getItem(i).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        }//from  w ww .  j a v a2 s.  co m
    }

    final MenuItem searchMenu = menu.findItem(R.id.menu_search);
    mSearchView = (SearchView) searchMenu.getActionView();
    mSearchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            mState.currentSearch = query;
            mSearchView.clearFocus();
            onCurrentDirectoryChanged(ANIM_NONE);
            return true;
        }

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

    searchMenu.setOnActionExpandListener(new OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            if (mIgnoreNextCollapse) {
                mIgnoreNextCollapse = false;
                return true;
            }

            mState.currentSearch = null;
            onCurrentDirectoryChanged(ANIM_NONE);
            return true;
        }
    });

    mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            if (mIgnoreNextClose) {
                mIgnoreNextClose = false;
                return false;
            }

            mState.currentSearch = null;
            onCurrentDirectoryChanged(ANIM_NONE);
            return false;
        }
    });

    return true;
}

From source file:com.jackleeentertainment.oq.ui.layout.fragment.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*from   ww w  .  j a  v  a2s . co  m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contact_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // In version 3.0 and later, sets up and configures the ActionBar SearchView
    if (Utils.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) searchItem.getActionView();

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Updates
                // the search filter, and restarts the loader to do a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;

                // Restarts the loader. This triggers onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (Utils.hasICS()) {
            // This listener added in ICS
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    // Nothing to do when the action item is expanded
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    // When the user collapses the SearchView the current search string is
                    // cleared and the loader restarted.
                    if (!TextUtils.isEmpty(mSearchTerm)) {
                        onSelectionCleared();
                    }
                    mSearchTerm = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Utils.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:com.hybris.mobile.app.commerce.activity.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.actionbar, menu);

    // HockeyApp feedback
    menu.findItem(R.id.menu_feedback).setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override//from   w ww . j  av a 2 s.  com
        public boolean onMenuItemClick(MenuItem item) {
            HockeyAppUtils.showFeedbackActivity(MainActivity.this);
            return true;
        }
    });

    // Sync Settings
    menu.findItem(R.id.menu_settings).setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(MainActivity.this, SettingsActivity.class));
            return true;
        }
    });

    // Barcode scanner
    menu.findItem(R.id.menu_scanner).setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            CommerceApplication.getScannerHelper().launch(MainActivity.this, MainActivity.this);
            return true;
        }
    });

    // Cart items
    MenuItem item = menu.findItem(R.id.b2b_icon_cart);

    if (mCartDrawer != null) {

        // Onclick to open/hide cart menu
        item.getActionView().setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mDrawerLayout != null) {
                    mDrawerLayout.closeDrawers();
                }
                if (mCartDrawer.isDrawerOpen(mCartDrawer.getChildAt(1))) {
                    mCartDrawer.closeDrawer(mCartDrawer.getChildAt(1));
                } else {
                    mCartDrawer.openDrawer(mCartDrawer.getChildAt(1));
                }
            }
        });
    } else {
        menu.removeItem(R.id.b2b_icon_cart);
    }

    // Search component
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.b2b_icon_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);

    return true;
}

From source file:com.shafiq.mytwittle.view.BaseLaneActivity.java

protected void configureActionBarSearchView(Menu menu) {

    MenuItem searchItem = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) searchItem.getActionView();

    searchItem.setShowAsActionFlags(/*from   w  w  w  .ja v  a  2  s.c om*/
            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    mSearchView.setOnQueryTextListener(this);

    OnFocusChangeListener onFocusChangeListener = new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {

            mCurrentComposeFragment.setIgnoreFocusChange(true);
            if (mComposeTweetView != null) {
                mComposeTweetView.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
            }
            if (mComposeDirectMessageView != null) {
                mComposeDirectMessageView.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
            }
            mCurrentComposeFragment.setIgnoreFocusChange(false);
        }

    };

    mSearchView.setOnQueryTextFocusChangeListener(onFocusChangeListener);
    mSearchView.setOnFocusChangeListener(onFocusChangeListener);
}

From source file:com.tweetlanes.android.core.view.BaseLaneActivity.java

void configureActionBarSearchView(Menu menu) {

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchItem.getActionView();

    searchItem.setShowAsActionFlags(//from   ww w.  java  2 s. c  o  m
            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    searchView.setOnQueryTextListener(this);

    OnFocusChangeListener onFocusChangeListener = new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {

            mCurrentComposeFragment.setIgnoreFocusChange(true);

            if (mComposeTweetView != null) {
                mComposeTweetView.setVisibility(View.GONE);
            }
            if (mComposeDirectMessageView != null) {
                mComposeDirectMessageView.setVisibility(View.GONE);
            }

            if (!hasFocus) {
                if (mCurrentComposeFragment == mComposeDirectMessageFragment) {
                    if (mComposeDirectMessageView != null) {
                        mComposeDirectMessageView.setVisibility(View.VISIBLE);
                    }
                } else {
                    if (mComposeTweetView != null) {
                        mComposeTweetView.setVisibility(View.VISIBLE);
                    }
                }
            }

            mCurrentComposeFragment.setIgnoreFocusChange(false);
        }

    };

    searchView.setOnQueryTextFocusChangeListener(onFocusChangeListener);
    searchView.setOnFocusChangeListener(onFocusChangeListener);
}

From source file:com.money.manager.ex.home.MainActivity.java

private void stopSyncIconRotation(MenuItem item) {
    if (item == null)
        return;/*from  w  w w  .j  av  a  2 s  . c  o m*/

    View actionView = item.getActionView();
    if (actionView == null)
        return;

    actionView.clearAnimation();
    item.setActionView(null);
}

From source file:dev.dworks.apps.anexplorer.DocumentsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.activity, menu);

    // Actions are always visible when showing as dialog
    /*        if (mShowAsDialog) {
    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    }//  w  ww  .j  av  a 2s.  c om
            }
    */
    final MenuItem searchMenu = menu.findItem(R.id.menu_search);
    mSearchView = (SearchView) searchMenu.getActionView();
    mSearchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            mState.currentSearch = query;
            mSearchView.clearFocus();
            onCurrentDirectoryChanged(ANIM_NONE);
            return true;
        }

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

    searchMenu.setOnActionExpandListener(new OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            if (mIgnoreNextCollapse) {
                mIgnoreNextCollapse = false;
                return true;
            }

            mState.currentSearch = null;
            onCurrentDirectoryChanged(ANIM_NONE);
            return true;
        }
    });

    mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            if (mIgnoreNextClose) {
                mIgnoreNextClose = false;
                return false;
            }

            mState.currentSearch = null;
            onCurrentDirectoryChanged(ANIM_NONE);
            return false;
        }
    });

    return true;
}

From source file:com.chris.ni.omw.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*  www .j a v a  2  s  .com*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    // Inflate the menu items
    inflater.inflate(R.menu.contact_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    // In versions prior to Android 3.0, hides the search item to prevent additional
    // searches. In Android 3.0 and later, searching is done via a SearchView in the ActionBar.
    // Since the search doesn't create a new Activity to do the searching, the menu item
    // doesn't need to be turned off.
    if (mIsSearchResultView) {
        searchItem.setVisible(false);
    }

    // In version 3.0 and later, sets up and configures the ActionBar SearchView
    if (Utils.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) searchItem.getActionView();

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Updates
                // the search filter, and restarts the loader to do a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;

                // Restarts the loader. This triggers onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (Utils.hasICS()) {
            // This listener added in ICS
            MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    // Nothing to do when the action item is expanded
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    // When the user collapses the SearchView the current search string is
                    // cleared and the loader restarted.
                    if (!TextUtils.isEmpty(mSearchTerm)) {
                        onSelectionCleared();
                    }
                    mSearchTerm = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Utils.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}