Example usage for android.view MenuItem setVisible

List of usage examples for android.view MenuItem setVisible

Introduction

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

Prototype

public MenuItem setVisible(boolean visible);

Source Link

Document

Sets the visibility of the menu item.

Usage

From source file:fr.paug.droidcon.ui.BaseActivity.java

protected void configureStandardMenuItems(Menu menu) {
    MenuItem wifiItem = menu.findItem(R.id.menu_wifi);
    if (wifiItem != null && !WiFiUtils.shouldOfferToSetupWifi(this, false)) {
        wifiItem.setVisible(false);
    }// ww  w . j av a 2s .  co  m

    MenuItem debugItem = menu.findItem(R.id.menu_debug);
    if (debugItem != null) {
        debugItem.setVisible(BuildConfig.DEBUG);
    }

    MenuItem ioExtendedItem = menu.findItem(R.id.menu_io_extended);
    if (ioExtendedItem != null) {
        ioExtendedItem.setVisible(PrefUtils.shouldOfferIOExtended(this, false));
    }

    // if attendee is remote, show map on the overflow instead of on the nav bar
    final boolean isRemote = !PrefUtils.isAttendeeAtVenue(this);
    final MenuItem mapItem = menu.findItem(R.id.menu_map);
    if (mapItem != null) {
        mapItem.setVisible(isRemote);
    }
}

From source file:in.shick.diode.user.ProfileActivity.java

/**
 * Hide or show specific menu items as necessary in a user's profile.
 */// w ww  .j av  a 2 s  . c o  m
private void hideShowMenuItems(Menu theMenu) {
    // Only show the 'View saved posts' menu item when the user is logged in AND we're currently viewing their
    // profile.
    MenuItem savedMenuItem = theMenu.findItem(R.id.saved_menu_id);
    if (savedMenuItem != null) {
        if (mSettings.isLoggedIn() && mSettings.getUsername().equalsIgnoreCase(mUsername)) {
            savedMenuItem.setVisible(true);
        } else {
            savedMenuItem.setVisible(false);
        }
    }
}

From source file:com.androzic.MapFragment.java

@Override
public void onPrepareOptionsMenu(final Menu menu) {
    boolean fixed = map != null && map.isFixed();

    MenuItem follow = menu.findItem(R.id.action_follow);
    if (!fixed || following && map != null && !map.getStrictUnfollow()) {
        follow.setVisible(false);
    } else if (following) {
        follow.setIcon(R.drawable.ic_lock_outline_white_24dp);
        follow.setTitle(R.string.action_unfollow);
    } else {//  w  ww. java 2s. co  m
        follow.setVisible(true);
        follow.setIcon(R.drawable.ic_lock_open_white_24dp);
        follow.setTitle(R.string.action_follow);
    }

    menu.findItem(R.id.action_locate).setVisible(!fixed);

    menu.findItem(R.id.action_locating).setChecked(application.isLocating());
    menu.findItem(R.id.action_tracking).setChecked(application.isTracking());

    boolean navigating = application.isNavigating();
    boolean viaRoute = application.isNavigatingViaRoute();

    menu.findItem(R.id.action_stop_navigation).setVisible(navigating);
    menu.findItem(R.id.action_next_nav_point).setVisible(viaRoute);
    menu.findItem(R.id.action_prev_nav_point).setVisible(viaRoute);
    if (viaRoute) {
        menu.findItem(R.id.action_next_nav_point)
                .setEnabled(application.navigationService.hasNextRouteWaypoint());
        menu.findItem(R.id.action_prev_nav_point)
                .setEnabled(application.navigationService.hasPrevRouteWaypoint());
    }
}

From source file:edu.umbc.cs.ebiquity.mithril.parserapp.contentparsers.contacts.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override//from   w  w  w  .j  a  va  2  s . 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 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;
                if (ParserApplication.getQueryOrLoader() == ParserApplication.getContactButtonLoader()) {
                    /**
                     * If the query text changes for the contact search then the loader is restarted
                     */
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    //                       Toast.makeText(getActivity(), ParserApplication.getQueryOrLoader()
                    //                             +"and"+ParserApplication.getButtonLoader(), Toast.LENGTH_LONG).show();
                } else if (ParserApplication.getQueryOrLoader()
                        .equals(ParserApplication.getContactButtonQuery())) {
                    //                       Toast.makeText(getActivity(), ParserApplication.getQueryOrLoader(), Toast.LENGTH_LONG).show();
                    getData();
                }
                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;
                    if (ParserApplication.getQueryOrLoader() == ParserApplication.getContactButtonLoader()) {
                        /**
                         * If the query text changes for the contact search then the loader is restarted
                         */
                        getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null,
                                ContactsListFragment.this);
                        //                           Toast.makeText(getActivity(), ParserApplication.getQueryOrLoader()
                        //                                 +"and"+ParserApplication.getButtonLoader(), Toast.LENGTH_LONG).show();
                    } else if (ParserApplication.getQueryOrLoader()
                            .equals(ParserApplication.getContactButtonQuery())) {
                        //                           Toast.makeText(getActivity(), ParserApplication.getQueryOrLoader(), Toast.LENGTH_LONG).show();
                        getData();
                    }
                    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:give_me_coins.dashboard.MainScreen.java

private void showIfEnabled(int key, int itemId) {
    boolean isEnabled = sharedPref.getBoolean(getString(key), true);
    MenuItem item = oMenu.findItem(itemId);
    item.setVisible(isEnabled);
}

From source file:com.android.gallery3d.filtershow.FilterShowActivity.java

private void setupMenu() {
    if (mMenu == null || mMasterImage == null) {
        return;//w  ww.j  a v  a  2 s. c o  m
    }
    MenuItem undoItem = mMenu.findItem(R.id.undoButton);
    MenuItem redoItem = mMenu.findItem(R.id.redoButton);
    MenuItem resetItem = mMenu.findItem(R.id.resetHistoryButton);
    MenuItem printItem = mMenu.findItem(R.id.printButton);
    if (!PrintHelper.systemSupportsPrint()) {
        printItem.setVisible(false);
    }
    mMasterImage.getHistory().setMenuItems(undoItem, redoItem, resetItem);
}

From source file:com.tavant.droid.womensecurity.fragments.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*from   www  .  j  av  a  2s  .  c  o  m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contacts_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
            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.adamas.client.android.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    _menuItemStartStop = menu.findItem(R.id.action_start_stop_vpn);
    MenuItem scan = menu.findItem(R.id.action_scan_qr_code);
    MenuItem delete = menu.findItem(R.id.action_delete_connector);
    MenuItem edit = menu.findItem(R.id.action_edit_connector);
    MenuItem importConnectorFile = menu.findItem(R.id.action_import_connector_from_image);
    MenuItem importConnectorText = menu.findItem(R.id.action_import_connector_from_text);
    MenuItem add = menu.findItem(R.id.action_add_connector_manually);
    MenuItem settings = menu.findItem(R.id.action_settings);

    if (_menuItemStartStop != null) {
        if (_currentActiveFragment == FRAGMENT_CONNECTORS) {
            _menuItemStartStop.setVisible(true);
            scan.setVisible(true);
            importConnectorFile.setVisible(true);
            importConnectorText.setVisible(true);
            add.setVisible(true);//  w  w  w. j  a  v a2 s  .c  o  m
            settings.setVisible(true);
            if (_selectedAdamasConnector != null) {
                delete.setVisible(true);
                edit.setVisible(true);
            } else {
                delete.setVisible(false);
                edit.setVisible(false);
            }
        } else if (_currentActiveFragment == FRAGMENT_STATISTICS) {
            _menuItemStartStop.setVisible(false);
            scan.setVisible(false);
            importConnectorFile.setVisible(false);
            importConnectorText.setVisible(false);
            add.setVisible(false);
            settings.setVisible(true);
            delete.setVisible(false);
            edit.setVisible(false);
        }
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.android.contacts.activities.DialtactsActivity.java

private void prepareOptionsMenuForDialerTab(Menu menu) {
    if (DEBUG) {// w  w w  .j a v  a 2  s .  c o m
        Log.d(TAG,
                "onPrepareOptionsMenu(dialer). swipe: " + mDuringSwipe + ", user tab click: " + mUserTabClick);
    }

    // get references to menu items
    final MenuItem searchMenuItem = menu.findItem(R.id.search_on_action_bar);
    final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option);
    final MenuItem addContactOptionMenuItem = menu.findItem(R.id.add_contact);
    final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings);
    final MenuItem emptyRightMenuItem = menu.findItem(R.id.empty_right_menu_item);

    // prepare the menu items
    filterOptionMenuItem.setVisible(false);
    addContactOptionMenuItem.setVisible(false);
    if (mDuringSwipe || mUserTabClick) {
        // During horizontal movement, the real ActionBar menu items are shown
        searchMenuItem.setVisible(true);
        callSettingsMenuItem.setVisible(true);
        // When there is a permanent menu key, there is no overflow icon on the right of
        // the action bar which would force the search menu item (if it is visible) to the
        // left.  This is the purpose of showing the emptyRightMenuItem.
        emptyRightMenuItem.setVisible(ViewConfiguration.get(this).hasPermanentMenuKey());
    } else {
        // This is when the user is looking at the dialer pad.  In this case, the real
        // ActionBar is hidden and fake menu items are shown.
        // Except in landscape, in which case the real search menu item is shown.
        searchMenuItem.setVisible(ContactsUtils.isLandscape(this));
        // If a permanent menu key is available, then we need to show the call settings item
        // so that the call settings item can be invoked by the permanent menu key.
        callSettingsMenuItem.setVisible(ViewConfiguration.get(this).hasPermanentMenuKey());
        emptyRightMenuItem.setVisible(false);
    }
}

From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java

private void setCommonMenu(final Menu menu) {
    final boolean hasMedia = hasMedia();
    final int activatedColor = getUserThemeColor(this);
    final MenuItem itemAddImageSubmenu = menu.findItem(R.id.add_image_submenu);
    if (itemAddImageSubmenu != null) {
        final Drawable iconAddImage = itemAddImageSubmenu.getIcon();
        iconAddImage.mutate();/*from  w ww .  j av a  2 s .  co  m*/
        if (hasMedia) {
            iconAddImage.setColorFilter(activatedColor, Mode.SRC_ATOP);
        } else {
            iconAddImage.clearColorFilter();
        }
    }
    final MenuItem itemAttachLocation = menu.findItem(MENU_ADD_LOCATION);
    if (itemAttachLocation != null) {
        final Drawable iconAttachLocation = itemAttachLocation.getIcon().mutate();
        final boolean attachLocation = mPreferences.getBoolean(KEY_ATTACH_LOCATION, false);
        if (attachLocation && getLocation()) {
            iconAttachLocation.setColorFilter(activatedColor, Mode.SRC_ATOP);
            itemAttachLocation.setTitle(R.string.remove_location);
            itemAttachLocation.setChecked(true);
        } else {
            setProgressVisibility(false);
            mPreferences.edit().putBoolean(KEY_ATTACH_LOCATION, false).commit();
            iconAttachLocation.clearColorFilter();
            itemAttachLocation.setTitle(R.string.add_location);
            itemAttachLocation.setChecked(false);
        }
    }
    final MenuItem viewItem = menu.findItem(MENU_VIEW);
    if (viewItem != null) {
        viewItem.setVisible(mInReplyToStatus != null);
    }
    final MenuItem itemToggleSensitive = menu.findItem(MENU_TOGGLE_SENSITIVE);
    if (itemToggleSensitive != null) {
        itemToggleSensitive.setVisible(hasMedia);
        itemToggleSensitive.setEnabled(hasMedia);
        itemToggleSensitive.setChecked(hasMedia && mIsPossiblySensitive);
        if (hasMedia) {
            final Drawable iconToggleSensitive = itemToggleSensitive.getIcon().mutate();
            if (mIsPossiblySensitive) {
                itemToggleSensitive.setTitle(R.string.remove_sensitive_mark);
                iconToggleSensitive.setColorFilter(activatedColor, Mode.SRC_ATOP);
            } else {
                itemToggleSensitive.setTitle(R.string.mark_as_sensitive);
                iconToggleSensitive.clearColorFilter();
            }
        }
    }
}