Example usage for android.view Menu add

List of usage examples for android.view Menu add

Introduction

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

Prototype

public MenuItem add(int groupId, int itemId, int order, @StringRes int titleRes);

Source Link

Document

Variation on #add(int,int,int,CharSequence) that takes a string resource identifier instead of the string itself.

Usage

From source file:com.cyeam.cInterphone.ui.CInterphone.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from   www .j  a v a2s . c  o  m*/
public boolean onCreateOptionsMenu(Menu menu) {
    boolean result = super.onCreateOptionsMenu(menu);

    MenuItem m;
    // m = menu.add(0, TEST1, 0, R.string.test);
    // m.setIcon(android.R.drawable.ic_menu_call);
    // m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);
    //
    // m = menu.add(0, TEST2, 0, R.string.test);
    // m.setIcon(android.R.drawable.ic_menu_gallery);
    // m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);

    m = menu.add(0, CONFIGURE_MENU_ITEM, 0, R.string.menu_settings);
    m.setIcon(android.R.drawable.ic_menu_preferences);
    m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);

    m = menu.add(0, ABOUT_MENU_ITEM, 0, R.string.menu_about);
    m.setIcon(android.R.drawable.ic_menu_info_details);
    m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);

    m = menu.add(0, EXIT_MENU_ITEM, 0, R.string.menu_exit);
    m.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
    m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);

    return result;
}

From source file:com.fimagena.filepicker.FilePickerFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.picker_actions, menu);
    MenuItem item = menu.findItem(R.id.action_createdir);
    item.setVisible(mParams.get(ALLOW_CREATE_DIR));

    // FIXME: Ensure the icon is visible on the light background. This is a hack and should be done through the theme!
    TypedValue value = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.colorAccent, value, true);
    menu.findItem(R.id.action_createdir).getIcon().mutate().setColorFilter(value.data,
            PorterDuff.Mode.SRC_ATOP);/*from www. j  a v a2s . c o m*/

    for (int root = 0; root < mFileSystemRoots.length; root++)
        menu.add(Menu.NONE, root, Menu.NONE, "Switch to " + mFileSystemRoots[root].getName());
}

From source file:moe.johnny.tombstone.ui.PreventFragment.java

private void updatePreventMenu(Menu menu, String packageName) {
    if (mActivity.getPreventPackages().containsKey(packageName)) {
        menu.add(Menu.NONE, R.string.remove, Menu.NONE, R.string.remove);
    } else {/*from  w  w  w  .  j  a va  2s. com*/
        menu.add(Menu.NONE, R.string.prevent, Menu.NONE, R.string.prevent);
    }
}

From source file:com.drextended.actionhandler.action.CompositeAction.java

/**
 * Prepares popup menu to show given menu items
 *
 * @param context    The Context, which generally get from view by {@link View#getContext()}
 * @param view       The View, which can be used for prepare any visual effect (like animation),
 *                   Generally it is that view which was clicked and initiated action to fire.
 * @param actionType The action type//from  www  .  j a v  a  2  s. c  o m
 * @param model      The model which should be handled by the action.
 * @param menuItems  list of items which will be shown in a menu
 * @return popup menu to show given menu items
 */
protected PopupMenu buildPopupMenu(final Context context, final View view, final String actionType,
        final M model, final List<ActionItem> menuItems) {
    final PopupMenu popupMenu = new PopupMenu(context, view);
    final Menu menu = popupMenu.getMenu();
    int count = menuItems.size();
    for (int index = 0; index < count; index++) {
        final ActionItem item = menuItems.get(index);
        //noinspection unchecked
        menu.add(0, index, 0, item.titleProvider.getTitle(context, model));
        if (mShowNonAcceptedActions) {
            menu.getItem(index).setEnabled(item.action.isModelAccepted(model));
        }
    }
    final AtomicBoolean activated = new AtomicBoolean(false);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            activated.set(true);
            final ActionItem actionItem = menuItems.get(item.getItemId());
            if (item.isEnabled()) {
                fireActionItem(context, view, actionItem.actionType, model, actionItem);
            } else {
                notifyOnActionDismiss("The model is not accepted for selected action", view, actionType, model);
            }
            return true;
        }
    });
    popupMenu.setOnDismissListener(new PopupMenu.OnDismissListener() {
        @Override
        public void onDismiss(PopupMenu menu) {
            if (!activated.get()) {
                notifyOnActionDismiss("CompositeAction menu dismissed", view, actionType, model);
            }
        }
    });
    return popupMenu;
}

From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java

private void configurePopupWithTracks(PopupMenu popup, final OnMenuItemClickListener customActionClickListener,
        final int trackType) {
    if (player == null) {
        return;/*from   w w w .ja v a  2  s . c  o  m*/
    }
    String[] tracks = player.getTracks(trackType);
    if (tracks == null) {
        return;
    }
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return (customActionClickListener != null && customActionClickListener.onMenuItemClick(item))
                    || onTrackItemClick(item, trackType);
        }
    });
    Menu menu = popup.getMenu();
    // ID_OFFSET ensures we avoid clashing with Menu.NONE (which equals 0)
    menu.add(MENU_GROUP_TRACKS, DemoPlayer.DISABLED_TRACK + ID_OFFSET, Menu.NONE, R.string.off);
    if (tracks.length == 1 && TextUtils.isEmpty(tracks[0])) {
        menu.add(MENU_GROUP_TRACKS, DemoPlayer.PRIMARY_TRACK + ID_OFFSET, Menu.NONE, R.string.on);
    } else {
        for (int i = 0; i < tracks.length; i++) {
            menu.add(MENU_GROUP_TRACKS, i + ID_OFFSET, Menu.NONE, tracks[i]);
        }
    }
    menu.setGroupCheckable(MENU_GROUP_TRACKS, true, true);
    menu.findItem(player.getSelectedTrackIndex(trackType) + ID_OFFSET).setChecked(true);
}

From source file:ch.teamuit.android.soundplusplus.LibraryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    menu.add(0, MENU_PLAYBACK, 0, R.string.playback_view);
    menu.add(0, MENU_SEARCH, 0, R.string.search).setIcon(R.drawable.ic_menu_search).setVisible(false);
    menu.add(0, MENU_SORT, 30, R.string.sort_by).setIcon(R.drawable.ic_menu_sort_alphabetically);
    return true;/* w  ww .ja v a2s.  c  om*/
}

From source file:com.abewy.android.apps.klyph.app.MainActivity.java

public boolean onCreateOptionsMenu(Menu menu) {
    if (notificationsFragment != null && menu.findItem(R.id.menu_notifications) == null) {
        final MenuItem notificationItem = menu.add(Menu.NONE, R.id.menu_notifications, 2,
                R.string.menu_notifications);
        notificationItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        notificationItem.setActionView(R.layout.actionbar_item_notifications);

        final TextView notificationTextView = (TextView) notificationItem.getActionView()
                .findViewById(R.id.textView);

        int count = notificationsFragment.getUnreadCount();

        notificationTextView.setText(String.valueOf(count));

        if (count > 0) {
            notificationTextView/*from   w  w  w.j ava  2 s  .com*/
                    .setBackgroundResource(AttrUtil.getResourceId(this, R.attr.notificationsItemBackground));
        } else {
            notificationTextView.setBackgroundResource(R.drawable.notifications_read_background);

        }

        notificationItem.getActionView().setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onOptionsItemSelected(notificationItem);
            }
        });
    }

    if (!KlyphFlags.IS_PRO_VERSION && menu.findItem(R.id.menu_buy_pro) == null) {
        menu.add(Menu.NONE, R.id.menu_buy_pro, 2, R.string.menu_buy_pro)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    if (menu.findItem(R.id.menu_faq) == null) {
        menu.add(Menu.NONE, R.id.menu_faq, Menu.NONE, R.string.menu_faq)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:org.alfresco.mobile.android.application.fragments.sync.SyncFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    info = SyncScanInfo.getLastSyncScanData(getActivity(), acc);
    if (info != null && (info.hasWarning() && !info.hasResponse())) {
        mi = menu.add(Menu.NONE, R.id.menu_sync_warning, Menu.FIRST, R.string.sync_warning);
        mi.setIcon(R.drawable.ic_warning);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }//from   w w  w  . j  a  va2s .co m

    MenuFragmentHelper.getMenu(getActivity(), menu);
}

From source file:de.aw.monma.wertpapier.FragmentWertpapierBuchungenListe.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.awlib_defaultFAB:
        PopupMenu popUpMenu = new PopupMenu(getActivity(), v);
        Menu menu = popUpMenu.getMenu();
        // Aufbau des zugehoerigen Submenues
        for (WPUmsatzArt umsatzArt : WPUmsatzArt.values()) {
            switch (umsatzArt) {
            case Kauf:
            case OthrInc:
            case WP_Einlage:
            case Ausgabe:
                Intent intent = new Intent(getActivity(), ActivityWPUmsatz.class);
                intent.putExtra(ACTION, (Parcelable) Action.DoWertpapierUmsatz);
                intent.putExtra(ACCOUNTID, mAccountID);
                intent.putExtra(WPUMSATZART, umsatzArt);
                MenuItem item = menu.add(Menu.NONE, umsatzArt.getTextResID(), Menu.NONE,
                        umsatzArt.getBeschreibungID());
                item.setIntent(intent);/*  www.j  av  a 2  s .  com*/
            }
        }
        popUpMenu.show();
        break;
    default:
    }
}

From source file:ca.spencerelliott.mercury.Changesets.java

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

    //For some reason android.R.drawable.ic_menu_refresh is missing so I needed to grab the 
    //actual file from the SDK and include it in the project
    if (!is_search_window) {
        menu.add(0, REFRESH, 0, R.string.refresh).setIcon(R.drawable.ic_menu_refresh);
        menu.add(0, SEARCH, 1, R.string.changesets_search_option).setIcon(android.R.drawable.ic_menu_search);
    }/*from ww w .  j  a  v  a  2s  . c  om*/

    return true;
}