Example usage for android.app AlertDialog.Builder AlertDialog.Builder

List of usage examples for android.app AlertDialog.Builder AlertDialog.Builder

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder AlertDialog.Builder.

Prototype

public Builder(Context context) 

Source Link

Document

Creates a builder for an alert dialog that uses the default alert dialog theme.

Usage

From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java

private void showHighlightEditDialog(final HighLight highLight) {
    final AlertDialog.Builder editalert = new AlertDialog.Builder(context);

    editalert.setTitle(R.string.text_note);
    final EditText input = new EditText(context);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    input.setLayoutParams(lp);/*from   w  ww  . ja  va 2 s  .  c om*/
    editalert.setView(input);
    input.setText(highLight.getTextNote());

    editalert.setPositiveButton(R.string.save_note, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            highLight.setTextNote(input.getText().toString());
            bookView.update();
            highlightManager.saveHighLights();
        }
    });
    editalert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });

    editalert.setNeutralButton(R.string.clear_note, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            highLight.setTextNote(null);
            bookView.update();
            highlightManager.saveHighLights();
        }
    });

    editalert.show();
}

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

public void handleMessage(String event, JSONObject message) {
    Log.i(LOGTAG, "Got message: " + event);
    try {/*from w  w  w  . j a v a  2 s  . co  m*/
        if (event.equals("Menu:Add")) {
            ExtraMenuItem item = new ExtraMenuItem();
            item.label = message.getString("name");
            item.id = message.getInt("id");
            try { // icon is optional
                item.icon = message.getString("icon");
            } catch (Exception ex) {
            }
            sExtraMenuItems.add(item);
        } else if (event.equals("Menu:Remove")) {
            // remove it from the menu and from our vector
            Iterator<ExtraMenuItem> i = sExtraMenuItems.iterator();
            int id = message.getInt("id");
            while (i.hasNext()) {
                ExtraMenuItem item = i.next();
                if (item.id == id) {
                    sExtraMenuItems.remove(item);
                    if (sMenu == null)
                        return;
                    MenuItem menu = sMenu.findItem(id);
                    if (menu != null)
                        sMenu.removeItem(id);
                }
            }
        } else if (event.equals("Toast:Show")) {
            final String msg = message.getString("message");
            final String duration = message.getString("duration");
            handleShowToast(msg, duration);
        } else if (event.equals("DOMContentLoaded")) {
            final int tabId = message.getInt("tabID");
            final String uri = message.getString("uri");
            final String title = message.getString("title");
            handleContentLoaded(tabId, uri, title);
            Log.i(LOGTAG, "URI - " + uri + ", title - " + title);
        } else if (event.equals("DOMTitleChanged")) {
            final int tabId = message.getInt("tabID");
            final String title = message.getString("title");
            handleTitleChanged(tabId, title);
            Log.i(LOGTAG, "title - " + title);
        } else if (event.equals("DOMLinkAdded")) {
            final int tabId = message.getInt("tabID");
            final String rel = message.getString("rel");
            final String href = message.getString("href");
            Log.i(LOGTAG, "link rel - " + rel + ", href - " + href);
            handleLinkAdded(tabId, rel, href);
        } else if (event.equals("DOMWindowClose")) {
            final int tabId = message.getInt("tabID");
            handleWindowClose(tabId);
        } else if (event.equals("log")) {
            // generic log listener
            final String msg = message.getString("msg");
            Log.i(LOGTAG, "Log: " + msg);
        } else if (event.equals("Content:LocationChange")) {
            final int tabId = message.getInt("tabID");
            final String uri = message.getString("uri");
            final String documentURI = message.getString("documentURI");
            final String contentType = message.getString("contentType");
            Log.i(LOGTAG, "URI - " + uri);
            handleLocationChange(tabId, uri, documentURI, contentType);
        } else if (event.equals("Content:SecurityChange")) {
            final int tabId = message.getInt("tabID");
            final String mode = message.getString("mode");
            Log.i(LOGTAG, "Security Mode - " + mode);
            handleSecurityChange(tabId, mode);
        } else if (event.equals("Content:StateChange")) {
            final int tabId = message.getInt("tabID");
            int state = message.getInt("state");
            Log.i(LOGTAG, "State - " + state);
            if ((state & GeckoAppShell.WPL_STATE_IS_NETWORK) != 0) {
                if ((state & GeckoAppShell.WPL_STATE_START) != 0) {
                    Log.i(LOGTAG, "Got a document start");
                    final boolean showProgress = message.getBoolean("showProgress");
                    handleDocumentStart(tabId, showProgress);
                } else if ((state & GeckoAppShell.WPL_STATE_STOP) != 0) {
                    Log.i(LOGTAG, "Got a document stop");
                    handleDocumentStop(tabId);
                }
            }
        } else if (event.equals("Content:LoadError")) {
            final int tabId = message.getInt("tabID");
            final String uri = message.getString("uri");
            final String title = message.getString("title");
            handleLoadError(tabId, uri, title);
        } else if (event.equals("onCameraCapture")) {
            //GeckoApp.mAppContext.doCameraCapture(message.getString("path"));
            doCameraCapture();
        } else if (event.equals("Doorhanger:Add")) {
            handleDoorHanger(message);
        } else if (event.equals("Doorhanger:Remove")) {
            handleDoorHangerRemove(message);
        } else if (event.equals("Gecko:Ready")) {
            sIsGeckoReady = true;
            mMainHandler.post(new Runnable() {
                public void run() {
                    if (sMenu != null)
                        sMenu.findItem(R.id.settings).setEnabled(true);
                }
            });
            setLaunchState(LaunchState.GeckoRunning);
            GeckoAppShell.sendPendingEventsToGecko();
            connectGeckoLayerClient();
        } else if (event.equals("ToggleChrome:Hide")) {
            mMainHandler.post(new Runnable() {
                public void run() {
                    mBrowserToolbar.hide();
                }
            });
        } else if (event.equals("ToggleChrome:Show")) {
            mMainHandler.post(new Runnable() {
                public void run() {
                    mBrowserToolbar.show();
                }
            });
        } else if (event.equals("DOMFullScreen:Start")) {
            mDOMFullScreen = true;
        } else if (event.equals("DOMFullScreen:Stop")) {
            mDOMFullScreen = false;
        } else if (event.equals("FormAssist:AutoComplete")) {
            final JSONArray suggestions = message.getJSONArray("suggestions");
            if (suggestions.length() == 0) {
                mMainHandler.post(new Runnable() {
                    public void run() {
                        mAutoCompletePopup.hide();
                    }
                });
            } else {
                final JSONArray rect = message.getJSONArray("rect");
                final double zoom = message.getDouble("zoom");
                mMainHandler.post(new Runnable() {
                    public void run() {
                        // Don't show autocomplete popup when using fullscreen VKB
                        InputMethodManager imm = (InputMethodManager) getSystemService(
                                Context.INPUT_METHOD_SERVICE);
                        if (!imm.isFullscreenMode())
                            mAutoCompletePopup.show(suggestions, rect, zoom);
                    }
                });
            }
        } else if (event.equals("Permissions:Data")) {
            String host = message.getString("host");
            JSONArray permissions = message.getJSONArray("permissions");
            showSiteSettingsDialog(host, permissions);
        } else if (event.equals("Downloads:Done")) {
            String displayName = message.getString("displayName");
            String path = message.getString("path");
            String mimeType = message.getString("mimeType");
            int size = message.getInt("size");

            handleDownloadDone(displayName, path, mimeType, size);
        } else if (event.equals("CharEncoding:Data")) {
            final JSONArray charsets = message.getJSONArray("charsets");
            int selected = message.getInt("selected");

            final int len = charsets.length();
            final String[] titleArray = new String[len];
            for (int i = 0; i < len; i++) {
                JSONObject charset = charsets.getJSONObject(i);
                titleArray[i] = charset.getString("title");
            }

            final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
            dialogBuilder.setSingleChoiceItems(titleArray, selected, new AlertDialog.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        JSONObject charset = charsets.getJSONObject(which);
                        GeckoAppShell.sendEventToGecko(
                                GeckoEvent.createBroadcastEvent("CharEncoding:Set", charset.getString("code")));
                        dialog.dismiss();
                    } catch (JSONException e) {
                        Log.e(LOGTAG, "error parsing json", e);
                    }
                }
            });
            dialogBuilder.setNegativeButton(R.string.button_cancel, new AlertDialog.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            mMainHandler.post(new Runnable() {
                public void run() {
                    dialogBuilder.show();
                }
            });
        } else if (event.equals("CharEncoding:State")) {
            final boolean visible = message.getString("visible").equals("true");
            GeckoPreferences.setCharEncodingState(visible);
            if (sMenu != null) {
                mMainHandler.post(new Runnable() {
                    public void run() {
                        sMenu.findItem(R.id.char_encoding).setVisible(visible);
                    }
                });
            }
        } else if (event.equals("Update:Restart")) {
            doRestart("org.mozilla.gecko.restart_update");
        } else if (event.equals("Tab:HasTouchListener")) {
            int tabId = message.getInt("tabID");
            Tab tab = Tabs.getInstance().getTab(tabId);
            tab.setHasTouchListeners(true);
            if (Tabs.getInstance().isSelectedTab(tab)) {
                mMainHandler.post(new Runnable() {
                    public void run() {
                        mLayerController.setWaitForTouchListeners(true);
                    }
                });
            }
        } else if (event.equals("Session:StatePurged")) {
            if (mAboutHomeContent != null) {
                mMainHandler.post(new Runnable() {
                    public void run() {
                        mAboutHomeContent.setLastTabsVisibility(false);
                    }
                });
            }
        } else if (event.equals("Bookmark:Insert")) {
            final String url = message.getString("url");
            final String title = message.getString("title");
            mMainHandler.post(new Runnable() {
                public void run() {
                    Toast.makeText(GeckoApp.mAppContext, R.string.bookmark_added, Toast.LENGTH_SHORT).show();
                    GeckoAppShell.getHandler().post(new Runnable() {
                        public void run() {
                            BrowserDB.addBookmark(GeckoApp.mAppContext.getContentResolver(), title, url);
                        }
                    });
                }
            });
        }
    } catch (Exception e) {
        Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
    }
}

From source file:net.nightwhistler.pageturner.fragment.ReadingFragment.java

private void showHighlightEditDialog(final HighLight highLight) {
    final AlertDialog.Builder editalert = new AlertDialog.Builder(context);

    editalert.setTitle(R.string.text_note);
    final EditText input = new EditText(context);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    input.setLayoutParams(lp);/*  w w  w.j  av a  2  s.c om*/
    editalert.setView(input);
    input.setText(highLight.getTextNote());

    editalert.setPositiveButton(R.string.save_note, (dialog, which) -> {
        highLight.setTextNote(input.getText().toString());
        bookView.update();
        highlightManager.saveHighLights();
    });

    editalert.setNegativeButton(android.R.string.cancel, (dialog, which) -> {
    });

    editalert.setNeutralButton(R.string.clear_note, (dialog, which) -> {
        highLight.setTextNote(null);
        bookView.update();
        highlightManager.saveHighLights();
    });

    editalert.show();
}

From source file:com.daiv.android.twitter.ui.drawer_activities.DrawerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    try {/*w  w w  .j  a v a 2 s  . c  o m*/
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
                mDrawerLayout.closeDrawer(Gravity.RIGHT);
            }
            return true;
        }
    } catch (Exception e) {
        // landscape
    }

    switch (item.getItemId()) {
    case R.id.menu_search:
        overridePendingTransition(0, 0);
        finish();
        overridePendingTransition(0, 0);
        return super.onOptionsItemSelected(item);

    case R.id.menu_compose:
        Intent compose = new Intent(context, ComposeActivity.class);
        sharedPrefs.edit().putBoolean("from_notification_bool", false).commit();
        startActivity(compose);
        return super.onOptionsItemSelected(item);

    case R.id.menu_settings:
        context.sendBroadcast(new Intent("com.daiv.android.twitter.MARK_POSITION"));
        finish();
        sharedPrefs.edit().putBoolean("should_refresh", false).commit();
        overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit);
        return super.onOptionsItemSelected(item);

    case R.id.menu_dismiss:
        InteractionsDataSource data = InteractionsDataSource.getInstance(context);
        data.markAllRead(DrawerActivity.settings.currentAccount);
        mDrawerLayout.closeDrawer(Gravity.RIGHT);
        notificationAdapter = new InteractionsCursorAdapter(context,
                data.getUnreadCursor(DrawerActivity.settings.currentAccount));
        notificationList.setAdapter(notificationAdapter);

        return super.onOptionsItemSelected(item);

    case R.id.menu_notifications:
        if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
            mDrawerLayout.closeDrawer(Gravity.LEFT);
        }

        if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
            mDrawerLayout.closeDrawer(Gravity.RIGHT);
        } else {
            mDrawerLayout.openDrawer(Gravity.RIGHT);
        }

        return super.onOptionsItemSelected(item);

    case R.id.menu_to_first:
        context.sendBroadcast(new Intent("com.daiv.android.twitter.TOP_TIMELINE"));
        return super.onOptionsItemSelected(item);

    case R.id.menu_tweetmarker:
        context.sendBroadcast(new Intent("com.daiv.android.twitter.TWEETMARKER"));
        return super.onOptionsItemSelected(item);

    case R.id.menu_get_help:
        new AlertDialog.Builder(context).setTitle(R.string.faq).setMessage(R.string.faq_first)
                .setPositiveButton("FAQ", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        XmlFaqUtils.showFaqDialog(context);
                    }
                }).setNegativeButton(R.string.contact, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        showContactUsDialog();
                    }
                }).setNeutralButton(R.string.follow, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        showFollowDialog();
                    }
                }).create().show();
        return super.onOptionsItemSelected(item);

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

From source file:net.nightwhistler.pageturner.fragment.ReadingFragment.java

private void deleteHightlight(final HighLight highLight) {

    if (highLight.getTextNote() != null && highLight.getTextNote().length() > 0) {
        new AlertDialog.Builder(context).setMessage(R.string.notes_attached)
                .setNegativeButton(android.R.string.no, (a, b) -> {
                }).setPositiveButton(android.R.string.yes, (dialogInterface, i) -> {
                    highlightManager.removeHighLight(highLight);
                    Toast.makeText(context, R.string.highlight_deleted, Toast.LENGTH_SHORT).show();
                    bookView.update();/*  w  w w.  j av  a  2s.c  om*/
                }).show();
    } else {
        highlightManager.removeHighLight(highLight);
        Toast.makeText(context, R.string.highlight_deleted, Toast.LENGTH_SHORT).show();
        bookView.update();
    }
}

From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java

private void deleteHightlight(final HighLight highLight) {

    final OnClickListener deleteHighlight = new OnClickListener() {
        @Override//w  w  w . j a  v a2 s  .  co m
        public void onClick(DialogInterface dialogInterface, int i) {
            highlightManager.removeHighLight(highLight);
            Toast.makeText(context, R.string.highlight_deleted, Toast.LENGTH_SHORT).show();
            bookView.update();
        }
    };

    if (highLight.getTextNote() != null && highLight.getTextNote().length() > 0) {
        new AlertDialog.Builder(context).setMessage(R.string.notes_attached)
                .setNegativeButton(android.R.string.no, null)
                .setPositiveButton(android.R.string.yes, deleteHighlight).show();
    } else {
        highlightManager.removeHighLight(highLight);
        Toast.makeText(context, R.string.highlight_deleted, Toast.LENGTH_SHORT).show();
        bookView.update();
    }
}

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

/**
 * @param aPermissions//from w  w  w . jav  a 2 s .c o m
 *        Array of JSON objects to represent site permissions.
 *        Example: { type: "offline-app", setting: "Store Offline Data: Allow" }
 */
private void showSiteSettingsDialog(String aHost, JSONArray aPermissions) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);

    View customTitleView = getLayoutInflater().inflate(R.layout.site_setting_title, null);
    ((TextView) customTitleView.findViewById(R.id.title)).setText(R.string.site_settings_title);
    ((TextView) customTitleView.findViewById(R.id.host)).setText(aHost);
    builder.setCustomTitle(customTitleView);

    // If there are no permissions to clear, show the user a message about that.
    // In the future, we want to disable the menu item if there are no permissions to clear.
    if (aPermissions.length() == 0) {
        builder.setMessage(R.string.site_settings_no_settings);
    } else {
        // Eventually we should use a list adapter and custom checkable list items
        // to make a two-line UI to match the mock-ups
        CharSequence[] items = new CharSequence[aPermissions.length()];
        boolean[] states = new boolean[aPermissions.length()];
        for (int i = 0; i < aPermissions.length(); i++) {
            try {
                items[i] = aPermissions.getJSONObject(i).getString("setting");
                // Make all the items checked by default
                states[i] = true;
            } catch (JSONException e) {
                Log.i(LOGTAG, "JSONException: " + e);
            }
        }
        builder.setMultiChoiceItems(items, states, new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog, int item, boolean state) {
                // Do nothing
            }
        });
        builder.setPositiveButton(R.string.site_settings_clear, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                ListView listView = ((AlertDialog) dialog).getListView();
                SparseBooleanArray checkedItemPositions = listView.getCheckedItemPositions();

                // An array of the indices of the permissions we want to clear
                JSONArray permissionsToClear = new JSONArray();
                for (int i = 0; i < checkedItemPositions.size(); i++) {
                    boolean checked = checkedItemPositions.get(i);
                    if (checked)
                        permissionsToClear.put(i);
                }
                GeckoAppShell.sendEventToGecko(
                        GeckoEvent.createBroadcastEvent("Permissions:Clear", permissionsToClear.toString()));
            }
        });
    }

    builder.setNegativeButton(R.string.site_settings_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    mMainHandler.post(new Runnable() {
        public void run() {
            builder.create().show();
        }
    });
}

From source file:com.daiv.android.twitter.ui.drawer_activities.DrawerActivity.java

private void showContactUsDialog() {
    new AlertDialog.Builder(context).setItems(new CharSequence[] { "Twitter", "Google+", "Email" },
            new DialogInterface.OnClickListener() {
                @Override/*from w  ww  . j a v a 2  s .  co  m*/
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (i == 0) {
                        final Intent tweet = new Intent(context, ComposeActivity.class);
                        new AlertDialog.Builder(context)
                                .setItems(new CharSequence[] { "@TestAndroid", "@daiv" },
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {
                                                if (i == 0) {
                                                    tweet.putExtra("user", "@TestAndroid");
                                                } else {
                                                    tweet.putExtra("user", "@daiv");
                                                }
                                                startActivity(tweet);
                                            }
                                        })
                                .create().show();
                    } else if (i == 1) {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://goo.gl/KCXlZk")));
                    } else {
                        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

                        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                                new String[] { "support@daivapps.com" });
                        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test (Classic)");
                        emailIntent.setType("plain/text");

                        startActivity(emailIntent);
                    }
                }
            }).create().show();
}

From source file:com.klinker.android.twitter.activities.drawer_activities.DrawerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    try {/*from  www  . jav  a2s.  c o  m*/
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
                mDrawerLayout.closeDrawer(Gravity.RIGHT);
            }
            return true;
        }
    } catch (Exception e) {
        // landscape
    }

    switch (item.getItemId()) {
    case R.id.menu_search:
        overridePendingTransition(0, 0);
        finish();
        overridePendingTransition(0, 0);
        return super.onOptionsItemSelected(item);

    case R.id.menu_compose:
        Intent compose = new Intent(context, ComposeActivity.class);
        sharedPrefs.edit().putBoolean("from_notification_bool", false).commit();
        startActivity(compose);
        return super.onOptionsItemSelected(item);

    case R.id.menu_direct_message:
        Intent dm = new Intent(context, ComposeDMActivity.class);
        sharedPrefs.edit().putBoolean("from_notification_bool", false).commit();
        startActivity(dm);
        return super.onOptionsItemSelected(item);

    case R.id.menu_settings:
        context.sendBroadcast(new Intent("com.klinker.android.twitter.MARK_POSITION"));
        Intent settings = new Intent(context, SettingsActivity.class);
        finish();
        sharedPrefs.edit().putBoolean("should_refresh", false).commit();
        overridePendingTransition(R.anim.slide_in_left, R.anim.activity_zoom_exit);
        startActivity(settings);
        return super.onOptionsItemSelected(item);

    case R.id.menu_dismiss:
        InteractionsDataSource data = InteractionsDataSource.getInstance(context);
        data.markAllRead(DrawerActivity.settings.currentAccount);
        mDrawerLayout.closeDrawer(Gravity.RIGHT);
        notificationAdapter = new InteractionsCursorAdapter(context,
                data.getUnreadCursor(DrawerActivity.settings.currentAccount));
        notificationList.setAdapter(notificationAdapter);

        return super.onOptionsItemSelected(item);

    case R.id.menu_notifications:
        if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
            mDrawerLayout.closeDrawer(Gravity.LEFT);
        }

        if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
            mDrawerLayout.closeDrawer(Gravity.RIGHT);
        } else {
            mDrawerLayout.openDrawer(Gravity.RIGHT);
        }

        return super.onOptionsItemSelected(item);

    case R.id.menu_to_first:
        context.sendBroadcast(new Intent("com.klinker.android.twitter.TOP_TIMELINE"));
        return super.onOptionsItemSelected(item);

    case R.id.menu_tweetmarker:
        context.sendBroadcast(new Intent("com.klinker.android.twitter.TWEETMARKER"));
        return super.onOptionsItemSelected(item);

    case R.id.menu_get_help:
        new AlertDialog.Builder(context).setTitle(R.string.faq).setMessage(R.string.faq_first)
                .setPositiveButton("FAQ", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        XmlFaqUtils.showFaqDialog(context);
                    }
                }).setNegativeButton(R.string.contact, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        showContactUsDialog();
                    }
                }).setNeutralButton(R.string.follow, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        showFollowDialog();
                    }
                }).create().show();
        return super.onOptionsItemSelected(item);

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

From source file:com.klinker.android.twitter.ui.drawer_activities.DrawerActivity.java

private void showContactUsDialog() {
    new AlertDialog.Builder(context).setItems(new CharSequence[] { "Twitter", "Google+", "Email" },
            new DialogInterface.OnClickListener() {
                @Override// w ww .ja  v a2s. c  o m
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (i == 0) {
                        final Intent tweet = new Intent(context, ComposeActivity.class);
                        new AlertDialog.Builder(context)
                                .setItems(new CharSequence[] { "@TalonAndroid", "@lukeklinker" },
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {
                                                if (i == 0) {
                                                    tweet.putExtra("user", "@TalonAndroid");
                                                } else {
                                                    tweet.putExtra("user", "@lukeklinker");
                                                }
                                                startActivity(tweet);
                                            }
                                        })
                                .create().show();
                    } else if (i == 1) {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://goo.gl/KCXlZk")));
                    } else {
                        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

                        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                                new String[] { "support@klinkerapps.com" });
                        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Talon (Classic)");
                        emailIntent.setType("plain/text");

                        startActivity(emailIntent);
                    }
                }
            }).create().show();
}