public override void OnLoadResource(Android.Webkit.WebView view, string url)
 {
     if (_originalClient != null)
     {
         _originalClient.OnLoadResource(view, url);
     }
 }
Example #2
0
        public Task PrintAsync(WebView viewToPrint, string jobName)
        {
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
            {
                IVisualElementRenderer existingRenderer = Platform.GetRenderer(viewToPrint);
                if ((existingRenderer ?? Platform.CreateRendererWithContext(viewToPrint, Settings.Context)) is IVisualElementRenderer renderer)
                {
                    Android.Webkit.WebView droidWebView = renderer.View as Android.Webkit.WebView;
                    if (droidWebView == null && renderer.View is WebViewRenderer xfWebViewRenderer)
                    {
                        droidWebView = xfWebViewRenderer.Control;
                    }
                    if (droidWebView != null)
                    {
                        droidWebView.Settings.JavaScriptEnabled = true;
                        droidWebView.Settings.DomStorageEnabled = true;
                        droidWebView.SetLayerType(Android.Views.LayerType.Software, null);

                        // Only valid for API 19+
                        if (string.IsNullOrWhiteSpace(jobName))
                        {
                            jobName = Forms9Patch.ApplicationInfoService.Name;
                        }
                        var printMgr = (PrintManager)Settings.Context.GetSystemService(Context.PrintService);
                        printMgr.Print(jobName, droidWebView.CreatePrintDocumentAdapter(jobName), null);
                    }

                    if (existingRenderer == null)
                    {
                        renderer.Dispose();
                    }
                }
            }
            return(Task.CompletedTask);
        }
        ///// <summary>
        ///// Initializes a new instance of the <see cref="FullScreenEnabledWebViewRenderer"/> class.
        ///// </summary>
        ///// <param name="context">An Android context.</param>

        protected override void OnElementChanged(ElementChangedEventArgs <WebView> e)
        {
            base.OnElementChanged(e);
            _dialogService = BaseLocator.Instance.Resolve <IDialogService>();
            if (e.OldElement is Controls.ExtWebView oldWebView && Control != null)
            {
                Control.RemoveJavascriptInterface("jsBridge");
                oldWebView.Cleanup();
            }
            if (e.NewElement is Controls.ExtWebView newWebView)
            {
                if (Control == null)
                {
                    var webView = new Android.Webkit.WebView(_context);
                    webView.Settings.JavaScriptEnabled = true;
                    webView.SetWebViewClient(new ExtWebViewClient(newWebView, $"javascript: {JavascriptFunction}"));
                    //webView.SetWebChromeClient(new Android.Webkit.WebChromeClient());

                    SetNativeControl(webView);
                }
                else
                {
                    _extWebView = newWebView;
                    Control.Settings.JavaScriptEnabled = true;

                    Control.SetWebViewClient(new ExtWebViewClient(newWebView, $"javascript: {JavascriptFunction}"));
                    //Control.SetWebChromeClient(new Android.Webkit.WebChromeClient());

                    Control.AddJavascriptInterface(new JSBridge(this), "jsBridge");
                    Control.SetBackgroundColor(Android.Graphics.Color.Transparent);
                }
            }
        }
 public override void DoUpdateVisitedHistory(Android.Webkit.WebView view, string url, bool isReload)
 {
     if (_originalClient != null)
     {
         _originalClient.DoUpdateVisitedHistory(view, url, isReload);
     }
 }
Example #5
0
 public static void UpdateSource(this AWebView nativeWebView, IWebView webView, IWebViewDelegate?webViewDelegate)
 {
     if (webViewDelegate != null)
     {
         webView.Source?.Load(webViewDelegate);
     }
 }
Example #6
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            var view = inflater.Inflate(Resource.Layout.CurrencyChartFragment, container, false);

            //Gets the bottom toolbar
            var bottomToolbar = (Toolbar)view.FindViewById(Resource.Id.currencyToolbarChartFragment);

            bottomToolbar.InflateMenu(Resource.Menu.bot_currency_menu);
            bottomToolbar.MenuItemClick += BottomToolbar_MenuItemClick;

            string contents;

            using (StreamReader sr = new StreamReader(filePath))
            {
                contents = sr.ReadToEnd();
            }

            //Finds and sets the webview
            Android.Webkit.WebView localWebView = view.FindViewById <Android.Webkit.WebView>(Resource.Id.chartWebView);
            localWebView.Settings.JavaScriptEnabled        = true;
            localWebView.Settings.DomStorageEnabled        = true;
            localWebView.Settings.BlockNetworkImage        = false;
            localWebView.Settings.DisplayZoomControls      = true;
            localWebView.Settings.LoadsImagesAutomatically = true;
            localWebView.LoadUrl(pathUri);

            return(view);
        }
Example #7
0
        void InnerPrint(TaskCompletionSource <ToFileResult> taskCompletionSource, string html, string jobName, FailAction failAction)
        {
            try
            {
                var size    = new Size(8.5, 11);
                var webView = new Android.Webkit.WebView(Android.App.Application.Context);
                webView.Settings.JavaScriptEnabled = true;
                webView.Settings.DomStorageEnabled = true;
#pragma warning disable CS0618 // Type or member is obsolete
                webView.DrawingCacheEnabled = true;
#pragma warning restore CS0618 // Type or member is obsolete
                webView.SetLayerType(LayerType.Software, null);

                //webView.Layout(0, 0, (int)((size.Width - 0.5) * 72), (int)((size.Height - 0.5) * 72));
                webView.Layout(36, 36, (int)((PageSize.Default.Width - 0.5) * 72), (int)((PageSize.Default.Height - 0.5) * 72));

                webView.SetWebViewClient(new WebViewCallBack(taskCompletionSource, jobName, PageSize.Default, null, OnPageFinished));
                webView.LoadData(html, "text/html; charset=utf-8", "UTF-8");
            }
            catch (Exception e)
            {
                if (failAction == FailAction.ShowAlert)
                {
                    using (Forms9Patch.Alert.Create("Print Failure", e.Message)) { }
                }
                else if (failAction == FailAction.ThrowException)
                {
                    throw e;
                }
            }
        }
 public override void OnUnhandledKeyEvent(Android.Webkit.WebView view, Android.Views.KeyEvent e)
 {
     if (_originalClient != null)
     {
         _originalClient.OnUnhandledKeyEvent(view, e);
     }
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.MarkUp);

            // Get our buttonTransform from the layout resource,
            // and attach an event to it
            Button buttonTransform = FindViewById <Button>(Resource.Id.Transform);

            Android.Webkit.WebView browser = FindViewById <Android.Webkit.WebView>(Resource.Id.webView1);

            string html = "";

            html = BusinessLogicObject.MarkUpHTML;

            if (Android.OS.Build.VERSION.Release.StartsWith("2."))
            {
                // http://developer.android.com/guide/topics/manifest/uses-sdk-element.html
                // In 2.x platforms loadData() fails in some cases (it requires the html to be escaped),
                // use loadDataWithBaseURL() instead and pass null for baseUrl and historyUrl:

                //html = Java.Net.URLEncoder.Encode(BusinessLogicObject.MarkUpHTML).Replace("\\+", " ");
                browser.LoadDataWithBaseURL(null, html, "text/html", "utf-8", null);
            }
            else
            {
                browser.LoadData(BusinessLogicObject.MarkUpHTML, mime, encoding);
            }

            buttonTransform.Click += new EventHandler(buttonTransform_Click);

            return;
        }
 public override void OnTooManyRedirects(Android.Webkit.WebView view, Android.OS.Message cancelMsg, Android.OS.Message continueMsg)
 {
     if (_originalClient != null)
     {
         _originalClient.OnTooManyRedirects(view, cancelMsg, continueMsg);
     }
 }
 public override void OnScaleChanged(Android.Webkit.WebView view, float oldScale, float newScale)
 {
     if (_originalClient != null)
     {
         _originalClient.OnScaleChanged(view, oldScale, newScale);
     }
 }
            public override void OnReceivedSslError(Android.Webkit.WebView view, Android.Webkit.SslErrorHandler handler, Android.Net.Http.SslError error)
            {
                bool success = false;

                if (_renderer.Element.ShouldTrustUnknownCertificate != null)
                {
                    var certificate = new Certificate(error.Url, error.Certificate);
                    var result      = _renderer.Element.ShouldTrustUnknownCertificate(certificate);
                    if (result)
                    {
                        success = true;
                        handler.Proceed();
                    }
                    else
                    {
                        handler.Cancel();
                    }
                }

                if (!success)
                {
                    SendNavigated(
                        new WebNavigatedEventArgs(
                            _renderer._lastNavigationEvent,
                            _renderer._lastSource,
                            _renderer._lastUrl,
                            WebNavigationResult.Failure));
                }
            }
 public override void OnReceivedHttpAuthRequest(Android.Webkit.WebView view, Android.Webkit.HttpAuthHandler handler, string host, string realm)
 {
     if (_originalClient != null)
     {
         _originalClient.OnReceivedHttpAuthRequest(view, handler, host, realm);
     }
 }
 public override void OnFormResubmission(Android.Webkit.WebView view, Android.OS.Message dontResend, Android.OS.Message resend)
 {
     if (_originalClient != null)
     {
         _originalClient.OnFormResubmission(view, dontResend, resend);
     }
 }
 public override void OnPageFinished(Android.Webkit.WebView view, string url)
 {
     if (_originalClient != null)
     {
         _originalClient.OnPageFinished(view, url);
     }
 }
Example #16
0
        public static void UpdateEnableZoomControls(this AWebView platformView, WebView webView)
        {
            var value = webView.OnThisPlatform().ZoomControlsEnabled();

            platformView.Settings.SetSupportZoom(value);
            platformView.Settings.BuiltInZoomControls = value;
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.SignUpActivity);

            FindViewById <TextView>(Resource.Id.toolbarTitle).Text     = "Qeydiyyat";
            FindViewById <ImageButton>(Resource.Id.backBtn).Visibility = ViewStates.Visible;

            webview = FindViewById <Android.Webkit.WebView>(Resource.Id.signUp); //new Android.Webkit.WebView(this);
            webview.Settings.JavaScriptEnabled = true;
            webview.Settings.AllowUniversalAccessFromFileURLs = true;
            webview.Settings.AllowFileAccessFromFileURLs      = true;
            webview.Settings.AllowFileAccess      = false;
            webview.Settings.UseWideViewPort      = true;
            webview.Settings.LoadWithOverviewMode = true;
            webview.Settings.BuiltInZoomControls  = false;
            webview.Settings.DisplayZoomControls  = false;
            // webview.Settings.SupportZoom();

            //webview.LoadUrl(string.Format("file:///android_asset/pdfjs/web/viewer.html?file={0}", string.Format("file:///{0}", "Ghaznavi Beirami və d..pdf")));
            webview.LoadUrl("https://eservice.e-health.gov.az/Login/Login/RegisterStep1");//, string.Format("file:///{0}", "Ghaznavi Beirami və d..pdf")));


            webview.SetWebChromeClient(new Android.Webkit.WebChromeClient());

            // Create your application here
        }
 public override void OnReceivedError(Android.Webkit.WebView view, Android.Webkit.ClientError errorCode, string description, string failingUrl)
 {
     if (_originalClient != null)
     {
         _originalClient.OnReceivedError(view, errorCode, description, failingUrl);
     }
 }
 public override void OnPageStarted(Android.Webkit.WebView view, string url, Android.Graphics.Bitmap favicon)
 {
     if (_originalClient != null)
     {
         _originalClient.OnPageStarted(view, url, favicon);
     }
 }
            public override async void OnPageFinished(Android.Webkit.WebView view, string url)
            {
                try
                {
                    _webView = view;
                    if (_extWebView != null)
                    {
                        view.Settings.JavaScriptEnabled = true;
                        await Task.Delay(100);

                        var result = await _extWebView.EvaluateJavaScriptAsync("(function(){return document.body.scrollHeight;})()");

                        if (int.TryParse(result, out var height))
                        {
                            _extWebView.HeightRequest = height + 30;
                        }
                        else
                        {
                            _extWebView.HeightRequest = view.ContentHeight;
                        }
                        view.EvaluateJavascript(_javascript, null);
                    }
                    base.OnPageFinished(view, url);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
 public override void OnPageFinished(Android.Webkit.WebView view, string url)
 {
     if (!pageCommitted)
     {
         view.LoadUrl(url);
     }
     base.OnPageFinished(view, url);
 }
        public override void OnPageFinished(Android.Webkit.WebView view, string url)
        {
            base.OnPageFinished(view, url);

            MainPage.CurrentUrl = url;

            MainPage.checkToShowButton();
        }
Example #23
0
 public override WebResourceResponse ShouldInterceptRequest(Android.Webkit.WebView view, IWebResourceRequest request)
 {
     if (request.RequestHeaders["Accept"]?.Contains("text/html") == true)
     {
         return(new DawgWebResourceResponse(request));
     }
     return(null);
 }
Example #24
0
 private void FormsWebViewRenderer_OnControlChanged(object sender, Android.Webkit.WebView e)
 {
     // 在pc上调试webview
     // chrome://inspect/#devices
     Android.Webkit.WebView.SetWebContentsDebuggingEnabled(true);
     WebSpeakerJs.Context = this;
     e.AddJavascriptInterface(WebSpeakerJs.Instance, WebSpeakerJs.INTERFACE);
 }
Example #25
0
 public override bool OnJsAlert(Android.Webkit.WebView view, string url, string message, JsResult result) {
     if(message.StartsWith("something") { //This is where you would look for your magic string, anything starting with your magic string is what you would extract and/or act on
         //Do something....
         result.Cancel(); //This cancels the JS alert (there are other talked about methods of doing this but this works for me)
         return true; //This tells the WebView "we got this"
     }
     return base.OnJsAlert(view, url, message, result); //Let the WebView handle this since we did not find out special string
 }
        public override void OnProgressChanged(Android.Webkit.WebView view, int newProgress)
        {
            //new progress is between 0-100 need to convert to 0-1

            double progress = newProgress / 100;

            Debug.WriteLine($"WebViewChromeClient - Progress Changed! - New Progress: {newProgress}");
            ProgressChanged?.Invoke(this, new ProgressEventArgs(progress));
        }
            public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, string url)
            {
                if (_originalClient != null)
                {
                    return(_originalClient.ShouldOverrideUrlLoading(view, url));
                }

                return(false);
            }
            public override bool ShouldOverrideKeyEvent(Android.Webkit.WebView view, Android.Views.KeyEvent e)
            {
                if (_originalClient != null)
                {
                    return(_originalClient.ShouldOverrideKeyEvent(view, e));
                }

                return(false);
            }
 public override void OnPageFinished(Android.Webkit.WebView webView, string url)
 {
     // TODO - investigate whether even using OnPageFinished is enough to always avoid getting a blank page output
     PrintServiceAndroidHelper.PrintFromWebView(webView, _printJobConfiguration);
     _printJobConfiguration = null;
     _webView.Dispose();
     _webView = null;
     Dispose(); // is this legitimate?
 }
Example #30
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Main);
            // SetUpMap();
            Android.Webkit.WebView webView = (Android.Webkit.WebView)FindViewById(Resource.Id.webView);
            webView.Settings.JavaScriptEnabled = true;
            webView.LoadUrl("http://maps.googleapis.com/maps/api/staticmap?ll=36.97,%20-122&lci=bike&z=13&t=p&size=500x500&sensor=true");
        }