Example usage for android.app AlertDialog setCancelable

List of usage examples for android.app AlertDialog setCancelable

Introduction

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

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:Main.java

public static void showAlertDialog(Context context, String title, String message) {
    AlertDialog dialog = new AlertDialog.Builder(context).create();
    dialog.setCancelable(true);
    dialog.setMessage(message);/*from  w  w  w.j a  v a 2s . c  o  m*/
    dialog.setTitle(title);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    dialog.show();
}

From source file:Main.java

public static void showMsgBox(Context c, String title, String msg) {
    AlertDialog ad = new AlertDialog.Builder(c).create();
    ad.setCancelable(false); // This blocks the 'BACK' button
    ad.setMessage(msg);//w w w .  ja va2  s  .c o  m
    ad.setTitle(title);
    ad.setButton(OK, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    ad.show();
}

From source file:com.crea_si.eviacam.wizard.WizardUtils.java

static void checkEngineAndFinishIfNeeded(final Activity a) {
    AccessibilityServiceModeEngine engine = MainEngine.getAccessibilityServiceModeEngine();
    if (engine == null || !engine.isReady()) {
        // Engine is not ready anymore
        final Resources res = a.getResources();
        AlertDialog ad = new AlertDialog.Builder(a).create();
        ad.setCancelable(false); // This blocks the 'BACK' button
        ad.setTitle(res.getText(R.string.eva_not_running));
        ad.setMessage(res.getText(R.string.eva_not_running_summary));
        ad.setButton(DialogInterface.BUTTON_NEUTRAL, res.getText(R.string.close),
                new DialogInterface.OnClickListener() {
                    @Override/*from  w  ww .j  a  v a 2  s  .  c o m*/
                    public void onClick(DialogInterface dialog, int which) {
                        finishWizard(a);
                    }
                });
        ad.show();
    }
}

From source file:com.cranberrygame.cordova.plugin.ad.adbuddiz.Util.java

public static void alert(Activity activity, String message) {
    AlertDialog ad = new AlertDialog.Builder(activity).create();
    ad.setCancelable(false); // This blocks the 'BACK' button  
    ad.setMessage(message);// w ww.  j  a v  a 2s .  c o  m
    ad.setButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    ad.show();
}

From source file:org.rm3l.ddwrt.utils.Utils.java

@NotNull
public static AlertDialog buildAlertDialog(@NotNull final Context context, @Nullable final String title,
        @NotNull final String msg, final boolean cancelable, final boolean cancelableOnTouchOutside) {
    @NotNull
    final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
    if (!Strings.isNullOrEmpty(title)) {
        alertDialog.setTitle(title);/*from   w ww . j av a 2s  .  co m*/
    }
    alertDialog.setMessage(msg);
    alertDialog.setCancelable(cancelable);
    alertDialog.setCanceledOnTouchOutside(cancelableOnTouchOutside);

    return alertDialog;
}

From source file:de.wikilab.android.friendica01.Max.java

public static void alert(Context ctx, String text, String title, String okButtonText) {
    AlertDialog ad = new AlertDialog.Builder(ctx).create();
    ad.setCancelable(false); // This blocks the 'BACK' button  
    ad.setMessage(Html.fromHtml(text));//  w ww  .j  av  a  2s .c  om
    ad.setTitle(title);
    ad.setButton(okButtonText, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    ad.show();
    ((TextView) ad.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.spoiledmilk.cykelsuperstier.navigation.SMRouteNavigationActivity.java

public static void showRouteNoBreakDialog(final Context context, AlertDialog dialog) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(CykelsuperstierApplication.getString("no_route"));
    builder.setMessage(CykelsuperstierApplication.getString("cannot_broken"));
    builder.setPositiveButton("OK", new OnClickListener() {
        @Override/*from  w w  w .  j  a v  a  2  s  . c  o  m*/
        public void onClick(DialogInterface dialog, int arg1) {
            dialog.dismiss();
        }
    });
    dialog = builder.create();
    dialog.setCancelable(false);
    dialog.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);/*  w  ww.  ja  v a2 s.co m*/
    alert.setMessage(Message);
    alert.setCancelable(false);
    alert.show();

}

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

/**
 * This function is used to print a java bitmap directly to a portable
 * printer./*from   ww w. j a va  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
 * //from w  ww . j a v  a 2s. 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:<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) {
            }
        }
    }
}