Java Code Examples for android.view.MenuItem#isChecked()

The following examples show how to use android.view.MenuItem#isChecked() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From android-kubernetes-blockchain with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    Fragment selectedFragment = null;
    if (item.isChecked()) {
        return false;
    }
    switch (item.getItemId()) {
        case R.id.navigation_technology:
            selectedFragment = TechFragment.newInstance();
            break;
        case R.id.navigation_user:
            selectedFragment = UserFragment.newInstance();
            break;
        case R.id.navigation_shop:
            selectedFragment = ShopFragment.newInstance();
            break;
        case R.id.navigation_leaderboards:
            selectedFragment = LeaderboardsFragment.newInstance();
    }
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.replace(R.id.frame_layout, selectedFragment);
    transaction.commit();
    return true;
}
 
Example 2
Source File: WeaponListFragment.java    From MonsterHunter4UDatabase with MIT License 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.filter_final:
            // toggle state
            item.setChecked(!item.isChecked());
            isFilterFinal = item.isChecked();

            // restart the loader so that filtering can occur
            getLoaderManager()
                    .restartLoader(R.id.weapon_list_fragment, getArguments(), this)
                    .forceLoad();

            return true;

        default:
            return false;
    }
}
 
Example 3
Source File: ViewerFragment.java    From OpenHub with GNU General Public License v3.0 6 votes vote down vote up
@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 4
Source File: StartConversationActivity.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	if (MenuDoubleTabUtil.shouldIgnoreTap()) {
		return false;
	}
	switch (item.getItemId()) {
		case android.R.id.home:
			navigateBack();
			return true;
		case R.id.action_scan_qr_code:
			UriHandlerActivity.scan(this);
			return true;
		case R.id.action_hide_offline:
			mHideOfflineContacts = !item.isChecked();
			getPreferences().edit().putBoolean("hide_offline", mHideOfflineContacts).apply();
			if (mSearchEditText != null) {
				filter(mSearchEditText.getText().toString());
			}
			invalidateOptionsMenu();
	}
	return super.onOptionsItemSelected(item);
}
 
Example 5
Source File: CommentsPresenter.java    From yahnac with Apache License 2.0 6 votes vote down vote up
public boolean onOptionsItemSelected(MenuItem item) {

        switch (item.getItemId()) {
            case R.id.action_bookmark:
                if (item.isChecked()) {
                    onBookmarkUnselected(item);
                } else {
                    onBookmarkSelected(item);
                }
                return true;
            case android.R.id.home:
                activity.finish();
                return true;
            default:
                return false;
        }

    }
 
Example 6
Source File: ShotFragment.java    From droidddle with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_share:
            UiUtils.shareShot(getActivity(), mShot);
            break;
        case R.id.action_add_attachment:
            startPickFile();
            break;
        case R.id.action_download:
            saveImage();
            break;

        case R.id.action_add_to_bucket:
            UiUtils.launchAddToBucket(getActivity(), mShot);
            break;

        case R.id.action_like:
            boolean checked = item.isChecked();
            item.setChecked(!checked);
            if (!checked) {
                item.setIcon(R.drawable.ic_action_liked);
            } else {
                item.setIcon(R.drawable.ic_action_like);
            }
            likeOrUnlikeShot(!checked);
            break;

    }
    return super.onOptionsItemSelected(item);
}
 
Example 7
Source File: AboutActivity.java    From about-page with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
  if (menuItem.getItemId() == R.id.menu_night_mode) {
    menuItem.setChecked(!menuItem.isChecked());
    if (menuItem.isChecked()) {
      AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
    } else {
      AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
    }
    getDelegate().applyDayNight();
  }
  return true;
}
 
Example 8
Source File: MainActivity.java    From android with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_carshare_mode) {
        final boolean toggled = !item.isChecked();

        item.setChecked(toggled);
        PrkngPrefs.getInstance(this).setCarshareMode(toggled);
        setupTabsMode(toggled);

        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 9
Source File: DemoLandingFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
  if (menuItem.getItemId() == R.id.favorite_toggle) {
    boolean isChecked = !menuItem.isChecked();
    FeatureDemoUtils.saveDefaultDemo(getContext(), isChecked ? getClass().getName() : "");
    setMenuItemChecked(menuItem, isChecked);
    return true;
  }

  return super.onOptionsItemSelected(menuItem);
}
 
Example 10
Source File: SensorFusionActivity.java    From BleSensorTag with MIT License 5 votes vote down vote up
private void lockOrientation(MenuItem item) {
    if (item.isChecked()) {
        item.setIcon(R.drawable.ic_action_lock_orientation_off);
        item.setTitle(R.string.menu_lock_orientation);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
    } else {
        item.setIcon(R.drawable.ic_action_lock_orientation_on);
        item.setTitle(R.string.menu_unlock_orientation);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    }
}
 
Example 11
Source File: LibraryActivity.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@IdRes
private int getSelectedDrawerItem() {
    Menu menu = mBinding.libraryDrawerNavigationView.getMenu();
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        if (item.isChecked()) {
            return item.getItemId();
        }
    }
    return R.id.menu_library_home;
}
 
Example 12
Source File: GamesFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.gamesFragment_showLocked) {
        boolean show = !item.isChecked();
        item.setChecked(show);
        Prefs.putBoolean(PK.FILTER_LOCKED_LOBBIES, !show);
        if (adapter != null) adapter.setFilterOutLockedLobbies(!show);
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 13
Source File: MainActivity.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void allNotesSelected(MenuItem item){
    Utils.setSelectedNotebookName(this, null);
    Utils.setSelectedTagName(this, null);

    final boolean checked = item.isChecked();
    if(!checked){
        item.setChecked(true);
        overviewFragment.allNotesSelected();
    }
    mDrawerLayout.closeDrawer(Gravity.LEFT);
}
 
Example 14
Source File: ProgressIndicatorDemoActivity.java    From imageprogressbar with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    super.onOptionsItemSelected(item);
    reset();
    final int itemId = item.getItemId();
    switch (itemId) {
        case R.id.action_indicator_blur:
            if (item.isChecked()) {
                item.setChecked(false);
            } else {
                item.setChecked(true);
            }
            progressImageView.setProgressIndicator(new BlurIndicator(this));
            return true;
        case R.id.action_indicator_colorfill:
            if (item.isChecked()) {
                item.setChecked(false);
            } else {
                item.setChecked(true);
            }
            progressImageView.setProgressIndicator(new ColorFillIndicator(ColorFillIndicator.PROGRESS_DIRECTION_HORIZONTAL_LEFT_RIGHT));
            return true;
        case R.id.action_indicator_random_block:
            if (item.isChecked()) {
                item.setChecked(false);
            } else {
                item.setChecked(true);
            }
            progressImageView.setProgressIndicator(new RandomBlockIndicator(BlockIndicator.BLOCK_SIZE_SMALL));
            return true;
        case R.id.action_indicator_pixelize:
            if (item.isChecked()) {
                item.setChecked(false);
            } else {
                item.setChecked(true);
            }
            progressImageView.setProgressIndicator(new PixelizeIndicator(this));
            return true;
        case R.id.action_indicator_ciculator:
            if (item.isChecked()) {
                item.setChecked(false);
            } else {
                item.setChecked(true);
            }
            progressImageView.setProgressIndicator(new CircularIndicator());
            return true;
        case R.id.action_indicator_alpha:
            if (item.isChecked()) {
                item.setChecked(false);
            } else {
                item.setChecked(true);
            }
            progressImageView.setProgressIndicator(new AlphaIndicator());
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 15
Source File: MainActivity.java    From TigerVideo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onNavigationItemSelected(MenuItem item) {

    if(item.isChecked()) {
        mDrawerLayout.closeDrawer(GravityCompat.START);
        return true;
    }

    int id = item.getItemId();
    Fragment fragment = mFragmentSparseArray.get(id);
    if(fragment == null) {
        switch (id) {
            case R.id.nav_net_easy:
                if(fragment == null) {
                    fragment = FragmentFactory.createMainFragment(DataType.NET_EASY);
                }
                break;
            case R.id.nav_ttkb:
                fragment = FragmentFactory.createMainFragment(DataType.TTKB);
                break;
            case R.id.nav_ifeng:
                fragment = FragmentFactory.createMainFragment(DataType.IFENG);
                break;
            case R.id.nav_share://分享
                ShareHelper.shareApp(this);
                break;
            case R.id.nav_about:
                startActivity(new Intent(MainActivity.this, AboutActivity.class));
                fragment = null;
                break;
        }
    }
    if(fragment != null) {
        mFragmentSparseArray.put(id, fragment);
    }
    mDrawerLayout.closeDrawer(GravityCompat.START);
    if(fragment != null) {
        switchFragment(fragment);
    }

    return true;
}
 
Example 16
Source File: MainActivity.java    From Loop with Apache License 2.0 4 votes vote down vote up
@Override
                public boolean onNavigationItemSelected(MenuItem menuItem) {
                    drawerLayout.closeDrawers();

                    String title = menuItem.getTitle().toString();
                    switch (title) {
                        case WATCH_NOW:
                            if(!menuItem.isChecked()){
                                menuItem.setChecked(true);
                                getSupportFragmentManager()
                                        .beginTransaction()
                                        .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
                                        .replace(R.id.content_fl, WatchNowFragment.newInstance(), "")
                                        .commit();
                            }
                            break;
                        case LIKES:
                            if(!menuItem.isChecked()) {
                                menuItem.setChecked(true);
                                getSupportFragmentManager()
                                        .beginTransaction()
                                        .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
                                        .replace(R.id.content_fl, LikedVideosFragment.newInstance(), "")
                                        .commit();
                            }
                            break;
                        case WATCH_LATER:
                            if(!menuItem.isChecked()) {
                                menuItem.setChecked(true);
                                getSupportFragmentManager()
                                        .beginTransaction()
                                        .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
                                        .replace(R.id.content_fl, WatchLaterVideosFragment.newInstance(), "")
                                        .commit();
                            }
                            break;
                        case EXPLORE:
                            if(!menuItem.isChecked()) {
                                menuItem.setChecked(true);
                                getSupportFragmentManager()
                                        .beginTransaction()
                                        .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
                                        .replace(R.id.content_fl, ExploreFragment.newInstance(), "")
                                        .commit();
                            }
                            break;
//                        case SETTINGS:
//                            getSupportFragmentManager()
//                                    .beginTransaction()
//                                    .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
//                                    .replace(R.id.content_fl, PlaceholderFragment.newInstance(), "")
//                                    .commit();
//                            break;
                        case HELP_AND_FEEDBACK:
                            try {
                                startActivity(EmailUtility.getEmailIntent(MainActivity.this));
                            } catch (android.content.ActivityNotFoundException ex) {
                                Snackbar.make(findViewById(android.R.id.content),
                                        TrestleUtility.getFormattedText("There are no email apps installed on your device", font, 16),
                                        Snackbar.LENGTH_LONG)
                                        .show();
                            }
                            break;
                        case LOGOUT:
                            LoopPrefs.signOut(MainActivity.this);
                            startActivity(new Intent(MainActivity.this, LauncherActivity.class));
                        default:
                            break;
                    }
                    return true;
                }
 
Example 17
Source File: YouTubePlayerV2Fragment.java    From SkyTube with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
		case R.id.menu_reload_video:
			player.seekToDefaultPosition();
			return true;

		case R.id.menu_open_video_with:
			player.setPlayWhenReady(false);
			youTubeVideo.playVideoExternally(getContext());
			return true;

		case R.id.share:
			player.setPlayWhenReady(false);
			youTubeVideo.shareVideo(getContext());
			return true;

		case R.id.copyurl:
			youTubeVideo.copyUrl(getContext());
			return true;

		case R.id.bookmark_video:
			youTubeVideo.bookmarkVideo(getContext(), menu);
			return true;

		case R.id.unbookmark_video:
			youTubeVideo.unbookmarkVideo(getContext(), menu);
			return true;

		case R.id.view_thumbnail:
			Intent i = new Intent(getActivity(), ThumbnailViewerActivity.class);
			i.putExtra(ThumbnailViewerActivity.YOUTUBE_VIDEO, youTubeVideo);
			startActivity(i);
			return true;

		case R.id.download_video:
			final Policy decision = new MobileNetworkWarningDialog(getContext())
					.showDownloadWarning(youTubeVideo);

			if (decision == Policy.ALLOW) {
				youTubeVideo.downloadVideo(getContext());
			}
			return true;

		case R.id.block_channel:
			youTubeChannel.blockChannel();
			return true;
		case R.id.disable_gestures:
			boolean disableGestures = !item.isChecked();
			item.setChecked(disableGestures);
			SkyTubeApp.getSettings().setDisableGestures(disableGestures);
			playerViewGestureHandler.setDisableGestures(disableGestures);
			return true;
		case R.id.video_repeat_toggle:
			boolean repeat = !item.isChecked();
			player.setRepeatMode(repeat ? Player.REPEAT_MODE_ALL : Player.REPEAT_MODE_OFF);
			item.setChecked(repeat);
			return true;
		default:
			return super.onOptionsItemSelected(item);
	}
}
 
Example 18
Source File: OcrCaptureActivity.java    From Document-Scanner with GNU General Public License v3.0 4 votes vote down vote up
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.

    switch (item.getItemId()) {

        case R.id.saved_texts:
            Intent intent = new Intent(this, SavedTextsList.class);
            startActivity(intent);
            return true;

        case R.id.tblocks:
            block = 0;
            if (item.isChecked())
                item.setChecked(false);
            else
                item.setChecked(true);
            break;

        case R.id.tlines:
            block = 1;
            if (item.isChecked())
                item.setChecked(false);
            else
                item.setChecked(true);
            break;

        case R.id.twords:
            block = 2;
            if (item.isChecked())
                item.setChecked(false);
            else
                item.setChecked(true);
            break;

        default:
            block = 1;
            break;
    }

    mSharedPref.edit().putInt("block", block);

    return false;
}
 
Example 19
Source File: MainActivity.java    From Shelter with Do What The F*ck You Want To Public License 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.main_menu_freeze_all:
            // This is the same as clicking on the batch freeze shortcut
            // so we just forward the request to DummyActivity
            Intent intent = new Intent(DummyActivity.PUBLIC_FREEZE_ALL);
            intent.setComponent(new ComponentName(this, DummyActivity.class));
            startActivity(intent);
            return true;
        case R.id.main_menu_settings:
            Intent settingsIntent = new Intent(this, SettingsActivity.class);
            Bundle extras = new Bundle();
            extras.putBinder("profile_service", mServiceWork.asBinder());
            settingsIntent.putExtra("extras", extras);
            startActivity(settingsIntent);
            return true;
        case R.id.main_menu_create_freeze_all_shortcut:
            Intent launchIntent = new Intent(DummyActivity.PUBLIC_FREEZE_ALL);
            launchIntent.setComponent(new ComponentName(this, DummyActivity.class));
            launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
            Utility.createLauncherShortcut(this, launchIntent,
                    Icon.createWithResource(this, R.mipmap.ic_freeze),
                    "shelter-freeze-all", getString(R.string.freeze_all_shortcut));
            return true;
        case R.id.main_menu_install_app_to_profile:
            Intent openApkIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            openApkIntent.addCategory(Intent.CATEGORY_OPENABLE);
            openApkIntent.setType("application/vnd.android.package-archive");
            startActivityForResult(openApkIntent, REQUEST_DOCUMENTS_CHOOSE_APK);
            return true;
        case R.id.main_menu_show_all:
            Runnable update = () -> {
                mShowAll = !item.isChecked();
                item.setChecked(mShowAll);
                LocalBroadcastManager.getInstance(this)
                        .sendBroadcast(new Intent(AppListFragment.BROADCAST_REFRESH));
            };

            if (!item.isChecked()) {
                new AlertDialog.Builder(this)
                        .setMessage(R.string.show_all_warning)
                        .setPositiveButton(R.string.first_run_alert_continue,
                                (dialog, which) -> update.run())
                        .setNegativeButton(R.string.first_run_alert_cancel, null)
                        .show();
            } else {
                update.run();
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 20
Source File: MainActivity.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.run:
            runCode();
            break;
        case R.id.redo:
            editor.redo();
            break;
        case R.id.undo:
            editor.undo();
            break;
        case R.id.gotoLine:
            editor.startGotoMode();
            break;
        case R.id.search:
            editor.startFindMode();
            break;
        case R.id.search_library:
            if(classList==null)
                classList=context.getClasses();
            editor.startLibrarySearchMode(classList);
            break;
        case R.id.view_result:
            showResult();
            break;
        case R.id.save:
            save();
            break;
        case R.id.open:{
            save();
            final FilePicker filePicker =new FilePicker(this, new File(editor.lastFile()),
                    pathname -> pathname.isDirectory() || pathname.getName().matches(".+(.lua)$"));
            filePicker.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 800));
            new AlertDialog.Builder(this,android.R.style.Theme_DeviceDefault_Light_Dialog).setView(filePicker).setNegativeButton(R.string.cancel,null).
                            setPositiveButton(R.string.confirm, (dialog2, which) -> {
                                File f =filePicker.getSelectedFile();
                                if(f!=null){
                                    loadFile(f.getAbsolutePath());
                                }
                            }).show();
        }
        break;
        case R.id.help:
            startActivity(new Intent().setAction(Intent.ACTION_VIEW).setData(Uri.parse("https://github.com/qtiuto/lua-for-android/wiki")));
            break;
        case R.id.lua_doc:
            startActivity(new Intent().setAction(Intent.ACTION_VIEW).setData(Uri.parse("http://www.lua.org/manual/5.3/manual.html")));
            break;
        case R.id.root_mode:{
            if(item.isChecked()){
                ((TransmitClient)(context)).close();
                context=old;
                item.setChecked(false);
                Toast.makeText(this,
                        R.string.root_mode_exited,Toast.LENGTH_SHORT).show();
            }else {
                new Thread(()->{
                    boolean switched=startRootMode();
                    handler.post(()->{
                        if(switched) item.setChecked(true);
                        Toast.makeText(this,switched?R.string.root_mode_ok:
                                R.string.root_mode_failed,Toast.LENGTH_SHORT).show();
                    });
                }).start();

            }

        }

    }
    return super.onOptionsItemSelected(item);
}