Exemplo n.º 1
0
 /// <summary>
 /// Subscribe to Resume Message
 /// </summary>
 private void SubscribeToResume()
 {
     MessagingCenter.Subscribe <App>(this, "APP_RESUME", (s) => {
         // reconnect to rtm, update conversations and notifications
         _webview.InjectJavaScript(ScriptHelper.ReconnectScript);
         _webview.InjectJavaScript(ScriptHelper.UpdateBadgeScript);
     });
 }
Exemplo n.º 2
0
        private async void CallCsFunctionButton_Clicked(object sender, EventArgs e)
        {
            using (var client = new HttpClient())
            {
                var uri      = new Uri("http://employeemobileappservice.azurewebsites.net/api/employeeapi?empId=2");
                var response = await client.GetAsync(uri);

                var uiData = JsonConvert.DeserializeObject <EmployeeForm>(await response.Content.ReadAsStringAsync());
                hybrid.CallJsFunction($"loadHtml('{uiData.Data}')");
                hybrid.InjectJavaScript("alert(\"Hello world!\");");
                //hybrid.CallJsFunction($"loadHtml", uiData.Data);
            }
        }
Exemplo n.º 3
0
        void PageDataLoaded()
        {
            if (_hybridWebView == null)
            {
                _hybridWebView = new HybridWebView(new JsonNetJsonSerializer());
                _hybridWebView.HorizontalOptions = LayoutOptions.FillAndExpand;
                _hybridWebView.VerticalOptions   = LayoutOptions.FillAndExpand;
                _hybridWebView.RegisterCallback("EditVisible", (data) => {
                    PageModel.EditVisible.Execute(data);
                });
                _hybridWebView.RegisterNativeFunction("GetGraphData", (input) => {
                    return(PageModel.GetGraphData(input));
                });

                _hybridWebView.LoadFinished += (s, e) => {
                    string data = JsonConvert.SerializeObject(PageModel.GraphData).Replace("\r\n", "");
                    _hybridWebView.InjectJavaScript("JellyBeanTrackerApp.buildChartStr('" + data + "');");
                };
                Content = _hybridWebView;
            }

            var profitReportRazorView = new JellyBeanGraph(); // { Model = PageModel.GraphData };
            var html = profitReportRazorView.GenerateString();

            _hybridWebView.LoadContent(html.Replace("\r\n", ""));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="url">The url to use. When a notification is received on Android, this is set to the notification url</param>
        public MainPage(string url = "")
        {
            // create a new hybrid webview
            _webview = new HybridWebView(new JsonSerializer())
            {
                Uri = ResolveUrl(url),
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand
            };

            // resume event
            SubscribeToResume();

            // push notification handler
            NotificationReceived += (sender, args) => {
                var notificationArgs = args as NotificationEventArgs;
                _webview.Uri = notificationArgs.NotificationUrl;
            };

            // register callbacks
            RegisterCallbacks();

            // handle load finished
            _webview.LoadFinished += (sender, args) => {
                _webview.InjectJavaScript(ScriptHelper.ScriptChecker);
            };

            // handle webview errors
            _webview.LoadError += async(sender, args) => {
                var select = await DisplayAlert("Connection error", $"The {Constants.DisplayShortName} site could not be loaded", $"Select another {Constants.DisplayShortName} site", "Retry");

                if (select)
                {
                    CrossSettings.Current.Remove("userguid");
                    CrossSettings.Current.Remove("url");
                    CrossSettings.Current.Remove("theme");

                    SelectSite();
                }
                else
                {
                    _webview.Uri = ResolveUrl(url);
                }
            };

            // the layout
            if (Device.RuntimePlatform == Device.iOS)
            {
                Padding = new Thickness(0, 50);
            }

            Content = _webview;
        }