List of usage examples for android.view MenuItem setVisible
public MenuItem setVisible(boolean visible);
From source file:com.dwdesign.tweetings.activity.HomeActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { final boolean bottom_actions = mPreferences.getBoolean(PREFERENCE_KEY_COMPOSE_BUTTON, false); final boolean leftside_compose_button = mPreferences.getBoolean(PREFERENCE_KEY_LEFTSIDE_COMPOSE_BUTTON, false);//from w w w .j a va2 s .c o m int icon = R.drawable.ic_menu_tweet, title = R.string.compose; if (mViewPager != null && mAdapter != null) { final int position = mViewPager.getCurrentItem(); int messagesPosition = TAB_POSITION_MESSAGES; if (mShowHomeTab == false) { messagesPosition--; } if (mShowMentionsTab == false) { messagesPosition--; } if (position == mAdapter.getCount() - 1 && mShowAccountsTab) { icon = R.drawable.ic_menu_add; title = R.string.add_account; } else { title = R.string.compose; if (mShowMessagesTab && position == messagesPosition) { icon = R.drawable.ic_menu_compose; } else { icon = R.drawable.ic_menu_tweet; } } final MenuItem composeItem = menu.findItem(MENU_COMPOSE); if (composeItem != null) { composeItem.setIcon(icon); composeItem.setTitle(title); composeItem.setVisible(!bottom_actions && mViewPager.getVisibility() == View.VISIBLE); } if (mComposeButton != null) { mComposeButton.setImageResource(icon); mComposeButton.setVisibility( bottom_actions && mViewPager.getVisibility() == View.VISIBLE ? View.VISIBLE : View.GONE); if (bottom_actions) { final FrameLayout.LayoutParams compose_lp = (FrameLayout.LayoutParams) mComposeButton .getLayoutParams(); compose_lp.gravity = Gravity.BOTTOM | (leftside_compose_button ? Gravity.LEFT : Gravity.RIGHT); mComposeButton.setLayoutParams(compose_lp); } } } return super.onPrepareOptionsMenu(menu); }
From source file:com.google.samples.apps.iosched.ui.SessionDetailFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.session_detail, menu); mSocialStreamMenuItem = menu.findItem(R.id.menu_social_stream); mShareMenuItem = menu.findItem(R.id.menu_share); MenuItem twitterShare = menu.findItem(R.id.menu_twitter); twitterShare.setVisible(PackageHelper.twitterInstalled(getActivity())); tryExecuteDeferredUiOperations();//w w w . j a v a 2 s .c o m }
From source file:org.andstatus.app.msg.TimelineActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MyAccount ma = MyContextHolder.get().persistentAccounts().getCurrentAccount(); boolean enableReload = isTimelineCombined() || ma.isValidAndSucceeded(); MenuItem item = menu.findItem(R.id.reload_menu_item); item.setEnabled(enableReload);/*from w ww. j a v a 2s . c om*/ item.setVisible(enableReload); prepareDrawer(); if (mContextMenu != null) { mContextMenu.setAccountUserIdToActAs(0); } if (mMessageEditor != null) { mMessageEditor.onPrepareOptionsMenu(menu); } boolean enableGlobalSearch = MyContextHolder.get().persistentAccounts().isGlobalSearchSupported(ma, isTimelineCombined()); item = menu.findItem(R.id.global_search_menu_id); item.setEnabled(enableGlobalSearch); item.setVisible(enableGlobalSearch); return super.onPrepareOptionsMenu(menu); }
From source file:de.vanita5.twittnuker.fragment.support.UserListFragment.java
@Override public void onPrepareOptionsMenu(Menu menu) { final AsyncTwitterWrapper twitter = getTwitterWrapper(); final ParcelableUserList userList = mUserList; final MenuItem followItem = menu.findItem(MENU_FOLLOW); if (followItem != null) { followItem.setEnabled(userList != null); if (userList == null) { followItem.setIcon(android.R.color.transparent); }//from w ww . j av a2 s. c o m } if (twitter == null || userList == null) return; final boolean isMyList = userList.user_id == userList.account_id; setMenuItemAvailability(menu, MENU_EDIT, isMyList); setMenuItemAvailability(menu, MENU_ADD, isMyList); setMenuItemAvailability(menu, MENU_DELETE, isMyList); final boolean isFollowing = userList.is_following; if (followItem != null) { followItem.setVisible(!isMyList); if (isFollowing) { followItem.setIcon(R.drawable.ic_action_cancel); followItem.setTitle(R.string.unsubscribe); } else { followItem.setIcon(R.drawable.ic_action_add); followItem.setTitle(R.string.subscribe); } } }
From source file:org.cm.podd.report.activity.HomeActivity.java
private void updateRecordMenu() { Menu menu = navigationView.getMenu(); MenuItem menuItem = menu.getItem(0); menuItem.getSubMenu().clear();//from www .j ava 2 s . com int cnt = 0; for (RecordSpec record : recordSpecDataSource.findRootRecords()) { menuItem.getSubMenu().add(0, (int) record.id, cnt, record.name); cnt++; } if (cnt == 0) { menuItem.setVisible(false); } else { menuItem.setVisible(true); } navigationView.invalidate(); mDrawerLayout.invalidate(); }
From source file:com.android.contacts.activities.ContactDetailActivity.java
public void setAssociationMenu(Menu menu, boolean fromOptionsMenu) { if (fromOptionsMenu) { MenuItem associationMenuItem = menu.findItem(R.id.menu_association_sim); if (associationMenuItem != null) { /*//ww w.j ava 2 s . com * Bug Fix by Mediatek Begin. * Original Android's code: * if (isHasPhoneItem()) { * CR ID: ALPS00116397 */ if (SlotUtils.isGeminiEnabled() && isHasPhoneItem() && !isMe()) { /* * Bug Fix by Mediatek End. */ int simInfoSize = SIMInfoWrapper.getDefault().getInsertedSimCount(); associationMenuItem.setVisible(!this.mContactData.isDirectoryEntry()); associationMenuItem.setEnabled(simInfoSize > 0); } else { associationMenuItem.setVisible(false); } } } }
From source file:net.sourceforge.servestream.activity.MediaPlayerActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); updateVolumeBar();//from w w w . ja va 2 s.c o m if (Build.VERSION.SDK_INT >= 9) { // Don't offer the audio effects display when running on an OS // before API level 9 because it relies on the getAudioSessionId method, // which isn't available until after API 8 if (menu.findItem(EFFECTS_PANEL) == null) { Intent i = new Intent("android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL"); if (getPackageManager().resolveActivity(i, 0) != null) { menu.add(0, EFFECTS_PANEL, 0, R.string.list_menu_effects).setIcon(R.drawable.ic_menu_eq); } } else { MenuItem item = menu.findItem(EFFECTS_PANEL); if (item != null) { if (MusicUtils.getCurrentAudioId() >= 0) { item.setVisible(true); } else { item.setVisible(false); } } } } return true; }
From source file:com.nononsenseapps.notepad.MainActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { // Hide entire sub menu in editor. if (currentContent == CONTENTVIEW.RIGHT) { MenuItem manageLists = menu.findItem(R.id.menu_managelists); if (manageLists != null) manageLists.setVisible(false); MenuItem clear = menu.findItem(R.id.menu_clearcompleted); if (clear != null) clear.setVisible(false);/*from w w w . java 2 s .c o m*/ MenuItem sync = menu.findItem(R.id.menu_sync); if (sync != null) sync.setVisible(false); } else { MenuItem deleteList = menu.findItem(R.id.menu_deletelist); MenuItem renameList = menu.findItem(R.id.menu_renamelist); MenuItem setDefaultList = menu.findItem(R.id.menu_setdefaultlist); if (null != mSectionAdapter) { if (deleteList != null) { // Only show this button if there is a list if (mSectionAdapter.getCount() <= 0) { deleteList.setVisible(false); } else { deleteList.setVisible(true); } } if (renameList != null) { // Only show this button if there is a list if (mSectionAdapter.getCount() <= 0) { renameList.setVisible(false); } else { renameList.setVisible(true); } } if (setDefaultList != null) { // Only show this button if there is a list if (mSectionAdapter.getCount() <= 0) { setDefaultList.setVisible(false); } else { setDefaultList.setVisible(true); } } } else { // with null adapter, must hide if (deleteList != null) { deleteList.setVisible(false); } if (renameList != null) { renameList.setVisible(false); } if (setDefaultList != null) setDefaultList.setVisible(false); } } return super.onPrepareOptionsMenu(menu); }
From source file:com.chris.ni.omw.ContactsListFragment.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override/*from w w w . j a v a 2 s . c om*/ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); // Inflate the menu items inflater.inflate(R.menu.contact_list_menu, menu); // Locate the search item MenuItem searchItem = menu.findItem(R.id.menu_search); // In versions prior to Android 3.0, hides the search item to prevent additional // searches. In Android 3.0 and later, searching is done via a SearchView in the ActionBar. // Since the search doesn't create a new Activity to do the searching, the menu item // doesn't need to be turned off. 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) searchItem.getActionView(); // 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, ContactsListFragment.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, ContactsListFragment.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:com.example.angelina.travelapp.map.MapFragment.java
/** * Set the menu options based on/*from w ww . ja v a 2 s . c o m*/ * the bottom sheet state * */ @Override public final void onPrepareOptionsMenu(final Menu menu) { final MenuItem listItem = menu.findItem(R.id.list_action); final MenuItem routeItem = menu.findItem(R.id.route_action); final MenuItem directionItem = menu.findItem(R.id.walking_directions); final MenuItem filterItem = menu.findItem(R.id.filter_in_map); if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) { listItem.setVisible(true); filterItem.setVisible(true); routeItem.setVisible(false); } else if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) { listItem.setVisible(false); filterItem.setVisible(true); routeItem.setVisible(true); } }