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.secupwn.aimsicd.ui.activities.MainActivity.java

/**
 * Display latest cell tracking & attack detection truth when opening menu over & over
 *
 * @param menu/* ww  w. ja  v  a  2  s.  c o m*/
 * @return
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // Bail early if there's no service to get the facts from
    if (mAimsicdService == null) {
        return super.onPrepareOptionsMenu(menu);
    }
    MenuItem toggleAttackDetectionMenuItem = menu.findItem(R.id.toggle_attack_detection);
    MenuItem toggleCellTrackingMenuItem = menu.findItem(R.id.toggle_cell_tracking);
    toggleAttackDetectionMenuItem.setChecked(mAimsicdService.isMonitoringCell());
    toggleCellTrackingMenuItem.setChecked(mAimsicdService.isTrackingCell());
    return super.onPrepareOptionsMenu(menu);
}

From source file:cz.yetanotherview.webcamviewer.app.MainActivity.java

private void setupNavDrawer() {

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//ww w .ja va2 s.  c o  m
        public boolean onNavigationItemSelected(MenuItem menuItem) {

            menuItem.setChecked(true);
            mDrawerLayout.closeDrawer(GravityCompat.START);
            String title = menuItem.getTitle().toString();
            switch (menuItem.getItemId()) {
            case R.id.latest_webcams:
                setNewRootFragment(StandardAppBarFragment.newInstance(), R.id.latest_webcams, title);
                return true;
            case R.id.popular_webcams:
                setNewRootFragment(StandardAppBarFragment.newInstance(), R.id.popular_webcams, title);
                return true;
            case R.id.nearby_webcams:
                setNewRootFragment(StandardAppBarFragment.newInstance(), R.id.nearby_webcams, title);
                return true;
            case R.id.selecting_by_name:
                setNewRootFragment(SearchAppBarFragment.newInstance(), R.id.selecting_by_name, title);
                return true;
            case R.id.selecting_by_country:
                //setNewRootFragment(StandardAppBarFragment.newInstance(), R.id.selecting_by_country, title);
                return true;
            case R.id.selecting_by_type:
                setNewRootFragment(TabHolderFragment.newInstance(), R.id.selecting_by_type, title);
                return true;
            case R.id.live_streams:
                setNewRootFragment(StandardAppBarFragment.newInstance(), R.id.live_streams, title);
                return true;
            case R.id.selecting_from_map:
                setNewRootFragment(MapAppBarFragment.newInstance(), R.id.selecting_from_map, title);
                return true;
            case R.id.favorites_webcams:
                //setNewRootFragment(StandardAppBarFragment.newInstance(), R.id.favorites_webcams, title);
                return true;
            case R.id.all_local_webcams:
                setNewRootFragment(StandardLocalAppBarFragment.newInstance(), R.id.all_local_webcams, title);
                return true;
            case R.id.action_settings:
                openSettings();
                return true;
            case R.id.action_menu_help:
                openHelp();
                return true;
            default:
                return true;
            }
        }
    });
}

From source file:com.landenlabs.all_devtool.ScreenFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int pos = -1;
    int id = item.getItemId();
    switch (id) {
    case R.id.screen_clear_menu:
        m_drawPoints.clear();//from   w w w .  ja v  a 2  s.c  om
        break;
    case R.id.screen_freeze_menu:
        m_drawPoints.autoPrune(false);
        break;
    case R.id.screen_prune_menu:
        m_drawPoints.autoPrune(true);
        break;

    default:
        break;
    }

    item.setChecked(true);
    return super.onOptionsItemSelected(item);
}

From source file:ca.ualberta.cmput301w14t08.geochan.fragments.ThreadViewFragment.java

/**
 * Checks the proper sort option in our options menu.
 * @param sort Code for the sort type./*from   w  w  w  .  j av a2  s.  c  om*/
 * @param menu The fragment's menu.
 */
private void setSortCheck(int sort, Menu menu) {
    MenuItem item;
    switch (sort) {
    case SortUtil.SORT_DATE_NEWEST:
        item = menu.findItem(R.id.comment_sort_date_new);
        item.setChecked(true);
        return;
    case SortUtil.SORT_DATE_OLDEST:
        item = menu.findItem(R.id.comment_sort_date_new);
        item.setChecked(true);
        return;
    case SortUtil.SORT_LOCATION:
        item = menu.findItem(R.id.comment_sort_location);
        item.setChecked(true);
        return;
    case SortUtil.SORT_USER_SCORE_HIGHEST:
        item = menu.findItem(R.id.comment_sort_score_high);
        item.setChecked(true);
        return;
    case SortUtil.SORT_USER_SCORE_LOWEST:
        item = menu.findItem(R.id.comment_sort_score_low);
        item.setChecked(true);
        return;
    case SortUtil.SORT_IMAGE:
        item = menu.findItem(R.id.comment_sort_image);
        item.setChecked(true);
        return;
    default:
        return;
    }
}

From source file:com.example.amand.mobileprogrammingfitnessapp.LoggedActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_logged);

    // toolbar reference, and is used to instantiate the toolbar
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitleTextColor(0xFFFFFFFF);
    setSupportActionBar(toolbar);/*  www .  j  a v a 2  s.  c om*/
    // this sets the toolbar colour and replaces the action bar, although this activity has style
    // of no actionbar

    // dialog is instantiated, and is set up with appropriate message, that is displayed when the user
    // presses the about icon
    dialog = new AlertDialog.Builder(this);
    dialog.setTitle("About");
    dialog.setMessage("This appliation was developed for Mobile & Ubiquitous Computing. This application"
            + "is a fitness app and composed of contents, such as nutrition, health, exercises and gym facilities."
            + "The gym facilities provides numerous features, such as displaying gyms near you"
            + System.lineSeparator()
            + "The application makes use of a circular Imageview that under apache 2.0 Licencing"
            + "http://www.apache.org/licenses/LICENSE-2.0.txt");

    // Reference to the database object, which is used to recieve users information
    database = new Database(getApplicationContext(), null, null, 1);
    // reference to the navogationn view that consists of navigation header and items
    navigationView = (NavigationView) findViewById(R.id.navigation_view);
    // the first fragment is loaded
    switchFragment(1);
    toolbar.setTitle("Nutrition");
    // the references to textviews and circle imageview to change the details of the navigation drawer
    header = navigationView.getHeaderView(0);
    circle = (CircleImageView) header.findViewById(R.id.profile_image);
    namee = (TextView) header.findViewById(R.id.fullnameheader);
    username = (TextView) header.findViewById(R.id.usernameheader);
    naviagtionbackground = (RelativeLayout) header.findViewById(R.id.navbackground);
    // reference to the drawerlayout
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    // reference to framelayout
    frame = (FrameLayout) findViewById(R.id.Screen);
    // the decode stream
    decode = new byte[100];
    // this gets the information that is passed in from the register screen. The data is the username, and
    //is needed when using the database methods
    // if the data recieved is null, then the visabilty of the setting icon is false
    Intent intt = getIntent();
    temp = intt.getStringExtra("key");
    if (temp == null) {
        setting = false;
    }

    //Two methods are called, when the oncreate method has ran, the first method is responsible
    //in displaying the users detail in the navigation drawer, takes the username as parameters
    // Likewise the loadpreference method, loads the preference of each user
    setNavigationDetails(temp);
    loadpreferences(temp);
    //      //  database.loadPreferenes(temp);
    //        objectDdecode = database.loadPreferenes(temp);
    //        Toast.makeText(getApplicationContext(),"done" +database.loadPreferenes(temp).toString(),Toast.LENGTH_LONG).show();
    //        Toast.makeText(getApplicationContext(),objectDdecode.toString(),Toast.LENGTH_LONG).show();

    // the naviagtion view is set with item click listener. This listens to the click of items that are
    // present in the application
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        // this method is responosble for dealing with the menu items that have been clicked.
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            // checks if the item has been selected, if its not selected set to false
            // else make it true to indicate its been checked
            if (menuItem.isChecked())
                menuItem.setChecked(false);
            else
                menuItem.setChecked(true);
            //closes the naviagtion drawer once checked
            drawerLayout.closeDrawers();

            //switch condidtion to assess what action is performed once the item has been  checked
            switch (menuItem.getItemId()) {
            // the nutrition fragment is selected, if the gym icon is showing, it will disappear
            // the toolbar text is also set to nutrition
            case R.id.nutritionF:
                switchFragment(1);
                show = false;
                // reloads the option menu
                invalidateOptionsMenu();
                toolbar.setTitle("Nutrition");
                return true;

            // the health fragment is selected, if the gym icon is showing, it will disappear
            // the toolbar text is also set to Health
            case R.id.HealthF:
                switchFragment(3);
                toolbar.setTitle("Health");
                show = false;
                // reloads the option menu
                invalidateOptionsMenu();
                return true;
            // the exercie fragment is selected, if the gym icon is showing, it will disappear
            // the toolbar text is also set to Exercise
            case R.id.ExerciseF:
                Toast.makeText(getApplicationContext(), "Exercise", Toast.LENGTH_SHORT).show();
                switchFragment(2);
                toolbar.setTitle("Exercises");
                show = false;
                // reloads the option menu
                invalidateOptionsMenu();
                return true;
            // the gym fragment is selected, if the gym icon is not showing, it will appear
            // the toolbar text is also set to gym
            case R.id.GymF:
                Toast.makeText(getApplicationContext(), "Gym Selected", Toast.LENGTH_SHORT).show();
                switchFragment(4);
                toolbar.setTitle("Gym Facilities");
                show = true;
                // reloads the option menu, to show the gym action icon
                invalidateOptionsMenu();
                return true;
            // the logout item would just be intent back to the login screen.
            // to ensure user cannot travel back, the finish method is called to delete activity off the
            // stack
            case R.id.logoffF:
                Intent intt = new Intent(getApplicationContext(), LoginScreen.class);
                startActivity(intt);
                finish();
                return true;
            // by default, even though this shouldnt happen, a toast message is presented to the user
            default:
                Toast.makeText(getApplicationContext(),
                        "Somethings Wrong, please contact amandeep for more detail", Toast.LENGTH_SHORT).show();
                return true;

            }
        }
    });
    //Syncs the actionbartoggle to sync in with the toolbar
    new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.opendrawer, R.string.closedrawer)
            .syncState();

}

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

@Override
public void onBackPressed() {
    super.onBackPressed();
    if (titles.size() > 1) {
        titles.pop();//from  w ww  . j av a 2 s.  c  o m
        mTitle = titles.peek();
    }
    Menu menuNav = navigationView.getMenu();
    int i = 0;
    int mSize = menuNav.size();
    while (i < mSize) {
        if (menuNav.getItem(i).getTitle() == mTitle) {
            MenuItem _current = menuNav.getItem(i);
            if (lastSelected != _current) {
                //remove last
                lastSelected.setChecked(false);
                // udpate for the next
                lastSelected = _current;
            }
            //set checked
            _current.setChecked(true);
            i = mSize;
        }
        i++;
    }
    restoreActionBar();
}

From source file:com.teitsmch.hearthmaker.MainActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
    menuItem.setChecked(true);
    if (mPreviousMenuItem != null) {
        mPreviousMenuItem.setChecked(false);
    }//from w  w  w  . ja v  a  2  s  . c  om
    mPreviousMenuItem = menuItem;
    selectItem(menuItem);
    invalidateOptionsMenu();
    return true;
}

From source file:com.irateam.vkplayer.activities.ListActivity.java

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    MenuItem menuItem = navigationView.getMenu().findItem(R.id.current_playlist);
    switch (item.getItemId()) {
    case R.id.action_play:
        playerService.setPlaylist(audioAdapter.getCheckedItems());
        playerService.play(0);//from   w  ww.  j ava 2  s.co m
        menuItem.setChecked(true);
        onNavigationItemSelected(menuItem);
        break;

    case R.id.action_cache:
        Intent intent = new Intent(this, DownloadService.class);
        intent.setAction(DownloadService.START_DOWNLOADING);
        intent.putExtra(DownloadService.AUDIO_LIST, (ArrayList<Audio>) audioAdapter.getCheckedItems());
        startService(intent);
        break;

    case R.id.action_remove_from_cache:
        List<Audio> list = audioAdapter.getCachedCheckedItems();
        audioService.removeFromCache(list, new AudioService.Listener() {
            @Override
            public void onComplete(List<Audio> list) {
                audioAdapter.updateAudiosById(list);
            }

            @Override
            public void onError(String errorMessage) {

            }
        });
        break;

    case R.id.action_delete:
        audioAdapter.removeChecked();
        break;

    case R.id.action_add_to_playlist:
        List<Audio> checked = audioAdapter.getCheckedItems();
        List<Audio> playlist = playerService.getPlaylist();
        List<Audio> listToAdd = new ArrayList<>();
        for (Audio audio : checked) {
            listToAdd.add(audio.clone());
        }
        playlist.addAll(0, listToAdd);
        audioAdapter.notifyDataSetChanged();
        Snackbar.make(coordinatorLayout, R.string.snackbar_add_to_playlist, Snackbar.LENGTH_LONG)
                .setAction(R.string.snackbar_cancel, (v -> {
                    for (int i = 0; i < checked.size(); i++)
                        playlist.remove(0);
                    audioAdapter.notifyDataSetChanged();
                })).show();
        break;
    }
    mode.finish();
    return true;
}

From source file:com.microhealthllc.mbmicalc.BmiChart.java

private void setUpNavigationDrawer() {
    /*/*  w w  w.  j a  v  a2 s .c  om*/
            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
            ActionBar actionBar = getSupportActionBar();
            
            try {
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setSubtitle(getString(R.string.subtitle));
    actionBar.setDisplayShowTitleEnabled(true);
            } catch (Exception ignored) {
            }
    */
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mNavigationView = (NavigationView) findViewById(R.id.navigation_view);
    mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            switch (menuItem.getItemId()) {
            case R.id.navigation_item_1:
                // mCurrentSelectedPosition = 0;
                break;
            case R.id.navigation_item_2:
                //  mCurrentSelectedPosition = 1;
                Intent i = new Intent(BmiChart.this, BasicSettings.class);
                startActivity(i);

                break;
            case R.id.navigation_item_3:
                //    mCurrentSelectedPosition = 2;
                Intent j = new Intent(BmiChart.this, LogActivity.class);
                startActivity(j);
                break;
            case R.id.navigation_item_4:
                //   mCurrentSelectedPosition = 3;
                new LovelyStandardDialog(BmiChart.this).setTopColorRes(R.color.accent)
                        .setButtonsColorRes(R.color.accent)

                        .setTitle("Warning!!")
                        .setMessage(" This will delete all stored data,This cannot be undone")
                        .setPositiveButton(android.R.string.ok, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Toast.makeText(BmiChart.this, "positive clicked", Toast.LENGTH_SHORT).show();

                                db.deleteEntry();

                                Intent i = new Intent(BmiChart.this, BmiChart.class);
                                startActivity(i);
                            }
                        }).setNegativeButton(android.R.string.no, null).show();

                break;
            case R.id.navigation_item_5:

                Intent about = new Intent(BmiChart.this, About.class);
                startActivity(about);

                break;
            case R.id.navigation_item_6:
                Intent js = new Intent(BmiChart.this, LineColumnDependencyActivity.class);
                startActivity(js);
                break;
            case R.id.bmi_info:
                showAdditionalBmiInfo();

            }

            // setTabs(mCurrentSelectedPosition + 1);
            mDrawerLayout.closeDrawer(mNavigationView);
            return true;
        }
    });

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open,
            R.string.drawer_close) {
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            //getSupportActionBar().setTitle(getString(R.string.drawer_opened));
            invalidateOptionsMenu();
        }

        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            //getSupportActionBar().setTitle(mActivityTitle);
            invalidateOptionsMenu();
        }
    };

    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerToggle.syncState();

}

From source file:com.pawnua.android.app.gpstrips.activities.TripDetailActivity.java

@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(false);
    else/*from  w w  w  .ja  v a2s. co  m*/
        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.action_openMap:
        openMap();
        return true;

    case R.id.action_show_camera: {

        takePhoto();
        return true;
    }

    case R.id.action_show_gallery: {

        openThumbGallery();
        return true;
    }

    case R.id.action_export: {

        saveTripTask(trip);
        return true;
    }

    case R.id.action_about: {
        new AboutFragment().show(mFragmentManager, "about_layout");
        return true;
    }

    default:
        Toast.makeText(getApplicationContext(), R.string.SmthWrong, Toast.LENGTH_SHORT).show();
        return true;

    }
}