Example usage for android.app AlertDialog.Builder show

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

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:palamarchuk.smartlife.app.RegisterActivity.java

public static void alert(Context context, String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(message);//from  w w w .  j av  a  2 s .c  o m
    builder.setTitle("");

    builder.setPositiveButton("Ok", null);
    builder.show();
}

From source file:Main.java

public static void showOkDialog(String title, String msg, Activity act) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(act);
    if (title != null) {

        TextView dialogTitle = new TextView(act);
        dialogTitle.setText(title);//from ww  w. j a v a 2  s. c  om
        dialogTitle.setPadding(10, 10, 10, 10);
        dialogTitle.setGravity(Gravity.CENTER);
        dialogTitle.setTextColor(Color.WHITE);
        dialogTitle.setTextSize(20);
        dialog.setCustomTitle(dialogTitle);

    }
    if (msg != null) {
        dialog.setMessage(msg);
    }
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub
            dialog.dismiss();
        }
    });
    AlertDialog dlg = dialog.show();
    TextView messageText = (TextView) dlg.findViewById(android.R.id.message);
    messageText.setGravity(Gravity.CENTER);

}

From source file:Main.java

public static void showGPSSettings(final Activity activity) {
    // check for internet connection
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity);
    alertDialog.setTitle("GPS adapter disabled");
    alertDialog.setMessage("GPS is not enabled. Please enable GPS");
    // Setting Positive "Yes" Button
    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            activity.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
        }/*  w w  w. ja v  a 2 s .  c o  m*/
    });
    // Setting Negative "NO" Button
    alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    // Showing Alert Message
    alertDialog.show();
}

From source file:Main.java

public static void showWifiSettings(final Activity activity, final Runnable yes, final Runnable no) {
    // check for internet connection
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity);
    alertDialog.setTitle("No Internet Connection");
    alertDialog.setMessage("Would you like to change settings ?");
    // Setting Positive "Yes" Button
    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            activity.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
            if (yes != null)
                yes.run();/*from www  .ja  va2 s  .  c  om*/
        }
    });
    // Setting Negative "NO" Button
    alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
            if (no != null)
                no.run();
        }
    });
    // Showing Alert Message
    alertDialog.show();
}

From source file:Main.java

public static void yesNoMessage(final Activity activity, final String title, final String body,
        final String yesButtonLabel, final String noButtonLabel, final Runnable yesRunnable,
        final Runnable noRunnable) {
    activity.runOnUiThread(new Runnable() {
        @Override//  w ww .  j a  v  a  2  s  . c o  m
        public void run() {

            AlertDialog.Builder dialog = new AlertDialog.Builder(activity);

            dialog.setTitle(title);
            dialog.setMessage(body);

            dialog.setPositiveButton(yesButtonLabel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    if (yesRunnable != null)
                        yesRunnable.run();
                }
            });

            dialog.setNegativeButton(noButtonLabel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    if (noRunnable != null)
                        noRunnable.run();
                }
            });

            dialog.create();
            dialog.show();
        }
    });
}

From source file:net.naonedbus.utils.InfoDialogUtils.java

/**
 * Afficher une dialog avec un contenu au format HTML
 * //  w  w  w  . j  ava2  s . com
 * @param context
 * @param html
 */
public static void showHtml(final Context context, final String html) {
    AlertDialog.Builder moreDetailsDialog = null;
    final WebView webView = new WebView(context);
    final ScrollView scrollView = new ScrollView(context);

    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webView.setBackgroundColor(Color.WHITE);
    webView.loadDataWithBaseURL("fake://not/needed", html, "text/html", "UTF-8", null); // Encoding
    // fix
    // for
    // Android
    // 3.x
    // /
    // 4.x
    scrollView.addView(webView);

    moreDetailsDialog = new AlertDialog.Builder(context);
    moreDetailsDialog.setIcon(android.R.drawable.ic_dialog_info);
    moreDetailsDialog.setTitle("Informations");
    moreDetailsDialog.setView(scrollView);
    moreDetailsDialog.setPositiveButton(android.R.string.ok, null);
    moreDetailsDialog.show();
}

From source file:Main.java

public static AlertDialog showDownloadDialog(final Context ctx) {
    AlertDialog.Builder downloadDialog = new AlertDialog.Builder(ctx);
    downloadDialog.setTitle("Layar is not available");
    downloadDialog.setMessage("Do you want to download it from the market?");
    downloadDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

        @Override/*from   w ww .j  av  a2  s. c  om*/
        public void onClick(DialogInterface dialogInterface, int i) {
            Uri uri = Uri.parse("market://details?id=com.layar");
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            try {
                ctx.startActivity(intent);
            } catch (ActivityNotFoundException anfe) {
                Toast.makeText(ctx, "Market not installed", Toast.LENGTH_SHORT).show();
            }
        }

    });

    downloadDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
        }

    });

    return downloadDialog.show();
}

From source file:li.klass.fhem.adapter.devices.genericui.AvailableTargetStatesDialogUtil.java

public static <D extends FhemDevice<D>> boolean handleSelectedOption(final Context context, final D device,
        String option, TargetStateSelectedCallback callback) {
    final TypeHandler<D> typeHandler = handlerForSelectedOption(device, context, option, callback);
    if (typeHandler == null) {
        return true;
    }/*from w w w. j  a v a  2s. c om*/
    final View view = typeHandler.getContentViewFor(context, device);
    AlertDialog.Builder builder = new AlertDialog.Builder(context).setTitle(R.string.stateAppendix)
            .setView(view).setNegativeButton(R.string.cancelButton, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                }
            });

    if (typeHandler.requiresPositiveButton()) {
        builder.setPositiveButton(R.string.okButton, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                if (typeHandler.onPositiveButtonClick(view, context, device)) {
                    dialog.dismiss();
                }
            }
        });
    }

    AlertDialog subDialog = builder.show();
    typeHandler.setDialog(subDialog);
    return false;
}

From source file:com.spoiledmilk.ibikecph.util.Util.java

public static void showLanguageDialog(final Activity activity) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(IbikeApplication.getString("choose_language"));
    builder.setItems(IbikePreferences.getLanguageNames(), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            ((IbikeApplication) activity.getApplication()).changeLanguage(Language.values()[item + 1]);
            ((iLanguageListener) activity).reloadStrings();
            dialog.dismiss();//from  w w  w . j ava2  s . c  om
        }
    });
    builder.setPositiveButton(IbikeApplication.getString("Cancel"), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    builder.show();
}

From source file:ch.prokopovi.ui.main.AboutFragment.java

@Click(R.id.bAboutNotice)
void noticeClick() {
    Context ctx = this.getActivity();

    String licenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(ctx);
    AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(ctx);
    LicenseDialog.setTitle(R.string.btn_about_notice);
    LicenseDialog.setMessage(licenseInfo);
    LicenseDialog.show();
}