コード例 #1
0
            public override bool ShouldOverrideUrlLoading(AWebView view, string url)
            {
                if (_renderer.Element == null)
                {
                    return(true);
                }
                if (url.StartsWith("weixin://wap/pay?"))
                {
                    Intent intent = new Intent()
                    {
                    };
                    intent.SetAction(Intent.ActionView);
                    intent.SetData(Android.Net.Uri.Parse(url));
                    _renderer.Context.StartActivity(intent);
                    return(true);
                }

                var args = new Xamarin.Forms.WebNavigatingEventArgs(Xamarin.Forms.WebNavigationEvent.NewPage, new Xamarin.Forms.UrlWebViewSource {
                    Url = url
                }, url);

                _renderer.ElementController.SendNavigating(args);
                _navigationResult = Xamarin.Forms.WebNavigationResult.Success;

                _renderer.UpdateCanGoBackForward();
                return(args.Cancel);
            }
コード例 #2
0
            //[Obsolete("OnReceivedError is obsolete as of version 2.3.0. This method was deprecated in API level 23.")]
            //public override void OnReceivedError(AWebView view, ClientError errorCode, string description, string failingUrl)
            //{

            //}

            public override void OnReceivedError(AWebView view, Com.Tencent.Smtt.Export.External.Interfaces.IWebResourceRequest request, Com.Tencent.Smtt.Export.External.Interfaces.WebResourceError error)
            {
                _navigationResult = Xamarin.Forms.WebNavigationResult.Failure;
                if (error.ErrorCode == (int)Android.Webkit.ClientError.Timeout)
                {
                    _navigationResult = Xamarin.Forms.WebNavigationResult.Timeout;
                }
                base.OnReceivedError(view, request, error);
            }
コード例 #3
0
            public override void OnReceivedError(AWebView view, int errorCode, string description, string failingUrl)
            {
                _navigationResult = Xamarin.Forms.WebNavigationResult.Failure;
                if (errorCode == (int)Android.Webkit.ClientError.Timeout)
                {
                    _navigationResult = Xamarin.Forms.WebNavigationResult.Timeout;
                }
#pragma warning disable 618
                base.OnReceivedError(view, errorCode, description, failingUrl);
#pragma warning restore 618
            }
        protected override void OnElementChanged(ElementChangedEventArgs <TencentWebView> e)
        {
            mRelativeLayout = Inflate(Context, Resource.Layout.WebViewLayout, null) as Android.Widget.RelativeLayout;

            tencentWebView = mRelativeLayout.FindViewById <Com.Tencent.Smtt.Sdk.WebView>(Resource.Id.forum_context);
            tencentWebView.Settings.JavaScriptCanOpenWindowsAutomatically = true;
            //x变量非null表示启用x5内核成功
            var x = tencentWebView.X5WebViewExtension;

            tencentWebView.SetMinimumWidth(100);
            tencentWebView.SetMinimumHeight(800);
            SetNativeControl(mRelativeLayout);
            //tencentWebView.LoadUrl("http://soft.imtt.qq.com/browser/tes/feedback.html");
            tencentWebView.LoadUrl("https://www.qq.com");
            //tencentWebView.LoadUrl("https://debugtbs.qq.com");
        }
コード例 #5
0
            public override void OnProgressChanged(AWebView view, int process)
            {
                //var pro = GetProcessBar(view);
                //if (pro != null)
                //{
                //    if (process == 100)
                //    {
                //        pro.Visibility = Android.Views.ViewStates.Gone;
                //        return;
                //    }
                //    pro.Visibility = Android.Views.ViewStates.Visible;
                //    pro.BringToFront();
                //    pro.Progress = process;

                //}
            }
コード例 #6
0
 public override void OnProgressChanged(Com.Tencent.Smtt.Sdk.WebView view, int newProgress)
 {
     progressBar.Progress = newProgress;
     if (newProgress < 100)
     {
         if (progressBar.Visibility == ViewStates.Gone)
         {
             progressBar.Visibility = ViewStates.Visible;
         }
     }
     else
     {
         progressBar.Visibility = ViewStates.Gone;
     }
     base.OnProgressChanged(view, newProgress);
 }
コード例 #7
0
            public async override void OnPageFinished(Com.Tencent.Smtt.Sdk.WebView view, string url)
            {
                if (Reference == null || !Reference.TryGetTarget(out DetailsViewRenderer renderer))
                {
                    return;
                }
                if (renderer.Element == null)
                {
                    return;
                }

                int i = 10;

                while (view.ContentHeight == 0 && i-- > 0)
                {
                    await System.Threading.Tasks.Task.Delay(200);
                }
                renderer.Element.HeightRequest = view.ContentHeight;
                await System.Threading.Tasks.Task.Delay(200);

                renderer.Element.OnCompleted();
            }
コード例 #8
0
            public override void OnPageFinished(AWebView view, string url)
            {
                if (_renderer.Element == null || url == "file:///android_asset/")
                {
                    return;
                }

                var source = new Xamarin.Forms.UrlWebViewSource {
                    Url = url
                };

                _renderer._ignoreSourceChanges = true;
                _renderer.ElementController.SetValueFromRenderer(Xamarin.Forms.WebView.SourceProperty, source);
                _renderer._ignoreSourceChanges = false;

                var args = new Xamarin.Forms.WebNavigatedEventArgs(Xamarin.Forms.WebNavigationEvent.NewPage, source, url, _navigationResult);

                _renderer.ElementController.SendNavigated(args);

                _renderer.UpdateCanGoBackForward();

                base.OnPageFinished(view, url);
            }
コード例 #9
0
 public override bool ShouldOverrideUrlLoading(Com.Tencent.Smtt.Sdk.WebView view, string url)
 {
     if (url.IndexOf("https://oauth.cnblogs.com/auth/callback#code=") > -1)
     {
         var codeindex  = url.IndexOf("#code=") + 6;
         var tokenindex = url.IndexOf("&id_token=");
         var code       = url.Substring(codeindex, tokenindex - codeindex);
         if (code != "")
         {
             (renderer.Element as AuthorizeView).OnAuthorizeStarted(new AuthorizeStartedEventArgs
             {
                 Code = code
             });
         }
         view.StopLoading();
         return(true);
     }
     else
     {
         view.LoadUrl(url);
         return(true);
     }
 }
コード例 #10
0
        protected override void OnElementChanged(ElementChangedEventArgs <TencentWebView> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                // Unsubscribe from event handlers and cleanup any resources
            }

            if (e.NewElement != null)
            {
                if (Control == null)
                {
                    // Instantiate the native control and assign it to the Control property with
                    // the SetNativeControl method
                    mRelativeLayout = Inflate(Context, Resource.Layout.WebViewLayout, null) as Android.Widget.RelativeLayout;

                    tencentWebView = mRelativeLayout.FindViewById <Com.Tencent.Smtt.Sdk.WebView>(Resource.Id.forum_context);
                    tencentWebView.Settings.JavaScriptCanOpenWindowsAutomatically = true;
                    //x变量非null表示启用x5内核成功
                    var x = tencentWebView.X5WebViewExtension;
                    tencentWebView.SetMinimumWidth(100);
                    tencentWebView.SetMinimumHeight(800);
                    //tencentWebView.SetLayerType();
                    tencentWebView.Settings.UseWideViewPort      = true;
                    tencentWebView.Settings.LoadWithOverviewMode = true;
                    tencentWebView.Settings.SetLayoutAlgorithm(WebSettings.LayoutAlgorithm.SingleColumn);
                    tencentWebView.Settings.TextZoom   = 100;
                    tencentWebView.DrawingCacheEnabled = true;

                    SetNativeControl(mRelativeLayout);
                    tencentWebView.LoadUrl(e.NewElement.Url);
                }
                // Configure the control and subscribe to event handlers
            }
        }