Example usage for android.view Menu setGroupCheckable

List of usage examples for android.view Menu setGroupCheckable

Introduction

In this page you can find the example usage for android.view Menu 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:org.gdg.frisbee.android.common.GdgNavDrawerActivity.java

private void setupDrawerContent(NavigationView navigationView) {

    Menu menu = navigationView.getMenu();
    menu.add(GROUP_ID, Const.DRAWER_HOME, Menu.NONE, R.string.home_gdg).setIcon(R.drawable.ic_drawer_home_gdg);
    menu.add(GROUP_ID, Const.DRAWER_GDE, Menu.NONE, R.string.gde).setIcon(R.drawable.ic_drawer_gde);
    menu.add(GROUP_ID, Const.DRAWER_PULSE, Menu.NONE, R.string.pulse).setIcon(R.drawable.ic_drawer_pulse);

    //adding special events in navigation drawer
    final ArrayList<TaggedEventSeries> currentEventSeries = App.getInstance().currentTaggedEventSeries();
    for (TaggedEventSeries taggedEventSeries : currentEventSeries) {
        menu.add(GROUP_ID, taggedEventSeries.getDrawerId(), Menu.NONE, taggedEventSeries.getTitleResId())
                .setIcon(taggedEventSeries.getDrawerIconResId());
    }//from www . j a va  2  s  . c  o  m

    SubMenu subMenu = menu.addSubMenu(GAMES_GROUP_ID, Const.DRAWER_SUBMENU_GAMES, Menu.NONE,
            R.string.drawer_subheader_games);
    subMenu.add(GAMES_GROUP_ID, Const.DRAWER_ACHIEVEMENTS, Menu.NONE, R.string.achievements)
            .setIcon(R.drawable.ic_drawer_achievements);
    subMenu.add(GAMES_GROUP_ID, Const.DRAWER_ARROW, Menu.NONE, R.string.arrow)
            .setIcon(R.drawable.ic_drawer_arrow).setCheckable(true);

    menu.add(SETTINGS_GROUP_ID, Const.DRAWER_SETTINGS, Menu.NONE, R.string.settings)
            .setIcon(R.drawable.ic_drawer_settings);
    menu.add(SETTINGS_GROUP_ID, Const.DRAWER_HELP, Menu.NONE, R.string.help).setIcon(R.drawable.ic_drawer_help);
    menu.add(SETTINGS_GROUP_ID, Const.DRAWER_FEEDBACK, Menu.NONE, R.string.feedback)
            .setIcon(R.drawable.ic_drawer_feedback);
    menu.add(SETTINGS_GROUP_ID, Const.DRAWER_ABOUT, Menu.NONE, R.string.about)
            .setIcon(R.drawable.ic_drawer_about);

    menu.setGroupCheckable(GROUP_ID, true, true);

    final int selectedDrawerItemId = getIntent().getIntExtra(EXTRA_SELECTED_DRAWER_ITEM_ID, Const.DRAWER_HOME);
    final MenuItem selectedItem = menu.findItem(selectedDrawerItemId);
    if (selectedItem != null) {
        selectedItem.setChecked(true);
    }

    navigationView.setNavigationItemSelectedListener(

            new NavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(MenuItem menuItem) {
                    onDrawerItemClick(menuItem);
                    mDrawerLayout.closeDrawers();
                    return true;
                }
            });
    View headerView = navigationView.getHeaderView(0);
    mDrawerImage = ButterKnife.findById(headerView, R.id.navdrawer_image);
    mDrawerUserPicture = ButterKnife.findById(headerView, R.id.navdrawer_user_picture);
}

From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java

public void refreshDrawer() {
    Menu menu = navView.getMenu();
    menu.clear();/*from  w ww.  j  a v a 2  s  .c  o  m*/
    actionViewStateManager.deselectCurrentActionView();

    int order = 0;
    ArrayList<String> storageDirectories = mainActivity.getStorageDirectories();
    phoneStorageCount = 0;
    for (String file : storageDirectories) {
        if (file.contains(OTGUtil.PREFIX_OTG)) {
            addNewItem(menu, STORAGES_GROUP, order++, "OTG", new MenuMetadata(file),
                    R.drawable.ic_usb_white_24dp, R.drawable.ic_show_chart_black_24dp);
            continue;
        }

        File f = new File(file);
        String name;
        @DrawableRes
        int icon1;
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)
                || "/mnt/sdcard".equals(file)) {
            name = resources.getString(R.string.storage);
            icon1 = R.drawable.ic_phone_android_white_24dp;
        } else if ("/storage/sdcard1".equals(file)) {
            name = resources.getString(R.string.extstorage);
            icon1 = R.drawable.ic_sd_storage_white_24dp;
        } else if ("/".equals(file)) {
            name = resources.getString(R.string.rootdirectory);
            icon1 = R.drawable.ic_drawer_root_white;
        } else {
            name = f.getName();
            icon1 = R.drawable.ic_sd_storage_white_24dp;
        }

        if (f.isDirectory() || f.canExecute()) {
            addNewItem(menu, STORAGES_GROUP, order++, name, new MenuMetadata(file), icon1,
                    R.drawable.ic_show_chart_black_24dp);
            if (phoneStorageCount == 0)
                firstPath = file;
            else if (phoneStorageCount == 1)
                secondPath = file;

            phoneStorageCount++;
        }
    }
    dataUtils.setStorages(storageDirectories);

    if (dataUtils.getServers().size() > 0) {
        Collections.sort(dataUtils.getServers(), new BookSorter());
        synchronized (dataUtils.getServers()) {
            for (String[] file : dataUtils.getServers()) {
                addNewItem(menu, SERVERS_GROUP, order++, file[0], new MenuMetadata(file[1]),
                        R.drawable.ic_settings_remote_white_24dp, R.drawable.ic_edit_24dp);
            }
        }
    }

    ArrayList<String[]> accountAuthenticationList = new ArrayList<>();

    if (CloudSheetFragment.isCloudProviderAvailable(mainActivity)) {
        for (CloudStorage cloudStorage : dataUtils.getAccounts()) {
            @DrawableRes
            int deleteIcon = R.drawable.ic_delete_grey_24dp;

            if (cloudStorage instanceof Dropbox) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_DROPBOX,
                        new MenuMetadata(CloudHandler.CLOUD_PREFIX_DROPBOX + "/"),
                        R.drawable.ic_dropbox_white_24dp, deleteIcon);

                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_DROPBOX,
                        CloudHandler.CLOUD_PREFIX_DROPBOX + "/", });
            } else if (cloudStorage instanceof Box) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_BOX,
                        new MenuMetadata(CloudHandler.CLOUD_PREFIX_BOX + "/"), R.drawable.ic_box_white_24dp,
                        deleteIcon);

                accountAuthenticationList.add(
                        new String[] { CloudHandler.CLOUD_NAME_BOX, CloudHandler.CLOUD_PREFIX_BOX + "/", });
            } else if (cloudStorage instanceof OneDrive) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_ONE_DRIVE,
                        new MenuMetadata(CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/"),
                        R.drawable.ic_onedrive_white_24dp, deleteIcon);

                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_ONE_DRIVE,
                        CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/", });
            } else if (cloudStorage instanceof GoogleDrive) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_GOOGLE_DRIVE,
                        new MenuMetadata(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/"),
                        R.drawable.ic_google_drive_white_24dp, deleteIcon);

                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_GOOGLE_DRIVE,
                        CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/", });
            }
        }
        Collections.sort(accountAuthenticationList, new BookSorter());
    }

    if (mainActivity.getBoolean(PREFERENCE_SHOW_SIDEBAR_FOLDERS)) {
        if (dataUtils.getBooks().size() > 0) {

            Collections.sort(dataUtils.getBooks(), new BookSorter());

            synchronized (dataUtils.getBooks()) {
                for (String[] file : dataUtils.getBooks()) {
                    addNewItem(menu, FOLDERS_GROUP, order++, file[0], new MenuMetadata(file[1]),
                            R.drawable.ic_folder_white_24dp, R.drawable.ic_edit_24dp);
                }
            }
        }
    }

    Boolean[] quickAccessPref = TinyDB.getBooleanArray(mainActivity.getPrefs(), QuickAccessPref.KEY,
            QuickAccessPref.DEFAULT);

    if (mainActivity.getBoolean(PREFERENCE_SHOW_SIDEBAR_QUICKACCESSES)) {
        if (quickAccessPref[0]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.quick, new MenuMetadata("5"),
                    R.drawable.ic_star_white_24dp, null);
        }
        if (quickAccessPref[1]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.recent, new MenuMetadata("6"),
                    R.drawable.ic_history_white_24dp, null);
        }
        if (quickAccessPref[2]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.images, new MenuMetadata("0"),
                    R.drawable.ic_photo_library_white_24dp, null);
        }
        if (quickAccessPref[3]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.videos, new MenuMetadata("1"),
                    R.drawable.ic_video_library_white_24dp, null);
        }
        if (quickAccessPref[4]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.audio, new MenuMetadata("2"),
                    R.drawable.ic_library_music_white_24dp, null);
        }
        if (quickAccessPref[5]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.documents, new MenuMetadata("3"),
                    R.drawable.ic_library_books_white_24dp, null);
        }
        if (quickAccessPref[6]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.apks, new MenuMetadata("4"),
                    R.drawable.ic_apk_library_white_24dp, null);
        }
    }

    addNewItem(menu, LASTGROUP, order++, R.string.ftp, new MenuMetadata(() -> {
        FragmentTransaction transaction2 = mainActivity.getSupportFragmentManager().beginTransaction();
        transaction2.replace(R.id.content_frame, new FtpServerFragment());
        mainActivity.getAppbar().getAppbarLayout().animate().translationY(0)
                .setInterpolator(new DecelerateInterpolator(2)).start();
        pending_fragmentTransaction = transaction2;
        if (!isDrawerLocked)
            close();
        else
            onDrawerClosed();
    }), R.drawable.ic_ftp_white_24dp, null);

    addNewItem(menu, LASTGROUP, order++, R.string.apps, new MenuMetadata(() -> {
        FragmentTransaction transaction2 = mainActivity.getSupportFragmentManager().beginTransaction();
        transaction2.replace(R.id.content_frame, new AppsListFragment());
        mainActivity.getAppbar().getAppbarLayout().animate().translationY(0)
                .setInterpolator(new DecelerateInterpolator(2)).start();
        pending_fragmentTransaction = transaction2;
        if (!isDrawerLocked)
            close();
        else
            onDrawerClosed();
    }), R.drawable.ic_android_white_24dp, null);

    addNewItem(menu, LASTGROUP, order++, R.string.setting, new MenuMetadata(() -> {
        Intent in = new Intent(mainActivity, PreferencesActivity.class);
        mainActivity.startActivity(in);
        mainActivity.finish();
    }), R.drawable.ic_settings_white_24dp, null);

    for (int i = 0; i < navView.getMenu().size(); i++) {
        navView.getMenu().getItem(i).setEnabled(true);
    }

    for (int group : GROUPS) {
        menu.setGroupCheckable(group, true, true);
    }

    MenuItem item = navView.getSelected();
    if (item != null) {
        item.setChecked(true);
        actionViewStateManager.selectActionView(item);
        isSomethingSelected = true;
    }
}