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:com.krayzk9s.imgurholo.ui.MessagingFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    ImgurHoloActivity activity = (ImgurHoloActivity) getActivity();
    if (activity.getApiCall().settings.getString("theme", MainActivity.HOLO_LIGHT)
            .equals(MainActivity.HOLO_LIGHT))
        inflater.inflate(R.menu.main, menu);
    else//from   w w w . j a v a  2 s.co m
        inflater.inflate(R.menu.main_dark, menu);
    menu.findItem(R.id.action_refresh).setVisible(true);
    menu.findItem(R.id.action_upload).setVisible(false);
    if (messageData != null) {
        menu.findItem(R.id.action_report).setVisible(true);
        menu.findItem(R.id.action_reply).setVisible(true);
        menu.findItem(R.id.action_delete).setVisible(true);
    } else {
        menu.findItem(R.id.action_message).setVisible(true);
    }
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossDeviceFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    try {//  w  w  w  . j  a va2  s  .co m
        if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)
                && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            inflater.inflate(R.menu.view_device, menu);
        }
    } catch (Exception e) {
        e.printStackTrace();
        BugSenseHandler.sendExceptionMessage("ViewZenossDeviceFragment", "onCreateOptionsMenu", e);
    }
}

From source file:com.notalenthack.blaster.CommandActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.add_command, menu);

    // Calling super after populating the menu is necessary here to ensure that the
    // action bar helpers have a chance to handle this event.
    return super.onCreateOptionsMenu(menu);
}

From source file:cc.echonet.coolmicapp.MainActivity.java

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

From source file:course1778.mobileapp.safeMedicare.Main.FamMemFrag.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_fam_mem, menu);

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.orbar.pxdemo.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    //inflate menu and attach the search listener

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);

    searchItem = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) searchItem.getActionView();
    mSearchView.setQueryHint(getResources().getText(R.string.search_hint));

    mSearchView.setOnQueryTextListener(new searchQueryListener());

    return super.onCreateOptionsMenu(menu);
}

From source file:ca.ualberta.cmput301w14t08.geochan.fragments.ThreadViewFragment.java

/**
 * Sets up the menu for the fragment.//from   w  w  w.  j a va  2s.  c o m
 * @param menu The Menu item for the fragment itself.
 * @param inflater The inflater for inflating the fragment's menu.
 */
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Inflate the menu; this adds items to the action bar if it is present.
    inflater.inflate(R.menu.thread_view, menu);
    MenuItem item = menu.findItem(R.id.action_settings);
    item.setVisible(true);
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:android_network.hetnet.vpn_service.ActivityLog.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.logging, menu);

    menuSearch = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(menuSearch);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from  w  w w .  j  av  a 2 s .  c  o m
        public boolean onQueryTextSubmit(String query) {
            if (adapter != null)
                adapter.getFilter().filter(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (adapter != null)
                adapter.getFilter().filter(newText);
            return true;
        }
    });
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            if (adapter != null)
                adapter.getFilter().filter(null);
            return true;
        }
    });

    return true;
}

From source file:blackman.matt.infinitebrowser.NavigationDrawerFragment.java

/**
 * Called when the options menu is created in the drawer.
 *
 * @param menu The menu being added in./*from  w w  w  .j  a  va  2 s  .c  o m*/
 * @param inflater The context of the utility that will inflate the view.
 */
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // If the drawer is open, show the global app actions in the action bar. See also
    // showGlobalContextActionBar, which controls the top-left area of the action bar.
    if (mDrawerLayout != null && isDrawerOpen()) {
        inflater.inflate(R.menu.board_browser, menu);
        showGlobalContextActionBar();
    }
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.example.alvarpao.popularmovies.MovieGridFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.main_fragment, menu);

    // Get the array of values for the sort options since the onItemSelected method only
    // returns the string representation of the item, not the value associated
    Resources resources = getResources();
    final TypedArray sortArrayValues = resources.obtainTypedArray(R.array.sort_options_values);

    MenuItem sortMenuItem = menu.findItem(R.id.sort_spinner);
    mSortSpinner = (Spinner) MenuItemCompat.getActionView(sortMenuItem);
    mSortSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override/*from  ww w .  jav  a  2 s  . co  m*/
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            if (Utility.getPreferredSortOptionPosition(getActivity()) != position) {
                // Update the shared preferences with the new sort option election
                SharedPreferences sharedPreferences = PreferenceManager
                        .getDefaultSharedPreferences(getActivity());
                SharedPreferences.Editor editor = sharedPreferences.edit();
                //Save the sort_by value to query the movie database
                editor.putString(getString(R.string.sort_preference_key), sortArrayValues.getString(position));
                // Save the current position of the selected sort option
                editor.putInt(getString(R.string.sort_position_preference_key), position);
                editor.commit();

                // Update movie grid to reflect new sort option selected by user
                resetMovieGrid();
                getMovies(PAGE_1);
            }

            else {
                // If the sort option didn't change, the event most likely was triggered by
                // either a rotation or the activity being created. In case of the rotation
                // the state has already been restored in the onCreate() method, after onCreate()
                // the onCreateOptionsMenu() is called. If the activity has been created, the
                // favorite movies need to be fetched
                if (Utility.getPreferredSortOption(getActivity())
                        .equals(getString(R.string.sort_favorites_value))) {
                    if (!mMovies.isEmpty() && ((MainActivity) getActivity()).inTwoPaneLayout())
                        updateDetailsFragment();
                    else if (mMovies.isEmpty())
                        getMovies(Integer.valueOf(mPageToFetch).toString());
                }

                else {
                    // For the other sort options since pagination is involved the default
                    // movie to display in the details fragment when the user hasn't selected
                    // any movie is either the first one in the returned list when it is
                    // first loaded or the first visible movie before rotation. The first one
                    // when is first loaded is instantiated in the onScroll method
                    if (((MainActivity) getActivity()).inTwoPaneLayout()) {
                        if ((mSelectedMovie != -1) && (mMovieAdapter.getCount() != 0)) {
                            Movie selectedMovie = mMovieAdapter.getItem(mSelectedMovie);
                            ((Callback) getActivity()).onItemSelected(selectedMovie);
                        }
                    }
                    // Determine if another page needs to be retrieved by making an API call
                    getMovies(Integer.valueOf(mPageToFetch).toString());
                }

                // Restoring the scroll position
                mMoviesGridView.smoothScrollToPosition(mCurrentScrollPosition);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            //Do nothing
        }
    });

    // This statement is needed to restore the state of the sort selection in case a screen
    // rotation has occurred. The spinner is restored to the position it was retrieved
    // from the SharedPreferences;
    mSortSpinner.setSelection(Utility.getPreferredSortOptionPosition(getActivity()));
}