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.dabay6.android.apps.carlog.ui.HomeActivity.java

/**
 * {@inheritDoc}//from  w w  w  .  j a va  2 s  .  co  m
 */
@Override
protected void onHideOptionsMenuItems(final Menu menu, final boolean isDrawerOpen) {
    MenuItem item;

    item = menu.findItem(id.menu_settings);
    if (item != null) {
        item.setVisible(!isDrawerOpen);
    }

    item = menu.findItem(id.menu_fuel_history_add);
    if (item != null) {
        item.setVisible(!isDrawerOpen);
    }

    item = menu.findItem(id.menu_fuel_history_edit);
    if (item != null) {
        item.setVisible(!isDrawerOpen);
    }
}

From source file:com.kaliturin.blacklist.fragments.SMSConversationFragment.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/*from  w w  w . j a v a 2s . com*/
        public boolean onMenuItemClick(MenuItem item) {
            // open activity with fragment of sending SMS
            openSMSSendActivity(contactName, contactNumber, messageEdit.getText().toString());
            messageEdit.setText("");
            return true;
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.arcgis.android.samples.localdata.localrasterdata.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.menu_layer_raster) || (item.getItemId() == R.id.menu_renderer)
                || (item.getItemId() == R.id.menu_dir_select)) {
            item.setVisible(false);
        } else if ((item.getItemId() == R.id.menu_dir_up)) {
            item.setVisible(true);//from   w  w w . j  a  v  a2 s  .  c o m
        }
    }
}

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

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.main, menu);
    MenuItem itemSearch = menu.findItem(R.id.action_search);
    Utils.setMenuIconTint(getContext(), itemSearch, R.attr.colorAccent);
    itemSearch.setVisible(true);

    // get the view from search menu item
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(itemSearch);
    searchView.setQueryHint(getString(R.string.Search_action));
    // set on text change listener
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//ww  w.  j a  va  2 s.  c  o  m
        public boolean onQueryTextSubmit(String query) {
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            reloadItems(newText);
            return true;
        }
    });

    // on search cancelling
    // SearchView.OnCloseListener is not calling so use other way...
    MenuItemCompat.setOnActionExpandListener(itemSearch, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            reloadItems(null);
            return true;
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.cerema.cloud2.ui.preview.PreviewTextFragment.java

/**
 * {@inheritDoc}/*from   ww w. ja  va2  s . c  o m*/
 */
@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    if (mContainerActivity.getStorageManager() != null) {
        FileMenuFilter mf = new FileMenuFilter(getFile(), mContainerActivity.getStorageManager().getAccount(),
                mContainerActivity, getActivity());
        mf.filter(menu);
    }

    // additional restriction for this fragment
    MenuItem item = menu.findItem(R.id.action_rename_file);
    if (item != null) {
        item.setVisible(false);
        item.setEnabled(false);
    }

    // additional restriction for this fragment
    item = menu.findItem(R.id.action_move);
    if (item != null) {
        item.setVisible(false);
        item.setEnabled(false);
    }

    // this one doesn't make sense since the file has to be down in order to be previewed
    item = menu.findItem(R.id.action_download_file);
    if (item != null) {
        item.setVisible(false);
        item.setEnabled(false);
    }

    item = menu.findItem(R.id.action_sync_file);
    if (item != null) {
        item.setVisible(false);
        item.setEnabled(false);
    }

    item = menu.findItem(R.id.action_sync_account);
    if (item != null) {
        item.setVisible(false);
        item.setEnabled(false);
    }

    Boolean dualPane = getResources().getBoolean(R.bool.large_land_layout);

    item = menu.findItem(R.id.action_switch_view);
    if (item != null && !dualPane) {
        item.setVisible(false);
        item.setEnabled(false);
    }

    item = menu.findItem(R.id.action_sort);
    if (item != null && !dualPane) {
        item.setVisible(false);
        item.setEnabled(false);
    }
}

From source file:com.paramedic.mobshaman.fragments.AccionesDetalleServicioFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    MenuItem itemMapa = menu.findItem(R.id.action_ubicacion_servicio);
    itemMapa.setVisible(false);

}

From source file:it_minds.dk.eindberetningmobil_android.views.StartActivity.java

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

    final MenuItem badgeItem = menu.findItem(R.id.missing_trip_menu_counter);
    final RelativeLayout badgeLayout = (RelativeLayout) badgeItem.getActionView();

    //Set badge/*  w  w  w.j av a2  s.c  om*/
    if (badgeCount > 0) {
        badgeItem.setVisible(true);

        TextView tv = (TextView) badgeLayout.findViewById(R.id.actionbar_notifcation_textview);
        tv.setText(badgeCount + "");
    } else {
        badgeItem.setVisible(false);
    }
    return true;
}

From source file:com.xengar.android.englishverbs.ui.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  va 2  s. c  o  m*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    // If this is a new verb, hide the "Delete" menu item.
    if (verbID == -1) {
        MenuItem menuItem = menu.findItem(R.id.action_delete);
        menuItem.setVisible(false);
    }
    return true;
}

From source file:com.zion.htf.ui.fragment.ArtistDetailsFragment.java

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

    if (0 == this.setId) {
        MenuItem addAlarmMenuItem = menu.findItem(R.id.action_addAlarm);
        MenuItem editAlarmMenuItem = menu.findItem(R.id.action_editAlarm);
        if (null != addAlarmMenuItem) {
            addAlarmMenuItem.setVisible(false);
            addAlarmMenuItem.setEnabled(false);
        }// w  w w  .  j  av a  2s .  c  om
        if (null != editAlarmMenuItem) {
            editAlarmMenuItem.setVisible(false);
            editAlarmMenuItem.setEnabled(false);
        }
    }
}

From source file:com.xengar.android.englishverbs.ui.DetailsActivity.java

/**
 * This method is called after invalidateOptionsMenu(), so that the
 * menu can be updated (some menu items can be hidden or made visible).
 *//*ww  w . ja va2  s . co m*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    // If this is a new verb, hide the "Edit" menu item for application verbs.
    if (verbID >= 0) {
        MenuItem menuItem = menu.findItem(R.id.action_edit);
        menuItem.setVisible(false);
    }
    return true;
}