2022-10-02 23:06:56 +02:00
|
|
|
package android.app;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
|
2023-08-10 11:06:02 +02:00
|
|
|
public class AlertDialog extends Dialog implements DialogInterface {
|
|
|
|
|
|
|
|
|
|
private native void nativeSetMessage(long ptr, String message);
|
|
|
|
|
private native void nativeSetButton(long ptr, int whichButton, String text);
|
|
|
|
|
private native void nativeSetItems(long ptr, String[] items, DialogInterface.OnClickListener listener);
|
|
|
|
|
|
|
|
|
|
public AlertDialog(Context context) {
|
2023-08-23 09:16:45 +02:00
|
|
|
super(context, 0);
|
2023-08-10 11:06:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setMessage(CharSequence message) {
|
|
|
|
|
System.out.println("AlertDialog setMessage called with: '" + message + "'");
|
|
|
|
|
nativeSetMessage(nativePtr, String.valueOf(message));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setButton(int whichButton, CharSequence text, OnClickListener listener) {
|
|
|
|
|
nativeSetButton(nativePtr, whichButton, String.valueOf(text));
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-02 23:06:56 +02:00
|
|
|
public static class Builder {
|
2023-08-10 11:06:02 +02:00
|
|
|
private AlertDialog dialog;
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public Builder(Context context) {
|
2022-10-02 23:06:56 +02:00
|
|
|
System.out.println("making an AlertDialog$Builder as we speak, my word!");
|
2023-08-10 11:06:02 +02:00
|
|
|
dialog = new AlertDialog(context);
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public AlertDialog.Builder setPositiveButton(int textId, DialogInterface.OnClickListener listener) {
|
2023-08-23 09:16:45 +02:00
|
|
|
return setPositiveButton(dialog.getContext().getText(textId), listener);
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public AlertDialog.Builder setPositiveButton(CharSequence text, DialogInterface.OnClickListener listener) {
|
2023-07-25 14:29:43 +02:00
|
|
|
System.out.println("AlertDialog.Builder setPositiveButton called with text: '" + text + "'");
|
2023-08-10 11:06:02 +02:00
|
|
|
dialog.setButton(DialogInterface.BUTTON_POSITIVE, text, listener);
|
2022-10-02 23:06:56 +02:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public AlertDialog.Builder setCancelable(boolean cancelable) {
|
2022-10-02 23:06:56 +02:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public AlertDialog.Builder setIcon(int iconId) {
|
2022-10-02 23:06:56 +02:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public AlertDialog.Builder setTitle(CharSequence title) {
|
|
|
|
|
System.out.println("AlertDialog.Builder setTitle called with: '" + title + "'");
|
2023-08-10 11:06:02 +02:00
|
|
|
dialog.setTitle(title);
|
2022-10-02 23:06:56 +02:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-10 11:06:02 +02:00
|
|
|
public AlertDialog.Builder setTitle(int title) {
|
2023-08-23 09:16:45 +02:00
|
|
|
return setTitle(dialog.getContext().getText(title));
|
2023-08-10 11:06:02 +02:00
|
|
|
}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public AlertDialog.Builder setMessage(CharSequence message) {
|
|
|
|
|
System.out.println("AlertDialog.Builder setMessage called with: '" + message + "'");
|
2023-08-10 11:06:02 +02:00
|
|
|
dialog.setMessage(message);
|
2022-10-02 23:06:56 +02:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 11:45:46 +02:00
|
|
|
public AlertDialog.Builder setView(View view) {
|
2022-10-02 23:06:56 +02:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-10 11:06:02 +02:00
|
|
|
public AlertDialog.Builder setItems(CharSequence[] items, final DialogInterface.OnClickListener listener) {
|
|
|
|
|
String[] stringItems = new String[items.length];
|
|
|
|
|
for (int i = 0; i < items.length; i++) {
|
|
|
|
|
stringItems[i] = String.valueOf(items[i]);
|
|
|
|
|
}
|
|
|
|
|
dialog.nativeSetItems(dialog.nativePtr, stringItems, listener);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Builder setOnCancelListener(OnCancelListener onCancelListener) {
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-02 23:06:56 +02:00
|
|
|
public AlertDialog create() {
|
2023-08-10 11:06:02 +02:00
|
|
|
return dialog;
|
2022-10-02 23:06:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|