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.javierc.albuquerquenow.TransitMap.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    if (item.getItemId() == R.id.offline_routes) {

        if (item.isChecked()) {
            item.setChecked(false);
            useOfflineRoutes = false;//  w  w w  .j a v  a2  s  .c o m
        } else {
            item.setChecked(true);
            useOfflineRoutes = true;
        }

    } else if (item.getItemId() == R.id.action_legalnotices) {
        String LicenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext());
        AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(TransitMap.this);
        LicenseDialog.setTitle("Legal Notices");
        LicenseDialog.setMessage(LicenseInfo);
        LicenseDialog.show();

    } else if (item.getItemId() == R.id.bus_refresh) {
        //first delete all the current markers
        refreshMarkers();
        //plot new markers
        plotBus(actionBar.getSelectedNavigationIndex());

    } else if (item.getItemId() == R.id.bus_stops) {
        new PlotStopsTask(this).execute();
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.commonsware.android.preso.decktastic.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.present:
        boolean original = item.isChecked();

        item.setChecked(!original);

        if (original) {
            helper.disable();//from  w  w  w  . j av  a 2s  .  c o m
        } else {
            helper.enable();
        }

        break;

    case R.id.first:
        pager.setCurrentItem(0);
        break;

    case R.id.last:
        pager.setCurrentItem(adapter.getCount() - 1);
        break;
    }

    return (super.onOptionsItemSelected(item));
}

From source file:com.morlunk.mumbleclient.channel.ChannelListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    MenuItem muteItem = menu.findItem(R.id.menu_mute_button);
    MenuItem deafenItem = menu.findItem(R.id.menu_deafen_button);

    if (getService() != null && getService().isSynchronized()) {
        // Color the action bar icons to the primary text color of the theme, TODO move this elsewhere
        int foregroundColor = getActivity().getTheme()
                .obtainStyledAttributes(new int[] { android.R.attr.textColorPrimaryInverse }).getColor(0, -1);

        IUser self = getService().getSessionUser();
        muteItem.setIcon(/*  www  .j  av a 2  s .  c  o  m*/
                self.isSelfMuted() ? R.drawable.ic_action_microphone_muted : R.drawable.ic_action_microphone);
        deafenItem
                .setIcon(self.isSelfDeafened() ? R.drawable.ic_action_audio_muted : R.drawable.ic_action_audio);
        muteItem.getIcon().mutate().setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY);
        deafenItem.getIcon().mutate().setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY);

        MenuItem bluetoothItem = menu.findItem(R.id.menu_bluetooth);
        bluetoothItem.setChecked(getService().usingBluetoothSco());
    }
}

From source file:com.epishie.tabs.feature.subreddits.SubredditsActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    MenuItem sidebar = menu.findItem(R.id.sidebar);
    MenuItem sortGroup = menu.findItem(R.id.sort);
    MenuItem refresh = menu.findItem(R.id.refresh);
    SubredditViewModel subreddit = mAdapter.getSubreddit(mPages.getCurrentItem());
    if (subreddit != null) {
        sortGroup.setVisible(true);// ww  w  .  j  a  v  a 2 s .  c om
        sortGroup.setVisible(true);
        MenuItem sortItem = menu.findItem(SORT_OPTIONS.get(mAdapter.getSort().ordinal()).first);
        sortItem.setChecked(true);
        refresh.setVisible(true);
    } else {
        sidebar.setVisible(false);
        sortGroup.setVisible(false);
        refresh.setVisible(false);
    }

    return true;
}

From source file:com.octade.droid.ilesansfil.IleSansFil.java

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_LOCATION:
        if (item.isChecked() == false) {
            item.setChecked(true);
            item.setTitle(getResources().getString(R.string.menuGpsOn));
            mainApp.getMapView().setLocationDetection(true);

        } else {//from ww w.  j  a  va2  s  .  co m
            item.setChecked(false);
            item.setTitle(getResources().getString(R.string.menuGpsOff));
            mainApp.getMapView().setLocationDetection(false);
        }
        return true;
    case MENU_SETTINGS:

        return true;
    case MENU_ABOUT:
        about();
        return true;
    case MENU_TOGGLE_PIN:
        if (mainApp.getMapView().togglePins() == true) {
            item.setChecked(true);
            item.setTitle(getResources().getString(R.string.menuPinOn));
        } else {
            item.setChecked(false);
            item.setTitle(getResources().getString(R.string.menuPinOff));
        }

        return true;
    }
    return false;
}

From source file:id.zelory.tanipedia.activity.CuacaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cuaca);
    toolbar = (Toolbar) findViewById(R.id.anim_toolbar);
    setSupportActionBar(toolbar);// w  ww. j ava 2s  .  c  o  m
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);

    animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);

    drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer);
    setUpNavDrawer();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    TextView nama = (TextView) navigationView.findViewById(R.id.nama);
    nama.setText(PrefUtils.ambilString(this, "nama"));
    TextView email = (TextView) navigationView.findViewById(R.id.email);
    email.setText(PrefUtils.ambilString(this, "email"));
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            Intent intent;
            switch (menuItem.getItemId()) {
            case R.id.cuaca:
                return true;
            case R.id.berita:
                intent = new Intent(CuacaActivity.this, BeritaActivity.class);
                break;
            case R.id.tanya:
                intent = new Intent(CuacaActivity.this, TanyaActivity.class);
                break;
            case R.id.harga:
                intent = new Intent(CuacaActivity.this, KomoditasActivity.class);
                break;
            case R.id.logout:
                PrefUtils.simpanString(CuacaActivity.this, "nama", null);
                intent = new Intent(CuacaActivity.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                return true;
            case R.id.tentang:
                intent = new Intent(CuacaActivity.this, TentangActivity.class);
                startActivity(intent);
                return true;
            default:
                return true;
            }
            startActivity(intent);
            finish();
            return true;
        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.scrollableview);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);

    fabButton = (FabButton) findViewById(R.id.determinate);
    fabButton.showProgress(true);
    fabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fabButton.showProgress(true);
            new DownloadData().execute();
        }
    });

    cuacaText = (TextView) findViewById(R.id.cuaca);
    suhu = (TextView) findViewById(R.id.suhu);
    minmax = (TextView) findViewById(R.id.minmax);
    iconCuaca = (ImageView) findViewById(R.id.icon_cuaca);
    kegiatan = (TextView) findViewById(R.id.kegiatan);
    background = (LinearLayout) findViewById(R.id.background);

    cuacaText.setVisibility(View.GONE);
    suhu.setVisibility(View.GONE);
    minmax.setVisibility(View.GONE);
    iconCuaca.setVisibility(View.GONE);
    kegiatan.setVisibility(View.GONE);

    if (checkPlayServices()) {
        buildGoogleApiClient();
    }

}

From source file:com.jecelyin.android.file_explorer.FileExplorerAction.java

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.select_all) {
        if (!item.isChecked()) {
            view.setSelectAll(true);//w  w  w.j  av a 2s. c o  m
            item.setChecked(true);
            item.setTitle(R.string.cancel_select_all);
        } else {
            view.setSelectAll(false);
        }
    } else if (id == R.id.copy && !checkedList.isEmpty()) {
        fileClipboard.setData(true, checkedList);
        destroyActionMode();
    } else if (id == R.id.cut && !checkedList.isEmpty()) {
        fileClipboard.setData(false, checkedList);
        destroyActionMode();
    } else if (id == R.id.paste) {
        destroyActionMode();
        fileClipboard.paste(explorerContext.getCurrentDirectory());
    } 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.commonsware.android.diceware.PassphraseFragment.java

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

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        menu.findItem(R.id.open).setEnabled(true);
    }/*w ww.j a  v  a 2  s .  c o  m*/

    MenuItem checkable = menu.findItem(WORD_COUNT_MENU_IDS[wordCount - 4]);

    if (checkable != null) {
        checkable.setChecked(true);
    }

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:android.support.design.internal.BottomNavigationMenuView.java

public BottomNavigationMenuView(Context context, AttributeSet attrs) {
    super(context, attrs);
    final Resources res = getResources();
    mInactiveItemMaxWidth = res.getDimensionPixelSize(R.dimen.design_bottom_navigation_item_max_width);
    mInactiveItemMinWidth = res.getDimensionPixelSize(R.dimen.design_bottom_navigation_item_min_width);
    mActiveItemMaxWidth = res.getDimensionPixelSize(R.dimen.design_bottom_navigation_active_item_max_width);
    mItemHeight = res.getDimensionPixelSize(R.dimen.design_bottom_navigation_height);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        mAnimationHelper = new BottomNavigationAnimationHelperIcs();
    } else {/*  ww  w  .j a  v a  2  s  . c o  m*/
        mAnimationHelper = new BottomNavigationAnimationHelperBase();
    }

    mOnClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            final BottomNavigationItemView itemView = (BottomNavigationItemView) v;
            MenuItem item = itemView.getItemData();
            if (!mMenu.performItemAction(item, mPresenter, 0)) {
                item.setChecked(true);
            }
        }
    };
    mTempChildWidths = new int[BottomNavigationMenu.MAX_ITEM_COUNT];
}

From source file:com.pepperonas.truthordare.MainActivity.java

private void initNavView() {
    mNavView = (NavigationView) findViewById(R.id.navigation_view);
    mNavView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//  www .j a va  2s.  co  m
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(menuItem.isChecked());
            mDrawerLayout.closeDrawers();

            return selectNavViewItem(menuItem);
        }
    });

    // selecting the first item
    selectNavViewItem(getNavigationView().getMenu().getItem(0).getSubMenu().getItem(0));
}