Example usage for android.view SubMenu add

List of usage examples for android.view SubMenu add

Introduction

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

Prototype

public MenuItem add(int groupId, int itemId, int order, CharSequence title);

Source Link

Document

Add a new item to the menu.

Usage

From source file:Main.java

public static void addItems2Menu(Menu menu, int idx, String nume, ViewPager vp) {
    final SubMenu smenu = menu.addSubMenu(0, idx, 0, nume);
    for (int i = 0; i < vp.getAdapter().getCount(); i++) {
        if (i != vp.getCurrentItem())
            smenu.add(0, idx + i + 1, 0, vp.getAdapter().getPageTitle(i));
    }/*from  ww w.  j a  va 2 s .com*/
}

From source file:Main.java

static public boolean doCreateOptionsMenu(Menu menu) {
    menu.add(0, MENU_KEYBOARD_SPECIAL, 0, "Special Keys");

    menu.add(0, MENU_FIT, 0, "Resize");
    SubMenu inputModeMenu = menu.addSubMenu("Input Mode");
    inputModeMenu.add(1, MENU_INPUT_MOUSE, 0, "Trackpad").setChecked(true);
    inputModeMenu.add(1, MENU_INPUT_JOYSTICK, 0, "Joystick");
    inputModeMenu.add(1, MENU_INPUT_SCROLL, 0, "Scroll Screen");
    inputModeMenu.setGroupCheckable(1, true, true);

    inputModeMenu.add(0, MENU_INPUT_SWAP_JOYPORT, 0, "Swap Joystick Ports");

    inputModeMenu.add(0, MENU_INPUT_HARDKEY, 0, "Vol. Up/Down as button").setCheckable(true);
    inputModeMenu.add(0, MENU_INPUT_USE_LEFT_ALT, 0, "Map Left-Alt Key").setCheckable(true);
    inputModeMenu.add(0, MENU_INPUT_TAP_CLICK, 0, "Tap Screen as click").setCheckable(true);
    inputModeMenu.add(0, MENU_INPUT_INPUT_METHOD, 0, "Input Method");
    inputModeMenu.add(0, MENU_INPUT_FORCE_KEYBOARD, 0, "Show Keyboard Fix").setCheckable(true);
    inputModeMenu.add(0, MENU_INPUT_KEYUP_DELAY, 0, "Keypress Fix").setCheckable(true);

    SubMenu buttonMenu = menu.addSubMenu("Buttons");
    buttonMenu.add(1, MENU_BUTTON_HIDE, 0, "Hide Buttons");
    buttonMenu.add(1, MENU_BUTTON_SHOW, 0, "Show Buttons (Slower)").setChecked(true);
    buttonMenu.add(1, MENU_BUTTON_OFF, 0, "Disable Buttons");
    buttonMenu.setGroupCheckable(1, true, true);
    buttonMenu.add(0, MENU_BUTTON_ALWAYS_SHOW_JOYSTICK, 0, "Always Show Joystick").setCheckable(true);
    buttonMenu.add(0, MENU_BUTTON_LARGE_JOYSTICK, 0, "Large Joystick").setCheckable(true);

    SubMenu settingMenu = menu.addSubMenu("Settings");
    settingMenu.add(0, MENU_SETTINGS_FRAMESKIP, 0, "Frameskip");
    settingMenu.add(0, MENU_SETTINGS_BETTER_VIDEO, 0, "Better Video").setCheckable(true);
    settingMenu.add(0, MENU_SETTINGS_SHOW_INFO, 0, "Show Info").setCheckable(true);
    settingMenu.add(0, MENU_SETTINGS_TRUE_DRIVE, 0, "True Drive Emulation").setCheckable(true);
    settingMenu.add(0, MENU_SETTINGS_SCALE_FILTER, 0, "Smooth Resize (Slower)").setCheckable(true);
    settingMenu.add(0, MENU_SETTINGS_SCALE_FACTOR, 0, "Resize Mode");
    settingMenu.add(0, MENU_SETTINGS_FAST_MOUSE, 0, "Better Mouse (Slower)").setCheckable(true);
    settingMenu.add(0, MENU_SETTINGS_MOUSE_SENSITIVITY, 0, "Mouse Sensitivity");
    settingMenu.add(0, MENU_SETTINGS_JOYKEY_SET, 0, "Joystick Keys");
    settingMenu.add(0, MENU_SETTINGS_KEY_MAPPER, 0, "Button Mapper");
    settingMenu.add(0, MENU_SETTINGS_HELP, 0, "Help");
    settingMenu.add(0, MENU_SETTINGS_LICENSE, 0, "Save license to /sdcard/gpl.txt");

    menu.add(0, MENU_KEYBOARD, 0, "Keyboard");
    return true;/*  w w  w.j ava  2  s .  co m*/
}

From source file:com.evvsoft.treeview.demo.DemoActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    SubMenu sub = menu.addSubMenu("Theme");
    sub.add(0, R.style.Theme_TreeView_Light, 0, "Light");
    sub.add(0, R.style.Theme_TreeView_Dark, 0, "Dark");
    sub.add(0, R.drawable.expander_custom_group_holo_light, 0, "Custom group indicator");
    sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
    return true;//  w  ww  . j av  a 2  s.c o  m
}

From source file:com.paad.wifi4us.ShareActionProvider.java

@Override
public void onPrepareSubMenu(SubMenu subMenu) {
    //mContext.getMenuInflater().inflate(R.menu.actionbar_meau, subMenu);
    subMenu.add(0, 0, 0, "back").setIcon(R.drawable.ic_back)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override//from  www .j  a  v a 2s  . com
                public boolean onMenuItemClick(MenuItem item) {
                    Toast toast = Toast.makeText(mContext, "click back sub-menu", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.TOP, 0, 0);
                    toast.show();
                    return true;
                }

            });
    subMenu.add(0, 0, 0, "more").setIcon(R.drawable.ic_more)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    Toast toast = Toast.makeText(mContext, "click more sub-menu", Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.TOP, 0, 0);
                    toast.show();
                    return true;
                }

            });
    super.onPrepareSubMenu(subMenu);
}

From source file:ca.rmen.android.scrumchatter.main.TeamNavigationMenu.java

void load() {
    Log.v(TAG, "load");
    mTeams.getAllTeams().subscribe(teamsData -> {
        // Update the navigation view.
        SubMenu teamsMenu = mNavigationMenu.findItem(R.id.teams_list).getSubMenu();
        teamsMenu.clear();//from  w  w  w  .  ja  va  2  s  .com
        for (Teams.Team team : teamsData.teams) {
            MenuItem teamMenuItem = teamsMenu.add(R.id.teams_list_items, Menu.NONE, Menu.NONE, team.teamName);
            if (team.teamName.equals(teamsData.currentTeam.teamName)) {
                teamMenuItem.setChecked(true);
            }
        }
    });
}

From source file:dev.ukanth.ufirewall.RulesActivity.java

protected void populateMenu(SubMenu sub) {
    if (G.enableIPv6()) {
        sub.add(0, MENU_IPV6_RULES, 0, R.string.switch_ipv6).setIcon(R.drawable.rules);
        sub.add(0, MENU_IPV4_RULES, 0, R.string.switch_ipv4).setIcon(R.drawable.rules);
    }/*from   w  w  w  .  j a  v a  2s  .co  m*/
    sub.add(0, MENU_FLUSH_RULES, 0, R.string.flush).setIcon(R.drawable.clearlog);
    sub.add(0, MENU_SEND_REPORT, 0, R.string.send_report).setIcon(R.drawable.ic_dialog_email);
}

From source file:org.randoomz.learnit.ui.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    subscribe = db.createQuery(Language.TABLE, Language.ALL_QUERY).map(Language.MAP)
            .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<List<Language>>() {
                @Override//  w  w w  .  j a  v a 2s  .com
                public void call(List<Language> languages) {
                    MainActivity.this.languages = languages;
                    final MenuItem item = navigationView.getMenu().findItem(R.id.languages);
                    final SubMenu subMenuLanguages = item.getSubMenu();
                    subMenuLanguages.clear();
                    for (int i = 0; i < languages.size(); i++) {
                        subMenuLanguages.add(Menu.NONE, i, i, languages.get(i).language()).setCheckable(true);
                    }
                    onNavigationItemSelected(subMenuLanguages.getItem(currentPosition));
                }
            });
}

From source file:org.getlantern.firetweet.menu.SupportAccountActionProvider.java

@Override
public void onPrepareSubMenu(final SubMenu subMenu) {
    subMenu.removeGroup(MENU_GROUP);/*from  w w w  .j  a va  2 s . co m*/
    if (mAccounts == null)
        return;
    for (int i = 0, j = mAccounts.length; i < j; i++) {
        final ParcelableAccount account = mAccounts[i];
        final MenuItem item = subMenu.add(MENU_GROUP, Menu.NONE, i, account.name);
        final Intent intent = new Intent();
        intent.putExtra(EXTRA_ACCOUNT, account);
        item.setIntent(intent);
    }
    subMenu.setGroupCheckable(MENU_GROUP, true, mExclusive);
    if (mAccountIds == null)
        return;
    for (int i = 0, j = subMenu.size(); i < j; i++) {
        final MenuItem item = subMenu.getItem(i);
        if (ArrayUtils.contains(mAccountIds, mAccounts[i].account_id)) {
            item.setChecked(true);
        }
    }
}

From source file:org.mariotaku.twidere.menu.AccountToggleProvider.java

@Override
public void onPrepareSubMenu(final SubMenu subMenu) {
    subMenu.removeGroup(MENU_GROUP);/*from  ww  w .j  av  a  2s.co m*/
    if (mAccounts == null)
        return;
    for (int i = 0, j = mAccounts.length; i < j; i++) {
        final ParcelableAccount account = mAccounts[i];
        final MenuItem item = subMenu.add(MENU_GROUP, Menu.NONE, i, account.name);
        final Intent intent = new Intent();
        intent.putExtra(EXTRA_ACCOUNT, account);
        item.setIntent(intent);
    }
    subMenu.setGroupCheckable(MENU_GROUP, true, mExclusive);
    for (int i = 0, j = subMenu.size(); i < j; i++) {
        final MenuItem item = subMenu.getItem(i);
        if (mAccounts[i].is_activated) {
            item.setChecked(true);
        }
    }
}

From source file:org.alfresco.mobile.android.application.fragments.browser.ChildrenBrowserFragment.java

public static void getMenu(AlfrescoSession session, Menu menu, Folder parentFolder, boolean actionMode) {
    MenuItem mi;//from   w  ww . java  2s.  c om

    if (parentFolder == null) {
        return;
    }
    Permissions permission = null;
    try {
        permission = session.getServiceRegistry().getDocumentFolderService().getPermissions(parentFolder);
    } catch (Exception e) {
        return;
    }

    if (!actionMode) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_SEARCH_FOLDER,
                Menu.FIRST + MenuActionItem.MENU_SEARCH_FOLDER, R.string.search);
        mi.setIcon(R.drawable.ic_search);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (!actionMode && permission.canAddChildren()) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_CREATE_FOLDER,
                Menu.FIRST + MenuActionItem.MENU_CREATE_FOLDER, R.string.folder_create);
        mi.setIcon(R.drawable.ic_add_folder);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

        SubMenu createMenu = menu.addSubMenu(Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE,
                Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE, R.string.add_menu);
        createMenu.setIcon(android.R.drawable.ic_menu_add);
        createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        createMenu.add(Menu.NONE, MenuActionItem.MENU_UPLOAD, Menu.FIRST + MenuActionItem.MENU_UPLOAD,
                R.string.upload_title);

        createMenu.add(Menu.NONE, MenuActionItem.MENU_CREATE_DOCUMENT,
                Menu.FIRST + MenuActionItem.MENU_CREATE_DOCUMENT, R.string.create_document);

        createMenu.add(Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_PHOTO,
                Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_PHOTO, R.string.take_photo);

        if (AndroidVersion.isICSOrAbove()) {
            createMenu.add(Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_VIDEO,
                    Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_VIDEO, R.string.make_video);
        }

        createMenu.add(Menu.NONE, MenuActionItem.MENU_DEVICE_CAPTURE_MIC_AUDIO,
                Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_MIC_AUDIO, R.string.record_audio);

    }

    if (actionMode) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_DETAILS, Menu.FIRST + MenuActionItem.MENU_DETAILS,
                R.string.action_view_properties);
        mi.setIcon(R.drawable.ic_details);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (actionMode && permission.canEdit()) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_EDIT, Menu.FIRST + MenuActionItem.MENU_EDIT,
                R.string.edit);
        mi.setIcon(R.drawable.ic_edit);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (actionMode && permission.canDelete()) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_DELETE, Menu.FIRST + MenuActionItem.MENU_DELETE,
                R.string.delete);
        mi.setIcon(R.drawable.ic_delete);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (!actionMode) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_REFRESH, Menu.FIRST + MenuActionItem.MENU_REFRESH,
                R.string.refresh);
        mi.setIcon(R.drawable.ic_refresh);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
}