Example usage for android.view MenuItem isChecked

List of usage examples for android.view MenuItem isChecked

Introduction

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

Prototype

public boolean isChecked();

Source Link

Document

Return whether the item is currently displaying a check mark.

Usage

From source file:com.chummy.jezebel.material.dark.activities.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);

    switch (item.getItemId()) {
    case R.id.share:
        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        String shareBody = "Check out " + getResources().getString(R.string.theme_name) + " by "
                + getResources().getString(R.string.nicholas_short) + "!\n\nDownload it here!: "
                + getResources().getString(R.string.play_store_link);
        sharingIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
        startActivity(Intent.createChooser(sharingIntent, (getResources().getString(R.string.share_title))));
        break;/* ww  w  . ja v  a  2s .com*/

    case R.id.sendemail:
        StringBuilder emailBuilder = new StringBuilder();
        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("mailto:" + getResources().getString(R.string.email_id)));
        if (!isAppInstalled("org.cyanogenmod.theme.chooser")) {
            if (!isAppInstalled("com.cyngn.theme.chooser")) {
                if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) {
                    intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject));
                } else {
                    intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_rro));
                }
            } else {
                intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_cos));
            }
        } else {
            intent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.email_subject_cm));
        }
        emailBuilder.append("\n \n \nOS Version: " + System.getProperty("os.version") + "("
                + Build.VERSION.INCREMENTAL + ")");
        emailBuilder.append("\nOS API Level: " + Build.VERSION.SDK_INT + " (" + Build.VERSION.RELEASE + ") "
                + "[" + Build.ID + "]");
        emailBuilder.append("\nDevice: " + Build.DEVICE);
        emailBuilder.append("\nManufacturer: " + Build.MANUFACTURER);
        emailBuilder.append("\nModel (and Product): " + Build.MODEL + " (" + Build.PRODUCT + ")");
        if (!isAppInstalled("org.cyanogenmod.theme.chooser")) {
            if (!isAppInstalled("com.cyngn.theme.chooser")) {
                if (!isAppInstalled("com.lovejoy777.rroandlayersmanager")) {
                    emailBuilder.append("\nTheme Engine: Not Available");
                } else {
                    emailBuilder.append("\nTheme Engine: Layers Manager (RRO)");
                }
            } else {
                emailBuilder.append("\nTheme Engine: Cyanogen OS Theme Engine");
            }
        } else {
            emailBuilder.append("\nTheme Engine: CyanogenMod Theme Engine");
        }
        PackageInfo appInfo = null;
        try {
            appInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        emailBuilder.append("\nApp Version Name: " + appInfo.versionName);
        emailBuilder.append("\nApp Version Code: " + appInfo.versionCode);

        intent.putExtra(Intent.EXTRA_TEXT, emailBuilder.toString());
        startActivity(Intent.createChooser(intent, (getResources().getString(R.string.send_title))));
        break;

    case R.id.changelog:
        changelog();
        break;

    case R.id.hide_launcher:
        boolean checked = item.isChecked();
        if (!checked) {
            new MaterialDialog.Builder(this).title(R.string.warning).content(R.string.hide_action)
                    .positiveText(R.string.nice).show();
        }
        item.setChecked(!checked);
        setLauncherIconEnabled(checked);
        return true;

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

From source file:org.mozilla.gecko.BrowserApp.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Tab tab = null;/*from  ww  w.  j a va 2 s .c  o  m*/
    Intent intent = null;

    final int itemId = item.getItemId();

    // Track the menu action. We don't know much about the context, but we can use this to determine
    // the frequency of use for various actions.
    Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.MENU,
            getResources().getResourceEntryName(itemId));

    mBrowserToolbar.cancelEdit();

    if (itemId == R.id.bookmark) {
        tab = Tabs.getInstance().getSelectedTab();
        if (tab != null) {
            if (item.isChecked()) {
                Telemetry.sendUIEvent(TelemetryContract.Event.UNSAVE, TelemetryContract.Method.MENU,
                        "bookmark");
                tab.removeBookmark();
                item.setIcon(resolveBookmarkIconID(false));
                item.setTitle(resolveBookmarkTitleID(false));
            } else {
                Telemetry.sendUIEvent(TelemetryContract.Event.SAVE, TelemetryContract.Method.MENU, "bookmark");
                tab.addBookmark();
                item.setIcon(resolveBookmarkIconID(true));
                item.setTitle(resolveBookmarkTitleID(true));
            }
        }
        return true;
    }

    if (itemId == R.id.reading_list) {
        tab = Tabs.getInstance().getSelectedTab();
        if (tab != null) {
            if (item.isChecked()) {
                Telemetry.sendUIEvent(TelemetryContract.Event.UNSAVE, TelemetryContract.Method.MENU,
                        "reading_list");
                tab.removeFromReadingList();
                item.setIcon(resolveReadingListIconID(false));
                item.setTitle(resolveReadingListTitleID(false));
            } else {
                Telemetry.sendUIEvent(TelemetryContract.Event.SAVE, TelemetryContract.Method.MENU,
                        "reading_list");
                tab.addToReadingList();
                item.setIcon(resolveReadingListIconID(true));
                item.setTitle(resolveReadingListTitleID(true));
            }
        }
        return true;
    }

    if (itemId == R.id.share) {
        shareCurrentUrl();
        return true;
    }

    if (itemId == R.id.reload) {
        tab = Tabs.getInstance().getSelectedTab();
        if (tab != null)
            tab.doReload();
        return true;
    }

    if (itemId == R.id.back) {
        tab = Tabs.getInstance().getSelectedTab();
        if (tab != null)
            tab.doBack();
        return true;
    }

    if (itemId == R.id.forward) {
        tab = Tabs.getInstance().getSelectedTab();
        if (tab != null)
            tab.doForward();
        return true;
    }

    if (itemId == R.id.save_as_pdf) {
        GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SaveAs:PDF", null));
        return true;
    }

    if (itemId == R.id.settings) {
        intent = new Intent(this, GeckoPreferences.class);

        // We want to know when the Settings activity returns, because
        // we might need to redisplay based on a locale change.
        startActivityForResult(intent, ACTIVITY_REQUEST_PREFERENCES);
        return true;
    }

    if (itemId == R.id.help) {
        final String VERSION = AppConstants.MOZ_APP_VERSION;
        final String OS = AppConstants.OS_TARGET;
        final String LOCALE = Locales.getLanguageTag(Locale.getDefault());

        final String URL = getResources().getString(R.string.help_link, VERSION, OS, LOCALE);
        Tabs.getInstance().loadUrlInTab(URL);
        return true;
    }

    if (itemId == R.id.addons) {
        Tabs.getInstance().loadUrlInTab(AboutPages.ADDONS);
        return true;
    }

    if (itemId == R.id.logins) {
        Tabs.getInstance().loadUrlInTab(AboutPages.LOGINS);
        return true;
    }

    if (itemId == R.id.downloads) {
        Tabs.getInstance().loadUrlInTab(AboutPages.DOWNLOADS);
        return true;
    }

    if (itemId == R.id.char_encoding) {
        GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Get", null));
        return true;
    }

    if (itemId == R.id.find_in_page) {
        mFindInPageBar.show();
        return true;
    }

    if (itemId == R.id.desktop_mode) {
        Tab selectedTab = Tabs.getInstance().getSelectedTab();
        if (selectedTab == null)
            return true;
        JSONObject args = new JSONObject();
        try {
            args.put("desktopMode", !item.isChecked());
            args.put("tabId", selectedTab.getId());
        } catch (JSONException e) {
            Log.e(LOGTAG, "error building json arguments", e);
        }
        GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("DesktopMode:Change", args.toString()));
        return true;
    }

    if (itemId == R.id.new_tab) {
        addTab();
        return true;
    }

    if (itemId == R.id.new_private_tab) {
        addPrivateTab();
        return true;
    }

    if (itemId == R.id.new_guest_session) {
        showGuestModeDialog(GuestModeDialog.ENTERING);
        return true;
    }

    if (itemId == R.id.exit_guest_session) {
        showGuestModeDialog(GuestModeDialog.LEAVING);
        return true;
    }

    // We have a few menu items that can also be in the context menu. If
    // we have not already handled the item, give the context menu handler
    // a chance.
    if (onContextItemSelected(item)) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:net.etuldan.sparss.fragment.EntryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mEntriesIds != null) {
        final Activity activity = getActivity();

        switch (item.getItemId()) {
        case R.id.menu_star: {
            mFavorite = !mFavorite;/*  ww w  .j  av a2  s .  c o  m*/

            if (mFavorite) {
                item.setTitle(R.string.menu_unstar).setIcon(R.drawable.ic_star);
            } else {
                item.setTitle(R.string.menu_star).setIcon(R.drawable.ic_star_border);
            }

            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentValues values = new ContentValues();
                    values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0);
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, values, null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }.start();
            break;
        }
        case R.id.menu_share: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            if (cursor != null) {
                String link = cursor.getString(mLinkPos);
                if (link != null) {
                    String title = cursor.getString(mTitlePos);
                    startActivity(Intent.createChooser(
                            new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title)
                                    .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN),
                            getString(R.string.menu_share)));
                }
            }
            break;
        }
        case R.id.menu_full_screen: {
            setImmersiveFullScreen(true);
            break;
        }
        case R.id.menu_copy_clipboard: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            ClipboardManager clipboard = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Copied Text", link);
            clipboard.setPrimaryClip(clip);

            Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show();
            break;
        }
        case R.id.menu_mark_as_unread: {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getUnreadContentValues(), null, null);
                }
            }.start();
            activity.finish();
            break;
        }
        case R.id.menu_open_in_browser: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            if (cursor != null) {
                String link = cursor.getString(mLinkPos);
                if (link != null) {
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
                    startActivity(browserIntent);
                }
            }
            break;
        }
        case R.id.menu_switch_full_original: {
            isChecked = !item.isChecked();
            item.setChecked(isChecked);
            if (mPreferFullText) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mPreferFullText = false;
                        mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true);
                    }
                });
            } else {
                Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
                final boolean alreadyMobilized = !cursor.isNull(mMobilizedHtmlPos);

                if (alreadyMobilized) {
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mPreferFullText = true;
                            mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true);
                        }
                    });
                } else if (!isRefreshing()) {
                    ConnectivityManager connectivityManager = (ConnectivityManager) activity
                            .getSystemService(Context.CONNECTIVITY_SERVICE);
                    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

                    // since we have acquired the networkInfo, we use it for basic checks
                    if (networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED) {
                        FetcherService.addEntriesToMobilize(new long[] { mEntriesIds[mCurrentPagerPos] });
                        activity.startService(new Intent(activity, FetcherService.class)
                                .setAction(FetcherService.ACTION_MOBILIZE_FEEDS));
                        activity.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                showSwipeProgress();
                            }
                        });
                    } else {
                        activity.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(activity, R.string.network_error, Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                }
            }
            break;
        }
        default:
            break;
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:org.de.jmg.learn.MainActivity.java

@Override
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.

    try {//from  w  w  w  .  j  av  a 2 s  .c  o  m
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            mPager.setCurrentItem(SettingsActivity.fragID);
        } else if (id == R.id.mnuCredits) {
            InputStream is = this.getAssets().open("CREDITS");
            java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
            String strCredits = s.hasNext() ? s.next() : "";
            s.close();
            is.close();
            String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(),
                    0).versionName;
            Spannable spn = lib.getSpanableString(strCredits + "\nV" + versionName);
            lib.ShowMessage(this, spn, "Credits");
        } else if (id == R.id.mnuContact) {
            Intent intent = new Intent(Intent.ACTION_SEND,
                    Uri.fromParts("mailto", "jhmgbl2@t-online.de", null));
            intent.setType("message/rfc822");
            intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "jhmgbl2@t-online.de" });
            String versionName = context.getPackageManager().getPackageInfo(context.getPackageName(),
                    0).versionName;
            intent.putExtra(Intent.EXTRA_SUBJECT, "learnforandroid " + versionName);
            intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.ConvertVok));
            this.startActivity(Intent.createChooser(intent, getString(R.string.SendMail)));
        } else if (id == R.id.mnuFileOpen) {
            mPager.setCurrentItem(fragFileChooser.fragID);
            //LoadFile(true);
        } else if (id == R.id.mnuHome) {
            mPager.setCurrentItem(_MainActivity.fragID);
        } else if (id == R.id.mnuOpenQuizlet) {
            //LoginQuizlet();
            if (mPager.getCurrentItem() != fragFileChooserQuizlet.fragID) {
                mPager.setCurrentItem(fragFileChooserQuizlet.fragID);
            } else {
                if (fPA != null && fPA.fragQuizlet != null) {
                    searchQuizlet();
                }
            }
        } else if (id == R.id.mnuUploadToQuizlet) {
            uploadtoQuizlet();

        } else if (id == R.id.mnuAskReverse) {
            item.setChecked(!item.isChecked());
            vok.reverse = item.isChecked();
            setMnuReverse();
        } else if (id == R.id.mnuOpenUri) {
            if (saveVok(false)) {
                String defaultURI = prefs.getString("defaultURI", "");
                Uri def;
                if (libString.IsNullOrEmpty(defaultURI)) {
                    File F = new File(JMGDataDirectory);
                    def = Uri.fromFile(F);
                } else {
                    def = Uri.parse(defaultURI);
                }
                lib.SelectFile(this, def);
            }
        } else if (id == R.id.mnuNew) {
            newVok();

        } else if (id == R.id.mnuAddWord) {
            mPager.setCurrentItem(_MainActivity.fragID);
            if (fPA.fragMain != null && fPA.fragMain.mainView != null) {
                if (fPA.fragMain.EndEdit(false)) {
                    vok.AddVokabel();
                    fPA.fragMain.getVokabel(true, false, true);
                    fPA.fragMain.StartEdit();
                }
            }

        } else if (id == R.id.mnuFileOpenASCII) {
            LoadFile(false);
        } else if (id == R.id.mnuConvMulti) {
            if (fPA.fragMain != null && fPA.fragMain.mainView != null) {
                vok.ConvertMulti();
                fPA.fragMain.getVokabel(false, false);
            }
        } else if (id == R.id.mnuFileSave) {
            saveVok(false);
        } else if (id == R.id.mnuSaveAs) {
            SaveVokAs(true, false);
        } else if (id == R.id.mnuRestart) {
            vok.restart();
        } else if (id == R.id.mnuDelete) {
            if (fPA.fragMain != null && fPA.fragMain.mainView != null) {
                vok.DeleteVokabel();
                fPA.fragMain.EndEdit2();
            }
        } else if (id == R.id.mnuReverse) {
            if (fPA.fragMain != null && fPA.fragMain.mainView != null) {
                vok.revert();
                fPA.fragMain.getVokabel(false, false);
            }
        } else if (id == R.id.mnuReset) {
            if (lib.ShowMessageYesNo(this, this.getString(R.string.ResetVocabulary),
                    "") == yesnoundefined.yes) {
                vok.reset();
            }

        } else if (id == R.id.mnuStatistics) {
            if (vok.getGesamtzahl() > 5) {
                try {
                    /*
                    IDemoChart chart = new org.de.jmg.learn.chart.LearnBarChart();
                    int UIMode = lib.getUIMode(this);
                            
                    switch (UIMode)
                    {
                    case Configuration.UI_MODE_TYPE_TELEVISION:
                    isTV = true;
                    break;
                    case Configuration.UI_MODE_TYPE_WATCH:
                    isWatch = true;
                    break;
                    }
                    Intent intent = chart.execute(this);
                    this.startActivity(intent);
                    */
                    mPager.setCurrentItem(fragStatistics.fragID);
                } catch (Exception ex) {
                    lib.ShowException(this, ex);
                }

            }
        } else if (id == R.id.mnuEdit) {
            if (fPA.fragMain != null && fPA.fragMain.mainView != null) {
                fPA.fragMain.edit();
            }
        } else if (id == R.id.mnuLoginQuizlet) {
            LoginQuizlet(false);
        }

    } catch (Throwable ex) {
        lib.ShowException(this, ex);
    }

    return super.onOptionsItemSelected(item);
}

From source file:it.iziozi.iziozi.gui.IOBoardActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.action_settings: {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        LayoutInflater inflater = getLayoutInflater();

        View layoutView = inflater.inflate(R.layout.settings_layout, null);

        Integer rows = mActualLevel.getBoardAtIndex(mActualIndex).getRows();
        Integer columns = mActualLevel.getBoardAtIndex(mActualIndex).getCols();

        final CheckBox bordersCheckbox = (CheckBox) layoutView.findViewById(R.id.bordersCheckbox);

        bordersCheckbox.setChecked(mActiveConfig.getShowBorders());

        builder.setTitle(getResources().getString(R.string.settings)).setView(layoutView).setPositiveButton(
                getResources().getString(R.string.apply), new DialogInterface.OnClickListener() {
                    @Override/*from w w  w.j av  a2  s  . c  o m*/
                    public void onClick(DialogInterface dialog, int which) {

                        if (newCols == 0)
                            newCols++;
                        if (newRows == 0)
                            newRows++;

                        mActualLevel.getBoardAtIndex(mActualIndex).setCols(newCols);
                        mActualLevel.getBoardAtIndex(mActualIndex).setRows(newRows);

                        IOBoardActivity.this.mActiveConfig.setShowBorders(bordersCheckbox.isChecked());

                        //TODO:createView();
                        refreshView();
                    }
                }).setNegativeButton(getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                Log.d("dialog", "dismiss and discard");
                            }
                        });

        SeekBar sRows = (SeekBar) layoutView.findViewById(R.id.seekRows);
        SeekBar sCols = (SeekBar) layoutView.findViewById(R.id.seekCols);

        final TextView rowsLbl = (TextView) layoutView.findViewById(R.id.numRowsLbl);
        final TextView colsLbl = (TextView) layoutView.findViewById(R.id.numColsLbl);

        sRows.setProgress(rows);
        sCols.setProgress(columns);

        newRows = rows;
        newCols = columns;

        rowsLbl.setText("" + rows);
        colsLbl.setText("" + columns);

        sRows.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                if (seekBar.getProgress() == 0)
                    seekBar.setProgress(1);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                Log.d("seeking", "seek rows " + progress);
                newRows = progress;
                rowsLbl.setText("" + progress);
            }
        });

        sCols.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                if (seekBar.getProgress() == 0)
                    seekBar.setProgress(1);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                Log.d("seeking", "seek cols " + progress);
                newCols = progress;
                colsLbl.setText("" + progress);
            }
        });

        builder.create().show();
        break;
    }
    case R.id.editMode: {
        Log.d("options menu", "edit mode selected");
        item.setChecked(!item.isChecked());
        toggleEditing();

        break;
    }

    case R.id.scanMode: {
        Log.d("options menu", "scan mode selected");
        item.setChecked(!item.isChecked());
        IOGlobalConfiguration.isScanMode = item.isChecked();

        if (IOGlobalConfiguration.isScanMode)
            startScanMode();
        else
            stopScanMode();

        break;
    }

    case R.id.action_new: {

        new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.warning))
                .setMessage(getString(R.string.new_board_alert))
                .setPositiveButton(getResources().getString(R.string.yes),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                FragmentManager fm = getSupportFragmentManager();
                                while (fm.getBackStackEntryCount() > 0)
                                    fm.popBackStackImmediate();

                                mActiveConfig = new IOConfiguration();
                                fm.beginTransaction()
                                        .replace(mFrameLayout.getId(),
                                                IOPaginatedBoardFragment.newInstance(mActiveConfig.getLevel()))
                                        .commit();

                                if (!IOGlobalConfiguration.isEditing)
                                    toggleEditing();

                            }
                        })
                .setNegativeButton(getResources().getString(R.string.cancel), null).setCancelable(false)
                .create().show();

        break;
    }

    case R.id.action_save: {
        if (null == mActualConfigName)
            IOBoardActivity.this.mActiveConfig.save();
        else
            IOBoardActivity.this.mActiveConfig.saveAs(mActualConfigName);
        break;
    }

    case R.id.action_save_as: {

        final AlertDialog.Builder alert = new AlertDialog.Builder(this);

        View contentView = getLayoutInflater().inflate(R.layout.rename_alert_layout, null);

        final EditText inputText = (EditText) contentView.findViewById(R.id.newNameEditText);

        alert.setView(contentView);
        alert.setPositiveButton(getString(R.string.confirm), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

                String value = inputText.getText().toString().trim();

                if (value.indexOf(".xml") != -1)
                    value = value.replace(".xml", "");

                File dirFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),
                        IOApplication.APPLICATION_NAME + "/boards");
                File file = new File(dirFile.toString(), value + ".xml");

                if (file.exists()) {
                    dialog.cancel();

                    new AlertDialog.Builder(IOBoardActivity.this).setTitle(getString(R.string.warning))
                            .setMessage(getString(R.string.file_already_exists))
                            .setPositiveButton(getString(R.string.continue_string), null).create().show();

                } else {
                    IOBoardActivity.this.mActiveConfig.saveAs(value);
                    mActualConfigName = value;
                }
            }
        });

        alert.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.cancel();
            }
        });
        alert.show();

        break;
    }

    case R.id.action_load: {

        File dirFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath(),
                IOApplication.APPLICATION_NAME + "/boards");
        if (!dirFile.exists())
            dirFile.mkdirs();

        final String[] configFiles = dirFile.list(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String filename) {

                if (filename.indexOf(".xml") != -1)
                    return true;

                return false;
            }
        });

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item);

        adapter.addAll(configFiles);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getResources().getString(R.string.choose))
                .setAdapter(adapter, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Log.d("media_debug", "click on item " + which);

                        String fileName = configFiles[which];
                        Log.d("board_debug", fileName);

                        FragmentManager fm = getSupportFragmentManager();
                        while (fm.getBackStackEntryCount() > 0)
                            fm.popBackStackImmediate();

                        mActiveConfig = IOConfiguration.getSavedConfiguration(fileName);

                        fm.beginTransaction()
                                .replace(mFrameLayout.getId(),
                                        IOPaginatedBoardFragment.newInstance(mActiveConfig.getLevel()))
                                .commit();

                    }
                }).setNegativeButton(getResources().getString(R.string.cancel), null).create().show();

        break;
    }

    case R.id.action_about: {
        Intent aboutIntent = new Intent(getApplicationContext(), IOAboutActivity.class);
        startActivity(aboutIntent);
        break;
    }

    case R.id.action_exit: {
        finish();
        break;
    }

    case R.id.action_lock: {
        if (IOGlobalConfiguration.isEditing)
            toggleEditing();
        lockUI();
        break;
    }

    default:
        break;

    }

    return super.onOptionsItemSelected(item);
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (DEBUG)/*from  ww w  .j  a v a2  s. co m*/
        Logger.LogDebug("OpenExplorer.onOptionsItemSelected(" + item + ")");
    if (item.getItemId() == R.id.menu_more && isGTV()) {
        showMenu(mOptsMenu, findViewById(item.getItemId()), false);
        return true;
    }

    if (item.getSubMenu() != null) {
        onPrepareOptionsMenu(item.getSubMenu());
        if (!USE_PRETTY_MENUS)
            return false;
        else {
            View anchor = findViewById(item.getItemId());
            if (anchor == null && !BEFORE_HONEYCOMB && item.getActionView() != null)
                anchor = item.getActionView();
            if (anchor == null && !BEFORE_HONEYCOMB) {
                anchor = getActionBar().getCustomView();
                if (anchor.findViewById(item.getItemId()) != null)
                    anchor = anchor.findViewById(item.getItemId());
            }
            if (anchor == null)
                anchor = mToolbarButtons;
            if (anchor == null)
                anchor = findViewById(android.R.id.home);
            if (anchor == null && !BEFORE_HONEYCOMB && USE_ACTION_BAR)
                anchor = getActionBar().getCustomView().findViewById(android.R.id.home);
            if (anchor == null)
                anchor = getCurrentFocus().getRootView();
            OpenFragment f = getSelectedFragment();
            if (f != null)
                if (f.onClick(item.getItemId(), anchor))
                    return true;
        }
    }

    if (item.isCheckable())
        item.setChecked(item.getGroupId() > 0 ? true : !item.isChecked());

    OpenFragment f = getSelectedFragment();
    if (f != null && f.onOptionsItemSelected(item))
        return true;

    if (DEBUG)
        Logger.LogDebug("OpenExplorer.onOptionsItemSelected(0x" + Integer.toHexString(item.getItemId()) + ")");

    return onClick(item.getItemId(), item, null);
}

From source file:com.esri.squadleader.view.SquadLeaderActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.add_layer:
        //Present Add Layer from Web dialog
        if (null == addLayerDialogFragment) {
            addLayerDialogFragment = new AddLayerDialogFragment();
            addLayerDialogFragment.setAddLayerFromFileRequestCode(ADD_LAYER_FROM_FILE);
        }//  w  ww .  j a v  a 2s .  c  o m
        addLayerDialogFragment.show(getFragmentManager(), getString(R.string.add_layer_fragment_tag));
        return true;
    case R.id.add_feature:
        // Present Add Feature dialog
        if (null == addFeatureDialogFragment) {
            addFeatureDialogFragment = new AddFeatureDialogFragment();
        }
        addFeatureDialogFragment.show(getFragmentManager(), getString(R.string.add_feature_fragment_tag));
        return true;
    case R.id.clear_messages:
        //Present Clear Messages dialog
        if (null == clearMessagesDialogFragment) {
            clearMessagesDialogFragment = new ClearMessagesDialogFragment();
        }
        clearMessagesDialogFragment.show(getFragmentManager(), getString(R.string.clear_messages_fragment_tag));
        return true;
    case R.id.go_to_mgrs:
        //Present Go to MGRS dialog
        if (null == goToMgrsDialogFragment) {
            goToMgrsDialogFragment = new GoToMgrsDialogFragment();
        }
        goToMgrsDialogFragment.show(getFragmentManager(), getString(R.string.go_to_mgrs_fragment_tag));
        return true;
    case R.id.set_location_mode:
        //Present Set Location Mode dialog
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.set_location_mode).setNegativeButton(R.string.cancel, null)
                .setSingleChoiceItems(
                        new String[] { getString(R.string.option_location_service),
                                getString(R.string.option_simulation_builtin),
                                getString(R.string.option_simulation_file) },
                        mapController.getLocationController().getMode() == LocationMode.LOCATION_SERVICE ? 0
                                : null == mapController.getLocationController().getGpxFile() ? 1 : 2,
                        new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                clearDisplayStrings();
                                try {
                                    if (2 == which) {
                                        //Present file chooser
                                        Intent getContentIntent = FileUtils.createGetContentIntent();
                                        Intent intent = Intent.createChooser(getContentIntent, "Select a file");
                                        startActivityForResult(intent, REQUEST_CHOOSER);
                                    } else {
                                        mapController.getLocationController().setGpxFile(null, true);
                                        mapController.getLocationController()
                                                .setMode(0 == which ? LocationMode.LOCATION_SERVICE
                                                        : LocationMode.SIMULATOR, true);
                                        mapController.getLocationController().start();
                                    }
                                } catch (Exception e) {
                                    Log.d(TAG, "Couldn't set location mode", e);
                                } finally {
                                    dialog.dismiss();
                                }
                            }

                        });
        AlertDialog dialog = builder.create();
        dialog.show();
        return true;
    case R.id.settings:
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivityForResult(intent, SETTINGS_ACTIVITY);
        return true;
    case R.id.toggle_labels:
        item.setChecked(!item.isChecked());
        item.setIcon(item.isChecked() ? R.drawable.ic_action_labels : R.drawable.ic_action_labels_off);
        SharedPreferences prefs = getPreferences(MODE_PRIVATE);
        String key = getString(R.string.pref_labels);
        prefs.edit().putBoolean(key, item.isChecked()).commit();
        if (null != mil2525cController) {
            mil2525cController.setShowLabels(item.isChecked());
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:org.uoyabause.android.YabauseHandler.java

@Override
public boolean onNavigationItemSelected(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.
    int id = item.getItemId();

    switch (id) {
    /*//  www.j  a v a 2 s .  c om
    case R.id.save_screen:{
        DateFormat dateFormat = new SimpleDateFormat("_yyyy_MM_dd_HH_mm_ss");
        Date date = new Date();
            
        String screen_shot_save_path = YabauseStorage.getStorage().getScreenshotPath()
                + YabauseRunnable.getCurrentGameCode() +
                dateFormat.format(date) + ".png";
            
        if (YabauseRunnable.screenshot(screen_shot_save_path) != 0) {
            break;
        }
            
        waiting_reault = true;
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        ContentResolver cr = getContentResolver();
        ContentValues cv = new ContentValues();
        cv.put(MediaStore.Images.Media.TITLE, YabauseRunnable.getCurrentGameCode());
        cv.put(MediaStore.Images.Media.DISPLAY_NAME, YabauseRunnable.getCurrentGameCode());
        cv.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
        cv.put(MediaStore.Images.Media.MIME_TYPE, "image/png");
        cv.put(MediaStore.Images.Media.DATA, screen_shot_save_path);
        Uri uri = cr.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, cv);
        shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
        shareIntent.setType("image/png");
        startActivityForResult(Intent.createChooser(shareIntent, "share screenshot to"), 0x01);
    }
    break;
    */
    case R.id.reset:
        YabauseRunnable.reset();
        break;
    case R.id.report:
        startReport();
        break;
    case R.id.save_state: {
        String save_path = YabauseStorage.getStorage().getStateSavePath();
        String current_gamecode = YabauseRunnable.getCurrentGameCode();
        File save_root = new File(YabauseStorage.getStorage().getStateSavePath(), current_gamecode);
        if (!save_root.exists())
            save_root.mkdir();

        String save_filename = YabauseRunnable.savestate(save_path + current_gamecode);
        if (save_filename != "") {
            int point = save_filename.lastIndexOf(".");
            if (point != -1) {
                save_filename = save_filename.substring(0, point);
            }
            String screen_shot_save_path = save_filename + ".png";
            if (YabauseRunnable.screenshot(screen_shot_save_path) != 0) {
                Snackbar.make(this.mDrawerLayout, "Failed to save the current state", Snackbar.LENGTH_SHORT)
                        .show();
            } else {
                Snackbar.make(this.mDrawerLayout, "Current state is saved as " + save_filename,
                        Snackbar.LENGTH_LONG).show();
            }
        } else {
            Snackbar.make(this.mDrawerLayout, "Failed to save the current state", Snackbar.LENGTH_SHORT).show();
        }

        StateListFragment.checkMaxFileCount(save_path + current_gamecode);

    }
        break;
    case R.id.load_state: {
        //String save_path = YabauseStorage.getStorage().getStateSavePath();
        //YabauseRunnable.loadstate(save_path);
        String basepath;
        String save_path = YabauseStorage.getStorage().getStateSavePath();
        String current_gamecode = YabauseRunnable.getCurrentGameCode();
        basepath = save_path + current_gamecode;
        waiting_reault = true;
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        StateListFragment fragment = new StateListFragment();
        fragment.setBasePath(basepath);
        transaction.replace(R.id.ext_fragment, fragment, StateListFragment.TAG);
        transaction.show(fragment);
        transaction.commit();
    }
        break;
    case R.id.menu_item_backup: {
        waiting_reault = true;
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        TabBackupFragment fragment = TabBackupFragment.newInstance("hoge", "hoge");
        //fragment.setBasePath(basepath);
        transaction.replace(R.id.ext_fragment, fragment, TabBackupFragment.TAG);
        transaction.show(fragment);
        transaction.commit();
    }
        break;
    case R.id.button_open_cd: {
        if (tray_state == 0) {
            YabauseRunnable.openTray();
            item.setTitle(getString(R.string.close_cd_tray));
            tray_state = 1;
        } else {
            item.setTitle(getString(R.string.open_cd_tray));
            tray_state = 0;
            File file = new File(gamepath);
            String path = file.getParent();
            FileDialog fd = new FileDialog(Yabause.this, path);
            fd.addFileListener(Yabause.this);
            fd.showDialog();
        }
    }
        break;
    case R.id.pad_mode: {
        YabausePad padv = (YabausePad) findViewById(R.id.yabause_pad);
        boolean mode = false;
        if (item.isChecked()) {
            item.setChecked(false);
            Yabause.this.padm.setAnalogMode(PadManager.MODE_HAT);
            YabauseRunnable.switch_padmode(PadManager.MODE_HAT);
            padv.setPadMode(PadManager.MODE_HAT);
            mode = false;
        } else {
            item.setChecked(true);
            Yabause.this.padm.setAnalogMode(PadManager.MODE_ANALOG);
            YabauseRunnable.switch_padmode(PadManager.MODE_ANALOG);
            padv.setPadMode(PadManager.MODE_ANALOG);
            mode = true;
        }
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Yabause.this);
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putBoolean("pref_analog_pad", mode);
        editor.apply();
        Yabause.this.showBottomMenu();
    }
        break;
    case R.id.menu_item_cheat: {
        waiting_reault = true;
        CheatEditDialogStandalone newFragment = new CheatEditDialogStandalone();
        newFragment.setGameCode(YabauseRunnable.getCurrentGameCode(), this.cheat_codes);
        newFragment.show(getFragmentManager(), "Cheat");
    }
        break;
    case R.id.exit: {
        YabauseRunnable.deinit();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {

        }
        //android.os.Process.killProcess(android.os.Process.myPid());
        finish();
        android.os.Process.killProcess(android.os.Process.myPid());
    }
        break;
    }
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

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

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUser user = getUser();
    final Relationship relationship = mRelationship;
    if (user == null || twitter == null)
        return false;
    switch (item.getItemId()) {
    case MENU_BLOCK: {
        if (mRelationship != null) {
            if (mRelationship.isSourceBlockingTarget()) {
                twitter.destroyBlockAsync(user.account_id, user.id);
            } else {
                CreateUserBlockDialogFragment.show(getFragmentManager(), user);
            }//  ww w.j  a va2 s. c  o m
        }
        break;
    }
    case MENU_REPORT_SPAM: {
        ReportSpamDialogFragment.show(getFragmentManager(), user);
        break;
    }
    case MENU_ADD_TO_FILTER: {
        final boolean filtering = Utils.isFilteringUser(getActivity(), user.id);
        final ContentResolver cr = getContentResolver();
        if (filtering) {
            final Expression where = Expression.equals(Filters.Users.USER_ID, user.id);
            cr.delete(Filters.Users.CONTENT_URI, where.getSQL(), null);
            Utils.showInfoMessage(getActivity(), R.string.message_user_unmuted, false);
        } else {
            cr.insert(Filters.Users.CONTENT_URI, ContentValuesCreator.createFilteredUser(user));
            Utils.showInfoMessage(getActivity(), R.string.message_user_muted, false);
        }
        break;
    }
    case MENU_MUTE_USER: {
        if (mRelationship != null) {
            if (mRelationship.isSourceMutingTarget()) {
                twitter.destroyMuteAsync(user.account_id, user.id);
            } else {
                CreateUserMuteDialogFragment.show(getFragmentManager(), user);
            }
        }
        break;
    }
    case MENU_MENTION: {
        final Intent intent = new Intent(INTENT_ACTION_MENTION);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_USER, user);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case MENU_SEND_DIRECT_MESSAGE: {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_TWIDERE);
        builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_ID, String.valueOf(user.account_id));
        builder.appendQueryParameter(QUERY_PARAM_USER_ID, String.valueOf(user.id));
        final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
        intent.putExtra(EXTRA_ACCOUNT, ParcelableCredentials.getAccount(getActivity(), user.account_id));
        intent.putExtra(EXTRA_USER, user);
        startActivity(intent);
        break;
    }
    case MENU_SET_COLOR: {
        final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class);
        intent.putExtra(EXTRA_COLOR, mUserColorNameManager.getUserColor(user.id, true));
        intent.putExtra(EXTRA_ALPHA_SLIDER, false);
        intent.putExtra(EXTRA_CLEAR_BUTTON, true);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case MENU_CLEAR_NICKNAME: {
        final UserColorNameManager manager = UserColorNameManager.getInstance(getActivity());
        manager.clearUserNickname(user.id);
        break;
    }
    case MENU_SET_NICKNAME: {
        final String nick = mUserColorNameManager.getUserNickname(user.id, true);
        SetUserNicknameDialogFragment.show(getFragmentManager(), user.id, nick);
        break;
    }
    case MENU_ADD_TO_LIST: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER_LIST);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_ID, user.account_id);
        intent.putExtra(EXTRA_SCREEN_NAME, Utils.getAccountScreenName(getActivity(), user.account_id));
        startActivityForResult(intent, REQUEST_ADD_TO_LIST);
        break;
    }
    case MENU_OPEN_WITH_ACCOUNT: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_ACCOUNT);
        intent.setClass(getActivity(), AccountSelectorActivity.class);
        intent.putExtra(EXTRA_SINGLE_SELECTION, true);
        startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
        break;
    }
    case MENU_FOLLOW: {
        if (relationship == null)
            return false;
        final boolean isFollowing = relationship.isSourceFollowingTarget();
        final boolean isCreatingFriendship = twitter.isCreatingFriendship(user.account_id, user.id);
        final boolean isDestroyingFriendship = twitter.isDestroyingFriendship(user.account_id, user.id);
        if (!isCreatingFriendship && !isDestroyingFriendship) {
            if (isFollowing) {
                DestroyFriendshipDialogFragment.show(getFragmentManager(), user);
            } else {
                twitter.createFriendshipAsync(user.account_id, user.id);
            }
        }
        return true;
    }
    case MENU_ENABLE_RETWEETS: {
        final boolean newState = !item.isChecked();
        final FriendshipUpdate update = new FriendshipUpdate();
        update.retweets(newState);
        twitter.updateFriendship(user.account_id, user.id, update);
        item.setChecked(newState);
        return true;
    }
    case R.id.muted_users: {
        Utils.openMutesUsers(getActivity(), user.account_id);
        return true;
    }
    case R.id.blocked_users: {
        Utils.openUserBlocks(getActivity(), user.account_id);
        return true;
    }
    case R.id.incoming_friendships: {
        Utils.openIncomingFriendships(getActivity(), user.account_id);
        return true;
    }
    case R.id.user_mentions: {
        Utils.openUserMentions(getActivity(), user.account_id, user.screen_name);
        return true;
    }
    case R.id.saved_searches: {
        Utils.openSavedSearches(getActivity(), user.account_id);
        return true;
    }
    default: {
        if (item.getIntent() != null) {
            try {
                startActivity(item.getIntent());
            } catch (final ActivityNotFoundException e) {
                Log.w(LOGTAG, e);
                return false;
            }
        }
        break;
    }
    }
    return true;
}

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

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    final Context context = getContext();
    final AsyncTwitterWrapper twitter = mTwitterWrapper;
    final ParcelableUser user = getUser();
    final UserRelationship userRelationship = mRelationship;
    if (user == null || twitter == null)
        return false;
    switch (item.getItemId()) {
    case R.id.block: {
        if (userRelationship == null)
            return true;
        if (userRelationship.blocking) {
            twitter.destroyBlockAsync(user.account_key, user.key);
        } else {/*  www . j  a  v  a 2 s.c o m*/
            CreateUserBlockDialogFragment.show(getFragmentManager(), user);
        }
        break;
    }
    case R.id.report_spam: {
        ReportSpamDialogFragment.show(getFragmentManager(), user);
        break;
    }
    case R.id.add_to_filter: {
        if (userRelationship == null)
            return true;
        final ContentResolver cr = getContentResolver();
        if (userRelationship.filtering) {
            final String where = Expression.equalsArgs(Filters.Users.USER_KEY).getSQL();
            final String[] whereArgs = { user.key.toString() };
            cr.delete(Filters.Users.CONTENT_URI, where, whereArgs);
            Utils.showInfoMessage(getActivity(), R.string.message_user_unmuted, false);
        } else {
            cr.insert(Filters.Users.CONTENT_URI, ContentValuesCreator.createFilteredUser(user));
            Utils.showInfoMessage(getActivity(), R.string.message_user_muted, false);
        }
        getFriendship();
        break;
    }
    case R.id.mute_user: {
        if (userRelationship == null)
            return true;
        if (userRelationship.muting) {
            twitter.destroyMuteAsync(user.account_key, user.key);
        } else {
            CreateUserMuteDialogFragment.show(getFragmentManager(), user);
        }
        break;
    }
    case R.id.mention: {
        final Intent intent = new Intent(INTENT_ACTION_MENTION);
        final Bundle bundle = new Bundle();
        bundle.putParcelable(EXTRA_USER, user);
        intent.putExtras(bundle);
        startActivity(intent);
        break;
    }
    case R.id.send_direct_message: {
        final Uri.Builder builder = new Uri.Builder();
        builder.scheme(SCHEME_TWIDERE);
        builder.authority(AUTHORITY_DIRECT_MESSAGES_CONVERSATION);
        builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, user.account_key.toString());
        builder.appendQueryParameter(QUERY_PARAM_USER_KEY, user.key.toString());
        final Intent intent = new Intent(Intent.ACTION_VIEW, builder.build());
        intent.putExtra(EXTRA_ACCOUNT,
                ParcelableCredentialsUtils.getCredentials(getActivity(), user.account_key));
        intent.putExtra(EXTRA_USER, user);
        startActivity(intent);
        break;
    }
    case R.id.set_color: {
        final Intent intent = new Intent(getActivity(), ColorPickerDialogActivity.class);
        intent.putExtra(EXTRA_COLOR, mUserColorNameManager.getUserColor(user.key));
        intent.putExtra(EXTRA_ALPHA_SLIDER, false);
        intent.putExtra(EXTRA_CLEAR_BUTTON, true);
        startActivityForResult(intent, REQUEST_SET_COLOR);
        break;
    }
    case R.id.clear_nickname: {
        mUserColorNameManager.clearUserNickname(user.key);
        break;
    }
    case R.id.set_nickname: {
        final String nick = mUserColorNameManager.getUserNickname(user.key);
        SetUserNicknameDialogFragment.show(getFragmentManager(), user.key, nick);
        break;
    }
    case R.id.add_to_list: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_USER_LIST);
        intent.setClass(getActivity(), UserListSelectorActivity.class);
        intent.putExtra(EXTRA_ACCOUNT_KEY, user.account_key);
        intent.putExtra(EXTRA_SCREEN_NAME,
                DataStoreUtils.getAccountScreenName(getActivity(), user.account_key));
        startActivityForResult(intent, REQUEST_ADD_TO_LIST);
        break;
    }
    case R.id.open_with_account: {
        final Intent intent = new Intent(INTENT_ACTION_SELECT_ACCOUNT);
        intent.setClass(getActivity(), AccountSelectorActivity.class);
        intent.putExtra(EXTRA_SINGLE_SELECTION, true);
        intent.putExtra(EXTRA_ACCOUNT_HOST, user.key.getHost());
        startActivityForResult(intent, REQUEST_SELECT_ACCOUNT);
        break;
    }
    case R.id.follow: {
        if (userRelationship == null)
            return true;
        final boolean updatingRelationship = twitter.isUpdatingRelationship(user.account_key, user.key);
        if (!updatingRelationship) {
            if (userRelationship.following) {
                DestroyFriendshipDialogFragment.show(getFragmentManager(), user);
            } else {
                twitter.createFriendshipAsync(user.account_key, user.key);
            }
        }
        return true;
    }
    case R.id.enable_retweets: {
        final boolean newState = !item.isChecked();
        final FriendshipUpdate update = new FriendshipUpdate();
        update.retweets(newState);
        twitter.updateFriendship(user.account_key, user.key.getId(), update);
        item.setChecked(newState);
        return true;
    }
    case R.id.muted_users: {
        IntentUtils.openMutesUsers(getActivity(), user.account_key);
        return true;
    }
    case R.id.blocked_users: {
        IntentUtils.openUserBlocks(getActivity(), user.account_key);
        return true;
    }
    case R.id.incoming_friendships: {
        IntentUtils.openIncomingFriendships(getActivity(), user.account_key);
        return true;
    }
    case R.id.user_mentions: {
        IntentUtils.openUserMentions(context, user.account_key, user.screen_name);
        return true;
    }
    case R.id.saved_searches: {
        IntentUtils.openSavedSearches(context, user.account_key);
        return true;
    }
    case R.id.scheduled_statuses: {
        IntentUtils.openScheduledStatuses(context, user.account_key);
        return true;
    }
    case R.id.open_in_browser: {
        final Uri uri = LinkCreator.getUserWebLink(user);
        final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        intent.setPackage(IntentUtils.getDefaultBrowserPackage(context, uri, true));
        if (intent.resolveActivity(context.getPackageManager()) != null) {
            startActivity(intent);
        }
        return true;
    }
    default: {
        final Intent intent = item.getIntent();
        if (intent != null && intent.resolveActivity(context.getPackageManager()) != null) {
            startActivity(intent);
        }
        break;
    }
    }
    return true;
}