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.uwetrottmann.wpdisplay.ui.DisplayFragment.java

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

    boolean paused = ConnectionTools.get().isPaused();
    MenuItem item = menu.findItem(R.id.menu_action_display_pause);
    item.setIcon(paused ? R.drawable.ic_play_arrow_white_24dp : R.drawable.ic_pause_white_24dp);
    item.setTitle(paused ? R.string.action_resume : R.string.action_pause);

    item.setEnabled(isConnected);//from w ww .  j ava  2  s.c  om
    item.setVisible(isConnected);
}

From source file:org.docrj.smartcard.reader.GroupViewActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // handle read-only default groups
    if (mReadOnly) {
        MenuItem editMenuItem = menu.findItem(R.id.menu_edit_group);
        editMenuItem.setVisible(false);
        MenuItem delMenuItem = menu.findItem(R.id.menu_delete_group);
        delMenuItem.setVisible(false);/*from  ww  w  .ja v  a 2s .  c  o  m*/
        MenuItem renameMenuItem = menu.findItem(R.id.menu_rename_group);
        renameMenuItem.setVisible(false);
    }
    return true;
}

From source file:com.example.android.cupboard.EditorActivity.java

/**
 * This method is called after invalidateOptionsMenu(), so that the
 * menu can be updated (some menu items can be hidden or made visible).
 */// w  ww .j a v a2s.  co  m
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    // If this is a new food item, hide the "Delete" menu item.
    if (mCurrentFoodUri == null) {
        MenuItem menuItem = menu.findItem(R.id.action_delete);
        menuItem.setVisible(false);
    }
    return true;
}

From source file:com.mobicage.rogerthat.NewsActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        switch (item.getItemId()) {
        case R.id.saved:
            item.setVisible(newsStore != null && newsStore.countNewsPinnedItems(feedName) > 0);
            break;
        }/*  w  w  w.  j  a  v  a2s. co  m*/
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:ca.rmen.android.scrumchatter.main.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    Log.v(TAG, "onPrepareOptionsMenu " + menu);
    // Only enable the "delete team" menu item if we have at least two teams.
    MenuItem deleteItem = menu.findItem(R.id.action_team_delete);
    deleteItem.setEnabled(mTeamCount > 1);
    // Add the current team name to the delete and rename menu items
    if (mTeam != null) {
        deleteItem.setTitle(getString(R.string.action_team_delete_name, mTeam.teamName));
        MenuItem renameItem = menu.findItem(R.id.action_team_rename);
        renameItem.setTitle(getString(R.string.action_team_rename_name, mTeam.teamName));
    }//w  w w.j a  v a  2 s  . c om
    // Only show the settings in v14+.  Currently the only setting
    // we have is for the day/night theme switch, which only works on
    // v14+.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        MenuItem settingsItem = menu.findItem(R.id.action_settings);
        settingsItem.setVisible(false);
    }

    // Only show the menu items for sharing a meeting and stats for a meeting, if the selected meeting is finished.
    MeetingFragment meetingFragment = MeetingFragment.lookupMeetingFragment(getSupportFragmentManager());
    boolean meetingIsFinished = meetingFragment != null
            && meetingFragment.getState() == MeetingColumns.State.FINISHED;
    MenuItem menuItem = menu.findItem(R.id.action_share_meeting);
    if (menuItem != null)
        menuItem.setVisible(meetingIsFinished);
    menuItem = menu.findItem(R.id.action_charts_meeting);
    if (menuItem != null)
        menuItem.setVisible(meetingIsFinished);

    // Don't show the global share/stats menu items unless we have at least one meeting
    MeetingsListFragment meetingsListFragment = (MeetingsListFragment) mMainPagerAdapter
            .instantiateItem(mBinding.pager, 0);
    boolean hasMeetings = meetingsListFragment != null && meetingsListFragment.hasMeetings();
    menu.findItem(R.id.action_share).setVisible(hasMeetings);
    menu.findItem(R.id.action_charts).setVisible(hasMeetings);
    menuItem = menu.findItem(R.id.action_share_submenu);
    if (menuItem != null)
        menuItem.setVisible(hasMeetings);
    menuItem = menu.findItem(R.id.action_charts_submenu);
    if (menuItem != null)
        menuItem.setVisible(hasMeetings);
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.esri.android.rt.map.PopupFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {

    // Turn on/off menu items based on popup's edit capabilities
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (mPopupContainer != null) {
            Popup popup = mPopupContainer.getCurrentPopup();
            if (popup != null) {
                if (popup.isEditMode()) {
                    if (item.getItemId() == R.id.menu_save || item.getItemId() == R.id.menu_camera) {
                        item.setVisible(true);
                        item.setEnabled(true);
                    } else {
                        item.setVisible(false);
                        item.setEnabled(false);
                    }/*from   w  w  w.j a  v a2 s.c o  m*/
                } else {
                    if (((item.getItemId() == R.id.menu_edit) && (popup.isEditable()))
                            || ((item.getItemId() == R.id.menu_delete) && (popup.isDeletable()))) {
                        item.setVisible(true);
                        item.setEnabled(true);
                    } else {
                        item.setVisible(false);
                        item.setEnabled(false);
                    }
                }
            } else {
                item.setVisible(false);
                item.setEnabled(false);
            }
        } else {
            item.setVisible(false);
            item.setEnabled(false);
        }
    }
}

From source file:com.btmura.android.reddit.app.NavigationFragment.java

private void prepareAboutItem(Menu menu, boolean visible) {
    MenuItem item = menu.findItem(R.id.menu_subreddit);
    item.setVisible(visible);
    if (visible) {
        item.setTitle(getString(R.string.menu_subreddit, getFirstCheckedSubreddit()));
    }/*from ww  w.j  av a 2s.  c  o m*/
}

From source file:es.uniovi.imovil.fcrtrainer.BaseExerciseFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.game_control, menu);
    MenuItem item = menu.findItem(R.id.action_change_game_mode);
    try {/* w w  w  .j a va  2 s.co  m*/
        MainActivity activity = (MainActivity) getActivity();
        if (item != null && activity != null) {
            item.setVisible(!activity.isDrawerOpen());
        }
    } catch (ClassCastException ex) {
        // El fragmento est incrustado en una actividad distinta a
        // MainActivity. No se hace nada
    }

    MenuItem setup = menu.findItem(R.id.action_settings);
    if (mIsPlaying) {
        item.setIcon(R.drawable.ic_action_stop);
        setup.setVisible(false);
    } else {
        item.setIcon(R.drawable.ic_action_play);
        setup.setVisible(true);
    }
}

From source file:com.numix.calculator.Calculator.java

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

    MenuItem mMatrixPanel = menu.findItem(R.id.matrix);
    if (mMatrixPanel != null)
        mMatrixPanel.setVisible(!getMatrixVisibility() && CalculatorSettings.matrixPanel(getContext()));

    MenuItem mGraphPanel = menu.findItem(R.id.graph);
    if (mGraphPanel != null)
        mGraphPanel.setVisible(!getGraphVisibility() && CalculatorSettings.graphPanel(getContext()));

    MenuItem mFunctionPanel = menu.findItem(R.id.function);
    if (mFunctionPanel != null)
        mFunctionPanel.setVisible(!getFunctionVisibility() && CalculatorSettings.functionPanel(getContext()));

    MenuItem mBasicPanel = menu.findItem(R.id.basic);
    if (mBasicPanel != null)
        mBasicPanel.setVisible(!getBasicVisibility() && CalculatorSettings.basicPanel(getContext()));

    MenuItem mAdvancedPanel = menu.findItem(R.id.advanced);
    if (mAdvancedPanel != null)
        mAdvancedPanel.setVisible(!getAdvancedVisibility() && CalculatorSettings.advancedPanel(getContext()));

    MenuItem mHexPanel = menu.findItem(R.id.hex);
    if (mHexPanel != null)
        mHexPanel.setVisible(!getHexVisibility() && CalculatorSettings.hexPanel(getContext()));

    return true;//from w  w  w  .ja v a2  s  .c  o m
}

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

/**
 * {@inheritDoc}// w ww  .  jav a  2  s .  c  o m
 */
@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    if (mContainerActivity.getStorageManager() != null && getFile() != null) {
        // Update the file
        setFile(mContainerActivity.getStorageManager().getFileById(getFile().getFileId()));

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

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

    // additional restriction for this fragment 
    // TODO allow refresh file in PreviewImageFragment
    item = menu.findItem(R.id.action_sync_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);
    }

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

}