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:org.fedorahosted.freeotp.main.Activity.java

@Override
public void onSelectEvent(NavigableSet<Integer> selected) {
    if (mMenu == null)
        return;/*from w  w w.j a  va2s.c  om*/

    for (int i = 0; i < mMenu.size(); i++) {
        MenuItem mi = mMenu.getItem(i);

        switch (mi.getItemId()) {
        case R.id.action_about:
            mi.setVisible(selected.size() == 0);
            break;

        case R.id.action_up:
            mi.setVisible(selected.size() > 0);
            mi.setEnabled(!mTokenAdapter.isSelected(0));
            break;

        case R.id.action_down:
            mi.setVisible(selected.size() > 0);
            mi.setEnabled(!mTokenAdapter.isSelected(mTokenAdapter.getItemCount() - 1));
            break;

        case R.id.action_delete:
            mi.setVisible(selected.size() > 0);
            break;

        default:
            break;
        }
    }
}

From source file:com.elixsr.portforwarder.ui.MainActivity.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_main, menu);

    menu.findItem(R.id.action_toggle_forwarding)
            .setTitle(generateForwardingActionMenuText(forwardingManager.isEnabled()));

    //setup the start forwarding button
    MenuItem toggleForwarding = menu.findItem(R.id.action_toggle_forwarding);

    //it should not be able to start if there are no rules
    if (ruleModels.size() <= 0) {
        toggleForwarding.setVisible(false);
    } else {//from ww w. j  a v  a  2 s.c o m
        toggleForwarding.setVisible(true);
    }

    return true;
}

From source file:com.kaliturin.blacklist.fragments.SMSConversationsListFragment.java

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

    MenuItem menuItem = menu.findItem(R.id.write_message);
    Utils.setMenuIconTint(getContext(), menuItem, R.attr.colorAccent);
    menuItem.setVisible(true);
    menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override/*ww w  . ja  v a2  s . c  om*/
        public boolean onMenuItemClick(MenuItem item) {
            // open SMS sending activity
            CustomFragmentActivity.show(getContext(), getString(R.string.New_message), SMSSendFragment.class,
                    null);
            return true;
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.owncloud.android.files.FileMenuFilter.java

/**
 * Filters out the file actions available in the passed {@link Menu} taken into account
 * the state of the {@link OCFile} held by the filter.
 *
 * @param menu              Options or context menu to filter.
 *///from   w  ww.ja  v a  2s .c  o m
public void filter(Menu menu, boolean displaySelectAll, boolean displaySelectInverse) {
    if (mFiles == null || mFiles.size() <= 0) {
        hideAll(menu);

    } else {
        List<Integer> toShow = new ArrayList<>();
        List<Integer> toHide = new ArrayList<>();

        filter(toShow, toHide, displaySelectAll, displaySelectInverse);

        MenuItem item;
        for (int i : toShow) {
            item = menu.findItem(i);
            if (item != null) {
                item.setVisible(true);
                item.setEnabled(true);
            }
        }

        for (int i : toHide) {
            item = menu.findItem(i);
            if (item != null) {
                item.setVisible(false);
                item.setEnabled(false);
            }
        }
    }
}

From source file:com.jtechme.apphub.FDroid.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    if (fdroidApp.bluetoothAdapter == null) {
        // ignore on devices without Bluetooth
        MenuItem btItem = menu.findItem(R.id.action_bluetooth_apk);
        btItem.setVisible(false);
    }/*w  ww. ja v a2 s. co  m*/

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchMenuItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    // LayoutParams.MATCH_PARENT does not work, use a big value instead
    searchView.setMaxWidth(1000000);
    searchView.setOnQueryTextListener(this);

    // If we were asked to execute a search before getting around to building the options
    // menu, then we should deal with that now that the options menu is all sorted out.
    if (pendingSearchQuery != null) {
        performSearch(pendingSearchQuery);
        pendingSearchQuery = null;
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.owncloud.android.ui.adapter.UserListAdapter.java

/**
 * Updates the sharee's menu with the current permissions of the {@link OCShare}
 *
 * @param menu  the menu of the sharee/shared file
 * @param share the shared file/*  ww  w  .j  a  v  a 2s.  c  o  m*/
 */
private void prepareOptionsMenu(Menu menu, OCShare share) {

    MenuItem editCreateItem = menu.findItem(R.id.action_can_edit_create);
    MenuItem editChangeItem = menu.findItem(R.id.action_can_edit_change);
    MenuItem editDeleteItem = menu.findItem(R.id.action_can_edit_delete);

    MenuItem hideFileListingItem = menu.findItem(R.id.action_hide_file_listing);
    MenuItem passwordItem = menu.findItem(R.id.action_password);
    MenuItem expirationDateItem = menu.findItem(R.id.action_expiration_date);

    MenuItem reshareItem = menu.findItem(R.id.action_can_reshare);

    if (isReshareForbidden(share)) {
        reshareItem.setVisible(false);
    }
    reshareItem.setChecked(canReshare(share));

    if (share.getShareType() == ShareType.EMAIL) {
        SharingMenuHelper.setupHideFileListingMenuItem(hideFileListingItem, file.isFolder(), canEdit(share),
                share.getPermissions());
        SharingMenuHelper.setupPasswordMenuItem(passwordItem, share.isPasswordProtected());

        reshareItem.setVisible(false);
        editCreateItem.setVisible(false);
        editChangeItem.setVisible(false);
        editDeleteItem.setVisible(false);
    } else {
        if (file.isFolder() && isEditOptionsAvailable(share)) {
            /// TODO change areEditOptionsAvailable in order to delete !isFederated
            editCreateItem.setChecked(canCreate(share));
            editChangeItem.setChecked(canUpdate(share));
            editDeleteItem.setChecked(canDelete(share));
        } else {
            editCreateItem.setVisible(false);
            editChangeItem.setVisible(false);
            editDeleteItem.setVisible(false);
        }

        hideFileListingItem.setVisible(false);
        passwordItem.setVisible(false);
        expirationDateItem.setVisible(false);
    }

    SharingMenuHelper.setupExpirationDateMenuItem(menu.findItem(R.id.action_expiration_date),
            share.getExpirationDate(), context.getResources());
}

From source file:com.cypress.cysmart.DataLoggerFragments.DataLoggerFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();// ww w  . j  a  va  2 s  . c  o  m
    inflater.inflate(R.menu.global, menu);
    MenuItem share = menu.findItem(R.id.share);
    MenuItem sharelogger = menu.findItem(R.id.sharelogger);
    MenuItem log = menu.findItem(R.id.log);
    MenuItem search = menu.findItem(R.id.search);
    MenuItem graph = menu.findItem(R.id.graph);
    search.setVisible(false);
    share.setVisible(false);
    log.setVisible(false);
    graph.setVisible(false);
    sharelogger.setVisible(true);
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.openerp.addons.note.EditNoteFragment.java

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

    inflater.inflate(R.menu.menu_fragment_note_detail, menu);
    // disabling the MORE [:] menu
    MenuItem item_operation = menu.findItem(R.id.menu_note_operation);
    item_operation.setVisible(false);
}

From source file:com.example.android.pets.EditorActivity.java

/**
 * This method is called after invalidateOptionsMenu(), so that the
 * menu can be updated (some menu items can be hidden or made visible).
 *///from  w w w  .j a  v a2 s  .co  m
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    // If this is a new pet, hide the "Delete" menu item.
    if (mCurrentPetUri == null) {
        MenuItem menuItem = menu.findItem(R.id.action_delete);
        menuItem.setVisible(false);
    }
    return true;
}

From source file:com.android.messaging.ui.mediapicker.AudioListView.java

public void onCreateOptionsMenu(final MenuInflater inflater, final Menu menu) {
    inflater.inflate(R.menu.gallery_picker_menu, menu);
    final MenuItem toggleMultiSelect = menu.findItem(R.id.action_multiselect);
    final MenuItem confirmMultiSelect = menu.findItem(R.id.action_confirm_multiselect);
    final boolean canToggleMultiSelect = canToggleMultiSelect();
    toggleMultiSelect.setVisible(canToggleMultiSelect);
    confirmMultiSelect.setVisible(!canToggleMultiSelect);
}