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.cx.demo.common.BaseDrawerLayoutActivity.java

/**
 * set menu item check status/*from   w w  w.j  av  a  2 s  .co  m*/
 *
 * @param itemId itemId
 * @return true to display the item as the selected item
 */
protected boolean menuItemChecked(int itemId) {
    MenuItem old = null;
    MenuItem now;
    if (this.mMenuItems.containsKey(itemId)) {
        for (Map.Entry<Integer, MenuItem> entry : this.mMenuItems.entrySet()) {
            MenuItem menuItem = entry.getValue();
            /*
             * item??
             * ???
             */
            if (menuItem.isChecked()) {
                old = menuItem;
            }

            /*
             * ??
             * ??
             */
            if (old != null && old.getItemId() == itemId)
                break;

            /*
             * ???
             */
            if (menuItem.getItemId() == itemId) {
                now = menuItem;
                menuItem.setChecked(true);
                this.onMenuItemOnClick(now);
            } else {
                menuItem.setChecked(false);
            }
        }
        this.mDrawerLayout.closeDrawer(this.mNavigationView);
        return true;
    } else {
        return false;
    }
}

From source file:com.example.ali.topcoderandroid.Activities.MainActivity.java

private void setNavigation(NavigationView navigationView, ChallengeType challengeType) {
    int preferredCheckItemId = 0;
    switch (challengeType) {
    case Design:/* w ww.  j  a  v a  2s . com*/
        preferredCheckItemId = 0;
        break;
    case Develop:
        preferredCheckItemId = 1;
        break;
    case Data:
        preferredCheckItemId = 2;
        break;
    }

    Menu menu = navigationView.getMenu();
    if (menu != null)
        menu.getItem(preferredCheckItemId).setChecked(true);

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {

            //Checking if the item is in checked state or not, if not make it in checked state
            if (!menuItem.isChecked()) {
                menuItem.setChecked(true);
            }

            //Closing drawer on item click
            drawerLayout.closeDrawers();

            //Check to see which item was being clicked and perform appropriate action
            switch (menuItem.getItemId()) {
            case R.id.navDesign:
                //Toast.makeText(getApplicationContext(), "Design Challenges", Toast.LENGTH_SHORT).show();
                preferredChallengeType = ChallengeType.Design;
                break;

            case R.id.navDevelop:
                //Toast.makeText(getApplicationContext(), "Develop Challenges", Toast.LENGTH_SHORT).show();
                preferredChallengeType = ChallengeType.Develop;
                break;

            case R.id.navData:
                //Toast.makeText(getApplicationContext(), "Data Challenges", Toast.LENGTH_SHORT).show();
                preferredChallengeType = ChallengeType.Data;
                break;

            default:
                Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show();
                return true;
            }

            recyclerViewFragment.fetchChallenges(preferredChallengeType);
            return true;

        }
    });
}

From source file:com.camnter.easygank.core.BaseDrawerLayoutActivity.java

/**
 * set menu item check status/*from   www. j  av  a2 s  .c  om*/
 *
 * @param itemId itemId
 * @return true to display the item as the selected item
 */
protected boolean menuItemChecked(int itemId) {
    MenuItem old = null;
    MenuItem now;
    if (this.mMenuItems.containsKey(itemId)) {
        for (Map.Entry<Integer, MenuItem> entry : this.mMenuItems.entrySet()) {
            MenuItem menuItem = entry.getValue();
            /*
             * item??
             * ???
             */
            if (menuItem.isChecked()) {
                old = menuItem;
            }

            /*
             * ??
             * ??
             */
            if (old != null && old.getItemId() == itemId)
                break;

            /*
             * ???
             */
            if (menuItem.getItemId() == itemId) {
                now = menuItem;
                menuItem.setChecked(true);
                this.onMenuItemOnClick(now);
            } else {
                menuItem.setChecked(false);
            }

        }
        this.mDrawerLayout.closeDrawer(this.mNavigationView);
        return true;
    } else {
        return false;
    }
}

From source file:com.duy.pascal.ui.editor.EditorDelegate.java

public boolean onOptionsItemSelected(MenuItem menuItem) {
    int id = menuItem.getItemId();
    if (menuItem.isCheckable())
        menuItem.setChecked(!menuItem.isChecked());
    switch (id) {
    case R.id.action_setting:
        mAnalytics.logEvent("action_setting", new Bundle());
        mActivity.startActivity(new Intent(mActivity, SettingsActivity.class));
        break;//from www .j  a v a  2s .  com
    case R.id.action_find:
        mAnalytics.logEvent("action_find", new Bundle());
        mActivity.showDialogFind();
        break;
    case R.id.action_find_and_replace:
        mAnalytics.logEvent("action_find_and_replace", new Bundle());
        mListener.findAndReplace();
        break;
    case R.id.action_doc:
        mListener.showDocumentActivity();
        break;
    case R.id.action_new_file:
        mListener.createNewSourceFile(null);
        break;
    case R.id.action_code_sample:
        mAnalytics.logEvent("action_code_sample", new Bundle());
        mActivity.startActivity(new Intent(mActivity, CodeSampleActivity.class));
        break;
    case R.id.action_rate:
        mAnalytics.logEvent("action_rate", new Bundle());
        StoreUtil.gotoPlayStore(mActivity, BuildConfig.APPLICATION_ID);
        break;
    case R.id.action_more_app:
        mAnalytics.logEvent("action_more_app", new Bundle());
        StoreUtil.moreApp(mActivity);
        break;
    case R.id.nav_run:
        mListener.runProgram();
        break;
    case R.id.action_compile:
        mListener.doCompile();
        break;
    case R.id.action_save: {
        EditorFragment fragment = mActivity.getEditorFragment();
        if (fragment != null)
            fragment.saveFile();
        break;
    }
    case R.id.action_save_as:
        mListener.saveAs();
        break;
    case R.id.action_goto_line:
        mAnalytics.logEvent("action_goto_line", new Bundle());
        mListener.goToLine();
        break;
    case R.id.action_format: {
        mAnalytics.logEvent("action_format", new Bundle());
        EditorFragment fragment = mActivity.getEditorFragment();
        if (fragment != null)
            fragment.formatCode();
        break;
    }
    case R.id.action_report_bug:
        mListener.reportBug();
        break;
    case R.id.action_undo: {
        EditorFragment fragment = mActivity.getEditorFragment();
        if (fragment != null)
            fragment.undo();
        break;
    }
    case R.id.action_redo: {
        EditorFragment fragment = mActivity.getEditorFragment();
        if (fragment != null)
            fragment.redo();
        break;
    }
    case R.id.action_paste: {
        EditorFragment fragment = mActivity.getEditorFragment();
        if (fragment != null)
            fragment.paste();
        break;
    }
    case R.id.action_copy_all: {
        EditorFragment fragment = mActivity.getEditorFragment();
        if (fragment != null)
            fragment.copyAll();
        break;
    }
    case R.id.action_select_theme:
        mAnalytics.logEvent("action_select_theme", new Bundle());
        mListener.selectThemeFont();
        break;
    case R.id.action_more_feature:
        mActivity.openDrawer(GravityCompat.END);
        break;
    case R.id.action_translate:
        mAnalytics.logEvent("action_translate", new Bundle());
        startActivityTranslate();
        break;
    case R.id.action_info:
        mAnalytics.logEvent("action_info", new Bundle());
        mActivity.startActivity(new Intent(mActivity, InfoActivity.class));
        break;
    case R.id.action_program_structure:
        mActivity.showProgramStructure();
        break;
    case R.id.action_debug:
        mAnalytics.logEvent("action_debug", new Bundle());
        mActivity.startDebug();
        break;
    case R.id.action_open_file:
        mActivity.openDrawer(GravityCompat.START);
        break;
    case R.id.action_insert_media_url:
        selectMediaUrl();
        break;
    case R.id.action_insert_color:
        mAnalytics.logEvent("action_insert_color", new Bundle());
        mActivity.insertColor();
        break;
    }
    return true;
}

From source file:net.hyx.app.volumenotification.ActivityMain.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;
    case R.id.menu_pref:
        startActivity(new Intent(this, ActivityPref.class));
        return true;
    case R.id.menu_dark_app_theme:
        boolean dark_theme = !item.isChecked();
        settings.edit().putBoolean("pref_dark_app_theme", dark_theme).apply();
        item.setChecked(dark_theme);/*from   w  w  w.j a v  a  2 s  .c  om*/
        setTheme(settings.getAppTheme());
        recreate();
        return true;
    case R.id.menu_about:
        Uri url = Uri.parse(getResources().getString(R.string.menu_about_url));
        startActivity(new Intent(Intent.ACTION_VIEW, url));
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:org.xbmc.kore.ui.sections.video.TVShowEpisodeListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_hide_watched:
        item.setChecked(!item.isChecked());
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
        preferences.edit().putBoolean(Settings.KEY_PREF_TVSHOW_EPISODES_FILTER_HIDE_WATCHED, item.isChecked())
                .apply();/*from w w w  . j  a  v a2  s  .c o m*/
        refreshList();
        break;
    default:
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.androguide.honamicontrol.soundcontrol.SoundFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.link_seekbars:
        SharedPreferences soundPrefs = fa.getSharedPreferences("SOUND_CONTROL", 0);
        if (item.isChecked()) {
            item.setChecked(false);//from   w ww . ja v a2s . com
            soundPrefs.edit().putBoolean("LINKED", false).commit();
        } else {
            item.setChecked(true);
            soundPrefs.edit().putBoolean("LINKED", true).commit();
        }
        break;

    }
    return super.onOptionsItemSelected(item);
}

From source file:com.android.settings.applications.AppOpsSummary.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.show_user_apps:
        final String prefNameUserApps = "show_user_apps";
        // set the menu checkbox and save it in shared preference
        item.setChecked(!item.isChecked());
        mPreferences.edit().putBoolean(prefNameUserApps, item.isChecked()).commit();
        // reload content
        resetAdapter();//from w  w w  .  j  a va  2s . c om
        return true;
    case R.id.show_system_apps:
        final String prefNameSysApps = "show_system_apps";
        // set the menu checkbox and save it in shared preference
        item.setChecked(!item.isChecked());
        mPreferences.edit().putBoolean(prefNameSysApps, item.isChecked()).commit();
        // reload view content
        resetAdapter();
        return true;
    case R.id.reset_counters:
        resetCountersConfirm();
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:info.wncwaterfalls.app.InformationMapFragment.java

private boolean setMapTypeIfUnchecked(MenuItem item, int newType) {
    GoogleMap googleMap = mMapView.getMap();
    if (!item.isChecked()) {
        googleMap.setMapType(newType);/*from   w  w w. j av a  2  s .  c o  m*/
        item.setChecked(true);
    }
    return true;
}

From source file:org.gnucash.android.ui.report.PieChartFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable())
        item.setChecked(!item.isChecked());
    switch (item.getItemId()) {
    case R.id.menu_order_by_size: {
        bubbleSort();/*  ww w  .j  a  va 2s  . c  o  m*/
        return true;
    }
    case R.id.menu_toggle_legend: {
        mChart.getLegend().setEnabled(!mChart.getLegend().isEnabled());
        mChart.getLegend().setForm(LegendForm.CIRCLE);
        mChart.getLegend().setPosition(LegendPosition.RIGHT_OF_CHART_CENTER);
        mChart.notifyDataSetChanged();
        mChart.invalidate();
        return true;
    }
    case R.id.menu_toggle_labels: {
        mChart.getData().setDrawValues(!mChart.isDrawSliceTextEnabled());
        mChart.setDrawSliceText(!mChart.isDrawSliceTextEnabled());
        mChart.invalidate();
        return true;
    }
    case R.id.menu_group_other_slice: {
        mGroupSmallerSlices = !mGroupSmallerSlices;
        displayChart();
        return true;
    }

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