forked from Clancey/MonoDroid.Dialog
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathHtmlElement.cs
62 lines (53 loc) · 1.68 KB
/
HtmlElement.cs
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
using Android.App;
using Android.Content;
using Android.OS;
using Android.Views;
using Android.Webkit;
using Uri = Android.Net.Uri;
namespace Android.Dialog
{
public class HtmlElement : StringElement
{
// public string Value;
public HtmlElement(string caption, string url)
: base(caption, Resource.Layout.dialog_labelfieldright)
{
Url = Uri.Parse(url);
}
public HtmlElement(string caption, Uri uri)
: base(caption, Resource.Layout.dialog_labelfieldright)
{
Url = uri;
}
public Uri Url { get; set; }
void OpenUrl(Context context)
{
var intent = new Intent(context, typeof(HtmlActivity));
intent.PutExtra("URL", Url.ToString());
intent.PutExtra("Title", Caption);
intent.AddFlags(ActivityFlags.NewTask);
context.StartActivity(intent);
}
public override View GetView(Context context, View convertView, ViewGroup parent)
{
var view = base.GetView(context, convertView, parent);
Click = (o, e) => OpenUrl(context);
return view;
}
}
[Activity]
public class HtmlActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
string url = Intent.GetStringExtra("URL");
Title = Intent.GetStringExtra("Title");
var webview = new WebView(this);
webview.Settings.JavaScriptEnabled = true;
webview.Settings.BuiltInZoomControls = true;
SetContentView(webview);
webview.LoadUrl(url);
}
}
}