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:com.gh4a.activities.GistActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean authorized = Gh4Application.get().isAuthorized();

    MenuItem starAction = menu.findItem(R.id.star);
    starAction.setVisible(authorized);
    if (authorized) {
        if (mIsStarred == null) {
            MenuItemCompat.setActionView(starAction, R.layout.ab_loading);
            MenuItemCompat.expandActionView(starAction);
        } else if (mIsStarred) {
            starAction.setTitle(R.string.repo_unstar_action);
            starAction.setIcon(R.drawable.unstar);
        } else {//from  w ww.j  a  va2 s  .  c o m
            starAction.setTitle(R.string.repo_star_action);
            starAction.setIcon(R.drawable.star);
        }
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.vuze.android.remote.fragment.PeersFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    if (AndroidUtils.DEBUG_MENU) {
        Log.d(TAG, "onPrepareOptionsMenu " + torrentID);
    }/* w  w  w .  j av  a 2  s.co  m*/

    MenuItem menuItem = menu.findItem(R.id.action_update_tracker);
    if (menuItem != null) {
        menuItem.setVisible(torrentID >= 0);
    }
    super.onPrepareOptionsMenu(menu);
}

From source file:net.kw.shrdlu.grtgtfs.Activities.MenuListActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerListView);
    MenuItem item;
    item = menu.findItem(R.id.menu_search);
    if (item != null)
        item.setVisible(!drawerOpen);
    item = menu.findItem(R.id.menu_refresh);
    if (item != null)
        item.setVisible(!drawerOpen);/*from   w  w  w.  j  a v a2s.  co m*/
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.jefftharris.passwdsafe.PasswdSafeRecordFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    MenuItem item = menu.findItem(R.id.menu_edit);
    if (item != null) {
        item.setVisible(itsCanEdit);
    }//from  w  w w  .ja v a 2 s .  com

    item = menu.findItem(R.id.menu_delete);
    if (item != null) {
        item.setVisible(itsCanDelete);
    }

    super.onPrepareOptionsMenu(menu);
}

From source file:com.vuze.android.remote.activity.DrawerActivity.java

public boolean onPrepareOptionsMenu_drawer(Menu menu) {

    if (mDrawerLayout == null) {
        return true;
    }/*  w  w  w . jav  a  2  s.c  o  m*/

    if (!mDrawerLayout.isDrawerOpen(mDrawerView)) {
        for (int i = 0; i < menu.size(); i++) {
            MenuItem item = menu.getItem(i);
            item.setVisible(true);
        }
    } else {
        final int[] itemsToKeep = { R.id.action_about, R.id.action_logout, R.id.action_social,
                R.id.action_settings };
        for (int i = 0; i < menu.size(); i++) {
            MenuItem item = menu.getItem(i);
            int id = item.getItemId();
            boolean visible = false;
            for (int itemID : itemsToKeep) {
                if (id == itemID) {
                    visible = true;
                    break;
                }
            }
            item.setVisible(visible);
        }
        return false; // skip all other prepares
    }

    return true;
}

From source file:com.github.michalbednarski.intentslab.browser.RegisteredReceiverInfoFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.component_info, menu);
    MenuItem packageInfoOption = menu.findItem(R.id.package_info);
    boolean packageInfoAvailable = mPackageName != null;
    packageInfoOption.setVisible(packageInfoAvailable);
    packageInfoOption.setEnabled(packageInfoAvailable);
}

From source file:cf.obsessiveorange.rhcareerfairlayout.ui.fragments.VPCompaniesFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MenuItem searchBtn = menu.findItem(R.id.action_search);
    searchBtn.setVisible(true);

    SubMenu selectionMenu = menu.addSubMenu(getResources().getString(R.string.selection_options_btn));
    selectionMenu.getItem().setIcon(new IconDrawable(this.getActivity(), Iconify.IconValue.fa_edit)
            .colorRes(R.color.accentNoTransparency).actionBarSize());
    selectionMenu.getItem().setTitle(getResources().getString(R.string.selection_options_btn));
    selectionMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    MenuItem selectAllItem = selectionMenu.add(getResources().getString(R.string.btn_select_all));
    selectAllItem.setIcon(new IconDrawable(this.getActivity(), Iconify.IconValue.fa_check_square_o)
            .colorRes(R.color.accentNoTransparency).actionBarSize());
    selectAllItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    selectAllItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override/*from  w ww  . jav a2s . c o  m*/
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(getActivity(), "Selected all items", Toast.LENGTH_SHORT).show();

            try {
                DBManager.setFilteredCompaniesSelected(true);
            } catch (SQLException e) {
                e.printStackTrace();
            }

            ((CompaniesCellAdapter) recyclerView.getAdapter()).refreshData();

            synchronized (RHCareerFairLayout.refreshMapNotifier) {
                RHCareerFairLayout.refreshMapNotifier.notifyChanged();
            }

            return true;
        }
    });

    MenuItem deselectAllItem = selectionMenu.add(getResources().getString(R.string.btn_deselect_all));
    deselectAllItem.setIcon(new IconDrawable(this.getActivity(), Iconify.IconValue.fa_square_o)
            .colorRes(R.color.accentNoTransparency).actionBarSize());
    deselectAllItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    deselectAllItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(getActivity(), "Deselected all items", Toast.LENGTH_SHORT).show();

            try {
                DBManager.setFilteredCompaniesSelected(false);
            } catch (SQLException e) {
                e.printStackTrace();
            }

            ((CompaniesCellAdapter) recyclerView.getAdapter()).refreshData();

            synchronized (RHCareerFairLayout.refreshMapNotifier) {
                RHCareerFairLayout.refreshMapNotifier.notifyChanged();
            }

            return true;
        }
    });
}

From source file:com.google.devrel.samples.memedroid.app.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem item = menu.findItem(R.id.menu_logout);
    if (item != null) {
        item.setVisible(mAccountName != null);
    }/*w ww  .j a  va 2  s  .  c o m*/
    return super.onPrepareOptionsMenu(menu);
}

From source file:ca.farrelltonsolar.classic.HourLogChart.java

private void setupSpinner(MenuItem item) {
    try {//from w  ww.  j  a  v  a 2s  .  com
        item.setVisible(true);
        item.setActionView(R.layout.action_chart_select);
        View view = MenuItemCompat.getActionView(item);
        if (view instanceof Spinner) {
            Spinner spinner = (Spinner) view;
            String[] itemArray = getResources().getStringArray(R.array.minute_log_chart_selection);
            ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this.getActivity(),
                    android.R.layout.simple_spinner_item, itemArray); //selected item will look like a spinner set from XML
            spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(spinnerArrayAdapter);
            spinner.setSelection(MonitorApplication.chargeControllers().getCurrentChargeController()
                    .getHourLogMenuSelection(), false);
            spinner.setOnItemSelectedListener(
                    new OnItemSelectedListenerWrapper(new AdapterView.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            chartView.clearSeries();
                            if (position < mSeries.size()) {
                                MonitorApplication.chargeControllers().getCurrentChargeController()
                                        .setHourLogMenuSelection(position);
                                chartView.addSeries(mSeries.get(position));
                            }
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> parent) {

                        }
                    }));
        }
    } catch (Exception ex) {
        Log.w(getClass().getName(), String.format("Hour Log Chart failed to load setupSpinner %s ex: %s",
                Thread.currentThread().getName(), ex));
    }
}

From source file:com.andremion.louvre.home.GalleryFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    boolean isMedia = mAdapter.getItemViewType(0) == GalleryAdapter.VIEW_TYPE_MEDIA;
    MenuItem selectAll = menu.findItem(R.id.action_select_all);
    selectAll.setVisible(isMedia);
    MenuItem clear = menu.findItem(R.id.action_clear);
    clear.setVisible(isMedia);/*from   w w  w  .  jav  a  2 s .  c om*/
}