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:au.org.intersect.faims.android.ui.activity.ShowModuleActivity.java

public boolean onPrepareOptionsMenu(Menu menu) {
    // gps status
    menu.findItem(R.id.action_gps_inactive).setVisible(false);
    menu.findItem(R.id.action_gps_active_has_signal).setVisible(false);
    menu.findItem(R.id.action_gps_active_no_signal).setVisible(false);
    if (gpsDataManager.isExternalGPSStarted() || gpsDataManager.isInternalGPSStarted()) {
        if (gpsDataManager.hasValidExternalGPSSignal() || gpsDataManager.hasValidInternalGPSSignal()) {
            menu.findItem(R.id.action_gps_active_has_signal).setVisible(true);
        } else {/*from w w w  . java 2 s  .  c  o  m*/
            menu.findItem(R.id.action_gps_active_no_signal).setVisible(true);
        }
    } else {
        menu.findItem(R.id.action_gps_inactive).setVisible(true);
    }

    // tracker status
    menu.findItem(R.id.action_tracker_active_no_gps).setVisible(false);
    menu.findItem(R.id.action_tracker_active_has_gps).setVisible(false);
    menu.findItem(R.id.action_tracker_inactive).setVisible(false);
    if (gpsDataManager.isTrackingStarted()) {
        if (gpsDataManager.hasValidExternalGPSSignal() || gpsDataManager.hasValidInternalGPSSignal()) {
            menu.findItem(R.id.action_tracker_active_has_gps).setVisible(true);
        } else {
            menu.findItem(R.id.action_tracker_active_no_gps).setVisible(true);
        }
    } else {
        menu.findItem(R.id.action_tracker_inactive).setVisible(true);
    }

    // sync status
    menu.findItem(R.id.action_sync).setVisible(false);
    menu.findItem(R.id.action_sync_active).setVisible(false);
    menu.findItem(R.id.action_sync_error).setVisible(false);
    menu.findItem(R.id.action_sync_has_changes).setVisible(false);
    menu.findItem(R.id.action_sync_inactive).setVisible(false);

    syncAnimImage.clearAnimation();

    switch (syncStatus) {
    case ACTIVE_SYNCING:
        MenuItem syncItem = menu.findItem(R.id.action_sync_active).setVisible(true);

        syncAnimImage.startAnimation(rotation);

        syncItem.setActionView(syncAnimImage);

        break;
    case ERROR:
        menu.findItem(R.id.action_sync_error).setVisible(true);
        break;
    case ACTIVE_NO_CHANGES:
        menu.findItem(R.id.action_sync).setVisible(true);
        break;
    case ACTIVE_HAS_CHANGES:
        menu.findItem(R.id.action_sync_has_changes).setVisible(true);
        break;
    default:
        menu.findItem(R.id.action_sync_inactive).setVisible(true);
        break;
    }

    // follow status
    MenuItem distance_text = menu.findItem(R.id.distance_text);
    distance_text.setVisible(pathIndicatorVisible);
    String distanceInfo = pathIndex < 0 ? "" : " to point (" + pathIndex + "/" + pathLength + ")";
    if (pathDistance > 1000) {
        distance_text.setTitle(
                MeasurementUtil.displayAsKiloMeters(pathDistance / 1000, "###,###,###,###.0") + distanceInfo);
    } else {
        distance_text.setTitle(MeasurementUtil.displayAsMeters(pathDistance, "###,###,###,###") + distanceInfo);
    }

    MenuItem direction_text = menu.findItem(R.id.direction_text);
    direction_text.setVisible(pathIndicatorVisible);
    direction_text.setTitle(MeasurementUtil.displayAsDegrees(pathBearing, "###"));

    MenuItem direction_indicator = menu.findItem(R.id.direction_indicator);
    direction_indicator.setVisible(pathIndicatorVisible);
    if (pathHeading != null) {
        if (tempBitmap != null) {
            tempBitmap.recycle();
        }
        if (whiteArrow == null) {
            whiteArrow = new BitmapDrawable(getResources(), UnscaledBitmapLoader.decodeResource(getResources(),
                    au.org.intersect.faims.android.R.drawable.white_arrow));
        }
        if (greyArrow == null) {
            greyArrow = new BitmapDrawable(getResources(), UnscaledBitmapLoader.decodeResource(getResources(),
                    au.org.intersect.faims.android.R.drawable.grey_arrow));
        }

        this.tempBitmap = BitmapUtil.rotateBitmap(pathValid ? whiteArrow.getBitmap() : greyArrow.getBitmap(),
                pathBearing - pathHeading);
        direction_indicator.setIcon(new BitmapDrawable(getResources(), tempBitmap));
    } else {
        direction_indicator.setVisible(false);
    }

    return true;
}

From source file:com.github.akinaru.hcidebugger.activity.HciDebuggerActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean ret = super.onPrepareOptionsMenu(menu);
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        toolbar.getMenu().findItem(R.id.scan_btn).setVisible(false);
        toolbar.getMenu().findItem(R.id.state_bt_btn).setVisible(false);
        toolbar.getMenu().findItem(R.id.reset_snoop_file).setVisible(false);
        nvDrawer.getMenu().findItem(R.id.scan_btn_nv).setVisible(true);

        if (mScanType == ScanType.CLASSIC_SCAN) {
            nvDrawer.getMenu().findItem(R.id.change_settings)
                    .setTitle(getString(R.string.scan_settings_type_classic_scan));
        } else {/*w  ww.j  a va  2  s.  c  o m*/
            nvDrawer.getMenu().findItem(R.id.change_settings)
                    .setTitle(getString(R.string.scan_settings_type_ble_scan));
        }
        if (Build.VERSION.SDK_INT <= 22) {
            nvDrawer.getMenu().findItem(R.id.reset_snoop_file_nv).setVisible(true);
        }
        MenuItem stateBtn = nvDrawer.getMenu().findItem(R.id.state_bt_btn_nv);
        stateBtn.setVisible(true);
        if (mBluetoothAdapter.isEnabled()) {
            stateBtn.setIcon(R.drawable.ic_bluetooth);
        } else {
            stateBtn.setIcon(R.drawable.ic_bluetooth_disabled);
        }
        stateBtn.setTitle(getResources().getString(R.string.menu_item_title_enable_bluetooth_portrait));

    }
    return ret;
}

From source file:de.enlightened.peris.CategoriesFragment.java

public final void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    final String serverUserId = this.application.getSession().getServer().serverUserId;
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;

    this.clickedTopicItem = (TopicItem) CategoriesFragment.this.getListView().getItemAtPosition(info.position);

    if (serverUserId == null) {
        return;/*from  w ww  .jav  a2s .c om*/
    }
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.setHeaderTitle(this.clickedTopicItem.getHeading());
    final MenuInflater inflater = this.activity.getMenuInflater();

    inflater.inflate(R.menu.categories_context, menu);

    final MenuItem ubsubItem = menu.findItem(R.id.categories_unsubscribe);
    final MenuItem subItem = menu.findItem(R.id.categories_subscribe);
    final MenuItem stickyItem = menu.findItem(R.id.categories_context_sticky);
    final MenuItem lockItem = menu.findItem(R.id.categories_context_lock);
    final MenuItem deleteItem = menu.findItem(R.id.categories_context_delete);

    final MenuItem subscribeItem = menu.findItem(R.id.categories_add_favorite);
    final MenuItem unsubscribeItem = menu.findItem(R.id.categories_remove_favorite);

    if (this.clickedTopicItem instanceof Category) {
        final Category category = (Category) this.clickedTopicItem;
        ubsubItem.setVisible(false);
        subItem.setVisible(false);
        stickyItem.setVisible(false);
        lockItem.setVisible(false);
        deleteItem.setVisible(false);

        if (category.isCanSubscribe()) {
            subscribeItem.setVisible(true);
        } else {
            subscribeItem.setVisible(false);
        }

        if (category.isSubscribed()) {
            unsubscribeItem.setVisible(true);
            subscribeItem.setVisible(false);
        } else {
            unsubscribeItem.setVisible(false);
        }
    } else {
        final Topic topic = (Topic) this.clickedTopicItem;

        unsubscribeItem.setVisible(false);
        subscribeItem.setVisible(false);

        if (topic.isCanStick()) {
            stickyItem.setVisible(true);

            if (Topic.Type.Sticky == topic.getType()) {
                stickyItem.setTitle("Unstick Topic");
            } else {
                stickyItem.setTitle("Stick Topic");
            }
        } else {
            stickyItem.setVisible(false);
        }

        if (topic.isCanDelete()) {
            deleteItem.setVisible(true);
        } else {
            deleteItem.setVisible(false);
        }

        if (topic.isCanClose()) {
            lockItem.setVisible(true);

            if (topic.isClosed()) {
                lockItem.setTitle("Unlock Topic");
            } else {
                lockItem.setTitle("Lock Topic");
            }
        } else {
            lockItem.setVisible(false);
        }

        if (this.subforumId.contentEquals("favs")) {
            ubsubItem.setVisible(true);
            subItem.setVisible(false);
        } else {
            ubsubItem.setVisible(false);
            subItem.setVisible(true);
        }
    }
}

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

    // 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 == session.studentIndex)
                item.setEnabled(false);/*from www  .  ja v  a2s  .  c o  m*/

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

    return super.onCreateOptionsMenu(menu);
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

@Override
public boolean onCreateOptionsMenu(@NotNull final Menu menu) {
    MenuInflater inflater = getMenuInflater();
    if (m_app.isDarkActionbar()) {
        inflater.inflate(R.menu.main, menu);
    } else {/*from   w w w.  j  a  v a 2s .  com*/
        inflater.inflate(R.menu.main_light, menu);
    }

    if (!m_app.fileStoreCanSync()) {
        MenuItem mItem = menu.findItem(R.id.sync);
        mItem.setVisible(false);
    }
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    searchView.setIconifiedByDefault(false);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        public boolean m_ignoreSearchChangeCallback;

        @Override
        public boolean onQueryTextSubmit(String query) {
            // Stupid searchview code will call onQueryTextChange callback
            // When the actionView collapse and the textview is reset
            // ugly global hack around this
            m_ignoreSearchChangeCallback = true;
            menu.findItem(R.id.search).collapseActionView();
            m_ignoreSearchChangeCallback = false;
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!m_ignoreSearchChangeCallback) {
                if (mFilter == null) {
                    mFilter = new ActiveFilter();
                }
                mFilter.setSearch(newText);
                mFilter.saveInPrefs(TodoApplication.getPrefs());
                if (m_adapter != null) {
                    m_adapter.setFilteredTasks();
                }
            }
            return true;
        }
    });
    this.options_menu = menu;
    return super.onCreateOptionsMenu(menu);
}

From source file:org.cobaltians.cobalt.activities.CobaltActivity.java

protected void addMenuItem(Menu menu, int order, JSONObject action, final int id, String position,
        String barsColor) {/*from   www.ja  v a 2s .c om*/
    try {
        final String name = action.getString(Cobalt.kActionName);
        String title = action.getString(Cobalt.kActionTitle);
        boolean visible = action.optBoolean(Cobalt.kActionVisible, true);
        boolean enabled = action.optBoolean(Cobalt.kActionEnabled, true);

        final MenuItem menuItem = menu.add(Menu.NONE, id, order, title);

        int showAsAction = MenuItemCompat.SHOW_AS_ACTION_IF_ROOM;
        switch (position) {
        case Cobalt.kPositionBottom:
            showAsAction = MenuItemCompat.SHOW_AS_ACTION_ALWAYS;
            break;
        case Cobalt.kPositionOverflow:
            showAsAction = MenuItemCompat.SHOW_AS_ACTION_NEVER;
            break;
        }
        MenuItemCompat.setShowAsAction(menuItem, showAsAction);

        ActionViewMenuItem actionView = new ActionViewMenuItem(this, action, barsColor);
        actionView.setActionViewMenuItemListener(new WeakReference<>(this));

        MenuItemCompat.setActionView(menuItem, actionView);
        menuItem.setVisible(visible);
        menuItem.setEnabled(enabled);
        mMenuItemsHashMap.put(name, actionView);
        //need this next hashmap to send onPressed when item is on overflow
        mMenuItemsIdMap.put(id, name);
        //need this next hashmap to set menuItem
        mMenuItemByNameMap.put(name, menuItem);
    } catch (JSONException exception) {
        if (Cobalt.DEBUG) {
            Log.w(Cobalt.TAG,
                    TAG + "addMenuItem: action " + action.toString() + " format not supported, use at least {\n"
                            + "\tname: \"name\",\n" + "\ttitle: \"title\",\n" + "}");
        }

        exception.printStackTrace();
    }
}

From source file:com.ichi2.anki.StudyOptionsFragment.java

@Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_undo:
        Timber.i("StudyOptionsFragment:: Undo button pressed");
        getCol().undo();/*  w  w w  . j  av a 2  s.c o  m*/
        openReviewer();
        return true;
    case R.id.action_deck_options:
        Timber.i("StudyOptionsFragment:: Deck options button pressed");
        if (getCol().getDecks().isDyn(getCol().getDecks().selected())) {
            openFilteredDeckOptions();
        } else {
            Intent i = new Intent(getActivity(), DeckOptions.class);
            startActivityForResult(i, DECK_OPTIONS);
            ActivityTransitionAnimation.slide(getActivity(), ActivityTransitionAnimation.FADE);
        }
        return true;
    case R.id.action_custom_study:
        Timber.i("StudyOptionsFragment:: custom study button pressed");
        showCustomStudyContextMenu();
        return true;
    case R.id.action_unbury:
        Timber.i("StudyOptionsFragment:: unbury button pressed");
        getCol().getSched().unburyCardsForDeck();
        refreshInterfaceAndDecklist(true);
        item.setVisible(false);
        return true;
    case R.id.action_rebuild:
        Timber.i("StudyOptionsFragment:: rebuild cram deck button pressed");
        mProgressDialog = StyledProgressDialog.show(getActivity(), "",
                getResources().getString(R.string.rebuild_cram_deck), true);
        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_REBUILD_CRAM, getDeckTaskListener(true),
                new DeckTask.TaskData(mFragmented));
        return true;
    case R.id.action_empty:
        Timber.i("StudyOptionsFragment:: empty cram deck button pressed");
        mProgressDialog = StyledProgressDialog.show(getActivity(), "",
                getResources().getString(R.string.empty_cram_deck), false);
        DeckTask.launchDeckTask(DeckTask.TASK_TYPE_EMPTY_CRAM, getDeckTaskListener(true),
                new DeckTask.TaskData(mFragmented));
        return true;
    case R.id.action_rename:
        ((DeckPicker) getActivity()).renameDeckDialog(getCol().getDecks().selected());
        return true;
    case R.id.action_delete:
        ((DeckPicker) getActivity()).confirmDeckDeletion(getCol().getDecks().selected());
        return true;
    case R.id.action_export:
        ((DeckPicker) getActivity()).exportDeck(getCol().getDecks().selected());
        return true;
    default:
        return false;
    }
}

From source file:com.dsdar.thosearoundme.TeamViewActivity.java

/**
 * Method to get users team information and design action bar accordingly
 */// w w  w  .  java 2  s  .  c o  m

@Override
public boolean onCreateOptionsMenu(Menu theMenu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_teamview_menu, theMenu);

    MenuItem myItem = theMenu.findItem(R.id.invitations);
    MenuItem team = theMenu.findItem(R.id.myTeams);
    int invite_cnt = 0;
    if (MyAppConstants.INVITATION_CNT == -1) {
        invite_cnt = 0;
    } else {
        invite_cnt = MyAppConstants.INVITATION_CNT;
    }

    myItem.setTitle(myItem.getTitle() + "(" + invite_cnt + ")");
    if (intSupported == 0) {
        itsAddTeam.setVisibility(View.INVISIBLE);
        team.setVisible(false);
    } else {
        itsAddTeam.setVisibility(View.VISIBLE);
        team.setVisible(true);
    }
    // MenuItem myItem1 = theMenu.findItem(R.id.myFollowers);
    // myItem1.setTitle(myItem1.getTitle() + "("
    // + MyAppConstants.FOLLOWERS_CNT + ")");
    // TextView txtInviteCnt = (TextView) findViewById(R.id.invitations);
    // txtInviteCnt.setText("(" + MyAppConstants.INVITATION_CNT + ")");
    //
    // TextView txtFolowersCnt = (TextView) findViewById(R.id.myFollowers);
    // txtFolowersCnt.setText("(" + MyAppConstants.FOLLOWERS_CNT + ")");

    return super.onCreateOptionsMenu(theMenu);
}

From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java

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

    final FragmentManager fm = getFragmentManager();

    final RootInfo root = getCurrentRoot();
    final DocumentInfo cwd = getCurrentDirectory();

    final MenuItem createDir = menu.findItem(R.id.menu_create_dir);
    final MenuItem search = menu.findItem(R.id.menu_search);
    final MenuItem sort = menu.findItem(R.id.menu_sort);
    final MenuItem sortSize = menu.findItem(R.id.menu_sort_size);
    final MenuItem grid = menu.findItem(R.id.menu_grid);
    final MenuItem list = menu.findItem(R.id.menu_list);
    final MenuItem settings = menu.findItem(R.id.menu_settings);

    // Open drawer means we hide most actions
    if (isRootsDrawerOpen()) {
        createDir.setVisible(false);
        search.setVisible(false);//from  w w w. j  a v a  2 s .co  m
        sort.setVisible(false);
        grid.setVisible(false);
        list.setVisible(false);
        mIgnoreNextCollapse = true;
        search.collapseActionView();
        return true;
    }

    sort.setVisible(cwd != null);
    grid.setVisible(mState.derivedMode != MODE_GRID);
    list.setVisible(mState.derivedMode != MODE_LIST);

    if (mState.currentSearch != null) {
        // Search uses backend ranking; no sorting
        sort.setVisible(false);

        search.expandActionView();

        mSearchView.setIconified(false);
        mSearchView.clearFocus();
        mSearchView.setQuery(mState.currentSearch, false);
    } else {
        mIgnoreNextClose = true;
        mSearchView.setIconified(true);
        mSearchView.clearFocus();

        mIgnoreNextCollapse = true;
        search.collapseActionView();
    }

    // Only sort by size when visible
    sortSize.setVisible(mState.showSize);

    final boolean searchVisible;
    if (mState.action == ACTION_CREATE) {
        createDir.setVisible(cwd != null && cwd.isCreateSupported());
        searchVisible = false;

        // No display options in recent directories
        if (cwd == null) {
            grid.setVisible(false);
            list.setVisible(false);
        }

        SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported());
    } else {
        createDir.setVisible(false);

        searchVisible = root != null && ((root.flags & Root.FLAG_SUPPORTS_SEARCH) != 0);
    }

    // TODO: close any search in-progress when hiding
    search.setVisible(searchVisible);

    settings.setVisible(mState.action != ACTION_MANAGE);

    return true;
}

From source file:com.android.contacts.activities.PeopleActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    mOptionsMenuContactsAvailable = areContactsAvailable();
    if (!mOptionsMenuContactsAvailable) {
        return false;
    }/*from  w  w  w  .  java2 s.c  o  m*/

    // Get references to individual menu items in the menu
    final MenuItem contactsFilterMenu = menu.findItem(R.id.menu_contacts_filter);
    final MenuItem clearFrequentsMenu = menu.findItem(R.id.menu_clear_frequents);
    final MenuItem helpMenu = menu.findItem(R.id.menu_help);

    final boolean isSearchOrSelectionMode = mActionBarAdapter.isSearchMode()
            || mActionBarAdapter.isSelectionMode();
    if (isSearchOrSelectionMode) {
        contactsFilterMenu.setVisible(false);
        clearFrequentsMenu.setVisible(false);
        helpMenu.setVisible(false);
    } else {
        switch (getTabPositionForTextDirection(mActionBarAdapter.getCurrentTab())) {
        case TabState.FAVORITES:
            contactsFilterMenu.setVisible(false);
            clearFrequentsMenu.setVisible(hasFrequents());
            break;
        case TabState.ALL:
            contactsFilterMenu.setVisible(true);
            clearFrequentsMenu.setVisible(false);
            break;
        }
        helpMenu.setVisible(HelpUtils.isHelpAndFeedbackAvailable());
    }
    final boolean showMiscOptions = !isSearchOrSelectionMode;
    final boolean showBlockedNumbers = PhoneCapabilityTester.isPhone(this) && ContactsUtils.FLAG_N_FEATURE
            && BlockedNumberContractCompat.canCurrentUserBlockNumbers(this);
    makeMenuItemVisible(menu, R.id.menu_search, showMiscOptions);
    makeMenuItemVisible(menu, R.id.menu_import_export, showMiscOptions);
    makeMenuItemVisible(menu, R.id.menu_accounts, showMiscOptions);
    makeMenuItemVisible(menu, R.id.menu_blocked_numbers, showMiscOptions && showBlockedNumbers);
    makeMenuItemVisible(menu, R.id.menu_settings, showMiscOptions && !ContactsPreferenceActivity.isEmpty(this));

    final boolean showSelectedContactOptions = mActionBarAdapter.isSelectionMode()
            && mAllFragment.getSelectedContactIds().size() != 0;
    makeMenuItemVisible(menu, R.id.menu_share, showSelectedContactOptions);
    makeMenuItemVisible(menu, R.id.menu_delete, showSelectedContactOptions);
    final boolean showLinkContactsOptions = mActionBarAdapter.isSelectionMode()
            && mAllFragment.getSelectedContactIds().size() > 1;
    makeMenuItemVisible(menu, R.id.menu_join, showLinkContactsOptions);

    // Debug options need to be visible even in search mode.
    makeMenuItemVisible(menu, R.id.export_database, mEnableDebugMenuOptions && hasExportIntentHandler());

    return true;
}