Example usage for android.view MenuInflater inflate

List of usage examples for android.view MenuInflater inflate

Introduction

In this page you can find the example usage for android.view MenuInflater inflate.

Prototype

public void inflate(@MenuRes int menuRes, Menu menu) 

Source Link

Document

Inflate a menu hierarchy from the specified XML resource.

Usage

From source file:edu.cens.loci.ui.PlaceViewActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.view, menu);
    return true;/*from w w  w  . ja va 2  s  .  co m*/
}

From source file:mobisocial.musubi.ui.fragments.FeedViewFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (mFeedUri == null) {
        Throwable e = new Throwable("No uri when setting options menu");
        UsageMetrics.getUsageMetrics(mActivity).report(e);
        return;/*w w w  .ja v  a  2s .c om*/
    }

    long id = Long.parseLong(mFeedUri.getLastPathSegment());
    FeedManager fm = new FeedManager(App.getDatabaseSource(mActivity));
    MFeed f = fm.lookupFeed(id);
    assert (f != null);
    if (f.type_ == MFeed.FeedType.EXPANDING) {
        inflater.inflate(R.menu.feed_group, menu);
    } else {
        inflater.inflate(R.menu.feed_fixed, menu);
    }
}

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   www . java  2 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:com.tealeaf.TeaLeaf.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    if (getOptions().isDevelop()) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.debugmenu, menu);
        return true;
    } else {//from   w w w. j  a  v a2 s .c  o m
        return false;
    }

}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    if (mItem != null) {
        // Add menu options
        inflater.inflate(R.menu.menu_item_fragment, menu);

        // Assume we are a folder first
        menu.findItem(R.id.action_download).setVisible(false);
        menu.findItem(R.id.action_copy).setVisible(false);
        configureSetCopyDestinationMenuItem(menu.findItem(R.id.action_set_copy_destination));

        // Make sure that the root folder has certain options unavailable
        if ("root".equalsIgnoreCase(mItemId)) {
            menu.findItem(R.id.action_rename).setVisible(false);
            menu.findItem(R.id.action_delete).setVisible(false);
        }/*  ww w.j  av a  2s .  co m*/

        // Make sure that if it is a file, we don't let you perform actions that don't make sense for files
        if (mItem.file != null) {
            menu.findItem(R.id.action_create_folder).setVisible(false);
            menu.findItem(R.id.action_upload_file).setVisible(false);
            menu.findItem(R.id.action_download).setVisible(true);
            menu.findItem(R.id.action_copy).setVisible(true);
        }
    }
}

From source file:com.kircherelectronics.accelerationfilter.activity.AccelerationPlotActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.settings_plot_menu, menu);
    return true;//  ww  w  . j av a2 s.  c o m
}

From source file:net.sourceforge.kalimbaradio.androidapp.activity.DownloadActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.nowplaying, menu);
    return true;/*from w  w  w.ja v  a  2s  .  c  o m*/
}

From source file:com.balakrish.gpstracker.WaypointsListActivity.java

/**
 * onCreateOptionsMenu handler/*w ww  .j  av  a  2  s. c o m*/
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.waypoints_menu, menu);
    return true;
}

From source file:br.com.mybaby.contatos.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*  w ww  . j  ava2  s  . c  o m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contatos_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 (Util.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 (Util.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 (Util.hasICS()) {
                searchItem.expandActionView();
            }

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

From source file:com.github.chenxiaolong.dualbootpatcher.patcher.PatchFileFragment.java

/**
 * {@inheritDoc}//w w w .java2s .  co  m
 */
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.actionbar_check_cancel, menu);

    // NOTE: May crash on some versions of Android due to a bug where getActivity() returns null
    // after onAttach() has been called, but before onDetach() has been called. It's similar to
    // this bug report, except it happens with android.app.Fragment:
    // https://code.google.com/p/android/issues/detail?id=67519
    int primary = ContextCompat.getColor(getActivity(), R.color.text_color_primary);
    MenuUtils.tintAllMenuIcons(menu, primary);

    mCheckItem = menu.findItem(R.id.check_item);
    mCancelItem = menu.findItem(R.id.cancel_item);

    updateToolbarIcons();

    super.onCreateOptionsMenu(menu, inflater);
}