Java Code Examples for android.view.MenuItem.setChecked()

The following are Jave code examples for showing how to use setChecked() of the android.view.MenuItem class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: AIMSICDL   File: MainActivity.java   View Source Code Vote up 6 votes
/**
 * Invoked only once during app's lifetime. For successive calls see
 * {@link #onPrepareOptionsMenu(Menu)}. Both used primarily to determine checkboxes for tracking
 * and detection.
 *
 * 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;
}
 
Example 2
Project: OpenHub   File: ViewerFragment.java   View Source Code Vote up 6 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if(item.getItemId() == R.id.action_wrap_lines){
        item.setChecked(!item.isChecked());
        wrap = item.isChecked();
        PrefUtils.set(PrefUtils.CODE_WRAP, wrap);
        if(ViewerActivity.ViewerType.RepoFile.equals(mPresenter.getViewerType())){
            loadCode(mPresenter.getDownloadSource(), mPresenter.getExtension());
        } else if(ViewerActivity.ViewerType.DiffFile.equals(mPresenter.getViewerType())){
            loadDiffFile(mPresenter.getCommitFile().getPatch());
        }
        return true;
    } else if(item.getItemId() == R.id.action_refresh){
        refresh();
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 3
Project: RetroMusicPlayer   File: ArtistsFragment.java   View Source Code Vote up 6 votes
private boolean handleSortOrderMenuItem(@NonNull MenuItem item) {
    String sortOrder = null;
    switch (item.getItemId()) {
        case R.id.action_sort_order_artist:
            sortOrder = ArtistSortOrder.ARTIST_A_Z;
            break;
        case R.id.action_sort_order_artist_desc:
            sortOrder = ArtistSortOrder.ARTIST_Z_A;
            break;
    }
    if (sortOrder != null) {
        item.setChecked(true);
        setSaveSortOrder(sortOrder);
    }
    return true;
}
 
Example 4
Project: Sprog-App   File: MainActivity.java   View Source Code Vote up 6 votes
@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

/*        if (id == R.id.action_force_refresh) {
            updatePoems(null);
            return true;
        } else */
        if (id == R.id.action_mark_read) {
            item.setChecked(!item.isChecked());
            presenter.optionMarkRead(item.isChecked());
        } else if (id == R.id.action_reset_read) {
            showConfirmClearReadDialog();
        } else if (id == R.id.action_notify_new) {
            item.setChecked(!item.isChecked());
            presenter.optionNotifyNew(item.isChecked());
            trackEvent("notificationOption", item.isChecked() ? "yes" : "no", null);
        } else if (id == R.id.action_long_press){
            item.setChecked(!item.isChecked());
            presenter.optionLongPress(item.isChecked());
        } else if (id == R.id.action_stats) {
            presenter.optionStats();
        }

        return super.onOptionsItemSelected(item);
    }
 
Example 5
Project: javaide   File: FileExplorerActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onOptionsItemSelected(MenuItem 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);
        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 super.onOptionsItemSelected(item);
}
 
Example 6
Project: robird-reborn   File: HomeActivity.java   View Source Code Vote up 5 votes
public void selectNavigation(MenuItem menuItem) {
    mSelectedAccountId = mAccounts.get(0).id();
    mSelectedNavigationPosition = menuItem.getOrder();
    setTitle(menuItem.getTitle());
    menuItem.setChecked(true);
    mDrawerLayout.closeDrawers();
}
 
Example 7
Project: buildAPKsSamples   File: ActivityAnimations.java   View Source Code Vote up 5 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_slow) {
        sAnimatorScale = item.isChecked() ? 1 : 5;
        item.setChecked(!item.isChecked());
    }
    return super.onOptionsItemSelected(item);
}
 
Example 8
Project: buildAPKsApps   File: AlarmClockActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
  case R.id.default_options:
    AlarmOptions options = new AlarmOptions();
    Bundle b = new Bundle();
    b.putLong(AlarmNotificationService.ALARM_ID, DbUtil.Settings.DEFAULTS_ID);
    options.setArguments(b);
    options.show(getFragmentManager(), "default_alarm_options");
    return true;

  case R.id.display_notification:
    boolean new_val = !item.isChecked();
    item.setChecked(new_val);
    PreferenceManager.getDefaultSharedPreferences(this)
      .edit()
      .putBoolean(AlarmNotificationService.DISPLAY_NOTIFICATION, new_val)
      .commit();
    AlarmNotificationService.refreshNotificationBar(this);
    return true;

  case R.id.delete_all:
    new DeleteAllConfirmation()
      .show(getFragmentManager(), "confirm_delete_all");

    return true;
  default:
    return super.onOptionsItemSelected(item);
  }
}
 
Example 9
Project: editor   File: Editor.java   View Source Code Vote up 5 votes
private void darkClicked(MenuItem item)
{
    theme = DARK;
    item.setChecked(true);

    if (Build.VERSION.SDK_INT != VERSION_M)
        recreate();
}
 
Example 10
Project: TechChat   File: ThreadsActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    switch (id){
        // TODO replace the duplicate code with function / classes
        case R.id.menu_sort_recent:
            if (! item.isChecked()) {
                // call the sort function
                item.setChecked(true);
            }
            break;
        case R.id.menu_sort_oldest:
            if (! item.isChecked()) {
                // call the sort function
                item.setChecked(true);
            }
            break;
        case R.id.menu_sort_trending:
            if (! item.isChecked()) {
                // call the sort function
                item.setChecked(true);
            }
            break;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 11
Project: RetroMusicPlayer   File: SongsFragment.java   View Source Code Vote up 5 votes
private boolean handleSortOrderMenuItem(@NonNull MenuItem item) {
    String sortOrder = null;
    switch (item.getItemId()) {
        case R.id.action_sort_order_album:
            sortOrder = SongSortOrder.SONG_ALBUM;
            break;
        case R.id.action_sort_order_title:
            sortOrder = SongSortOrder.SONG_A_Z;
            break;
        case R.id.action_sort_order_title_desc:
            sortOrder = SongSortOrder.SONG_Z_A;
            break;
        case R.id.action_sort_order_artist:
            sortOrder = SongSortOrder.SONG_ARTIST;
            break;
        case R.id.action_sort_order_year:
            sortOrder = SongSortOrder.SONG_YEAR;
            break;
        case R.id.action_sort_order_duration:
            sortOrder = SongSortOrder.SONG_DURATION;
            break;
        case R.id.action_sort_order_date:
            sortOrder = SongSortOrder.SONG_DATE;
            break;
    }
    if (sortOrder != null) {
        item.setChecked(true);
        setSaveSortOrder(sortOrder);
    }
    return true;
}
 
Example 12
Project: editor   File: Editor.java   View Source Code Vote up 5 votes
private void wrapClicked(MenuItem item)
{
    wrap = !wrap;
    item.setChecked(wrap);

    if (Build.VERSION.SDK_INT != VERSION_M)
        recreate();
}
 
Example 13
Project: crossword   File: Main.java   View Source Code Vote up 5 votes
private boolean onDarkClick(MenuItem item)
{
    dark = !dark;
    item.setChecked(dark);
    if (Build.VERSION.SDK_INT != VERSION_M)
        recreate();

    return true;
}
 
Example 14
Project: react-native-android-bottom-navigation   File: RNBottomNavigationManager.java   View Source Code Vote up 5 votes
@ReactProp(name = "activeTab", defaultInt = 0)
public void setActiveTab(RNBottomNavigation view, int activeTab) {
    Menu menu = view.getMenu();

    for (int i = 0; i < menu.size(); i++) {
        MenuItem menuItem = menu.getItem(i);
        if (i == activeTab) {
            menuItem.setChecked(true);
        } else {
            menuItem.setChecked(false);
        }
    }
}
 
Example 15
Project: mobile-app-dev-book   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public void onPageSelected(int position) {
    if (prevSelection != null)
        prevSelection.setChecked(false);
    MenuItem thisMenu = bottomTabs.getMenu().getItem(position);
    thisMenu.setChecked(true);
    prevSelection = thisMenu;
}
 
Example 16
Project: AIMSICDL   File: MainActivity.java   View Source Code Vote up 5 votes
/**
 * Display latest cell tracking & attack detection truth when opening menu over & over
 *
 * @param menu
 * @return
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // Bail early if there's no service to get the facts from
    if (mAimsicdService == null) {
        return super.onPrepareOptionsMenu(menu);
    }
    MenuItem toggleAttackDetectionMenuItem = menu.findItem(R.id.toggle_attack_detection);
    MenuItem toggleCellTrackingMenuItem = menu.findItem(R.id.toggle_cell_tracking);
    toggleAttackDetectionMenuItem.setChecked(mAimsicdService.isMonitoringCell());
    toggleCellTrackingMenuItem.setChecked(mAimsicdService.isTrackingCell());
    return super.onPrepareOptionsMenu(menu);
}
 
Example 17
Project: JsoupSample   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
public void selectMenuFirst() {
    MenuItem item = navigationView.getMenu().findItem(R.id.dbmz);
    item.setChecked(true);
    toolbar.setTitle(item.getTitle());
}
 
Example 18
Project: RetroMusicPlayer   File: ArtistDetailActivity.java   View Source Code Vote up 4 votes
private boolean handleSortOrderMenuItem(@NonNull MenuItem item) {
    String sortOrder = null;
    final ArrayList<Song> songs = getArtist().getSongs();
    switch (item.getItemId()) {
        case R.id.action_play_next:
            MusicPlayerRemote.playNext(songs);
            return true;
        case R.id.action_add_to_current_playing:
            MusicPlayerRemote.enqueue(songs);
            return true;
        case R.id.action_add_to_playlist:
            AddToPlaylistDialog.create(songs).show(getSupportFragmentManager(), "ADD_PLAYLIST");
            return true;
        case android.R.id.home:
            super.onBackPressed();
            return true;
        case R.id.action_colored_footers:
            item.setChecked(!item.isChecked());
            return true;
        /*Sort*/
        case R.id.action_sort_order_title:
            sortOrder = ArtistSongSortOrder.SONG_A_Z;
            break;
        case R.id.action_sort_order_title_desc:
            sortOrder = ArtistSongSortOrder.SONG_Z_A;
            break;
        case R.id.action_sort_order_album:
            sortOrder = ArtistSongSortOrder.SONG_ALBUM;
            break;
        case R.id.action_sort_order_year:
            sortOrder = ArtistSongSortOrder.SONG_YEAR;
            break;
        case R.id.action_sort_order_artist_song_duration:
            sortOrder = ArtistSongSortOrder.SONG_DURATION;
            break;
        case R.id.action_sort_order_date:
            sortOrder = ArtistSongSortOrder.SONG_DATE;
            break;
        case R.id.action_set_artist_image:
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("image/*");
            startActivityForResult(Intent.createChooser(intent, getString(R.string.pick_from_local_storage)), REQUEST_CODE_SELECT_IMAGE);
            return true;
        case R.id.action_reset_artist_image:
            Toast.makeText(ArtistDetailActivity.this, getResources().getString(R.string.updating), Toast.LENGTH_SHORT).show();
            CustomArtistImageUtil.getInstance(ArtistDetailActivity.this).resetCustomArtistImage(mArtist);
            forceDownload = true;
            return true;
    }
    if (sortOrder != null) {
        item.setChecked(true);
        setSaveSortOrder(sortOrder);
    }
    return true;
}
 
Example 19
Project: BilibiliClient   File: MainActivity.java   View Source Code Vote up 4 votes
private void changeFragmentIndex(MenuItem item, int currIndex) {
    mIndex = currIndex;
    switchFragment();
    item.setChecked(true);
}
 
Example 20
Project: Quran   File: PagerActivity.java   View Source Code Vote up 4 votes
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
  super.onPrepareOptionsMenu(menu);
  MenuItem item = menu.findItem(R.id.favorite_item);
  if (item != null) {
    int page = QuranInfo.getPageFromPos(viewPager.getCurrentItem(), isDualPages);

    boolean bookmarked = false;
    if (bookmarksCache.indexOfKey(page) >= 0) {
      bookmarked = bookmarksCache.get(page);
    }

    if (!bookmarked && isDualPages &&
        bookmarksCache.indexOfKey(page - 1) >= 0) {
      bookmarked = bookmarksCache.get(page - 1);
    }

    item.setIcon(bookmarked ? R.drawable.ic_favorite : R.drawable.ic_not_favorite);
  }

  MenuItem quran = menu.findItem(R.id.goto_quran);
  MenuItem translation = menu.findItem(R.id.goto_translation);
  if (quran != null && translation != null) {
    if (!showingTranslation) {
      quran.setVisible(false);
      translation.setVisible(true);
    } else {
      quran.setVisible(true);
      translation.setVisible(false);
    }
  }

  MenuItem nightMode = menu.findItem(R.id.night_mode);
  if (nightMode != null) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean isNightMode = prefs.getBoolean(Constants.PREF_NIGHT_MODE, false);
    nightMode.setChecked(isNightMode);
    nightMode.setIcon(isNightMode ? R.drawable.ic_night_mode : R.drawable.ic_day_mode);
  }
  return true;
}