1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| public class AlertOneItem { private Context context; private String title; private String message; private Consumer<Boolean> consumer; private String positiveTips = "确定"; private String negativeTips = "取消";
private AlertOneItem(Context context, Consumer<Boolean> consumer) { this.context = context; this.consumer = consumer; }
public static AlertOneItem builder(Context context, Consumer<Boolean> consumer) { return new AlertOneItem(context, consumer); }
public AlertOneItem title(String title) { this.title = title; return this; }
public AlertOneItem message(String message) { this.message = message; return this; }
public AlertOneItem positiveTips(String positiveTips) { this.positiveTips = positiveTips; return this; }
public AlertOneItem negativeTips(String negativeTips) { this.negativeTips = negativeTips; return this; }
public void show() { AlertDialog.Builder builder = new AlertDialog.Builder(context); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } if (!TextUtils.isEmpty(message)) { builder.setMessage(message); } if (!TextUtils.isEmpty(negativeTips)) { builder.setNegativeButton(negativeTips, (dialog, which) -> consumer.accept(false)); }
if (!TextUtils.isEmpty(positiveTips)) { builder.setPositiveButton(positiveTips, (dialog, which) -> consumer.accept(true)); }
builder.setCancelable(true); builder.create(); builder.show(); } }
Udialog.AlertOneItem.builder(context, result -> { if (result) { toSetWallpaperAsync(context, imageView, color); } }).message("设置成壁纸?").show();
|