Implement prompt() for android. #72

This commit is contained in:
Cory McWilliams 2024-08-14 12:45:22 -04:00
parent 17f4eb1a56
commit 3895c33915

View File

@ -15,6 +15,7 @@ import android.os.Parcel;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.StrictMode; import android.os.StrictMode;
import android.text.InputType;
import android.util.Base64; import android.util.Base64;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -32,6 +33,7 @@ import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest; import android.webkit.WebResourceRequest;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -192,7 +194,24 @@ public class TildeFriendsActivity extends Activity {
web_view.setWebChromeClient(new WebChromeClient() { web_view.setWebChromeClient(new WebChromeClient() {
@Override @Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
new AlertDialog.Builder(view.getContext())
.setTitle("Tilde Friends")
.setMessage(message)
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
result.confirm();
}
})
.create()
.show();
return true;
}
@Override
public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
new AlertDialog.Builder(view.getContext()) new AlertDialog.Builder(view.getContext())
.setTitle("Tilde Friends") .setTitle("Tilde Friends")
.setMessage(message) .setMessage(message)
@ -216,15 +235,27 @@ public class TildeFriendsActivity extends Activity {
} }
@Override @Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) { public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
EditText input = new EditText(view.getContext());
input.setInputType(InputType.TYPE_CLASS_TEXT);
input.setText(defaultValue);
new AlertDialog.Builder(view.getContext()) new AlertDialog.Builder(view.getContext())
.setTitle("Tilde Friends") .setTitle("Tilde Friends")
.setMessage(message) .setMessage(message)
.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() .setView(input)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener()
{ {
public void onClick(DialogInterface dialog, int which) public void onClick(DialogInterface dialog, int which)
{ {
result.confirm(); result.confirm(input.getText().toString());
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
result.cancel();
} }
}) })
.create() .create()