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

The following are Jave code examples for showing how to use isChecked() 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: chromium-for-android-56-debug-video   File: AppMenuAdapter.java   View Source Code Vote up 6 votes
private void setupImageButton(TintedImageButton button, final MenuItem item) {
    // Store and recover the level of image as button.setimageDrawable
    // resets drawable to default level.
    int currentLevel = item.getIcon().getLevel();
    button.setImageDrawable(item.getIcon());
    item.getIcon().setLevel(currentLevel);
    if (item.isChecked()) {
        button.setTint(ApiCompatibilityUtils.getColorStateList(
                button.getResources(), R.color.blue_mode_tint));
    }
    button.setEnabled(item.isEnabled());
    button.setFocusable(item.isEnabled());
    button.setContentDescription(item.getTitleCondensed());

    button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mAppMenu.onItemClick(item);
        }
    });

    // Menu items may be hidden by command line flags before they get to this point.
    button.setVisibility(item.isVisible() ? View.VISIBLE : View.GONE);
}
 
Example 2
Project: RefreshLoadLayout   File: MainActivity.java   View Source Code Vote up 6 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id=item.getItemId();
    switch (id){
        case R.id.toRecycler:
            startActivity(new Intent(this,RecyclerViewActivity.class));
            return true;
        case R.id.ban_refresh:
            boolean enable=item.isChecked();
            item.setChecked(!enable);
            refreshLoadLayout.setRefreshingEnabled(enable);
            return true;
        case R.id.ban_load:
            boolean checked=item.isChecked();
            item.setChecked(!checked);
            refreshLoadLayout.setLoadingEnabled(checked);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }

}
 
Example 3
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 4
Project: tumbviewer   File: VideoFragment.java   View Source Code Vote up 6 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.show_user_video) {
        item.setChecked(!item.isChecked());
        showUserVideo = item.isChecked();
        if (showUserVideo) {
            initVideoDataUser();
        } else {
            initVideoDataAll();
        }
        adapter.resetData(videoList.toArray(), false);
        PreferencesUtils.putBoolean(SHOW_USER_VIDEO, showUserVideo);
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 5
Project: GitHub   File: HomeActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
    mDrawerLayout.closeDrawer(GravityCompat.START);
    if (item.isChecked()) {
        return true;
    }
    mItemId = item.getItemId();
    return true;
}
 
Example 6
Project: underlx   File: MapFragment.java   View Source Code Vote up 5 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_zoom_out:
            webview.zoomOut();
            return true;
        case R.id.menu_zoom_in:
            webview.zoomIn();
            return true;
        case R.id.menu_swap_map:
            portraitMap = !portraitMap;
            SharedPreferences sharedPref = getContext().getSharedPreferences("settings", MODE_PRIVATE);
            SharedPreferences.Editor e = sharedPref.edit();
            e.putBoolean("pref_portrait_map", portraitMap);
            e.apply();
            if (portraitMap) {
                webview.getSettings().setUseWideViewPort(false);
                webview.loadUrl("file:///android_asset/map-" + networkId + "-portrait.html");
            } else {
                webview.getSettings().setUseWideViewPort(true);
                webview.loadUrl("file:///android_asset/map-" + networkId + ".html");
            }
            return true;
        case R.id.menu_mock_location:
            mockLocationMode = !item.isChecked();
            item.setChecked(mockLocationMode);
            return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example 7
Project: GitHub   File: Redirect302Sample.java   View Source Code Vote up 5 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable()) {
        item.setChecked(!item.isChecked());
        if (item.getItemId() == MENU_ENABLE_REDIRECTS) {
            enableRedirects = item.isChecked();
        } else if (item.getItemId() == MENU_ENABLE_RELATIVE_REDIRECTs) {
            enableRelativeRedirects = item.isChecked();
        } else if (item.getItemId() == MENU_ENABLE_CIRCULAR_REDIRECTS) {
            enableCircularRedirects = item.isChecked();
        }
    }
    return super.onOptionsItemSelected(item);
}
 
Example 8
Project: SimpleRssReader   File: HistoryAwareBottomNavigationView.java   View Source Code Vote up 5 votes
private void setPreviousSelectedItemIdInternal() {
    final Menu menu = getMenu();

    for (int i = 0; i < menu.size(); i++) {
        final MenuItem item = menu.getItem(i);

        if (item.isChecked()) {
            mPreviousSelectedItemId = item.getItemId();
            break;
        }
    }
}
 
Example 9
Project: AndroidAsyncHTTP   File: Redirect302Sample.java   View Source Code Vote up 5 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable()) {
        item.setChecked(!item.isChecked());
        if (item.getItemId() == MENU_ENABLE_REDIRECTS) {
            enableRedirects = item.isChecked();
        } else if (item.getItemId() == MENU_ENABLE_RELATIVE_REDIRECTs) {
            enableRelativeRedirects = item.isChecked();
        } else if (item.getItemId() == MENU_ENABLE_CIRCULAR_REDIRECTS) {
            enableCircularRedirects = item.isChecked();
        }
    }
    return super.onOptionsItemSelected(item);
}
 
Example 10
Project: mvvm-template   File: ViewerFragment.java   View Source Code Vote up 5 votes
@Override public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.wrap) {
        item.setChecked(!item.isChecked());
        isWrap = item.isChecked();
        setLoading(true);
        onSetCode(viewModel.getDownloadedStream());
    }
    return super.onOptionsItemSelected(item);
}
 
Example 11
Project: android-fido   File: U2FDemoActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    // Handle navigation view item clicks here.
    switch (item.getItemId()) {
        case R.id.nav_signin:
            signIn();
            break;
        case R.id.nav_signout:
            signOut();
            break;
        case R.id.nav_register:
            getRegisterRequest();
            break;
        case R.id.nav_auth:
            getSignRequest();
            break;
        case R.id.nav_gitbuh:
            Intent browser = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(getString(R.string.github_location)));
            this.startActivity(browser);
            break;
        case R.id.nav_allowReregistration:
            boolean newStatus = !item.isChecked();
            item.setChecked(newStatus);
            return true;
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example 12
Project: Lazy-Switches   File: BluetoothActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case android.R.id.home:
            bluetoothService.stop();
            NavUtils.navigateUpFromSameTask(this);
            return true;
        case R.id.action_reconnect:
            reconnect();
            return true;
        case R.id.action_clear:
            // chatAdapter.clear();
            return true;
        case R.id.checkable_auto_scroll:
            autoScrollIsChecked = !item.isChecked();
            item.setChecked(autoScrollIsChecked);
            return true;
        case R.id.checkable_show_messages:
            openTimePickerDialog(false);
            return true;
        case R.id.checkable_show_time:
            showTimeIsChecked = !item.isChecked();
            item.setChecked(showTimeIsChecked);
            // chatAdapter.notifyDataSetChanged();
            return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 13
Project: IslamicLibraryAndroid   File: BookPageFragment.java   View Source Code Vote up 5 votes
private void setBookMarkIcon(MenuItem item) {
    TypedValue typedvalueattr = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.menuBookmarkIcon, typedvalueattr, true);
    StateListDrawable stateListDrawable = (StateListDrawable) getResources().getDrawable(typedvalueattr.resourceId);
    int[] state = {item.isChecked() ? android.R.attr.state_checked : -android.R.attr.state_checked};
    stateListDrawable.setState(state);
    item.setIcon(stateListDrawable.getCurrent());
    item.setTitle(item.isChecked() ? R.string.action_remove_book_mark : R.string.action_add_book_mark);
}
 
Example 14
Project: IslamicLibraryAndroid   File: BrowsingActivityNavigationController.java   View Source Code Vote up 5 votes
boolean handleButtomNavigationItem(MenuItem item) {
    if (!item.isChecked()) {
        saveBottomBarPosition(item);
        return switchBottomNavigationTo(item.getItemId());
    } else {
        return false;
    }
}
 
Example 15
Project: javaide   File: FileExplorerAction.java   View Source Code Vote up 5 votes
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.select_all) {
        if (!item.isChecked()) {
            view.setSelectAll(true);
            item.setChecked(true);
            item.setTitle(R.string.cancel_select_all);
        } else {
            view.setSelectAll(false);
        }
    } else if (id == R.id.copy && !checkedList.isEmpty()) {
        fileClipboard.setData(true, checkedList);
        destroyActionMode();
    } else if (id == R.id.cut && !checkedList.isEmpty()) {
        fileClipboard.setData(false, checkedList);
        destroyActionMode();
    } else if (id == R.id.paste) {
        destroyActionMode();
        fileClipboard.paste(context, explorerContext.getCurrentDirectory(), new OnClipboardPasteFinishListener() {
            @Override
            public void onFinish(int count, String error) {
                fileClipboard.showPasteResult(context, count, error);
            }
        });
    } else if (id == R.id.rename) {
        doRenameAction();
    } else if (id == R.id.share) {
        shareFile();
    } else if (id == R.id.delete) {
        doDeleteAction();
    } else {
        return false;
    }
    return true;
}
 
Example 16
Project: buildAPKsSamples   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_clear_all:
            mLogLines.clear();
            logOnUiThread("");
            break;
        case R.id.action_keep_screen_on:
            boolean checked = !item.isChecked();
            setKeepScreenOn(checked);
            item.setChecked(checked);
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 17
Project: buildAPKsSamples   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_keep_screen_on:
            boolean checked = !item.isChecked();
            setKeepScreenOn(checked);
            item.setChecked(checked);
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 18
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 19
Project: buildAPKsSamples   File: SquashAndStretch.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 20
Project: NeverCrash   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.item_show_system:
            item.setChecked(!item.isChecked());
            mSharedPreferences.edit()
                    .putBoolean(PREF_SHOW_SYSTEM, item.isChecked())
                    .apply();
            mIsSystemEnable = item.isChecked();
            filterApps(app -> true);
            break;
        case R.id.item_show_toast:
            item.setChecked(!item.isChecked());
            mSharedPreferences.edit()
                    .putBoolean(PREF_TOAST, item.isChecked())
                    .apply();
            break;
        case R.id.item_cancel_all:
            filterApps(app -> {
                app.get_it = false;
                return true;
            });
            updatePref();
            break;
        case R.id.item_on:
            item.setChecked(true);
            filterApps(app -> app.get_it);
            break;
        case R.id.item_off:
            item.setChecked(true);
            filterApps(app -> !app.get_it);
            break;
        case R.id.item_all:
            item.setChecked(true);
            filterApps(app -> true);
            break;
        case R.id.item_help:
            new AlertDialog.Builder(MainActivity.this)
                    .setTitle(getString(R.string.using_warning_title))
                    .setMessage(getString(R.string.using_warning))
                    .show();
            break;
        case R.id.item_select_all:
            filterApps(app -> {
                app.get_it = true;
                return true;
            });
            updatePref();
            break;

        case R.id.item_sort_by_name:
            item.setChecked(true);
            sort((a, b) -> a.name.compareTo(b.name));
            break;
        case R.id.item_sort_by_name_reverse:
            item.setChecked(true);
            sort(Collections.reverseOrder((a, b) -> a.name.compareTo(b.name)));
            break;
        case R.id.item_sort_by_install_time:
            item.setChecked(true);
            sort((a, b) -> a.installTime == b.installTime ? 0 : (a.installTime > b.installTime ? 1 : -1));
            break;
        case R.id.item_sort_by_install_time_reverse:
            item.setChecked(true);
            sort(Collections.reverseOrder((a, b) -> a.installTime == b.installTime ? 0 : (a.installTime > b.installTime ? 1 : -1)));
            break;
        case R.id.item_sort_by_update_time:
            item.setChecked(true);
            sort((a, b) -> a.updateTime == b.updateTime ? 0 : (a.updateTime > b.updateTime ? 1 : -1));
            break;
        case R.id.item_sort_by_update_time_reverse:
            item.setChecked(true);
            sort(Collections.reverseOrder((a, b) -> a.updateTime == b.updateTime ? 0 : (a.updateTime > b.updateTime ? 1 : -1)));
            break;
    }
    return true;
}