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.owncloud.android.ui.adapter.UserListAdapter.java

/**
 * Updates the sharee's menu with the current permissions of the {@link OCShare}
 *
 * @param menu  the menu of the sharee/shared file
 * @param share the shared file/* w  w  w.  ja  v a 2 s. co  m*/
 */
private void prepareOptionsMenu(Menu menu, OCShare share) {

    MenuItem editCreateItem = menu.findItem(R.id.action_can_edit_create);
    MenuItem editChangeItem = menu.findItem(R.id.action_can_edit_change);
    MenuItem editDeleteItem = menu.findItem(R.id.action_can_edit_delete);

    MenuItem hideFileListingItem = menu.findItem(R.id.action_hide_file_listing);
    MenuItem passwordItem = menu.findItem(R.id.action_password);
    MenuItem expirationDateItem = menu.findItem(R.id.action_expiration_date);

    MenuItem reshareItem = menu.findItem(R.id.action_can_reshare);

    if (isReshareForbidden(share)) {
        reshareItem.setVisible(false);
    }
    reshareItem.setChecked(canReshare(share));

    if (share.getShareType() == ShareType.EMAIL) {
        SharingMenuHelper.setupHideFileListingMenuItem(hideFileListingItem, file.isFolder(), canEdit(share),
                share.getPermissions());
        SharingMenuHelper.setupPasswordMenuItem(passwordItem, share.isPasswordProtected());

        reshareItem.setVisible(false);
        editCreateItem.setVisible(false);
        editChangeItem.setVisible(false);
        editDeleteItem.setVisible(false);
    } else {
        if (file.isFolder() && isEditOptionsAvailable(share)) {
            /// TODO change areEditOptionsAvailable in order to delete !isFederated
            editCreateItem.setChecked(canCreate(share));
            editChangeItem.setChecked(canUpdate(share));
            editDeleteItem.setChecked(canDelete(share));
        } else {
            editCreateItem.setVisible(false);
            editChangeItem.setVisible(false);
            editDeleteItem.setVisible(false);
        }

        hideFileListingItem.setVisible(false);
        passwordItem.setVisible(false);
        expirationDateItem.setVisible(false);
    }

    SharingMenuHelper.setupExpirationDateMenuItem(menu.findItem(R.id.action_expiration_date),
            share.getExpirationDate(), context.getResources());
}

From source file:com.github.chenxiaolong.dualbootpatcher.MainActivity.java

private void onDrawerItemClicked(@IdRes final int item, boolean userClicked) {
    if (mDrawerItemSelected == item && userClicked) {
        mDrawerLayout.closeDrawer(mDrawerView);
        return;// w  ww.j a  v a 2  s  .  c om
    }

    if (isItemAFragment(item)) {
        mDrawerItemSelected = item;
        // Animate if user clicked
        hideFragments(userClicked);

        Menu menu = mDrawerView.getMenu();
        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            menuItem.setChecked(menuItem.getItemId() == item);
        }
    }

    if (mDrawerLayout.isDrawerOpen(mDrawerView)) {
        mPending = new Runnable() {
            @Override
            public void run() {
                performDrawerItemSelection(item);
            }
        };
    } else {
        performDrawerItemSelection(item);
    }

    mDrawerLayout.closeDrawer(mDrawerView);
}

From source file:com.bringcommunications.etherpay.SendActivity.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.show_gas: {
        boolean show_gas = item.isChecked() ? false : true;
        item.setChecked(show_gas);
        SharedPreferences.Editor preferences_editor = preferences.edit();
        preferences_editor.putBoolean("show_gas", show_gas);
        preferences_editor.apply();/*from  www . j a  v a  2 s  . com*/
        recreate();
        return true;
    }
    case R.id.show_data: {
        boolean show_data = item.isChecked() ? false : true;
        item.setChecked(show_data);
        SharedPreferences.Editor preferences_editor = preferences.edit();
        preferences_editor.putBoolean("show_data", show_data);
        preferences_editor.apply();
        recreate();
        return true;
    }
    case R.id.help:
        do_help(R.string.send_help_title, R.string.send_help);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.example.carrie.carrie_test1.druginfo.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_druginfo);
    Bundle bundle = getIntent().getExtras();
    my_id = bundle.getString("my_id");//get  id
    my_google_id = bundle.getString("my_google_id");//get google_ id
    my_mon_id = bundle.getString("my_supervise_id");
    m_calid = bundle.getString("m_calid", "not found");

    Log.d("qqqqq", m_calid);

    btmbar = (RelativeLayout) findViewById(R.id.btmbar);
    if (my_id.equals("0") && my_google_id.equals("0") && my_mon_id.equals("0")) {
        //???????
        btmbar.setVisibility(View.GONE);
    } else {/* w w w  . ja  v  a 2 s  . c  om*/
        BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavView_Bar);
        BottomNavigationViewHelper.disableShiftMode(bottomNavigationView);
        Menu menu = bottomNavigationView.getMenu();
        MenuItem menuItem = menu.getItem(3);
        menuItem.setChecked(true);

        bottomNavigationView.setOnNavigationItemSelectedListener(
                new BottomNavigationView.OnNavigationItemSelectedListener() {
                    @Override
                    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                        switch (item.getItemId()) {
                        case R.id.ic_list:
                            Intent intent0 = new Intent(druginfo.this, Choice.class);
                            Bundle bundle0 = new Bundle();
                            bundle0.putString("memberid", my_id);
                            bundle0.putString("my_google_id", my_google_id);
                            bundle0.putString("my_supervise_id", my_mon_id);
                            intent0.putExtras(bundle0); // put???
                            startActivity(intent0);
                            break;

                        case R.id.ic_eye:
                            Intent intent1 = new Intent(druginfo.this, MonitorActivity.class);
                            Bundle bundle1 = new Bundle();
                            bundle1.putString("my_id", my_id);
                            bundle1.putString("my_google_id", my_google_id);
                            bundle1.putString("my_supervise_id", my_mon_id);
                            intent1.putExtras(bundle1);
                            startActivity(intent1);
                            break;

                        case R.id.ic_home:
                            Intent intent2 = new Intent(druginfo.this, MainActivity.class);
                            Bundle bundle2 = new Bundle();
                            bundle2.putString("googleid", my_google_id);
                            intent2.putExtras(bundle2);
                            startActivity(intent2);
                            break;

                        case R.id.ic_information:
                            Intent intent3 = new Intent(druginfo.this, druginfo.class);
                            Bundle bundle3 = new Bundle();
                            bundle3.putString("my_id", my_id);
                            bundle3.putString("my_google_id", my_google_id);
                            bundle3.putString("my_supervise_id", my_mon_id);
                            intent3.putExtras(bundle3);
                            startActivity(intent3);
                            break;

                        case R.id.ic_beacon:
                            Intent intent4 = new Intent(druginfo.this, Beacon.class);
                            Bundle bundle4 = new Bundle();
                            bundle4.putString("my_id", my_id);
                            bundle4.putString("my_google_id", my_google_id);
                            bundle4.putString("my_supervise_id", my_mon_id);
                            intent4.putExtras(bundle4);
                            startActivity(intent4);
                            break;
                        }

                        return false;
                    }
                });
    }

    listView = (ListView) findViewById(R.id.listview);
    editText = (EditText) findViewById(R.id.textsearch);

    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (!s.toString().equals("")) {
                //reset listview

                //                    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
                //                    data_list = new ArrayList<>();
                //                    load_data_from_server(0);
                //
                //                    gridLayoutManager = new GridLayoutManager(getBaseContext(), 2);
                //                    recyclerView.setLayoutManager(gridLayoutManager);
                //
                //                    adapter = new CustomAdapter2(getBaseContext(), data_list);
                //                    recyclerView.setAdapter(adapter);
                //
                //                    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                //                        @Override
                //                        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                //
                //                            if (gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size() - 1) {
                //                                load_data_from_server(data_list.get(data_list.size() - 1).getId());
                //                            }
                //
                //                        }
                //                    });
                recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
                data_list2 = new ArrayList<>();
                Log.d("searchtest", "3");
                load_data_from_server_search(s.toString());

                Log.d("searchtest", "1");
                gridLayoutManager = new GridLayoutManager(getBaseContext(), 2);
                recyclerView.setLayoutManager(gridLayoutManager);
                Log.d("searchtest", "2");
                adapter = new CustomAdapter2(getBaseContext(), data_list2, m_calid);
                recyclerView.setAdapter(adapter);
            } else {
                recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

                gridLayoutManager = new GridLayoutManager(getBaseContext(), 2);
                recyclerView.setLayoutManager(gridLayoutManager);

                adapter = new CustomAdapter2(getBaseContext(), data_list, m_calid);
                recyclerView.setAdapter(adapter);

            }

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    data_list = new ArrayList<>();
    load_data_from_server(0);

    gridLayoutManager = new GridLayoutManager(this, 2);
    recyclerView.setLayoutManager(gridLayoutManager);

    adapter = new CustomAdapter2(this, data_list, m_calid);
    recyclerView.setAdapter(adapter);

    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

            if (gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size() - 1) {
                load_data_from_server(data_list.get(data_list.size() - 1).getId());
            }

        }
    });

}

From source file:android.support.design.widget.BottomNavigationView.java

/**
 * Set the selected menu item ID. This behaves the same as tapping on an item.
 *
 * @param itemId The menu item ID. If no item has this ID, the current selection is unchanged.
 *
 * @see #getSelectedItemId()//w w w.  ja  v  a  2s .  c  o  m
 */
public void setSelectedItemId(@IdRes int itemId) {
    MenuItem item = mMenu.findItem(itemId);
    if (item != null) {
        if (!mMenu.performItemAction(item, mPresenter, 0)) {
            item.setChecked(true);
        }
    }
}

From source file:com.duy.pascal.ui.file.FileExplorerAction.java

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.select_all) {
        if (!item.isChecked()) {
            mView.setSelectAll(true);//from w w w  .  j av  a 2 s  . co m
            item.setChecked(true);
            item.setTitle(R.string.cancel_select_all);
        } else {
            mView.setSelectAll(false);
        }
    } else if (id == R.id.copy && !mCheckedList.isEmpty()) {
        mFileClipboard.setData(true, mCheckedList);
        destroyActionMode();
    } else if (id == R.id.cut && !mCheckedList.isEmpty()) {
        mFileClipboard.setData(false, mCheckedList);
        destroyActionMode();
    } else if (id == R.id.paste) {
        destroyActionMode();
        mFileClipboard.paste(mContext, mExplorerContext.getCurrentDirectory(),
                new OnClipboardPasteFinishListener() {
                    @Override
                    public void onFinish(int count, String error) {
                        mFileClipboard.showPasteResult(mContext, count, error);
                    }
                });
    } else if (id == R.id.rename) {
        doRenameAction();
    } else if (id == R.id.share) {
        shareFile();
    } else if (id == R.id.delete) {
        doDeleteAction();
    } else {
        return false;
    }
    return true;
}

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

@Override
public void onPrepareOptionsMenu(Menu menu) {
    MenuItem showOnlyUsed = menu.findItem(R.id.menu_show_used);
    if (showOnlyUsed != null) {
        showOnlyUsed.setChecked(mShowOnlyUsedCurrencies);
    }//from   ww  w.  j  a v  a 2  s . co m
}

From source file:de.amuttsch.ioweu.app.ui.DebtListsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Pass the event to ActionBarDrawerToggle, if it returns
    // true, then it has handled the app icon touch event
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }//  w ww  . ja  va2 s.  co m

    Callback currentFragment = getCurrentFragment();

    switch (item.getItemId()) {
    case R.id.action_show_history:
        item.setChecked(!item.isChecked());
        mShowHistory = item.isChecked();
        currentFragment.showHistory(mShowHistory);
        break;
    case R.id.action_make_all_even:
        ((DebtListFragment) currentFragment).makeAllDebtsEven();
        break;
    case R.id.action_delete_all:
        ((DebtListFragment) currentFragment).deleteAllDebts();
        break;
    default:
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:fr.simon.marquis.preferencesmanager.ui.PreferencesFragment.java

@SuppressWarnings("ConstantConditions")
@Override//from www . jav  a 2s .co  m
public void onPrepareOptionsMenu(Menu menu) {
    menu.findItem(R.id.action_add).setEnabled(preferenceFile != null && preferenceFile.isValidPreferenceFile());
    menu.findItem(R.id.action_add)
            .setIcon(preferenceFile != null && preferenceFile.isValidPreferenceFile() ? R.drawable.ic_action_add
                    : R.drawable.ic_action_add_disabled);
    MenuItem sortAlpha = menu.findItem(R.id.action_sort_alpha);
    MenuItem sortType = menu.findItem(R.id.action_sort_type);
    sortAlpha.setChecked(false);
    sortType.setChecked(false);
    if (PreferencesActivity.preferenceSortType == PreferenceSortType.ALPHANUMERIC) {
        sortAlpha.setChecked(true);
    } else if (PreferencesActivity.preferenceSortType == PreferenceSortType.TYPE_AND_ALPHANUMERIC) {
        sortType.setChecked(true);
    }
    menu.findItem(R.id.action_restore_file).setVisible(mListener != null && mListener.canRestoreFile(mFile));
    super.onPrepareOptionsMenu(menu);
}

From source file:de.uni.stuttgart.informatik.ToureNPlaner.UI.Activities.MapScreen.MapScreen.java

private void setupGpsMenu(MenuItem item) {
    item.setChecked(gpsListener.isFollowing());
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override/* w  w  w .j a v  a2 s  . c  om*/
        public boolean onMenuItemClick(MenuItem item) {
            item.setChecked(!item.isChecked());
            gpsListener.setFollowing(item.isChecked());
            MapScreen.this.invalidateOptionsMenu();
            return true;
        }
    });
}