From 3895c33915003ee96072f8223bf90df4bc4b7f86 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 14 Aug 2024 12:45:22 -0400 Subject: [PATCH] Implement prompt() for android. #72 --- .../tildefriends/TildeFriendsActivity.java | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/android/com/unprompted/tildefriends/TildeFriendsActivity.java b/src/android/com/unprompted/tildefriends/TildeFriendsActivity.java index a117460f..56f30486 100644 --- a/src/android/com/unprompted/tildefriends/TildeFriendsActivity.java +++ b/src/android/com/unprompted/tildefriends/TildeFriendsActivity.java @@ -15,6 +15,7 @@ import android.os.Parcel; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.os.StrictMode; +import android.text.InputType; import android.util.Base64; import android.util.Log; import android.view.KeyEvent; @@ -32,6 +33,7 @@ import android.webkit.WebChromeClient; import android.webkit.WebResourceRequest; import android.webkit.WebView; import android.webkit.WebViewClient; +import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import java.io.BufferedReader; @@ -192,7 +194,24 @@ public class TildeFriendsActivity extends Activity { web_view.setWebChromeClient(new WebChromeClient() { @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()) .setTitle("Tilde Friends") .setMessage(message) @@ -216,15 +235,27 @@ public class TildeFriendsActivity extends Activity { } @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()) .setTitle("Tilde Friends") .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) { - 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()