Example usage for android.view MenuItem isCheckable

List of usage examples for android.view MenuItem isCheckable

Introduction

In this page you can find the example usage for android.view MenuItem isCheckable.

Prototype

public boolean isCheckable();

Source Link

Document

Return whether the item can currently display a check mark.

Usage

From source file:com.loopj.android.http.sample.Redirect302Sample.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable()) {
        item.setChecked(!item.isChecked());
        if (item.getItemId() == 0) {
            enableRedirects = item.isChecked();
        } else if (item.getItemId() == 1) {
            enableRelativeRedirects = item.isChecked();
        } else if (item.getItemId() == 2) {
            enableCircularRedirects = item.isChecked();
        }/*ww w . ja va 2s .  co m*/
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.voidsink.anewjkuapp.LocationOverlay.java

public void setSnapToLocationItem(MenuItem item) {
    if (item != null && item.isCheckable()) {
        this.snapToLocationItem = item;
    } else {// w w  w  .j  a  v a  2  s  .c  om
        this.snapToLocationItem = null;
    }
}

From source file:com.vrem.wifianalyzer.navigation.NavigationMenuViewTest.java

@Test
public void testGetCurrentMenuItem() throws Exception {
    // setup//from  w  w w.ja va 2s  . c  o m
    MenuItem expected = getMenuItem(NavigationMenu.ACCESS_POINTS);
    // execute
    MenuItem actual = fixture.getCurrentMenuItem();
    // validate
    assertEquals(expected, actual);
    assertTrue(actual.isCheckable());
    assertTrue(actual.isChecked());
}

From source file:com.microsoft.azure.engagement.MainActivity.java

/**
 * Method that updates the current menu item selected
 *
 * @param item The menu item to select//ww w . ja v  a  2 s .  com
 */
private final void updateSelection(MenuItem item) {
    if (item.isCheckable() == true) {
        item.setChecked(true);
        if (previousItem != null) {
            previousItem.setChecked(false);
        }
        previousItem = item;
    }
}

From source file:se.eliga.aves.songs.BirdSpeciesXenoCantoPlayerFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable()) {
        audioAutoNext.setChecked(false);
        audioRepeat.setChecked(false);/*from   w  w  w.  j a  v  a2 s.  c om*/
        item.setChecked(true);
    }
    return true;
}

From source file:se.eliga.aves.birdlist.BirdListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    if (item.isCheckable()) {

        if (R.id.filtering_group == item.getGroupId()) {
            item.setChecked(!item.isChecked());
        } else if (R.id.sort_order_group == item.getGroupId()) {
            swedishSortItem.setChecked(false);
            englishSortItem.setChecked(false);
            latinSortItem.setChecked(false);
            phylogeneticSortItem.setChecked(false);
            populationSortItem.setChecked(false);
            item.setChecked(true);/*from  w ww. ja v a 2  s.c o  m*/
        }

        BirdListAdapter birdListAdapter = (BirdListAdapter) getListAdapter();
        switch (item.getItemId()) {
        case R.id.alphabetic_latin:
            birdListAdapter.setSortOption(BirdListAdapter.SortOption.SCIENTIFIC);
            break;
        case R.id.alphabetic_swedish:
            birdListAdapter.setSortOption(BirdListAdapter.SortOption.SWEDISH);
            break;
        case R.id.alphabetic_english:
            birdListAdapter.setSortOption(BirdListAdapter.SortOption.ENGLISH);
            break;
        case R.id.phylogenic_sort:
            birdListAdapter.setSortOption(BirdListAdapter.SortOption.PHYLOGENETIC);
            break;
        case R.id.population_sort:
            birdListAdapter.setSortOption(BirdListAdapter.SortOption.POPULATION);
            break;

        }

        birdListAdapter.setShowBreeding(breedingItem.isChecked());
        birdListAdapter.setShowBreedingUnclear(breedingUnclearItem.isChecked());
        birdListAdapter.setShowMigrant(migrantItem.isChecked());
        birdListAdapter.setShowRare(rareItem.isChecked());
        birdListAdapter.setShowRegularVisitor(regularVisitorItem.isChecked());
        birdListAdapter.setShowUnseen(unseenItem.isChecked());
        birdListAdapter.setShowUnclassified(unclassifiedItem.isChecked());
        birdListAdapter.setShowNonSpontaneous(nonSpontaneousItem.isChecked());

        birdListAdapter.refresh();
        birdListAdapter.notifyDataSetChanged();
    }
    SharedPreferences settings = getActivity().getSharedPreferences(Constants.BIRD_APP_SETTINGS, 0);
    saveFilterPreferences(settings);
    return true;
}

From source file:org.voidsink.anewjkuapp.fragment.LvaDetailFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    inflater.inflate(R.menu.lva, menu);/*from  w ww  .ja  va 2  s .  com*/

    MenuItem item = menu.findItem(R.id.action_toggle_visible_lvas);
    if (item != null) {
        item.setChecked(item.isCheckable() && PreferenceWrapper.getShowCoursesWithAssessmentOnly(getContext()));
    }
}

From source file:org.mariotaku.twidere.fragment.support.RetweetQuoteDialogFragment.java

@NonNull
@Override/*w  w w.j a  v a2  s . c  o  m*/
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity());
    final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped);
    final Context context = builder.getContext();
    mValidator = new TwidereValidator(context);
    mPreferences = SharedPreferencesWrapper.getInstance(context, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE,
            SharedPreferenceConstants.class);
    final LayoutInflater inflater = LayoutInflater.from(context);
    @SuppressLint("InflateParams")
    final View view = inflater.inflate(R.layout.dialog_status_quote_retweet, null);
    final StatusViewHolder holder = new StatusViewHolder(new DummyStatusHolderAdapter(context),
            view.findViewById(R.id.item_content));
    final ParcelableStatus status = getStatus();

    assert status != null;

    builder.setView(view);
    builder.setTitle(R.string.retweet_quote_confirm_title);
    if (isMyRetweet(status)) {
        builder.setPositiveButton(R.string.cancel_retweet, this);
    } else if (!status.user_is_protected) {
        builder.setPositiveButton(R.string.retweet, this);
    }
    builder.setNeutralButton(R.string.quote, this);
    builder.setNegativeButton(android.R.string.cancel, null);

    holder.displayStatus(status, null, false, true);

    view.findViewById(R.id.item_menu).setVisibility(View.GONE);
    view.findViewById(R.id.action_buttons).setVisibility(View.GONE);
    view.findViewById(R.id.item_content).setFocusable(false);
    view.findViewById(R.id.comment_container)
            .setVisibility(status.user_is_protected ? View.GONE : View.VISIBLE);
    mEditComment = (UserHashtagAutoCompleteEditText) view.findViewById(R.id.edit_comment);
    mEditComment.setAccountId(status.account_id);
    mEditComment.setLengthChecker(new METLengthChecker() {

        final String statusLink = LinkCreator.getTwitterStatusLink(status.user_screen_name, status.quote_id)
                .toString();

        @Override
        public int getLength(CharSequence text) {
            return mValidator.getTweetLength(text + " " + statusLink);
        }
    });
    mEditComment.setMaxCharacters(mValidator.getMaxTweetLength());

    final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND);
    final EditTextEnterHandler enterHandler = EditTextEnterHandler.attach(mEditComment,
            new EditTextEnterHandler.EnterListener() {
                @Override
                public void onHitEnter() {
                    final AsyncTwitterWrapper twitter = getTwitterWrapper();
                    final ParcelableStatus status = getStatus();
                    if (twitter == null || status == null)
                        return;
                    retweetOrQuote(twitter, status);
                    dismiss();
                }
            }, sendByEnter);
    enterHandler.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            final Dialog dialog = getDialog();
            if (!(dialog instanceof AlertDialog))
                return;
            final Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            if (positiveButton == null)
                return;
            positiveButton.setText(s.length() > 0 ? R.string.comment : R.string.retweet);
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
    mCommentMenu = view.findViewById(R.id.comment_menu);

    mPopupMenu = new PopupMenu(context, mCommentMenu, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0);
    mCommentMenu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mPopupMenu.show();
        }
    });
    mCommentMenu.setOnTouchListener(mPopupMenu.getDragToOpenListener());
    mPopupMenu.inflate(R.menu.menu_dialog_comment);
    final Menu menu = mPopupMenu.getMenu();
    MenuUtils.setMenuItemAvailability(menu, R.id.quote_original_status,
            status.retweet_id > 0 || status.quote_id > 0);
    mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.isCheckable()) {
                item.setChecked(!item.isChecked());
                return true;
            }
            return false;
        }
    });

    return builder.create();
}

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

public boolean onOptionsItemSelected(MenuItem menuItem) {
    int id = menuItem.getItemId();
    if (menuItem.isCheckable())
        menuItem.setChecked(!menuItem.isChecked());
    switch (id) {
    case R.id.action_setting:
        mAnalytics.logEvent("action_setting", new Bundle());
        mActivity.startActivity(new Intent(mActivity, SettingsActivity.class));
        break;/* www. j a va  2s .co  m*/
    case R.id.action_find:
        mAnalytics.logEvent("action_find", new Bundle());
        mActivity.showDialogFind();
        break;
    case R.id.action_find_and_replace:
        mAnalytics.logEvent("action_find_and_replace", new Bundle());
        mListener.findAndReplace();
        break;
    case R.id.action_doc:
        mListener.showDocumentActivity();
        break;
    case R.id.action_new_file:
        mListener.createNewSourceFile(null);
        break;
    case R.id.action_code_sample:
        mAnalytics.logEvent("action_code_sample", new Bundle());
        mActivity.startActivity(new Intent(mActivity, CodeSampleActivity.class));
        break;
    case R.id.action_rate:
        mAnalytics.logEvent("action_rate", new Bundle());
        StoreUtil.gotoPlayStore(mActivity, BuildConfig.APPLICATION_ID);
        break;
    case R.id.action_more_app:
        mAnalytics.logEvent("action_more_app", new Bundle());
        StoreUtil.moreApp(mActivity);
        break;
    case R.id.nav_run:
        mListener.runProgram();
        break;
    case R.id.action_compile:
        mListener.doCompile();
        break;
    case R.id.action_save: {
        EditorFragment fragment = mActivity.getEditorFragment();
        if (fragment != null)
            fragment.saveFile();
        break;
    }
    case R.id.action_save_as:
        mListener.saveAs();
        break;
    case R.id.action_goto_line:
        mAnalytics.logEvent("action_goto_line", new Bundle());
        mListener.goToLine();
        break;
    case R.id.action_format: {
        mAnalytics.logEvent("action_format", new Bundle());
        EditorFragment fragment = mActivity.getEditorFragment();
        if (fragment != null)
            fragment.formatCode();
        break;
    }
    case R.id.action_report_bug:
        mListener.reportBug();
        break;
    case R.id.action_undo: {
        EditorFragment fragment = mActivity.getEditorFragment();
        if (fragment != null)
            fragment.undo();
        break;
    }
    case R.id.action_redo: {
        EditorFragment fragment = mActivity.getEditorFragment();
        if (fragment != null)
            fragment.redo();
        break;
    }
    case R.id.action_paste: {
        EditorFragment fragment = mActivity.getEditorFragment();
        if (fragment != null)
            fragment.paste();
        break;
    }
    case R.id.action_copy_all: {
        EditorFragment fragment = mActivity.getEditorFragment();
        if (fragment != null)
            fragment.copyAll();
        break;
    }
    case R.id.action_select_theme:
        mAnalytics.logEvent("action_select_theme", new Bundle());
        mListener.selectThemeFont();
        break;
    case R.id.action_more_feature:
        mActivity.openDrawer(GravityCompat.END);
        break;
    case R.id.action_translate:
        mAnalytics.logEvent("action_translate", new Bundle());
        startActivityTranslate();
        break;
    case R.id.action_info:
        mAnalytics.logEvent("action_info", new Bundle());
        mActivity.startActivity(new Intent(mActivity, InfoActivity.class));
        break;
    case R.id.action_program_structure:
        mActivity.showProgramStructure();
        break;
    case R.id.action_debug:
        mAnalytics.logEvent("action_debug", new Bundle());
        mActivity.startDebug();
        break;
    case R.id.action_open_file:
        mActivity.openDrawer(GravityCompat.START);
        break;
    case R.id.action_insert_media_url:
        selectMediaUrl();
        break;
    case R.id.action_insert_color:
        mAnalytics.logEvent("action_insert_color", new Bundle());
        mActivity.insertColor();
        break;
    }
    return true;
}

From source file:org.gnucash.android.ui.report.PieChartFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable())
        item.setChecked(!item.isChecked());
    switch (item.getItemId()) {
    case R.id.menu_order_by_size: {
        bubbleSort();/*from  w  ww .j  a  v  a  2  s . co  m*/
        return true;
    }
    case R.id.menu_toggle_legend: {
        mChart.getLegend().setEnabled(!mChart.getLegend().isEnabled());
        mChart.getLegend().setForm(LegendForm.CIRCLE);
        mChart.getLegend().setPosition(LegendPosition.RIGHT_OF_CHART_CENTER);
        mChart.notifyDataSetChanged();
        mChart.invalidate();
        return true;
    }
    case R.id.menu_toggle_labels: {
        mChart.getData().setDrawValues(!mChart.isDrawSliceTextEnabled());
        mChart.setDrawSliceText(!mChart.isDrawSliceTextEnabled());
        mChart.invalidate();
        return true;
    }
    case R.id.menu_group_other_slice: {
        mGroupSmallerSlices = !mGroupSmallerSlices;
        displayChart();
        return true;
    }

    default:
        return super.onOptionsItemSelected(item);
    }
}