コード例 #1
0
        protected void custom_tabs_activit_manager_CustomTabsServiceConnected
        (
            Content.ComponentName name,
            CustomTabsClient client
        )
        {
            custom_tabs_intent_builder = new CustomTabsIntent.Builder(custom_tabs_activity_manager.Session);

            custom_tabs_intent_builder.EnableUrlBarHiding();

            if (CustomTabsConfiguration.IsWarmUpUsed)
            {
                System.Diagnostics.Debug.WriteLine("CustomTabsActivityManager.WarmUp()");
                client.Warmup(0);
                //custom_tabs_activity_manager.Warmup();
            }

            if (CustomTabsConfiguration.IsPrefetchUsed)
            {
                System.Diagnostics.Debug.WriteLine("CustomTabsActivityManager PREFETCH");
                custom_tabs_activity_manager.MayLaunchUrl(uri.ToString(), null, null);
            }

            if (CustomTabsConfiguration.AreAnimationsUsed)
            {
                custom_tabs_intent_builder.SetStartAnimations
                (
                    activity,
                    Xamarin.Auth.Resource.Animation.slide_in_right,
                    Xamarin.Auth.Resource.Animation.slide_out_left
                );
                custom_tabs_intent_builder.SetExitAnimations
                (
                    activity,
                    global::Android.Resource.Animation.SlideInLeft,
                    global::Android.Resource.Animation.SlideOutRight
                );
            }

            custom_tabs_activity_manager.LaunchUrl(uri.ToString(), custom_tabs_intent_builder.Build());

            return;
        }
コード例 #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

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

            editText        = FindViewById <EditText> (Resource.Id.edit);
            connectButton   = FindViewById <Button> (Resource.Id.connect_button);
            warmupButton    = FindViewById <Button> (Resource.Id.warmup_button);
            mayLaunchButton = FindViewById <Button> (Resource.Id.may_launch_button);
            launchButton    = FindViewById <Button> (Resource.Id.launch_button);
            Spinner spinner = FindViewById <Spinner> (Resource.Id.spinner);

            customTabs = new CustomTabsActivityManager(this);
            customTabs.CustomTabsServiceConnected += (name, client) => {
                connectButton.Enabled   = false;
                warmupButton.Enabled    = true;
                mayLaunchButton.Enabled = true;
                launchButton.Enabled    = true;
            };
            customTabs.CustomTabsServiceDisconnected += (name) => {
                connectButton.Enabled   = true;
                warmupButton.Enabled    = false;
                mayLaunchButton.Enabled = false;
                launchButton.Enabled    = false;
            };
            customTabs.NavigationEvent += (navigationEvent, extras) => {
                Android.Util.Log.Debug(TAG, "Navigation: " + navigationEvent);
            };


            simpleLaunch        = FindViewById <Button> (Resource.Id.buttonSimpleLaunch);
            simpleLaunch.Click += (sender, e) => {
                var mgr = new CustomTabsActivityManager(this);
                mgr.CustomTabsServiceConnected += delegate {
                    mgr.LaunchUrl("http://xamarin.com");
                };
                mgr.BindService();
            };

            editText.RequestFocus();
            connectButton.Click += delegate {
                if (!customTabs.BindService(packageNameToBind))
                {
                    Toast.MakeText(this, "Custom Tabs Not Supported - try installing Chrome", ToastLength.Long).Show();
                }
            };
            warmupButton.Click += delegate {
                warmupButton.Enabled = customTabs.Warmup();

                Toast.MakeText(this, "Warmed Up", ToastLength.Short).Show();
            };
            mayLaunchButton.Click += delegate {
                var url = editText.Text;

                mayLaunchButton.Enabled = customTabs.MayLaunchUrl(url, null, null);

                Toast.MakeText(this, "May Launch Called", ToastLength.Short).Show();
            };
            launchButton.Click += delegate {
                var url = editText.Text;

                var builder = new CustomTabsIntent.Builder(customTabs.Session)
                              .SetToolbarColor(Color.Argb(255, 52, 152, 219))
                              .SetShowTitle(true)
                              .SetStartAnimations(this, Resource.Animation.slide_in_right, Resource.Animation.slide_out_left)
                              .SetExitAnimations(this, Resource.Animation.slide_in_left, Resource.Animation.slide_out_right);

                prepareMenuItems(builder);
                prepareActionButton(builder);

                var customTabsIntent = builder.Build();

                CustomTabsHelper.AddKeepAliveExtra(this, customTabsIntent.Intent);

                customTabsIntent.LaunchUrl(this, Android.Net.Uri.Parse(url));
            };

            spinner.Adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem,
                                                        CustomTabsHelper.Packages);


            spinner.ItemSelected += (sender, e) => {
                if (string.IsNullOrEmpty(e.Parent.GetItemAtPosition(e.Position).ToString()))
                {
                    packageNameToBind = null;
                }
            };
            spinner.NothingSelected += (sender, e) => {
                packageNameToBind = null;
            };
        }