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.money.manager.ex.account.AccountTransactionListFragment.java

private void selectCurrentPeriod(Menu menu) {
    MenuItem item = menu.findItem(R.id.menu_period);
    if (item == null)
        return;//from w  w w . j  av a2s .  c om

    SubMenu subMenu = item.getSubMenu();

    // on init, mark the default item as checked
    AppSettings settings = new AppSettings(getActivity());
    DefinedDateRangeName rangeName = settings.getLookAndFeelSettings().getShowTransactions();
    if (rangeName == null)
        return;

    DefinedDateRanges ranges = new DefinedDateRanges(getActivity());
    DefinedDateRange range = ranges.get(rangeName);
    if (range == null)
        return;
    int id = range.menuResourceId;

    MenuItem itemToMark = subMenu.findItem(id);
    if (itemToMark == null)
        return;

    itemToMark.setChecked(true);
}

From source file:com.readingcards.notes.MainNotesActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//w  ww. j  a va  2s.c  o m
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
            case R.id.notes_navigation_menu_item:
                ActivityCompat.startActivity(MainNotesActivity.this,
                        new Intent(MainNotesActivity.this, MainNotesActivity.class), null);
                break;
            case R.id.collection_cards_navigation_menu_item:
                ActivityCompat.startActivity(MainNotesActivity.this,
                        new Intent(MainNotesActivity.this, CardCollectionActivity.class), null);
                break;
            default:
                ActivityCompat.startActivity(MainNotesActivity.this,
                        new Intent(MainNotesActivity.this, MainNotesActivity.class), null);
                break;
            }
            // Close the navigation drawer when an item is selected.
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}

From source file:info.corne.performancetool.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);

    SharedPreferences pm = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    onBootEnabled = pm.getBoolean(Settings.SET_ON_BOOT_SETTING, false);
    MenuItem onBootMenu = menu.findItem(R.id.menu_onboot);
    onBootMenu.setChecked(onBootEnabled);

    return true;//from ww  w.j  a v a  2 s.  co m
}

From source file:com.bluros.music.activities.MainActivity.java

private void updatePosition(final MenuItem menuItem) {
    runnable = null;//ww  w  . j  av a  2s .c o  m

    switch (menuItem.getItemId()) {
    case R.id.nav_library:
        runnable = navigateLibrary;

        break;
    case R.id.nav_playlists:
        runnable = navigatePlaylist;

        break;
    case R.id.nav_nowplaying:
        NavigationUtils.navigateToNowplaying(MainActivity.this, false);
        break;
    case R.id.nav_queue:
        runnable = navigateQueue;

        break;
    case R.id.nav_settings:
        NavigationUtils.navigateToSettings(MainActivity.this);
        break;
    }

    if (runnable != null) {
        menuItem.setChecked(true);
        mDrawerLayout.closeDrawers();
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                runnable.run();
            }
        }, 350);
    }
}

From source file:de.spiritcroc.ownlog.ui.fragment.LogFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() != R.id.action_search) {
        closeSearchView();//from  w w w . ja  v a  2s .co m
    }
    switch (item.getItemId()) {
    case R.id.action_add:
        LogItemEditFragment.show(getActivity(), null);
        return true;
    case R.id.action_layout_continuous:
        mLayoutContinuous = !mLayoutContinuous;
        item.setChecked(mLayoutContinuous);
        loadContent(false);
        return true;
    case R.id.action_exit:
        Util.onExit(getActivity());
        getActivity().finish();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.filterdevice.ProfileScanningFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();// w ww  .ja va2s  .co  m
    inflater.inflate(R.menu.global, menu);
    final EditText mEditText = (EditText) menu.findItem(R.id.search).getActionView();
    mEditText.addTextChangedListener(textWatcher);

    MenuItem pairCache = menu.findItem(R.id.pairing);
    if (Utils.getBooleanSharedPreference(getActivity(), Constants.PREF_PAIR_CACHE_STATUS)) {
        pairCache.setChecked(true);
    } else {
        pairCache.setChecked(false);
    }

    MenuItem mSearch = menu.findItem(R.id.search);
    mSearch.setVisible(true);
    mSearch.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // Do something when collapsed
            View view = getActivity().getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            Logger.e("Collapsed");
            return true; // Return true to collapse action view
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            Logger.e("Expanded");
            mEditText.requestFocus();
            View view = getActivity().getCurrentFocus();
            if (view != null) {
                InputMethodManager inputManager = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
            }
            return true; // Return true to expand action view
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:io.ordunaleon.lumios.ui.DrawerActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
    mDrawerLayout.closeDrawers();/*from   w ww  . ja va2s  .c o m*/

    Fragment fragment;
    switch (menuItem.getItemId()) {
    case R.id.drawer_item_main:
        fragment = PriceListFragment.newInstance();
        break;
    case R.id.drawer_item_settings:
        Intent i = new Intent(this, SettingsActivity.class);
        startActivity(i);
        return false;
    default:
        fragment = DummyFragment.newInstance(menuItem.getTitle());
        break;
    }

    // Insert the fragment by replacing any existing fragment.
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.frame_layout, fragment).commit();

    // Highlight the selected item, update the title, and close the drawer.
    menuItem.setChecked(true);
    setTitle(menuItem.getTitle());
    return true;
}

From source file:com.afollestad.polar.ui.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.changelog) {
        ChangelogDialog.show(this);
        return true;
    } else if (item.getItemId() == R.id.darkTheme) {
        darkTheme(!darkTheme());/*w ww  .j ava 2 s . c  o m*/
        mToolbar.postDelayed(new Runnable() {
            @Override
            public void run() {
                recreate();
            }
        }, 500);
        return true;
    } else if (item.getItemId() == R.id.navDrawerMode) {
        item.setChecked(!item.isChecked());
        Config.get().navDrawerModeEnabled(item.isChecked());
        recreate();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Configure the SetCopyDestination menu item
 * @param item The menu item for SetCopyDestination
 *//*  w w  w . j  av  a 2  s  .c  o m*/
private void configureSetCopyDestinationMenuItem(final MenuItem item) {
    if (mItem.file != null) {
        item.setVisible(false);
    } else {
        item.setVisible(true);
        item.setChecked(false);
        if (getCopyPrefs().getString(COPY_DESTINATION_PREF_KEY, null) != null) {
            item.setChecked(true);
        }
    }
}

From source file:nz.ac.auckland.lablet.ExperimentRunViewManager.java

/**
 * Show a menu to enable or disable sensors.
 *//*  www . ja v  a2s.co  m*/
private void showSensorMenu() {
    View menuView = findViewById(R.id.action_sensors);
    PopupMenu popup = new PopupMenu(menuView.getContext(), menuView);

    final List<ISensorPlugin> plugins = ExperimentPluginFactory.getFactory().getSensorPlugins();
    for (int i = 0; i < plugins.size(); i++) {
        ISensorPlugin plugin = plugins.get(i);

        MenuItem item = popup.getMenu().add(1, i, i, plugin.getSensorName());
        item.setCheckable(true);

        if (getExperiment(plugin) != null)
            item.setChecked(true);
    }

    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            ISensorPlugin plugin = plugins.get(menuItem.getItemId());
            IExperimentSensor experimentSensor = getExperiment(plugin);
            if (experimentSensor != null)
                removeExperimentRun(experimentSensor);
            else
                addExperiment(plugin);
            return true;
        }
    });

    popup.show();
}