Example usage for android.app AlertDialog.Builder create

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

Introduction

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

Prototype

public void create() 

Source Link

Document

Forces immediate creation of the dialog.

Usage

From source file:de.grobox.blitzmail.MainActivity.java

private void addSendNowPref(final Context c) {
    JSONObject mails = MailStorage.getMails(this);

    if (mails != null && mails.length() > 0) {
        PreferenceCategory targetCategory = (PreferenceCategory) findPreference("pref_sending");

        Preference pref = new Preference(this);
        pref.setKey("pref_send_now");
        pref.setTitle(R.string.pref_send_now);
        pref.setSummary(/*from w  w  w . ja va  2 s  .  c om*/
                String.format(getResources().getString(R.string.pref_send_now_summary), mails.length()));

        pref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
            public boolean onPreferenceClick(Preference preference) {
                if (BuildConfig.PRO)
                    sendNow();
                else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(c);

                    builder.setTitle(c.getString(R.string.app_name));
                    builder.setMessage(c.getString(R.string.error_lite_version));
                    builder.setIcon(android.R.drawable.ic_dialog_info);

                    // Add the buttons
                    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            Uri uri = Uri.parse(
                                    "https://play.google.com/store/apps/details?id=de.grobox.blitzmail.pro");
                            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                            if (intent.resolveActivity(c.getPackageManager()) != null) {
                                c.startActivity(intent);
                            }
                            dialog.dismiss();
                        }
                    });
                    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                        }
                    });

                    // Create and show the AlertDialog
                    AlertDialog dialog = builder.create();
                    dialog.setCanceledOnTouchOutside(false);
                    dialog.show();
                }

                return true;
            }
        });

        targetCategory.addPreference(pref);
    }
}

From source file:org.hfoss.posit.android.functionplugin.reminder.SetReminder.java

private void showAddrEnterDialog() {
    // Set the current dialog
    currentDialog = ADDRESS_ENTER_DIALOG_ID;

    // Build Address Enter Dialog
    AlertDialog.Builder addrEnterBuilder = new AlertDialog.Builder(this);
    addrEnterBuilder.setTitle("Step 3: Enter Location Name / Address");

    // Initialize EditText for user to type the desired address
    addressET = new EditText(this);
    addressET.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    addrEnterBuilder.setView(addressET);

    // Set Listeners
    addrEnterBuilder.setPositiveButton("Search", mAddrEnterOnClickListner);
    // Finish the activity when the user presses cancel
    addrEnterBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            setResult(RESULT_OK);/*from   w w  w  .  jav  a2 s. c  o m*/
            finish();
        }
    });
    addrEnterBuilder.setOnKeyListener(mBackKeyListener);

    // Show Address Enter Dialog
    addrEnterDialog = addrEnterBuilder.create();
    addrEnterDialog.show();
}

From source file:com.fvd.nimbus.MainActivity.java

@SuppressLint("NewApi")
@Override/*  w  w  w . j a  v  a 2s .  c om*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == TAKE_PHOTO) {
        if (resultCode == -1) {
            try {
                if (data != null) {
                    if (data.hasExtra("data")) {
                        Bitmap bm = data.getParcelableExtra("data");
                        photoFileName = appSettings.saveTempBitmap(bm);
                        bm.recycle();
                    }
                } else {
                    if (outputFileUri != null)
                        photoFileName = outputFileUri.getPath();
                    else
                        photoFileName = getImagePath();
                }

                if (appSettings.isFileExists(photoFileName)) {
                    Intent iPaint = new Intent();
                    iPaint.putExtra("temp", true);
                    iPaint.putExtra("path", photoFileName);
                    iPaint.setClassName("com.fvd.nimbus", "com.fvd.nimbus.PaintActivity");
                    startActivity(iPaint);
                }
                showProgress(false);
            } catch (Exception e) {
                appSettings.appendLog("main:onActivityResult: exception -  " + e.getMessage());
                showProgress(false);
            }
        } else
            showProgress(false);
    } else if (requestCode == TAKE_PICTURE) {
        if (resultCode == -1 && data != null) {
            boolean temp = false;

            try {
                Uri resultUri = data.getData();
                String drawString = resultUri.getPath();
                String galleryString = getGalleryPath(resultUri);
                if (galleryString != null && galleryString.length() > 0) {
                    drawString = galleryString;
                } else {
                    try {
                        InputStream input = getApplicationContext().getContentResolver()
                                .openInputStream(resultUri);
                        Bitmap bm = BitmapFactory.decodeStream(input);
                        drawString = appSettings.saveTempBitmap(bm);
                        bm.recycle();
                        temp = true;

                    } catch (Exception e) {
                        drawString = "";
                        showProgress(false);
                    }
                }

                if (drawString.length() > 0 && drawString.indexOf("/exposed_content/") == -1) {
                    try {
                        Intent iPaint = new Intent();
                        iPaint.putExtra("temp", temp);
                        iPaint.putExtra("path", drawString);
                        iPaint.setClassName("com.fvd.nimbus", "com.fvd.nimbus.PaintActivity");
                        startActivity(iPaint);
                    } catch (Exception e) {

                    }
                }
                showProgress(false);

            } catch (Exception e) {
                appSettings.appendLog("main:onActivityResult  " + e.getMessage());
                showProgress(false);
            }
        } else
            showProgress(false);
    } else if (requestCode == 5) {
        if (resultCode == RESULT_OK) {
            userMail = data.getStringExtra("userMail");
            userPass = data.getStringExtra("userPass");
            serverHelper.getInstance().sendOldRequest("user_register", String.format(
                    "{\"action\": \"user_register\",\"email\":\"%s\",\"password\":\"%s\",\"_client_software\": \"ff_addon\"}",
                    userMail, userPass), "");
        }
    } else if (requestCode == 6) {
        showLogin();
    } else if (requestCode == SHOW_SETTINGS) {
        switch (resultCode) {
        case RESULT_FIRST_USER + 1:
            Intent i = new Intent(getApplicationContext(), PrefsActivity.class);
            startActivity(i);
            //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
            overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
            break;
        case RESULT_FIRST_USER + 2:
            if (appSettings.sessionId.length() == 0)
                showLogin();
            else {
                if (true || appSettings.service == "") {
                    appSettings.sessionId = "";
                    Editor e = prefs.edit();
                    e.putString("userMail", userMail);
                    e.putString("userPass", "");
                    e.putString("sessionId", appSettings.sessionId);
                    e.commit();
                    showLogin();
                } else {
                    i = new Intent(getApplicationContext(), loginWithActivity.class);
                    i.putExtra("logout", "true");
                    i.putExtra("service", appSettings.service);
                    startActivity(i);
                    overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
                }
            }
            break;
        case RESULT_FIRST_USER + 3:
            try {
                startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("market://details?id=" + getApplicationInfo().packageName)));
            } catch (Exception e) {
            }
        case RESULT_FIRST_USER + 4:
            Uri uri = Uri.parse(
                    "http://help.everhelper.me/customer/portal/articles/1376820-nimbus-clipper-for-android---quick-guide");
            Intent it = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(it);
            //overridePendingTransition( R.anim.slide_in_up, R.anim.slide_out_up );
            overridePendingTransition(R.anim.carbon_slide_in, R.anim.carbon_slide_out);
            break;
        case RESULT_FIRST_USER + 5:
            final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this,
                    AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            alertDialogBuilder.setMessage(getScriptContent("license.txt")).setCancelable(false)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // no alert dialog shown
                            //alertDialogShown = null;
                            // canceled
                            setResult(RESULT_CANCELED);
                            // and finish
                            //finish();
                        }
                    });
            // create alert dialog
            final AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.setTitle(getString(R.string.license_title));

            // and show
            //alertDialogShown = alertDialog;
            try {
                alertDialog.show();
            } catch (final java.lang.Exception e) {
                // nothing to do
            } catch (final java.lang.Error e) {
                // nothing to do
            }
            break;
        default:
            break;
        }
    }
}

From source file:com.nps.micro.view.TestsSectionFragment.java

private void prepareScenarios() {
    ScenariosGenerator scenariosGeneratior = new ScenariosGenerator(model);
    final List<Scenario> scenarios = scenariosGeneratior.generate();
    List<CharSequence> items = new ArrayList<CharSequence>();
    for (Scenario scenario : scenarios) {
        items.add(scenario.toString());/*from w  ww  .j  av  a2 s.co m*/
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.test_scenatios_title)
            .setItems(items.toArray(new CharSequence[items.size()]), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do nothing
                }
            }).setPositiveButton(R.string.run, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    if (listener != null) {
                        listener.runUsbTest(scenarios);
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            });
    builder.create().show();
}

From source file:com.CloudRecognition.CloudReco.java

public void showErrorMessage(int errorCode, double errorTime, boolean finishActivityOnError) {
    if (errorTime < (mLastErrorTime + 5.0) || errorCode == mlastErrorCode)
        return;//from  ww  w.j  a v a  2  s .  c o m

    mlastErrorCode = errorCode;
    mFinishActivityOnError = finishActivityOnError;

    runOnUiThread(new Runnable() {
        public void run() {
            if (mErrorDialog != null) {
                mErrorDialog.dismiss();
            }

            // Generates an Alert Dialog to show the error message
            AlertDialog.Builder builder = new AlertDialog.Builder(CloudReco.this);
            builder.setMessage(getStatusDescString(CloudReco.this.mlastErrorCode))
                    .setTitle(getStatusTitleString(CloudReco.this.mlastErrorCode)).setCancelable(false)
                    .setIcon(0)
                    .setPositiveButton(getString(R.string.button_OK), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            if (mFinishActivityOnError) {
                                finish();
                            } else {
                                dialog.dismiss();
                            }
                        }
                    });

            mErrorDialog = builder.create();
            mErrorDialog.show();
        }
    });
}

From source file:com.radicaldynamic.groupinform.activities.LauncherActivity.java

public Dialog onCreateDialog(int id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    Dialog dialog = null;/*  w w  w .j  a  v a 2 s.com*/

    if (isFinishing()) {
        return dialog;
    }

    switch (id) {
    case DIALOG_COUCH_ERROR:
        builder.setMessage("Error Initializing or Starting Database")
                .setPositiveButton("Try Again?", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        startCouch();
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        LauncherActivity.this.moveTaskToBack(true);
                    }
                });

        dialog = builder.create();
        break;

    case DIALOG_EXPIRED:
        builder.setCancelable(false).setIcon(R.drawable.ic_dialog_alert).setTitle("Subscription Expired")
                .setMessage(
                        "The subscription for this device profile has expired.\n\nPlease see your account owner to have the subscription renewed or this profile transferred to an active subscription or email our support team at\n\nsupport@groupcomplete.com");

        builder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                exitApplication();
            }
        });

        dialog = builder.create();
        break;

    case DIALOG_EXPIRED_CANNOT_CONNECT:
        builder.setCancelable(false).setIcon(R.drawable.ic_dialog_alert).setTitle("Subscription Expired")
                .setMessage(
                        "The subscription for this device profile has expired.\n\nPlease see your account owner to have the subscription renewed or this profile transferred to an active subscription or email our support team at\n\nsupport@groupcomplete.com\n\nPlease note that the Group Complete service could not be contacted so this message may not reflect up-to-date changes to your Group Complete account.  Please ensure that this device can access the Internet and restart GC Mobile.");

        builder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                exitApplication();
            }
        });

        dialog = builder.create();
        break;

    case DIALOG_EXTERNAL_STORAGE_UNAVAILABLE:
        builder.setCancelable(false).setIcon(R.drawable.ic_dialog_alert)
                .setMessage(getString(R.string.no_sd_error));

        builder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                finish();
            }
        });

        dialog = builder.create();
        break;

    // Registered    
    case DIALOG_UNABLE_TO_CONNECT_OFFLINE_DISABLED:
        String msg;

        if (Collect.getInstance().getInformOnlineState().hasReplicatedFolders())
            msg = getString(R.string.tf_connection_error_registered_with_db_msg);
        else
            msg = getString(R.string.tf_connection_error_registered_without_db_msg);

        builder.setCancelable(false).setIcon(R.drawable.ic_dialog_alert).setTitle(R.string.tf_unable_to_connect)
                .setMessage(msg);

        builder.setPositiveButton(getText(R.string.tf_retry), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                restartActivity(true);
            }
        });

        if (Collect.getInstance().getInformOnlineState().hasReplicatedFolders()) {
            builder.setNeutralButton(getText(R.string.tf_go_offline), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    startCouch();
                }
            });
        }

        builder.setNegativeButton(getText(R.string.tf_exit_inform), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                finish();
            }
        });

        dialog = builder.create();
        break;

    // Registered
    case DIALOG_UNABLE_TO_CONNECT_OFFLINE_ENABLED:
        builder.setCancelable(false).setIcon(R.drawable.ic_dialog_info)
                .setTitle(R.string.tf_offline_mode_enabled)
                .setMessage(getString(R.string.tf_offline_mode_enabled_msg));

        builder.setPositiveButton(getText(R.string.tf_continue), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                startCouch();
            }
        });

        dialog = builder.create();
        break;

    case DIALOG_UNABLE_TO_REGISTER:
        builder.setCancelable(false).setIcon(R.drawable.ic_dialog_alert).setTitle(R.string.tf_unable_to_connect)
                .setMessage(getString(R.string.tf_connection_error_unregistered_msg));

        builder.setPositiveButton(getText(R.string.tf_retry), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                restartActivity(true);
            }
        });

        builder.setNegativeButton(getText(R.string.tf_exit_inform), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                finish();
            }
        });

        dialog = builder.create();
        break;

    case DIALOG_UPGRADE_FAILED:
        builder.setMessage("Error Upgrading Application")
                .setPositiveButton("Try Again?", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        restartActivity(true);
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        LauncherActivity.this.moveTaskToBack(true);
                    }
                });

        dialog = builder.create();
        break;
    }

    return dialog;
}

From source file:net.bytten.comicviewer.ComicViewerActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    // Set up variables for a dialog and a dialog builder. Only need one of each.
    Dialog dialog = null;/*from  www. j av  a  2s  . c  o m*/
    AlertDialog.Builder builder = null;

    // Determine the type of dialog based on the integer passed. These are defined in constants
    // at the top of the class.
    switch (id) {
    case DIALOG_SHOW_HOVER_TEXT:
        //Build and show the Hover Text dialog
        builder = new AlertDialog.Builder(ComicViewerActivity.this);
        builder.setMessage(comicInfo.getAlt());
        builder.setPositiveButton("Open Link...", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                openComicLink();
            }
        });
        builder.setNegativeButton("Close", null);
        dialog = builder.create();
        builder = null;
        break;
    case DIALOG_SHOW_ABOUT:
        //Build and show the About dialog
        builder = new AlertDialog.Builder(this);
        builder.setTitle(getStringAppName());
        builder.setIcon(android.R.drawable.ic_menu_info_details);
        builder.setNegativeButton(android.R.string.ok, null);
        builder.setNeutralButton("Donate", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                donate();
            }
        });
        builder.setPositiveButton("Developer Website", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                developerWebsite();
            }
        });
        View v = LayoutInflater.from(this).inflate(R.layout.about, null);
        TextView tv = (TextView) v.findViewById(R.id.aboutText);
        tv.setText(String.format(getStringAboutText(), getVersion()));
        builder.setView(v);
        dialog = builder.create();
        builder = null;
        v = null;
        tv = null;
        break;
    case DIALOG_SEARCH_BY_TITLE:
        //Build and show the Search By Title dialog
        builder = new AlertDialog.Builder(this);

        LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.search_dlg, (ViewGroup) findViewById(R.id.search_dlg));

        final EditText input = (EditText) layout.findViewById(R.id.search_dlg_edit_box);

        builder.setTitle("Search by Title");
        builder.setIcon(android.R.drawable.ic_menu_search);
        builder.setView(layout);
        builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                String query = input.getText().toString();
                Uri uri = comicDef.getArchiveUrl();
                Intent i = new Intent(ComicViewerActivity.this, getArchiveActivityClass());
                i.setAction(Intent.ACTION_VIEW);
                i.setData(uri);
                i.putExtra(getPackageName() + "LoadType", ArchiveActivity.LoadType.SEARCH_TITLE);
                i.putExtra(getPackageName() + "query", query);
                startActivityForResult(i, PICK_ARCHIVE_ITEM);
            }
        });
        builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        dialog = builder.create();
        builder = null;
        break;
    case DIALOG_FAILED:
        // Probably doesn't need its own builder, but because this is a special case
        // dialog I gave it one.
        AlertDialog.Builder adb = new AlertDialog.Builder(this);
        adb.setTitle("Error");
        adb.setIcon(android.R.drawable.ic_dialog_alert);

        adb.setNeutralButton(android.R.string.ok, null);

        //Set failedDialog to our dialog so we can dismiss
        //it manually
        failedDialog = adb.create();
        failedDialog.setMessage(errors);

        dialog = failedDialog;
        break;
    default:
        dialog = null;
    }

    return dialog;
}

From source file:com.wheelphone.remotemini.WheelphoneRemoteMini.java

public void msgbox(String title, String msg) {
    AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
    dlgAlert.setTitle(title);/*from   w  w w.j a  va  2 s .c  om*/
    dlgAlert.setMessage(msg);
    dlgAlert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            //finish(); 
        }
    });
    dlgAlert.setCancelable(true);
    dlgAlert.create().show();
}

From source file:com.abc.driver.PersonalActivity.java

private void doCrop() {
    Log.d(TAG, "doCrop()");
    final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>();

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setType("image/*");

    List<ResolveInfo> list = this.getPackageManager().queryIntentActivities(intent, 0);

    int size = list.size();

    if (size == 0) {
        Log.d(TAG, " Crop activity is not found.  List size is zero.");
        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        app.setPortaritBitmap(Bitmap.createScaledBitmap(tmpBmp, CellSiteConstants.IMAGE_WIDTH,
                CellSiteConstants.IMAGE_HEIGHT, false));

        mUserPortraitIv.setImageBitmap(app.getPortaritBitmap());
        isPortraitChanged = true;/*  w w  w  .j  a  v a 2s  .  c om*/

        Log.d(TAG, "set bitmap");

        return;
    } else {
        Log.d(TAG, "found the crop activity.");
        intent.setData(imageUri);

        intent.putExtra("outputX", CellSiteConstants.IMAGE_WIDTH);
        intent.putExtra("outputY", CellSiteConstants.IMAGE_HEIGHT);
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);

        if (size == 1) {
            Log.d(TAG, "Just one as choose it as crop activity.");
            Intent i = new Intent(intent);
            ResolveInfo res = list.get(0);
            i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

            startActivityForResult(i, CellSiteConstants.CROP_PICTURE);
        } else {
            Log.d(TAG, "More that one activity for crop  is found . will chooose one");
            for (ResolveInfo res : list) {
                final CropOption co = new CropOption();

                co.title = getPackageManager().getApplicationLabel(res.activityInfo.applicationInfo);
                co.icon = getPackageManager().getApplicationIcon(res.activityInfo.applicationInfo);
                co.appIntent = new Intent(intent);

                co.appIntent
                        .setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

                cropOptions.add(co);
            }

            CropOptionAdapter adapter = new CropOptionAdapter(getApplicationContext(), cropOptions);

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Choose Crop App");

            builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    startActivityForResult(cropOptions.get(item).appIntent, CellSiteConstants.CROP_PICTURE);
                }
            });

            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                // @Override
                public void onCancel(DialogInterface dialog) {
                    if (imageUri != null) {
                        getContentResolver().delete(imageUri, null, null);
                        imageUri = null;
                        isPortraitChanged = false;
                    }
                }
            });
            AlertDialog alert = builder.create();

            alert.show();
        }
    }
}

From source file:com.nanosheep.bikeroute.Feedback.java

@Override
public Dialog onCreateDialog(final int id) {
    AlertDialog.Builder builder;
    ProgressDialog pDialog;/*  ww w .  j a va2s  .c o  m*/
    Dialog dialog;
    switch (id) {
    case R.id.send:
        pDialog = new ProgressDialog(this);
        pDialog.setCancelable(true);
        pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pDialog.setMessage(getText(R.string.send_msg));
        pDialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(final DialogInterface arg0) {
                removeDialog(R.id.send);
            }
        });
        pDialog.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(final DialogInterface arg0) {
                submitHandler.cancel(true);
            }

        });
        dialog = pDialog;
        break;
    case R.id.thanks:
        builder = new AlertDialog.Builder(this);
        builder.setMessage(getText(R.string.thanks_message)).setCancelable(true)
                .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int id) {
                        dialog.dismiss();
                        finish();
                    }
                });
        dialog = builder.create();
        break;
    case R.id.feedback_fail:
        builder = new AlertDialog.Builder(this);
        builder.setMessage(getText(R.string.feedback_fail_message)).setCancelable(true)
                .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int id) {
                        dialog.dismiss();
                    }
                });
        dialog = builder.create();
        break;
    default:
        dialog = null;
    }
    return dialog;
}