com.google.android.gms.games.GamesClient Java Examples

The following examples show how to use com.google.android.gms.games.GamesClient. 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: AchievementsLoadListener.java    From ANE-Google-Play-Game-Services with Apache License 2.0 6 votes vote down vote up
@Override
public void onAchievementsLoaded(int statusCode, AchievementBuffer achBuffer) {
	if (statusCode == GamesClient.STATUS_OK) {
		Iterator<Achievement> iterator = achBuffer.iterator();
		while(iterator.hasNext()){
			Achievement achievement = iterator.next();
			if(achievement.getType() == Achievement.TYPE_INCREMENTAL && achievement.getAchievementId().equals(achievementId))
			{
			    this.incrementAchievementWhenDataIsLoaded(achievement);
			}
		}
		
	}
	else{
		//Achievements loading has failed
	}
	achBuffer.close();
}
 
Example #2
Source File: Request.java    From play_games with MIT License 5 votes vote down vote up
public void setPopupOptions(boolean show, int gravity) {
    GamesClient gamesClient = Games.getGamesClient(registrar.activity(), currentAccount);
    if (show) {
        gamesClient.setViewForPopups(registrar.view());
        gamesClient.setGravityForPopups(gravity);
    } else {
        gamesClient.setViewForPopups(null);
    }
    result(true);
}
 
Example #3
Source File: GPGamesHelper.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 5 votes vote down vote up
public static void setPopupView(@NonNull Context context, @NonNull View view, @MagicConstant(flagsFromClass = Gravity.class) int gravity) {
    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(context);
    if (account == null) return;

    GamesClient client = Games.getGamesClient(context, account);
    client.setViewForPopups(view);
    client.setGravityForPopups(gravity);
}
 
Example #4
Source File: GooglePlay.java    From ExtensionsPack with MIT License 5 votes vote down vote up
public static void start(Context ctx)
{
  gamesClient = new GamesClient.Builder(ctx,
      new GooglePlayCallback("GAMES_CLIENT"),
      new GooglePlayCallback("GAMES_CLIENT"))
    .setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL)
    .setScopes(Scopes.GAMES)
    .create();

  appStateClient = new AppStateClient.Builder(ctx,
      new GooglePlayCallback("APP_STATE_CLIENT"),
      new GooglePlayCallback("APP_STATE_CLIENT"))
    .setScopes(Scopes.APP_STATE)
    .create();
}
 
Example #5
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
private void onConnected(GoogleSignInAccount googleSignInAccount) {
  Log.d(TAG, "onConnected(): connected to Google APIs");
  if (mSignedInAccount != googleSignInAccount) {

    mSignedInAccount = googleSignInAccount;

    // update the clients
    mRealTimeMultiplayerClient = Games.getRealTimeMultiplayerClient(this, googleSignInAccount);
    mInvitationsClient = Games.getInvitationsClient(MainActivity.this, googleSignInAccount);

    // get the playerId from the PlayersClient
    PlayersClient playersClient = Games.getPlayersClient(this, googleSignInAccount);
    playersClient.getCurrentPlayer()
        .addOnSuccessListener(new OnSuccessListener<Player>() {
          @Override
          public void onSuccess(Player player) {
            mPlayerId = player.getPlayerId();

            switchToMainScreen();
          }
        })
        .addOnFailureListener(createFailureListener("There was a problem getting the player id!"));
  }

  // register listener so we are notified if we receive an invitation to play
  // while we are in the game
  mInvitationsClient.registerInvitationCallback(mInvitationCallback);

  // get the invitation from the connection hint
  // Retrieve the TurnBasedMatch from the connectionHint
  GamesClient gamesClient = Games.getGamesClient(MainActivity.this, googleSignInAccount);
  gamesClient.getActivationHint()
      .addOnSuccessListener(new OnSuccessListener<Bundle>() {
        @Override
        public void onSuccess(Bundle hint) {
          if (hint != null) {
            Invitation invitation =
                hint.getParcelable(Multiplayer.EXTRA_INVITATION);

            if (invitation != null && invitation.getInvitationId() != null) {
              // retrieve and cache the invitation ID
              Log.d(TAG, "onConnected: connection hint has a room invite!");
              acceptInviteToRoom(invitation.getInvitationId());
            }
          }
        }
      })
      .addOnFailureListener(createFailureListener("There was a problem getting the activation hint!"));
}
 
Example #6
Source File: SkeletonActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
private void onConnected(GoogleSignInAccount googleSignInAccount) {
  Log.d(TAG, "onConnected(): connected to Google APIs");

  mTurnBasedMultiplayerClient = Games.getTurnBasedMultiplayerClient(this, googleSignInAccount);
  mInvitationsClient = Games.getInvitationsClient(this, googleSignInAccount);

  Games.getPlayersClient(this, googleSignInAccount)
      .getCurrentPlayer()
      .addOnSuccessListener(
          new OnSuccessListener<Player>() {
            @Override
            public void onSuccess(Player player) {
              mDisplayName = player.getDisplayName();
              mPlayerId = player.getPlayerId();

              setViewVisibility();
            }
          }
      )
      .addOnFailureListener(createFailureListener("There was a problem getting the player!"));

  Log.d(TAG, "onConnected(): Connection successful");

  // Retrieve the TurnBasedMatch from the connectionHint
  GamesClient gamesClient = Games.getGamesClient(this, googleSignInAccount);
  gamesClient.getActivationHint()
      .addOnSuccessListener(new OnSuccessListener<Bundle>() {
        @Override
        public void onSuccess(Bundle hint) {
          if (hint != null) {
            TurnBasedMatch match = hint.getParcelable(Multiplayer.EXTRA_TURN_BASED_MATCH);

            if (match != null) {
              updateMatch(match);
            }
          }
        }
      })
      .addOnFailureListener(createFailureListener(
          "There was a problem getting the activation hint!"));

  setViewVisibility();

  // As a demonstration, we are registering this activity as a handler for
  // invitation and match events.

  // This is *NOT* required; if you do not register a handler for
  // invitation events, you will get standard notifications instead.
  // Standard notifications may be preferable behavior in many cases.
  mInvitationsClient.registerInvitationCallback(mInvitationCallback);

  // Likewise, we are registering the optional MatchUpdateListener, which
  // will replace notifications you would get otherwise. You do *NOT* have
  // to register a MatchUpdateListener.
  mTurnBasedMultiplayerClient.registerTurnBasedMatchUpdateCallback(mMatchUpdateCallback);
}