Example usage for android.view Menu getItem

List of usage examples for android.view Menu getItem

Introduction

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

Prototype

public MenuItem getItem(int index);

Source Link

Document

Gets the menu item at the given index.

Usage

From source file:com.tct.mail.ui.ActionBarController.java

public boolean onPrepareOptionsMenu(Menu menu) {
    // We start out with every option enabled. Based on the current view, we disable actions
    // that are possible.
    LogUtils.d(LOG_TAG, "ActionBarView.onPrepareOptionsMenu().");

    //[FEATURE]-Add-BEGIN by CDTS.zhonghua.tuo,05/21/2014,FR 670064
    // TS: xiaolin.li 2014-11-25 EMAIL READ_PLF MOD_S
    //boolean searchEnhance = mContext.getResources().getBoolean(R.bool.feature_email_search_enhance_on);
    boolean searchEnhance = PLFUtils.getBoolean(mContext, "feature_email_search_enhance_on");
    // TS: xiaolin.li 2014-11-25 EMAIL READ_PLF MOD_E
    if (mLocalSearchItem != null) {
        mLocalSearchItem//from w  w  w .j a  v  a2s  .c  om
                .setVisible(mAccount != null && mFolder != null && SERVICE_SEARCH_MODE && searchEnhance);
    }
    if (mServiceSearchItem != null) {
        mServiceSearchItem.setVisible(mAccount != null && mFolder != null
                && mAccount.supportsCapability(AccountCapabilities.SERVER_SEARCH) && !SERVICE_SEARCH_MODE
                && searchEnhance);
    }
    //[FEATURE]-Add-END by CDTS.zhonghua.tuo
    //TS: junwei-xu 2015-10-27 EMAIL BUGFIX-791734 MOD
    //NOTE: Check if mController is null
    if (mController != null && mController.shouldHideMenuItems()) {
        // Shortcut: hide all menu items if the drawer is shown
        final int size = menu.size();

        for (int i = 0; i < size; i++) {
            final MenuItem item = menu.getItem(i);
            item.setVisible(false);
        }
        return false;
    }
    validateVolatileMenuOptionVisibility();

    switch (getMode()) {
    case ViewMode.CONVERSATION:
    case ViewMode.SEARCH_RESULTS_CONVERSATION:
        // We update the ActionBar options when we are entering conversation view because
        // waiting for the AbstractConversationViewFragment to do it causes duplicate icons
        // to show up during the time between the conversation is selected and the fragment
        // is added.
        setConversationModeOptions(menu);
        break;
    case ViewMode.CONVERSATION_LIST:
        // Show search if the account supports it
        Utils.setMenuItemVisibility(menu, R.id.search, mAccount.supportsSearch());//[FEATURE]-Add-BEGIN by TSNJ Zhenhua.Fan,10/23/2014,PR 728378
        //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-S
        // Hide star toggle if not support it
        updateStarToggleVisible(isExpandedSearch());
        //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 ADD-E
        break;
    case ViewMode.SEARCH_RESULTS_LIST:
        // Hide compose and search
        Utils.setMenuItemVisibility(menu, R.id.compose, false);
        Utils.setMenuItemVisibility(menu, R.id.search, false);
        LogUtils.logFeature(LogTag.SEARCH_TAG, "EmailActionBarView onPrepareOptionsMenu SEARCH_RESULTS_LIST");
        break;
    }

    return false;
}

From source file:org.mariotaku.twidere.fragment.UserProfileFragment.java

@Override
public void onClick(final View view) {
    if (getActivity() == null)
        return;/*  w  w  w.j a  va 2  s .co  m*/
    switch (view.getId()) {
    case R.id.edit_follow: {
        if (mUser == null || mAccountId <= 0)
            return;
        if (mAccountId == mUserId) {
            final Bundle bundle = getArguments();
            final Intent intent = new Intent(INTENT_ACTION_EDIT_USER_PROFILE);
            intent.setClass(getActivity(), EditUserProfileActivity.class);
            if (bundle != null) {
                intent.putExtras(bundle);
            }
            startActivity(intent);
        } else {
            if (mUser.is_follow_request_sent)
                return;
            if (mFriendship.isSourceFollowingTarget()) {
                mPopupMenu = PopupMenu.getInstance(getActivity(), view);
                mPopupMenu.inflate(R.menu.action_user_profile_follow);
                mPopupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(final MenuItem item) {
                        switch (item.getItemId()) {
                        case R.id.unfollow: {
                            mFollowProgress.setVisibility(View.VISIBLE);
                            mEditFollowButton.setVisibility(View.GONE);
                            mTwitterWrapper.destroyFriendship(mAccountId, mUser.user_id);
                            return true;
                        }
                        }
                        return false;
                    }
                });
                mPopupMenu.show();
            } else {
                mFollowProgress.setVisibility(View.VISIBLE);
                mEditFollowButton.setVisibility(View.GONE);
                mTwitterWrapper.createFriendship(mAccountId, mUser.user_id);
            }
        }
        break;
    }
    case R.id.retry: {
        getUserInfo(true);
        break;
    }
    case R.id.profile_image_container: {
        final Uri uri = Uri.parse(getOriginalTwitterProfileImage(mUser.profile_image_url));
        openImage(getActivity(), uri, false);
        break;
    }
    case R.id.tweets_container: {
        if (mUser == null)
            return;
        openUserTimeline(getActivity(), mAccountId, mUser.user_id, mUser.screen_name);
        break;
    }
    case R.id.followers_container: {
        if (mUser == null)
            return;
        openUserFollowers(getActivity(), mAccountId, mUser.user_id, mUser.screen_name);
        break;
    }
    case R.id.friends_container: {
        if (mUser == null)
            return;
        openUserFriends(getActivity(), mAccountId, mUser.user_id, mUser.screen_name);
        break;
    }
    case R.id.more_options: {
        if (mUser == null)
            return;
        mPopupMenu = PopupMenu.getInstance(getActivity(), view);
        mPopupMenu.inflate(R.menu.action_user_profile);
        final Menu menu = mPopupMenu.getMenu();
        if (mUser.user_id != mAccountId) {
            if (mFriendship == null)
                return;
            final MenuItem blockItem = menu.findItem(MENU_BLOCK);
            if (blockItem != null) {
                final Drawable blockIcon = blockItem.getIcon();
                if (mFriendship.isSourceBlockingTarget()) {
                    blockItem.setTitle(R.string.unblock);
                    blockIcon.mutate().setColorFilter(getResources().getColor(R.color.holo_blue_bright),
                            PorterDuff.Mode.MULTIPLY);
                } else {
                    blockItem.setTitle(R.string.block);
                    blockIcon.clearColorFilter();
                }
            }
            final MenuItem sendDirectMessageItem = menu.findItem(MENU_SEND_DIRECT_MESSAGE);
            if (sendDirectMessageItem != null) {
                sendDirectMessageItem.setVisible(mFriendship.isTargetFollowingSource());
            }
        } else {
            final int size = menu.size();
            for (int i = 0; i < size; i++) {
                final MenuItem item = menu.getItem(i);
                final int id = item.getItemId();
                item.setVisible(id == R.id.set_color_submenu || id == MENU_EXTENSIONS_SUBMENU);
            }
        }
        final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU);
        if (extensions != null) {
            final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER);
            final Bundle extras = new Bundle();
            extras.putParcelable(INTENT_KEY_USER, mUser);
            intent.putExtras(extras);
            addIntentToSubMenu(getActivity(), extensions.getSubMenu(), intent);
        }
        mPopupMenu.setOnMenuItemClickListener(this);
        mPopupMenu.show();
        break;
    }
    case R.id.name_container: {
        if (mUser == null || mAccountId != mUserId)
            return;
        startActivity(new Intent(getActivity(), EditUserProfileActivity.class));
        break;
    }
    }

}

From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    mOptionsMenuContactsAvailable = mContactsAvailable;
    if (!mOptionsMenuContactsAvailable) {
        return;/*  w  w w  . j av a  2s . c  o  m*/
    }

    final boolean isSearchOrSelectionMode = mActionBarAdapter.isSearchMode()
            || mActionBarAdapter.isSelectionMode();
    makeMenuItemVisible(menu, R.id.menu_search, !isSearchOrSelectionMode);

    final boolean showSelectedContactOptions = mActionBarAdapter.isSelectionMode()
            && getSelectedContactIds().size() != 0;
    makeMenuItemVisible(menu, R.id.menu_share, showSelectedContactOptions);
    makeMenuItemVisible(menu, R.id.menu_delete, showSelectedContactOptions);
    final boolean showLinkContactsOptions = mActionBarAdapter.isSelectionMode()
            && 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());

    // Light tint the icons for normal mode, dark tint for search or selection mode.
    for (int i = 0; i < menu.size(); ++i) {
        final Drawable icon = menu.getItem(i).getIcon();
        if (icon != null && !isSearchOrSelectionMode) {
            icon.mutate().setColorFilter(ContextCompat.getColor(getContext(), R.color.actionbar_icon_color),
                    PorterDuff.Mode.SRC_ATOP);
        }
    }
}

From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.TrafficMapActivity.java

/**
 * Set up the App bar menu//from   w w w. ja va2  s .c om
 *
 * Loop through all menu items, checking ID for set up.
 * We do it this way because item indices aren't set since the menu is dynamic.
 * (ex. travel charts may be added to the start)
 *
 * @param menu
 * @return
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();

    getMenuInflater().inflate(R.menu.traffic, menu);

    if (bestTimesAvailable) {
        menu.add(0, R.id.best_times_to_travel, 0, "Best Times to Travel").setIcon(R.drawable.ic_menu_chart)
                .setActionView(R.layout.action_bar_notification_icon)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        final MenuItem chartMenuItem = menu.findItem(R.id.best_times_to_travel);
        // Since we added an action view, need to hook up the onclick ourselves.
        chartMenuItem.getActionView()
                .setOnClickListener(v -> TrafficMapActivity.this.onMenuItemSelected(0, chartMenuItem));
        menu_item_refresh = 2;
    } else {
        menu_item_refresh = 1;
    }

    for (int i = 0; i < menu.size(); i++) {
        switch (menu.getItem(i).getItemId()) {
        case R.id.toggle_cameras:
            if (showCameras) {
                menu.getItem(i).setTitle("Hide Cameras");
                menu.getItem(i).setIcon(R.drawable.ic_menu_traffic_cam);
            } else {
                menu.getItem(i).setTitle("Show Cameras");
                menu.getItem(i).setIcon(R.drawable.ic_menu_traffic_cam_off);
            }
            break;
        default:
            break;
        }
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.tweetlanes.android.core.view.TweetFeedFragment.java

@Override
public boolean configureOptionsMenu(MenuInflater inflater, Menu menu) {

    if (inflater != null && mContentHandle != null
            && (mContentHandle.getStatusesType() == StatusesType.USER_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_HOME_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_LIST_TIMELINE)) {

        if (getBaseLaneActivity() instanceof HomeActivity) {
            inflater.inflate(R.menu.home_tweet_feed_action_bar, menu);
        } else {//ww w .  j a  va 2s  .c  o m
            inflater.inflate(R.menu.tweet_feed_action_bar, menu);
        }

        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            if (menuItem.getItemId() == R.id.action_feed_filter) {
                SubMenu subMenu = menuItem.getSubMenu();
                if (subMenu != null) {
                    SocialNetConstant.Type socialNetType = getApp().getCurrentAccount().getSocialNetType();
                    int subMenuSize = subMenu.size();
                    for (int j = 0; j < subMenuSize; j++) {
                        MenuItem subMenuItem = subMenu.getItem(j);
                        int i1 = subMenuItem.getItemId();
                        if (i1 == R.id.action_replies_visibility) {
                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowReplies()
                                            ? R.string.action_hide_replies
                                            : R.string.action_show_replies));

                        } else if (i1 == R.id.action_retweets_visibility) {
                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowRetweets()
                                            ? socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_hide_retweets
                                                    : R.string.action_hide_retweets_adn
                                            : socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_show_retweets
                                                    : R.string.action_show_retweets_adn));

                        } else {
                        }

                    }
                }
            }
        }

        return true;
    }

    return false;
}

From source file:com.smc.tw.waltz.MainActivity.java

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    if (DEBUG)//  w  w  w.j  a  va2s  .  co m
        Log.d(TAG, "onRestoreInstanceState b:" + savedInstanceState);

    super.onRestoreInstanceState(savedInstanceState);

    mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION, 0);
    Menu menu = mNavigationView.getMenu();
    menu.getItem(mCurrentSelectedPosition).setChecked(true);
}

From source file:com.plusot.senselib.SenseMain.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (menu.size() < 2)
        super.onPrepareOptionsMenu(menu);
    menuItemz = new MenuItem[menu.size()];
    for (int i = 0; i < menu.size(); i++) {
        menuItemz[i] = menu.getItem(i);
    }/*w w  w.java 2  s.  c  o m*/
    //      if (SenseGlobals.activity.equals(SenseGlobals.ActivityMode.RUN)) {
    //         menuItemz[0].setVisible(false);
    //         menuItemz[1].setVisible(true);
    //      } else {
    //         menuItemz[0].setVisible(true);
    //         menuItemz[1].setVisible(false);
    //      }
    //      if (!Globals.isBikeApp) {
    //         MenuItem item = menuItems.get(MyMenu.MENU_STEPS);
    //         if (item != null) item.setVisible(false);
    //      }
    return super.onPrepareOptionsMenu(menu);
}

From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java

@Override
public void onCreateOptionsMenu(Menu pMenu, MenuInflater inflater) {
    super.onCreateOptionsMenu(pMenu, inflater);
    inflater.inflate(R.menu.menu, pMenu);
    mGPS = pMenu.getItem(0);
}

From source file:org.mozilla.gecko.BrowserApp.java

private static Menu findParentMenu(Menu menu, MenuItem item) {
    final int itemId = item.getItemId();

    final int count = (menu != null) ? menu.size() : 0;
    for (int i = 0; i < count; i++) {
        MenuItem menuItem = menu.getItem(i);
        if (menuItem.getItemId() == itemId) {
            return menu;
        }//w w  w  . j ava 2  s.  co m
        if (menuItem.hasSubMenu()) {
            Menu parent = findParentMenu(menuItem.getSubMenu(), item);
            if (parent != null) {
                return parent;
            }
        }
    }

    return null;
}

From source file:de.rosche.spectraTelemetry.SpectraTelemetry.java

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

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.option_menu, (android.view.Menu) menu);
    mMenuItemConnect = menu.getItem(0);
    mMenuItemLog = menu.getItem(2);/*from w  w w. j  ava 2  s  .  c o m*/
    if (mMenuItemConnect != null && aurora_ready == true) {
        mMenuItemConnect.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
        mMenuItemConnect.setTitle(R.string.disconnect);
    }
    return true;
}