Java Code Examples for android.view.MenuItem#setVisible()

The following examples show how to use android.view.MenuItem#setVisible() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ModelDetailActivity.java    From Synapse with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    final MenuItem mInterruptItem = menu.findItem(R.id.interrupt);
    final MenuItem mPlayItem = menu.findItem(R.id.play);
    final MenuItem mDeleteItem = menu.findItem(R.id.delete);

    if (mIntentType == IS_TRAINING) {
        mInterruptItem.setVisible(true);
        mDeleteItem.setVisible(false);
        mPlayItem.setVisible(false);
    } else if (mIntentType == IS_TRAINED) {
        mInterruptItem.setVisible(false);
        mDeleteItem.setVisible(true);
        mPlayItem.setVisible(true);
    }

    return super.onPrepareOptionsMenu(menu);
}
 
Example 2
Source File: BaseFragment.java    From microMathematics with GNU General Public License v3.0 6 votes vote down vote up
public void updateModeTitle()
{
    androidx.appcompat.view.ActionMode mode = ((MainActivity) activity).getActionMode();
    if (mode != null)
    {
        final int selected = formulas.getSelectedEquations().size();
        final int total = formulas.getEquationsNumber();
        if (selected == 0)
        {
            mode.setTitle("");
        }
        else
        {
            mode.setTitle(String.valueOf(selected) + "/" + String.valueOf(total));
        }
        Menu m = mode.getMenu();
        if (m != null)
        {
            MenuItem mi = m.findItem(R.id.context_menu_expand);
            if (mi != null)
            {
                mi.setVisible(total > selected);
            }
        }
    }
}
 
Example 3
Source File: RTEditorActivity.java    From memoir with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // configure theme item
    MenuItem item = menu.findItem(R.id.theme);
    item.setTitle(mUseDarkTheme ? R.string.menu_light_theme : R.string.menu_dark_theme);

    // configure split toolbar item
    item = menu.findItem(R.id.split_toolbar);
    item.setTitle(mSplitToolbar ? R.string.menu_single_toolbar : R.string.menu_split_toolbar);

    item = menu.findItem(R.id.editor_activity);
    if (item != null) 
        item.setVisible(false);

    return true;
}
 
Example 4
Source File: HomeActivity.java    From SmsCode with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_home, menu);
    MenuItem faqItem = menu.findItem(R.id.action_home_faq);
    if (mCurrentFragment instanceof FaqFragment) {
        faqItem.setVisible(false);
    } else {
        faqItem.setVisible(true);
    }

    MenuItem ignoreOptimizeItem = menu.findItem(R.id.action_ignore_battery_optimization);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        ignoreOptimizeItem.setVisible(false);
    } else {
        ignoreOptimizeItem.setVisible(true);
    }
    return true;
}
 
Example 5
Source File: main_activity.java    From telegram-sms with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
        MenuItem set_proxy_item = menu.findItem(R.id.set_proxy);
        set_proxy_item.setVisible(false);
    }
    return true;
}
 
Example 6
Source File: ConferenceDetailsActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    final boolean groupChat = mConversation != null && mConversation.isPrivateAndNonAnonymous();
    getMenuInflater().inflate(R.menu.muc_details, menu);
    final MenuItem share = menu.findItem(R.id.action_share);
    share.setVisible(!groupChat);
    return super.onCreateOptionsMenu(menu);
}
 
Example 7
Source File: MainActivity.java    From external-nfc-api with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
	
	for(int i = 0; i < menu.size(); i++) {
		MenuItem item = menu.getItem(i);
		if(item.getItemId() == R.id.action_ndef_format) {
			item.setVisible(ndefFormatable != null);
		} else if(item.getItemId() == R.id.action_ndef_write) {
			item.setVisible(ndef != null);
		}
	}
	
	return super.onPrepareOptionsMenu(menu);
}
 
Example 8
Source File: MainActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
  super.onPrepareOptionsMenu(menu);
  MenuItem menuItem = menu.findItem(R.id.action_filter);

  // Modify Menu Items
  menuItem.setVisible(false);
  return true;
}
 
Example 9
Source File: DialtactsActivity.java    From coursera-android with MIT License 5 votes vote down vote up
private void prepareOptionsMenuInSearchMode(Menu menu) {
    // get references to menu items
    final MenuItem searchMenuItem = menu.findItem(R.id.search_on_action_bar);
    final MenuItem filterOptionMenuItem = menu.findItem(R.id.filter_option);
    final MenuItem addContactOptionMenuItem = menu.findItem(R.id.add_contact);
    final MenuItem callSettingsMenuItem = menu.findItem(R.id.menu_call_settings);
    final MenuItem emptyRightMenuItem = menu.findItem(R.id.empty_right_menu_item);

    // prepare the menu items
    searchMenuItem.setVisible(false);
    filterOptionMenuItem.setVisible(ViewConfiguration.get(this).hasPermanentMenuKey());
    addContactOptionMenuItem.setVisible(false);
    callSettingsMenuItem.setVisible(false);
    emptyRightMenuItem.setVisible(false);
}
 
Example 10
Source File: BottomNavigationViewTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@UiThreadTest
@Test
@SmallTest
public void testSettingLabeledMenuItemVisibility() throws Throwable {
  bottomNavigation.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
  final MenuItem homeMenuItem = bottomNavigation.getMenu().findItem(R.id.destination_home);
  assertTrue(homeMenuItem.isVisible());
  homeMenuItem.setVisible(false);
  assertFalse(homeMenuItem.isVisible());
}
 
Example 11
Source File: StandaloneActivity.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@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);
    sort.setVisible(cwd != null);
    grid.setVisible(mState.derivedMode != State.MODE_GRID);
    list.setVisible(mState.derivedMode != State.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);
    search.setVisible(true);
    createDir.setVisible(true);
    return true;
}
 
Example 12
Source File: RecommendedFragment.java    From phphub-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();
    Menu menu = toolbarView.getMenu();
    if (menu != null) {
        MenuItem publishView = menu.findItem(R.id.action_publish);
        if (publishView != null) {
            publishView.setVisible(Utils.hasLoggedIn(getContext(), accountManager));
        }
    }
}
 
Example 13
Source File: MainActivity.java    From views-widgets-samples with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
    logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
    logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);

    return super.onPrepareOptionsMenu(menu);
}
 
Example 14
Source File: MainActivity.java    From android-PermissionRequest with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
    logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
    logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);

    return super.onPrepareOptionsMenu(menu);
}
 
Example 15
Source File: ConfigurationActivity.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (!BuildConfig.DEBUG) {
        MenuItem sendLogsItem = menu.findItem(R.id.action_send_logs);
        if (sendLogsItem != null) {
            sendLogsItem.setVisible(false);
        }
    }
    return true;
}
 
Example 16
Source File: OmemoActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
	super.onCreateContextMenu(menu, v, menuInfo);
	Object account = v.getTag(R.id.TAG_ACCOUNT);
	Object fingerprint = v.getTag(R.id.TAG_FINGERPRINT);
	Object fingerprintStatus = v.getTag(R.id.TAG_FINGERPRINT_STATUS);
	if (account != null
			&& fingerprint != null
			&& account instanceof Account
			&& fingerprintStatus != null
			&& fingerprint instanceof String
			&& fingerprintStatus instanceof FingerprintStatus) {
		getMenuInflater().inflate(R.menu.omemo_key_context, menu);
		MenuItem distrust = menu.findItem(R.id.distrust_key);
		MenuItem verifyScan = menu.findItem(R.id.verify_scan);
		if (this instanceof TrustKeysActivity) {
			distrust.setVisible(false);
			verifyScan.setVisible(false);
		} else {
			FingerprintStatus status = (FingerprintStatus) fingerprintStatus;
			if (!status.isActive() || status.isVerified()) {
				verifyScan.setVisible(false);
			}
			distrust.setVisible(status.isVerified() || (!status.isActive() && status.isTrusted()));
		}
		this.mSelectedAccount = (Account) account;
		this.mSelectedFingerprint = (String) fingerprint;
	}
}
 
Example 17
Source File: ConversationsActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_conversations, menu);
    final MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
    final MenuItem menuEditProfiles = menu.findItem(R.id.action_accounts);
    final MenuItem inviteUser = menu.findItem(R.id.action_invite_user);
    if (qrCodeScanMenuItem != null) {
        if (isCameraFeatureAvailable()) {
            Fragment fragment = getFragmentManager().findFragmentById(R.id.main_fragment);
            boolean visible = getResources().getBoolean(R.bool.show_qr_code_scan)
                    && fragment instanceof ConversationsOverviewFragment;
            qrCodeScanMenuItem.setVisible(visible);
        } else {
            qrCodeScanMenuItem.setVisible(false);
        }
    }
    if (xmppConnectionServiceBound && xmppConnectionService.getAccounts().size() == 1 && !xmppConnectionService.multipleAccounts()) {
        menuEditProfiles.setTitle(R.string.action_account);
    } else {
        menuEditProfiles.setTitle(R.string.action_accounts);
    }
    if (xmppConnectionServiceBound && xmppConnectionService.getAccounts().size() > 0) {
        inviteUser.setVisible(true);
    } else {
        inviteUser.setVisible(false);
    }
    return super.onCreateOptionsMenu(menu);
}
 
Example 18
Source File: ConversationMenuConfigurator.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
public static void configureAttachmentMenu(@NonNull Conversation conversation, Menu menu, Boolean Quick_share_attachment_choice, boolean hasAttachments) {
    if (menu == null) {
        return;
    }
    final MenuItem menuAttach = menu.findItem(R.id.action_attach_file);
    boolean isPM = false;
    try {
        isPM = conversation.getMode() == Conversation.MODE_MULTI && conversation.getNextCounterpart() != null;
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (Quick_share_attachment_choice && !hasAttachments && !isPM) {
        menuAttach.setVisible(false);
        return;
    }
    final boolean visible;
    if (conversation.getMode() == Conversation.MODE_MULTI) {
        visible = conversation.getAccount().httpUploadAvailable() && conversation.getMucOptions().participating()
                || conversation.getAccount().httpUploadAvailable() && isPM;
    } else {
        visible = true;
    }
    menuAttach.setVisible(visible);
    if (!visible) {
        return;
    }
    menu.findItem(R.id.attach_record_voice).setVisible(microphoneAvailable);
    menu.findItem(R.id.attach_location).setVisible(locationAvailable);
}
 
Example 19
Source File: ToolbarManager.java    From MDPreference with Apache License 2.0 5 votes vote down vote up
/**
 * This function should be called in onPrepareOptionsMenu(Menu) of Activity that use
 * Toolbar as ActionBar, or after inflating menu.
 */
public void onPrepareMenu(){
    if(mGroupChanged || mMenuDataChanged){
        mToolbar.getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);

        Menu menu = mToolbar.getMenu();
        for(int i = 0, count = menu.size(); i < count; i++){
            MenuItem item = menu.getItem(i);
            item.setVisible(item.getGroupId() == mCurrentGroup || item.getGroupId() == 0);
        }

        mMenuDataChanged = false;
    }
}
 
Example 20
Source File: ConversationActivity.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
  MenuInflater inflater = this.getMenuInflater();
  menu.clear();

  boolean isEncryptedForAllSubscriptionIdsConversation = SessionUtil.hasSession(this, masterSecret, recipients.getPrimaryRecipient().getNumber(), activeSubscriptions);

  if (isSingleConversation() && isEncryptedConversation) {
    inflater.inflate(R.menu.conversation_secure_identity, menu);
    inflateSubMenuVerifyIdentity(menu);
    inflater.inflate(R.menu.conversation_secure_sms, menu.findItem(R.id.menu_security).getSubMenu());
    inflateSubMenuAbortSecureSession(menu);
  } else if (isSingleConversation() && !isEncryptedConversation) {
    inflater.inflate(R.menu.conversation_insecure_no_push, menu);
    inflater.inflate(R.menu.conversation_insecure, menu);
  }

  if (isSingleConversation() && !isEncryptedForAllSubscriptionIdsConversation) {
    inflateSubMenuStartSecureSession(menu);
  } else {
    MenuItem item = menu.findItem(R.id.menu_start_secure_session);
    if (item != null) item.setVisible(false);
  }

  if (isSingleConversation()) {
    inflater.inflate(R.menu.conversation_callable, menu);
  } else if (isGroupConversation()) {
    inflater.inflate(R.menu.conversation_group_options, menu);

    if (!isPushGroupConversation()) {
      inflater.inflate(R.menu.conversation_mms_group_options, menu);
      if (distributionType == ThreadDatabase.DistributionTypes.BROADCAST) {
        menu.findItem(R.id.menu_distribution_broadcast).setChecked(true);
      } else {
        menu.findItem(R.id.menu_distribution_conversation).setChecked(true);
      }
    }
  }

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

  if (recipients != null && recipients.isMuted()) inflater.inflate(R.menu.conversation_muted, menu);
  else                                            inflater.inflate(R.menu.conversation_unmuted, menu);

  if (isSingleConversation() && getRecipients().getPrimaryRecipient().getContactUri() == null) {
    inflater.inflate(R.menu.conversation_add_to_contacts, menu);
  }

  if (archived) menu.findItem(R.id.menu_archive_conversation)
                    .setTitle(R.string.conversation__menu_unarchive_conversation);

  super.onPrepareOptionsMenu(menu);
  return true;
}