本文整理汇总了Java中com.google.android.gms.games.Games类的典型用法代码示例。如果您正苦于以下问题:Java Games类的具体用法?Java Games怎么用?Java Games使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Games类属于com.google.android.gms.games包,在下文中一共展示了Games类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import com.google.android.gms.games.Games; //导入依赖的package包/类
/**
* Initializes the GoogleApiClient. Give your main AndroidLauncher as context.
* <p>
* Don't forget to add onActivityResult method there with call to onGpgsActivityResult.
*
* @param context your AndroidLauncher class
* @param enableDriveAPI true if you activate save gamestate feature
* @return this for method chunking
*/
public GpgsClient initialize(Activity context, boolean enableDriveAPI) {
if (mGoogleApiClient != null)
throw new IllegalStateException("Already initialized.");
myContext = context;
// retry some times when connect fails (needed when game state sync is enabled)
firstConnectAttempt = MAX_CONNECTFAIL_RETRIES;
GoogleApiClient.Builder builder = new GoogleApiClient.Builder(myContext)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Games.API).addScope(Games.SCOPE_GAMES);
driveApiEnabled = enableDriveAPI;
if (driveApiEnabled)
builder.addApi(Drive.API).addScope(Drive.SCOPE_APPFOLDER);
// add other APIs and scopes here as needed
mGoogleApiClient = builder.build();
return this;
}
示例2: delete
import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public PendingResult<DeleteSnapshotResult> delete(GoogleApiClient googleApiClient,
final SnapshotMetadata snapshotMetadata) {
if (!isAlreadyOpen(snapshotMetadata.getUniqueName()) &&
!isAlreadyClosing(snapshotMetadata.getUniqueName())) {
setIsClosing(snapshotMetadata.getUniqueName());
try {
return new CoordinatedPendingResult<>(
Games.Snapshots.delete(googleApiClient, snapshotMetadata),
new ResultListener() {
@Override
public void onResult(Result result) {
// deleted files are closed.
setClosed(snapshotMetadata.getUniqueName());
}
});
} catch (RuntimeException e) {
setClosed(snapshotMetadata.getUniqueName());
throw e;
}
} else {
throw new IllegalStateException(snapshotMetadata.getUniqueName() +
" is either open or is busy");
}
}
示例3: openLeaderboard
import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void openLeaderboard() {
Log.d(LOG_TAG, "The user opened the leaderboard");
GoogleApiClientCallback myActivity = (GoogleApiClientCallback) getActivity();
GoogleApiClient myClient = myActivity.getGoogleApiClient();
if (myClient.isConnected()) {
startActivityForResult(
Games.Leaderboards.getAllLeaderboardsIntent(myClient),
RC_UNUSED);
} else {
BaseGameUtils.makeSimpleDialog(
getActivity(),
getString(R.string.leaderboards_not_available))
.show();
}
}
示例4: matchCompleted
import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void matchCompleted(boolean victory) {
if(!isSignedIn())
return;
Games.Achievements.unlock(gameHelper.getApiClient(),
getString(R.string.achievement_your_first_match));
Games.Achievements.increment(gameHelper.getApiClient(),
getString(R.string.achievement_5_matches), 1);
Games.Achievements.increment(gameHelper.getApiClient(),
getString(R.string.achievement_25_matches), 1);
Games.Achievements.increment(gameHelper.getApiClient(),
getString(R.string.achievement_50_matches), 1);
if(victory) {
Games.Achievements.increment(gameHelper.getApiClient(),
getString(R.string.achievement_10_wins), 1);
Games.Achievements.increment(gameHelper.getApiClient(),
getString(R.string.achievement_25_wins), 1);
Games.Achievements.increment(gameHelper.getApiClient(),
getString(R.string.achievement_50_wins), 1);
}
}
示例5: startMatch
import com.google.android.gms.games.Games; //导入依赖的package包/类
public void startMatch(TurnBasedMatch match) {
System.out.println("Started match");
mTurnData = new GameModelWrapper();
mMatch = match;
String playerId = Games.Players.getCurrentPlayerId(gameHelper.getApiClient());
String myParticipantId = mMatch.getParticipantId(playerId);
Games.TurnBasedMultiplayer.takeTurn(gameHelper.getApiClient(), match.getMatchId(),
mTurnData.convertToByteArray(), myParticipantId).setResultCallback(
new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
@Override
public void onResult(TurnBasedMultiplayer.UpdateMatchResult result) {
processResult(result);
}
});
}
示例6: onConnected
import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void onConnected(Bundle connectionHint) {
Log.d(TAG, "onConnected() called. Sign in successful!");
Log.d(TAG, "Sign-in succeeded.");
// register listener so we are notified if we receive an invitation to play
// while we are in the game
Games.Invitations.registerInvitationListener(mGoogleApiClient, this);
if (connectionHint != null) {
Log.d(TAG, "onConnected: connection hint provided. Checking for invite.");
Invitation inv = connectionHint
.getParcelable(Multiplayer.EXTRA_INVITATION);
if (inv != null && inv.getInvitationId() != null) {
// retrieve and cache the invitation ID
Log.d(TAG,"onConnected: connection hint has a room invite!");
acceptInviteToRoom(inv.getInvitationId());
return;
}
}
switchToMainScreen();
}
示例7: onConnectedToRoom
import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void onConnectedToRoom(Room room) {
Log.d(TAG, "onConnectedToRoom.");
//get participants and my ID:
mParticipants = room.getParticipants();
mMyId = room.getParticipantId(Games.Players.getCurrentPlayerId(mGoogleApiClient));
// save room ID if its not initialized in onRoomCreated() so we can leave cleanly before the game starts.
if(mRoomId==null)
mRoomId = room.getRoomId();
// print out the list of participants (for debug purposes)
Log.d(TAG, "Room ID: " + mRoomId);
Log.d(TAG, "My ID " + mMyId);
Log.d(TAG, "<< CONNECTED TO ROOM>>");
}
示例8: onStop
import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void onStop(int score) {
animateTitle(true);
gameView.setOnClickListener(this);
int highScore = prefs.getInt(PreferenceUtils.PREF_HIGH_SCORE, 0);
if (score > highScore) {
//TODO: awesome high score animation or something
highScore = score;
prefs.edit().putInt(PreferenceUtils.PREF_HIGH_SCORE, score).apply();
if (isConnected())
Games.Leaderboards.submitScore(apiClient, getString(R.string.leaderboard_high_score), highScore);
}
highScoreView.setText(String.format(getString(R.string.score_high), highScore));
if (achievementUtils != null)
achievementUtils.onStop(score);
}
示例9: onConnected
import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void onConnected(Bundle connectionHint)
{
// The player is signed in. Hide the sign-in button and allow the
// player to proceed.
Log.i("yoyo","Sign In Succeeded");
Player p = Games.Players.getCurrentPlayer(getApiClient());
String displayName;
String id;
if (p == null) {
Log.i("yoyo", "mGamesClient.getCurrentPlayer() is NULL!");
displayName = "???";
id="-1";
}
else {
displayName = p.getDisplayName();
id = p.getPlayerId();
}
Log.i("yoyo","Found displayname " + displayName + " with id " + id);
RunnerJNILib.OnLoginSuccess(displayName,id,"","","","","");
//Call back to generate the social event
}
示例10: Logout
import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void Logout()
{
if (mGoogleApiClient != null && mGoogleApiClient.isConnected())
{
mSignInClicked= false;
Games.signOut(mGoogleApiClient);
mGoogleApiClient.disconnect();
Log.i("yoyo","Logged out of Google Play Services");
RunnerJNILib.OnLoginSuccess("Not logged in","-1","","","","","");
}
}
示例11: rematch
import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void rematch() {
Games.TurnBasedMultiplayer.rematch(gameHelper.getApiClient(), mMatch.getMatchId()).setResultCallback(
new ResultCallback<TurnBasedMultiplayer.InitiateMatchResult>() {
@Override
public void onResult(TurnBasedMultiplayer.InitiateMatchResult result) {
processResult(result);
}
});
mMatch = null;
isDoingTurn = false;
}
示例12: onConnected
import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void onConnected(Bundle bundle) {
super.onConnected(bundle);
if (googleResource == Constants.LEADERBOARD)
startActivityForResult(Games.Leaderboards.getAllLeaderboardsIntent(App.getGoogleApiHelper().getGoogleApiClient()), 1);
else
startActivityForResult(Games.Achievements.getAchievementsIntent(App.getGoogleApiHelper().getGoogleApiClient()), 1);
}
示例13: onShowGSAchievements
import com.google.android.gms.games.Games; //导入依赖的package包/类
public void onShowGSAchievements()
{
if (isSignedIn()) {
RunnerActivity.CurrentActivity.startActivityForResult(Games.Achievements.getAchievementsIntent(getApiClient()), RC_GPS_ACTIVITY);
}
else {
(new AlertDialog.Builder(RunnerActivity.CurrentActivity))
.setTitle("Achievement Not Available")
.setMessage("You can't view achievements because you are not signed in.")
.setNeutralButton("OK", null)
.show();
}
}
示例14: openIfConnected
import com.google.android.gms.games.Games; //导入依赖的package包/类
private void openIfConnected() {
if (App.getGoogleApiHelper().getGoogleApiClient() == null || !App.getGoogleApiHelper().getGoogleApiClient().isConnected()) {
Message msg = new Message();
msg.what = Constants.CONNECT;
msg.obj = this;
googleHandler.sendMessage(msg);
} else {
if (googleResource == Constants.LEADERBOARD)
startActivityForResult(Games.Leaderboards.getAllLeaderboardsIntent(App.getGoogleApiHelper().getGoogleApiClient()), 1);
else
startActivityForResult(Games.Achievements.getAchievementsIntent(App.getGoogleApiHelper().getGoogleApiClient()), 1);
}
}
示例15: showLeaderboards
import com.google.android.gms.games.Games; //导入依赖的package包/类
@Override
public void showLeaderboards(String leaderBoardId) throws GameServiceException {
if (isSessionActive()) {
if (gpgsLeaderboardIdMapper != null)
leaderBoardId = gpgsLeaderboardIdMapper.mapToGsId(leaderBoardId);
myContext.startActivityForResult(leaderBoardId != null ?
Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient, leaderBoardId) :
Games.Leaderboards.getAllLeaderboardsIntent(mGoogleApiClient), RC_LEADERBOARD);
} else
throw new GameServiceException.NoSessionException();
}