com.google.android.gms.plus.Plus Java Examples

The following examples show how to use com.google.android.gms.plus.Plus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From gplus-haiku-client-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View view) {
    if (view.getId() == R.id.button_sign_in) {
        beginSignInFlow();
    } else if (view.getId() == R.id.button_create_haiku) {
        Intent intent = new Intent(this, CreateHaikuActivity.class);
        startActivityForResult(intent, REQ_CREATE_HAIKU);
    } else if (view.getId() == R.id.button_sign_out) {
        setProgressBarIndeterminateVisibility(true);
        mHaikuApi.signOut(this);
        mGoogleApiClient.disconnect();
    } else if (view.getId() == R.id.button_disconnect) {
        setProgressBarIndeterminateVisibility(true);
        mHaikuApi.disconnect(this);

        if (mGoogleApiClient.isConnected()) {
            Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
            Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient);
            mGoogleApiClient.disconnect();
        }
    }
}
 
Example #2
Source File: MainActivity.java    From android-google-accounts with Apache License 2.0 6 votes vote down vote up
/**
 * Called when the Activity successfully connects to Google Play Services. When the function
 * is triggered, an account was selected on the device, the selected account has granted
 * requested permissions to the app, and the app has established a connection to Google Play
 * Services.
 *
 * @param connectionHint can be inspected for additional connection info
 */
@Override
public void onConnected(Bundle connectionHint) {
    // Reaching onConnected means the user signed in via their Google Account and all APIs
    // previously specified are available.
    googleApiClientConnectionStateChange(true);

    // IMPORTANT NOTE: If you are storing any user data locally or even in a remote
    // application DO NOT associate it to the accountName (which is also an email address).
    // Associate the user data to the Google Account ID. Under some circumstances it is possible
    // for a Google Account to have the primary email address change.

    Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);

    // The logic below ensures you won't mix account data if a user switches between Google
    // Accounts.
    // TODO(developer): Check the account ID against any previous login locally.
    // TODO(developer): Delete the local data if the account ID differs.
    // TODO(developer): Construct local storage keyed on the account ID.

    onSignedIn(currentPerson);
}
 
Example #3
Source File: SoomlaGooglePlus.java    From android-profile with Apache License 2.0 6 votes vote down vote up
private void login(boolean enableGameServices) {
    GoogleApiClient.Builder clientBuilder = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API, Plus.PlusOptions.builder().build())
            .addScope(Plus.SCOPE_PLUS_LOGIN);
    if (enableGameServices) {
        clientBuilder
                .addApi(Games.API, Games.GamesOptions.builder().build())
                .addScope(Games.SCOPE_GAMES);
    }
    googleApiClient = clientBuilder.build();

    if (!googleApiClient.isConnecting()){
        signInRequested = true;
        googleApiClient.connect();
    }
}
 
Example #4
Source File: GPlusUserProfileBuilder.java    From pubnub-android-chat with MIT License 6 votes vote down vote up
public UserProfile build() {

        UserProfile newUserProfile = new UserProfile();
        String email = Plus.AccountApi.getAccountName(googleApiClient);
        newUserProfile.setEmail(email);


        if (Plus.PeopleApi.getCurrentPerson(googleApiClient) != null) {
            Person currentPerson = Plus.PeopleApi.getCurrentPerson(googleApiClient);
            newUserProfile.setUserName(currentPerson.getDisplayName());
            newUserProfile.setFirstName(currentPerson.getName().getGivenName());
            newUserProfile.setLastName(currentPerson.getName().getFamilyName());
            newUserProfile.setImageURL(currentPerson.getImage().getUrl());
            return (newUserProfile);
        }


        return null;
    }
 
Example #5
Source File: MainActivity.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    if (!mGoogleApiClient.isConnecting()) {
        switch (v.getId()) {
            case R.id.sign_in_button:
                mStatus.setText("Signing In");
                resolveSignInError();
                break;
            case R.id.sign_out_button:
                Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
                mGoogleApiClient.disconnect();
                mGoogleApiClient.connect();
                break;
            case R.id.revoke_access_button:
                Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
                Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient);
                mGoogleApiClient = buildGoogleApiClient();
                mGoogleApiClient.connect();
                break;
        }
    }
}
 
Example #6
Source File: MainActivity.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnected(Bundle connectionHint) {
    mSignInButton.setEnabled(false);
    mSignOutButton.setEnabled(true);
    mRevokeButton.setEnabled(true);

    // Indicate that the sign in process is complete.
    mSignInProgress = SIGNED_IN;

    try {
        String emailAddress = Plus.AccountApi.getAccountName(mGoogleApiClient);
        mStatus.setText(String.format("Signed In to My App as %s", emailAddress));
    }
    catch(Exception ex){
        String exception = ex.getLocalizedMessage();
        String exceptionString = ex.toString();
    }

}
 
Example #7
Source File: GoogleApiClientBridge.java    From friendspell with Apache License 2.0 6 votes vote down vote up
public String init(
    Activity activity,
    GoogleApiClient.ConnectionCallbacks connectedListener,
    GoogleApiClient.OnConnectionFailedListener connectionFailedListener) {
  // Configure sign-in to request the user's ID, email address, and basic profile. ID and
  // basic profile are included in DEFAULT_SIGN_IN.
  GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
          .requestEmail()
          .requestId()
          .requestProfile()
          .build();

  GoogleApiClient googleApiClient = new GoogleApiClient.Builder(activity)
      .addConnectionCallbacks(connectedListener)
      .addOnConnectionFailedListener(connectionFailedListener)
      .addApi(Plus.API)
      .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
      .addApi(Nearby.MESSAGES_API)
      .build();
  String token = UUID.randomUUID().toString();
  clients.put(token, googleApiClient);
  return token;
}
 
Example #8
Source File: FriendlyPingActivity.java    From friendlyping with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.sign_out) {
        if (mGoogleApiClient == null) {
            Log.w(TAG, "GoogleApiClient is null. Make sure to set it before accessing it.");
        } else {
            AnalyticsHelper.send(this, USER_LOGOUT);
            if (mGoogleApiClient.isConnected()) {
                Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
                mGoogleApiClient.disconnect();
                PreferenceManager.getDefaultSharedPreferences(this).edit().remove(
                        RegistrationConstants.SENT_TOKEN_TO_SERVER).apply();
            }
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.fragment, getSignInFragment()).commit();
        }
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #9
Source File: FriendlyPingActivity.java    From friendlyping with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_friendly_ping);
    mProgressView = findViewById(R.id.progress);
    mContentView = findViewById(R.id.fragment);
    // Build GoogleApiClient with access to basic profile
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(mConnectionCallbacks)
            .addOnConnectionFailedListener(mConnectionFailedListener)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_PROFILE)
            .build();
    // Check if the intent has a sender, if so save sender in SharedPreferences.
    // When pingers are listed next. this saved sender will be moved to the top.
    if (getIntent().hasExtra(IntentExtras.PING_SENDER)) {
        String pingerToken = getIntent().getStringExtra(IntentExtras.PING_SENDER);
        SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
        editor.putString(PreferenceKeys.SENDING_PINGER_TOKEN, pingerToken).apply();
    }
}
 
Example #10
Source File: BaseActivity.java    From attendee-checkin with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Google+ Sign in
    mApiClient = new GoogleApiClient.Builder(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .addScope(Plus.SCOPE_PLUS_PROFILE)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
    mConnectionProgressDialog = new ProgressDialog(this);
    mConnectionProgressDialog.setMessage(getString(R.string.signing_in));
    GutenbergApplication app = GutenbergApplication.from(this);
    if (!app.isUserLoggedIn()) {
        selectAccount(false);
    } else {
        app.requestSync(false);
    }
    adjustTaskDescription();
}
 
Example #11
Source File: MainActivity.java    From cloud-cup-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Firebase.setAndroidContext(this);
    setContentView(R.layout.activity_main);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();

    firebase = new Firebase(Consts.FIREBASE_URL);
    username = (TextView) findViewById(R.id.username);
    userImage = (ImageView) findViewById(R.id.user_image);
    code = (EditText) findViewById(R.id.code);
    code.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            join();
            return true;
        }
    });
    code.requestFocus();
}
 
Example #12
Source File: MainActivity.java    From firebase-login-demo-android with MIT License 6 votes vote down vote up
/**
 * Unauthenticate from Firebase and from providers where necessary.
 */
private void logout() {
    if (this.mAuthData != null) {
        /* logout of Firebase */
        mFirebaseRef.unauth();
        /* Logout of any of the Frameworks. This step is optional, but ensures the user is not logged into
         * Facebook/Google+ after logging out of Firebase. */
        if (this.mAuthData.getProvider().equals("facebook")) {
            /* Logout from Facebook */
            LoginManager.getInstance().logOut();
        } else if (this.mAuthData.getProvider().equals("google")) {
            /* Logout from Google+ */
            if (mGoogleApiClient.isConnected()) {
                Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
                mGoogleApiClient.disconnect();
            }
        }
        /* Update authenticated user and show login buttons */
        setAuthenticatedUser(null);
    }
}
 
Example #13
Source File: GoogleOAuthActivity.java    From firebase-login-demo-android with MIT License 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();

    mGoogleLoginClicked = true;
    if (!mGoogleApiClient.isConnecting()) {
        if (mGoogleConnectionResult != null) {
            resolveSignInError();
        } else if (mGoogleApiClient.isConnected()) {
            getGoogleOAuthTokenAndLogin();
        } else {
                /* connect API now */
            Log.d(TAG, "Trying to connect to Google API");
            mGoogleApiClient.connect();
        }
    }
}
 
Example #14
Source File: MainActivity.java    From gplus-haiku-client-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    Log.d(TAG, "onConnected");
    HaikuSession.State state = mHaikuPlusSession.checkSessionState();
    if (state == HaikuSession.State.UNAUTHENTICATED) {
        // We think we're signed in, but we don't seem to be!
        // Just bin the current session and start again
        
        // Note: in this case it is possible that we are wrong and the server already has
        // a refresh token for this user.  A more robust method here would be to ask the
        // server for account information rather than disconnecting and connecting.
        Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
        mGoogleApiClient.disconnect();
        mGoogleApiClient.connect();
    } else if (state == HaikuSession.State.HAS_SESSION) {
        if (mUser == null) {
            mHaikuApi.fetchCurrentUser(this);
        } else {
            onUserRetrieved(mUser);
        }
    }
}
 
Example #15
Source File: GameHelper.java    From ANE-Google-Play-Game-Services with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        builder.addApi(Games.API, mGamesApiOptions);
        builder.addScope(Games.SCOPE_GAMES);
    }

    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        builder.addApi(Plus.API);
        builder.addScope(Plus.SCOPE_PLUS_LOGIN);
    }

    if (0 != (mRequestedClients & CLIENT_APPSTATE)) {
        builder.addApi(AppStateManager.API);
        builder.addScope(AppStateManager.SCOPE_APP_STATE);
    }

    mGoogleApiClientBuilder = builder;
    return builder;
}
 
Example #16
Source File: GameHelper.java    From google-play-game-services-ane with MIT License 5 votes vote down vote up
/** Sign out and disconnect from the APIs. */
public void signOut() {
    if (!mGoogleApiClient.isConnected()) {
        // nothing to do
        debugLog("signOut: was already disconnected, ignoring.");
        return;
    }

    // for Plus, "signing out" means clearing the default account and
    // then disconnecting
    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        debugLog("Clearing default account on PlusClient.");
        Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
    }

    // For the games client, signing out means calling signOut and disconnecting
    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        debugLog("Signing out from GamesClient.");
        Games.signOut(mGoogleApiClient);
    }

    // Ready to disconnect
    debugLog("Disconnecting client.");
    mConnectOnStart = false;
    mConnecting = false;
    mGoogleApiClient.disconnect();
}
 
Example #17
Source File: MainActivity.java    From android-google-accounts with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a client.
 *
 * @return un-connected client.
 */
protected synchronized void rebuildGoogleApiClient() {
    // When we build the GoogleApiClient we specify where connected and connection failed
    // callbacks should be returned, which Google APIs our app uses and which OAuth 2.0
    // scopes our app requests.
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(new Scope(Scopes.PROFILE))
            // TODO(developer): Specify any additional API Scopes or APIs you need here.
            // The GoogleApiClient will ensure these APIs are available, and the Scopes
            // are approved before invoking the onConnected callbacks.
            .build();
}
 
Example #18
Source File: MainActivity.java    From android-google-accounts with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View view) {
    if (!mGoogleApiClient.isConnecting()) {
        // We only process button clicks when GoogleApiClient is not transitioning between
        // connected and not connected.
        switch (view.getId()) {
            case R.id.sign_in_button:
                mStatus.setText(R.string.status_signing_in);
                resolveSignInError();
                break;
            case R.id.sign_out_button:
                // We clear the default account on sign out so that Google Play Services will
                // not return an onConnected callback without user interaction.
                deleteUserData();
                Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
                rebuildGoogleApiClient();
                mGoogleApiClient.connect();
                break;
            case R.id.revoke_access_button:
                // After we revoke permissions for the user with a GoogleApiClient instance,
                // we must discard it and create a new one.
                deleteUserData();
                Plus.AccountApi.revokeAccessAndDisconnect(mGoogleApiClient);
                Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
                rebuildGoogleApiClient();
                mGoogleApiClient.connect();
                break;
        }
    }
}
 
Example #19
Source File: MainActivity.java    From android-google-accounts with Apache License 2.0 5 votes vote down vote up
/**
 * Called when the Activity successfully connects to Google Play Services. When the function
 * is triggered, an account was selected on the device, the selected account has granted
 * requested permissions to the app, and the app has established a connection to Google Play
 * Services.
 *
 * @param connectionHint can be inspected for additional connection info
 */
@Override
public void onConnected(Bundle connectionHint) {
    // Reaching onConnected means we consider the user signed in and all APIs previously
    // specified are available.
    Log.i(TAG, "onConnected");

    // IMPORTANT NOTE: If you are storing any user data locally or even in a remote
    // application DO NOT associate it to the accountName (which is also an email address).
    // Associate the user data to the Google Account ID. Under some circumstances it is possible
    // for a Google Account to have the primary email address change.

    Person currentPerson = Plus.PeopleApi.getCurrentPerson(mGoogleApiClient);

    // TODO(developer): Check the account ID against any previous login locally.
    // TODO(developer): Delete the local data if the account ID differs.
    // TODO(developer): Construct local storage keyed on the account ID.

    mStatus.setText(String.format(getResources().getString(R.string
            .signed_in_as), currentPerson.getDisplayName()));
    mSignInButton.setEnabled(false);
    mSignOutButton.setEnabled(true);
    mRevokeButton.setEnabled(true);

    // Indicate that the sign in process is complete.
    mSignInProgress = STATE_DEFAULT;
}
 
Example #20
Source File: GameHelper.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        if (mGamesApiOptions != null) {
            builder.addApi(Games.API, mGamesApiOptions);
        } else {
            builder.addApi(Games.API);
        }

        builder.addScope(Games.SCOPE_GAMES);
    }

    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        if (mPlusApiOptions != null) {
            builder.addApi(Plus.API, mPlusApiOptions);
        } else {
            builder.addApi(Plus.API);
        }
        builder.addScope(Plus.SCOPE_PLUS_LOGIN);
    }

    if (0 != (mRequestedClients & CLIENT_APPSTATE)) {
        builder.addApi(AppStateManager.API);
        builder.addScope(AppStateManager.SCOPE_APP_STATE);
    }

    mGoogleApiClientBuilder = builder;
    return builder;
}
 
Example #21
Source File: GameHelper.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
/** Sign out and disconnect from the APIs. */
public void signOut() {
    if (!mGoogleApiClient.isConnected()) {
        // nothing to do
        debugLog("signOut: was already disconnected, ignoring.");
        return;
    }

    // for Plus, "signing out" means clearing the default account and
    // then disconnecting
    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        debugLog("Clearing default account on PlusClient.");
        Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
    }

    // For the games client, signing out means calling signOut and
    // disconnecting
    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        debugLog("Signing out from the Google API Client.");
        Games.signOut(mGoogleApiClient);
    }

    // Ready to disconnect
    debugLog("Disconnecting client.");
    mConnectOnStart = false;
    mConnecting = false;
    mGoogleApiClient.disconnect();
}
 
Example #22
Source File: GameHelper.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        if (mGamesApiOptions != null) {
            builder.addApi(Games.API, mGamesApiOptions);
        } else {
            builder.addApi(Games.API);
        }

        builder.addScope(Games.SCOPE_GAMES);
    }

    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        if (mPlusApiOptions != null) {
            builder.addApi(Plus.API, mPlusApiOptions);
        } else {
            builder.addApi(Plus.API);
        }
        builder.addScope(Plus.SCOPE_PLUS_LOGIN);
    }

    if (0 != (mRequestedClients & CLIENT_APPSTATE)) {
        builder.addApi(AppStateManager.API);
        builder.addScope(AppStateManager.SCOPE_APP_STATE);
    }

    mGoogleApiClientBuilder = builder;
    return builder;
}
 
Example #23
Source File: GameHelper.java    From io2014-codelabs with Apache License 2.0 5 votes vote down vote up
/** Sign out and disconnect from the APIs. */
public void signOut() {
    if (!mGoogleApiClient.isConnected()) {
        // nothing to do
        debugLog("signOut: was already disconnected, ignoring.");
        return;
    }

    // for Plus, "signing out" means clearing the default account and
    // then disconnecting
    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        debugLog("Clearing default account on PlusClient.");
        Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
    }

    // For the games client, signing out means calling signOut and
    // disconnecting
    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        debugLog("Signing out from the Google API Client.");
        Games.signOut(mGoogleApiClient);
    }

    // Ready to disconnect
    debugLog("Disconnecting client.");
    mConnectOnStart = false;
    mConnecting = false;
    mGoogleApiClient.disconnect();
}
 
Example #24
Source File: GameHelper.java    From Onesearch with MIT License 5 votes vote down vote up
/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        builder.addApi(Games.API, mGamesApiOptions);
        builder.addScope(Games.SCOPE_GAMES);
    }

    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        builder.addApi(Plus.API);
        builder.addScope(Plus.SCOPE_PLUS_LOGIN);
    }

    if (0 != (mRequestedClients & CLIENT_APPSTATE)) {
        builder.addApi(AppStateManager.API);
        builder.addScope(AppStateManager.SCOPE_APP_STATE);
    }

    if (0 != (mRequestedClients & CLIENT_SNAPSHOT)) {
      builder.addScope(Drive.SCOPE_APPFOLDER);
      builder.addApi(Drive.API);
    }

    mGoogleApiClientBuilder = builder;
    return builder;
}
 
Example #25
Source File: GameHelper.java    From ANE-Google-Play-Game-Services with Apache License 2.0 5 votes vote down vote up
/** Sign out and disconnect from the APIs. */
  public void signOut() {
      if (!mGoogleApiClient.isConnected()) {
          // nothing to do
          debugLog("signOut: was already disconnected, ignoring.");
          return;
      }

      // for Plus, "signing out" means clearing the default account and
      // then disconnecting
      if (0 != (mRequestedClients & CLIENT_PLUS)) {
          debugLog("Clearing default account on PlusClient.");
          Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
      }

      // For the games client, signing out means calling signOut and
      // disconnecting
      if (0 != (mRequestedClients & CLIENT_GAMES)) {
          debugLog("Signing out from the Google API Client.");
          Games.signOut(mGoogleApiClient);
      }

      // Ready to disconnect
      debugLog("Disconnecting client.");
      mConnectOnStart = false;
      mConnecting = false;
mConnectionResult = null;
mGoogleApiClient.disconnect();
  }
 
Example #26
Source File: GameHelper.java    From cordova-google-play-games-services with MIT License 5 votes vote down vote up
/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        builder.addApi(Games.API, mGamesApiOptions);
        builder.addScope(Games.SCOPE_GAMES);
    }

    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        builder.addApi(Plus.API);
        builder.addScope(Plus.SCOPE_PLUS_LOGIN);
    }


    if (0 != (mRequestedClients & CLIENT_SNAPSHOT)) {
      builder.addScope(Drive.SCOPE_APPFOLDER);
      builder.addApi(Drive.API);
    }

    mGoogleApiClientBuilder = builder;
    return builder;
}
 
Example #27
Source File: GameHelper.java    From Onesearch with MIT License 5 votes vote down vote up
/** Sign out and disconnect from the APIs. */
public void signOut() {
    if (!mGoogleApiClient.isConnected()) {
        // nothing to do
        debugLog("signOut: was already disconnected, ignoring.");
        return;
    }

    // for Plus, "signing out" means clearing the default account and
    // then disconnecting
    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        debugLog("Clearing default account on PlusClient.");
        Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
    }

    // For the games client, signing out means calling signOut and
    // disconnecting
    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        debugLog("Signing out from the Google API Client.");
        Games.signOut(mGoogleApiClient);
    }

    // Ready to disconnect
    debugLog("Disconnecting client.");
    mConnectOnStart = false;
    mConnecting = false;
    mGoogleApiClient.disconnect();
}
 
Example #28
Source File: GameHelper.java    From tedroid with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally,
 * you do not have to do this; use this method only if you need to make
 * nonstandard setup (e.g. adding extra scopes for other APIs) on the
 * GoogleApiClient.Builder before calling @link{#setup}.
 */
public GoogleApiClient.Builder createApiClientBuilder() {
    if (mSetupDone) {
        String error = "GameHelper: you called GameHelper.createApiClientBuilder() after "
                + "calling setup. You can only get a client builder BEFORE performing setup.";
        logError(error);
        throw new IllegalStateException(error);
    }

    GoogleApiClient.Builder builder = new GoogleApiClient.Builder(
            mActivity, this, this);

    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        builder.addApi(Games.API, mGamesApiOptions);
        builder.addScope(Games.SCOPE_GAMES);
    }

    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        builder.addApi(Plus.API);
        builder.addScope(Plus.SCOPE_PLUS_LOGIN);
    }

    if (0 != (mRequestedClients & CLIENT_APPSTATE)) {
        builder.addApi(AppStateManager.API);
        builder.addScope(AppStateManager.SCOPE_APP_STATE);
    }

    mGoogleApiClientBuilder = builder;
    return builder;
}
 
Example #29
Source File: GameHelper.java    From tedroid with Apache License 2.0 5 votes vote down vote up
/** Sign out and disconnect from the APIs. */
public void signOut() {
    if (!mGoogleApiClient.isConnected()) {
        // nothing to do
        debugLog("signOut: was already disconnected, ignoring.");
        return;
    }

    // for Plus, "signing out" means clearing the default account and
    // then disconnecting
    if (0 != (mRequestedClients & CLIENT_PLUS)) {
        debugLog("Clearing default account on PlusClient.");
        Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
    }

    // For the games client, signing out means calling signOut and
    // disconnecting
    if (0 != (mRequestedClients & CLIENT_GAMES)) {
        debugLog("Signing out from the Google API Client.");
        Games.signOut(mGoogleApiClient);
    }

    // Ready to disconnect
    debugLog("Disconnecting client.");
    mConnectOnStart = false;
    mConnecting = false;
    mGoogleApiClient.disconnect();
}
 
Example #30
Source File: LoginActivity.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 5 votes vote down vote up
private void initGoogleApliClient(){
	
	googleAPIClient = new GoogleApiClient.Builder(this)
	.addConnectionCallbacks(
			(GoogleApiClient.ConnectionCallbacks) this)
	.addOnConnectionFailedListener(
			(GoogleApiClient.OnConnectionFailedListener) this)
	.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN).build();
	
}