Example usage for android.app AlertDialog show

List of usage examples for android.app AlertDialog show

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

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  .  j  av  a 2s.  co  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:com.otaupdater.utils.Utils.java

public static void showProKeyOnlyFeatureDialog(final Context ctx, final DialogCallback callback) {
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setTitle(R.string.prokey_only_feature_title);
    builder.setMessage(R.string.prokey_only_feature_message);
    builder.setPositiveButton(R.string.prokey_only_get, new DialogInterface.OnClickListener() {
        @Override//from  w w w  . ja va  2  s. c  om
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            Intent i = new Intent(ctx, SettingsActivity.class);
            i.setAction(SettingsActivity.EXTRA_SHOW_GET_PROKEY_DLG);
            i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            ctx.startActivity(i);
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    final AlertDialog dlg = builder.create();
    dlg.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            if (callback != null)
                callback.onDialogShown(dlg);
        }
    });
    dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            if (callback != null)
                callback.onDialogClosed(dlg);
        }
    });
    dlg.show();
}

From source file:it.evilsocket.dsploit.core.System.java

public static boolean checkNetworking(final Activity current) {
    if (Network.isWifiConnected(mContext) == false) {
        AlertDialog.Builder builder = new AlertDialog.Builder(current);

        builder.setCancelable(false);/*w  ww  . j  av a 2s  . c  o m*/
        builder.setTitle("Error");
        builder.setMessage("WiFi connectivity went down.");
        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();

                Bundle bundle = new Bundle();
                bundle.putBoolean(WifiScannerActivity.CONNECTED, false);

                Intent intent = new Intent();
                intent.putExtras(bundle);

                current.setResult(Activity.RESULT_OK, intent);

                current.finish();
            }
        });

        AlertDialog alert = builder.create();
        alert.show();

        return false;
    }

    return true;
}

From source file:com.hemou.android.account.AccountUtils.java

/**
 * Show conflict message about previously registered authenticator from
 * another application//  ww  w.ja  v a2  s .c  o m
 * 
 * @param activity
 */
private static void showConflictMessage(final Activity activity) {
    AlertDialog dialog = LightAlertDialog.create(activity);
    dialog.setTitle(activity.getString(string.authenticator_conflict_title));
    dialog.setMessage(activity.getString(string.authenticator_conflict_message));
    dialog.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            activity.finish();
        }
    });
    dialog.setButton(BUTTON_POSITIVE, activity.getString(android.R.string.ok), new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            activity.finish();
        }
    });
    dialog.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 source file:com.star.printer.StarPrinter.java

private static void ShowAlert(String Title, String Message) {
    Builder dialog = new AlertDialog.Builder(mContext);
    dialog.setNegativeButton("Ok", null);
    AlertDialog alert = dialog.create();
    alert.setTitle(Title);/*from  w  w  w  .j  a  v  a2  s.c  o m*/
    alert.setMessage(Message);
    alert.setCancelable(false);
    alert.show();

}

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  ww  .  j  av  a 2s  .  c  o m*/
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            signOut();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:net.phamngochai.beefnoodle.ui.DownloadDictionaryActivity.java

public void showAlertDialog(String str) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(str).setCancelable(false).setNeutralButton("OK", null);
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.star.printer.StarPrinter.java

/**
 * This function is used to print a java bitmap directly to a portable
 * printer.// w  w w . j a v a 2s  . c o m
 * 
 * @param context
 *            Activity for displaying messages to the user
 * @param portName
 *            Port name to use for communication. This should be
 *            (TCP:<IPAddress> or BT:<Device pair name>)
 * @param portSettings
 *            Should be mini, the port settings mini is used for portable
 *            printers
 * @param res
 *            The resources object containing the image data
 * @param source
 *            The resource id of the image data
 * @param maxWidth
 *            The maximum width of the image to print. This is usually the
 *            page width of the printer. If the image exceeds the maximum
 *            width then the image is scaled down. The ratio is maintained.
 */
public static void PrintBitmapImage(Context context, String portName, String portSettings, Resources res,
        int source, int maxWidth, boolean compressionEnable, boolean pageModeEnable) {
    ArrayList<byte[]> commands = new ArrayList<byte[]>();

    Bitmap bm = BitmapFactory.decodeResource(res, source);
    StarBitmap starbitmap = new StarBitmap(bm, false, maxWidth);

    try {

        commands.add(starbitmap.getImageEscPosDataForPrinting(compressionEnable, pageModeEnable));

        sendCommand(context, portName, portSettings, commands);
    } catch (StarIOPortException e) {
        Builder dialog = new AlertDialog.Builder(context);
        dialog.setNegativeButton("Ok", null);
        AlertDialog alert = dialog.create();
        alert.setTitle("Failure");
        alert.setMessage(e.getMessage());
        alert.setCancelable(false);
        alert.show();
    }
}

From source file:net.dahanne.android.regalandroid.tasks.LoginTask.java

private void showAlert(String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(R.string.problem).setMessage(message).setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {
                @Override/*  w ww . ja va2s . c o m*/
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}