Example usage for android.app AlertDialog.Builder setMessage

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

Introduction

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

Prototype

public void setMessage(CharSequence message) 

Source Link

Usage

From source file:org.geek.utils.ApplicationUtils.java

/**
 * Display a standard Ok / Cancel dialog.
 * @param context The current context.//  w  w  w . j a v  a2s. c o m
 * @param icon The dialog icon.
 * @param title The dialog title.
 * @param message The dialog message.
 * @param onYes The dialog listener for the yes button.
 */
public static void showOkCancelDialog(Context context, int icon, String title, String message,
        DialogInterface.OnClickListener onYes) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setCancelable(true);
    builder.setIcon(icon);
    builder.setTitle(title);
    builder.setMessage(message);

    builder.setInverseBackgroundForced(true);
    builder.setPositiveButton(context.getResources().getString(R.string.Commons_Ok), onYes);
    builder.setNegativeButton(context.getResources().getString(R.string.Commons_Cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.geek.utils.ApplicationUtils.java

/**
 * Display a standard yes / no dialog.//  w w w. j  a  va2 s .  co  m
 * @param context The current context.
 * @param icon The dialog icon.
 * @param title The dialog title.
 * @param message The dialog message.
 * @param onYes The dialog listener for the yes button.
 */
public static void showYesNoDialog(Context context, int icon, int title, int message,
        DialogInterface.OnClickListener onYes) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setCancelable(true);
    builder.setIcon(icon);
    builder.setTitle(context.getResources().getString(title));
    builder.setMessage(context.getResources().getString(message));

    builder.setInverseBackgroundForced(true);
    builder.setPositiveButton(context.getResources().getString(R.string.Commons_Yes), onYes);
    builder.setNegativeButton(context.getResources().getString(R.string.Commons_No),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Shows a dialog informing the user that the action she's trying to perform
 * requires an Internet connection which is not available at the moment.
 * /*from ww w .  ja  va2  s. c o m*/
 * @param activity
 *            the caller activity
 * @param whyItsNeeded
 *            the resource ID within <tt>strings.xml</tt> that explains to
 *            the user why an Internet connection is needed by the operation
 * @param finishActivityOnOk
 *            whether the caller activity must be {@link Activity#finish()}
 *            'ed after the user hides the dialog
 */
public static void noInternetConnection(final FragmentActivity activity, final int whyItsNeeded,
        final boolean finishActivityOnOk) {
    new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder;
            if (finishActivityOnOk) {
                builder = getNoUiBuilder(activity);
            } else {
                builder = getBuilder(activity);
            }
            builder.setMessage(getString(R.string.no_internet_connection, getString(whyItsNeeded)));
            Dialog dialog = builder.create();
            dialog.setCanceledOnTouchOutside(!finishActivityOnOk);
            return dialog;
        }
    }.show(activity.getSupportFragmentManager(), "no_internet");
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Shows a dialog informing the user about what went wrong while trying to
 * registrate her device with GCM./*w  ww  .  j a va2  s. c o  m*/
 * 
 * @param errorCode
 *            the error message's resource ID within <tt>strings.xml</tt>
 * @param activity
 *            the caller activity
 * @param finishActivityOnOk
 *            whether the call comes from an activity with no UI that
 *            requires clicks on ok (or back) to call
 *            {@link Activity#finish()} on the caller activity
 */
public static void onRegistrationError(final int errorCode, final FragmentActivity activity,
        final boolean finishActivityOnOk) {
    new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder;
            if (finishActivityOnOk) {
                builder = getNoUiBuilder(activity);
            } else {
                builder = getBuilder(activity);
            }
            builder.setMessage(getString(R.string.gcm_registration_error, getString(errorCode)));
            builder.setPositiveButton(android.R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // just hide dialog
                }
            });
            Dialog dialog = builder.create();
            dialog.setCanceledOnTouchOutside(!finishActivityOnOk);
            return dialog;
        }
    }.show(activity.getSupportFragmentManager(), "gcm_error");
}

From source file:com.onesignal.GenerateNotification.java

private static int showNotificationAsAlert(final JSONObject gcmJson, final Activity activity) {
    final int aNotificationId = new Random().nextInt();

    activity.runOnUiThread(new Runnable() {
        @Override/*from ww  w  .  jav  a 2s.c  o m*/
        public void run() {
            AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setTitle(getTitle(gcmJson));
            try {
                builder.setMessage(gcmJson.getString("alert"));
            } catch (Throwable t) {
            }

            List<String> buttonsLabels = new ArrayList<String>();
            List<String> buttonIds = new ArrayList<String>();

            addAlertButtons(gcmJson, buttonsLabels, buttonIds);

            final List<String> finalButtonIds = buttonIds;

            Intent buttonIntent = getNewBaseIntent(aNotificationId);
            buttonIntent.putExtra("action_button", true);
            buttonIntent.putExtra("from_alert", true);
            buttonIntent.putExtra("onesignal_data", gcmJson.toString());
            try {
                if (gcmJson.has("grp"))
                    buttonIntent.putExtra("grp", gcmJson.getString("grp"));
            } catch (JSONException e) {
            }

            final Intent finalButtonIntent = buttonIntent;

            DialogInterface.OnClickListener buttonListener = new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    int index = which + 3;

                    if (finalButtonIds.size() > 1) {
                        try {
                            JSONObject customJson = new JSONObject(gcmJson.getString("custom"));
                            JSONObject additionalDataJSON = customJson.getJSONObject("a");
                            additionalDataJSON.put("actionSelected", finalButtonIds.get(index));

                            JSONObject newJsonData = new JSONObject(gcmJson.toString());
                            newJsonData.put("custom", customJson.toString());

                            finalButtonIntent.putExtra("onesignal_data", newJsonData.toString());

                            NotificationOpenedProcessor.processIntent(activity, finalButtonIntent);
                        } catch (Throwable t) {
                        }
                    } else // No action buttons, close button simply pressed.
                        NotificationOpenedProcessor.processIntent(activity, finalButtonIntent);
                }
            };

            // Back button pressed
            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    NotificationOpenedProcessor.processIntent(activity, finalButtonIntent);
                }
            });

            for (int i = 0; i < buttonsLabels.size(); i++) {
                if (i == 0)
                    builder.setNeutralButton(buttonsLabels.get(i), buttonListener);
                else if (i == 1)
                    builder.setNegativeButton(buttonsLabels.get(i), buttonListener);
                else if (i == 2)
                    builder.setPositiveButton(buttonsLabels.get(i), buttonListener);
            }

            AlertDialog alertDialog = builder.create();
            alertDialog.setCanceledOnTouchOutside(false);
            alertDialog.show();
        }
    });

    return aNotificationId;
}

From source file:org.csware.ee.utils.Tools.java

public static void show(final Activity activity, final int id) {
    final Context context = activity;
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle("");
    builder.setMessage("");

    builder.setPositiveButton("", new DialogInterface.OnClickListener() {
        @Override// w  ww.j  a v a 2s  .co m
        public void onClick(DialogInterface dialog, int which) {
            int version = android.os.Build.VERSION.SDK_INT;
            Intent intent;
            if (version < 11) {
                intent = new Intent();
                intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings");
            } else {
                //3.0?
                //intent = new Intent( android.provider.Settings.ACTION_WIRELESS_SETTINGS);
                intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
            }
            if (id == 1) {
                activity.finish();
            }
            context.startActivity(intent);
        }
    });
    builder.setNegativeButton("?", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (id == 1) {
                activity.finish();
            }
        }
    });
    builder.create().show();
}

From source file:com.dvn.vindecoder.ui.user.GetAllVehicalDetails.java

public static void displayPromptForEnablingGPS(final Activity activity) {

    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
    final String message = "Do you want open GPS setting?";

    builder.setMessage(message).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface d, int id) {
            activity.startActivity(new Intent(action));
            d.dismiss();/*from   w  w  w. ja  v  a  2  s  .  c  om*/
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface d, int id) {
            d.cancel();
        }
    });
    builder.create().show();
}

From source file:hongik.android.project.best.ReviewActivity.java

public void showAlertDialog() {
    AlertDialog.Builder alert_confirm = new AlertDialog.Builder(this);
    alert_confirm.setMessage("Please write a review : about " + sname).setCancelable(true);
    AlertDialog alert = alert_confirm.create();
    alert.show();/*from  w  ww.  java2s.c om*/
}

From source file:com.owncloud.android.CrashlogSendActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    if (id == DIALOG_SUBMIT) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.crashlog_message);
        builder.setNegativeButton(R.string.crashlog_dont_send_report, this);
        builder.setPositiveButton(R.string.crashlog_send_report, this);
        builder.setCancelable(true);/* ww  w  .j a va  2  s  .  c  o  m*/
        builder.setOnCancelListener(this);
        return builder.create();
    }
    return super.onCreateDialog(id);
}

From source file:com.example.clienttest.AbstractGreenhouseActivity.java

protected void displayAuthorizationError() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("You are not authorized to connect to Greenhouse. Please reauthorize the app.");
    builder.setCancelable(false);//from   w  w w . ja  va  2  s .co m
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            signOut();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}