下面列出了android.app.AlertDialog#setMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void onEnterStartedState() {
Log.d(TAG, "call onEnterStartedState");
/* Connect camera */
if (!connectCamera(getWidth(), getHeight())) {
AlertDialog ad = new AlertDialog.Builder(getContext()).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
((Activity) getContext()).finish();
}
});
ad.show();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.about) {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(getString(R.string.app_name));
alertDialog.setIcon(android.R.drawable.ic_dialog_info);
alertDialog.setMessage("Developed by Basilis Charalampakis\n\n" +
"GitHub : http://github.com/charbgr\n" +
"Linkedin : http://linkedin.com/in/charalampakisbasilis/");
alertDialog.show();
return true;
}
return super.onOptionsItemSelected(item);
}
private void onEnterStartedState() {
Log.d(TAG, "call onEnterStartedState");
/* Connect camera */
if (!connectCamera(getWidth(), getHeight())) {
AlertDialog ad = new AlertDialog.Builder(getContext()).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
((Activity) getContext()).finish();
}
});
ad.show();
}
}
public static void alert(final Object context,
final String message, final String title,final String buttonText) {
Log.i("RuntimeErrorAlert", "in alert");
AlertDialog alertDialog = new AlertDialog.Builder((Context) context).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
alertDialog.setButton(buttonText, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
((Activity) context).finish();
}});
if (message == null) {
// Avoid passing null to Log.e, which would cause a NullPointerException.
Log.e(RuntimeErrorAlert.class.getName(), "No error message available");
} else {
Log.e(RuntimeErrorAlert.class.getName(), message);
}
alertDialog.show();
}
/**
* Show dialog with rationale for required permissions
*
* @param activity calling activity which the AlertDialog is shown on (PermissionsActivity)
* @return the dialog that is shown
*/
private static AlertDialog showRequiredPermissionRationale(final Activity activity) {
final AlertDialog
alertDialog = new AlertDialog.Builder(activity).create();
alertDialog.setTitle(activity.getString(R.string.title_activity_permissions));
alertDialog.setMessage(activity.getString(R.string.initial_permissions_required));
alertDialog.setButton(android.support.v7.app.AlertDialog.BUTTON_NEUTRAL,
activity.getString(R.string.ask_me_again),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
requestRequiredPermissions(activity, true);
}
});
alertDialog.setCancelable(false);
alertDialog.show();
return alertDialog;
}
private void onEnterStartedState() {
Log.d(TAG, "call onEnterStartedState");
/* Connect camera */
if (!connectCamera(getWidth(), getHeight())) {
AlertDialog ad = new AlertDialog.Builder(getContext()).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
((Activity) getContext()).finish();
}
});
ad.show();
}
}
/**
* Show rationale for storage permissions
*
* @param activity the activity to show the rationale on (PlaybackActivity)
*/
private static void showStoragePermissionRationale(final Activity activity) {
final AlertDialog
alertDialog = new AlertDialog.Builder(activity).create();
alertDialog.setMessage(activity.getString(R.string.storage_permission_rationale));
alertDialog.setButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE,
activity.getString(R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
requestStoragePermission(activity, true);
}
});
alertDialog.show();
}
@Override
public void onBackPressed() {
if (core != null && core.hasChanges()) {
mAlertBuilder = new AlertDialog.Builder(mContext);
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == AlertDialog.BUTTON_POSITIVE)
core.save();
finish();
}
};
AlertDialog alert = mAlertBuilder.create();
alert.setTitle("MuPDF");
alert.setMessage(getString(R.string.document_has_changes_save_them_));
alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.yes), listener);
alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.no), listener);
alert.show();
} else {
super.onBackPressed();
}
}
private void onEnterStartedState() {
Log.d(TAG, "call onEnterStartedState");
/* Connect camera */
if (!connectCamera(getWidth(), getHeight())) {
AlertDialog ad = new AlertDialog.Builder(getContext()).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
((Activity) getContext()).finish();
}
});
ad.show();
}
}
private void onEnterStartedState() {
Log.d(TAG, "call onEnterStartedState");
/* Connect camera */
if (!connectCamera(getWidth(), getHeight())) {
AlertDialog ad = new AlertDialog.Builder(getContext()).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
((Activity) getContext()).finish();
}
});
ad.show();
}
}
private void onEnterStartedState() {
Log.d(TAG, "call onEnterStartedState");
/* Connect camera */
if (!connectCamera(getWidth(), getHeight())) {
AlertDialog ad = new AlertDialog.Builder(getContext()).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
((Activity) getContext()).finish();
}
});
ad.show();
}
}
private void onEnterStartedState() {
Log.d(TAG, "call onEnterStartedState");
/* Connect camera */
if (!connectCamera(getWidth(), getHeight())) {
AlertDialog ad = new AlertDialog.Builder(getContext()).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
((Activity) getContext()).finish();
}
});
ad.show();
}
}
private void onEnterStartedState() {
Log.d(TAG, "call onEnterStartedState");
/* Connect camera */
if (!connectCamera(getWidth(), getHeight())) {
AlertDialog ad = new AlertDialog.Builder(getContext()).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
((Activity) getContext()).finish();
}
});
ad.show();
}
}
private void onEnterStartedState() {
Log.d(TAG, "call onEnterStartedState");
/* Connect camera */
if (!connectCamera(getWidth(), getHeight())) {
AlertDialog ad = new AlertDialog.Builder(getContext()).create();
ad.setCancelable(false); // This blocks the 'BACK' button
ad.setMessage("It seems that you device does not support camera (or it is locked). Application will be closed.");
ad.setButton(DialogInterface.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
((Activity) getContext()).finish();
}
});
ad.show();
}
}
static void about(Context context) {
final SpannableString s = new SpannableString(
context.getText(R.string.aboutText));
Linkify.addLinks(s, Linkify.ALL);
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle(context.getText(R.string.aboutTitle));
alertDialog.setMessage(s);
alertDialog.setButton(DialogInterface.BUTTON_NEUTRAL,
context.getText(R.string.aboutCloseButton),
new Dialog.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog,
final int which) {
try {
finalize();
} catch (final Throwable e) {
e.printStackTrace();
}
}
});
alertDialog.show();
((TextView) alertDialog.findViewById(android.R.id.message))
.setMovementMethod(mMovementCheck);
}
@SuppressWarnings("deprecation")
@Override
protected void onPrepareDialog(int id, Dialog dialog, Bundle bundle) {
if (id == DIALOG_CONFIRM_DRIVE_SYNC_ON) {
AlertDialog alertDialog = (AlertDialog) dialog;
String googleAccount = PreferencesUtils.getString(
this, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
alertDialog.setMessage(getString(R.string.sync_drive_confirm_message, googleAccount,
getString(R.string.my_tracks_app_name)));
}
super.onPrepareDialog(id, dialog, bundle);
}
public void showAlertDialog(Context context, String title, String message) {
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle(title);
alertDialog.setMessage(message);
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
public void preparePatchInfo(AlertDialog dialog, ContentListItem patch) {
dialog.setTitle(patch.toString(getResources()));
String patchInfo;
try {
patchInfo = getPatchInfo(patch);
} catch (Exception e) {
patchInfo = "Cannot show info: " + e.getStackTrace();
}
dialog.setMessage(patchInfo);
}
public void saveUser(String result) {
ResultOfEnroll resultOfEnroll = gson.fromJson(result, ResultOfEnroll.class);
Log.d(TAG, resultOfEnroll.result.user);
editor = sharedPreferences.edit();
editor.putString("BlockchainUserId",resultOfEnroll.result.user);
editor.apply();
sendToMongo(resultOfEnroll.result.user);
// send user id to registeree-api
// save the user name
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Enrollment successful!");
alertDialog.setMessage("You have been enrolled to the blockchain network. Your User ID is:\n\n" + resultOfEnroll.result.user);
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "CONFIRM",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
public static void confirm(String message, Activity activity, Boolean cancelable, DialogInterface.OnClickListener listener) {
AlertDialog dialog = new AlertDialog.Builder(activity).create();
dialog.setTitle(activity.getString(R.string.title));
dialog.setMessage(message);
dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", listener);
dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "NO", listener);
if(cancelable){dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Cancel",listener);}
dialog.show();
}