本文整理汇总了Java中com.google.android.gms.games.snapshot.SnapshotContents类的典型用法代码示例。如果您正苦于以下问题:Java SnapshotContents类的具体用法?Java SnapshotContents怎么用?Java SnapshotContents使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SnapshotContents类属于com.google.android.gms.games.snapshot包,在下文中一共展示了SnapshotContents类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processOpenSnapshotResult
import com.google.android.gms.games.snapshot.SnapshotContents; //导入依赖的package包/类
private void processOpenSnapshotResult(OpenSnapshotResult result, final UserData userData, IConflictResolver resolver) {
final Snapshot snapshot = result.getSnapshot();
if (result.getStatus().isSuccess()) {
final SnapshotContents contents = snapshot.getSnapshotContents();
final Map server = fromBytes(contents);
if (server != null && server.containsKey("uuid") && !server.get("uuid").equals(userData.uuid())) {
performUserResolve(server, resolver, new IConflictResolverCallback() {
@Override public void onResolved(boolean useLocal) {
contents.writeBytes(useLocal ? toBytes(userData) : toBytes(server));
Games.Snapshots.commitAndClose(client, snapshot, EMPTY_CHANGE);
}
});
} else {
contents.writeBytes(toBytes(userData));
Games.Snapshots.commitAndClose(client, snapshot, EMPTY_CHANGE);
}
} else if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT) {
Snapshot conflictingSnapshot = result.getConflictingSnapshot();
startResolving(userData, conflictingSnapshot, result.getConflictId(), resolver);
}
}
示例2: startResolving
import com.google.android.gms.games.snapshot.SnapshotContents; //导入依赖的package包/类
private void startResolving(final UserData userData, final Snapshot conflictingSnapshot, final String conflictId, final IConflictResolver resolver) {
final SnapshotContents contents = conflictingSnapshot.getSnapshotContents();
final Map server = fromBytes(contents);
if (server == null) {
contents.writeBytes(toBytes(userData));
Games.Snapshots.resolveConflict(client, conflictId, SNAPSHOT_ID, EMPTY_CHANGE, contents);
return;
}
performUserResolve(server, resolver, new IConflictResolverCallback() {
@SuppressWarnings("unchecked")
@Override public void onResolved(boolean useLocal) {
contents.writeBytes(useLocal ? toBytes(userData) : toBytes(server));
Games.Snapshots
.resolveConflict(client, conflictId, SNAPSHOT_ID, EMPTY_CHANGE, contents)
.setResultCallback(new ResultCallback<OpenSnapshotResult>() {
@Override public void onResult(OpenSnapshotResult result) {
if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT) {
startResolving(userData, result.getConflictingSnapshot(), result.getConflictId(), resolver);
}
}
});
}
});
}
示例3: writeToSnapshot
import com.google.android.gms.games.snapshot.SnapshotContents; //导入依赖的package包/类
private void writeToSnapshot(String snapshotId, byte[] content) {
Log.i("Play Games", "Streaming to " + snapshotId);
PendingResult<Snapshots.OpenSnapshotResult> result = Games.Snapshots.open(googleApiClient, snapshotId, true, Snapshots.RESOLUTION_POLICY_MOST_RECENTLY_MODIFIED);
Snapshots.OpenSnapshotResult openResult = result.await(5, TimeUnit.SECONDS);
Snapshot snapshot = openResult.getSnapshot();
if (openResult.getStatus().isSuccess() && snapshot != null) {
SnapshotContents contents = snapshot.getSnapshotContents();
contents.writeBytes(content);
PendingResult<Snapshots.CommitSnapshotResult> pendingResult = Games.Snapshots.commitAndClose(googleApiClient, snapshot, SnapshotMetadataChange.EMPTY_CHANGE);
pendingResult.setResultCallback(new ResultCallback<Snapshots.CommitSnapshotResult>() {
@Override
public void onResult(@NonNull Snapshots.CommitSnapshotResult commitSnapshotResult) {
if (commitSnapshotResult.getStatus().isSuccess()) {
Log.i("Play Games", "commit ok");
} else {
EventCollector.logEvent("Play Games", "commit" + commitSnapshotResult.getStatus().getStatusMessage());
}
}
});
}
}
示例4: resolveConflict
import com.google.android.gms.games.snapshot.SnapshotContents; //导入依赖的package包/类
@Override
public PendingResult<OpenSnapshotResult> resolveConflict(GoogleApiClient googleApiClient,
String conflictId, String snapshotId,
SnapshotMetadataChange snapshotMetadataChange,
SnapshotContents snapshotContents) {
// Since the unique name of the snapshot is unknown, this resolution method cannot be safely
// used. Please use another method of resolution.
throw new IllegalStateException("resolving conflicts with ids is not supported.");
}
示例5: resolveConflict
import com.google.android.gms.games.snapshot.SnapshotContents; //导入依赖的package包/类
public Task<SnapshotsClient.DataOrConflict<Snapshot>> resolveConflict(SnapshotsClient snapshotsClient,
String conflictId, String snapshotId,
SnapshotMetadataChange snapshotMetadataChange,
SnapshotContents snapshotContents) {
// Since the unique name of the snapshot is unknown, this resolution method cannot be safely
// used. Please use another method of resolution.
throw new IllegalStateException("resolving conflicts with ids is not supported.");
}