Example usage for android.view SubMenu setGroupCheckable

List of usage examples for android.view SubMenu setGroupCheckable

Introduction

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

Prototype

public void setGroupCheckable(int group, boolean checkable, boolean exclusive);

Source Link

Document

Control whether a particular group of items can show a check mark.

Usage

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 . ja va 2  s.c  o  m
}

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

@Override
public void onPrepareSubMenu(final SubMenu subMenu) {
    subMenu.removeGroup(MENU_GROUP);//from  ww  w  .  j ava2  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 w  ww. ja  va2  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);
    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:com.ushahidi.android.presentation.view.ui.activity.PostActivity.java

private void setNavigationViewMenuItems(@NonNull Menu menu) {
    // Reset menu items to avoid duplicates because we reinitialize them
    menu.clear();// w w  w.  j a  v a 2s  .com
    if (!Utility.isCollectionEmpty(mDeploymentModelList)) {
        SubMenu subMenu = menu.addSubMenu(Menu.NONE, Menu.FIRST, Menu.NONE, R.string.deployments);
        subMenu.setGroupCheckable(DEPLOYMENTS_MENU_ITEMS_GROUP_ID, true, true);
        // Use item position as the menu item's id that way we can retrieve the individual
        // deployment when user clicks on it to make it the active deployment
        for (int pos = 0; pos < mDeploymentModelList.size(); pos++) {
            subMenu.add(DEPLOYMENTS_MENU_ITEMS_GROUP_ID, pos, pos, mDeploymentModelList.get(pos).getTitle())
                    .setIcon(R.drawable.ic_action_globe);
            if (mDeploymentModelList.get(pos).getStatus().equals(DeploymentModel.Status.ACTIVATED)) {
                mNavigationView.getMenu().findItem(pos).setChecked(true);
                mToolbar.setTitle(mNavigationView.getMenu().findItem(pos).getTitle());
            } else {
                mNavigationView.getMenu().findItem(pos).setChecked(false);
            }
        }
    }

    mSubMenuMisc = menu.addSubMenu(Menu.NONE, Menu.FIRST, Menu.NONE, R.string.actions);

    mSubMenuMisc.add(MISC_MENU_ITEMS, MANAGE_DEPLOYMENT_MENU_ID, 1, R.string.manage_deployments)
            .setIcon(R.drawable.ic_action_map);

    mSubMenuMisc.add(MISC_MENU_ITEMS, FEEDBACK_MENU_ID, 2, R.string.send_feedback)
            .setIcon(R.drawable.ic_action_help);
    mSubMenuMisc.add(MISC_MENU_ITEMS, ABOUT_MENU_ID, 3, R.string.about).setIcon(R.drawable.ic_action_info);

    if (mSessionManager.getActiveSession() != null) {
        mSubMenuMisc.add(MISC_MENU_ITEMS, LOGOUT_MENU_ID, 4, R.string.logout)
                .setIcon(R.drawable.ic_action_logout);
    }

    mSubMenuMisc.setGroupCheckable(MISC_MENU_ITEMS, true, true);

}

From source file:io.github.hidroh.materialistic.ReadabilityFragment.java

@Override
protected void createOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_font_options, menu);
    mTextSizeOptionValues = getResources().getStringArray(R.array.pref_text_size_values);
    mFontOptionValues = getResources().getStringArray(R.array.font_values);
    SubMenu subMenu = menu.findItem(R.id.menu_font_size).getSubMenu();
    String[] options = getResources().getStringArray(R.array.text_size_options);
    String initialTextSize = Preferences.Theme.getPreferredReadabilityTextSize(getActivity());
    for (int i = 0; i < options.length; i++) {
        MenuItem item = subMenu.add(R.id.menu_font_size_group, Menu.NONE, i, options[i]);
        item.setChecked(TextUtils.equals(initialTextSize, mTextSizeOptionValues[i]));
    }/*from  w w w  .  ja v  a  2s .c om*/
    subMenu.setGroupCheckable(R.id.menu_font_size_group, true, true);
    subMenu = menu.findItem(R.id.menu_font).getSubMenu();
    options = getResources().getStringArray(R.array.font_options);
    String initialTypeface = Preferences.Theme.getReadabilityTypeface(getActivity());
    for (int i = 0; i < options.length; i++) {
        MenuItem item = subMenu.add(R.id.menu_font_group, Menu.NONE, i, options[i]);
        item.setChecked(TextUtils.equals(initialTypeface, mFontOptionValues[i]));
    }
    subMenu.setGroupCheckable(R.id.menu_font_group, true, true);
}

From source file:com.cyanogenmod.effem.FmRadio.java

/**
 * Sets up the options menu when the menu button is pushed, dynamic
 * population of the station select menu
 */// w  w w. ja v a  2s  .  co  m
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    boolean result = super.onCreateOptionsMenu(menu);

    // Create and populate the band selection menu
    SubMenu subMenu = menu.addSubMenu(BASE_OPTION_MENU, FM_BAND, Menu.NONE, R.string.band_select);
    subMenu.setIcon(android.R.drawable.ic_menu_mapmode);
    subMenu.add(BAND_SELECTION_MENU, BAND_US, Menu.NONE, R.string.band_us);
    subMenu.add(BAND_SELECTION_MENU, BAND_EU, Menu.NONE, R.string.band_eu);
    subMenu.add(BAND_SELECTION_MENU, BAND_JAPAN, Menu.NONE, R.string.band_ja);
    subMenu.add(BAND_SELECTION_MENU, BAND_CHINA, Menu.NONE, R.string.band_ch);
    subMenu.setGroupCheckable(BAND_SELECTION_MENU, true, true);
    subMenu.getItem(mSelectedBand).setChecked(true);

    // Create and populate the speaker/headset selection menu if speaker supported
    if (context.getResources().getBoolean(R.bool.speaker_supported)) {
        subMenu = menu.addSubMenu(BASE_OPTION_MENU, OUTPUT_SOUND, Menu.NONE, R.string.output_select);
        subMenu.setIcon(android.R.drawable.ic_menu_mapmode);
        subMenu.add(LOUDSPEAKER_SELECTION_MENU, OUTPUT_HEADSET, Menu.NONE, R.string.output_select_default);
        subMenu.add(LOUDSPEAKER_SELECTION_MENU, OUTPUT_SPEAKER, Menu.NONE, R.string.output_select_loudspeaker);
        subMenu.setGroupCheckable(LOUDSPEAKER_SELECTION_MENU, true, true);
        subMenu.getItem(mSelectedOutput).setChecked(true);
    }

    // Create the station select menu
    subMenu = menu.addSubMenu(BASE_OPTION_MENU, STATION_SELECT, Menu.NONE, R.string.station_select);
    subMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    // Dynamically populate the station select menu
    if (mMenuAdapter.isEmpty()) {
        subMenu.setGroupEnabled(STATION_SELECTION_MENU, false);
    } else {
        subMenu.setGroupEnabled(STATION_SELECTION_MENU, true);
        for (int i = 0; i < mMenuAdapter.getCount(); i++) {
            subMenu.add(STATION_SELECTION_MENU, STATION_SELECT_MENU_ITEMS + i, Menu.NONE,
                    mMenuAdapter.getItem(i).toString());
        }
    }
    return result;
}

From source file:nl.thehyve.transmartclient.MainActivity.java

private void refreshNavigationMenu() {

    NavigationView mNavigationView = (NavigationView) findViewById(R.id.nav_view);
    final Menu menu = mNavigationView.getMenu();
    List<TransmartServer> connectedServers = getConnectedServers();

    menu.clear();//from   www . ja  v  a2 s  .c  o  m

    int order = 0;
    int group = 1;

    SubMenu serverMenu = menu.addSubMenu(Menu.NONE, order, order, getString(R.string.menu_serversSubmenu));
    order += 1;

    for (TransmartServer transmartServer : connectedServers) {
        int menuItemID = serverMenu.add(group, order, order, transmartServer.getServerLabel())
                .setIcon(R.drawable.ic_action_accounts).getItemId();
        transmartServer.setMenuItemID(menuItemID);
        order += 1;
    }
    add_server_item = serverMenu.add(group, order, order, R.string.menu_addNewServer)
            .setIcon(R.drawable.ic_action_new_account).getItemId();
    order += 1;

    serverMenu.setGroupCheckable(group, true, true);

    about_item = menu.add(Menu.NONE, order, order, R.string.menu_about).setIcon(R.drawable.ic_action_about)
            .getItemId();
}

From source file:com.dycody.android.idealnote.ListFragment.java

private void initSortingSubmenu() {
    final String[] arrayDb = getResources().getStringArray(R.array.sortable_columns);
    final String[] arrayDialog = getResources().getStringArray(R.array.sortable_columns_human_readable);
    int selected = Arrays.asList(arrayDb).indexOf(prefs.getString(Constants.PREF_SORTING_COLUMN, arrayDb[0]));

    SubMenu sortMenu = this.menu.findItem(R.id.menu_sort).getSubMenu();
    for (int i = 0; i < arrayDialog.length; i++) {
        if (sortMenu.findItem(i) == null) {
            sortMenu.add(Constants.MENU_SORT_GROUP_ID, i, i, arrayDialog[i]);
        }/*from  ww w .j  a v a  2 s  .  co m*/
        if (i == selected)
            sortMenu.getItem(i).setChecked(true);
    }
    sortMenu.setGroupCheckable(Constants.MENU_SORT_GROUP_ID, true, true);
}

From source file:org.tvbrowser.tvbrowser.TvBrowser.java

private synchronized void updateFromFilterEdit() {
    final SubMenu filters = mFilterItem.getSubMenu();

    for (int i = 0; i < FILTER_MAX_ID; i++) {
        filters.removeItem(i);/*from w w  w.j  a  v  a 2  s .c o m*/
    }

    ArrayList<ChannelFilterValues> channelFilterList = new ArrayList<ChannelFilterValues>();
    SharedPreferences filterPreferences = PrefUtils.getSharedPreferences(PrefUtils.TYPE_PREFERENCES_FILTERS,
            TvBrowser.this);
    Map<String, ?> filterValues = filterPreferences.getAll();

    for (String key : filterValues.keySet()) {
        Object values = filterValues.get(key);

        if (key.startsWith("filter.") && values instanceof String && values != null) {
            channelFilterList.add(new ChannelFilterValues(key, (String) values));
        }
    }

    Collections.sort(channelFilterList, ChannelFilterValues.CHANNEL_FILTER_VALUES_COMPARATOR);

    int groupId = 3;
    int id = 1;

    mAllFilter = new ChannelFilterValues(SettingConstants.ALL_FILTER_ID,
            getString(R.string.activity_edit_filter_list_text_all), "");

    MenuItem all = filters.add(groupId, id++, groupId, mAllFilter.toString());
    all.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            updateChannelFilter(mAllFilter, R.drawable.ic_filter_default);
            item.setChecked(true);
            return true;
        }
    });

    if (mCurrentChannelFilterId == null || mAllFilter.getId().endsWith(mCurrentChannelFilterId)) {
        all.setChecked(true);
    }

    for (final ChannelFilterValues filter : channelFilterList) {
        MenuItem item = filters.add(groupId, id++, groupId, filter.toString());

        if (mCurrentChannelFilterId != null && filter.getId().endsWith(mCurrentChannelFilterId)) {
            mFilterItem.setIcon(R.drawable.ic_filter_on);
            item.setChecked(true);
        }

        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                updateChannelFilter(filter, R.drawable.ic_filter_on);
                item.setChecked(true);

                return true;
            }
        });
    }

    FILTER_MAX_ID = id;

    filters.setGroupCheckable(groupId, true, true);
}