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.adnanbal.fxdedektifi.forex.presentation.view.activity.SignalsActivity.java

private void uncheckAllMenuItems(NavigationView navigationView) {
    final Menu menu = navigationView.getMenu();
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.hasSubMenu()) {
            SubMenu subMenu = item.getSubMenu();
            for (int j = 0; j < subMenu.size(); j++) {
                MenuItem subMenuItem = subMenu.getItem(j);
                subMenuItem.setChecked(false);
            }// ww w .j  a v  a2 s .c om
        } else {
            item.setChecked(false);
        }
    }
}

From source file:com.ichi2.anki.Statistics.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
    case R.id.item_time_month:
        if (item.isChecked())
            item.setChecked(false);
        else/*from   w  w w .  ja v  a 2s.co  m*/
            item.setChecked(true);
        if (mTaskHandler.getStatType() != Stats.TYPE_MONTH) {
            mTaskHandler.setStatType(Stats.TYPE_MONTH);
            mSectionsPagerAdapter.notifyDataSetChanged();
        }
        return true;
    case R.id.item_time_year:
        if (item.isChecked())
            item.setChecked(false);
        else
            item.setChecked(true);
        if (mTaskHandler.getStatType() != Stats.TYPE_YEAR) {
            mTaskHandler.setStatType(Stats.TYPE_YEAR);
            mSectionsPagerAdapter.notifyDataSetChanged();
        }
        return true;
    case R.id.item_time_all:
        if (item.isChecked())
            item.setChecked(false);
        else
            item.setChecked(true);
        if (mTaskHandler.getStatType() != Stats.TYPE_LIFE) {
            mTaskHandler.setStatType(Stats.TYPE_LIFE);
            mSectionsPagerAdapter.notifyDataSetChanged();
        }
        return true;
    case R.id.action_time_chooser:
        //showTimeDialog();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.offsec.nethunter.AppNavHomeActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//from  www .  ja  v  a2 s  .  c  om
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            // only change it if is no the same as the last one
            if (lastSelected != menuItem) {
                //remove last
                lastSelected.setChecked(false);
                // udpate for the next
                lastSelected = menuItem;
            }
            //set checked
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            mTitle = menuItem.getTitle();
            titles.push(mTitle.toString());

            FragmentManager fragmentManager = getSupportFragmentManager();
            int itemId = menuItem.getItemId();
            switch (itemId) {
            case R.id.nethunter_item:
                fragmentManager.beginTransaction()
                        .replace(R.id.container, NetHunterFragment.newInstance(itemId)).addToBackStack(null)
                        .commit();
                break;
            /*
            case R.id.kalilauncher_item:
                fragmentManager
                        .beginTransaction()
                        .replace(R.id.container, KaliLauncherFragment.newInstance(itemId))
                        .addToBackStack(null)
                        .commit();
                break;
            */
            case R.id.kaliservices_item:
                fragmentManager.beginTransaction()
                        .replace(R.id.container, KaliServicesFragment.newInstance(itemId)).addToBackStack(null)
                        .commit();
                break;

            case R.id.custom_commands_item:
                fragmentManager.beginTransaction()
                        .replace(R.id.container, CustomCommandsFragment.newInstance(itemId))
                        .addToBackStack(null).commit();
                break;

            case R.id.hid_item:
                fragmentManager.beginTransaction().replace(R.id.container, HidFragment.newInstance(itemId))
                        .addToBackStack(null).commit();
                break;
            case R.id.duckhunter_item:
                fragmentManager.beginTransaction()
                        .replace(R.id.container, DuckHunterFragment.newInstance(itemId)).addToBackStack(null)
                        .commit();
                break;
            case R.id.badusb_item:
                fragmentManager.beginTransaction().replace(R.id.container, BadusbFragment.newInstance(itemId))
                        .addToBackStack(null).commit();
                break;
            case R.id.mana_item:
                fragmentManager.beginTransaction().replace(R.id.container, ManaFragment.newInstance(itemId))
                        .addToBackStack(null).commit();
                break;
            case R.id.macchanger_item:
                fragmentManager.beginTransaction()
                        .replace(R.id.container, MacchangerFragment.newInstance(itemId)).addToBackStack(null)
                        .commit();
                break;
            case R.id.createchroot_item:
                fragmentManager.beginTransaction()
                        .replace(R.id.container, ChrootManagerFragment.newInstance(itemId)).addToBackStack(null)
                        .commit();
                break;
            case R.id.mpc_item:
                fragmentManager.beginTransaction().replace(R.id.container, MPCFragment.newInstance(itemId))
                        .addToBackStack(null).commit();
                break;
            case R.id.mitmf_item:
                fragmentManager.beginTransaction().replace(R.id.container, MITMfFragment.newInstance(itemId))
                        .addToBackStack(null).commit();
                break;
            case R.id.vnc_item:
                fragmentManager.beginTransaction().replace(R.id.container, VNCFragment.newInstance(itemId))
                        .addToBackStack(null).commit();
                break;
            case R.id.searchsploit_item:
                fragmentManager.beginTransaction()
                        .replace(R.id.container, SearchSploitFragment.newInstance(itemId)).addToBackStack(null)
                        .commit();
                break;
            case R.id.nmap_item:
                fragmentManager.beginTransaction().replace(R.id.container, NmapFragment.newInstance(itemId))
                        .addToBackStack(null).commit();
                break;
            case R.id.pineapple_item:
                fragmentManager.beginTransaction()
                        .replace(R.id.container, PineappleFragment.newInstance(itemId)).addToBackStack(null)
                        .commit();
                break;
            case R.id.checkforupdate_item:
                checkUpdate();
                break;
            }
            restoreActionBar();
            return true;
        }
    });
}

From source file:net.etuldan.sparss.fragment.EntryFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.entry, menu);

    if (mFavorite) {
        MenuItem item = menu.findItem(R.id.menu_star);
        item.setTitle(R.string.menu_unstar).setIcon(R.drawable.ic_star);
    }//from  ww w .j  a va 2 s  .  c o m
    MenuItem item = menu.findItem(R.id.menu_switch_full_original);
    item.setChecked(mPreferFullText);

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.brayanarias.alarmproject.activity.MainActivity.java

private void setupNavigationView() {
    navigationView = (NavigationView) findViewById(R.id.navigation);
    MenuItem item = navigationView.getMenu().findItem(actualItem);
    View nav_header = LayoutInflater.from(this).inflate(R.layout.nav_header, null);
    final NavigationView navigationView = (NavigationView) findViewById(R.id.navigation);
    navigationView.addHeaderView(nav_header);
    //salute//from  w w w  .ja  v  a2 s.  c  om
    String salute = AlarmUtilities.getSalute(getApplicationContext());
    TextView tvWellcome = (TextView) nav_header.findViewById(R.id.tvWellcome);
    tvWellcome.setText(salute);
    if (item != null) {
        item.setChecked(true);
    }
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            CharSequence title = menuItem.getTitle();
            closeDrawer();
            switch (menuItem.getItemId()) {
            case R.id.itMyAlarms:
                showFragment(R.id.itMyAlarms);
                actualItem = menuItem.getItemId();
                menuItem.setChecked(true);
                getSupportActionBar().setTitle(title);
                return true;
            case R.id.itAddAlarm:
                Calendar calendar = Calendar.getInstance();
                int hour = calendar.get(Calendar.HOUR_OF_DAY);
                int minute = calendar.get(Calendar.MINUTE);
                TimePickerDialog timePickerDialog = TimePickerDialog
                        .newInstance(new TimePickerDialog.OnTimeSetListener() {
                            @Override
                            public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
                                Alarm alarm = AlarmUtilities.createDefaultAlarm();
                                String min = minute < 10 ? "0" + minute : "" + minute;
                                if (hourOfDay == 12) {
                                    alarm.setAmPm("PM");
                                    alarm.setHour(hourOfDay);
                                    alarm.setHourFormatted((hourOfDay) + ":" + min);
                                } else if (hourOfDay > 12) {
                                    alarm.setAmPm("PM");
                                    alarm.setHour(hourOfDay - 12);
                                    alarm.setHourFormatted((hourOfDay - 12) + ":" + min);
                                } else {
                                    if (hourOfDay == 0) {
                                        hourOfDay = 12;
                                    }
                                    alarm.setAmPm("AM");
                                    alarm.setHour(hourOfDay);
                                    alarm.setHourFormatted(hourOfDay + ":" + min);
                                }
                                alarm.setMinute(minute);
                                Intent intent = new Intent(getApplicationContext(), AddAlarmActivity.class);
                                intent.putExtra(Constant.actionAlarmKey, Constant.addAlarm);
                                intent.putExtra(Constant.alarmSerializableKey, alarm);
                                startActivity(intent);
                            }
                        }, hour, minute, false);
                timePickerDialog.show(getSupportFragmentManager(), "tag");
                return true;
            case R.id.itCurrentMonth:
                actualItem = menuItem.getItemId();
                menuItem.setChecked(true);
                showFragment(R.id.itCurrentMonth);
                getSupportActionBar().setTitle(title);
                return true;
            /*
            case R.id.itConfig:
                actualItem = menuItem.getItemId();
                menuItem.setChecked(true);
                showFragment(R.id.itConfig);
                getSupportActionBar().setTitle(title);
                closeDrawer();
                return true;
            */
            case R.id.itAbout:
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(MainActivity.this);
                WebView wvLegal = (WebView) LayoutInflater.from(getApplication())
                        .inflate(R.layout.web_view_legal, null);
                wvLegal.loadData(getString(R.string.html_legal), "text/html", "UTF-8");
                wvLegal.setWebChromeClient(new WebChromeClient());
                alertBuilder.setView(wvLegal);
                alertBuilder.setTitle(R.string.txt_about_app);
                alertBuilder.setCancelable(true).setPositiveButton(getString(R.string.txt_button_ok),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                            }
                        });
                alertBuilder.show();
                return true;
            default:
                return false;
            }

        }
    });
}

From source file:net.bible.android.control.page.window.WindowControl.java

/**
 * Add the Window sub-menu resource which is not included in the main.xml for the main menu
 * Set the synchronised checkbox in the app menu before displayed
 * Disable various menu items if links window selected
 *///from ww  w.  j  a  va2 s.c  o  m
public void updateOptionsMenu(Menu menu) {
    // when updating main menu rather than Window options menu
    MenuItem windowSubmenuItemPosition = menu.findItem(R.id.windowSubMenu);
    if (windowSubmenuItemPosition != null) {
        // check the Window sub-menu has been added
        Menu subMenuToPopulate = windowSubmenuItemPosition.getSubMenu();
        if (subMenuToPopulate.findItem(R.id.windowNew) == null) {
            new MenuInflater(BibleApplication.getApplication()).inflate(R.menu.window_popup_menu,
                    subMenuToPopulate);
        }
    }

    MenuItem synchronisedMenuItem = menu.findItem(R.id.windowSynchronise);
    MenuItem moveFirstMenuItem = menu.findItem(R.id.windowMoveFirst);
    MenuItem closeMenuItem = menu.findItem(R.id.windowClose);
    MenuItem minimiseMenuItem = menu.findItem(R.id.windowMinimise);
    MenuItem maximiseMenuItem = menu.findItem(R.id.windowMaximise);
    Window window = getActiveWindow();

    if (synchronisedMenuItem != null && moveFirstMenuItem != null) {
        // set synchronised & maximised checkbox state
        synchronisedMenuItem.setChecked(window.isSynchronised());
        maximiseMenuItem.setChecked(window.isMaximised());

        // the dedicated links window cannot be treated as a normal window
        boolean isDedicatedLinksWindowActive = isActiveWindow(windowRepository.getDedicatedLinksWindow());
        synchronisedMenuItem.setEnabled(!isDedicatedLinksWindowActive);
        moveFirstMenuItem.setEnabled(!isDedicatedLinksWindowActive);

        // cannot close last normal window
        closeMenuItem.setEnabled(isWindowRemovable(window));
        minimiseMenuItem.setEnabled(isWindowMinimisable(window));

        // if window is already first then cannot promote
        List<Window> visibleWindows = windowRepository.getVisibleWindows();
        if (visibleWindows.size() > 0 && window.equals(visibleWindows.get(0))) {
            moveFirstMenuItem.setEnabled(false);
        }
    }
}

From source file:com.example.android.uvdemo.UVFragment.java

/**
 * Respond to the user's selection of the Refresh action item. Start the SwipeRefreshLayout
 * progress bar, then initiate the background task that refreshes the content.
 * <p/>/*  www.  j  a  v a  2s .  c  o m*/
 * <p>A color scheme menu item used for demonstrating the use of SwipeRefreshLayout's color
 * scheme functionality. This kind of menu item should not be incorporated into your app,
 * it just to demonstrate the use of color. Instead you should choose a color scheme based
 * off of your application's branding.
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case com.example.android.uvdemo.R.id.menu_refresh:
        Log.i(LOG_TAG, "Refresh menu item selected");

        // We make sure that the SwipeRefreshLayout is displaying it's refreshing indicator
        if (!isRefreshing()) {
            setRefreshing(true);
        }
        doRequest();
        // Start our refresh background task
        //                initiateRefresh();
        return true;

    case com.example.android.uvdemo.R.id.menu_color_scheme_1:
        Log.i(LOG_TAG, "setColorScheme #1");
        item.setChecked(true);

        // Change the colors displayed by the SwipeRefreshLayout by providing it with 4
        // color resource ids
        setColorScheme(com.example.android.uvdemo.R.color.color_scheme_1_1,
                com.example.android.uvdemo.R.color.color_scheme_1_2,
                com.example.android.uvdemo.R.color.color_scheme_1_3,
                com.example.android.uvdemo.R.color.color_scheme_1_4);
        return true;

    case com.example.android.uvdemo.R.id.menu_color_scheme_2:
        Log.i(LOG_TAG, "setColorScheme #2");
        item.setChecked(true);

        // Change the colors displayed by the SwipeRefreshLayout by providing it with 4
        // color resource ids
        setColorScheme(com.example.android.uvdemo.R.color.color_scheme_2_1,
                com.example.android.uvdemo.R.color.color_scheme_2_2,
                com.example.android.uvdemo.R.color.color_scheme_2_3,
                com.example.android.uvdemo.R.color.color_scheme_2_4);
        return true;

    case com.example.android.uvdemo.R.id.menu_color_scheme_3:
        Log.i(LOG_TAG, "setColorScheme #3");
        item.setChecked(true);

        // Change the colors displayed by the SwipeRefreshLayout by providing it with 4
        // color resource ids
        setColorScheme(com.example.android.uvdemo.R.color.color_scheme_3_1,
                com.example.android.uvdemo.R.color.color_scheme_3_2,
                com.example.android.uvdemo.R.color.color_scheme_3_3,
                com.example.android.uvdemo.R.color.color_scheme_3_4);
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.by_syk.lib.nanoiconpack.fragment.ReqStatsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.menu_show_unmarked) {
        updateData(0, limitLevel);/*from  ww w.  j av a2  s . c o  m*/
        getActivity().invalidateOptionsMenu();
        return true;
    } else if (id == R.id.menu_show_marked) {
        updateData(1, limitLevel);
        getActivity().invalidateOptionsMenu();
        return true;
    } else if (id == R.id.menu_top_32) {
        item.setChecked(true);
        updateData(filterType, 0);
        return true;
    } else if (id == R.id.menu_top_64) {
        item.setChecked(true);
        updateData(filterType, 1);
        return true;
    } else if (id == R.id.menu_top_128) {
        item.setChecked(true);
        updateData(filterType, 2);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.haha01haha01.harail.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_reset) {
        if (!isFailed()) {
            resetEnvironment();//from  w w  w  .  ja v a2  s. c om
        }
        return true;
    } else if (id == R.id.action_download) {
        downloadDb();
        return true;
    } else if (id == R.id.action_set_legacy) {
        classic_mode = !classic_mode;
        item.setChecked(classic_mode);
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.hctrom.romcontrol.MainViewActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    SharedPreferences.Editor editor;/*from   ww w  .j av  a2s  . com*/
    SharedPreferences prefs = getSharedPreferences("ConfigMenuFlotante", Context.MODE_PRIVATE);
    switch (item.getItemId()) {
    case R.id.option1:
        if (item.isChecked()) {
            item.setChecked(false);
            menu.setEnabled(false);
            Toast.makeText(MainViewActivity.this, "Men flotante desactivado", Toast.LENGTH_LONG).show();
            editor = prefs.edit();
            editor.putBoolean("floating_button_activador", false);
            editor.commit();
        } else {
            item.setChecked(true);
            menu.setEnabled(true);
            Toast.makeText(MainViewActivity.this, "Men flotante activado", Toast.LENGTH_LONG).show();
            editor = prefs.edit();
            editor.putBoolean("floating_button_activador", true);
            editor.commit();
        }
        break;
    case R.id.option2:
        if (item.isChecked()) {
            item.setChecked(false);
            fab_close = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fab_close);
            menu.startAnimation(fab_close);
            menu.hide();
            Toast.makeText(MainViewActivity.this, "Men flotante oculto", Toast.LENGTH_LONG).show();
            editor = prefs.edit();
            editor.putBoolean("floating_button_vista", false);
            editor.commit();
        } else {
            item.setChecked(true);
            fab_open = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fab_open);
            menu.startAnimation(fab_open);
            menu.show();
            Toast.makeText(MainViewActivity.this, "Men flotante visible", Toast.LENGTH_LONG).show();
            editor = prefs.edit();
            editor.putBoolean("floating_button_vista", true);
            editor.commit();
        }
        break;
    case R.id.action_reboot:
        showHideRebootMenu();
        break;
    }
    return super.onOptionsItemSelected(item);
}