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.max2idea.android.limbo.main.LimboActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();//from   w ww  .  j a  v  a2s  . c  o m

    menu.add(0, INSTALL, 0, "Install Roms").setIcon(android.R.drawable.ic_menu_agenda);
    menu.add(0, DELETE, 0, "Delete Machine").setIcon(android.R.drawable.ic_menu_close_clear_cancel);
    menu.add(0, EXPORT, 0, "Export Machines").setIcon(android.R.drawable.ic_menu_save);
    menu.add(0, IMPORT, 0, "Import Machines").setIcon(android.R.drawable.ic_menu_send);
    menu.add(0, HELP, 0, "Help").setIcon(android.R.drawable.ic_menu_help);
    menu.add(0, CHANGELOG, 0, "Changelog").setIcon(android.R.drawable.ic_menu_help);
    menu.add(0, LICENSE, 0, "License").setIcon(android.R.drawable.ic_menu_help);
    menu.add(0, QUIT, 0, "Exit").setIcon(android.R.drawable.ic_lock_power_off);

    return true;

}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void addIntentToMenu(final Context context, final Menu menu, final Intent queryIntent,
        final int groupId) {
    if (context == null || menu == null || queryIntent == null)
        return;/* w w  w . j av  a  2s.c om*/
    final PackageManager pm = context.getPackageManager();
    final Resources res = context.getResources();
    final float density = res.getDisplayMetrics().density;
    final int padding = Math.round(density * 4);
    final List<ResolveInfo> activities = pm.queryIntentActivities(queryIntent, 0);
    for (final ResolveInfo info : activities) {
        final Intent intent = new Intent(queryIntent);
        final Drawable icon = info.loadIcon(pm);
        intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        final MenuItem item = menu.add(groupId, Menu.NONE, Menu.NONE, info.loadLabel(pm));
        item.setIntent(intent);
        final int iw = icon.getIntrinsicWidth(), ih = icon.getIntrinsicHeight();
        if (iw > 0 && ih > 0) {
            final Drawable iconWithPadding = new PaddingDrawable(icon, padding);
            iconWithPadding.setBounds(0, 0, iw, ih);
            item.setIcon(iconWithPadding);
        } else {
            item.setIcon(icon);
        }
    }
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

protected void showListFilter(final View v) {
    QuickSelectMenu popup = new QuickSelectMenu(this, v);
    int i_list;//from  www .j  a v a 2  s.co  m

    Menu menu = popup.getMenu();
    if (menu == null) {
        return;
    }

    // get the list of lists
    mCursorShoppingLists.requery();
    int count = mCursorShoppingLists.getCount();
    mCursorShoppingLists.moveToFirst();
    for (i_list = 0; i_list < count; i_list++) {
        String name = mCursorShoppingLists.getString(mStringListFilterNAME);
        menu.add(0, i_list, Menu.NONE, name);
        mCursorShoppingLists.moveToNext();
    }

    popup.setOnItemSelectedListener(new QuickSelectMenu.OnItemSelectedListener() {
        public void onItemSelected(CharSequence name, int pos) {
            setSelectedListPos(pos);
        }
    });

    popup.show();
}

From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuItem iAdd = menu.add(0, MENU_CONTACTINVITE, 0, R.string.menu_SelectShareApp)
            .setIcon(R.drawable.ic_action_add_person);
    MenuCompat.setShowAsAction(iAdd, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);

    menu.add(0, MENU_CONTACTINVITE, 0, R.string.menu_SelectShareApp).setIcon(R.drawable.ic_action_add_person);
    menu.add(0, MENU_SENDINTRO, 0, R.string.title_SecureIntroduction).setIcon(R.drawable.ic_action_secintro);
    menu.add(0, MENU_FEEDBACK, 0, R.string.menu_sendFeedback).setIcon(android.R.drawable.ic_menu_send);
    menu.add(0, MENU_LOGOUT, 0, R.string.menu_Logout).setIcon(android.R.drawable.ic_menu_close_clear_cancel);
    menu.add(0, MENU_SETTINGS, 0, R.string.menu_Settings).setIcon(android.R.drawable.ic_menu_preferences);
    menu.add(0, MENU_REFERENCE, 0, R.string.menu_Help).setIcon(android.R.drawable.ic_menu_help);

    return true;// w  w  w  .j a  va 2 s . c om
}

From source file:com.nttec.everychan.ui.presentation.BoardFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MenuItem itemAddPost = menu.add(Menu.NONE, R.id.menu_add_post, 101, resources
            .getString(pageType == TYPE_POSTSLIST ? R.string.menu_add_post : R.string.menu_add_thread));
    MenuItem itemUpdate = menu.add(Menu.NONE, R.id.menu_update, 102, resources.getString(
            tabModel.type != TabModel.TYPE_LOCAL ? R.string.menu_update : R.string.menu_from_internet));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        itemAddPost.setIcon(ThemeUtils.getActionbarIcon(activity.getTheme(), resources, R.attr.actionAddPost));
        itemUpdate.setIcon(ThemeUtils.getActionbarIcon(activity.getTheme(), resources, R.attr.actionRefresh));
        CompatibilityImpl.setShowAsActionIfRoom(itemAddPost);
        CompatibilityImpl.setShowAsActionIfRoom(itemUpdate);
    } else {/*from  w w w  .j  a va 2  s.c om*/
        itemAddPost.setIcon(R.drawable.ic_menu_edit);
        itemUpdate.setIcon(R.drawable.ic_menu_refresh);
    }
    menu.add(Menu.NONE, R.id.menu_catalog, 103, resources.getString(R.string.menu_catalog))
            .setIcon(R.drawable.ic_menu_list);
    menu.add(Menu.NONE, R.id.menu_search, 104, resources.getString(R.string.menu_search))
            .setIcon(android.R.drawable.ic_menu_search);
    menu.add(Menu.NONE, R.id.menu_save_page, 105, resources.getString(R.string.menu_save_page))
            .setIcon(android.R.drawable.ic_menu_save);
    menu.add(Menu.NONE, R.id.menu_board_gallery, 106, resources.getString(R.string.menu_board_gallery))
            .setIcon(android.R.drawable.ic_menu_slideshow);
    menu.add(Menu.NONE, R.id.menu_quickaccess_add, 107, resources.getString(R.string.menu_quickaccess_add))
            .setIcon(R.drawable.ic_menu_add_bookmark);
    this.menu = menu;
    updateMenu();
}

From source file:gov.cdc.epiinfo.RecordList.java

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

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = new SearchView(this);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override/* w  ww  .ja va2s.com*/
        public boolean onQueryTextSubmit(String searchTerm) {

            try {
                mDbHelper.fetchTopOne();

                String query = BuildQuery(searchTerm);

                String fieldName1;
                String fieldName2;
                String fieldName3;
                String[] from = new String[1];
                int[] to = new int[1];

                if (formMetadata.DataFields.size() > 2) {

                    fieldName1 = formMetadata.DataFields.get(0).getName();
                    fieldName2 = formMetadata.DataFields.get(1).getName();
                    fieldName3 = formMetadata.DataFields.get(2).getName();
                    mNotesCursor = mDbHelper.fetchWhere(fieldName1, fieldName2, fieldName3, query);
                    from = new String[] { "_id", "columnName1", fieldName1, "columnName2", fieldName2,
                            "columnName3", fieldName3, "_syncStatus" };
                    to = new int[] { R.id.text1, R.id.header2, R.id.text2, R.id.header3, R.id.text3,
                            R.id.header4, R.id.text4, R.id.hiddenText };
                } else if (formMetadata.DataFields.size() == 2) {
                    fieldName1 = formMetadata.DataFields.get(0).getName();
                    fieldName2 = formMetadata.DataFields.get(1).getName();
                    mNotesCursor = mDbHelper.fetchWhere(fieldName1, fieldName2, query);
                    from = new String[] { "_id", "columnName1", fieldName1, "columnName2", fieldName2,
                            "_syncStatus" };
                    to = new int[] { R.id.text1, R.id.header2, R.id.text2, R.id.header3, R.id.text3,
                            R.id.hiddenText };
                } else if (formMetadata.DataFields.size() == 1) {
                    fieldName1 = formMetadata.DataFields.get(0).getName();
                    mNotesCursor = mDbHelper.fetchWhere(fieldName1, query);
                    from = new String[] { "_id", "columnName1", fieldName1, "_syncStatus" };
                    to = new int[] { R.id.text1, R.id.header2, R.id.text2, R.id.hiddenText };
                }

                startManagingCursor(mNotesCursor);
                CustomListAdapter notes = new CustomListAdapter(self, R.layout.line_list_row, mNotesCursor,
                        from, to);
                lineListFragment.setListAdapter(notes);

            } catch (Exception ex) {
                fillData();
            }

            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {

            if (newText.equals("")) {
                fillData();
            }

            return false;
        }
    });

    mnuSearch = menu.add(0, SEARCH_ID, 0, R.string.menu_search);
    mnuSearch.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    mnuSearch.setActionView(searchView);
    mnuSearch.setIcon(gov.cdc.epiinfo.R.drawable.action_search);

    MenuItem mnuQR = menu.add(0, QR_ID, 1, R.string.menu_barcode);
    mnuQR.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    mnuQR.setIcon(gov.cdc.epiinfo.R.drawable.qrcode_scan);

    MenuItem mnuCloud = menu.add(0, CLOUD_ID, 2, R.string.menu_cloud_sync);
    mnuCloud.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    MenuItem mnuSync = menu.add(0, SYNC_ID, 3, R.string.menu_sync_file);
    mnuSync.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    MenuItem mnuDeleteAll = menu.add(0, DELETE_ALL_ID, 4, R.string.menu_delete_all);
    mnuDeleteAll.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    if (fkeyGuid == null || fkeyGuid.length() == 0) {
        mnuSetDefault = menu.add(0, SET_DEFAULT_ID, 5, R.string.set_default_form);
        mnuSetDefault.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        mnuExitDefault = menu.add(0, EXIT_DEFAULT_MODE_ID, 5, R.string.exit_default_form);
        mnuExitDefault.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        if (AppManager.getDefaultForm().equals("")) {
            mnuSetDefault.setVisible(true);
            mnuExitDefault.setVisible(false);
        } else {
            mnuSetDefault.setVisible(false);
            mnuExitDefault.setVisible(true);
        }
    }

    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    if (sharedPref.getString("cloud_service", "").equals("Box")) {
        mnuBoxSignin = menu.add(0, BOX_SIGNIN_ID, 6, R.string.box_signin);
        mnuBoxSignin.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        mnuBoxSignout = menu.add(0, BOX_SIGNOUT_ID, 6, R.string.box_signout);
        mnuBoxSignout.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

        if (BoxClient.isAuthenticated(this)) {
            mnuBoxSignout.setVisible(true);
            mnuBoxSignin.setVisible(false);
        } else {
            mnuBoxSignout.setVisible(false);
            mnuBoxSignin.setVisible(true);
        }
    }

    MenuItem mnuHelp = menu.add(1, HELP_ID, 7, R.string.menu_help);
    mnuHelp.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    return true;
}

From source file:com.ichi2.anki2.DeckPicker.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item;//from ww  w .jav  a 2 s  .c o m

    if (mFragmented) {
        UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_SYNC, Menu.NONE, R.string.sync_title,
                R.drawable.ic_menu_refresh);

        UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_ADD_NOTE, Menu.NONE, R.string.add,
                R.drawable.ic_menu_add);

        int icon;
        SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(this);
        if (preferences.getBoolean("invertedColors", false)) {
            icon = R.drawable.ic_menu_night_checked;
        } else {
            icon = R.drawable.ic_menu_night;
        }
        UIUtils.addMenuItemInActionBar(menu, Menu.NONE, StudyOptionsActivity.MENU_NIGHT, Menu.NONE,
                R.string.night_mode, icon);

        UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_STATISTICS, Menu.NONE, R.string.statistics_menu,
                R.drawable.ic_menu_statistics);

        UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_CARDBROWSER, Menu.NONE, R.string.menu_cardbrowser,
                R.drawable.ic_menu_cardbrowser);
    }
    UIUtils.addMenuItemInActionBar(menu, Menu.NONE, MENU_HELP, Menu.NONE, R.string.help_title,
            R.drawable.ic_menu_help);

    item = menu.add(Menu.NONE, MENU_PREFERENCES, Menu.NONE, R.string.menu_preferences);
    item.setIcon(R.drawable.ic_menu_preferences);
    item = menu.add(Menu.NONE, MENU_ADD_SHARED_DECK, Menu.NONE, R.string.menu_get_shared_decks);
    item.setIcon(R.drawable.ic_menu_download);
    item = menu.add(Menu.NONE, MENU_CREATE_DECK, Menu.NONE, R.string.new_deck);
    item.setIcon(R.drawable.ic_menu_add);
    item = menu.add(Menu.NONE, MENU_CREATE_DYNAMIC_DECK, Menu.NONE, R.string.new_dynamic_deck);
    item.setIcon(R.drawable.ic_menu_add);
    item = menu.add(Menu.NONE, MENU_IMPORT, Menu.NONE, R.string.menu_import);
    item.setIcon(R.drawable.ic_menu_download);
    UIUtils.addMenuItem(menu, Menu.NONE, CHECK_DATABASE, Menu.NONE, R.string.check_db,
            R.drawable.ic_menu_search);
    item = menu.add(Menu.NONE, StudyOptionsActivity.MENU_ROTATE, Menu.NONE, R.string.menu_rotate);
    item.setIcon(R.drawable.ic_menu_always_landscape_portrait);
    item = menu.add(Menu.NONE, MENU_FEEDBACK, Menu.NONE, R.string.studyoptions_feedback);
    item.setIcon(R.drawable.ic_menu_send);
    item = menu.add(Menu.NONE, MENU_ABOUT, Menu.NONE, R.string.menu_about);
    item.setIcon(R.drawable.ic_menu_info_details);
    item = menu.add(Menu.NONE, MENU_REUPGRADE, Menu.NONE, R.string.restart_upgrade_process);
    item.setIcon(R.drawable.ic_menu_preferences);

    return true;
}

From source file:com.android.launcher2.Launcher.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (isWorkspaceLocked()) {
        return false;
    }//from   ww w .j  a va  2s  .co  m

    super.onCreateOptionsMenu(menu);

    Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS);
    manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
    settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    String helpUrl = getString(R.string.help_url);
    Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl));
    help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

    menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
            .setIcon(android.R.drawable.ic_menu_gallery).setAlphabeticShortcut('W');
    menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps).setIcon(android.R.drawable.ic_menu_manage)
            .setIntent(manageApps).setAlphabeticShortcut('M');
    menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings).setIcon(android.R.drawable.ic_menu_preferences)
            .setIntent(settings).setAlphabeticShortcut('P');
    if (!helpUrl.isEmpty()) {
        menu.add(0, MENU_HELP, 0, R.string.menu_help).setIcon(android.R.drawable.ic_menu_help).setIntent(help)
                .setAlphabeticShortcut('H');
    }
    return true;
}

From source file:org.getlantern.firetweet.util.Utils.java

public static void addIntentToMenuForExtension(final Context context, final Menu menu, final int groupId,
        final String action, final String parelableKey, final String parelableJSONKey,
        final FiretweetParcelable parcelable) {
    if (context == null || menu == null || action == null || parelableKey == null || parcelable == null)
        return;//from   w  w w  .j a va2 s  .com
    final PackageManager pm = context.getPackageManager();
    final Resources res = context.getResources();
    final float density = res.getDisplayMetrics().density;
    final int padding = Math.round(density * 4);
    final Intent queryIntent = new Intent(action);
    queryIntent.setExtrasClassLoader(context.getClassLoader());
    final List<ResolveInfo> activities = pm.queryIntentActivities(queryIntent, PackageManager.GET_META_DATA);
    for (final ResolveInfo info : activities) {
        final Intent intent = new Intent(queryIntent);
        if (isExtensionUseJSON(info)) {
            intent.putExtra(parelableJSONKey, JSONSerializer.toJSONObjectString(parcelable));
        } else {
            intent.putExtra(parelableKey, parcelable);
        }
        intent.setClassName(info.activityInfo.packageName, info.activityInfo.name);
        final MenuItem item = menu.add(groupId, Menu.NONE, Menu.NONE, info.loadLabel(pm));
        item.setIntent(intent);
        final Drawable metaDataDrawable = getMetadataDrawable(pm, info.activityInfo,
                METADATA_KEY_EXTENSION_ICON);
        final int actionIconColor = ThemeUtils.getThemeForegroundColor(context);
        if (metaDataDrawable != null) {
            metaDataDrawable.mutate();
            metaDataDrawable.setColorFilter(actionIconColor, Mode.SRC_ATOP);
            item.setIcon(metaDataDrawable);
        } else {
            final Drawable icon = info.loadIcon(pm);
            final int iw = icon.getIntrinsicWidth(), ih = icon.getIntrinsicHeight();
            if (iw > 0 && ih > 0) {
                final Drawable iconWithPadding = new PaddingDrawable(icon, padding);
                iconWithPadding.setBounds(0, 0, iw, ih);
                item.setIcon(iconWithPadding);
            } else {
                item.setIcon(icon);
            }
        }

    }
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(1, 0, 0, "User name");
    if (GTConstants.isAccount)
        menu.add(1, 1, 1, "Accounts");
    if (GTConstants.isTour)
        menu.add(1, 2, 2, "Select Tour");
    if (GTConstants.isTraffic)
        menu.add(1, 3, 3, "License Plate Check");
    menu.add(1, 4, 4, "Help");
    menu.add(1, 5, 5, "About");
    menu.add(1, 6, 6, "Diagnostics");
    menu.add(1, 7, 7, "GPS Settings");

    return true;/*from   ww w .java  2s .c  om*/
}