Example usage for android.view Menu hasVisibleItems

List of usage examples for android.view Menu hasVisibleItems

Introduction

In this page you can find the example usage for android.view Menu hasVisibleItems.

Prototype

public boolean hasVisibleItems();

Source Link

Document

Return whether the menu currently has item items that are visible.

Usage

From source file:de.vanita5.twittnuker.fragment.support.UserProfileFragment.java

@Override
public void onPrepareOptionsMenu(final Menu menu) {
    if (!shouldUseNativeMenu() || !menu.hasVisibleItems())
        return;//w  ww. ja  v a2 s.c om
    setMenu(menu);
}

From source file:com.chuhan.privatecalc.fragment.os.FragmentActivity.java

/**
 * Dispatch onPrepareOptionsMenu() to fragments.
 *//*  ww  w .j  a va 2  s. c om*/
@Override
public boolean onPreparePanel(int featureId, View view, Menu menu) {
    if (featureId == Window.FEATURE_OPTIONS_PANEL && menu != null) {
        if (mOptionsMenuInvalidated) {
            mOptionsMenuInvalidated = false;
            menu.clear();
            onCreatePanelMenu(featureId, menu);
        }
        boolean goforit = super.onPreparePanel(featureId, view, menu);
        goforit |= mFragments.dispatchPrepareOptionsMenu(menu);
        return goforit && menu.hasVisibleItems();
    }
    return super.onPreparePanel(featureId, view, menu);
}

From source file:org.getlantern.firetweet.fragment.support.UserFragment.java

@Override
public void onPrepareOptionsMenu(final Menu menu) {
    if (!shouldUseNativeMenu() || !menu.hasVisibleItems())
        return;/*w  w w.j  a  v a 2 s  .  c om*/
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = getUser();
    final Relationship relationship = mRelationship;
    if (twitter == null || user == null)
        return;
    final boolean isMyself = user.account_id == user.id;
    final MenuItem mentionItem = menu.findItem(MENU_MENTION);
    if (mentionItem != null) {
        mentionItem.setTitle(
                getString(R.string.mention_user_name, UserColorNameUtils.getDisplayName(getActivity(), user)));
    }
    Utils.setMenuItemAvailability(menu, MENU_MENTION, !isMyself);
    Utils.setMenuItemAvailability(menu, R.id.incoming_friendships, isMyself);
    //        final MenuItem followItem = menu.findItem(MENU_FOLLOW);
    //        followItem.setVisible(!isMyself);
    //        final boolean shouldShowFollowItem = !creatingFriendship && !destroyingFriendship && !isMyself
    //                && relationship != null;
    //        followItem.setEnabled(shouldShowFollowItem);
    //        if (shouldShowFollowItem) {
    //            followItem.setTitle(isFollowing ? R.string.unfollow : isProtected ? R.string.send_follow_request
    //                    : R.string.follow);
    //            followItem.setIcon(isFollowing ? R.drawable.ic_action_cancel : R.drawable.ic_action_add);
    //        } else {
    //            followItem.setTitle(null);
    //            followItem.setIcon(null);
    //        }
    if (!isMyself && relationship != null) {
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, relationship.canSourceDMTarget());
        setMenuItemAvailability(menu, MENU_BLOCK, true);
        setMenuItemAvailability(menu, MENU_MUTE_USER, true);
        final MenuItem blockItem = menu.findItem(MENU_BLOCK);
        if (blockItem != null) {
            final boolean blocking = relationship.isSourceBlockingTarget();
            ActionIconDrawable.setMenuHighlight(blockItem, new FiretweetMenuInfo(blocking));
            blockItem.setTitle(blocking ? R.string.unblock : R.string.block);
        }
        final MenuItem muteItem = menu.findItem(MENU_MUTE_USER);
        if (muteItem != null) {
            final boolean muting = relationship.isSourceMutingTarget();
            ActionIconDrawable.setMenuHighlight(muteItem, new FiretweetMenuInfo(muting));
            muteItem.setTitle(muting ? R.string.unmute : R.string.mute);
        }
        final MenuItem filterItem = menu.findItem(MENU_ADD_TO_FILTER);
        if (filterItem != null) {
            final boolean filtering = Utils.isFilteringUser(getActivity(), user.id);
            ActionIconDrawable.setMenuHighlight(filterItem, new FiretweetMenuInfo(filtering));
            filterItem.setTitle(filtering ? R.string.remove_from_filter : R.string.add_to_filter);
        }
    } else {
        setMenuItemAvailability(menu, MENU_SEND_DIRECT_MESSAGE, false);
        setMenuItemAvailability(menu, MENU_BLOCK, false);
        setMenuItemAvailability(menu, MENU_MUTE_USER, false);
        setMenuItemAvailability(menu, MENU_REPORT_SPAM, false);
    }
    setMenuItemAvailability(menu, R.id.muted_users, isMyself);
    setMenuItemAvailability(menu, R.id.blocked_users, isMyself);
    final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER);
    final Bundle extras = new Bundle();
    extras.putParcelable(EXTRA_USER, user);
    intent.putExtras(extras);
    menu.removeGroup(MENU_GROUP_USER_EXTENSION);
    addIntentToMenu(getActivity(), menu, intent, MENU_GROUP_USER_EXTENSION);
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

private boolean shouldFlushMenu(Menu menu) {
    if (menu == null)
        return true;
    if (!menu.hasVisibleItems())
        return true;
    OpenFragment f = getSelectedFragment();
    if (f == null)
        return false;
    return !f.getClassName().equals(mLastMenuClass);
}