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:io.syng.fragment.profile.ProfileDialogFragment.java

@Nullable
@Override/*from   w  ww  .j a v  a 2 s.c  o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.profile_edit_dialog, container);
    TabLayout tabLayout = (TabLayout) view.findViewById(R.id.profile_tabs);
    mViewPager = (ViewPager) view.findViewById(R.id.profile_view_pager);

    mViewPager.addOnPageChangeListener(this);
    mToolbar = (Toolbar) view.findViewById(R.id.profile_toolbar);
    mToolbar.setTitle("Edit Profile");
    mToolbar.inflateMenu(R.menu.profile_menu);

    MenuItem exportProfile = mToolbar.getMenu().findItem(R.id.action_key_export);
    exportProfile.setVisible(false);
    exportProfile.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            return false;
        }
    });
    MenuItem importProfile = mToolbar.getMenu().findItem(R.id.action_key_import);
    importProfile.setVisible(false);
    importProfile.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            GeneralUtil.showProfileImportDialog(getActivity());
            return false;
        }
    });

    mToolbar.setNavigationIcon(R.drawable.ic_arrow_back_black_24dp);
    mToolbar.setNavigationOnClickListener(this);
    mToolbar.setOnMenuItemClickListener(this);
    tintMenuItem();

    mViewPager.setAdapter(new ProfileViewPagerAdapter(getChildFragmentManager(), getActivity(), mProfileId));
    tabLayout.setupWithViewPager(mViewPager);

    return view;
}

From source file:com.gmail.taneza.ronald.carbs.myfoods.MyFoodDetailsActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//from   w  w w  .j  a v  a 2 s  . c  o  m
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_my_food_details, menu);

    if (mMode == Mode.NewFood) {
        MenuItem menuItem = menu.findItem(R.id.menu_my_food_delete);
        menuItem.setVisible(false);
    }

    return true;
}

From source file:com.gmail.taneza.ronald.carbs.main.FoodDetailsActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from   www . j  a  va2  s. c o m*/
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_food_details, menu);

    if (mMode == Mode.NewFood) {
        MenuItem menuItem = menu.findItem(R.id.menu_food_details_delete);
        menuItem.setVisible(false);
    }

    return true;
}

From source file:com.sonaive.v2ex.ui.FeedDetailActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.feeds, menu);

    MenuItem refreshMenu = menu.findItem(R.id.menu_refresh);
    if (isRefreshing()) {
        refreshMenu.setVisible(true);
        refreshMenu.setActionView(R.layout.progress_bar);
    }// w  w w . j  a  va  2 s  .  co m

    return true;
}

From source file:com.translationexchange.samples.wammer.activities.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // if nav drawer is opened, hide the action items
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
    MenuItem menuItem = (MenuItem) menu.findItem(R.id.change_language);
    menuItem.setVisible(!drawerOpen);
    menuItem.setTitle("Change Language");
    menuItem = (MenuItem) menu.findItem(R.id.inline_translator);
    menuItem.setVisible(!drawerOpen);/*from   w  ww.  j  av  a 2s. c  o  m*/
    menuItem.setTitle("Translate");
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.justplay1.shoppist.features.lists.items.ListItemActivity.java

@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    super.onPrepareActionMode(mode, menu);
    MenuItem move = menu.findItem(R.id.action_move);
    MenuItem copy = menu.findItem(R.id.action_copy);
    boolean enable = fragment.isMoveCopyButtonEnable();
    move.setEnabled(enable);/*w  ww .j a va 2s  .c  o m*/
    copy.setEnabled(enable);

    MenuItem edit = menu.findItem(R.id.action_edit);
    if (edit != null) {
        edit.setVisible(fragment.isEditButtonEnable());
    }

    MenuItem checkAll = menu.findItem(R.id.menu_check_all);
    checkAll.setEnabled(fragment.isCheckAllButtonEnable());
    return true;
}

From source file:com.luorrak.ouroboros.deepzoom.DeepZoomFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_deep_zoom, menu);
    MenuItem saveImage = menu.findItem(R.id.action_save_image);
    MenuItem openExternalButton = menu.findItem(R.id.action_external_browser);
    MenuItem shareButton = menu.findItem(R.id.menu_item_share);

    shareButton.setVisible(true);
    saveImage.setVisible(true);//from   ww w  .  j a  v a2 s .  c  om
    openExternalButton.setVisible(true);
    getActivity().setTitle(mediaItem.fileName + mediaItem.ext);

    shareActionProvider = MenuItemCompat.getActionProvider(shareButton);
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:bbct.android.common.activity.FilterCards.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    MenuItem confirm = menu.findItem(R.id.save_menu);

    if (this.numberChecked() > 0) {
        confirm.setVisible(true);
        confirm.setEnabled(true);/*w  w w. ja v a  2s  .com*/
    } else {
        confirm.setVisible(false);
        confirm.setEnabled(false);
    }
}

From source file:com.google.reviewit.DetailedChangeFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    SortActionHandler actionHandler = getApp().getSortActionHandler();
    inflater.inflate(R.menu.menu_detailed_change, menu);
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.getItemId() == R.id.action_abandon) {
            item.setVisible(actionHandler.hasCurrentChange()
                    && (actionHandler.getCurrentChange().info.status == ChangeStatus.NEW
                            || actionHandler.getCurrentChange().info.status == ChangeStatus.SUBMITTED));
        } else if (item.getItemId() == R.id.action_restore) {
            item.setVisible(actionHandler.hasCurrentChange()
                    && actionHandler.getCurrentChange().info.status == ChangeStatus.ABANDONED);
        }//from  w w w.j  a v a 2s  .c o  m
    }
}

From source file:com.fimagena.filepicker.FilePickerFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.picker_actions, menu);
    MenuItem item = menu.findItem(R.id.action_createdir);
    item.setVisible(mParams.get(ALLOW_CREATE_DIR));

    // FIXME: Ensure the icon is visible on the light background. This is a hack and should be done through the theme!
    TypedValue value = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.colorAccent, value, true);
    menu.findItem(R.id.action_createdir).getIcon().mutate().setColorFilter(value.data,
            PorterDuff.Mode.SRC_ATOP);/*from w  w w  .ja va2  s .  co m*/

    for (int root = 0; root < mFileSystemRoots.length; root++)
        menu.add(Menu.NONE, root, Menu.NONE, "Switch to " + mFileSystemRoots[root].getName());
}