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:org.ednovo.goorusearchwidget.SearchResults_resource.java

/**
 * @function name : showDialog// w  w w . j  av  a2  s.  c om
 * 
 *           This function is used to show alert dialog
 * 
 * @param String
 *            message to show
 * 
 * @return void
 * 
 * 
 */

public void showDialog(String data) {

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
    alertDialog.setMessage(data).setCancelable(false).setPositiveButton("Ok",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // dialog.cancel();

                    dialog.cancel();
                }
            });
    AlertDialog alert = alertDialog.create();
    // Title for AlertDialog
    alert.setTitle(" Info ");

    alert.show();
}

From source file:cm.aptoide.pt.ApkInfo.java

public void loadMalware(final MalwareStatus malwareStatus) {
    runOnUiThread(new Runnable() {

        @Override//from  w  w w . j av a  2 s .  c o m
        public void run() {
            try {
                EnumApkMalware apkStatus = EnumApkMalware
                        .valueOf(malwareStatus.getStatus().toUpperCase(Locale.ENGLISH));
                Log.d("ApkInfoMalware-malwareStatus", malwareStatus.getStatus());
                Log.d("ApkInfoMalware-malwareReason", malwareStatus.getReason());

                switch (apkStatus) {
                case SCANNED:
                    ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.trusted));
                    ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_scanned);
                    ((LinearLayout) findViewById(R.id.badge_layout)).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            View trustedView = LayoutInflater.from(ApkInfo.this)
                                    .inflate(R.layout.dialog_anti_malware, null);
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ApkInfo.this)
                                    .setView(trustedView);
                            final AlertDialog trustedDialog = dialogBuilder.create();
                            trustedDialog.setIcon(R.drawable.badge_scanned);
                            trustedDialog.setTitle(getString(R.string.app_trusted, viewApk.getName()));
                            trustedDialog.setCancelable(true);

                            TextView tvSignatureValidation = (TextView) trustedView
                                    .findViewById(R.id.tv_signature_validation);
                            tvSignatureValidation.setText(getString(R.string.signature_verified));
                            ImageView check_signature = (ImageView) trustedView
                                    .findViewById(R.id.check_signature);
                            check_signature.setImageResource(R.drawable.ic_yes);

                            trustedDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    trustedDialog.dismiss();
                                }
                            });
                            trustedDialog.show();
                        }
                    });
                    break;
                //             case UNKNOWN:
                //                ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.unknown));
                //                ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_unknown);
                //                break;
                case WARN:
                    ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.warning));
                    ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_warn);
                    ((LinearLayout) findViewById(R.id.badge_layout)).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            View warnView = LayoutInflater.from(ApkInfo.this)
                                    .inflate(R.layout.dialog_anti_malware, null);
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ApkInfo.this)
                                    .setView(warnView);
                            final AlertDialog warnDialog = dialogBuilder.create();
                            warnDialog.setIcon(R.drawable.badge_warn);
                            warnDialog.setTitle(getString(R.string.app_warning, viewApk.getName()));
                            warnDialog.setCancelable(true);

                            TextView tvSignatureValidation = (TextView) warnView
                                    .findViewById(R.id.tv_signature_validation);
                            tvSignatureValidation.setText(getString(R.string.signature_not_verified));
                            ImageView check_signature = (ImageView) warnView.findViewById(R.id.check_signature);
                            check_signature.setImageResource(R.drawable.ic_failed);

                            warnDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    warnDialog.dismiss();
                                }
                            });
                            warnDialog.show();
                        }
                    });
                    break;
                //             case CRITICAL:
                //                ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.critical));
                //                ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_critical);
                //                break;
                default:
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    });

}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Renames a sourceItem/*from  w w  w.  j a va 2  s.  c  om*/
 * @param sourceItem The sourceItem to rename
 */
private void renameItem(final Item sourceItem) {
    final Activity activity = getActivity();
    final EditText newName = new EditText(activity);
    newName.setInputType(InputType.TYPE_CLASS_TEXT);
    newName.setHint(sourceItem.name);
    final AlertDialog alertDialog = new AlertDialog.Builder(activity).setTitle(R.string.rename)
            .setIcon(android.R.drawable.ic_menu_edit).setView(newName)
            .setPositiveButton(R.string.rename, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    final ICallback<Item> callback = new DefaultCallback<Item>(getActivity()) {
                        @Override
                        public void success(final Item item) {
                            Toast.makeText(activity,
                                    activity.getString(R.string.renamed_item, sourceItem.name, item.name),
                                    Toast.LENGTH_LONG).show();
                            refresh();
                            dialog.dismiss();
                        }

                        @Override
                        public void failure(final ClientException error) {
                            Toast.makeText(activity, activity.getString(R.string.rename_error, sourceItem.name),
                                    Toast.LENGTH_LONG).show();
                            dialog.dismiss();
                        }
                    };
                    Item updatedItem = new Item();
                    updatedItem.id = sourceItem.id;
                    updatedItem.name = newName.getText().toString();
                    ((BaseApplication) activity.getApplication()).getOneDriveClient().getDrive()
                            .getItems(updatedItem.id).buildRequest().update(updatedItem, callback);
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.cancel();
                }
            }).create();
    alertDialog.show();
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Creates a folder//  w w w. ja  v  a 2  s  . c o m
 * @param item The parent of the folder to create
 */
private void createFolder(final Item item) {
    final Activity activity = getActivity();
    final EditText newName = new EditText(activity);
    newName.setInputType(InputType.TYPE_CLASS_TEXT);
    newName.setHint(activity.getString(R.string.new_folder_hint));

    final AlertDialog alertDialog = new AlertDialog.Builder(activity).setTitle(R.string.create_folder)
            .setView(newName).setIcon(android.R.drawable.ic_menu_add)
            .setPositiveButton(R.string.create_folder, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    final ICallback<Item> callback = new DefaultCallback<Item>(activity) {
                        @Override
                        public void success(final Item createdItem) {
                            Toast.makeText(activity,
                                    activity.getString(R.string.created_folder, createdItem.name, item.name),
                                    Toast.LENGTH_LONG).show();
                            refresh();
                            dialog.dismiss();
                        }

                        @Override
                        public void failure(final ClientException error) {
                            super.failure(error);
                            Toast.makeText(activity, activity.getString(R.string.new_folder_error, item.name),
                                    Toast.LENGTH_LONG).show();
                            dialog.dismiss();
                        }
                    };

                    final Item newItem = new Item();
                    newItem.name = newName.getText().toString();
                    newItem.folder = new Folder();

                    ((BaseApplication) activity.getApplication()).getOneDriveClient().getDrive()
                            .getItems(mItemId).getChildren().buildRequest().create(newItem, callback);
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.cancel();
                }
            }).create();
    alertDialog.show();
}

From source file:com.max2idea.android.limbo.main.LimboActivity.java

public static void UIAlert(String title, String body, Activity activity) {
    AlertDialog ad;
    ad = new AlertDialog.Builder(activity).create();
    ad.setTitle(title);//from  w  w  w .  ja  va2 s  .  c om
    ad.setMessage(body);
    ad.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    });
    ad.show();
}

From source file:com.altcanvas.twitspeak.TwitSpeakActivity.java

public boolean checkStackTrace() {
    FileInputStream traceIn = null;
    try {/*from w w  w.j ava  2 s.  com*/
        traceIn = openFileInput("stack.trace");
        traceIn.close();
    } catch (FileNotFoundException fnfe) {
        // No stack trace available
        return false;
    } catch (IOException ioe) {
        return false;
    }

    AlertDialog alert = new AlertDialog.Builder(this).create();
    alert.setMessage(getResources().getString(R.string.crashreport_msg));

    alert.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.emailstr),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    String trace = "";
                    String line = null;
                    try {
                        BufferedReader reader = new BufferedReader(
                                new InputStreamReader(TwitSpeakActivity.this.openFileInput("stack.trace")));
                        while ((line = reader.readLine()) != null) {
                            trace += line + "\n";
                        }
                    } catch (FileNotFoundException fnfe) {
                        Log.logException(TAG, fnfe);
                    } catch (IOException ioe) {
                        Log.logException(TAG, ioe);
                    }

                    Intent sendIntent = new Intent(Intent.ACTION_SEND);
                    String subject = "Error report";
                    String body = getResources().getString(R.string.mailthisto_msg) + " jayesh@altcanvas.com: "
                            + "\n\n" + G.getPhoneInfo() + "\n\n" + "TwitSpeak [" + G.VERSION_STRING + "]"
                            + "\n\n" + trace + "\n\n";

                    sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "jayesh@altcanvas.com" });
                    sendIntent.putExtra(Intent.EXTRA_TEXT, body);
                    sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                    sendIntent.setType("message/rfc822");

                    TwitSpeakActivity.this.startActivityForResult(
                            Intent.createChooser(sendIntent, getResources().getString(R.string.emailstr)),
                            G.REQCODE_EMAIL_STACK_TRACE);

                    TwitSpeakActivity.this.deleteFile("stack.trace");
                }
            });
    alert.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancelstr),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    TwitSpeakActivity.this.deleteFile("stack.trace");
                    TwitSpeakActivity.this.continueOnCreate();
                }
            });

    alert.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            TwitSpeakActivity.this.deleteFile("stack.trace");
            TwitSpeakActivity.this.continueOnCreate();
        }
    });

    alert.show();

    return true;
}

From source file:com.updetector.MainActivity.java

/** Make sure that GPS is enabled */
public void checkGPSEnabled() {
    if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        Log.e(LOG_TAG, "GPS not enabled yet");
        /** Ask user to enable GPS */
        final AlertDialog enableGPS = new AlertDialog.Builder(this)
                .setTitle(Constants.APP_NAME + " needs access to GPS. Please enable GPS.")
                .setPositiveButton("Press here to enable GPS", new DialogInterface.OnClickListener() {
                    public void onClick(final DialogInterface dialog, final int id) {
                        startActivityForResult(
                                new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS),
                                Constants.SENSOR_GPS);
                    }// ww w . j  ava 2s  . c  om
                }).setCancelable(false).create();
        /*.setNegativeButton("Skip", new DialogInterface.OnClickListener() {
           public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
           }
        })*/

        enableGPS.show();
    } else {
        Log.e(LOG_TAG, "GPS already enabled");
        //GPS already enabled
        checkBluetoothEnabled();
    }
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Creates and shows a custom Alert dialog that will execute
 * the actions specified for positive, negative and 
 * neutral buttons./*from   ww  w  .j  av a2s.c o m*/
 * 
 * @param context
 * @param title
 * @param message
 * @param positiveBtnActions   Can be null. When null button is not shown.
 * @param negativeBtnActions   Can be null. When null button is not shown.
 * @param neutralBtnActions   Can be null.
 */
public static void dialog_showCustomActionsDialog(Context context, String title, String message,
        String positiveBtnText, final Runnable positiveBtnActions, String negativeBtnText,
        final Runnable negativeBtnActions, String neutralBtnText, final Runnable neutralBtnActions) {

    AlertDialog dialog = new AlertDialog.Builder(context).create();

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

    dialog.setCancelable(true);
    dialog.setButton(AlertDialog.BUTTON_NEUTRAL, neutralBtnText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            if (neutralBtnActions != null) {
                neutralBtnActions.run();
            }
            dialog.dismiss();
        }
    });

    if (negativeBtnActions != null) {
        dialog.setButton(AlertDialog.BUTTON_NEGATIVE, negativeBtnText, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                negativeBtnActions.run();
            }
        });
    }

    if (positiveBtnActions != null) {
        dialog.setButton(AlertDialog.BUTTON_POSITIVE, positiveBtnText, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                positiveBtnActions.run();
            }
        });
    }

    dialog.show();
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Creates a link on this item//from ww  w  . j  a v  a  2  s.  c om
 * @param item The item to delete
 */
private void createLink(final Item item) {
    final CharSequence[] items = { "view", "edit" };
    final int nothingSelected = -1;
    final AtomicInteger selection = new AtomicInteger(nothingSelected);
    final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.create_link)
            .setIcon(android.R.drawable.ic_menu_share)
            .setPositiveButton(R.string.create_link, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    if (selection.get() == nothingSelected) {
                        return;
                    }

                    final BaseApplication application = (BaseApplication) getActivity().getApplication();
                    application.getOneDriveClient().getDrive().getItems(item.id)
                            .getCreateLink(items[selection.get()].toString()).buildRequest()
                            .create(new DefaultCallback<Permission>(getActivity()) {
                                @Override
                                public void success(final Permission permission) {
                                    final ClipboardManager cm = (ClipboardManager) getActivity()
                                            .getSystemService(Context.CLIPBOARD_SERVICE);
                                    final ClipData data = ClipData.newPlainText("Link Url",
                                            permission.link.webUrl);
                                    cm.setPrimaryClip(data);
                                    Toast.makeText(getActivity(), application.getString(R.string.created_link),
                                            Toast.LENGTH_LONG).show();
                                    getActivity().onBackPressed();
                                }
                            });
                }
            }).setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    selection.set(which);
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.cancel();
                }
            }).create();
    alertDialog.show();
}

From source file:com.max2idea.android.limbo.main.LimboActivity.java

public static void UIAlertHtml(String title, String html, Activity activity) {

    AlertDialog alertDialog;
    alertDialog = new AlertDialog.Builder(activity).create();
    alertDialog.setTitle(title);//from  w ww.  ja  v a 2  s . co m
    WebView webview = new WebView(activity);
    webview.setBackgroundColor(Color.BLACK);
    webview.loadData("<font color=\"FFFFFF\">" + html + " </font>", "text/html", "UTF-8");
    alertDialog.setView(webview);
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    });
    alertDialog.show();
}