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:us.shandian.blacklight.ui.statuses.NewPostActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable() && item.isEnabled()) {
        item.setChecked(!item.isChecked());
    }/*from  w  ww  .j a va2 s  .  c  o m*/

    int id = item.getItemId();
    if (id == android.R.id.home) {
        finish();
        return true;
    } else if (id == R.id.post_send) {
        try {
            if (!TextUtils.isEmpty(mText.getText().toString())) {
                new Uploader().execute();
            } else {
                Toast.makeText(this, R.string.empty_weibo, Toast.LENGTH_SHORT).show();
            }
        } catch (Exception e) {

        }
        return true;
    } else if (id == R.id.post_pic) {
        if (mBitmap == null) {
            showPicturePicker();
        } else {
            setPicture(null);
        }
        return true;
    } else if (id == R.id.post_emoticon) {
        if (mDrawer.isDrawerOpen(Gravity.END)) {
            mDrawer.closeDrawer(Gravity.END);
        } else {
            mDrawer.openDrawer(Gravity.END);
        }
        return true;
    } else if (id == R.id.post_at) {
        AtUserSuggestDialog diag = new AtUserSuggestDialog(this);
        diag.setListener(new AtUserSuggestDialog.AtUserListener() {
            @Override
            public void onChooseUser(String name) {
                mText.getText().insert(mText.getSelectionStart(), " @" + name + " ");
            }
        });
        diag.show();
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable())
        item.setChecked(!item.isChecked());
    switch (item.getItemId()) {
    case R.id.menu_toggle_legend:
        mChart.getLegend().setEnabled(!mChart.getLegend().isEnabled());
        mChart.invalidate();//www .j  a v  a  2 s  .c o  m
        return true;

    case R.id.menu_toggle_average_lines:
        if (mChart.getAxisLeft().getLimitLines().isEmpty()) {
            for (LineDataSet set : mChart.getData().getDataSets()) {
                LimitLine line = new LimitLine(set.getYValueSum() / set.getEntryCount(), set.getLabel());
                line.enableDashedLine(10, 5, 0);
                line.setLineColor(set.getColor());
                mChart.getAxisLeft().addLimitLine(line);
            }
        } else {
            mChart.getAxisLeft().removeAllLimitLines();
        }
        mChart.invalidate();
        return true;

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

From source file:org.sufficientlysecure.keychain.ui.EncryptFileActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable()) {
        item.setChecked(!item.isChecked());
    }/*from w w  w.  ja v a2  s.co m*/
    switch (item.getItemId()) {
    case R.id.check_use_symmetric:
        mCurrentMode = item.isChecked() ? MODE_SYMMETRIC : MODE_ASYMMETRIC;
        updateModeFragment();
        notifyUpdate();
        break;
    case R.id.check_use_armor:
        mUseArmor = item.isChecked();
        notifyUpdate();
        break;
    case R.id.check_delete_after_encrypt:
        mDeleteAfterEncrypt = item.isChecked();
        notifyUpdate();
        break;
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable())
        item.setChecked(!item.isChecked());
    switch (item.getItemId()) {
    case R.id.menu_toggle_legend:
        Legend legend = mChart.getLegend();
        if (!legend.isLegendCustom()) {
            Toast.makeText(getActivity(), R.string.toast_legend_too_long, Toast.LENGTH_LONG).show();
        } else {// w  ww  . j  a  v  a 2 s  . c om
            legend.setEnabled(!mChart.getLegend().isEnabled());
            mChart.invalidate();
        }
        return true;

    case R.id.menu_percentage_mode:
        mTotalPercentageMode = !mTotalPercentageMode;
        int msgId = mTotalPercentageMode ? R.string.toast_chart_percentage_mode_total
                : R.string.toast_chart_percentage_mode_current_bar;
        Toast.makeText(getActivity(), msgId, Toast.LENGTH_LONG).show();
        return true;

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

From source file:uk.ac.horizon.artcodes.activity.NavigationActivity.java

@Override
public boolean onNavigationItemSelected(final MenuItem menuItem) {
    if (menuItem != null) {
        if (menuItem.isCheckable()) {
            if (selected != null) {
                selected.setChecked(false);
            }//from  www. j  a v  a2  s . c  om

            selected = menuItem;
            menuItem.setChecked(true);
        }
        drawerActionHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                navigate(menuItem, true);
            }
        }, DRAWER_CLOSE_DELAY_MS);
    }

    binding.drawer.closeDrawer(GravityCompat.START);
    return true;
}

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

@NonNull
@Override//from   w w w .  ja  v a  2  s . co m
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    final Context context = builder.getContext();
    final ParcelableStatus status = getStatus();
    assert status != null;
    final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(getContext(),
            status.account_key);
    assert credentials != null;

    builder.setView(R.layout.dialog_status_quote_retweet);
    builder.setTitle(R.string.retweet_quote_confirm_title);
    builder.setPositiveButton(R.string.retweet, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.setNeutralButton(R.string.quote, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final Intent intent = new Intent(INTENT_ACTION_QUOTE);
            final Menu menu = mPopupMenu.getMenu();
            final MenuItem quoteOriginalStatus = menu.findItem(R.id.quote_original_status);
            intent.putExtra(EXTRA_STATUS, status);
            intent.putExtra(EXTRA_QUOTE_ORIGINAL_STATUS, quoteOriginalStatus.isChecked());
            startActivity(intent);
        }
    });

    final Dialog dialog = builder.create();
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialogInterface) {
            final AlertDialog dialog = (AlertDialog) dialogInterface;

            final View itemContent = dialog.findViewById(R.id.item_content);
            final StatusTextCountView textCountView = (StatusTextCountView) dialog
                    .findViewById(R.id.comment_text_count);
            final View itemMenu = dialog.findViewById(R.id.item_menu);
            final View actionButtons = dialog.findViewById(R.id.action_buttons);
            final View commentContainer = dialog.findViewById(R.id.comment_container);
            final ComposeEditText editComment = (ComposeEditText) dialog.findViewById(R.id.edit_comment);
            final View commentMenu = dialog.findViewById(R.id.comment_menu);
            assert itemContent != null && textCountView != null && itemMenu != null && actionButtons != null
                    && commentContainer != null && editComment != null && commentMenu != null;

            final DummyItemAdapter adapter = new DummyItemAdapter(context);
            adapter.setShouldShowAccountsColor(true);
            final IStatusViewHolder holder = new StatusViewHolder(adapter, itemContent);
            holder.displayStatus(status, false, true);

            textCountView.setMaxLength(TwidereValidator.getTextLimit(credentials));

            itemMenu.setVisibility(View.GONE);
            actionButtons.setVisibility(View.GONE);
            itemContent.setFocusable(false);
            final boolean useQuote = useQuote(!status.user_is_protected, credentials);

            commentContainer.setVisibility(useQuote ? View.VISIBLE : View.GONE);
            editComment.setAccountKey(status.account_key);

            final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND);
            final EditTextEnterHandler enterHandler = EditTextEnterHandler.attach(editComment,
                    new EditTextEnterHandler.EnterListener() {
                        @Override
                        public boolean shouldCallListener() {
                            return true;
                        }

                        @Override
                        public boolean onHitEnter() {
                            final ParcelableStatus status = getStatus();
                            if (status == null)
                                return false;
                            if (retweetOrQuote(credentials, status, SHOW_PROTECTED_CONFIRM)) {
                                dismiss();
                                return true;
                            }
                            return false;
                        }
                    }, 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) {
                    updateTextCount(getDialog(), s, status, credentials);
                }

                @Override
                public void afterTextChanged(Editable s) {

                }
            });

            mPopupMenu = new PopupMenu(context, commentMenu, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle,
                    0);
            commentMenu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mPopupMenu.show();
                }
            });
            commentMenu.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 != null || status.quoted_id != null);
            mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    if (item.isCheckable()) {
                        item.setChecked(!item.isChecked());
                        return true;
                    }
                    return false;
                }
            });

            dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    boolean dismissDialog = false;
                    if (editComment.length() > 0) {
                        dismissDialog = retweetOrQuote(credentials, status, SHOW_PROTECTED_CONFIRM);
                    } else if (isMyRetweet(status)) {
                        mTwitterWrapper.cancelRetweetAsync(status.account_key, status.id, status.my_retweet_id);
                        dismissDialog = true;
                    } else if (useQuote(!status.user_is_protected, credentials)) {
                        dismissDialog = retweetOrQuote(credentials, status, SHOW_PROTECTED_CONFIRM);
                    } else {
                        TwidereBugReporter.logException(new IllegalStateException(status.toString()));
                    }
                    if (dismissDialog) {
                        dismiss();
                    }
                }
            });

            updateTextCount(dialog, editComment.getText(), status, credentials);
        }
    });
    return dialog;
}

From source file:info.papdt.blacklight.ui.statuses.NewPostActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable() && item.isEnabled()) {
        item.setChecked(!item.isChecked());
    }/*from   www.j  a  v a  2s.  c o  m*/

    int id = item.getItemId();
    if (id == android.R.id.home) {
        finish();
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_refresh_stats:
        Intent mUpdateService = new Intent(getActivity(), UpdateService.class);
        mUpdateService.putExtra(Consts.ARG_UPDATE_KUSSS_COURSES, true);
        mUpdateService.putExtra(Consts.ARG_UPDATE_KUSSS_ASSESSMENTS, true);
        getActivity().startService(mUpdateService);

        return true;
    case R.id.action_toggle_grades:
        item.setChecked(item.isCheckable() && !item.isChecked());
        PreferenceWrapper.setPrefPositiveGradesOnly(getContext(), item.isChecked());
        return true;
    default://from  www.j  ava 2s  .  co m
        return super.onOptionsItemSelected(item);
    }
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_refresh_lvas:
        Intent mUpdateService = new Intent(getActivity(), UpdateService.class);
        mUpdateService.putExtra(Consts.ARG_UPDATE_KUSSS_COURSES, true);
        mUpdateService.putExtra(Consts.ARG_UPDATE_KUSSS_ASSESSMENTS, true);
        getActivity().startService(mUpdateService);

        return true;
    case R.id.action_toggle_visible_lvas:
        item.setChecked(item.isCheckable() && !item.isChecked());
        PreferenceWrapper.setShowCoursesWithAssessmentOnly(getContext(), item.isChecked());
        return true;
    default://from  ww  w .j a v  a2s. c  om
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.github.rubensousa.navigationmanager.NavigationManager.java

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    if (mNavigationListener != null) {
        mNavigationListener.onItemSelected(item);
    }//www  .ja v  a 2s  .c om

    closeDrawer();
    boolean firstStart = mCurrentId == 0;

    if (item.getItemId() == mCurrentId) {
        mNavigating = false;
        return false;
    }

    mCurrentId = item.getItemId();
    mTitle = item.getTitle().toString();

    // If an item is checkable, then a fragment should be used
    if (item.isCheckable()) {
        mNavigationView.setCheckedItem(mCurrentId);

        if (mNavigationListener != null && mCurrentFragment != null) {
            mNavigationListener.onSectionChange(mCurrentFragment);
        }

        mCurrentFragment = createFragment(item.getItemId());

        // Check if we have an Intent to pass to the fragment
        if (mIntent != null) {
            Bundle args = mCurrentFragment.getArguments();
            Bundle extras = mIntent.getExtras();

            // If no arguments were passed to the fragment, the bundle must be created
            if (args == null) {
                args = new Bundle();
            }

            // Add the fragment's arguments to the new Intent
            if (extras != null) {
                args.putAll(extras);
            }

            mCurrentFragment.setArguments(args);
            mIntent = null;
        }

        if (!shouldDelayTransaction(mCurrentId) || firstStart || mNavigating) {
            commitFragmentTransaction(createFragmentTransaction(mCurrentFragment));
        } else {
            mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            mFragmentTransaction = createFragmentTransaction(mCurrentFragment);
        }
        mNavigating = false;
        return true;
    }

    mNavigating = false;
    return false;
}