Пример #1
0
 void Relogin()
 {
     if (_googleApiClient.HasConnectedApi(DriveClass.API))
     {
         _googleApiClient.ClearDefaultAccountAndReconnect();
     }
 }
Пример #2
0
 public void logoutFromGoogle(GoogleApiClient mGoogleApiClient)
 {
     if (mGoogleApiClient != null && mGoogleApiClient.IsConnected)
     {
         mGoogleApiClient.ClearDefaultAccountAndReconnect().SetResultCallback(new resultCallbackMethod(mGoogleApiClient));
     }
 }
Пример #3
0
        public void OnConnected(Bundle connectionHint)
        {
            //AccountEmail = App.State.BackupAccountEmail;

            if (!_googleAccountPopupOpened)
            {
                _googleApiClient.ClearDefaultAccountAndReconnect();
            }
            else
            {
                //Connected?.Invoke(this, success: true);
            }
        }
Пример #4
0
        public static async Task SignIn()
        {
            var signInIntent = Auth.GoogleSignInApi.GetSignInIntent(ApiClient);

            if (ApiClient != null && ApiClient.IsConnected)
            {
                await ApiClient.ClearDefaultAccountAndReconnect();
            }

            UIRuntime.CurrentActivity.StartActivityForResult(signInIntent, SIGNIN_REQUEST_CODE);

            await Task.CompletedTask;
        }
        private void Googlebutton_Click(object sender, EventArgs e)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                Toast.MakeText(this, "Please check your internet connection", ToastLength.Long).Show();
                return;
            }
            if (firebaseAuth.CurrentUser == null)
            {
                AppDataHelper.editor.PutString("WhichButtonClick", "google");
                AppDataHelper.editor.Apply();

                var intent = Auth.GoogleSignInApi.GetSignInIntent(googleApiClient);
                googleApiClient.ClearDefaultAccountAndReconnect();
                StartActivityForResult(intent, 1);
            }
        }
Пример #6
0
        public async void OnClick(View v)
        {
            switch (v.Id)
            {
            case Resource.Id.sign_in_button:
                ShouldResolve = true;
                GoogleApiClient.Connect();
                var signInIntent = Auth.GoogleSignInApi.GetSignInIntent(GoogleApiClient);
                StartActivityForResult(signInIntent, RC_SIGN_IN);
                break;

            case Resource.Id.sign_out_button:
                if (GoogleApiClient.IsConnected)
                {
                    await GoogleApiClient.ClearDefaultAccountAndReconnect();

                    GoogleApiClient.Disconnect();
                }
                UpdateUI(false);
                break;
            }
        }
Пример #7
0
        protected override void OnCreate (Bundle savedInstanceState)
        {
            base.OnCreate (savedInstanceState);
            // If you want to understand the life cycle more, you can use below command to turn on
            // verbose logging for this Activity on your testing device:
            // adb shell setprop log.tag.SignInActivity VERBOSE
            mIsLogVerbose = Android.Util.Log.IsLoggable (TAG, Android.Util.LogPriority.Verbose);

            SetContentView (Resource.Layout.sign_in_activity);

            restoreState (savedInstanceState);

            logVerbose ("Activity onCreate, creating new GoogleApiClient");

            mGoogleApiClient = buildGoogleApiClient (false);

            mSignInStatus = FindViewById<TextView> (Resource.Id.sign_in_status);
            mSignInButton = FindViewById<SignInButton> (Resource.Id.sign_in_button);
            mSignInButton.Click += (sender, e) => {
                if (!mGoogleApiClient.IsConnecting) {
                    int available = GooglePlayServicesUtil.IsGooglePlayServicesAvailable (this);
                    if (available != ConnectionResult.Success) {
                        ShowDialog (DIALOG_GET_GOOGLE_PLAY_SERVICES);
                        return;
                    }

                    mSignInClicked = true;
                    mSignInStatus.Text = GetString (Resource.String.signing_in_status);
                    resolveSignInError ();
                }
            };

            mServerAuthCodeDisabledLabel = FindViewById<TextView> (Resource.Id.server_auth_code_disabled);
            mServerAuthCodeResetButton = FindViewById<View> (Resource.Id.server_auth_code_reset_button);
            mServerAuthCodeResetButton.Click += (sender, e) => {
                mServerAuthCodeRequired.Set (true);
            };
            if (!isUsingOfflineAccess ()) {
                mServerAuthCodeDisabledLabel.Visibility = ViewStates.Visible;
                mServerAuthCodeResetButton.Visibility = ViewStates.Gone;
            } else {
                mServerAuthCodeDisabledLabel.Visibility = ViewStates.Gone;
                mServerAuthCodeResetButton.Visibility = ViewStates.Visible;
            }

            mSignOutButton = FindViewById<View> (Resource.Id.sign_out_button);
            mSignOutButton.Click += (sender, e) => {
                if (mGoogleApiClient.IsConnected)
                    mGoogleApiClient.ClearDefaultAccountAndReconnect ();
            };
            mRevokeAccessButton = FindViewById (Resource.Id.revoke_access_button);
            mRevokeAccessButton.Click += async delegate {
                mServerAuthCodeRequired.Set (true);
                if (mGoogleApiClient.IsConnected) {
                    var result = await PlusClass.AccountApi.RevokeAccessAndDisconnectAsync (mGoogleApiClient);

                    if (result.IsSuccess) {
                        mSignInStatus.SetText (Resource.String.revoke_access_status);
                    } else {
                        mSignInStatus.SetText (Resource.String.revoke_access_error_status);
                    }
                    mGoogleApiClient.Reconnect ();
                       
                    updateButtons (false /* isSignedIn */);
                }
            };

            mScopeSelector = FindViewById<ToggleButton> (Resource.Id.scope_selection_toggle);
            mScopeSelector.CheckedChange += (sender, e) => {
                mGoogleApiClient.Disconnect ();
                // Since we changed the configuration, the cached connection result is no longer
                // valid.
                mConnectionResult = null;
                mGoogleApiClient = buildGoogleApiClient (e.IsChecked);
                mGoogleApiClient.Connect ();
            };


            if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb) {
                ActionBar.SetDisplayHomeAsUpEnabled (true);
            }
        }
Пример #8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // If you want to understand the life cycle more, you can use below command to turn on
            // verbose logging for this Activity on your testing device:
            // adb shell setprop log.tag.SignInActivity VERBOSE
            //mIsLogVerbose = Android.Util.Log.IsLoggable (TAG, Android.Util.LogPriority.Verbose);
            mIsLogVerbose = true;

            SetContentView(Resource.Layout.sign_in_activity);

            restoreState(savedInstanceState);

            logVerbose("Activity onCreate, creating new GoogleApiClient");

            mGoogleApiClient = buildGoogleApiClient(false);

            mSignInStatus        = FindViewById <TextView> (Resource.Id.sign_in_status);
            mSignInButton        = FindViewById <SignInButton> (Resource.Id.sign_in_button);
            mSignInButton.Click += (sender, e) => {
                if (!mGoogleApiClient.IsConnecting)
                {
                    int available = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this);
                    if (available != ConnectionResult.Success)
                    {
                        ShowDialog(DIALOG_GET_GOOGLE_PLAY_SERVICES);
                        return;
                    }

                    mSignInClicked     = true;
                    mSignInStatus.Text = GetString(Resource.String.signing_in_status);
                    resolveSignInError();
                }
            };

            mPlusButton        = FindViewById <PlusOneButton>(Resource.Id.plus_button);
            mPlusButton.Click += MPlusButton_Click;

            mServerAuthCodeDisabledLabel      = FindViewById <TextView> (Resource.Id.server_auth_code_disabled);
            mServerAuthCodeResetButton        = FindViewById <View> (Resource.Id.server_auth_code_reset_button);
            mServerAuthCodeResetButton.Click += (sender, e) => {
                mServerAuthCodeRequired.Set(true);
            };
            if (!isUsingOfflineAccess())
            {
                mServerAuthCodeDisabledLabel.Visibility = ViewStates.Visible;
                mServerAuthCodeResetButton.Visibility   = ViewStates.Gone;
            }
            else
            {
                mServerAuthCodeDisabledLabel.Visibility = ViewStates.Gone;
                mServerAuthCodeResetButton.Visibility   = ViewStates.Visible;
            }

            mSignOutButton        = FindViewById <View> (Resource.Id.sign_out_button);
            mSignOutButton.Click += (sender, e) => {
                if (mGoogleApiClient.IsConnected)
                {
                    mGoogleApiClient.ClearDefaultAccountAndReconnect();
                }
            };
            mRevokeAccessButton        = FindViewById(Resource.Id.revoke_access_button);
            mRevokeAccessButton.Click += async delegate {
                mServerAuthCodeRequired.Set(true);
                if (mGoogleApiClient.IsConnected)
                {
                    var result = await PlusClass.AccountApi.RevokeAccessAndDisconnectAsync(mGoogleApiClient);

                    if (result.IsSuccess)
                    {
                        mSignInStatus.SetText(Resource.String.revoke_access_status);
                    }
                    else
                    {
                        mSignInStatus.SetText(Resource.String.revoke_access_error_status);
                    }
                    mGoogleApiClient.Reconnect();

                    updateButtons(false /* isSignedIn */);
                }
            };

            mScopeSelector = FindViewById <ToggleButton> (Resource.Id.scope_selection_toggle);
            mScopeSelector.CheckedChange += (sender, e) => {
                mGoogleApiClient.Disconnect();
                // Since we changed the configuration, the cached connection result is no longer
                // valid.
                mConnectionResult = null;
                mGoogleApiClient  = buildGoogleApiClient(e.IsChecked);
                mGoogleApiClient.Connect();
            };


            if (Build.VERSION.SdkInt >= BuildVersionCodes.Honeycomb)
            {
                ActionBar.SetDisplayHomeAsUpEnabled(true);
            }
        }