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.cirdles.chroni.AliquotMenuActivity.java

/**
 * The purpose of overriding this method is to alter/delete some of the menu items from the default
 * menu, as they are not wanted in this Activity. Doing so prevents the unnecessary stacking of
 * Activities by making the user follow the intended flow of Activities in the application.
 *
 * @param menu the menu that has been inflated in the Activity
 * @return true so that the menu is displayed
 *///from  w  w w. j av a 2s. c  o m
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // removes the History item from the menu
    MenuItem historyItem = menu.findItem(R.id.historyMenu);
    historyItem.setVisible(false);

    // removes the Edit Credentials item from the menu
    MenuItem credentialsItem = menu.findItem(R.id.editProfileMenu);
    credentialsItem.setVisible(false);

    MenuItem viewFiles = menu.findItem(R.id.viewFilesMenu);
    viewFiles.setVisible(false);

    // if coming from a Table Activity, changes Main Menu item to say "Back to Table"
    if (getIntent().hasExtra("From_Table")) {
        if (getIntent().getStringExtra("From_Table").equals("true")) {
            MenuItem backItem = menu.findItem(R.id.returnToMenu);
            backItem.setTitle("Back to Table");
        }
    }

    return true;
}

From source file:mobile_final.ChattingRoomActivity.java

/**
 * Override Activity lifecycle method.//ww w.  j av  a2  s.  c  o  m
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem loginItem = menu.findItem(R.id.switch_account);
    loginItem.setVisible(Consts.IS_AUTH_ENABLED);
    MenuItem voteItem = menu.findItem(R.id.vote);
    voteItem.setVisible(true);
    MenuItem voteResultItem = menu.findItem(R.id.voteResult);
    return true;
}

From source file:org.fdroid.fdroid.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 . j a va  2  s .co  m
    if (Build.VERSION.SDK_INT < 10) {
        MenuItem menuItem = menu.findItem(R.id.action_swap);
        menuItem.setVisible(false);
    }

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchMenuItem = menu.findItem(R.id.action_search);
    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:de.enlightened.peris.ProfileFragment.java

@SuppressLint("NewApi")
@Override/*from   ww  w.j  ava  2  s  .  c  o m*/
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.profile_menu, menu);
    if (ThemeSetter.getForegroundDark(this.application.getSession().getServer().serverColor)) {
        final MenuItem item = menu.findItem(R.id.profile_menu_message);
        item.setIcon(R.drawable.ic_action_new_email_dark);
    }
    if (this.userName == null
            || this.userName.contentEquals(this.application.getSession().getServer().serverUserName)) {
        final MenuItem msgitem = menu.findItem(R.id.profile_menu_message);
        msgitem.setVisible(false);
    }
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.luorrak.ouroboros.thread.ThreadFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem goToBottomButton = menu.findItem(R.id.action_scroll_bottom);
    MenuItem goToTopButton = menu.findItem(R.id.action_scroll_top);
    MenuItem replyButton = menu.findItem(R.id.action_reply);
    MenuItem watchlistButton = menu.findItem(R.id.action_add_watchlist);
    MenuItem refreshButton = menu.findItem(R.id.action_refresh);
    MenuItem galleryButton = menu.findItem(R.id.action_gallery);
    MenuItem saveAllImagesButton = menu.findItem(R.id.action_save_all_images);
    MenuItem openExternalButton = menu.findItem(R.id.action_external_browser);
    MenuItem shareButton = menu.findItem(R.id.menu_item_share);
    MenuItem menuLayout = menu.findItem(R.id.action_menu_layout);

    MenuItem searchButton = menu.findItem(R.id.action_search);
    searchButton.setVisible(true);
    final SearchView searchView = (SearchView) searchButton.getActionView();
    searchView.setIconifiedByDefault(false);
    searchView.setSubmitButtonEnabled(false);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*  ww  w  .j av a2 s .  co  m*/
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            threadAdapter.setFilterQueryProvider(new FilterQueryProvider() {
                @Override
                public Cursor runQuery(CharSequence constraint) {
                    return infiniteDbHelper.searchThreadForString(constraint.toString(), resto);
                }
            });
            threadAdapter.getFilter().filter(newText);
            return true;
        }
    });

    MenuItemCompat.setOnActionExpandListener(searchButton, this);

    refreshButton.setVisible(true);
    goToBottomButton.setVisible(true);
    goToTopButton.setVisible(true);
    replyButton.setVisible(true);
    galleryButton.setVisible(true);
    saveAllImagesButton.setVisible(true);
    openExternalButton.setVisible(true);
    shareButton.setVisible(true);
    watchlistButton.setVisible(true);
    menuLayout.setVisible(true);

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:edu.berkeley.boinc.ProjectDetailsFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {

    super.onPrepareOptionsMenu(menu);
    if (project == null)
        return;//from w  w  w  . ja va2 s  .c  om

    // no new tasks, adapt based on status 
    MenuItem nnt = menu.findItem(R.id.projects_control_nonewtasks);
    if (project.dont_request_more_work)
        nnt.setTitle(R.string.projects_control_allownewtasks);
    else
        nnt.setTitle(R.string.projects_control_nonewtasks);

    // project suspension, adapt based on status 
    MenuItem suspend = menu.findItem(R.id.projects_control_suspend);
    if (project.suspended_via_gui)
        suspend.setTitle(R.string.projects_control_resume);
    else
        suspend.setTitle(R.string.projects_control_suspend);

    // detach, only show when project not managed
    MenuItem remove = menu.findItem(R.id.projects_control_remove);
    if (project.attached_via_acct_mgr)
        remove.setVisible(false);
}

From source file:com.heske.alexandria.activities.MainActivity.java

private void hideMenuItem(Menu menu, int menuItemId) {
    MenuItem menuItem = menu.findItem(menuItemId);
    if (menuItem != null)
        menuItem.setVisible(false);
}

From source file:com.fusionx.lightirc.ui.IRCActivity.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    final MenuItem userMenu = menu.findItem(R.id.activity_server_channel_ab_users);
    final boolean isChannel = (FragmentType.Channel.equals(mIRCPagerFragment.getCurrentType()));
    userMenu.setVisible(isChannel && mUserSlidingMenu != null);
    return true;/*from w ww . j  a  v  a  2  s.  c  o  m*/
}

From source file:com.soil.soilsample.ui.main.FileBrowserFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if ((item.getItemId() == R.id.action_add_sample) || (item.getItemId() == R.id.menu_dir_select)
                || (item.getItemId() == R.id.action_upload)) {
            item.setVisible(false);
        } else if ((item.getItemId() == R.id.menu_dir_up)) {
            item.setVisible(true);//from   www.  j a  va2  s. c om
        }
    }
}

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

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    //find menu dashboard
    MenuItem itemDashboard = menu.findItem(R.id.menu_dashboard);
    if (itemDashboard != null)
        itemDashboard.setVisible(false);
}