diff --git a/BookAStar/BookAStar.Droid/MarkdownRazorWebViewClient.cs b/BookAStar/BookAStar.Droid/MarkdownRazorWebViewClient.cs deleted file mode 100644 index 8cd6642d..00000000 --- a/BookAStar/BookAStar.Droid/MarkdownRazorWebViewClient.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using Android.App; -using Android.Content; -using Android.OS; -using Android.Runtime; -using Android.Views; -using Android.Widget; -using Android.Webkit; -using Java.Lang; -using Java.IO; -using Android.Content.Res; - -namespace BookAStar.Droid -{ - class MarkdownRazorWebViewClient : WebViewClient - { - Context context; - public MarkdownRazorWebViewClient(Context context) - { - this.context = context; - } - - - private WebResourceResponse getWebResourceResponseFromAssets(string name) - { - var desc = - getActivity().Assets.OpenFd(name); - var stream = desc.CreateInputStream(); - string encoding = null; - string mimet = "text/html"; - if (name.EndsWith(".css")) - { - mimet = "text/css"; - encoding = "utf-8"; - } - else if (name.EndsWith(".js")) - { mimet = "text/js"; - encoding = "utf-8"; - } - else if (name.EndsWith(".ico")) - { mimet = "image/ico"; - encoding = "utf-8"; - } - - return new WebResourceResponse(mimet, encoding, stream ); - - } - private static Activity getActivity () - { - return (Activity)App.PlateformSpecificInstance; - } - public override WebResourceResponse ShouldInterceptRequest(WebView view, IWebResourceRequest request) - { - - if (request.Url.Scheme=="file") - { - return getWebResourceResponseFromAssets(request.Url.Path); - } - if (request.Url.Scheme=="hybrid") - { - getActivity().RunOnUiThread( - () => testGetContent(view)); - } - return base.ShouldInterceptRequest(view, request); - } - - class ContentCallBack : Java.Lang.Object, IValueCallback - { - public string Result { get; private set; } - public void OnReceiveValue(Java.Lang.Object value) - { - if (value == null) { Result = null; } - else { Result = new string(((Java.Lang.String)value).ToCharArray()); } - } - } - - void testGetContent(WebView view) - { - var cb = new ContentCallBack(); - view.EvaluateJavascript("$('#Content').val()", cb); - } - - } -} \ No newline at end of file diff --git a/BookAStar/BookAStar.Droid/MarkdownWebViewClient.cs b/BookAStar/BookAStar.Droid/MarkdownWebViewClient.cs new file mode 100644 index 00000000..ef038ed8 --- /dev/null +++ b/BookAStar/BookAStar.Droid/MarkdownWebViewClient.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using Android.App; +using Android.Content; +using Android.OS; +using Android.Runtime; +using Android.Views; +using Android.Widget; +using Android.Webkit; +using Java.Lang; +using Java.IO; +using Android.Content.Res; + +namespace BookAStar.Droid +{ + class MarkdownWebViewClient : WebViewClient + { + Action update; + public MarkdownWebViewClient(Action update) : base() + { + this.update = update; + } + private static Activity getActivity () + { + return (Activity)App.PlateformSpecificInstance; + } + public string Markdown { get; private set; } + public override WebResourceResponse ShouldInterceptRequest(WebView view, IWebResourceRequest request) + { + if (request.Url.Scheme=="file") + { + if (request.Url.Path=="/android_asset/validate") + { + Markdown = request.Url.GetQueryParameter("md"); + update(Markdown); + return new WebResourceResponse("application/json", "utf-8" ,200, "Ok", null, null); + } + } + return base.ShouldInterceptRequest(view, request); + } + } +} \ No newline at end of file