Example usage for android.view MenuItem isChecked

List of usage examples for android.view MenuItem isChecked

Introduction

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

Prototype

public boolean isChecked();

Source Link

Document

Return whether the item is currently displaying a check mark.

Usage

From source file:com.dogar.geodesic.activities.MainActivity.java

private void reverseCheck(MenuItem item) {
    if (item.isChecked())
        item.setChecked(false);/* ww  w .  ja  v  a2  s .c  om*/
    else
        item.setChecked(true);
}

From source file:com.jkenneth.droidovpn.ui.activity.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    switch (id) {
    case R.id.sort_country:
        item.setChecked(item.isChecked());
        sort(SORT_COUNTRY);/*from  w w  w  .j a  v  a 2s. c  o  m*/
        break;
    case R.id.sort_speed:
        item.setChecked(item.isChecked());
        sort(SORT_SPEED);
        break;
    case R.id.sort_ping:
        item.setChecked(item.isChecked());
        sort(SORT_PING);
        break;
    case R.id.action_licenses:
        LicensesDialogFragment licensesDialog = new LicensesDialogFragment();
        licensesDialog.show(getSupportFragmentManager(), "licenses_dialog");
        break;
    case R.id.action_settings:
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.jecelyin.android.file_explorer.FileExplorerAction.java

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.select_all) {
        if (!item.isChecked()) {
            view.setSelectAll(true);//from  w  ww  . j  a v a2  s .c o  m
            item.setChecked(true);
            item.setTitle(R.string.cancel_select_all);
        } else {
            view.setSelectAll(false);
        }
    } else if (id == R.id.copy && !checkedList.isEmpty()) {
        fileClipboard.setData(true, checkedList);
        destroyActionMode();
    } else if (id == R.id.cut && !checkedList.isEmpty()) {
        fileClipboard.setData(false, checkedList);
        destroyActionMode();
    } else if (id == R.id.paste) {
        destroyActionMode();
        fileClipboard.paste(explorerContext.getCurrentDirectory());
    } else if (id == R.id.rename) {
        doRenameAction();
    } else if (id == R.id.share) {
        shareFile();
    } else if (id == R.id.delete) {
        doDeleteAction();
    } else {
        return false;
    }
    return true;
}

From source file:android.support.design.internal.BottomNavigationMenuView.java

public void updateMenuView() {
    final int menuSize = mMenu.size();
    if (menuSize != mButtons.length) {
        // The size has changed. Rebuild menu view from scratch.
        buildMenuView();//  ww w.  j  av a 2  s  .  c  o  m
        return;
    }
    int previousSelectedId = mSelectedItemId;

    for (int i = 0; i < menuSize; i++) {
        MenuItem item = mMenu.getItem(i);
        if (item.isChecked()) {
            mSelectedItemId = item.getItemId();
            mSelectedItemPosition = i;
        }
    }
    if (previousSelectedId != mSelectedItemId) {
        // Note: this has to be called before BottomNavigationItemView#initialize().
        mAnimationHelper.beginDelayedTransition(this);
    }

    for (int i = 0; i < menuSize; i++) {
        mPresenter.setUpdateSuspended(true);
        mButtons[i].initialize((MenuItemImpl) mMenu.getItem(i), 0);
        mPresenter.setUpdateSuspended(false);
    }

}

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);/* w ww .  j a v a2 s. c  om*/
    } 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:website.openeng.anki.NavigationDrawerActivity.java

public boolean onNavigationItemSelected(MenuItem item) {
    // Don't do anything if user selects already selected position
    if (item.isChecked()) {
        return true;
    }//from w ww  .  j a  v  a  2  s. co m
    // Take action if a different item selected
    switch (item.getItemId()) {
    case R.id.nav_decks:
        Intent deckPicker = new Intent(this, DeckPicker.class);
        deckPicker.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); // opening DeckPicker should clear back history
        startActivityWithAnimation(deckPicker, ActivityTransitionAnimation.RIGHT);
        break;
    case R.id.nav_browser:
        Intent cardBrowser = new Intent(this, CardBrowser.class);
        cardBrowser.putExtra("selectedDeck", getCol().getDecks().selected());
        startActivityForResultWithAnimation(cardBrowser, REQUEST_BROWSE_CARDS,
                ActivityTransitionAnimation.LEFT);
        break;
    case R.id.nav_stats:
        Intent intent = new Intent(this, Statistics.class);
        intent.putExtra("selectedDeck", getCol().getDecks().selected());
        startActivityForResultWithAnimation(intent, REQUEST_STATISTICS, ActivityTransitionAnimation.LEFT);
        break;
    case R.id.nav_night_mode:
        SharedPreferences preferences = KanjiDroidApp.getSharedPrefs(this);
        if (preferences.getBoolean("invertedColors", false)) {
            Timber.i("StudyOptionsFragment:: Night mode was disabled");
            preferences.edit().putBoolean("invertedColors", false).commit();
        } else {
            Timber.i("StudyOptionsFragment:: Night mode was enabled");
            preferences.edit().putBoolean("invertedColors", true).commit();
        }
        setNightModeIcon();
        CompatHelper.getCompat().restartActivityInvalidateBackstack(this);
        return true;
    case R.id.nav_settings:
        mOldColPath = CollectionHelper.getCurrentKanjiDroidDirectory(this);
        startActivityForResultWithAnimation(new Intent(this, Preferences.class), REQUEST_PREFERENCES_UPDATE,
                ActivityTransitionAnimation.FADE);
        break;
    case R.id.nav_help:
        Intent helpIntent = new Intent("android.intent.action.VIEW", Uri.parse(KanjiDroidApp.getManualUrl()));
        startActivityWithoutAnimation(helpIntent);
        break;
    case R.id.nav_feedback:
        Intent feedbackIntent = new Intent("android.intent.action.VIEW",
                Uri.parse(KanjiDroidApp.getFeedbackUrl()));
        startActivityWithoutAnimation(feedbackIntent);
        break;
    default:
        return false;
    }
    mDrawerLayout.closeDrawers();
    return true;
}

From source file:com.app4am.app4am.LatestNewsListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem item = menu.findItem(R.id.action_catalog);
    if (item != null) {
        boolean checked = item.isChecked();
        Log.d("checked", "state: " + checked + ", internal checked: " + checkedState);
        item.setChecked(checkedState);/*from w ww. j  a  va2  s  . com*/
    }
}

From source file:com.marshalchen.common.demoofui.stickygridheadersexample.StickGridItemListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_toggle_sticky:
        item.setChecked(!item.isChecked());
        ((StickyGridHeadersGridView) mGridView)
                .setAreHeadersSticky(!((StickyGridHeadersGridView) mGridView).areHeadersSticky());

        return true;
    case R.id.menu_use_list_adapter:
        mGridView.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.stickygridheader_item,
                getResources().getStringArray(R.array.countries)));
        mMenu.findItem(R.id.menu_use_list_adapter).setVisible(false);
        mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(true);
        mMenu.findItem(R.id.menu_toggle_sticky).setVisible(false);
        return true;
    case R.id.menu_use_sticky_adapter:
        mGridView.setAdapter(new StickyGridHeadersSimpleArrayAdapter<String>(
                getActivity().getApplicationContext(), getResources().getStringArray(R.array.countries),
                R.layout.stickygridheader_header, R.layout.stickygridheader_item));
        mMenu.findItem(R.id.menu_use_list_adapter).setVisible(true);
        mMenu.findItem(R.id.menu_toggle_sticky).setVisible(true);
        mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(false);
        return true;

    default://from   w w w. j a  v  a 2  s  .co m
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.tonicartos.stickygridheadersexample.ItemListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_toggle_sticky:
        item.setChecked(!item.isChecked());
        ((StickyGridHeadersGridView) mGridView)
                .setAreHeadersSticky(!((StickyGridHeadersGridView) mGridView).areHeadersSticky());

        return true;
    case R.id.menu_use_list_adapter:
        mGridView.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.item,
                getResources().getStringArray(R.array.countries)));
        mMenu.findItem(R.id.menu_use_list_adapter).setVisible(false);
        mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(true);
        mMenu.findItem(R.id.menu_toggle_sticky).setVisible(false);
        return true;
    case R.id.menu_use_sticky_adapter:
        mGridView.setAdapter(//  w w  w  .  j  a va 2  s  . c om
                new StickyGridHeadersSimpleArrayAdapter<String>(getActivity().getApplicationContext(),
                        getResources().getStringArray(R.array.countries), R.layout.header, R.layout.item));
        mMenu.findItem(R.id.menu_use_list_adapter).setVisible(true);
        mMenu.findItem(R.id.menu_toggle_sticky).setVisible(true);
        mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(false);
        return true;

    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.michael.openexercise.mc_customview.stickygridheaders.StickyItemListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_toggle_sticky:
        item.setChecked(!item.isChecked());
        ((StickyGridHeadersGridView) mGridView)
                .setAreHeadersSticky(!((StickyGridHeadersGridView) mGridView).areHeadersSticky());

        return true;
    case R.id.menu_use_list_adapter:
        mGridView.setAdapter(new ArrayAdapter<String>(getActivity(), R.layout.sticky_item,
                getResources().getStringArray(R.array.countries)));
        mMenu.findItem(R.id.menu_use_list_adapter).setVisible(false);
        mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(true);
        mMenu.findItem(R.id.menu_toggle_sticky).setVisible(false);
        return true;
    case R.id.menu_use_sticky_adapter:
        mGridView.setAdapter(new StickyGridHeadersSimpleArrayAdapter<String>(
                getActivity().getApplicationContext(), getResources().getStringArray(R.array.countries),
                R.layout.sticky_header, R.layout.sticky_item));
        mMenu.findItem(R.id.menu_use_list_adapter).setVisible(true);
        mMenu.findItem(R.id.menu_toggle_sticky).setVisible(true);
        mMenu.findItem(R.id.menu_use_sticky_adapter).setVisible(false);
        return true;

    default://  www.  j a v a  2 s.  c o  m
        break;
    }
    return super.onOptionsItemSelected(item);
}