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:com.biscofil.defcon2016.MainActivity.java

public void selectDrawerItem(MenuItem menuItem) {
    if (menuItem.getItemId() == R.id.menu_web) {
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(getString(R.string.web_url)));
        startActivity(i);/*from  ww w . ja va2  s . c o m*/
    } else if (!menuItem.isChecked()) {
        switch (menuItem.getItemId()) {
        case R.id.menu_menu:
            setFragmentContent(this, Menu_fragment.class, menuItem, true);
            break;
        case R.id.menu_meter:
            setFragmentContent(this, Meter_fragment.class, menuItem, false);
            break;
        case R.id.menu_map:
            setFragmentContent(this, Map_fragment.class, menuItem, false);
            break;
        case R.id.menu_guida:
            setFragmentContent(this, Guida_fragment.class, menuItem, false);
            break;
        case R.id.menu_calc:
            setFragmentContent(this, GuidaCalcoloIndice_fragment.class, menuItem, false);
            break;
        case R.id.menu_license:
            setFragmentContent(this, Licenze_fragment.class, menuItem, false);
            break;
        case R.id.menu_credits:
            setFragmentContent(this, Credits_fragment.class, menuItem, false);
            break;
        default:
            setFragmentContent(this, Map_fragment.class, menuItem, false);
        }
        menuItem.setChecked(true);
        setTitle(menuItem.getTitle());
        mDrawer.closeDrawers();
    }
}

From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java

/**
 * Change the input mode sub-menu to reflect change in scaling
 *//*ww  w .  java2 s. c o m*/
void updateInputMenu() {
    try {
        for (MenuItem item : inputModeMenuItems) {
            item.setEnabled(canvas.scaling.isValidInputMode(item.getItemId()));
            if (getInputHandlerById(item.getItemId()) == inputHandler)
                item.setChecked(true);
        }
    } catch (NullPointerException e) {
    }
}

From source file:github.popeen.dsub.activity.SubsonicActivity.java

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    int size = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE);
    String[] ids = savedInstanceState.getStringArray(Constants.MAIN_BACK_STACK);
    FragmentManager fm = getSupportFragmentManager();
    currentFragment = (SubsonicFragment) fm.findFragmentByTag(ids[0]);
    currentFragment.setPrimaryFragment(true);
    currentFragment.setSupportTag(ids[0]);
    supportInvalidateOptionsMenu();//from  w  ww.  j a v a  2 s  .c  o  m
    FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
    for (int i = 1; i < size; i++) {
        SubsonicFragment frag = (SubsonicFragment) fm.findFragmentByTag(ids[i]);
        frag.setSupportTag(ids[i]);
        if (secondaryContainer != null) {
            frag.setPrimaryFragment(false, true);
        }
        trans.hide(frag);
        backStack.add(frag);
    }
    trans.commit();

    // Current fragment is hidden in secondaryContainer
    if (secondaryContainer == null && !currentFragment.isVisible()) {
        trans = getSupportFragmentManager().beginTransaction();
        trans.remove(currentFragment);
        trans.commit();
        getSupportFragmentManager().executePendingTransactions();

        trans = getSupportFragmentManager().beginTransaction();
        trans.add(R.id.fragment_container, currentFragment, ids[0]);
        trans.commit();
    }
    // Current fragment needs to be moved over to secondaryContainer
    else if (secondaryContainer != null && secondaryContainer.findViewById(currentFragment.getRootId()) == null
            && backStack.size() > 0) {
        trans = getSupportFragmentManager().beginTransaction();
        trans.remove(currentFragment);
        trans.show(backStack.get(backStack.size() - 1));
        trans.commit();
        getSupportFragmentManager().executePendingTransactions();

        trans = getSupportFragmentManager().beginTransaction();
        trans.add(R.id.fragment_second_container, currentFragment, ids[0]);
        trans.commit();

        secondaryContainer.setVisibility(View.VISIBLE);
    }

    lastSelectedPosition = savedInstanceState.getInt(Constants.FRAGMENT_POSITION);
    if (lastSelectedPosition != 0) {
        MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
        if (item != null) {
            item.setChecked(true);
        }
    }
    recreateSpinner();
    checkIfServerOutdated();
}

From source file:net.tjado.passwdsafe.PasswdSafeOpenFileFragment.java

private void setYubikeyState(boolean state, int slot) {
    itsMenu.setGroupEnabled(R.id.menu_group_slots, state);

    itsYubiSlot = slot;/*from  w  w w. java 2s .  co m*/

    MenuItem item;
    switch (itsYubiSlot) {
    case 1: {
        item = itsMenu.findItem(R.id.menu_slot_1);
        break;
    }
    case 2: {
        item = itsMenu.findItem(R.id.menu_slot_2);
        break;
    }
    default: {
        item = itsMenu.findItem(R.id.menu_slot_none);
    }
    }
    item.setChecked(true);
}

From source file:github.popeen.dsub.activity.SubsonicActivity.java

private void populateTabs() {
    drawerList.getMenu().clear();//from w ww. j  ava2s  .  co m
    drawerList.inflateMenu(R.menu.drawer_navigation);

    SharedPreferences prefs = Util.getPreferences(this);
    boolean podcastsEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_PODCASTS_ENABLED, true);
    boolean bookmarksEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED, true)
            && !Util.isOffline(this) && ServerInfo.canBookmark(this);
    boolean internetRadioEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_INTERNET_RADIO_ENABLED, true)
            && !Util.isOffline(this) && ServerInfo.canInternetRadio(this);
    boolean sharedEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_SHARED_ENABLED, true)
            && !Util.isOffline(this);
    boolean chatEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_CHAT_ENABLED, true)
            && !Util.isOffline(this);
    boolean adminEnabled = prefs.getBoolean(Constants.PREFERENCES_KEY_ADMIN_ENABLED, true)
            && !Util.isOffline(this);

    MenuItem offlineMenuItem = drawerList.getMenu().findItem(R.id.drawer_offline);
    if (Util.isOffline(this)) {
        setDrawerItemVisible(R.id.drawer_home, false);

        if (lastSelectedPosition == 0 || lastSelectedPosition == R.id.drawer_home) {
            String newFragment = Util.openToTab(this);
            if (newFragment == null || "Home".equals(newFragment)) {
                newFragment = "Artist";
            }

            lastSelectedPosition = getDrawerItemId(newFragment);
            drawerItemSelected(newFragment);
        }

        offlineMenuItem.setTitle(R.string.main_online);
    } else {
        offlineMenuItem.setTitle(R.string.main_offline);
    }

    if (!podcastsEnabled) {
        setDrawerItemVisible(R.id.drawer_podcasts, false);
    }
    if (!bookmarksEnabled) {
        setDrawerItemVisible(R.id.drawer_bookmarks, false);
    }
    if (!internetRadioEnabled) {
        setDrawerItemVisible(R.id.drawer_internet_radio_stations, false);
    }
    if (!sharedEnabled) {
        setDrawerItemVisible(R.id.drawer_shares, false);
    }
    if (!chatEnabled) {
        setDrawerItemVisible(R.id.drawer_chat, false);
    }
    if (!adminEnabled) {
        setDrawerItemVisible(R.id.drawer_admin, false);
    }

    if (lastSelectedPosition != 0) {
        MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
        if (item != null) {
            item.setChecked(true);
        }
    }
    drawerHeaderToggle.setImageResource(R.drawable.main_select_server_dark);

    showingTabs = true;
}

From source file:nhannt.musicplayer.ui.home.HomeActivity.java

private void setupNavigationView() {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from   w ww  . j a va  2s.co  m*/
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            switch (item.getItemId()) {
            case R.id.btn_lib_nav:
                navItemIndex = 0;
                CURRENT_TAG = TAG_LIBRARY;
                break;
            case R.id.btn_playlist_nav:
                CURRENT_TAG = TAG_PLAYLISTS;
                navItemIndex = 1;
                break;
            case R.id.btn_play_queue_nav:
                CURRENT_TAG = TAG_PLAYING_QUEUE;
                navItemIndex = 2;
                break;
            case R.id.btn_now_playing_nav:
                navItemIndex = 3;
                startActivity(new Intent(HomeActivity.this, PlayBackActivity.class));
                drawerLayout.closeDrawers();
                return true;
            case R.id.btn_about_nav:
                break;
            case R.id.btn_license_nav:
                break;
            case R.id.btn_feedback_nav:
                break;
            default:
                navItemIndex = 0;
            }

            if (item.isChecked()) {
                item.setChecked(false);
            } else {
                item.setChecked(true);
            }
            item.setChecked(true);
            loadHomeFragment();
            return true;
        }
    });

}

From source file:nyc.c4q.jordansmith.finefree.ActivityMain.java

public void selectDrawerItem(final MenuItem menuItem) {
    switch (menuItem.getTitle().toString()) {
    case "Home":
        startDefaultHomeFragment();/* www .ja  v  a2 s  .c o m*/
        break;
    case "Settings":
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_holder, new FragmentSettings())
                .commit();
        break;
    case "Add New Car":
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_holder, new FragmentNewCar())
                .commit();
        break;
    }

    // Submenu of cars
    String plate;
    for (int i = 0; i < cars.size(); i++) {
        if (cars.get(i).getName().equals(menuItem.getTitle())) {
            plate = cars.get(i).getLicensePlate();
            Bundle bundle = new Bundle();
            bundle.putSerializable(PLATE_KEY, cars.get(i));
            FragmentHome fragmentHome = new FragmentHome();
            fragmentHome.setArguments(bundle);

            getSupportFragmentManager().beginTransaction()
                    .setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit)
                    .replace(R.id.fragment_holder, fragmentHome).commit();

        }
    }

    menuItem.setChecked(true);
    setTitle(menuItem.getTitle());

    drawerLayout.closeDrawers();
}

From source file:org.addhen.smssync.presentation.view.ui.activity.MainActivity.java

private void setupFragment(MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    case R.id.nav_incoming_messages:
        mMessageFragment = MessageFragment.newInstance();
        replaceFragment(R.id.fragment_main_content, mMessageFragment, INCOMING_FAG_TAG);
        setToolbarTitle(menuItem);//from   ww w  . j a va 2  s  .c  o m
        break;
    case R.id.nav_published_messages:
        replaceFragment(R.id.fragment_main_content, PublishedMessageFragment.newInstance(),
                PUBLISHED_MESSAGES_TAG);
        setToolbarTitle(menuItem);
        break;
    case R.id.nav_filters:
        replaceFragment(R.id.fragment_main_content, FilterFragment.newInstance(), FILTERS_TAG);
        setToolbarTitle(menuItem);
        break;
    case R.id.nav_reports:
        replaceFragment(R.id.fragment_main_content, LogFragment.newInstance(), LOGS_TAG);
        setToolbarTitle(menuItem);
        break;
    case R.id.nav_integration:
        replaceFragment(R.id.fragment_main_content, IntegrationFragment.newInstance(), INTEGRATION_TAG);
        setToolbarTitle(menuItem);
        break;
    case R.id.nav_settings:
        menuItem.setChecked(false);
        mAppComponent.launcher().launchSettings();
        break;
    default:
        break;
    }
}

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

public void initMainActivity(@Nullable Bundle savedInstanceState, boolean isLicenseCheckerEnabled,
        @NonNull byte[] salt, @NonNull String licenseKey, @NonNull String[] donationProductsId) {
    super.setTheme(Preferences.getPreferences(this).isDarkTheme() ? R.style.AppThemeDark : R.style.AppTheme);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wallpaper_board);
    ButterKnife.bind(this);

    ViewHelper.resetNavigationBarTranslucent(this, getResources().getConfiguration().orientation);

    ColorHelper.setStatusBarIconColor(this);
    registerBroadcastReceiver();//from   www  .  j a v  a2  s.  c  o m

    SoftKeyboardHelper softKeyboardHelper = new SoftKeyboardHelper(this, findViewById(R.id.container));
    softKeyboardHelper.enable();

    mFragManager = getSupportFragmentManager();
    mLicenseKey = licenseKey;
    mDonationProductsId = donationProductsId;

    Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
    toolbar.setTitle("");

    ViewHelper.setupToolbar(toolbar, true);
    setSupportActionBar(toolbar);

    mBottomNavigationView.setOnNavigationItemSelectedListener(
            new BottomNavigationViewNew.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    int id = item.getItemId();
                    int newPosition = -1;
                    if (id == R.id.navigation_view_wallpapers) {
                        newPosition = 0;
                    }
                    if (id == R.id.navigation_view_favorites) {
                        newPosition = 2;
                    }
                    if (id == R.id.navigation_view_categories) {
                        newPosition = 1;
                    }
                    if (id == R.id.navigation_view_new) {
                        newPosition = 4;
                    }
                    if (newPosition != -1 && newPosition != mPosition) {
                        setMenuChecked(false);
                        mPosition = newPosition;
                        setFragment(getFragment(mPosition));
                        item.setChecked(true);
                        mToolbarTitle.setText(getToolbarTitle());
                        return true;
                    }
                    if (id == R.id.menu_filter) {
                        final PopupMenu popup = new PopupMenu(WallpaperBoardActivity.this,
                                ((ViewGroup) mBottomNavigationView.getChildAt(0)).getChildAt(2));
                        fileCategoryMenu(popup.getMenu());
                        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                            public boolean onMenuItemClick(MenuItem item) {
                                item.setChecked(!item.isChecked());
                                new Database(WallpaperBoardActivity.this).selectCategory(
                                        item.getItemId() - MENU_CATEGORY_START, item.isChecked());
                                filterWallpapers();
                                return true;
                            }
                        });
                        popup.show();
                        return false;
                    }
                    return false;
                }
            });

    initInAppBilling();

    mPosition = 0;
    if (savedInstanceState != null) {
        mPosition = savedInstanceState.getInt(Extras.EXTRA_POSITION, 0);
    }
    setMenuChecked(false);
    setFragment(getFragment(mPosition));
    MenuItem item = mBottomNavigationView.getMenu().findItem(mapPositionToMenuId());
    if (item != null) {
        item.setChecked(true);
    }
    mToolbarTitle.setText(getToolbarTitle());

    ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.coordinator),
            new OnApplyWindowInsetsListener() { // setContentView() must be fired already
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    mNavBarHeight = insets.getSystemWindowInsetBottom();
                    ViewHelper.resetViewBottomPadding(mBottomNavigationView, mNavBarHeight, true);
                    // need to call here since first fragment is created before this
                    WallpapersFragment fragment = (WallpapersFragment) mFragManager
                            .findFragmentByTag(Extras.TAG_WALLPAPERS);
                    if (fragment != null) {
                        fragment.resetViewBottomPadding();
                    }
                    return insets;
                }
            });
    if (Preferences.getPreferences(this).isFirstRun() && isLicenseCheckerEnabled) {
        LicenseHelper.getLicenseChecker(this).checkLicense(mLicenseKey, salt);
        return;
    }

    checkWallpapers();

    if (isLicenseCheckerEnabled && !Preferences.getPreferences(this).isLicensed()) {
        finish();
    }
}

From source file:org.gateshipone.malp.application.views.NowPlayingView.java

/**
     * Called to open the popup menu on the top right corner.
     */*from  w ww.j a v a  2 s. c om*/
     * @param v
     */
    private void showAdditionalOptionsMenu(View v) {
        PopupMenu menu = new PopupMenu(getContext(), v);
        // Inflate the menu from a menu xml file
        menu.inflate(R.menu.popup_menu_nowplaying);
        // Set the main NowPlayingView as a listener (directly implements callback)
        menu.setOnMenuItemClickListener(this);

        // Set the checked menu item state if a MPDCurrentStatus is available
        if (null != mLastStatus) {
            MenuItem singlePlaybackItem = menu.getMenu().findItem(R.id.action_toggle_single_mode);
            singlePlaybackItem.setChecked(mLastStatus.getSinglePlayback() == 1);

            MenuItem consumeItem = menu.getMenu().findItem(R.id.action_toggle_consume_mode);
            consumeItem.setChecked(mLastStatus.getConsume() == 1);
        }

        // Check if the current view is the cover or the playlist. If it is the playlist hide its actions.
        // If the viewswitcher only has one child the dual pane layout is used
        if (mViewSwitcher.getDisplayedChild() == 0 && (mViewSwitcher.getChildCount() > 1)) {
            menu.getMenu().setGroupEnabled(R.id.group_playlist_actions, false);
            menu.getMenu().setGroupVisible(R.id.group_playlist_actions, false);
        }
        // Open the menu itself
        menu.show();
    }