Example usage for android.view MenuItem setChecked

List of usage examples for android.view MenuItem setChecked

Introduction

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

Prototype

public MenuItem setChecked(boolean checked);

Source Link

Document

Control whether this item is shown with a check mark.

Usage

From source file:dg.shenm233.mmaps.ui.MainActivity.java

private void initNavigationView() {
    NavigationView nv = (NavigationView) mDrawerLayout.findViewById(R.id.navigation_view);
    nv.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from w ww.j  av a2 s .co m*/
        public boolean onNavigationItemSelected(MenuItem item) {
            MapsModule mapsModule = ((MapsFragment) getMapsFragment()).getMapsModule();
            int itemId = item.getItemId();
            boolean isChecked = item.isChecked();
            if (itemId == R.id.navigation_satellite) {
                if (!isChecked) {
                    mapsModule.setMapType(MapsModule.MAP_TYPE_SATELLITE);
                } else {
                    mapsModule.setMapType(MapsModule.MAP_TYPE_NORMAL);
                }
                item.setChecked(!isChecked);
                mDrawerLayout.closeDrawers();
            } else if (itemId == R.id.navigation_traffic) {
                mapsModule.setTrafficEnabled(!isChecked);
                item.setChecked(!isChecked);
                mDrawerLayout.closeDrawers();
            } else if (itemId == R.id.navigation_offline) {
                Intent intent = new Intent(MainActivity.this, OfflineMapActivity.class);
                startActivity(intent);
            } else if (itemId == R.id.navigation_settings) {
                Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
                startActivity(intent);
            } else if (itemId == R.id.navigation_favorite) {
                mDrawerLayout.closeDrawers();
                switchToFavorite();
            }
            return true;
        }
    });
}

From source file:io.demiseq.jetreader.activities.MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    setIntent(intent);// w ww  .ja  v a2  s.co m
    boolean isOpenFromNotification = intent.getBooleanExtra("favorite", false);
    if (isOpenFromNotification) {
        GetSubscription();
        new getAllMangas().execute();
        NavigationView view = (NavigationView) findViewById(R.id.navigation_view);
        Menu menu = view.getMenu();
        for (int i = 0; i < menu.size(); i++) {
            MenuItem item = menu.getItem(i);
            if (item.getItemId() == R.id.drawer_feeds) {
                savedMenuId = item.getItemId();
                item.setChecked(true);
            }
        }
    }
}

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

@Override
public void onBackPressed() {
    if (mFragManager.getBackStackEntryCount() > 0) {
        clearBackStack();//from   ww  w. j a  va  2s. c  o  m
        return;
    }

    if (!mFragmentTag.equals(Extras.TAG_WALLPAPERS)) {
        mPosition = 0;
        setFragment(getFragment(mPosition));
        MenuItem item = mBottomNavigationView.getMenu().findItem(mapPositionToMenuId());
        if (item != null) {
            item.setChecked(true);
        }
        mToolbarTitle.setText(getToolbarTitle());
        return;
    }
    super.onBackPressed();
}

From source file:com.irateam.vkplayer.activities.ListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);

    emptyView = findViewById(R.id.empty_list_view);
    emptyView.setVisibility(View.GONE);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from   w w  w.ja  va2s  .  c  o m
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationOnClickListener(v -> drawerLayout.openDrawer(GravityCompat.START));

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    navigationView = (NavigationView) findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(this);
    roundImageView = (RoundImageView) findViewById(R.id.navigation_drawer_header_avatar);
    userFullName = (TextView) findViewById(R.id.navigation_drawer_header_full_name);
    userVkId = (TextView) findViewById(R.id.navigation_drawer_header_id);

    new UserService(this).getCurrentUser((user) -> {
        ImageLoader.getInstance().displayImage(user.photo_100, roundImageView);
        userFullName.setText(user.first_name + " " + user.last_name);
        userVkId.setText(UserService.USER_LINK + String.valueOf(user.id));
    });

    ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawerLayout.setDrawerListener(drawerToggle);
    drawerToggle.syncState();

    coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator_layout);

    playerController = new PlayerController(this, findViewById(R.id.player_panel));
    playerController.rootView.setVisibility(View.GONE);
    playerController.setFabOnClickListener(v -> startActivity(new Intent(this, AudioActivity.class)));

    refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_layout);
    refreshLayout.setColorSchemeResources(R.color.accent, R.color.primary);
    refreshLayout.setOnRefreshListener(() -> {
        if (actionMode != null)
            actionMode.finish();

        if (audioAdapter.isSortMode())
            audioAdapter.setSortMode(false);

        audioService.repeatLastRequest();
    });

    listView = (DragSortListView) findViewById(R.id.list);
    listView.setAdapter(audioAdapter);
    listView.setOnItemClickListener((parent, view, position, id) -> {
        List<Audio> list = audioAdapter.getListByPosition(position);
        playerService.setPlaylist(list);
        playerService.play(audioAdapter.getPosition(position));
        if (actionMode != null)
            actionMode.finish();

        MenuItem item = navigationView.getMenu().getItem(0);
        boolean isFromSearch = audioAdapter.belongsToSearchList(position);
        if (!isFromSearch) {
            item.setChecked(true);
            getSupportActionBar().setTitle(item.getTitle());
        }
        if (!isFromSearch || item.isChecked()) {
            audioAdapter.setOriginalList(list);
        }
    });
    listView.setOnItemLongClickListener((parent, view, position, id) -> {
        performCheck(position);
        return true;
    });
    listView.setDropListener(audioAdapter::drop);

    audioAdapter.setCoverCheckListener(this::performCheck);
    audioService.addListener(this);

    downloadFinishedReceiver = new DownloadFinishedReceiver() {
        @Override
        public void onDownloadFinished(Audio audio) {
            audioAdapter.updateAudioById(audio);
        }
    };
    registerReceiver(downloadFinishedReceiver, new IntentFilter(DownloadService.DOWNLOAD_FINISHED));

    startService(new Intent(this, PlayerService.class));
    bindService(new Intent(this, PlayerService.class), this, BIND_AUTO_CREATE);
}

From source file:com.eugene.fithealthmaingit.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (savedInstanceState != null) {
        mNavItemId = savedInstanceState.getInt(NAV_ITEM_ID);
        isFirstFragmentAdded = savedInstanceState.getBoolean(FIRST_FRAGMENT_ADDED);
    } else {/*ww w .  ja va 2 s  . c om*/
        mNavItemId = R.id.nav_journal;
    }

    mNavigationDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    // Set menu header text to User Name
    TextView mHeaderText = (TextView) findViewById(R.id.txtName);
    mHeaderText.setText(PreferenceManager.getDefaultSharedPreferences(this).getString(Globals.USER_NAME, ""));

    /**
     * Initiate NavigationView
     * Inflate Menu based on FitBit connection status
     */
    NavigationView mNavigationView = (NavigationView) findViewById(R.id.nav);

    if (PreferenceManager.getDefaultSharedPreferences(this).getString("FITBIT_ACCESS_TOKEN", "").equals("")) {
        mNavigationView.inflateMenu(R.menu.drawer);
    } else {
        mNavigationView.inflateMenu(R.menu.drawer_fitbit);
    }
    mNavigationView.getMenu().findItem(mNavItemId).setChecked(true);
    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            if (menuItem.getItemId() != R.id.nav_settings) {
                mNavItemId = menuItem.getItemId();
                switchFragment(menuItem.getItemId());
                menuItem.setChecked(true);
                Fragment loading = new FragmentBlankLoading();
                Bundle b = new Bundle();
                b.putInt(NAV_ITEM_ID, mNavItemId);
                loading.setArguments(b);
                getSupportFragmentManager().beginTransaction().replace(R.id.container, loading).commit();
            } else {
                startActivity(new Intent(MainActivity.this, UserInformationActivity.class));
            }
            handleNavigationDrawer();
            return false;
        }
    });

    // Nav Menu Fonts
    Menu m = mNavigationView.getMenu();
    for (int i = 0; i < m.size(); i++) {
        MenuItem mi = m.getItem(i);

        //for aapplying a font to subMenu ...
        SubMenu subMenu = mi.getSubMenu();
        if (subMenu != null && subMenu.size() > 0) {
            for (int j = 0; j < subMenu.size(); j++) {
                MenuItem subMenuItem = subMenu.getItem(j);
                applyFontToMenuItem(subMenuItem);
            }
        }

        //the method we have create in activity
        applyFontToMenuItem(mi);
    }
    switchFragment(mNavItemId);

    /**
     * Handles Home Screen Widget
     * Search and Add
     */
    Intent widgetIntent = this.getIntent();
    if (widgetIntent != null) {
        if (widgetIntent.getAction() != null && savedInstanceState == null) {
            if (widgetIntent.getAction().equals(FitHealthWidget.ACTION_SEARCH)) {
                // Post delay to allow the app to open and not interfere with animation
                final Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        getSupportFragmentManager().beginTransaction()
                                .replace(R.id.containerSearch, new FragmentSearch()).addToBackStack(null)
                                .commit();
                    }
                }, 100);
            }
            if (widgetIntent.getAction().equals(FitHealthWidget.ACTION_ADD)) {
                widgetAdd();
            }
        }
    }
}

From source file:com.grarak.kerneladiutor.fragments.tools.customcontrols.CustomControlsFragment.java

private CardView getCard(final Controls.ControlItem controlItem) {
    CardView cardView = new CardView(getActivity());
    cardView.setOnMenuListener(new CardView.OnMenuListener() {

        @Override/*  w  w  w.ja  va2 s  . co  m*/
        public void onMenuReady(CardView cardView, PopupMenu popupMenu) {
            Menu menu = popupMenu.getMenu();
            menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.edit));
            final MenuItem onBoot = menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.on_boot))
                    .setCheckable(true);
            onBoot.setChecked(controlItem.isOnBootEnabled());
            menu.add(Menu.NONE, 2, Menu.NONE, getString(R.string.export));
            menu.add(Menu.NONE, 3, Menu.NONE, getString(R.string.delete));

            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case 0:
                        edit(controlItem);
                        break;
                    case 1:
                        onBoot.setChecked(!onBoot.isChecked());
                        controlItem.enableOnBoot(onBoot.isChecked());
                        mControlsProvider.commit();
                        break;
                    case 2:
                        mExportItem = controlItem;
                        requestPermission(0, Manifest.permission.WRITE_EXTERNAL_STORAGE);
                        break;
                    case 3:
                        mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.sure_question),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                    }
                                }, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        delete(controlItem.getUniqueId());
                                    }
                                }, new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialog) {
                                        mDeleteDialog = null;
                                    }
                                }, getActivity()).setTitle(getString(R.string.delete));
                        mDeleteDialog.show();
                        break;
                    }
                    return false;
                }
            });
        }
    });
    return cardView;
}

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);/*from  w w  w  . j  a va  2  s .  c om*/
        item.setChecked(c.isSelected());
    }
}

From source file:com.secupwn.aimsicd.ui.activities.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.toggle_attack_detection:
        monitorCell();//w w  w .jav  a  2  s .c o  m
        item.setChecked(mAimsicdService.isMonitoringCell());
        break;
    case R.id.toggle_cell_tracking:
        trackCell();
        item.setChecked(mAimsicdService.isTrackingCell());
        break;
    case R.id.settings:
        Intent settingsIntent = new Intent(this, SettingsActivity.class);
        startActivity(settingsIntent);
        break;
    case R.id.about:
        Intent aboutIntent = new Intent(this, AboutActivity.class);
        startActivity(aboutIntent);
        break;
    case R.id.debugging:
        Intent i = new Intent(this, DebugLogs.class);
        startActivity(i);
        break;
    }

    return mDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
}

From source file:com.example.hzh.materialdesigndemo.MainActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from  w w w.  j av a2 s .c om*/
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            Intent intent;
            switch (menuItem.getItemId()) {
            case R.id.nav_login:
                intent = new Intent(MainActivity.this, TextInputLayoutActivity.class);
                startActivity(intent);
                break;
            case R.id.nav_test:
                intent = new Intent(MainActivity.this, TestActivity.class);
                startActivity(intent);
                break;
            }
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}

From source file:com.antew.redditinpictures.library.ui.RedditFragmentActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    item.setChecked(true);

    switch (item.getItemId()) {
    case R.id.change_view:
        switch (mActiveViewType) {
        case LIST:
            EasyTracker.getInstance(this)
                    .send(MapBuilder.createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                            Constants.Analytics.Action.CHANGE_VIEW, Constants.Analytics.Label.GRID, null)
                            .build());// w w  w  .  jav a  2s . co  m
            break;
        case GRID:
            EasyTracker.getInstance(this)
                    .send(MapBuilder.createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                            Constants.Analytics.Action.CHANGE_VIEW, Constants.Analytics.Label.LIST, null)
                            .build());
            break;
        }
        changeViewType(mActiveViewType == ViewType.LIST ? ViewType.GRID : ViewType.LIST);
        return true;
    case R.id.settings:
        EasyTracker.getInstance(this)
                .send(MapBuilder.createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                        Constants.Analytics.Action.OPEN_SETTINGS, null, null).build());
        startPreferences();
        return true;
    case R.id.refresh_all:
        EasyTracker.getInstance(this)
                .send(MapBuilder.createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                        Constants.Analytics.Action.REFRESH_POSTS, null, null).build());
        // Notify our image fragment(s) that they need
        // to remove references to the now stale data
        mBus.post(new ForcePostRefreshEvent());
        produceRequestInProgressEvent();
        forceRefreshCurrentSubreddit();
        return true;
    case R.id.login:
        if (RedditLoginInformation.isLoggedIn()) {
            EasyTracker.getInstance(this)
                    .send(MapBuilder
                            .createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                                    Constants.Analytics.Action.LOGIN, Constants.Analytics.Label.LOGGED_IN, null)
                            .build());
        } else {
            EasyTracker.getInstance(this)
                    .send(MapBuilder.createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                            Constants.Analytics.Action.LOGIN, Constants.Analytics.Label.NOT_LOGGED_IN, null)
                            .build());
        }
        handleLoginAndLogout();
        return true;
    // fall through
    case R.id.category_hot:
    case R.id.category_new:
    case R.id.category_rising:
    case R.id.category_top_hour:
    case R.id.category_top_today:
    case R.id.category_top_week:
    case R.id.category_top_month:
    case R.id.category_top_year:
    case R.id.category_top_all_time:
    case R.id.category_controversial_hour:
    case R.id.category_controversial_today:
    case R.id.category_controversial_week:
    case R.id.category_controversial_month:
    case R.id.category_controversial_year:
    case R.id.category_controversial_all_time:
        if (RedditSort.contains(item.getItemId())) {
            produceRequestInProgressEvent();
            RedditSort.SortCriteria sortCriteria = RedditSort.get(item.getItemId());
            EasyTracker
                    .getInstance(
                            this)
                    .send(MapBuilder.createEvent(Constants.Analytics.Category.ACTION_BAR_ACTION,
                            Constants.Analytics.Action.OPEN_SUBREDDIT,
                            mSelectedSubreddit + "/" + Strings.toString(sortCriteria.getCategory()) + "/"
                                    + Strings.toString(sortCriteria.getAge()),
                            null).build());
            loadSubreddit(mSelectedSubreddit, sortCriteria.getCategory(), sortCriteria.getAge());
            return true;
        } else {
            Ln.e("Unable to get sorting criteria for menu item id: " + item.getItemId()
                    + ", unable to load subreddit");
            return super.onOptionsItemSelected(item);
        }
    default:
        return super.onOptionsItemSelected(item);
    }
}