/// <summary>
        /// Internal Use Only.
        /// </summary>
        /// <param name="type">The type of event</param>
        /// <param name="eventObject">The WVE object to pass</param>
        /// <returns></returns>
        public object InvokeEvent(WebViewEventType type, WebViewDelegate eventObject)
        {
            switch (type)
            {
            case WebViewEventType.NavigationRequested:
                return(NavigationStarted == null ? eventObject as NavigationRequestedDelegate : NavigationStarted.Invoke(eventObject as NavigationRequestedDelegate));

            case WebViewEventType.NavigationComplete:
                NavigationCompleted?.Invoke(eventObject as NavigationCompletedDelegate);
                break;

            case WebViewEventType.JavascriptCallback:
                var            data = (eventObject as JavascriptResponseDelegate).Data;
                ActionResponse ar;
                if (data.ValidateJSON() && (ar = data.AttemptParseActionResponse()) != null)
                {
                    if (RegisteredActions.ContainsKey(ar.Action))
                    {
                        RegisteredActions[ar.Action]?.Invoke(ar.Data);
                    }
                }
                else
                {
                    OnJavascriptResponse?.Invoke(eventObject as JavascriptResponseDelegate);
                }
                break;
            }

            return(eventObject);
        }
Exemplo n.º 2
0
 public MainForm()
 {
     InitializeComponent();
     webViewDelegate  = new WebViewDelegate(updateWebView);
     temporaryStorage = new TemporaryStorage();
     loadPreferences();
 }
Exemplo n.º 3
0
 public MainForm()
 {
     InitializeComponent();
     webViewDelegate = new WebViewDelegate(updateWebView);
     temporaryStorage = new TemporaryStorage();
     loadPreferences();
 }
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);

            if (e.OldElement == null)
            {
                WeakDelegate = new WebViewDelegate(ResponseParsingWebView);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Internal Use Only.
        /// </summary>
        /// <param name="type">The type of event</param>
        /// <param name="eventObject">The WVE object to pass</param>
        /// <returns></returns>
        public object InvokeEvent(WebViewEventType type, WebViewDelegate eventObject)
        {
            switch (type)
            {
            case WebViewEventType.NavigationRequested:
                return(OnNavigationStarted == null ? eventObject as NavigationRequestedDelegate : OnNavigationStarted.Invoke(eventObject as NavigationRequestedDelegate));

            case WebViewEventType.NavigationComplete:
                OnNavigationCompleted?.Invoke(eventObject as NavigationCompletedDelegate);
                break;

            case WebViewEventType.NavigationError:
                OnNavigationError?.Invoke(eventObject as NavigationErrorDelegate);
                break;

            case WebViewEventType.ContentLoaded:
                OnContentLoaded?.Invoke(eventObject as ContentLoadedDelegate);
                break;

            case WebViewEventType.NavigationStackUpdate:
                CanGoBack    = (eventObject as NavigationStackUpdateDelegate).CanGoBack;
                CanGoForward = (eventObject as NavigationStackUpdateDelegate).CanGoForward;
                break;

            case WebViewEventType.JavascriptCallback:
                var            data = (eventObject as JavascriptResponseDelegate).Data;
                ActionResponse ar;

                if (data.ValidateJSON() && (ar = data.AttemptParseActionResponse()) != null)
                {
                    // Attempt Locals
                    if (RegisteredActions[this].ContainsKey(ar.Action))
                    {
                        RegisteredActions[this][ar.Action]?.Invoke(ar.Data);
                    }

                    // Attempt Globals
                    if (RegisteredActions[_globalKey].ContainsKey(ar.Action))
                    {
                        RegisteredActions[_globalKey][ar.Action]?.Invoke(ar.Data);
                    }
                }
                else
                {
                    OnJavascriptResponse?.Invoke(eventObject as JavascriptResponseDelegate);
                }

                break;
            }

            return(eventObject);
        }
Exemplo n.º 6
0
    void Start()
    {
        _webview = new UIWebView(locationAndSize);
        UIApplication.SharedApplication().keyWindow.rootViewController.view.AddSubview(_webview);

        // SayStuff is an offline html file under the Resources/ folder of Unity
        string html = (Resources.Load("SayStuff") as TextAsset).text;
        Debug.Log ("HTML: " + html);
        _webview.LoadHTMLString(html, null);

        _webViewDelegate = new WebViewDelegate();
        _webview.Delegate = _webViewDelegate;

        _webview.backgroundColor = UIColor.ClearColor();
        _webview.opaque = false;
    }
Exemplo n.º 7
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Title = "Help";
            View.BackgroundColor = UIColor.GroupTableViewBackgroundColor;

            string html = ReplaceTokens();
            _webView = new UIWebView();
            _webView.Frame = new RectangleF(0, 0, 320, 480);
            _webView.LoadHtmlString(html, new NSUrl("/"));
            _webView.BackgroundColor = UIColor.Clear;
            _webView.Opaque = false;

            _webViewDelegate = new WebViewDelegate();
            _webView.Delegate = _webViewDelegate;
            View.AddSubview(_webView);
        }
Exemplo n.º 8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Title = "Help";
            View.BackgroundColor = UIColor.GroupTableViewBackgroundColor;

            string html = ReplaceTokens();

            _webView       = new UIWebView();
            _webView.Frame = new RectangleF(0, 0, 320, 480);
            _webView.LoadHtmlString(html, new NSUrl("/"));
            _webView.BackgroundColor = UIColor.Clear;
            _webView.Opaque          = false;

            _webViewDelegate  = new WebViewDelegate();
            _webView.Delegate = _webViewDelegate;
            View.AddSubview(_webView);
        }
Exemplo n.º 9
0
    void Start()
    {
        _webview = new UIWebView(locationAndSize);
        UIApplication.SharedApplication().keyWindow.rootViewController.view.AddSubview(_webview);

        // SayStuff is an offline html file under the Resources/ folder of Unity
        string html = (Resources.Load("SayStuff") as TextAsset).text;

        Debug.Log("HTML: " + html);
        _webview.LoadHTMLString(html, null);


        _webViewDelegate  = new WebViewDelegate();
        _webview.Delegate = _webViewDelegate;


        _webview.backgroundColor = UIColor.ClearColor();
        _webview.opaque          = false;
    }
        protected override void Dispose(bool disposing)
        {
            if (disposing && !_disposed)
            {
                if (RefreshControl != null && ManageNativeControlLifetime)
                {
                    RefreshControl.OnFocusChangeListener = null;
                    RefreshControl.RemoveView(Native);
                    RefreshControl.Refresh -= RefreshControlRefresh;
                    RefreshControl.RemoveFromParent();
                    Native.SetWebViewClient(null);
                    Native.SetWebChromeClient(null);
                    Native            = null;
                    webViewDelegate   = null;
                    webChromeDelegate = null;
                    RefreshControl    = null;
                    WebViewer         = null;
                }
                _disposed = true;
            }

            base.Dispose(disposing);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Internal Use Only.
        /// </summary>
        /// <param name="type">The type of event</param>
        /// <param name="eventObject">The WVE object to pass</param>
        /// <returns></returns>
        public object InvokeEvent(WebViewEventType type, WebViewDelegate eventObject)
        {
            switch (type)
            {
            case WebViewEventType.NavigationRequested:
                SetValue(NavigatingProperty, true);
                return(OnNavigationStarted?.Invoke(eventObject as NavigationRequestedDelegate));

            case WebViewEventType.NavigationComplete:
                SetValue(NavigatingProperty, false);
                OnNavigationCompleted?.Invoke(eventObject as NavigationCompletedDelegate);
                break;

            case WebViewEventType.NavigationError:
                SetValue(NavigatingProperty, false);
                OnNavigationError?.Invoke(eventObject as NavigationErrorDelegate);
                break;

            case WebViewEventType.ContentLoaded:
                SetValue(NavigatingProperty, false);
                OnContentLoaded?.Invoke(eventObject as ContentLoadedDelegate);
                break;

            case WebViewEventType.NavigationStackUpdate:
                var stackUpdateDelegate           = eventObject as NavigationStackUpdateDelegate;
                var navigationStackUpdateDelegate = eventObject as NavigationStackUpdateDelegate;

                if (stackUpdateDelegate != null)
                {
                    SetValue(CanGoBackProperty, stackUpdateDelegate.CanGoBack);
                }

                if (navigationStackUpdateDelegate != null)
                {
                    SetValue(CanGoForwardProperty, navigationStackUpdateDelegate.CanGoForward);
                }
                break;

            case WebViewEventType.JavascriptCallback:
                var javascriptResponseDelegate = eventObject as JavascriptResponseDelegate;
                if (javascriptResponseDelegate != null)
                {
                    var            data = javascriptResponseDelegate.Data;
                    ActionResponse ar;
                    if (data.ValidateJSON() && (ar = data.AttemptParseActionResponse()) != null)
                    {
                        // Attempt Locals
                        if (LocalRegisteredActions.ContainsKey(ar.Action))
                        {
                            LocalRegisteredActions[ar.Action]?.Invoke(ar.Data);
                        }

                        // Attempt Globals
                        if (GlobalRegisteredActions.ContainsKey(ar.Action))
                        {
                            GlobalRegisteredActions[ar.Action]?.Invoke(ar.Data);
                        }
                    }
                    else
                    {
                        OnJavascriptResponse?.Invoke((JavascriptResponseDelegate)eventObject);
                    }
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }

            return(eventObject);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <WebviewContainer> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                System.Diagnostics.Debug.WriteLine("WebViewRenderer DISPOSE");
            }


            if (e.NewElement != null)
            {
                WebViewer = (e.NewElement as WebviewContainer).WebViewer;

                WebViewer.OnRotate += WebViewer_OnRotate;

                webViewDelegate   = new WebViewDelegate(this);
                webChromeDelegate = new WebChromeDelegate(this);

                Native = new WebView(this.Context);
                Native.SetWebViewClient(webViewDelegate);
                Native.SetWebChromeClient(webChromeDelegate);
                if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
                {
                    Native.SetLayerType(LayerType.Hardware, null);
                }
                else
                {
                    Native.SetLayerType(LayerType.Software, null);
                }
                Native.Settings.JavaScriptEnabled = true;
                Native.Settings.JavaScriptCanOpenWindowsAutomatically = true;
                Native.Settings.AllowFileAccess   = true;
                Native.Settings.DomStorageEnabled = true;
                Native.Settings.DatabaseEnabled   = true;
                Native.Settings.AllowFileAccess   = true;
                Native.DrawingCacheEnabled        = true;
                Native.Settings.MediaPlaybackRequiresUserGesture = false;
                Native.Settings.LoadWithOverviewMode             = true;
                Native.Settings.UseWideViewPort      = true;
                Native.Settings.BuiltInZoomControls  = false;
                Native.Settings.LoadWithOverviewMode = true;
                //Native.Settings.MixedContentMode = MixedContentHandling.AlwaysAllow;
                Native.ScrollBarStyle         = ScrollbarStyles.OutsideOverlay;
                Native.ScrollbarFadingEnabled = true;
                Native.Settings.SetLayoutAlgorithm(WebSettings.LayoutAlgorithm.SingleColumn);
                Native.Settings.SetAppCacheEnabled(true);
                Native.Settings.SetAppCacheMaxSize(1024 * 1024 * 32);
                Native.Settings.SetAppCachePath(MainActivity.Instance.CacheDir.AbsolutePath);
                Native.Settings.SetGeolocationEnabled(true);
                Native.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);

                WebViewer.BaseUrl = WebViewer.Uri;
                //refreshControl = new CustomRefreshControl(this.Context, Native);
                RefreshControl = new SwipeRefreshLayout(this.Context);
                RefreshControl.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);

                RefreshControl.SetBackgroundColor(Color.Transparent);
                RefreshControl.Refresh += RefreshControlRefresh;
                if (Native.Parent == null)
                {
                    RefreshControl.AddView(Native);
                }
                //RefreshControl.SetDistanceToTriggerSync(50);
                RefreshControl.AddView(new LoadingOverlay(MainActivity.Instance.ApplicationContext, false, WebViewer.Orientation));
                SetNativeControl(RefreshControl);


                if (string.IsNullOrEmpty(homeUrl))
                {
                    homeUrl = WebViewer.Uri;
                }
                WebViewer.PropertyChanged += (sender, ea) =>
                {
                    if (ea.PropertyName == "Action")
                    {
                        switch (WebViewer.Action)
                        {
                        case "GoHome":
                            GoHome(WebViewer.NeedCheckEtag);
                            break;
                        }
                        WebViewer.Action = string.Empty;
                    }
                    else if (ea.PropertyName == "Uri")
                    {
                        LoadUrl();
                    }
                };
                LoadUrl();
            }
        }