protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.WebView);
            var webView = FindViewById <WebView>(Resource.Id.webView);

            webView.LongClickable         = false;
            webView.HapticFeedbackEnabled = false;
            webView.LongClick            += (sender, args) => { };

            switch ((ESample)Intent.GetIntExtra("Sample", -1))
            {
            case ESample.MethodSamples:
                new WebViewHybridBridge(webView).Add(
                    new ClassBridge <MethodSamplesController>().AddInstance(new MethodSamplesController(this),
                                                                            "Controller"));
                webView.LoadDataWithBaseURL("file:///android_asset/", new MethodSamples().GenerateString(),
                                            "text/html", "UTF-8", null);
                break;

            case ESample.PropertySamples:
                new WebViewHybridBridge(webView).Add(
                    new ClassBridge <PropertySamplesController>().AddInstance(new PropertySamplesController(),
                                                                              "Controller"));
                webView.LoadDataWithBaseURL("file:///android_asset/", new PropertySamples().GenerateString(),
                                            "text/html", "UTF-8", null);
                break;

            case ESample.EventSamples:
                new WebViewHybridBridge(webView).Add(new ClassBridge <EventSamplesController>());
                webView.LoadDataWithBaseURL("file:///android_asset/", new EventSamples().GenerateString(),
                                            "text/html", "UTF-8", null);
                break;

            case ESample.MessagingSamples:
                var bridge = new WebViewHybridBridge(webView)
                {
                    new HybridMessagingHandler()
                };
                bridge.JavascriptTimeout = TimeSpan.FromSeconds(30);
                bridge.Add(
                    new ClassBridge <MessagingSamplesController>().AddInstance(
                        new MessagingSamplesController(this, bridge.Get <HybridMessagingHandler>()), "Controller"));
                webView.LoadDataWithBaseURL("file:///android_asset/", new MessagingSamples().GenerateString(),
                                            "text/html", "UTF-8", null);
                break;

            default:
                StartActivity(typeof(SamplesActivity));
                break;
            }
        }
Exemple #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (e.Parameter != null)
            {
                switch ((ESample)e.Parameter)
                {
                case ESample.MethodSamplesAsync:
                    new WebViewHybridBridge(webView).Add(
                        new ClassBridge <MethodSamplesController>().AddInstance(new MethodSamplesController(),
                                                                                "Controller"));
                    webView.Navigate(new Uri(@"ms-appx-web:///Views/MethodSamplesAsync.html"));
                    break;

                case ESample.PropertySamplesAsync:
                    new WebViewHybridBridge(webView).Add(
                        new ClassBridge <PropertySamplesControllerAsync>().AddInstance(new PropertySamplesControllerAsync(),
                                                                                       "Controller"));
                    webView.Navigate(new Uri(@"ms-appx-web:///Views/PropertySamplesAsync.html"));
                    break;

                case ESample.EventSamplesAsync:
                    new WebViewHybridBridge(webView).Add(new ClassBridge <EventSamplesController>());
                    webView.Navigate(new Uri(@"ms-appx-web:///Views/EventSamplesAsync.html"));
                    break;

                case ESample.MessagingSamplesAsync:
                    var bridgeAsync = new WebViewHybridBridge(webView)
                    {
                        new HybridMessagingHandler()
                    };
                    bridgeAsync.JavascriptTimeout = TimeSpan.FromSeconds(30);
                    bridgeAsync.Add(
                        new ClassBridge <MessagingSamplesController>().AddInstance(
                            new MessagingSamplesController(bridgeAsync.Get <HybridMessagingHandler>()), "Controller"));
                    webView.Navigate(new Uri(@"ms-appx-web:///Views/MessagingSamplesAsync.html"));
                    break;

                case ESample.MethodSamples:
                    new WebViewHybridServer(webView).Add(
                        new ClassBridge <MethodSamplesController>().AddInstance(new MethodSamplesController(),
                                                                                "Controller"));
                    webView.Navigate(new Uri(@"ms-appx-web:///Views/MethodSamples.html"));
                    break;

                case ESample.PropertySamples:
                    new WebViewHybridServer(webView).Add(
                        new ClassBridge <PropertySamplesController>().AddInstance(new PropertySamplesController(),
                                                                                  "Controller"));
                    webView.Navigate(new Uri(@"ms-appx-web:///Views/PropertySamples.html"));
                    break;

                case ESample.EventSamples:
                    new WebViewHybridServer(webView).Add(new ClassBridge <EventSamplesController>());
                    webView.Navigate(new Uri(@"ms-appx-web:///Views/EventSamples.html"));
                    break;

                case ESample.MessagingSamples:
                    var bridge = new WebViewHybridServer(webView)
                    {
                        new HybridMessagingHandler()
                    };
                    bridge.JavascriptTimeout = TimeSpan.FromSeconds(30);
                    bridge.Add(
                        new ClassBridge <MessagingSamplesController>().AddInstance(
                            new MessagingSamplesController(bridge.Get <HybridMessagingHandler>()), "Controller"));
                    webView.Navigate(new Uri(@"ms-appx-web:///Views/MessagingSamples.html"));
                    break;

                default:
                    GoBack();
                    break;
                }
            }
        }