private void LoginActivity_Click(object sender, EventArgs e) { View dialogLayout = LayoutInflater.Inflate(Resource.Layout.DialogButtonsX2, null); var termsButton = dialogLayout.FindViewById <Button>(Resource.Id.dialogBtn1); termsButton.Text = Resources.GetString(Resource.String.LoginOpenTerms); termsButton.Click += (args, o) => { Intent browserIntent = new Intent(Intent.ActionView, global::Android.Net.Uri.Parse( ConfidentialData.api + "terms")); StartActivity(browserIntent); }; var privacyButton = dialogLayout.FindViewById <Button>(Resource.Id.dialogBtn2); privacyButton.Text = Resources.GetString(Resource.String.LoginOpenPrivacy); privacyButton.Click += (args, o) => { Intent browserIntent = new Intent(Intent.ActionView, global::Android.Net.Uri.Parse( ConfidentialData.api + "privacypolicy")); StartActivity(browserIntent); }; new global::Android.Support.V7.App.AlertDialog.Builder(this) .SetTitle(Resource.String.LoginTermsTitle) .SetMessage(Resource.String.LoginTerms) .SetView(dialogLayout) .SetNegativeButton(Resource.String.dialog_cancel, (a, args) => { }) .SetPositiveButton(Resource.String.LoginAgreeTerms, (a, args) => { string buttonText = ((Button)sender).Text; ExternalLogin chosen = providers.FirstOrDefault(prov => prov.Name == buttonText); if (chosen == null) { return; } chromeManager = new CustomTabsActivityManager(this); // build custom tab var builder = new CustomTabsIntent.Builder(chromeManager.Session) .SetShowTitle(true) .EnableUrlBarHiding(); var customTabsIntent = builder.Build(); customTabsIntent.Intent.AddFlags(ActivityFlags.NoHistory); chromeManager.Warmup(0L); customTabsIntent.LaunchUrl(this, global::Android.Net.Uri.Parse(ConfidentialData.api + chosen.Url)); }) .Show(); }
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; }; }