You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
refactor Dialog implementation to support custom content
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user