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.bq.autobus.sample.LocationActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Enable or disable logs for the default bus.
    if (item.getItemId() == R.id.action_enable_logs) {
        boolean loggingEnabled = !BusProvider.getInstance().isLoggingEnabled();
        BusProvider.getInstance().setLoggingEnabled(loggingEnabled);
        item.setChecked(loggingEnabled);
    }// ww  w . j  a v  a2s  .  co m
    return super.onOptionsItemSelected(item);
}

From source file:com.example.admin.parkingappfinal.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Adding Toolbar to Main screen
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from   ww  w. java 2s  .com*/
    // Setting ViewPager for each Tabs
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

    // Set Tabs inside Toolbar
    //TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
    //tabs.setupWithViewPager(viewPager);
    Adapter adapter = new Adapter(getSupportFragmentManager());
    adapter.addFragment(new TileContentFragment(), "Tile");
    viewPager.setAdapter(adapter);
    // Create Navigation drawer and inflate layout
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    // Adding menu icon to Toolbar
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        VectorDrawableCompat indicator = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu,
                getTheme());
        indicator.setTint(ResourcesCompat.getColor(getResources(), R.color.white, getTheme()));
        supportActionBar.setHomeAsUpIndicator(indicator);
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }
    // Set behavior of Navigation drawer
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        // This method will trigger on item Click of navigation menu
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            // Set item in checked state
            menuItem.setChecked(true);

            // TODO: handle navigation

            // Closing drawer on item click
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
    // Adding Floating Action Button to bottom right of main view
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Snackbar.make(v, "Hello Snackbar!", Snackbar.LENGTH_LONG).show();
        }
    });
    //        super.onCreate(savedInstanceState);
    setContentView(R.layout.park_display);
    Button button = (Button) findViewById(R.id.refreshButton);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            try {
                update();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
}

From source file:com.mikepenz.iconics.sample.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle presses on the action bar items
    switch (item.getItemId()) {
    case R.id.action_randomize:
        item.setChecked(!item.isChecked());
        mIconsFragment.randomize(item.isChecked());
        mRandomize = item.isChecked();//from w  w w .j av  a2 s .co  m
        return true;
    case R.id.action_opensource:
        new LibsBuilder().withFields(R.string.class.getFields()).withLicenseShown(true)
                .withActivityTitle(getString(R.string.action_opensource)).withActivityTheme(R.style.AppTheme)
                .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR).start(MainActivity.this);

        return true;
    case R.id.action_playground:
        startActivity(new Intent(getApplicationContext(), PlaygroundActivity.class));
        return true;
    case R.id.action_automatic:
        startActivity(new Intent(getApplicationContext(), AutomaticActivity.class));
        return true;
    case R.id.action_old_automatic:
        startActivity(new Intent(getApplicationContext(), OldAutomaticActivity.class));
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.hotmart.dragonfly.ui.BaseActivity.java

private void setupViews() {
    if (mToolbar != null) {
        setSupportActionBar(mToolbar);//from   w  w w . ja  va2  s .  c o  m
    }

    if (mDrawer != null) {
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, mDrawer, mToolbar,
                R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        mDrawer.addDrawerListener(toggle);
        toggle.syncState();
    }

    if (mNavigationView != null) {
        mNavigationView.setNavigationItemSelectedListener(this);
        MenuItem menuItem = mNavigationView.getMenu().findItem(getSelfNavigationMenuItem());
        if (menuItem != null) {
            menuItem.setChecked(true);
        }

        mNavigationMenuViewModel = new NavigationMenuViewModel(mNavigationView.getHeaderView(0));
        mNavigationMenuViewModel.update();
    }
}

From source file:com.example.android.materialdesigncodelab.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Adding Toolbar to Main screen
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from w  w  w  .  j  av a 2s .c  o m
    // Setting ViewPager for each Tabs
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);
    // Set Tabs inside Toolbar
    TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
    tabs.setupWithViewPager(viewPager);
    // Create Navigation drawer and inlfate layout
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    // Adding menu icon to Toolbar
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        VectorDrawableCompat indicator = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu,
                getTheme());
        indicator.setTint(ResourcesCompat.getColor(getResources(), R.color.white, getTheme()));
        supportActionBar.setHomeAsUpIndicator(indicator);
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }
    // Set behavior of Navigation drawer
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        // This method will trigger on item Click of navigation menu
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            // Set item in checked state
            menuItem.setChecked(true);

            // TODO: handle navigation

            // Closing drawer on item click
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
    // Adding Floating Action Button to bottom right of main view
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Context context = v.getContext();
            Intent intent = new Intent(context, InstantMapAcitivity.class);
            intent.putExtra(InstantMapAcitivity.NEED_LOCATE, true);
            context.startActivity(intent);
        }
    });

    initListView();
}

From source file:com.xixicm.de.presentation.view.fragment.SentenceDetailFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.once) {
        item.setChecked(true);
        mPresenter.setPlayStyle(Constants.PLAY_ONCE);
        return true;
    }/*from   ww  w .  j  a v  a  2 s .  c  o  m*/
    if (id == R.id.repeat) {
        item.setChecked(true);
        mPresenter.setPlayStyle(Constants.PLAY_REPEAT);
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:net.vexelon.currencybg.app.ui.activities.MainActivity.java

/**
 * Create a new fragment and specify the planet to show based on position.
 *
 * @param menuItem//from  ww  w. j a va2s. c  om
 * @param clazz
 */
private <T extends AbstractFragment> void selectDrawerItem(MenuItem menuItem, Class<T> clazz) {
    try {
        showFragment(clazz);
        // Highlight the selected item, update the title, and close the
        // drawer
        menuItem.setChecked(true);
        setTitle(menuItem.getTitle());
        drawerLayout.closeDrawers();
    } catch (Exception e) {
        Log.e(Defs.LOG_TAG, "Unknown drawer section!", e);
    }
}

From source file:is.hello.go99.example.HomeActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_long_animations: {
        final boolean newValue = !enableLongAnimations;
        setEnableLongAnimations(newValue);
        item.setChecked(newValue);
        return true;
    }/* ww  w  .  j  a  v a2  s.  c  o m*/

    case R.id.action_clear: {
        final AmplitudesFragment currentFragment = (AmplitudesFragment) adapter.getCurrentFragment();
        if (currentFragment != null) {
            currentFragment.clear();
        }
        return true;
    }

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

From source file:me.drakeet.meizhi.ui.MainActivity.java

private void initNotifiableItemState(MenuItem item) {
        PreferencesLoader loader = new PreferencesLoader(this);
        item.setChecked(loader.getBoolean(R.string.action_notifiable, true));
    }//from  ww  w  .  j a v  a2s  .  c  o  m

From source file:com.smartx.bill.mepad.mestore.uimgloader.AbsListViewBaseActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.item_pause_on_scroll:
        pauseOnScroll = !pauseOnScroll;//from   w  w  w.  j  a  v a 2 s . c o m
        item.setChecked(pauseOnScroll);
        applyScrollListener();
        return true;
    case R.id.item_pause_on_fling:
        pauseOnFling = !pauseOnFling;
        item.setChecked(pauseOnFling);
        applyScrollListener();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}