Example usage for android.view MenuItem isChecked

List of usage examples for android.view MenuItem isChecked

Introduction

In this page you can find the example usage for android.view MenuItem isChecked.

Prototype

public boolean isChecked();

Source Link

Document

Return whether the item is currently displaying a check mark.

Usage

From source file:de.tap.easy_xkcd.fragments.overview.OverviewRecyclerBaseFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_favorite:
        if (prefHelper.overviewFav()) {
            item.setIcon(R.drawable.ic_favorite_outline);
            item.setTitle(R.string.nv_favorites);
        } else {/*w  ww.jav  a2 s.co m*/
            item.setIcon(R.drawable.ic_action_favorite);
            item.setTitle(R.string.action_overview);
        }
        prefHelper.setOverviewFav(!prefHelper.overviewFav());
        getActivity().invalidateOptionsMenu();
        setupAdapter();
        break;
    case R.id.action_boomark:
        super.goToComic(bookmark - 1);
        break;
    case R.id.action_unread:
        databaseManager.setComicsUnread();
        setupAdapter();
        break;
    case R.id.action_hide_read:
        item.setChecked(!item.isChecked());
        prefHelper.setHideRead(item.isChecked());
        setupAdapter();
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:website.openeng.anki.Statistics.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // The action bar home/up action should open or close the drawer.
    // ActionBarDrawerToggle will take care of this.
    if (getDrawerToggle().onOptionsItemSelected(item)) {
        return true;
    }/*from  www  .  j a va2 s  .c  o  m*/
    int itemId = item.getItemId();
    switch (itemId) {
    case R.id.item_time_month:
        if (item.isChecked())
            item.setChecked(false);
        else
            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.afollestad.polar.ui.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.changelog) {
        ChangelogDialog.show(this);
        return true;
    } else if (item.getItemId() == R.id.darkTheme) {
        darkTheme(!darkTheme());/*www .j a va2  s .  c om*/
        mToolbar.postDelayed(new Runnable() {
            @Override
            public void run() {
                recreate();
            }
        }, 500);
        return true;
    } else if (item.getItemId() == R.id.navDrawerMode) {
        item.setChecked(!item.isChecked());
        Config.get().navDrawerModeEnabled(item.isChecked());
        recreate();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:de.tap.easy_xkcd.fragments.overview.OverviewListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_boomark:
        super.goToComic(bookmark - 1);
        break;/*  w  ww  . j  a v  a2 s. c  om*/
    case R.id.action_unread:
        databaseManager.setComicsUnread();
        setupAdapter();
        break;
    case R.id.action_favorite:
        if (prefHelper.overviewFav()) {
            item.setIcon(R.drawable.ic_favorite_outline);
            item.setTitle(R.string.nv_favorites);
        } else {
            item.setIcon(R.drawable.ic_action_favorite);
            item.setTitle(R.string.action_overview);
        }
        prefHelper.setOverviewFav(!prefHelper.overviewFav());
        getActivity().invalidateOptionsMenu();
        setupAdapter();
        break;
    case R.id.action_hide_read:
        item.setChecked(!item.isChecked());
        prefHelper.setHideRead(item.isChecked());
        setupAdapter();
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean retval;
    ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity();

    switch (item.getItemId()) {
    case android.R.id.home:
        contactsPreferenceActivity.onBackPressed();
        retval = true;/*from  ww  w. j a va  2  s. c om*/
        break;
    case R.id.action_select_all:
        item.setChecked(!item.isChecked());
        setSelectAllMenuItem(item, item.isChecked());
        contactListAdapter.selectAllFiles(item.isChecked());
        retval = true;
        break;
    default:
        retval = super.onOptionsItemSelected(item);
        break;
    }
    return retval;
}

From source file:com.master.metehan.filtereagle.ActivityLog.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    final File pcap_file = new File(getCacheDir(), "netguard.pcap");

    switch (item.getItemId()) {
    case android.R.id.home:
        Log.i(TAG, "Up");
        NavUtils.navigateUpFromSameTask(this);
        return true;

    case R.id.menu_protocol_udp:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("proto_udp", item.isChecked()).apply();
        updateAdapter();//from  w w w .  j ava2 s.  co m
        return true;

    case R.id.menu_protocol_tcp:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("proto_tcp", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_protocol_other:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("proto_other", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_traffic_allowed:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("traffic_allowed", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_traffic_blocked:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("traffic_blocked", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_log_live:
        item.setChecked(!item.isChecked());
        live = item.isChecked();
        if (live) {
            DatabaseHelper.getInstance(this).addLogChangedListener(listener);
            updateAdapter();
        } else
            DatabaseHelper.getInstance(this).removeLogChangedListener(listener);
        return true;

    case R.id.menu_refresh:
        updateAdapter();
        return true;

    case R.id.menu_log_resolve:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("resolve", item.isChecked()).apply();
        adapter.setResolve(item.isChecked());
        adapter.notifyDataSetChanged();
        return true;

    case R.id.menu_log_organization:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("organization", item.isChecked()).apply();
        adapter.setOrganization(item.isChecked());
        adapter.notifyDataSetChanged();
        return true;

    case R.id.menu_pcap_enabled:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("pcap", item.isChecked()).apply();
        ServiceSinkhole.setPcap(item.isChecked(), ActivityLog.this);
        return true;

    case R.id.menu_pcap_export:
        startActivityForResult(getIntentPCAPDocument(), REQUEST_PCAP);
        return true;

    case R.id.menu_log_clear:
        new AsyncTask<Object, Object, Object>() {
            @Override
            protected Object doInBackground(Object... objects) {
                DatabaseHelper.getInstance(ActivityLog.this).clearLog();
                if (prefs.getBoolean("pcap", false)) {
                    ServiceSinkhole.setPcap(false, ActivityLog.this);
                    if (pcap_file.exists() && !pcap_file.delete())
                        Log.w(TAG, "Delete PCAP failed");
                    ServiceSinkhole.setPcap(true, ActivityLog.this);
                } else {
                    if (pcap_file.exists() && !pcap_file.delete())
                        Log.w(TAG, "Delete PCAP failed");
                }
                return null;
            }

            @Override
            protected void onPostExecute(Object result) {
                if (running)
                    updateAdapter();
            }
        }.execute();
        return true;

    case R.id.menu_log_support:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md#FAQ27"));
        if (getPackageManager().resolveActivity(intent, 0) != null)
            startActivity(intent);
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:eu.faircode.adblocker.ActivityLog.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    final File pcap_file = new File(getCacheDir(), "adblocker.pcap");

    switch (item.getItemId()) {
    case android.R.id.home:
        Log.i(TAG, "Up");
        NavUtils.navigateUpFromSameTask(this);
        return true;

    case R.id.menu_protocol_udp:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("proto_udp", item.isChecked()).apply();
        updateAdapter();/*from   w  w  w . j ava  2s. c om*/
        return true;

    case R.id.menu_protocol_tcp:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("proto_tcp", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_protocol_other:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("proto_other", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_traffic_allowed:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("traffic_allowed", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_traffic_blocked:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("traffic_blocked", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_log_live:
        item.setChecked(!item.isChecked());
        live = item.isChecked();
        if (live) {
            DatabaseHelper.getInstance(this).addLogChangedListener(listener);
            updateAdapter();
        } else
            DatabaseHelper.getInstance(this).removeLogChangedListener(listener);
        return true;

    case R.id.menu_refresh:
        updateAdapter();
        return true;

    case R.id.menu_log_resolve:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("resolve", item.isChecked()).apply();
        adapter.setResolve(item.isChecked());
        adapter.notifyDataSetChanged();
        return true;

    case R.id.menu_log_organization:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("organization", item.isChecked()).apply();
        adapter.setOrganization(item.isChecked());
        adapter.notifyDataSetChanged();
        return true;

    case R.id.menu_pcap_enabled:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("pcap", item.isChecked()).apply();
        ServiceSinkhole.setPcap(item.isChecked(), ActivityLog.this);
        return true;

    case R.id.menu_pcap_export:
        startActivityForResult(getIntentPCAPDocument(), REQUEST_PCAP);
        return true;

    case R.id.menu_log_clear:
        new AsyncTask<Object, Object, Object>() {
            @Override
            protected Object doInBackground(Object... objects) {
                DatabaseHelper.getInstance(ActivityLog.this).clearLog();
                if (prefs.getBoolean("pcap", false)) {
                    ServiceSinkhole.setPcap(false, ActivityLog.this);
                    if (pcap_file.exists() && !pcap_file.delete())
                        Log.w(TAG, "Delete PCAP failed");
                    ServiceSinkhole.setPcap(true, ActivityLog.this);
                } else {
                    if (pcap_file.exists() && !pcap_file.delete())
                        Log.w(TAG, "Delete PCAP failed");
                }
                return null;
            }

            @Override
            protected void onPostExecute(Object result) {
                if (running)
                    updateAdapter();
            }
        }.execute();
        return true;

    case R.id.menu_log_support:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md#FAQ27"));
        if (getPackageManager().resolveActivity(intent, 0) != null)
            startActivity(intent);
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:android_network.hetnet.vpn_service.ActivityLog.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    final File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap");

    switch (item.getItemId()) {
    case android.R.id.home:
        Log.i(TAG, "Up");
        NavUtils.navigateUpFromSameTask(this);
        return true;

    case R.id.menu_protocol_udp:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("proto_udp", item.isChecked()).apply();
        updateAdapter();//  w ww. j  a v  a  2 s  . c om
        return true;

    case R.id.menu_protocol_tcp:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("proto_tcp", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_protocol_other:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("proto_other", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_traffic_allowed:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("traffic_allowed", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_traffic_blocked:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("traffic_blocked", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_log_live:
        item.setChecked(!item.isChecked());
        live = item.isChecked();
        if (live) {
            DatabaseHelper.getInstance(this).addLogChangedListener(listener);
            updateAdapter();
        } else
            DatabaseHelper.getInstance(this).removeLogChangedListener(listener);
        return true;

    case R.id.menu_refresh:
        updateAdapter();
        return true;

    case R.id.menu_log_resolve:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("resolve", item.isChecked()).apply();
        adapter.setResolve(item.isChecked());
        adapter.notifyDataSetChanged();
        return true;

    case R.id.menu_log_organization:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("organization", item.isChecked()).apply();
        adapter.setOrganization(item.isChecked());
        adapter.notifyDataSetChanged();
        return true;

    case R.id.menu_pcap_enabled:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("pcap", item.isChecked()).apply();
        ServiceSinkhole.setPcap(item.isChecked(), ActivityLog.this);
        return true;

    case R.id.menu_pcap_export:
        startActivityForResult(getIntentPCAPDocument(), REQUEST_PCAP);
        return true;

    case R.id.menu_log_clear:
        new AsyncTask<Object, Object, Object>() {
            @Override
            protected Object doInBackground(Object... objects) {
                DatabaseHelper.getInstance(ActivityLog.this).clearLog();
                if (prefs.getBoolean("pcap", false)) {
                    ServiceSinkhole.setPcap(false, ActivityLog.this);
                    if (pcap_file.exists() && !pcap_file.delete())
                        Log.w(TAG, "Delete PCAP failed");
                    ServiceSinkhole.setPcap(true, ActivityLog.this);
                } else {
                    if (pcap_file.exists() && !pcap_file.delete())
                        Log.w(TAG, "Delete PCAP failed");
                }
                return null;
            }

            @Override
            protected void onPostExecute(Object result) {
                if (running)
                    updateAdapter();
            }
        }.execute();
        return true;

    case R.id.menu_log_support:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md#FAQ27"));
        if (getPackageManager().resolveActivity(intent, 0) != null)
            startActivity(intent);
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:mroza.forms.ChooseProgramActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.sync_now:
        syncData();//from  w  w w  . j a  v  a 2  s .c o  m
        return true;
    case R.id.sync_date:
        showLastSyncDate();
        return true;
    case R.id.teaching_ended:
    case R.id.teaching_not_started:
    case R.id.teaching_saved:
    case R.id.general_ended:
    case R.id.general_not_started:
    case R.id.general_saved:
        if (item.isChecked()) {
            item.setChecked(false);
            selectedFilters.remove(item);
        } else {
            item.setChecked(true);
            selectedFilters.add(item);
            letterFilter = null;
        }
        filterPrograms();
        return true;
    case R.id.choose_letter_A:
    case R.id.choose_letter_B:
    case R.id.choose_letter_C:
    case R.id.choose_letter_D:
    case R.id.choose_letter_E:
    case R.id.choose_letter_F:
    case R.id.choose_letter_G:
    case R.id.choose_letter_H:
    case R.id.choose_letter_I:
    case R.id.choose_letter_J:
    case R.id.choose_letter_K:
    case R.id.choose_letter_L:
    case R.id.choose_letter_M:
    case R.id.choose_letter_N:
    case R.id.choose_letter_O:
    case R.id.choose_letter_P:
    case R.id.choose_letter_Q:
    case R.id.choose_letter_R:
    case R.id.choose_letter_S:
    case R.id.choose_letter_T:
    case R.id.choose_letter_U:
    case R.id.choose_letter_V:
    case R.id.choose_letter_W:
    case R.id.choose_letter_X:
    case R.id.choose_letter_Y:
    case R.id.choose_letter_Z:
        if (item.isChecked()) {
            item.setChecked(false);
            letterFilter = null;
        } else {
            item.setChecked(true);
            letterFilter = item;
        }
        filterPrograms();
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:eu.faircode.netguard.ActivityLog.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    final File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap");

    switch (item.getItemId()) {
    case android.R.id.home:
        Log.i(TAG, "Up");
        NavUtils.navigateUpFromSameTask(this);
        return true;

    case R.id.menu_protocol_udp:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("proto_udp", item.isChecked()).apply();
        updateAdapter();/*from w  ww. ja va 2  s .  c om*/
        return true;

    case R.id.menu_protocol_tcp:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("proto_tcp", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_protocol_other:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("proto_other", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_traffic_allowed:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("traffic_allowed", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_traffic_blocked:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("traffic_blocked", item.isChecked()).apply();
        updateAdapter();
        return true;

    case R.id.menu_log_live:
        item.setChecked(!item.isChecked());
        live = item.isChecked();
        if (live) {
            DatabaseHelper.getInstance(this).addLogChangedListener(listener);
            updateAdapter();
        } else
            DatabaseHelper.getInstance(this).removeLogChangedListener(listener);
        return true;

    case R.id.menu_refresh:
        updateAdapter();
        return true;

    case R.id.menu_log_resolve:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("resolve", item.isChecked()).apply();
        adapter.setResolve(item.isChecked());
        adapter.notifyDataSetChanged();
        return true;

    case R.id.menu_log_organization:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("organization", item.isChecked()).apply();
        adapter.setOrganization(item.isChecked());
        adapter.notifyDataSetChanged();
        return true;

    case R.id.menu_pcap_enabled:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("pcap", item.isChecked()).apply();
        ServiceSinkhole.setPcap(item.isChecked(), ActivityLog.this);
        return true;

    case R.id.menu_pcap_export:
        startActivityForResult(getIntentPCAPDocument(), REQUEST_PCAP);
        return true;

    case R.id.menu_log_clear:
        new AsyncTask<Object, Object, Object>() {
            @Override
            protected Object doInBackground(Object... objects) {
                DatabaseHelper.getInstance(ActivityLog.this).clearLog(-1);
                if (prefs.getBoolean("pcap", false)) {
                    ServiceSinkhole.setPcap(false, ActivityLog.this);
                    if (pcap_file.exists() && !pcap_file.delete())
                        Log.w(TAG, "Delete PCAP failed");
                    ServiceSinkhole.setPcap(true, ActivityLog.this);
                } else {
                    if (pcap_file.exists() && !pcap_file.delete())
                        Log.w(TAG, "Delete PCAP failed");
                }
                return null;
            }

            @Override
            protected void onPostExecute(Object result) {
                if (running)
                    updateAdapter();
            }
        }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        return true;

    case R.id.menu_log_support:
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md#FAQ27"));
        if (getPackageManager().resolveActivity(intent, 0) != null)
            startActivity(intent);
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}