Example usage for android.view MenuItem setCheckable

List of usage examples for android.view MenuItem setCheckable

Introduction

In this page you can find the example usage for android.view MenuItem setCheckable.

Prototype

public MenuItem setCheckable(boolean checkable);

Source Link

Document

Control whether this item can display a check mark.

Usage

From source file:com.vrem.wifianalyzer.navigation.NavigationMenuView.java

public void setCurrentNavigationMenu(@NonNull NavigationMenu navigationMenu) {
    this.currentNavigationMenu = navigationMenu;
    Menu menu = navigationView.getMenu();
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        item.setCheckable(navigationMenu.ordinal() == i);
        item.setChecked(navigationMenu.ordinal() == i);
    }//from   w w w  . j  a  v a 2  s  . c  om
}

From source file:nz.ac.auckland.lablet.ExperimentAnalysisFragment.java

private void showDataMenu(ExperimentAnalysis experimentAnalysis) {
    final View menuView = getActivity().findViewById(R.id.action_data);
    PopupMenu popup = new PopupMenu(getActivity(), menuView);
    final ViewPager pager = ((ExperimentAnalysisActivity) getActivity()).getViewPager();

    final List<ExperimentAnalysis.AnalysisEntry> analysisList = experimentAnalysis
            .getAnalysisRunAt(analysisRef.runId).analysisList;
    int i = 0;/*from  ww  w.j  a va2  s  .  co m*/
    for (ExperimentAnalysis.AnalysisEntry analysisEntry : analysisList) {
        MenuItem item = popup.getMenu().add(1, i, Menu.NONE, analysisEntry.analysis.getDisplayName());
        item.setCheckable(true);

        if (pager.getCurrentItem() == i)
            item.setChecked(true);
        i++;
    }
    popup.getMenu().setGroupCheckable(1, true, true);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            int item = menuItem.getItemId();
            pager.requestLayout();
            pager.setCurrentItem(item, true);
            return false;
        }
    });
    popup.show();
}

From source file:org.digitalcampus.oppia.utils.ui.DrawerMenuManager.java

public void onPrepareOptionsMenu(Menu menu, Integer currentOption, Map<Integer, MenuOption> options) {

    if (options != null)
        this.customOptions = options;

    Menu drawerMenu = navigationView.getMenu();
    MenuItem itemLogout = drawerMenu.findItem(R.id.menu_logout);
    MenuItem itemSettings = drawerMenu.findItem(R.id.menu_settings);
    MenuItem itemMonitor = drawerMenu.findItem(R.id.menu_monitor);
    MenuItem itemCourseDownload = drawerMenu.findItem(R.id.menu_download);
    MenuItem itemLanguageDialog = drawerMenu.findItem(R.id.menu_language);

    if (currentOption != null) {
        MenuItem current = drawerMenu.findItem(currentOption);
        if (current != null) {
            current.setCheckable(true);
            current.setChecked(true);/*w ww.j a  v  a 2s. co  m*/
        }
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(drawerAct);
    itemLogout
            .setVisible(prefs.getBoolean(PrefsActivity.PREF_LOGOUT_ENABLED, MobileLearning.MENU_ALLOW_LOGOUT));
    itemSettings.setVisible(MobileLearning.MENU_ALLOW_SETTINGS);
    itemMonitor.setVisible(MobileLearning.MENU_ALLOW_MONITOR);
    itemCourseDownload.setVisible(MobileLearning.MENU_ALLOW_COURSE_DOWNLOAD);
    itemLanguageDialog.setVisible(customOptions.containsKey(R.id.menu_language));
}

From source file:com.jadebyte.popularmovies.activities.MainActivity.java

private void showLabelsPopup() {
    View view = findViewById(R.id.action_sort);
    PopupMenu popup = new PopupMenu(this, view);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//  w  w  w.j  a  va  2 s.c o m
        public boolean onMenuItemClick(MenuItem item) {
            String moviesUrl = null;

            switch (item.getItemId()) {
            case R.id.sort_popular:
                moviesUrl = Constants.URLS.getPopularUrl();
                checkItemIndex = 0;
                break;

            case R.id.sort_rating:
                moviesUrl = Constants.URLS.getHighestRatingUrl();
                checkItemIndex = 1;
                break;

            case R.id.sort_favourites:
                checkItemIndex = 2;

            default:
                break;
            }

            if (!item.isChecked()) {
                if (moviesUrl != null) {
                    launchMovieListFragment(moviesUrl);

                } else {
                    launchFavoriteListFragment();
                }
                return true;
            } else {
                return false;
            }
        }
    });
    popup.inflate(R.menu.sort_menu);
    popup.show();
    final MenuItem popupItem = popup.getMenu().getItem(checkItemIndex);
    popupItem.setCheckable(true);
    popupItem.setChecked(true);
}

From source file:com.classiqo.nativeandroid_32bitz.ui.ActionBarCastActivity.java

private void populateDrawerItems(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from   www. ja  v a2  s .  c o  m*/
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setCheckable(true);
            mItemToOpenWhenDrawerCloses = menuItem.getItemId();
            mDrawerLayout.closeDrawers();

            return true;
        }
    });

    if (MusicPlayerActivity.class.isAssignableFrom(getClass())) {
        navigationView.setCheckedItem(R.id.navigation_allmusic);
    } else if (PlaceholderActivity.class.isAssignableFrom(getClass())) {
        navigationView.setCheckedItem(R.id.navigation_playlists);
    }
}

From source file:at.tm.android.fitacity.MainActivity.java

/**
 * Method to display the category data//from   w w  w .  j a va 2  s. co m
 *
 * @param categories - category list to display
 */
private void setCategoriesMenu(List<Category> categories) {
    // If the provided category data is valid
    if (categories != null) {
        mCategoryMenuMap = new HashMap<>();

        // Add the category data to the main menu
        for (Category category : categories) {
            int itemId = View.generateViewId();

            mCategoryMenuMap.put(itemId, category);
            MenuItem menuItem = mNavigationView.getMenu().getItem(0).getSubMenu().add(0, itemId, 0,
                    category.getName());

            menuItem.setCheckable(true);
            menuItem.setIcon(R.drawable.ic_dashboard);

            // If the selected category id is the actual category id, set the menu item to checked
            if (category.getId() == mSelectedCategoryId) {
                menuItem.setChecked(true);
            }
        }
    }

    if (mSelectedCategoryId == FAVORITE_CATEGORY_ID) {
        MenuItem menuItem = mNavigationView.getMenu().getItem(1);
        menuItem.setChecked(true);
    }
}

From source file:com.maxwen.wallpaper.board.activities.WallpaperBoardActivity.java

public void fileCategoryMenu(Menu menu) {
    List<Category> categories = new Database(this).getCategories();
    for (Category c : categories) {
        menu.removeItem(MENU_CATEGORY_START + c.getId());
        MenuItem item = menu.add(Menu.NONE, MENU_CATEGORY_START + c.getId(), Menu.NONE, c.getName());
        item.setCheckable(true);
        item.setChecked(c.isSelected());
    }/*from  w ww .j  a  v a2 s  . co  m*/
}

From source file:com.grarak.kerneladiutor.activities.NavigationActivity.java

private void appendFragments(boolean setShortcuts) {
    sActualFragments.clear();//  w  w w .  j  a  v a2  s.  c o  m
    Menu menu = mNavigationView.getMenu();
    menu.clear();

    SubMenu lastSubMenu = null;
    for (NavigationFragment navigationFragment : sFragments) {
        Fragment fragment = navigationFragment.mFragment;
        int id = navigationFragment.mId;

        Drawable drawable = ContextCompat.getDrawable(this,
                Utils.DONATED && Prefs.getBoolean("section_icons", false, this)
                        && navigationFragment.mDrawable != 0 ? navigationFragment.mDrawable
                                : R.drawable.ic_blank);

        if (fragment == null) {
            lastSubMenu = menu.addSubMenu(id);
            sActualFragments.put(id, null);
        } else if (Prefs.getBoolean(fragment.getClass().getSimpleName() + "_enabled", true, this)) {
            MenuItem menuItem = lastSubMenu == null ? menu.add(0, id, 0, id) : lastSubMenu.add(0, id, 0, id);
            menuItem.setIcon(drawable);
            menuItem.setCheckable(true);
            if (mSelection != 0) {
                mNavigationView.setCheckedItem(mSelection);
            }
            sActualFragments.put(id, fragment);
        }
    }
    if (setShortcuts) {
        setShortcuts();
    }
}

From source file:uk.ac.horizon.artcodes.activity.NavigationActivity.java

private void updateAccounts() {
    final Menu menu = binding.navigation.getMenu();
    final MenuItem libraries = menu.findItem(R.id.nav_libraries);
    final SubMenu subMenu = libraries.getSubMenu();

    while (subMenu.size() > 0) {
        subMenu.removeItem(subMenu.getItem(0).getItemId());
    }/*w  w  w  .j a  v  a2  s . c o m*/

    final List<Account> accounts = getServer().getAccounts();
    for (int index = 0; index < accounts.size(); index++) {
        final Account account = accounts.get(index);
        final MenuItem menuItem = subMenu.add(R.id.navigation, index, Menu.NONE, account.getDisplayName());
        if (account.getId().equals("local")) {
            menuItem.setIcon(R.drawable.ic_folder_24dp);
        } else {
            menuItem.setIcon(R.drawable.ic_cloud_24dp);
        }
        menuItem.setCheckable(true);
    }

    final MenuItem menuItem = subMenu.add(R.id.navigation, R.id.nav_addaccount, Menu.NONE,
            R.string.nav_addaccount);
    menuItem.setIcon(R.drawable.ic_add_24dp);

    for (int i = 0, count = binding.navigation.getChildCount(); i < count; i++) {
        final View child = binding.navigation.getChildAt(i);
        if (child != null && child instanceof ListView) {
            final ListView menuView = (ListView) child;
            final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter();
            final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter();
            wrapped.notifyDataSetChanged();
        }
    }

    getServer().loadRecent(new LoadCallback<List<String>>() {
        @Override
        public void loaded(List<String> item) {
            final MenuItem recent = menu.findItem(R.id.nav_recent);
            if (recent != null) {
                recent.setVisible(!item.isEmpty());
            }
        }

        @Override
        public void error(Throwable e) {
            GoogleAnalytics.trackException(e);
        }
    });
    getServer().loadStarred(new LoadCallback<List<String>>() {
        @Override
        public void loaded(List<String> item) {
            final MenuItem starred = menu.findItem(R.id.nav_starred);
            if (starred != null) {
                starred.setVisible(!item.isEmpty());
            }
        }

        @Override
        public void error(Throwable e) {
            GoogleAnalytics.trackException(e);
        }
    });
}

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

public void showAudioPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    Menu menu = popup.getMenu();//from   w  w  w  .  j  ava 2  s .  c o m
    menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio);
    final MenuItem backgroundAudioItem = menu.findItem(0);
    backgroundAudioItem.setCheckable(true);
    backgroundAudioItem.setChecked(enableBackgroundAudio);
    OnMenuItemClickListener clickListener = new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item == backgroundAudioItem) {
                enableBackgroundAudio = !item.isChecked();
                return true;
            }
            return false;
        }
    };
    configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO);
    popup.show();
}