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.google.android.apps.muzei.gallery.GallerySettingsActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.gallery_activity, menu);

    int rotateIntervalMin = GalleryArtSource.getSharedPreferences(this)
            .getInt(GalleryArtSource.PREF_ROTATE_INTERVAL_MIN, GalleryArtSource.DEFAULT_ROTATE_INTERVAL_MIN);
    int menuId = sRotateMenuIdsByMin.get(rotateIntervalMin);
    if (menuId != 0) {
        MenuItem item = menu.findItem(menuId);
        if (item != null) {
            item.setChecked(true);
        }//from w w w  .j ava  2 s .co m
    }
    return true;
}

From source file:com.abhijitvalluri.android.fitnotifications.AppChoicesActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        onBackPressed();/*  w ww.j  a  v a 2  s  .  co  m*/
        return true;
    case R.id.menu_filter_enabled:
        mShowOnlyEnabledApps = !mShowOnlyEnabledApps; // toggles the state of the filter
        mPreferences.edit().putBoolean(getString(R.string.show_enabled_apps_key), mShowOnlyEnabledApps).apply();
        item.setChecked(mShowOnlyEnabledApps);
        recyclerViewShowEnabled();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.money.manager.ex.reports.IncomeVsExpensesListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        getActivity().finish();//  w w  w . java  2 s . co  m
    } else if (item.getItemId() == R.id.menu_sort_asceding || item.getItemId() == R.id.menu_sort_desceding) {
        mSort = item.getItemId() == R.id.menu_sort_asceding ? SORT_ASCENDING : SORT_DESCENDING;
        startLoader();
        item.setChecked(true);
    } else if (item.getItemId() == R.id.menu_chart) {
        showChart();
    } else if (item.getItemId() == R.id.menu_period) {
        showDialogYears();
    }

    return super.onOptionsItemSelected(item);
}

From source file:de.tap.easy_xkcd.Activities.MainActivity.java

private void showDrawerErrorToast(int errorId) {
    Toast.makeText(this, errorId, Toast.LENGTH_SHORT).show();
    MenuItem m = mNavView.getMenu().findItem(mCurrentFragment);
    m.setChecked(true);
    mDrawer.closeDrawers();/*www  .  j  av a 2s  .  c  o m*/
}

From source file:com.github.michalbednarski.intentslab.editor.IntentEditorActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    {//  w w  w.j av a2s . c  om
        MenuItem runIntentOption = menu.findItem(R.id.menu_run_intent);
        if (mComponentType == IntentEditorConstants.RESULT) {
            if (getIntent().getBooleanExtra(EXTRA_FORWARD_ABLE_RESULT, false)) {
                runIntentOption.setVisible(true).setTitle("setResult(); finish()");
            } else {
                runIntentOption.setVisible(false);
            }
        } else {
            runIntentOption.setVisible(true).setTitle(
                    IntentGeneralFragment.getMethodNamesArray(getResources(), mComponentType)[mMethodId]);
        }
    }
    menu.findItem(R.id.set_editor_result).setVisible(mGenericEditorMode);
    menu.findItem(R.id.detach_intent_filter).setVisible(mAttachedIntentFilters != null);
    menu.findItem(R.id.component_info).setVisible(mEditedIntent.getComponent() != null);
    menu.findItem(R.id.attach_intent_filter).setVisible(mEditedIntent.getComponent() != null);

    // Intent tracking options
    {
        boolean intentTrackerAvailable = isIntentTrackerAvailable();
        MenuItem trackIntentOption = menu.findItem(R.id.track_intent);
        trackIntentOption.setVisible(intentTrackerAvailable);
        trackIntentOption.setEnabled(intentTrackerAvailable);
        trackIntentOption.setChecked(getIntentTracker() != null);
    }

    // "Disable interception" option
    menu.findItem(R.id.disable_interception).setVisible(isInterceptedIntent()).setEnabled(
            isInterceptedIntent() && getPackageManager().getComponentEnabledSetting(new ComponentName(this,
                    IntentEditorInterceptedActivity.class)) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED);
    return true;
}

From source file:com.syncedsynapse.kore2.ui.TVShowListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.tvshow_list, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);
    searchView.setQueryHint(getString(R.string.action_search_tvshows));

    // Setup filters
    MenuItem hideWatched = menu.findItem(R.id.action_hide_watched),
            ignoreArticles = menu.findItem(R.id.action_ignore_prefixes),
            sortByName = menu.findItem(R.id.action_sort_by_name),
            sortByDateAdded = menu.findItem(R.id.action_sort_by_date_added);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    hideWatched.setChecked(preferences.getBoolean(Settings.KEY_PREF_TVSHOWS_FILTER_HIDE_WATCHED,
            Settings.DEFAULT_PREF_TVSHOWS_FILTER_HIDE_WATCHED));
    ignoreArticles.setChecked(preferences.getBoolean(Settings.KEY_PREF_TVSHOWS_IGNORE_PREFIXES,
            Settings.DEFAULT_PREF_TVSHOWS_IGNORE_PREFIXES));

    int sortOrder = preferences.getInt(Settings.KEY_PREF_TVSHOWS_SORT_ORDER,
            Settings.DEFAULT_PREF_TVSHOWS_SORT_ORDER);
    switch (sortOrder) {
    case Settings.SORT_BY_DATE_ADDED:
        sortByDateAdded.setChecked(true);
        break;//w  w  w. java2s.c  o  m
    default:
        sortByName.setChecked(true);
        break;
    }

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.secupwn.aimsicd.ui.activities.MainActivity.java

/**
 * Invoked only once during app's lifetime. For successive calls see
 * {@link #onPrepareOptionsMenu(Menu)}. Both used primarily to determine checkboxes for tracking
 * and detection./*from  www  .ja v  a  2  s  .c o  m*/
 *
 * Because the service may not available on app boot, we default to false until the service
 * boots. Once that occurs, the checkboxes are driven by the service's status.
 *
 * @param menu
 * @return
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);

    MenuItem toggleAttackDetectionMenuItem = menu.findItem(R.id.toggle_attack_detection);
    MenuItem toggleCellTrackingMenuItem = menu.findItem(R.id.toggle_cell_tracking);

    // The service may not exist on first app boot. Choose sane defaults
    if (mAimsicdService == null) {
        toggleAttackDetectionMenuItem.setChecked(false);
        toggleCellTrackingMenuItem.setChecked(false);
    } else {
        toggleAttackDetectionMenuItem.setChecked(mAimsicdService.isMonitoringCell());
        toggleCellTrackingMenuItem.setChecked(mAimsicdService.isTrackingCell());
    }
    return true;
}

From source file:com.syncedsynapse.kore2.ui.MovieListFragment.java

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

    // Setup search view
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);
    searchView.setQueryHint(getString(R.string.action_search_movies));

    // Setup filters
    MenuItem hideWatched = menu.findItem(R.id.action_hide_watched),
            ignoreArticles = menu.findItem(R.id.action_ignore_prefixes),
            sortByName = menu.findItem(R.id.action_sort_by_name),
            sortByDateAdded = menu.findItem(R.id.action_sort_by_date_added);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    hideWatched.setChecked(preferences.getBoolean(Settings.KEY_PREF_MOVIES_FILTER_HIDE_WATCHED,
            Settings.DEFAULT_PREF_MOVIES_FILTER_HIDE_WATCHED));
    ignoreArticles.setChecked(preferences.getBoolean(Settings.KEY_PREF_MOVIES_IGNORE_PREFIXES,
            Settings.DEFAULT_PREF_MOVIES_IGNORE_PREFIXES));

    int sortOrder = preferences.getInt(Settings.KEY_PREF_MOVIES_SORT_ORDER,
            Settings.DEFAULT_PREF_MOVIES_SORT_ORDER);
    switch (sortOrder) {
    case Settings.SORT_BY_DATE_ADDED:
        sortByDateAdded.setChecked(true);
        break;//from   w w  w  . j a v  a  2 s .  c om
    default:
        sortByName.setChecked(true);
        break;
    }

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:edu.Groove9.TunesMaster.playlist.PlaylistActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*from  www  .  j  av  a2s.  c  o m*/
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
            case R.id.list_navigation_menu_item:
                // Do nothing, we're already on that screen
                break;
            case R.id.statistics_navigation_menu_item:
                Intent statisticsIntent = new Intent(PlaylistActivity.this, StatisticsActivity.class);
                statisticsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(statisticsIntent);
                break;
            default:
                break;
            }
            // Close the navigation drawer when an item is selected.
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}

From source file:com.duy.pascal.ui.editor.BaseEditorActivity.java

@Override
public boolean onMenuItemClick(MenuItem item) {
    DLog.d(TAG, "onMenuItemClick() called with: item = [" + item + "]");

    Pref pref = Pref.getInstance(this);
    int id = item.getItemId();
    if (id == R.id.show_hidden_files_menu) {
        item.setChecked(!item.isChecked());
        pref.setShowHiddenFiles(item.isChecked());
    } else if (id == R.id.sort_by_name_menu) {
        item.setChecked(true);//from  w  w w .  j  a  v  a  2  s.  c o m
        pref.setFileSortType(FileListSorter.SORT_NAME);
    } else if (id == R.id.sort_by_datetime_menu) {
        item.setChecked(true);
        pref.setFileSortType(FileListSorter.SORT_DATE);
    } else if (id == R.id.sort_by_size_menu) {
        item.setChecked(true);
        pref.setFileSortType(FileListSorter.SORT_SIZE);
    } else if (id == R.id.sort_by_type_menu) {
        item.setChecked(true);
        pref.setFileSortType(FileListSorter.SORT_TYPE);
    }
    return mFileExplorer.onOptionsItemSelected(item);
}