100 lines
3.0 KiB
C#
100 lines
3.0 KiB
C#
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Sarand.Net.Standard.Mobile.Forms.Controls
|
|
{
|
|
//=======================================================================
|
|
public class SaxWebView : WebView
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
public String html = "";
|
|
private HtmlWebViewSource htmlSource;
|
|
private UrlWebViewSource aboutBlankSource = new UrlWebViewSource() { Url = "about:blank" };
|
|
// Managers.
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SaxWebView ()
|
|
{
|
|
// Events.
|
|
Navigating += WebView_Navigating;
|
|
Navigated += WebView_Navigated;
|
|
|
|
// HTML source.
|
|
htmlSource = new HtmlWebViewSource() { Html = html };
|
|
Source = aboutBlankSource;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Properties.
|
|
// HTML Panel.
|
|
public static String AppActionPrefix => "App:";
|
|
public String Html
|
|
{
|
|
get { return html; }
|
|
set
|
|
{
|
|
Source = aboutBlankSource;
|
|
htmlSource.Html = null;
|
|
html = value;
|
|
htmlSource.Html = html;
|
|
Source = htmlSource;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// N a v i g a t i o n
|
|
//-------------------------------------------------------------------
|
|
public class AppNavigatingEventArgs : EventArgs
|
|
{
|
|
public String AppAction { get; set; }
|
|
}
|
|
public delegate void AppNavigatingEventHandler (object sender, AppNavigatingEventArgs e);
|
|
public event AppNavigatingEventHandler AppNavigating;
|
|
private void OnAppNavigating (String appAction)
|
|
{
|
|
if (AppNavigating != null) AppNavigating.Invoke(this, new AppNavigatingEventArgs() { AppAction = appAction });
|
|
}
|
|
private String GetAppAction (String location)
|
|
{
|
|
if (!location.StartsWithCI(AppActionPrefix)) return "";
|
|
return location.Right(location.Length - AppActionPrefix.Length);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// C o n t r o l E v e n t s
|
|
//-------------------------------------------------------------------
|
|
private void WebView_Navigating (object sender, WebNavigatingEventArgs e)
|
|
{
|
|
String appAction = GetAppAction(e.Url);
|
|
SaLogger.Debug("SaxWebView_Navigating URL: "+e.Url+". App action: "+ appAction);
|
|
if (!StringUtil.IsEmpty(appAction))
|
|
{
|
|
e.Cancel = true;
|
|
OnAppNavigating(appAction);
|
|
}
|
|
}
|
|
private void WebView_Navigated (object sender, WebNavigatedEventArgs e)
|
|
{
|
|
SaLogger.Debug("SaxWebView_Navigated URL: " + e.Url);
|
|
String appAction = GetAppAction(e.Url);
|
|
if (!StringUtil.IsEmpty(appAction))
|
|
{
|
|
Source = htmlSource;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|