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.springsource.greenhouse.twitter.TweetDetailsActivity.java

private void showRetweetDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Are you sure you want to Retweet?").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    retweet();/* w w  w .  j  a  v a2s.c om*/
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

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

/**
 * This function shows how to get the status of a printer
 * // w  w w . ja v a2s. 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:<DeviceName> for bluetooth)
 * @param portSettings
 *            Should be mini, the port settings mini is used for portable
 *            printers
 */
// portSettings = "mini";
// String portName = BT:<DeviceName>;
// context = this
public static void CheckStatus(Context context, String portName, String portSettings) {
    StarIOPort port = null;
    try {
        /*
         * using StarIOPort3.1.jar (support USB Port) Android OS Version:
         * upper 2.2
         */
        port = StarIOPort.getPort(portName, portSettings, 10000, context);
        /*
         * using StarIOPort.jar Android OS Version: under 2.1 port =
         * StarIOPort.getPort(portName, portSettings, 10000);
         */

        // A sleep is used to get time for the socket to completely open
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        }

        StarPrinterStatus status = port.retreiveStatus();

        if (status.offline == false) {
            Builder dialog = new AlertDialog.Builder(context);
            dialog.setNegativeButton("Ok", null);
            AlertDialog alert = dialog.create();
            alert.setTitle("Printer");
            alert.setMessage("Printer is Online");
            alert.setCancelable(false);
            alert.show();
        } else {
            String message = "Printer is offline";
            if (status.receiptPaperEmpty == true) {
                message += "\nPaper is Empty";
            }
            if (status.coverOpen == true) {
                message += "\nCover is Open";
            }
            Builder dialog = new AlertDialog.Builder(context);
            dialog.setNegativeButton("Ok", null);
            AlertDialog alert = dialog.create();
            alert.setTitle("Printer");
            alert.setMessage(message);
            alert.setCancelable(false);
            alert.show();
        }
    } catch (StarIOPortException e) {
        Builder dialog = new AlertDialog.Builder(context);
        dialog.setNegativeButton("Ok", null);
        AlertDialog alert = dialog.create();
        alert.setTitle("Failure");
        alert.setMessage("Failed to connect to printer");
        alert.setCancelable(false);
        alert.show();
    } finally {
        if (port != null) {
            try {
                StarIOPort.releasePort(port);
            } catch (StarIOPortException e) {
            }
        }
    }
}

From source file:hr.kodbiro.quickbyte.activities.TrolleyActivity.java

private void sendOrder(String order) {
    RequestParams params = new RequestParams();
    params.put("application/json", order);
    QuickAsyncHttpClient.post("order", params, new JsonHttpResponseHandler() {
        @Override//from   w  ww  . ja  va2  s.c  o  m
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                String sFinal = response.getString("status") + response.getString("wait_time");

                alertDialogBuilder
                        .setMessage(
                                String.format("%s %s", getString(R.string.dialog_order_status_success_textview),
                                        response.getString("wait_time")))
                        .setPositiveButton(R.string.dialog_positive_button,
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialogInterface, int i) {
                                        orderList.clear();
                                        finishActivityWithList();
                                    }
                                });
                AlertDialog dialog = alertDialogBuilder.create();
                dialog.show();

                Log.i("json response", sFinal);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            alertDialogBuilder.setMessage(getString(R.string.dialog_order_status_failure_textview))
                    .setPositiveButton(R.string.dialog_positive_button, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    });
            AlertDialog dialog = alertDialogBuilder.create();
            dialog.show();
        }
    });
}

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

private static boolean sendCommand(Context context, String portName, String portSettings,
        ArrayList<byte[]> byteList) {
    boolean result = true;
    StarIOPort port = null;//w  ww .ja va2s.co  m
    try {
        /*
         * using StarIOPort3.1.jar (support USB Port) Android OS Version:
         * upper 2.2
         */
        port = StarIOPort.getPort(portName, portSettings, 20000, context);
        /*
         * using StarIOPort.jar Android OS Version: under 2.1 port =
         * StarIOPort.getPort(portName, portSettings, 10000);
         */
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
        }

        /*
         * Portable Printer Firmware Version 2.4 later, SM-S220i(Firmware
         * Version 2.0 later) Using Begin / End Checked Block method for
         * preventing "data detective". When sending large amounts of raster
         * data, use Begin / End Checked Block method and adjust the value
         * in the timeout in the "StarIOPort.getPort" in order to prevent
         * "timeout" of the "endCheckedBlock method" while a printing. If
         * receipt print is success but timeout error occurs(Show message
         * which is
         * "There was no response of the printer within the timeout period."
         * ), need to change value of timeout more longer in
         * "StarIOPort.getPort" method. (e.g.) 10000 -> 30000When use
         * "Begin / End Checked Block Sample Code", do comment out
         * "query commands Sample code".
         */

        /* Start of Begin / End Checked Block Sample code */
        StarPrinterStatus status = port.beginCheckedBlock();

        if (true == status.offline) {
            throw new StarIOPortException("A printer is offline");
        }

        byte[] commandToSendToPrinter = convertFromListByteArrayTobyteArray(byteList);
        port.writePort(commandToSendToPrinter, 0, commandToSendToPrinter.length);

        port.setEndCheckedBlockTimeoutMillis(30000);// Change the timeout
        // time of
        // endCheckedBlock
        // method.
        status = port.endCheckedBlock();

        if (true == status.coverOpen) {
            throw new StarIOPortException("Printer cover is open");
        } else if (true == status.receiptPaperEmpty) {
            throw new StarIOPortException("Receipt paper is empty");
        } else if (true == status.offline) {
            throw new StarIOPortException("Printer is offline");
        }
        /* End of Begin / End Checked Block Sample code */

        /*
         * Portable Printer Firmware Version 2.3 earlier Using query
         * commands for preventing "data detective". When sending large
         * amounts of raster data, send query commands after writePort data
         * for confirming the end of printing and adjust the value in the
         * timeout in the "checkPrinterSendToComplete" method in order to
         * prevent "timeout" of the "sending query commands" while a
         * printing. If receipt print is success but timeout error
         * occurs(Show message which is
         * "There was no response of the printer within the timeout period."
         * ), need to change value of timeout more longer in
         * "checkPrinterSendToComplete" method. (e.g.) 10000 -> 30000When
         * use "query commands Sample code", do comment out
         * "Begin / End Checked Block Sample Code".
         */

        /* Start of query commands Sample code */
        // byte[] commandToSendToPrinter =
        // convertFromListByteArrayTobyteArray(byteList);
        // port.writePort(commandToSendToPrinter, 0,
        // commandToSendToPrinter.length);
        //
        // checkPrinterSendToComplete(port);
        /* End of query commands Sample code */
    } catch (StarIOPortException e) {
        result = false;
        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();
    } finally {
        if (port != null) {
            try {
                StarIOPort.releasePort(port);
            } catch (StarIOPortException e) {
            }
        }
    }

    return result;
}

From source file:me.ziccard.secureit.async.upload.AuthenticatorTask.java

/**
 * Shows an authentication failure dialog
 *///from  ww  w  .j ava2  s . c o  m
public void showFailureDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setMessage("Authentication failed").setCancelable(false).setPositiveButton("Ok",
            new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub

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

From source file:com.klick.plugins.listviewalert.ListViewAlert.java

public void loadList(final JSONArray thelist, final CallbackContext callbackContext) {
    final CordovaInterface cordova = this.cordova;
    Runnable runnable = new Runnable() {
        public void run() {
            List<String> list = new ArrayList<String>();
            // we start with index 1 because index 0 is the title
            for (int x = 1; x < thelist.length(); x++) {
                try {
                    list.add(thelist.getString(x));
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }/*ww w.  j  av a  2s. co m*/
            }
            CharSequence[] items = list.toArray(new CharSequence[list.size()]);
            AlertDialog.Builder builder = new AlertDialog.Builder(
                    new ContextThemeWrapper(cordova.getActivity(), android.R.style.Theme_Holo_Dialog));
            try {
                builder.setTitle(thelist.getString(0));
                // builder.setMessage( "This is a hardcoded message to try whether or not this is feasible!");
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } // index 0 contains the title
            builder.setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    dialog.dismiss();
                    // we +1 to item because item starts from 0, but from
                    // thelist[0], that was the title...
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, item + 1));
                    //callbackContext.sendPluginResult(pluginResult)
                }
            });
            AlertDialog alert = builder.create();
            alert.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            alert.show();
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.HskPackage.HskNamespace.HSK1ProjectActivity.java

public void showDef(View v) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(ssignificato).setCancelable(false).setNegativeButton("Clear",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();//from w w w.  j  a va 2s .c o  m
                }
            });

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

From source file:geert.stef.sm.beheerautokm.AddRitActivity.java

public void showNotValidNumberDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Not a valid number").setMessage("Something like \"12.34\"")
            .setIcon(android.R.drawable.ic_dialog_alert)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    //do some thing here which you need
                }//from  ww  w  . j  a va 2 s. c  o m
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:geert.stef.sm.beheerautokm.AddRitActivity.java

public void showAddedDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Added").setMessage("The number is added.").setIcon(android.R.drawable.ic_dialog_alert)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    //do some thing here which you need
                }//from   ww w.  ja va2s  .c om
            });
    /*builder.setNegativeButton("No", new DialogInterface.OnClickListener()
    {
    public void onClick(DialogInterface dialog, int which)
    {
        dialog.dismiss();
    }
    });*/
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.springsource.greenhouse.WebOAuthActivity.java

private void displayAppAuthorizationError(String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(message);//from  ww  w. j  av  a  2  s.  co  m
    builder.setCancelable(false);
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            signOut();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}