refactor Dialog implementation to support custom content

This commit is contained in:
Julian Winkler
2023-08-23 10:32:29 +02:00
parent 029b26beb2
commit 0f7548f189
7 changed files with 106 additions and 73 deletions

View File

@@ -2,28 +2,16 @@ package android.app;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
public class AlertDialog extends Dialog implements DialogInterface {
private long nativePtr;
private native long nativeInit();
private native void nativeSetTitle(long ptr, String title);
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);
private native void nativeShow(long ptr);
public AlertDialog(Context context) {
super(context, 0);
nativePtr = nativeInit();
}
public void setTitle(CharSequence title) {
nativeSetTitle(nativePtr, String.valueOf(title));
}
public void setMessage(CharSequence message) {
@@ -35,21 +23,6 @@ public class AlertDialog extends Dialog implements DialogInterface {
nativeSetButton(nativePtr, whichButton, String.valueOf(text));
}
public boolean isShowing() {
return false;
}
@Override
public void show() {
super.show();
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
nativeShow(nativePtr);
}
});
}
public static class Builder {
private AlertDialog dialog;

View File

@@ -3,14 +3,23 @@ package android.app;
import android.content.Context;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
public class Dialog {
protected long nativePtr;
private native long nativeInit();
private native void nativeSetTitle(long ptr, String title);
private native void nativeSetContentView(long ptr, long widget);
private native void nativeShow(long ptr);
private Context context;
public Dialog(Context context, int themeResId) {
this.context = context;
nativePtr = nativeInit();
}
public final boolean requestWindowFeature(int featureId) {
@@ -21,7 +30,13 @@ public class Dialog {
return context;
}
public void setContentView(View view) {}
public void setContentView(View view) {
nativeSetContentView(nativePtr, view.widget);
}
public void setTitle(CharSequence title) {
nativeSetTitle(nativePtr, String.valueOf(title));
}
public void setOwnerActivity(Activity activity) {}
@@ -33,6 +48,16 @@ public class Dialog {
public void show() {
System.out.println("totally showing the Dialog " + this + " right now, most definitely doing that");
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
nativeShow(nativePtr);
}
});
}
public boolean isShowing() {
return false;
}
public void dismiss() {