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.berlin_vegan.bvapp.activities.LocationsOverviewActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem menuItem = menu.findItem(R.id.menu_search);
    if (mLocations.getDataType() == Locations.DATA_TYPE.GASTRO
            || mLocations.getDataType() == Locations.DATA_TYPE.SHOPPING) {
        initializeSearch(menuItem);/*from w  ww .  j  a  v  a  2s. co m*/
    } else {
        menuItem.setVisible(false); // hide for favorite
    }

    menuItem = menu.findItem(R.id.action_filter);
    if (mLocations.getDataType() == Locations.DATA_TYPE.FAVORITE
            || mLocations.getDataType() == Locations.DATA_TYPE.SHOPPING) { // at the moment no filter for shopping and favorite
        menuItem.setVisible(false);
    }
    return true;
}

From source file:com.dwdesign.tweetings.fragment.UserListDetailsFragment.java

@Override
public void onClick(final View view) {
    switch (view.getId()) {
    case R.id.follow_more: {
        if (mUserList == null)
            return;
        /*if (mAccountId != mUserId) {
           mFollowMoreButton.setVisibility(View.GONE);
           if (mUserList.isFollowing()) {
          mService.destroyUserListSubscription(mAccountId, mUserList.getId());
           } else {//from w w w  .ja  v a  2 s  .  co m
          mService.createUserListSubscription(mAccountId, mUserList.getId());
           }
        } else {*/
        mPopupMenu = PopupMenu.getInstance(getActivity(), view);
        mPopupMenu.inflate(R.menu.action_user_list_details);
        if (mUserId == mAccountId) {
            final MenuItem followItem = mPopupMenu.getMenu().findItem(MENU_FOLLOW);
            followItem.setVisible(false);
        } else {
            final MenuItem followItem = mPopupMenu.getMenu().findItem(MENU_FOLLOW);
            followItem.setTitle(mUserList.isFollowing() ? R.string.unfollow : R.string.follow);
            final MenuItem addMemberItem = mPopupMenu.getMenu().findItem(MENU_ADD);
            addMemberItem.setVisible(false);
            final MenuItem deleteItem = mPopupMenu.getMenu().findItem(MENU_DELETE_SUBMENU);
            deleteItem.setVisible(false);
        }
        mPopupMenu.setOnMenuItemClickListener(this);
        mPopupMenu.show();
        //}
        break;
    }
    case R.id.retry: {
        reloadUserListInfo();
        break;
    }
    case R.id.profile_image_container: {
        if (mAccountId > 0 && (mUserId > 0 || mUserScreenName != null)) {
            openUserProfile(getActivity(), mAccountId, mUserId, mUserScreenName);
        }
        break;
    }
    }

}

From source file:com.android.gpstest.GpsTestActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem item;

    item = menu.findItem(R.id.send_location);
    if (item != null) {
        item.setVisible(mLastLocation != null);
    }/*from ww  w  .j a  va  2 s  .  com*/

    return true;
}

From source file:com.gimranov.zandy.app.ItemActivity.java

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

    // Turn on sort item
    MenuItem sort = menu.findItem(R.id.do_sort);
    sort.setEnabled(true);//  w  ww. j a v a2s .  c om
    sort.setVisible(true);

    // Turn on search item
    MenuItem search = menu.findItem(R.id.do_search);
    search.setEnabled(true);
    search.setVisible(true);

    // Turn on identifier item
    MenuItem identifier = menu.findItem(R.id.do_identifier);
    identifier.setEnabled(true);
    identifier.setVisible(true);

    return true;
}

From source file:examples.baku.io.permissions.examples.ComposeActivity.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_compose, menu);
    menu.findItem(R.id.action_cast)/* w ww . j  a  va 2s  .  com*/
            .setIcon(new IconDrawable(this, MaterialIcons.md_cast).color(Color.WHITE).actionBarSize());
    MenuItem deleteItem = menu.findItem(R.id.action_delete);

    MenuItem attachItem = menu.findItem(R.id.action_attach)
            .setIcon(new IconDrawable(this, MaterialIcons.md_attach_file).color(Color.WHITE).actionBarSize());
    attachItem.setVisible(false);
    if (mOwner == null || !mOwner.equals(mDeviceId)) {
        attachItem.setVisible(false);
        deleteItem.setVisible(false);
    }
    mMenu = menu;
    return true;
}

From source file:com.esri.android.ecologicalmarineunitexplorer.MainActivity.java

/**
 *
 * @param menu Menu/*www. j a  v  a  2 s. c  o  m*/
 * @return boolean
 */
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    final MenuItem profile = menu.findItem(R.id.action_profile);
    final MenuItem search = menu.findItem(R.id.action_search);
    final int state = mBottomSheetBehavior.getState();
    if ((state == BottomSheetBehavior.STATE_COLLAPSED) || (state == BottomSheetBehavior.STATE_EXPANDED)) {
        profile.setVisible(true);
        search.setVisible(false);
    } else if (mInMapState) {
        profile.setVisible(false);
        search.setVisible(true);
    } else {
        profile.setVisible(false);
        search.setVisible(false);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.openatk.rockapp.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    if (mCurrentState == STATE_DEFAULT) {
        menu.clear();/*  www. j a  v a  2s.  c o m*/
        inflater.inflate(R.menu.main, menu);

        MenuItem showHideItem = menu.findItem(R.id.show_hide);
        MenuItem currentShowHideItem;

        switch (mRockState) {
        case STATE_ROCKS_BOTH:
            currentShowHideItem = menu.findItem(R.id.all_rocks);
            break;

        case STATE_ROCKS_NOT_PICKED_UP:
            currentShowHideItem = menu.findItem(R.id.not_picked_rocks);
            break;

        case STATE_ROCKS_PICKED_UP:
            currentShowHideItem = menu.findItem(R.id.picked_rocks);
            break;
        default:
            // We are some how lost, just revert back to showing everything
            Log.e("MainActivity", "Lost Rock Shown State");
            mRockState = STATE_ROCKS_BOTH;
            currentShowHideItem = menu.findItem(R.id.all_rocks);
            break;
        }

        // Copy the current selection to the action bar
        showHideItem.setTitle(currentShowHideItem.getTitle());

        // Mark the current one as checked
        currentShowHideItem.setChecked(true);

        // The location button changes depending the current state
        // of location

        // TODO
        /*
         * MenuItem gps = menu.findItem(R.id.gps); if(map.ha) {
         * if(mRockLocationManager.haveUserLocation()) {
         * gps.setIcon(R.drawable.gps_found);
         * gps.setTitle(R.string.menu_gps); } else {
         * gps.setIcon(R.drawable.gps_searching);
         * gps.setTitle(R.string.menu_gps_searching); } } else {
         * gps.setIcon(R.drawable.gps_off);
         * gps.setTitle(R.string.menu_gps_off); }
         */
    } else if (mCurrentState == STATE_ROCK_EDIT) {
        menu.clear();
        inflater.inflate(R.menu.rock_edit_menu, menu);
        MenuItem undoButton = menu.findItem(R.id.rock_undo_move);
        if (undoMoves.isEmpty()) {
            undoButton.setVisible(false);
        } else {
            undoButton.setVisible(true);
        }
    }
    return true;
}

From source file:org.digitalcampus.oppia.utils.ui.DrawerMenuManager.java

public void onPrepareOptionsMenu(Menu menu, Integer currentOption, Map<Integer, MenuOption> options) {

    if (options != null)
        this.customOptions = options;

    Menu drawerMenu = navigationView.getMenu();
    MenuItem itemLogout = drawerMenu.findItem(R.id.menu_logout);
    MenuItem itemSettings = drawerMenu.findItem(R.id.menu_settings);
    MenuItem itemMonitor = drawerMenu.findItem(R.id.menu_monitor);
    MenuItem itemCourseDownload = drawerMenu.findItem(R.id.menu_download);
    MenuItem itemLanguageDialog = drawerMenu.findItem(R.id.menu_language);

    if (currentOption != null) {
        MenuItem current = drawerMenu.findItem(currentOption);
        if (current != null) {
            current.setCheckable(true);//from w  w w  .  ja v a2s  . c  o m
            current.setChecked(true);
        }
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(drawerAct);
    itemLogout
            .setVisible(prefs.getBoolean(PrefsActivity.PREF_LOGOUT_ENABLED, MobileLearning.MENU_ALLOW_LOGOUT));
    itemSettings.setVisible(MobileLearning.MENU_ALLOW_SETTINGS);
    itemMonitor.setVisible(MobileLearning.MENU_ALLOW_MONITOR);
    itemCourseDownload.setVisible(MobileLearning.MENU_ALLOW_COURSE_DOWNLOAD);
    itemLanguageDialog.setVisible(customOptions.containsKey(R.id.menu_language));
}

From source file:app.sunstreak.yourpisd.ClassSwipeActivity.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.class_swipe_actions, menu);

    if (termIndex == 0)
        menu.findItem(R.id.previous_six_weeks).setEnabled(false);
    else if (termIndex == 7)
        menu.findItem(R.id.next_six_weeks).setEnabled(false);

    // Create list of students in Menu.
    if (session.MULTIPLE_STUDENTS) {
        for (int i = 0; i < session.getStudents().size(); i++) {
            String name = session.getStudents().get(i).name;
            MenuItem item = menu.add(name);

            // Set the currently enabled student un-clickable.
            if (i == studentIndex)
                item.setEnabled(false);/*from w ww .  j  a va2s  . c  o m*/

            item.setOnMenuItemClickListener(new StudentSelectListener(i));
            item.setVisible(true);
        }
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.duy.pascal.ui.file.fragment.FileListPagerFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.paste_menu) {
        final FileClipboard fileClipboard = ((FileExplorerActivity) getActivity()).getFileClipboard();
        fileClipboard.paste(getContext(), getCurrentDirectory(), new OnClipboardPasteFinishListener() {
            @Override/*w  ww. jav a  2 s  . co m*/
            public void onFinish(int count, String error) {
                onRefresh();
                fileClipboard.showPasteResult(getContext(), count, error);
            }
        });
        item.setVisible(false);
    } else if (item.getItemId() == R.id.add_folder_menu) {
        mAction.doCreateFolder(null);
    }
    return super.onOptionsItemSelected(item);
}