forked from tinyeeliu/androidquery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebDialog.java
More file actions
165 lines (112 loc) · 4.35 KB
/
Copy pathWebDialog.java
File metadata and controls
165 lines (112 loc) · 4.35 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package com.androidquery;
import android.R;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.androidquery.util.AQUtility;
public class WebDialog extends Dialog {
private String url;
private WebViewClient client;
private WebView wv;
private LinearLayout ll;
private String message;
public WebDialog(Context context, String url, WebViewClient client) {
//super(context, R.style.Theme_Light_NoTitleBar);
super(context, R.style.Theme_NoTitleBar);
this.url = url;
this.client = client;
}
public void setLoadingMessage(String message){
this.message = message;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RelativeLayout layout = new RelativeLayout(getContext());
layout.setBackgroundColor(0xFFFFFFFF);
setupWebView(layout);
setupProgress(layout);
FrameLayout.LayoutParams FILL = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
addContentView(layout, FILL);
}
private void setupProgress(RelativeLayout layout){
Context context = getContext();
ll = new LinearLayout(context);
ProgressBar progress = new ProgressBar(context);
int p = AQUtility.dip2pixel(context, 30);
LinearLayout.LayoutParams plp = new LinearLayout.LayoutParams(p, p);
ll.addView(progress, plp);
if(message != null){
TextView tv = new TextView(context);
LinearLayout.LayoutParams tlp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
tlp.leftMargin = AQUtility.dip2pixel(context, 5);
tlp.gravity = 0x10;
tv.setText(message);
ll.addView(tv, tlp);
}
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(ll, lp);
}
private void setupWebView(RelativeLayout layout) {
wv = new WebView(getContext());
wv.setVerticalScrollBarEnabled(false);
wv.setHorizontalScrollBarEnabled(false);
if(client == null) client = new WebViewClient();
wv.setWebViewClient(new DialogWebViewClient());
WebSettings ws = wv.getSettings();
ws.setJavaScriptEnabled(true);
//ws.setSaveFormData(false);
//wv.loadUrl(url);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
layout.addView(wv, lp);
}
public void load(){
if(wv != null){
wv.loadUrl(url);
}
}
private void showProgress(boolean show){
if(ll != null){
if(show) ll.setVisibility(View.VISIBLE);
else ll.setVisibility(View.GONE);
}
}
@Override
public void dismiss(){
try{
super.dismiss();
}catch(Exception e){
}
}
private class DialogWebViewClient extends WebViewClient{
@Override
public void onPageFinished(WebView view, String url) {
showProgress(false);
client.onPageFinished(view, url);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
client.onPageStarted(view, url, favicon);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
client.onReceivedError(view, errorCode, description, failingUrl);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return client.shouldOverrideUrlLoading(view, url);
}
}
}