Repository navigation
Expand file tree
/
Copy pathEnhancedWebChromeClient.java
More file actions
75 lines (65 loc) · 2.51 KB
/
Copy pathEnhancedWebChromeClient.java
File metadata and controls
75 lines (65 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.viaadvancedbrowser.browser;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import androidx.appcompat.app.AppCompatActivity;
public class EnhancedWebChromeClient extends WebChromeClient {
private AppCompatActivity activity;
public EnhancedWebChromeClient(AppCompatActivity activity) {
this.activity = activity;
}
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
// Handle JavaScript alerts
new android.app.AlertDialog.Builder(activity)
.setTitle("Alert")
.setMessage(message)
.setPositiveButton("OK", (dialog, which) -> result.confirm())
.setCancelable(false)
.create()
.show();
return true;
}
@Override
public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
new android.app.AlertDialog.Builder(activity)
.setTitle("Confirm")
.setMessage(message)
.setPositiveButton("OK", (dialog, which) -> result.confirm())
.setNegativeButton("Cancel", (dialog, which) -> result.cancel())
.setCancelable(false)
.create()
.show();
return true;
}
@Override
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
// Handle JavaScript prompts
final android.widget.EditInput input = new android.widget.EditText(activity);
input.setText(defaultValue);
new android.app.AlertDialog.Builder(activity)
.setTitle("Prompt")
.setMessage(message)
.setView(input)
.setPositiveButton("OK", (dialog, which) -> result.confirm(input.getText().toString()))
.setNegativeButton("Cancel", (dialog, which) -> result.cancel())
.setCancelable(false)
.create()
.show();
return true;
}
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
// Update progress bar if needed
activity.setProgress(newProgress * 100);
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
if (activity != null && title != null) {
activity.setTitle(title);
}
}
}