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:org.getlantern.firetweet.fragment.support.MessagesConversationFragment.java

private void showMenu(final View view, final ParcelableDirectMessage dm) {
    if (mPopupMenu != null) {
        mPopupMenu.dismiss();/*  ww w. ja  v  a2  s.  c o m*/
    }
    final Context context = getActivity();
    mPopupMenu = new PopupMenu(context, view);
    mPopupMenu.inflate(R.menu.action_direct_message);
    final Menu menu = mPopupMenu.getMenu();
    final MenuItem view_profile_item = menu.findItem(MENU_VIEW_PROFILE);
    if (view_profile_item != null && dm != null) {
        view_profile_item.setVisible(dm.account_id != dm.sender_id);
    }
    mPopupMenu.setOnMenuItemClickListener(this);
    mPopupMenu.show();
}

From source file:com.battlelancer.seriesguide.ui.OverviewFragment.java

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

    // If no episode is visible, hide actions related to the episode
    boolean isEpisodeVisible = mCurrentEpisodeCursor != null && mCurrentEpisodeCursor.moveToFirst();

    // enable/disable menu items
    MenuItem itemShare = menu.findItem(R.id.menu_overview_share);
    itemShare.setEnabled(isEpisodeVisible);
    itemShare.setVisible(isEpisodeVisible);
    MenuItem itemCalendar = menu.findItem(R.id.menu_overview_calendar);
    itemCalendar.setEnabled(isEpisodeVisible);
    itemCalendar.setVisible(isEpisodeVisible);
    MenuItem itemManageLists = menu.findItem(R.id.menu_overview_manage_lists);
    if (itemManageLists != null) {
        itemManageLists.setEnabled(isEpisodeVisible);
        itemManageLists.setVisible(isEpisodeVisible);
    }//from   w w  w  . j  a v a  2s  .c  om
}

From source file:comingle.dragracing.TrackActivity.java

public void setMenuItemVisibility(int id, boolean visible) {
    if (options_menu == null) {
        String msg = "Option menu is null";
        Log.e(TAG, msg);//from www  . j  a v  a2s  .c o  m
        // postToast(msg);
        return;
    }
    MenuItem item = options_menu.findItem(id);
    if (item != null) {
        item.setVisible(visible);
    } else {
        String msg = "Failed to find item " + id;
        Log.e(TAG, msg);
        // postToast(msg);
    }
}

From source file:com.filterdevice.ProfileScanningFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();/*from   www. ja  va  2s. c o m*/
    inflater.inflate(R.menu.global, menu);
    final EditText mEditText = (EditText) menu.findItem(R.id.search).getActionView();
    mEditText.addTextChangedListener(textWatcher);

    MenuItem pairCache = menu.findItem(R.id.pairing);
    if (Utils.getBooleanSharedPreference(getActivity(), Constants.PREF_PAIR_CACHE_STATUS)) {
        pairCache.setChecked(true);
    } else {
        pairCache.setChecked(false);
    }

    MenuItem mSearch = menu.findItem(R.id.search);
    mSearch.setVisible(true);
    mSearch.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // Do something when collapsed
            View view = getActivity().getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            Logger.e("Collapsed");
            return true; // Return true to collapse action view
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            Logger.e("Expanded");
            mEditText.requestFocus();
            View view = getActivity().getCurrentFocus();
            if (view != null) {
                InputMethodManager inputManager = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
            }
            return true; // Return true to expand action view
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:learn2crack.activities.WnContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override//ww w.j  av a  2s  .co m
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem searchItem = menu.findItem(R.id.action_search);

    if (mIsSearchResultView) {
        searchItem.setVisible(false);
    }

    // In version 3.0 and later, sets up and configures the ActionBar SearchView
    if (Utils.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        //final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        //toolbar.setNavigationContentDescription(new Toolbar.On);
        //searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Updates
                // the search filter, and restarts the loader to do a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;

                // Restarts the loader. This triggers onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, WnContactsListFragment.this);
                return true;
            }
        });

        if (Utils.hasICS()) {
            // This listener added in ICS
            MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    // Nothing to do when the action item is expanded
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    // When the user collapses the SearchView the current search string is
                    // cleared and the loader restarted.
                    if (!TextUtils.isEmpty(mSearchTerm)) {
                        onSelectionCleared();
                    }
                    mSearchTerm = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, WnContactsListFragment.this);
                    return true;
                }
            });
        }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Utils.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:cz.muni.fi.japanesedictionary.main.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);

    MenuItem noteItem = menu.findItem(R.id.ab_note);
    MenuItem favoriteItem = menu.findItem(R.id.favorite);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    if (searchItem != null) {
        searchItem.setVisible(!drawerOpen);
    }//from   w w  w .j a v a 2  s. c o m

    if (drawerOpen) {
        //is open
        Log.i(LOG_TAG, "Drawer open");
        mNoteVisible = noteItem != null && noteItem.isVisible();
        mFavoriteVisible = favoriteItem != null && favoriteItem.isVisible();
        mSearchVisible = MenuItemCompat.isActionViewExpanded(searchItem);
        if (noteItem != null) {
            noteItem.setVisible(false);
        }
        if (favoriteItem != null) {
            favoriteItem.setVisible(false);
        }
        Log.i(LOG_TAG, "Drawer open - hide search");
        MenuItemCompat.collapseActionView(searchItem);
        if (searchItem != null) {
            searchItem.setVisible(false);
            searchItem.setEnabled(false);
        }

    } else {
        Log.i(LOG_TAG, "Drawer close");
        if (favoriteItem != null) {
            favoriteItem.setVisible(mFavoriteVisible);
        }
        if (noteItem != null) {
            noteItem.setVisible(mNoteVisible);
        }
        if (searchItem != null) {
            searchItem.setVisible(true);
            searchItem.setEnabled(true);
        }
        if (mSearchVisible) {
            Log.i(LOG_TAG, "Drawer close, expand search");
            MenuItemCompat.expandActionView(searchItem);
            mSearchView.setQuery(mCurFilter, false);
        }
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:eu.power_switch.api.taskerplugin.EditActivity.java

private void setPositiveButtonVisibility(boolean isValid) {
    if (getOptionsMenu() != null) {
        MenuItem saveButton = getOptionsMenu().findItem(R.id.twofortyfouram_locale_menu_save);
        saveButton.setEnabled(isValid);//from   w  w  w.  j a  va 2 s.c o  m
        saveButton.setVisible(isValid);

        onPrepareOptionsMenu(getOptionsMenu());
    }
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Configure the SetCopyDestination menu item
 * @param item The menu item for SetCopyDestination
 *///from  w ww . j av  a  2s. c o  m
private void configureSetCopyDestinationMenuItem(final MenuItem item) {
    if (mItem.file != null) {
        item.setVisible(false);
    } else {
        item.setVisible(true);
        item.setChecked(false);
        if (getCopyPrefs().getString(COPY_DESTINATION_PREF_KEY, null) != null) {
            item.setChecked(true);
        }
    }
}

From source file:com.owncloud.android.ui.fragment.OCFileListFragment.java

/**
 * {@inheritDoc}/*from  ww  w .j  av  a  2  s. c o  m*/
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    Bundle args = getArguments();
    boolean allowContextualActions = (args == null) ? true
            : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
    if (allowContextualActions) {
        MenuInflater inflater = getActivity().getMenuInflater();
        inflater.inflate(R.menu.file_actions_menu, menu);
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
        OCFile targetFile = (OCFile) mAdapter.getItem(info.position);

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

        /// TODO break this direct dependency on FileDisplayActivity... if possible
        MenuItem item = menu.findItem(R.id.action_open_file_with);
        FileFragment frag = ((FileDisplayActivity) getActivity()).getSecondFragment();
        if (frag != null && frag instanceof FileDetailFragment
                && frag.getFile().getFileId() == targetFile.getFileId()) {
            item = menu.findItem(R.id.action_see_details);
            if (item != null) {
                item.setVisible(false);
                item.setEnabled(false);
            }
        }
    }
}

From source file:mn.today.TheHubActivity.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    menu.clear();/*from ww w  . j  a v a 2  s . c om*/
    getMenuInflater().inflate(R.menu.menu_the_hub, menu);

    MenuItem newF = menu.findItem(R.id.action_new_flow);
    //        MenuItem deleteAllF = menu.findItem(R.id.action_delete_flows);
    if (menuState.equals(AppConstants.MENU_ITEMS_HIDE)) {
        newF.setVisible(false);
        //            deleteAllF.setVisible(false);
    }
    return super.onCreateOptionsMenu(menu);
}