示例#1
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            this.webHybrid = new WebHybrid(this.webView, new JsonSerializer());

            SaveFilesInHTMLFolderToIsoStore();
            this.webView.Navigate(new Uri("HTML/home.html", UriKind.Relative));

            //var fi = new FileInfo(@"./Assets/home.html");

            //using (var streamReader = new StreamReader(fi.FullName))
            //{
            //    this.webView.NavigateToString(streamReader.ReadToEnd());
            //}

            this.webHybrid.RegisterCallback("test", s =>
                {
                    System.Diagnostics.Debug.WriteLine(s);
                    var serializer = new JsonSerializer();
                    var m = serializer.Deserialize<ChartViewModel>(s);
                    System.Diagnostics.Debug.WriteLine(m);
                });

            this.webHybrid.RegisterCallback("dataCallback", s => System.Diagnostics.Debug.WriteLine(s));
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            
            var webHybrid = new WebHybrid (this.webView, new SimplyMobile.Text.ServiceStack.JsonSerializer());

            string homePageUrl = NSBundle.MainBundle.BundlePath + "/Content/ButtonClicks.html";

            this.webView.LoadRequest (new NSUrlRequest (new NSUrl (homePageUrl, false)));

            this.model = new NavigationViewModel (
                Resolver.GetService<INavigationController> (),
                webHybrid);
//            webHybrid.RegisterCallback ("openNativeView", idString =>
//            {
//                int id;
//                if (int.TryParse(idString, out id))
//                {
//                    var newViewController = new NewViewController(id);
//                    this.NavigationController.PushViewController(newViewController, true);
//                }
//                else
//                {
//                    // notify something here
//                }
//            });
        }
示例#3
0
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

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

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

            var serializer = new SimplyMobile.Text.ServiceStack.JsonSerializer();



            var webView = FindViewById<WebView> (Resource.Id.webView1);

            this.webHybrid = new WebHybrid (webView, serializer);

            this.webHybrid.RegisterCallback ("dataCallback", Console.WriteLine);

            webView.LoadUrl("file:///android_asset/Content/home.html");

            button.Click += delegate
            {
                var data = new Data()
                {
                    Name = "Sami",
                    Count = 99
                };

                this.webHybrid.InjectJavaScript(string.Format("Native(\"test\", {0})", serializer.Serialize(data)));

                this.webHybrid.CallJsFunction("Native", "test", data);

                this.webHybrid.CallJsFunction("alert", "test");
            };
        }
示例#4
0
 public Client(WebHybrid webHybrid)
 {
     this.webHybrid = new WeakReference<WebHybrid>(webHybrid);
 }
示例#5
0
 public Client(WebHybrid webHybrid)
 {
     this.webHybrid = new WeakReference <WebHybrid>(webHybrid);
 }
        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            
            // Perform any additional setup after loading the view, typically from a nib.

            string homePageUrl = NSBundle.MainBundle.BundlePath + "/Content/home.html";

            var serializer = new JsonSerializer ();
            this.webHybrid = new WebHybrid (this.webView, serializer);

            this.webHybrid.RegisterCallback ("test", Console.WriteLine);

            this.buttonSendScript.TouchUpInside += (object sender, EventArgs e) => 
            {
                //this.webHybrid.InjectJavaScript("RunMyItem();");
                //this.webHybrid.CallJsFunction("alert", "test");
            };

//          this.buttonSendScript.OnClick ((s, e) => {
//
//
//              this.webHybrid.CallJsFunction ("onViewModelData", model);
//
//
//          });

            this.webView.LoadRequest (new NSUrlRequest (new NSUrl (homePageUrl, false)));


            var model = ChartViewModel.Dummy;

            var dataSource = new ObservableDataSource<DataPoint> ()
            {
                Data = model.DataPoints
            };

            dataSource.Bind(this.datapointTable);

            foreach( var point in model.DataPoints) point.PropertyChanged += (s,e) => this.webHybrid.CallJsFunction ("onViewModelData", model);
//          if (this.canvasView != null) 
//          {
//              var canvas = new CanvasView (this.canvasView, serializer);
//              canvas.Load ();
//
//              var model = new ColumnModel () {
//                  theme = "theme2",
//                  title = new Title()
//                  {
//                      text = "Canvas Demo"
//                  },
//                  data = new ColumnData()
//                  {
//                      dataPoints = new ObservableCollection<DataPoint>(
//                          new[] {new DataPoint() { label = "Banana", y = 10 }}
//                      )
//                  }
//              };
//
//              canvas.SetModel (model);
//          }
        }