コード例 #1
0
        public override void OnActivityResult(int requestCode, int resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            try
            {
                if (requestCode == 1)
                {
                    GoogleSignInResult result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
                    if (result.IsSuccess)
                    {
                        GoogleSignInAccount account = result.SignInAccount;
                        string gClientId            = AppController.Globals.GoogleClientId_Android;
                        string gEmail = account.Email;
                        string gToken = account.IdToken;

                        _cts0 = new CancellationTokenSource();
                        AppController.LoginUser(_cts0, gClientId, gEmail, gToken,
                                                (d) =>
                        {
                            AppController.Settings.LastLoginUserIdUsed   = d.UserId;
                            AppController.Settings.LastLoginUsernameUsed = _email;
                            AppController.Settings.AuthAccessToken       = d.AuthAccessToken;
                            AppController.Settings.AuthExpirationDate    = d.AuthExpirationDate.GetValueOrDefault().ToLocalTime();
                            AppController.Settings.GoogleSignedIn        = true;

                            var f = new GimmicksFragment();
                            this.FragmentManager.BeginTransaction()
                            .AddToBackStack("BeforeGimmicksFragment")
                            .Replace(Resource.Id.ContentLayout, f, "GimmicksFragment")
                            .Commit();
                        },
                                                (error) =>
                        {
                            Toast.MakeText(this.Activity.Application, error, ToastLength.Long).Show();
                        },
                                                () =>
                        {
                            ((MainActivity)this.Activity).UnblockUI();
                        });
                    }
                    else
                    {
                        ((MainActivity)this.Activity).UnblockUI();

                        Toast.MakeText(this.Activity.Application, "Unable to login with Google!", ToastLength.Long).Show();
                    }
                }
            }
            catch (Exception ex)
            {
                ((MainActivity)this.Activity).UnblockUI();

                Toast.MakeText(this.Activity.ApplicationContext, "Error logging with Google!", ToastLength.Long).Show();
            }
            finally
            {
                // Nothing to do
            }
        }
コード例 #2
0
        private void LoginUser()
        {
            if (ValidateInput())
            {
                if (_isLogginUser)
                {
                    return;
                }

                _isLogginUser = true;

                _email    = this.EmailText.Text;
                _password = this.PasswordText.Text;

                // Prevent user form tapping views while logging
                ((MainActivity)this.Activity).BlockUI();

                // Create a new cancellation token for this request
                _cts0 = new CancellationTokenSource();
                AppController.LoginUser(_cts0, _email, _password,
                                        // Service call success
                                        (data) =>
                {
                    AppController.Settings.LastLoginUserIdUsed   = data.UserId;
                    AppController.Settings.LastLoginUsernameUsed = _email;
                    AppController.Settings.AuthAccessToken       = data.AuthAccessToken;
                    AppController.Settings.AuthExpirationDate    = data.AuthExpirationDate.GetValueOrDefault().ToLocalTime();
                    AppController.Settings.GoogleSignedIn        = false;

                    var f = new GimmicksFragment();
                    this.FragmentManager.BeginTransaction()
                    .AddToBackStack("BeforeGimmicksFragment")
                    .Replace(Resource.Id.ContentLayout, f, "GimmicksFragment")
                    .Commit();
                },
                                        // Service call error
                                        (error) =>
                {
                    if (error.Contains("confirm"))
                    {
                        this.VerifyButton.Visibility = ViewStates.Visible;
                    }

                    Toast.MakeText(this.Activity.Application, error, ToastLength.Long).Show();
                },
                                        // Service call finished
                                        () =>
                {
                    _isLogginUser = false;

                    // Allow user to tap views
                    ((MainActivity)this.Activity).UnblockUI();
                });
            }
        }
コード例 #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            #region Desinger Stuff

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.ActivityMain, Resource.Id.ContentLayout, Resource.Id.Toolbar);

            this.SupportActionBar.SetDisplayShowHomeEnabled(true);
            this.SupportActionBar.SetDisplayHomeAsUpEnabled(true);

            #endregion

            this.LoadLayout.Focusable            = true;
            this.LoadLayout.FocusableInTouchMode = true;
            this.LoadLayout.Clickable            = true;
            this.LoadLayout.Visibility           = ViewStates.Gone;

            bool isResuming = this.SupportFragmentManager.FindFragmentById(Resource.Id.ContentLayout) != null;
            if (!isResuming)
            {
                this.SupportFragmentManager.BeginTransaction()
                .Add(Resource.Id.ContentLayout, new LoginFragment(), "LoginFragment")
                .Commit();

                _userRestored = this.Arguments.GetBoolean("UserRestored", false);
                if (_userRestored)
                {
                    var f = new GimmicksFragment();
                    this.SupportFragmentManager.BeginTransaction()
                    .AddToBackStack("BeforeGimmicksFragment")
                    .Replace(Resource.Id.ContentLayout, f, "GimmicksFragment")
                    .Commit();
                }
            }
        }