public static WebAuthenticatorFragment NewInstance(WebAuthenticator authenticator)
        {
            var frag = new WebAuthenticatorFragment
            {
                Arguments     = new Bundle(),
                Authenticator = authenticator
            };

            return(frag);
        }
        protected override void SetPlatformUI(UIContext context)
        {
            var relativeLayout = new RelativeLayout(context);
            var fragment       = WebAuthenticatorFragment.NewInstance(this);

            var fragmentTransaction = ((Activity)context).FragmentManager.BeginTransaction();

            fragmentTransaction.Add(Android.Resource.Id.Content, fragment);
            fragmentTransaction.Commit();

            fragment.BeginLoadingInitialUrl();
        }
Exemple #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            //
            // Load the state either from a configuration change or from the intent.
            //
            state = LastNonConfigurationInstance as State;
            if (state == null && Intent.HasExtra("StateKey"))
            {
                var stateKey = Intent.GetStringExtra("StateKey");
                state = StateRepo.Remove(stateKey);
            }
            if (state == null)
            {
                Finish();
                return;
            }

            Title = state.Authenticator.Title;

            //
            // Watch for completion
            //
            state.Authenticator.Completed += (s, e) => {
                SetResult(e.IsAuthenticated ? Result.Ok : Result.Canceled);
                Finish();
            };
            state.Authenticator.Error += (s, e) => {
                if (e.Exception != null)
                {
                    this.ShowError("Authentication Error", e.Exception);
                }
                else
                {
                    this.ShowError("Authentication Error", e.Message);
                }
            };

            //
            // Build the UI
            //
            var relativeLayout = new RelativeLayout(this);

            relativeLayout.SetBackgroundColor(Color.White);

            var linearLayout = new LinearLayout(this)
            {
                Orientation      = Orientation.Vertical,
                LayoutParameters = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.FillParent,
                    LinearLayout.LayoutParams.MatchParent)
            };

            linearLayout.SetGravity(GravityFlags.Bottom);

            var progressBar = new ProgressBar(this)
            {
                LayoutParameters = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.FillParent,
                    dpToPx(40))
            };

            linearLayout.AddView(progressBar);

            var textView = new TextView(this)
            {
                LayoutParameters = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WrapContent,
                    LinearLayout.LayoutParams.WrapContent)
                {
                    Gravity = GravityFlags.CenterHorizontal
                },
                Text = "Logging in..."
            };

            ((ViewGroup.MarginLayoutParams)textView.LayoutParameters).BottomMargin = dpToPx(75);
            linearLayout.AddView(textView);

            relativeLayout.AddView(linearLayout);

            AddContentView(relativeLayout, new LinearLayout.LayoutParams(
                               Android.Views.ViewGroup.LayoutParams.FillParent,
                               Android.Views.ViewGroup.LayoutParams.MatchParent)
            {
                Gravity = GravityFlags.Bottom
            });

            var details             = WebAuthenticatorFragment.NewInstance(state.Authenticator);
            var fragmentTransaction = this.FragmentManager.BeginTransaction();

            fragmentTransaction.Add(Android.Resource.Id.Content, details);
            fragmentTransaction.Commit();

            details.BeginLoadingInitialUrl();
        }
 public Client(WebAuthenticatorFragment fragment)
 {
     this.fragment = fragment;
 }