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:chaitanya.im.searchforreddit.LauncherActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    Log.d(TAG, "onCreateOptionsMenu");
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);
    MenuItem actionDark = menu.findItem(R.id.action_dark);

    if (donate == 1) {
        menu.findItem(R.id.action_donate).setVisible(false);
    }// w w  w .j  a v a2s. co m

    if (theme != 0) {
        actionDark.setChecked(true);
        isChecked = true;
        searchEditText.getText().clear();
        menu.findItem(R.id.action_refresh).setIcon(R.drawable.ic_refresh_white);
    }

    return true;
}

From source file:com.todev.rabbitmqmanagement.ui.drawer.DrawerActivity.java

@Override
public boolean onNavigationMenuItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.nav_overview:
        presenter.onOverviewMenuItemClicked();
        break;//from   w  w w.ja va  2  s  .c o m
    case R.id.nav_connections:
        presenter.onConnectionsMenuItemClicked();
        break;
    case R.id.nav_channels:
        presenter.onChannelsMenuItemClicked();
        break;
    case R.id.nav_exchanges:
        presenter.onExchangesMenuItemClicked();
        break;
    case R.id.nav_queues:
        presenter.onQueuesMenuItemClicked();
        break;
    case R.id.nav_admin:
        presenter.onAdminMenuItemClicked();
        break;
    default:
        presenter.onOverviewMenuItemClicked();
    }

    item.setChecked(true);
    drawerLayoutView.closeDrawer(GravityCompat.START);

    return true;
}

From source file:com.money.manager.ex.currency.list.CurrencyListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    CurrencyUIFeatures ui = new CurrencyUIFeatures(getActivity());

    switch (item.getItemId()) {
    case R.id.menu_import_all_currencies:
        ui.showDialogImportAllCurrencies();
        return true;

    case R.id.menu_update_exchange_rate:
        ui.showDialogUpdateExchangeRates();
        break;//from ww w  .  j  av  a 2s. co  m

    case R.id.menu_show_used:
        if (item.isChecked()) {
            item.setChecked(false);
            // list all accounts
            mShowOnlyUsedCurrencies = false;
            reloadData();
        } else {
            item.setChecked(true);
            // list only used accounts
            mShowOnlyUsedCurrencies = true;
            reloadData();
        }
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.example.db.messagewall.activity.MainActivity.java

private void setupDrawerContent(NavigationView navigationView) {

    CircleImageView imageView = (CircleImageView) navigationView.findViewById(R.id.account_logo);
    final TextView textView = (TextView) navigationView.findViewById(R.id.account_name);
    final TextView nichen = (TextView) navigationView.findViewById(R.id.account_nichen);
    /*/* w ww . j a  va  2 s .c  o m*/
    
     */
    AVQuery<AVObject> query = new AVQuery<AVObject>("NiChen");
    query.whereEqualTo("username", AVUser.getCurrentUser().getUsername());
    query.findInBackground(new FindCallback<AVObject>() {
        @Override
        public void done(List<AVObject> list, AVException e) {
            if (e == null) {
                AVObject avObject = (AVObject) list.get(0);
                if (avObject.get("nichen").toString() != null) {
                    textView.setText("?: " + AVUser.getCurrentUser().getUsername());
                    nichen.setText(": " + avObject.get("nichen").toString());
                } else {
                    textView.setText("?: " + AVUser.getCurrentUser().getUsername());
                    nichen.setText(": " + AVUser.getCurrentUser().getUsername());
                }
            } else {
                e.printStackTrace();
            }
        }
    });
    /*
    logo
     */
    SharedPreferences sharedPreferences = this.getSharedPreferences("com.example.db.alife_walllogo",
            Context.MODE_PRIVATE);
    String paper = sharedPreferences.getString("paper_path", "");
    if (paper.equals("")) {
        imageView.setBackgroundResource(R.drawable.head_xiaoqiang_m);
    } else {
        Bitmap bitmap = BitmapFactory.decodeFile(paper);
        imageView.setImageBitmap(bitmap);
    }
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, PersonInfoActivity.class);
            intent.putExtras(bundle);
            startActivity(intent);
        }
    });

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

            switch (menuItem.getItemId()) {

            case R.id.nav_home:

                toolbar.setTitle(menuItem.getTitle());
                MessageWallFragment messageWallFeagment = new MessageWallFragment();
                messageWallFeagment.setArguments(bundle);
                fragmentTransaction = getSupportFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.container, messageWallFeagment).commit();
                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();

                break;

            case R.id.nav_partner:

                toolbar.setTitle(menuItem.getTitle());
                MembersFragment membersFragment = new MembersFragment();
                membersFragment.setArguments(bundle);
                fragmentTransaction = getSupportFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.container, membersFragment).commit();
                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();

                break;

            case R.id.nav_messages:

                toolbar.setTitle(menuItem.getTitle());
                WallInfoFragment wallInfoFragment = new WallInfoFragment();
                wallInfoFragment.setArguments(bundle);
                fragmentTransaction = getSupportFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.container, wallInfoFragment).commit();
                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();

                break;

            case R.id.nav_edit:

                toolbar.setTitle(menuItem.getTitle());
                fragmentTransaction = getSupportFragmentManager().beginTransaction();
                EditWallPaperFragment editWallPaperFeagment = new EditWallPaperFragment();
                editWallPaperFeagment.setArguments(bundle);
                fragmentTransaction.replace(R.id.container, editWallPaperFeagment).commit();
                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();

                break;

            case R.id.nav_add:

                toolbar.setTitle(menuItem.getTitle());
                AskMembersFragment askMembersFragment = new AskMembersFragment();
                askMembersFragment.setArguments(bundle);
                fragmentTransaction = getSupportFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.container, askMembersFragment).commit();
                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();

                break;

            case R.id.nav_alert:

                toolbar.setTitle(menuItem.getTitle());
                startActivity(new Intent(MainActivity.this, AlertWallActivity.class));
                MainActivity.this.finish();
                menuItem.setChecked(true);
                mDrawerLayout.closeDrawers();

                break;

            }
            return true;
        }
    });
}

From source file:no.group09.ucsoftwarestore.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.menu_search:
        onSearchRequested();//from w w  w . j av a 2  s  .  c  o m
        return true;

    case R.id.toggle_incompitable:

        //Prepare to edit the setting
        Editor edit = sharedPref.edit();

        //Fetches the current value of the 'hide incompatible' option in the preference file
        boolean hideIncompatible = sharedPref.getBoolean("hide_incompatible", false);

        if (hideIncompatible == true) {

            //Changes the value and commits the changes
            edit.putBoolean("hide_incompatible", false);
            edit.commit();

            item.setChecked(false);
        }

        else {
            //Changes the value and commits the changes
            edit.putBoolean("hide_incompatible", true);
            edit.commit();

            item.setChecked(true);
        }

        return true;

    //Start the preferences class
    case R.id.settings:
        //Create an intent to start the preferences activity
        Intent myIntent = new Intent(getApplicationContext(), Preferences.class);
        this.startActivity(myIntent);
        return true;

    //Show the device list
    case R.id.device_list:
        Intent intent = new Intent(this, Devices.class);
        startActivity(intent);
        return true;

    default:
        return false;
    }
}

From source file:com.granita.tasks.TaskListFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*w  ww .ja va 2s  . com*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // create menu
    inflater.inflate(R.menu.task_list_fragment_menu, menu);

    // restore menu state
    MenuItem item = menu.findItem(R.id.menu_show_completed);
    if (item != null) {
        item.setChecked(mSavedCompletedFilter);

        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            if (mSavedCompletedFilter) {
                item.setTitle(R.string.menu_hide_completed);
            } else {
                item.setTitle(R.string.menu_show_completed);
            }
        }
    }
}

From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java

public void refreshDrawer() {
    Menu menu = navView.getMenu();
    menu.clear();//from www. jav  a  2 s  . c om
    actionViewStateManager.deselectCurrentActionView();

    int order = 0;
    ArrayList<String> storageDirectories = mainActivity.getStorageDirectories();
    phoneStorageCount = 0;
    for (String file : storageDirectories) {
        if (file.contains(OTGUtil.PREFIX_OTG)) {
            addNewItem(menu, STORAGES_GROUP, order++, "OTG", new MenuMetadata(file),
                    R.drawable.ic_usb_white_24dp, R.drawable.ic_show_chart_black_24dp);
            continue;
        }

        File f = new File(file);
        String name;
        @DrawableRes
        int icon1;
        if ("/storage/emulated/legacy".equals(file) || "/storage/emulated/0".equals(file)
                || "/mnt/sdcard".equals(file)) {
            name = resources.getString(R.string.storage);
            icon1 = R.drawable.ic_phone_android_white_24dp;
        } else if ("/storage/sdcard1".equals(file)) {
            name = resources.getString(R.string.extstorage);
            icon1 = R.drawable.ic_sd_storage_white_24dp;
        } else if ("/".equals(file)) {
            name = resources.getString(R.string.rootdirectory);
            icon1 = R.drawable.ic_drawer_root_white;
        } else {
            name = f.getName();
            icon1 = R.drawable.ic_sd_storage_white_24dp;
        }

        if (f.isDirectory() || f.canExecute()) {
            addNewItem(menu, STORAGES_GROUP, order++, name, new MenuMetadata(file), icon1,
                    R.drawable.ic_show_chart_black_24dp);
            if (phoneStorageCount == 0)
                firstPath = file;
            else if (phoneStorageCount == 1)
                secondPath = file;

            phoneStorageCount++;
        }
    }
    dataUtils.setStorages(storageDirectories);

    if (dataUtils.getServers().size() > 0) {
        Collections.sort(dataUtils.getServers(), new BookSorter());
        synchronized (dataUtils.getServers()) {
            for (String[] file : dataUtils.getServers()) {
                addNewItem(menu, SERVERS_GROUP, order++, file[0], new MenuMetadata(file[1]),
                        R.drawable.ic_settings_remote_white_24dp, R.drawable.ic_edit_24dp);
            }
        }
    }

    ArrayList<String[]> accountAuthenticationList = new ArrayList<>();

    if (CloudSheetFragment.isCloudProviderAvailable(mainActivity)) {
        for (CloudStorage cloudStorage : dataUtils.getAccounts()) {
            @DrawableRes
            int deleteIcon = R.drawable.ic_delete_grey_24dp;

            if (cloudStorage instanceof Dropbox) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_DROPBOX,
                        new MenuMetadata(CloudHandler.CLOUD_PREFIX_DROPBOX + "/"),
                        R.drawable.ic_dropbox_white_24dp, deleteIcon);

                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_DROPBOX,
                        CloudHandler.CLOUD_PREFIX_DROPBOX + "/", });
            } else if (cloudStorage instanceof Box) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_BOX,
                        new MenuMetadata(CloudHandler.CLOUD_PREFIX_BOX + "/"), R.drawable.ic_box_white_24dp,
                        deleteIcon);

                accountAuthenticationList.add(
                        new String[] { CloudHandler.CLOUD_NAME_BOX, CloudHandler.CLOUD_PREFIX_BOX + "/", });
            } else if (cloudStorage instanceof OneDrive) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_ONE_DRIVE,
                        new MenuMetadata(CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/"),
                        R.drawable.ic_onedrive_white_24dp, deleteIcon);

                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_ONE_DRIVE,
                        CloudHandler.CLOUD_PREFIX_ONE_DRIVE + "/", });
            } else if (cloudStorage instanceof GoogleDrive) {
                addNewItem(menu, CLOUDS_GROUP, order++, CloudHandler.CLOUD_NAME_GOOGLE_DRIVE,
                        new MenuMetadata(CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/"),
                        R.drawable.ic_google_drive_white_24dp, deleteIcon);

                accountAuthenticationList.add(new String[] { CloudHandler.CLOUD_NAME_GOOGLE_DRIVE,
                        CloudHandler.CLOUD_PREFIX_GOOGLE_DRIVE + "/", });
            }
        }
        Collections.sort(accountAuthenticationList, new BookSorter());
    }

    if (mainActivity.getBoolean(PREFERENCE_SHOW_SIDEBAR_FOLDERS)) {
        if (dataUtils.getBooks().size() > 0) {

            Collections.sort(dataUtils.getBooks(), new BookSorter());

            synchronized (dataUtils.getBooks()) {
                for (String[] file : dataUtils.getBooks()) {
                    addNewItem(menu, FOLDERS_GROUP, order++, file[0], new MenuMetadata(file[1]),
                            R.drawable.ic_folder_white_24dp, R.drawable.ic_edit_24dp);
                }
            }
        }
    }

    Boolean[] quickAccessPref = TinyDB.getBooleanArray(mainActivity.getPrefs(), QuickAccessPref.KEY,
            QuickAccessPref.DEFAULT);

    if (mainActivity.getBoolean(PREFERENCE_SHOW_SIDEBAR_QUICKACCESSES)) {
        if (quickAccessPref[0]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.quick, new MenuMetadata("5"),
                    R.drawable.ic_star_white_24dp, null);
        }
        if (quickAccessPref[1]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.recent, new MenuMetadata("6"),
                    R.drawable.ic_history_white_24dp, null);
        }
        if (quickAccessPref[2]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.images, new MenuMetadata("0"),
                    R.drawable.ic_photo_library_white_24dp, null);
        }
        if (quickAccessPref[3]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.videos, new MenuMetadata("1"),
                    R.drawable.ic_video_library_white_24dp, null);
        }
        if (quickAccessPref[4]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.audio, new MenuMetadata("2"),
                    R.drawable.ic_library_music_white_24dp, null);
        }
        if (quickAccessPref[5]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.documents, new MenuMetadata("3"),
                    R.drawable.ic_library_books_white_24dp, null);
        }
        if (quickAccessPref[6]) {
            addNewItem(menu, QUICKACCESSES_GROUP, order++, R.string.apks, new MenuMetadata("4"),
                    R.drawable.ic_apk_library_white_24dp, null);
        }
    }

    addNewItem(menu, LASTGROUP, order++, R.string.ftp, new MenuMetadata(() -> {
        FragmentTransaction transaction2 = mainActivity.getSupportFragmentManager().beginTransaction();
        transaction2.replace(R.id.content_frame, new FtpServerFragment());
        mainActivity.getAppbar().getAppbarLayout().animate().translationY(0)
                .setInterpolator(new DecelerateInterpolator(2)).start();
        pending_fragmentTransaction = transaction2;
        if (!isDrawerLocked)
            close();
        else
            onDrawerClosed();
    }), R.drawable.ic_ftp_white_24dp, null);

    addNewItem(menu, LASTGROUP, order++, R.string.apps, new MenuMetadata(() -> {
        FragmentTransaction transaction2 = mainActivity.getSupportFragmentManager().beginTransaction();
        transaction2.replace(R.id.content_frame, new AppsListFragment());
        mainActivity.getAppbar().getAppbarLayout().animate().translationY(0)
                .setInterpolator(new DecelerateInterpolator(2)).start();
        pending_fragmentTransaction = transaction2;
        if (!isDrawerLocked)
            close();
        else
            onDrawerClosed();
    }), R.drawable.ic_android_white_24dp, null);

    addNewItem(menu, LASTGROUP, order++, R.string.setting, new MenuMetadata(() -> {
        Intent in = new Intent(mainActivity, PreferencesActivity.class);
        mainActivity.startActivity(in);
        mainActivity.finish();
    }), R.drawable.ic_settings_white_24dp, null);

    for (int i = 0; i < navView.getMenu().size(); i++) {
        navView.getMenu().getItem(i).setEnabled(true);
    }

    for (int group : GROUPS) {
        menu.setGroupCheckable(group, true, true);
    }

    MenuItem item = navView.getSelected();
    if (item != null) {
        item.setChecked(true);
        actionViewStateManager.selectActionView(item);
        isSomethingSelected = true;
    }
}

From source file:com.cx.demo.common.BaseDrawerLayoutActivity.java

/**
 * set menu item check status//ww  w  .j  av a2s.  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.camnter.easygank.core.BaseDrawerLayoutActivity.java

/**
 * set menu item check status//  w  w w. j  av  a  2s. 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:org.dmfs.tasks.TaskListActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_visible_list) {
        Intent settingsIntent = new Intent(getBaseContext(), SyncSettingsActivity.class);
        startActivity(settingsIntent);//w w w  .j  a  v a  2 s .c  o  m
        return true;
    } else if (item.getItemId() == R.id.menu_alarms) {
        // set and save state
        boolean activatedAlarms = !item.isChecked();
        item.setChecked(activatedAlarms);
        AlarmBroadcastReceiver.setAlarmPreference(this, activatedAlarms);
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}