List of usage examples for android.app AlertDialog setMessage
public void setMessage(CharSequence message)
From source file:com.star.printer.StarPrinter.java
/** * This function is used to print a java bitmap directly to a portable * printer.// w ww. j av a 2 s .co 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:com.star.printer.StarPrinter.java
/** * This function shows how to get the firmware information of a printer * //www. j a v a 2 s. com * @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 */ public static void CheckFirmwareVersion(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) { } Map<String, String> firmware = port.getFirmwareInformation(); String modelName = firmware.get("ModelName"); String firmwareVersion = firmware.get("FirmwareVersion"); String message = "Model Name:" + modelName; message += "\nFirmware Version:" + firmwareVersion; Builder dialog = new AlertDialog.Builder(context); dialog.setNegativeButton("Ok", null); AlertDialog alert = dialog.create(); alert.setTitle("Firmware Information"); 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:com.star.printer.StarPrinter.java
/** * This function shows how to get the status of a printer * /*from w w w . j a v a 2 s . 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:com.star.printer.StarPrinter.java
private static boolean sendCommand(Context context, String portName, String portSettings, ArrayList<byte[]> byteList) { boolean result = true; StarIOPort port = null;/*from w w w . j a v a2 s . c om*/ 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:com.github.mobile.ui.ConfirmDialogFragment.java
public Dialog onCreateDialog(final Bundle savedInstanceState) { AlertDialog dialog = LightAlertDialog.create(getActivity()); dialog.setTitle(getTitle());//from w w w. j av a2 s. c om dialog.setMessage(getMessage()); dialog.setButton(BUTTON_POSITIVE, getResources().getString(android.R.string.yes), this); dialog.setButton(BUTTON_NEGATIVE, getResources().getString(android.R.string.no), this); dialog.setCancelable(true); dialog.setOnCancelListener(this); return dialog; }
From source file:com.jonathongrigg.apps.spark.MainActivity.java
public void showAboutDialog() { final AlertDialog aboutDialog = new AlertDialog.Builder(this).create(); aboutDialog.setTitle(this.getText(R.string.dialog_title)); aboutDialog.setMessage(this.getText(R.string.dialog_text)); aboutDialog.setIcon(R.drawable.ic_menu_info_details); aboutDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { aboutDialog.dismiss();//from ww w .j a v a 2 s.co m } }); aboutDialog.show(); }
From source file:com.github.mobile.ui.DialogFragmentHelper.java
/** * Create default dialog/*from ww w .j a v a2 s . co m*/ * * @return dialog */ protected AlertDialog createDialog() { final AlertDialog dialog = LightAlertDialog.create(getActivity()); dialog.setTitle(getTitle()); dialog.setMessage(getMessage()); dialog.setCancelable(true); dialog.setOnCancelListener(this); return dialog; }
From source file:com.secbro.qark.customintent.ChooseIntentUseCaseActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // Check which request we're responding to if (requestCode == START_ACTIVITY_FOR_RESULT) { // Make sure the request was successful if (resultCode == RESULT_OK) { AlertDialog result = new AlertDialog.Builder(this).create(); result.setTitle("Result from startActivityForResult()"); result.setMessage(data.getDataString()); result.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss();//from w w w . j a v a 2 s . co m } }); result.show(); } } }
From source file:at.jclehner.androidutils.AlertDialogFragment.java
public void setMessage(CharSequence message) { mMessage = message;/* w ww. j a v a 2 s. c om*/ final AlertDialog dialog = getDialog(); if (dialog == null) return; dialog.setMessage(message); }
From source file:com.danvelazco.fbwrapper.preferences.FacebookPreferences.java
/** * Show an alert dialog with the information about the application. */// w w w.j a va 2 s . co m private void showAboutAlert() { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle(getString(R.string.menu_about)); alertDialog.setMessage(getString(R.string.txt_about)); alertDialog.setIcon(R.drawable.ic_launcher); alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.lbl_dialog_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Don't do anything, simply close the dialog } }); alertDialog.show(); }