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.github.michalbednarski.intentslab.Utils.java

public static void updateLegacyCheckedIcon(MenuItem menuItem) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        menuItem.setIcon(menuItem.isChecked() ? R.drawable.ic_menu_checked : R.drawable.ic_menu_unchecked);
    }// ww w  .  j  a v  a 2 s  .  c  o m
}

From source file:com.loopj.android.http.sample.Redirect302Sample.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable()) {
        item.setChecked(!item.isChecked());
        if (item.getItemId() == 0) {
            enableRedirects = item.isChecked();
        } else if (item.getItemId() == 1) {
            enableRelativeRedirects = item.isChecked();
        } else if (item.getItemId() == 2) {
            enableCircularRedirects = item.isChecked();
        }//from   w w w . ja  v  a  2 s.c  o  m
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.commonsware.android.tablayout.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.fixed) {
        item.setChecked(!item.isChecked());

        if (item.isChecked()) {
            adapter.setPageCount(3);//from w  ww  .  ja v a2  s .  co m
            tabs.setTabMode(TabLayout.MODE_FIXED);
        } else {
            adapter.setPageCount(10);
            tabs.setTabMode(TabLayout.MODE_SCROLLABLE);
        }

        adapter.notifyDataSetChanged();

        if (pager.getCurrentItem() >= 3) {
            pager.setCurrentItem(2);
        }

        return (true);
    }

    return (super.onOptionsItemSelected(item));
}

From source file:com.commonsware.android.assist.mo.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.fixed) {
        item.setChecked(!item.isChecked());

        if (item.isChecked()) {
            if (pager.getCurrentItem() > 2) {
                pager.setCurrentItem(2);
            }//  ww w .  jav a  2  s .c om

            pager.postDelayed(new Runnable() {
                @Override
                public void run() {
                    adapter.setPageCount(3);
                    adapter.notifyDataSetChanged();
                }
            }, 100);
        } else {
            adapter.setPageCount(10);
            adapter.notifyDataSetChanged();
        }

        return (true);
    }

    return (super.onOptionsItemSelected(item));
}

From source file:com.example.mpodera.tourismapp.MainActivity.java

private void setNavigationDrawer() {
    mTitle = mDrawerTitle = getTitle();//from w  w w.  j  a  v  a 2 s  . co  m
    dLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    navView = (NavigationView) findViewById(R.id.navigation);
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            dLayout, /* DrawerLayout object */
            R.drawable.ic_menu_white_24dp, /* nav drawer image to replace 'Up' caret */
            R.string.abierto, /* "open drawer" description for accessibility */
            R.string.cerrado /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            if (navView.getMenu().findItem(menuItemD).isChecked()) {
                getSupportActionBar().setTitle(mTitle);
            } else {
                navView.getMenu().findItem(menuItemD).setChecked(false);
                getSupportActionBar().setTitle(R.string.aC);
            }
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            //getSupportActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    dLayout.setDrawerListener(mDrawerToggle);
    navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            if (menuItem.isChecked())
                menuItem.setChecked(false);
            else
                menuItem.setChecked(true);
            menuItemD = menuItem.getItemId();
            selectItem(menuItem.getItemId());
            setTitle(menuItem.getTitle());
            return false;
        }
    });
}

From source file:me.abhrajit.hackernewsreader.MainActivity.java

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    Menu menu = navigationView.getMenu();
    int selected = -1;
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.isChecked()) {
            selected = i;//w  ww.  ja  va  2 s  .c o  m
            break;
        }
    }
    savedInstanceState.putInt(getString(R.string.nav_Selected), selected);
    super.onSaveInstanceState(savedInstanceState);
}

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

@Test
public void testGetCurrentMenuItem() throws Exception {
    // setup//ww w. ja  v  a 2s  . co m
    MenuItem expected = getMenuItem(NavigationMenu.ACCESS_POINTS);
    // execute
    MenuItem actual = fixture.getCurrentMenuItem();
    // validate
    assertEquals(expected, actual);
    assertTrue(actual.isCheckable());
    assertTrue(actual.isChecked());
}

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

private boolean onOptionsItemSelected(MenuItem item) {
    // If it is the current selected item, we do nothing
    if (item.isChecked())
        return false;

    final int itemId = item.getItemId();
    AdminSecurityManager.checkAdminPermission(drawerAct, itemId, new AdminSecurityManager.AuthListener() {
        public void onPermissionGranted() {
            // Check if the option has custom manager
            if (customOptions.containsKey(itemId)) {
                customOptions.get(itemId).onOptionSelected();
            } else if (itemId == R.id.menu_download) {
                launchIntentForActivity(TagSelectActivity.class);
            } else if (itemId == R.id.menu_about) {
                launchIntentForActivity(AboutActivity.class);
            } else if (itemId == R.id.menu_monitor) {
                launchIntentForActivity(MonitorActivity.class);
            } else if (itemId == R.id.menu_scorecard) {
                launchIntentForActivity(ScorecardActivity.class);
            } else if (itemId == R.id.menu_search) {
                launchIntentForActivity(SearchActivity.class);
            } else if (itemId == R.id.menu_settings) {
                launchIntentForActivity(PrefsActivity.class);
            } else if (itemId == R.id.menu_logout) {
                logout();/*from  w  w w  .j  av  a2  s  .co m*/
            }
        }
    });

    return true;
}

From source file:org.dmfs.webcal.fragments.CalendarTitleFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.menu_starred) {
        boolean checked = !item.isChecked();
        item.setChecked(checked);/* www.j  a  v  a  2s  .co m*/
        // Selectors don't seem to work with menu options, so we have to hard code the icons.
        item.setIcon(checked ? R.drawable.ic_fa_star : R.drawable.ic_fa_star_o);
        ContentItem.setStarred(getActivity(), mId, checked);
        Analytics.event("starred", "calendar-action", checked ? "starred" : "un-starred", null,
                String.valueOf(mId), null);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.android.immersive.ImmersiveDrawerActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Don't do anything if user selects already selected position
    if (item.isChecked()) {
        return true;
    }//  www  .j av  a  2s . c  om
    Intent intent = null;
    switch (item.getItemId()) {
    case R.id.nav_1:
        intent = new Intent(this, ImmersiveDrawerActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        break;
    case R.id.nav_2:
        intent = new Intent(this, ImmersiveActivity.class);
        break;
    case R.id.nav_3:
        intent = new Intent(this, ImmersiveStickyActivity.class);
        break;
    }
    startActivity(intent);
    mDrawerLayout.closeDrawers();
    return true;
}