From a3f786b42ad2c9a9c1bd1b160e326d987edd60a0 Mon Sep 17 00:00:00 2001
From: wanggang <76527413@qq.com>
Date: Sun, 21 Apr 2019 10:59:51 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=B0xamarin=20froms=204.?=
=?UTF-8?q?0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
projects/Demo/Demo.Android/BaseUrl_Android.cs | 15 ------
.../Demo/Demo.Android/Demo.Android.csproj | 7 +--
.../Infrastructure/HybridWebViewRenderer.cs | 45 ----------------
.../Demo.Android/Infrastructure/JSBridge.cs | 28 ----------
.../Infrastructure/JavascriptWebViewClient.cs | 20 -------
projects/Demo/Demo.iOS/BaseUrl_iOS.cs | 16 ------
projects/Demo/Demo.iOS/Demo.iOS.csproj | 4 +-
.../Infrastructure/HybridWebViewRenderer.cs | 52 -------------------
projects/Demo/Demo/Demo.csproj | 2 +-
projects/Demo/Demo/IBaseUrl.cs | 7 ---
.../Demo/Demo/Infrastructure/HybridWebView.cs | 41 ---------------
projects/Demo/Demo/MainPage.xaml.cs | 9 ++--
projects/Demo/Demo/OnvifPage.xaml.cs | 6 ---
13 files changed, 6 insertions(+), 246 deletions(-)
delete mode 100644 projects/Demo/Demo.Android/BaseUrl_Android.cs
delete mode 100644 projects/Demo/Demo.Android/Infrastructure/HybridWebViewRenderer.cs
delete mode 100644 projects/Demo/Demo.Android/Infrastructure/JSBridge.cs
delete mode 100644 projects/Demo/Demo.Android/Infrastructure/JavascriptWebViewClient.cs
delete mode 100644 projects/Demo/Demo.iOS/BaseUrl_iOS.cs
delete mode 100644 projects/Demo/Demo.iOS/Infrastructure/HybridWebViewRenderer.cs
delete mode 100644 projects/Demo/Demo/IBaseUrl.cs
delete mode 100644 projects/Demo/Demo/Infrastructure/HybridWebView.cs
diff --git a/projects/Demo/Demo.Android/BaseUrl_Android.cs b/projects/Demo/Demo.Android/BaseUrl_Android.cs
deleted file mode 100644
index 28981461..00000000
--- a/projects/Demo/Demo.Android/BaseUrl_Android.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Demo.Droid;
-using Xamarin.Forms;
-
-[assembly: Dependency(typeof(BaseUrl_Android))]
-
-namespace Demo.Droid
-{
- public class BaseUrl_Android : IBaseUrl
- {
- public string Get()
- {
- return "file:///android_asset/";
- }
- }
-}
\ No newline at end of file
diff --git a/projects/Demo/Demo.Android/Demo.Android.csproj b/projects/Demo/Demo.Android/Demo.Android.csproj
index de48f64c..d9f80df3 100644
--- a/projects/Demo/Demo.Android/Demo.Android.csproj
+++ b/projects/Demo/Demo.Android/Demo.Android.csproj
@@ -46,7 +46,6 @@
-
@@ -56,7 +55,7 @@
3.1.2
-
+
@@ -67,14 +66,10 @@
-
-
-
-
diff --git a/projects/Demo/Demo.Android/Infrastructure/HybridWebViewRenderer.cs b/projects/Demo/Demo.Android/Infrastructure/HybridWebViewRenderer.cs
deleted file mode 100644
index 924a854a..00000000
--- a/projects/Demo/Demo.Android/Infrastructure/HybridWebViewRenderer.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using Android.Content;
-using Demo.Droid.Infrastructure;
-using Demo.Infrastructure;
-using Xamarin.Forms;
-using Xamarin.Forms.Platform.Android;
-
-[assembly: ExportRenderer(typeof(HybridWebView), typeof(HybridWebViewRenderer))]
-
-namespace Demo.Droid.Infrastructure
-{
- public class HybridWebViewRenderer : ViewRenderer
- {
- private const string JavascriptFunction = "function invokeCSharpAction(data){jsBridge.invokeAction(data);}";
- private Context _context;
-
- public HybridWebViewRenderer(Context context) : base(context)
- {
- _context = context;
- }
-
- protected override void OnElementChanged(ElementChangedEventArgs e)
- {
- base.OnElementChanged(e);
-
- if (Control == null)
- {
- var webView = new Android.Webkit.WebView(_context);
- webView.Settings.JavaScriptEnabled = true;
- webView.SetWebViewClient(new JavascriptWebViewClient($"javascript: {JavascriptFunction}"));
- SetNativeControl(webView);
- }
- if (e.OldElement != null)
- {
- Control.RemoveJavascriptInterface("jsBridge");
- var hybridWebView = e.OldElement as HybridWebView;
- hybridWebView.Cleanup();
- }
- if (e.NewElement != null)
- {
- Control.AddJavascriptInterface(new JSBridge(this), "jsBridge");
- Control.LoadUrl(Element.Uri);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/projects/Demo/Demo.Android/Infrastructure/JSBridge.cs b/projects/Demo/Demo.Android/Infrastructure/JSBridge.cs
deleted file mode 100644
index b8c84e50..00000000
--- a/projects/Demo/Demo.Android/Infrastructure/JSBridge.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Android.Webkit;
-using Java.Interop;
-using System;
-
-namespace Demo.Droid.Infrastructure
-{
- public class JSBridge : Java.Lang.Object
- {
- private readonly WeakReference hybridWebViewRenderer;
-
- public JSBridge(HybridWebViewRenderer hybridRenderer)
- {
- hybridWebViewRenderer = new WeakReference(hybridRenderer);
- }
-
- [JavascriptInterface]
- [Export("invokeAction")]
- public void InvokeAction(string data)
- {
- HybridWebViewRenderer hybridRenderer;
-
- if (hybridWebViewRenderer != null && hybridWebViewRenderer.TryGetTarget(out hybridRenderer))
- {
- hybridRenderer.Element.InvokeAction(data);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/projects/Demo/Demo.Android/Infrastructure/JavascriptWebViewClient.cs b/projects/Demo/Demo.Android/Infrastructure/JavascriptWebViewClient.cs
deleted file mode 100644
index ee370fb3..00000000
--- a/projects/Demo/Demo.Android/Infrastructure/JavascriptWebViewClient.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Android.Webkit;
-
-namespace Demo.Droid.Infrastructure
-{
- public class JavascriptWebViewClient : WebViewClient
- {
- string _javascript;
-
- public JavascriptWebViewClient(string javascript)
- {
- _javascript = javascript;
- }
-
- public override void OnPageFinished(WebView view, string url)
- {
- base.OnPageFinished(view, url);
- view.EvaluateJavascript(_javascript, null);
- }
- }
-}
\ No newline at end of file
diff --git a/projects/Demo/Demo.iOS/BaseUrl_iOS.cs b/projects/Demo/Demo.iOS/BaseUrl_iOS.cs
deleted file mode 100644
index 16141873..00000000
--- a/projects/Demo/Demo.iOS/BaseUrl_iOS.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Demo.iOS;
-using Foundation;
-using Xamarin.Forms;
-
-[assembly: Dependency(typeof(BaseUrl_iOS))]
-
-namespace Demo.iOS
-{
- public class BaseUrl_iOS : IBaseUrl
- {
- public string Get()
- {
- return NSBundle.MainBundle.BundlePath;
- }
- }
-}
\ No newline at end of file
diff --git a/projects/Demo/Demo.iOS/Demo.iOS.csproj b/projects/Demo/Demo.iOS/Demo.iOS.csproj
index 8196a378..456e1a72 100644
--- a/projects/Demo/Demo.iOS/Demo.iOS.csproj
+++ b/projects/Demo/Demo.iOS/Demo.iOS.csproj
@@ -98,8 +98,6 @@
-
-
@@ -170,7 +168,7 @@
3.1.5-alpha
-
+
diff --git a/projects/Demo/Demo.iOS/Infrastructure/HybridWebViewRenderer.cs b/projects/Demo/Demo.iOS/Infrastructure/HybridWebViewRenderer.cs
deleted file mode 100644
index ed3c4bc3..00000000
--- a/projects/Demo/Demo.iOS/Infrastructure/HybridWebViewRenderer.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-using Demo.Infrastructure;
-using Demo.iOS.Infrastructure;
-using Foundation;
-using System.IO;
-using WebKit;
-using Xamarin.Forms;
-using Xamarin.Forms.Platform.iOS;
-
-[assembly: ExportRenderer(typeof(HybridWebView), typeof(HybridWebViewRenderer))]
-
-namespace Demo.iOS.Infrastructure
-{
- public class HybridWebViewRenderer : ViewRenderer, IWKScriptMessageHandler
- {
- private const string JavaScriptFunction = "function invokeCSharpAction(data){window.webkit.messageHandlers.invokeAction.postMessage(data);}";
- private WKUserContentController userController;
-
- protected override void OnElementChanged(ElementChangedEventArgs e)
- {
- base.OnElementChanged(e);
-
- if (Control == null)
- {
- userController = new WKUserContentController();
- var script = new WKUserScript(new NSString(JavaScriptFunction), WKUserScriptInjectionTime.AtDocumentEnd, false);
- userController.AddUserScript(script);
- userController.AddScriptMessageHandler(this, "invokeAction");
-
- var config = new WKWebViewConfiguration { UserContentController = userController };
- var webView = new WKWebView(Frame, config);
- SetNativeControl(webView);
- }
- if (e.OldElement != null)
- {
- userController.RemoveAllUserScripts();
- userController.RemoveScriptMessageHandler("invokeAction");
- var hybridWebView = e.OldElement as HybridWebView;
- hybridWebView.Cleanup();
- }
- if (e.NewElement != null)
- {
- string fileName = Path.Combine(NSBundle.MainBundle.BundlePath, string.Format("Content/{0}", Element.Uri));
- Control.LoadRequest(new NSUrlRequest(new NSUrl(fileName, false)));
- }
- }
-
- public void DidReceiveScriptMessage(WKUserContentController userContentController, WKScriptMessage message)
- {
- Element.InvokeAction(message.Body.ToString());
- }
- }
-}
\ No newline at end of file
diff --git a/projects/Demo/Demo/Demo.csproj b/projects/Demo/Demo/Demo.csproj
index 7857df84..1acf3219 100644
--- a/projects/Demo/Demo/Demo.csproj
+++ b/projects/Demo/Demo/Demo.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/projects/Demo/Demo/IBaseUrl.cs b/projects/Demo/Demo/IBaseUrl.cs
deleted file mode 100644
index 78913575..00000000
--- a/projects/Demo/Demo/IBaseUrl.cs
+++ /dev/null
@@ -1,7 +0,0 @@
-namespace Demo
-{
- public interface IBaseUrl
- {
- string Get();
- }
-}
\ No newline at end of file
diff --git a/projects/Demo/Demo/Infrastructure/HybridWebView.cs b/projects/Demo/Demo/Infrastructure/HybridWebView.cs
deleted file mode 100644
index b10381a9..00000000
--- a/projects/Demo/Demo/Infrastructure/HybridWebView.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using System;
-using Xamarin.Forms;
-
-namespace Demo.Infrastructure
-{
- public class HybridWebView : View
- {
- private Action action;
-
- public static readonly BindableProperty UriProperty = BindableProperty.Create(
- propertyName: "Uri",
- returnType: typeof(string),
- declaringType: typeof(HybridWebView),
- defaultValue: default(string));
-
- public string Uri
- {
- get { return (string)GetValue(UriProperty); }
- set { SetValue(UriProperty, value); }
- }
-
- public void RegisterAction(Action callback)
- {
- action = callback;
- }
-
- public void Cleanup()
- {
- action = null;
- }
-
- public void InvokeAction(string data)
- {
- if (action == null || data == null)
- {
- return;
- }
- action.Invoke(data);
- }
- }
-}
\ No newline at end of file
diff --git a/projects/Demo/Demo/MainPage.xaml.cs b/projects/Demo/Demo/MainPage.xaml.cs
index aa29dcf1..1c9f2d4e 100644
--- a/projects/Demo/Demo/MainPage.xaml.cs
+++ b/projects/Demo/Demo/MainPage.xaml.cs
@@ -1,6 +1,5 @@
using Plugin.LocalNotifications;
using System;
-using System.Threading.Tasks;
using Xamarin.Forms;
using ZXing.Net.Mobile.Forms;
@@ -15,8 +14,6 @@ namespace Demo
this.webView.Navigating += WebView_Navigating;
this.webView.Navigated += WebView_Navigated;
this.webView.Source = $"http://127.0.0.1:8080/index.html";
- //webView.RegisterAction(data => DisplayAlert("Alert", "Hello " + data, "OK"));
- //this.webView.Uri = "http://127.0.0.1:8080/login.html";
}
private void WebView_Navigating(object sender, WebNavigatingEventArgs e)
@@ -24,18 +21,18 @@ namespace Demo
Console.WriteLine(e.Url);
if (e.Url.Contains("webqr.html"))
{
- Scan();
e.Cancel = true;
+ Scan();
}
else if (e.Url.Contains("notify.html"))
{
- CrossLocalNotifications.Current.Show("title", e.Url);
e.Cancel = true;
+ CrossLocalNotifications.Current.Show("title", e.Url);
}
else if (e.Url.Contains("rtmp://") || e.Url.Contains(".flv") || e.Url.Contains(".m3u8"))
{
- this.Navigation.PushAsync(new OnvifPage(e.Url));
e.Cancel = true;
+ this.Navigation.PushAsync(new OnvifPage(e.Url));
}
}
diff --git a/projects/Demo/Demo/OnvifPage.xaml.cs b/projects/Demo/Demo/OnvifPage.xaml.cs
index 3496f967..334c5f32 100644
--- a/projects/Demo/Demo/OnvifPage.xaml.cs
+++ b/projects/Demo/Demo/OnvifPage.xaml.cs
@@ -40,12 +40,6 @@ namespace Demo
this.videoView.MediaPlayer.Stop();
}
- //protected override bool OnBackButtonPressed()
- //{
- // this.videoView.MediaPlayer.Stop();
- // return base.OnBackButtonPressed();
- //}
-
private void Button_Clicked(object sender, System.EventArgs e)
{
this.videoView.MediaPlayer.Stop();