android.view.MenuItem#isChecked ( )源码实例Demo

下面列出了android.view.MenuItem#isChecked ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Conversations   文件: StartConversationActivity.java
@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);
}
 
源代码2 项目: yahnac   文件: CommentsPresenter.java
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;
        }

    }
 
@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;
}
 
源代码4 项目: OpenHub   文件: ViewerFragment.java
@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);
}
 
@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;
    }
}
 
源代码6 项目: kolabnotes-android   文件: MainActivity.java
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);
}
 
源代码7 项目: Jockey   文件: LibraryActivity.java
@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;
}
 
@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);
}
 
源代码9 项目: droidddle   文件: ShotFragment.java
@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);
}
 
源代码10 项目: about-page   文件: AboutActivity.java
@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;
}
 
源代码11 项目: android   文件: MainActivity.java
@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);
}
 
源代码12 项目: BleSensorTag   文件: SensorFusionActivity.java
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);
    }
}
 
源代码13 项目: PretendYoureXyzzyAndroid   文件: GamesFragment.java
@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);
}
 
@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);
    }
}
 
源代码15 项目: TigerVideo   文件: MainActivity.java
@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;
}
 
源代码16 项目: Loop   文件: MainActivity.java
@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;
                }
 
源代码17 项目: SkyTube   文件: YouTubePlayerV2Fragment.java
@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);
	}
}
 
源代码18 项目: Document-Scanner   文件: OcrCaptureActivity.java
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;
}
 
源代码19 项目: Shelter   文件: MainActivity.java
@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);
}
 
源代码20 项目: lua-for-android   文件: MainActivity.java
@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);
}