本文整理汇总了Java中com.google.android.gms.games.snapshot.SnapshotMetadataChange类的典型用法代码示例。如果您正苦于以下问题:Java SnapshotMetadataChange类的具体用法?Java SnapshotMetadataChange怎么用?Java SnapshotMetadataChange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SnapshotMetadataChange类属于com.google.android.gms.games.snapshot包,在下文中一共展示了SnapshotMetadataChange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInBackground
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的package包/类
@Override
protected Snapshots.CommitSnapshotResult doInBackground(Void... params) {
Bitmap coverImage = BitmapFactory.decodeResource(mActivity.getResources(), R.drawable.ic_launcher);
SnapshotMetadataChange metadata = new SnapshotMetadataChange.Builder()
.setDescription(String.format(mActivity.getString(R.string.singleplayer_savegame_text), mSavegame.getCurrentRound(), mSavegame.getWonRounds()))
.setCoverImage(coverImage)
.build();
byte[] data = mSavegame.toBytes();
Snapshots.OpenSnapshotResult openSnapshot = Games.Snapshots.open(mActivity.getGoogleApiClient(), mSavegame.getUUID(), true).await();
int status = openSnapshot.getStatus().getStatusCode();
if (status == GamesStatusCodes.STATUS_OK) {
Snapshot snapshot = openSnapshot.getSnapshot();
snapshot.writeBytes(data);
return Games.Snapshots.commitAndClose(mActivity.getGoogleApiClient(), snapshot, metadata).await();
}
return null;
}
示例2: writeToSnapshot
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的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());
}
}
});
}
}
示例3: gserviceUpdateState
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的package包/类
@Override
public void gserviceUpdateState() {
if (gHelper.isSignedIn()) {
System.out.println("===> SAVEDGAME UPDATE");
Games.Snapshots.open(gHelper.getApiClient(), snapshotName, true).setResultCallback(
new ResultCallback<Snapshots.OpenSnapshotResult>() {
@Override
public void onResult(Snapshots.OpenSnapshotResult result) {
if (result.getStatus().isSuccess()) {
// Write data
result.getSnapshot().getSnapshotContents().writeBytes(AppDataManager.getInstance().getBytes());
// Commit and close
Games.Snapshots.commitAndClose(gHelper.getApiClient(), result.getSnapshot(), SnapshotMetadataChange.EMPTY_CHANGE);
}
}
}
);
}
}
示例4: resolveConflict
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的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: commitAndClose
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的package包/类
@Override
public PendingResult<CommitSnapshotResult> commitAndClose(GoogleApiClient googleApiClient,
final Snapshot snapshot,
SnapshotMetadataChange
snapshotMetadataChange) {
if (isAlreadyOpen(snapshot.getMetadata().getUniqueName()) &&
!isAlreadyClosing(snapshot.getMetadata().getUniqueName())) {
setIsClosing(snapshot.getMetadata().getUniqueName());
try {
return new CoordinatedPendingResult<>(
Games.Snapshots.commitAndClose(googleApiClient, snapshot,
snapshotMetadataChange),
new ResultListener() {
@Override
public void onResult(Result result) {
// even if commit and close fails, the file is closed.
Log.d(TAG, "CommitAndClose complete, closing " +
snapshot.getMetadata().getUniqueName());
setClosed(snapshot.getMetadata().getUniqueName());
}
});
} catch (RuntimeException e) {
setClosed(snapshot.getMetadata().getUniqueName());
throw e;
}
} else {
throw new IllegalStateException(snapshot.getMetadata().getUniqueName() +
" is either closed or is closing");
}
}
示例6: save
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的package包/类
private static SnapshotMetadata save(@Nullable GoogleApiClient googleApiClient,
String snapshotName) {
final Snapshot snapshot = getSnapshot(googleApiClient, snapshotName, true);
if (snapshot == null) {
return null;
}
final Context context = googleApiClient.getContext();
// Set the data payload for the snapshot
String progressJson = PuzzleProvider.getInstance(context).getProgressJson();
final byte[] data = progressJson.getBytes();
snapshot.getSnapshotContents().writeBytes(data);
// Create the change operation
SnapshotMetadataChange metadataChange = new SnapshotMetadataChange.Builder()
.setDescription(context.getString(R.string.saved_game_name, SystemUtils.getDeviceName()))
.build();
try {
// Commit the operation
Snapshots.CommitSnapshotResult saveResult = Games.Snapshots.commitAndClose(googleApiClient, snapshot, metadataChange).await();
if (saveResult.getStatus().isSuccess()) {
PrefsUtils.setLastSavegameName(snapshotName);
return saveResult.getSnapshotMetadata();
}
} catch (IllegalStateException e) {
// Not sure why we're still seeing errors about the connection state, but here we are
Crashlytics.logException(e);
return null;
}
return null;
}
示例7: writeSnapshot
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的package包/类
/**
* Generates metadata, takes a screenshot, and performs the write operation for saving a
* snapshot.
*/
private String writeSnapshot(Snapshot snapshot) {
// Set the data payload for the snapshot.
snapshot.getSnapshotContents().writeBytes(mSaveGame.toBytes());
// Save the snapshot.
SnapshotMetadataChange metadataChange = new SnapshotMetadataChange.Builder()
.setCoverImage(getScreenShot())
.setDescription("Modified data at: " + Calendar.getInstance().getTime())
.build();
Games.Snapshots.commitAndClose(mGoogleApiClient, snapshot, metadataChange);
return snapshot.toString();
}
示例8: writeSnapshot
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的package包/类
/**
* Generates metadata, takes a screenshot, and performs the write operation for saving a
* snapshot.
*/
private Task<SnapshotMetadata> writeSnapshot(Snapshot snapshot) {
// Set the data payload for the snapshot.
snapshot.getSnapshotContents().writeBytes(mSaveGame.toBytes());
// Save the snapshot.
SnapshotMetadataChange metadataChange = new SnapshotMetadataChange.Builder()
.setCoverImage(getScreenShot())
.setDescription("Modified data at: " + Calendar.getInstance().getTime())
.build();
return SnapshotCoordinator.getInstance().commitAndClose(mSnapshotsClient, snapshot, metadataChange);
}
示例9: resolveConflict
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的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.");
}
示例10: onStateConflict
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的package包/类
private void onStateConflict(Snapshots.OpenSnapshotResult result) {
final Snapshot remoteSnapshot = result.getSnapshot();
final Snapshot localSnapshot = result.getConflictingSnapshot();
// Resolve with one of the snapshot (temporarily)
Games.Snapshots.resolveConflict(gHelper.getApiClient(), result.getConflictId(), remoteSnapshot);
// Reopen the snapshot and write bytes on the result snapshot
Games.Snapshots.open(gHelper.getApiClient(), snapshotName, true).setResultCallback(
new ResultCallback<Snapshots.OpenSnapshotResult>() {
@Override
public void onResult(Snapshots.OpenSnapshotResult res) {
int status = res.getStatus().getStatusCode();
byte[] data = new byte[0];
if (status == GamesStatusCodes.STATUS_OK) {
try {
data = onStateConflictBehaviour(localSnapshot.getSnapshotContents().readFully(),
res.getSnapshot().getSnapshotContents().readFully());
} catch (IOException e) {
e.printStackTrace();
}
// Write data
res.getSnapshot().getSnapshotContents().writeBytes(data);
// Commit and close
Games.Snapshots.commitAndClose(gHelper.getApiClient(), res.getSnapshot(), SnapshotMetadataChange.EMPTY_CHANGE);
}
}
}
);
}
示例11: onGSStringSave
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的package包/类
public void onGSStringSave(String data,String desc,Integer id)
{
final String _data=data;
final String _desc=desc;
final Integer _id=id;
Log.i("yoyo","Google onGSStringSave called");
AsyncTask<Void, Void, Integer> task = new AsyncTask<Void, Void, Integer>()
{
@Override
protected Integer doInBackground(Void... params) {
boolean createIfMissing = true;
byte[] databytes = _data.getBytes();
// Open the snapshot, creating if necessary
Snapshots.OpenSnapshotResult open = Games.Snapshots.open(
mGoogleApiClient, mCurrentSaveName, createIfMissing).await();
if (!open.getStatus().isSuccess())
{
Log.i("yoyo", "Could not open Snapshot for saving.");
return -1;
}
// Write the new data to the snapshot
Snapshot snapshot = open.getSnapshot();
snapshot.getSnapshotContents().writeBytes(databytes);
String s = new String(databytes);
Log.i("yoyo","saving snapshot:" + s);
// Change metadata
SnapshotMetadataChange metadataChange = new SnapshotMetadataChange.Builder()
.fromMetadata(snapshot.getMetadata())
.setDescription("Modified data at: " + Calendar.getInstance().getTime())
// .setCoverImage(bitmap)
// .setDescription(description)
// .setPlayedTimeMillis(playedTimeMillis)
.build();
Snapshots.CommitSnapshotResult commit = Games.Snapshots.commitAndClose(
mGoogleApiClient, snapshot, metadataChange).await();
if (!commit.getStatus().isSuccess()) {
Log.i("yoyo", "Failed to commit Snapshot.");
return -1;
}
Log.i("yoyo", "Commit Snapshot success");
return 0;
}
@Override
protected void onPostExecute(Integer status) {
// Dismiss progress dialog and reflect the changes in the UI.
// ...
Log.i("yoyo","onGSStringSaves completed with " + status);
}
};
task.execute();
}
示例12: saveGameStateSync
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的package包/类
@NonNull
public Boolean saveGameStateSync(String id, byte[] gameState, long progressValue,
ISaveGameStateResponseListener listener) {
if (!isSessionActive()) {
if (listener != null)
listener.onGameStateSaved(false, "NOT_CONNECTED");
return false;
}
// Open the snapshot, creating if necessary
Snapshots.OpenSnapshotResult open = Games.Snapshots.open(
mGoogleApiClient, id, true).await();
Snapshot snapshot = processSnapshotOpenResult(open, 0);
if (snapshot == null) {
Gdx.app.log(GAMESERVICE_ID, "Could not open Snapshot.");
if (listener != null)
listener.onGameStateSaved(false, "Could not open Snapshot.");
return false;
}
if (progressValue < snapshot.getMetadata().getProgressValue()) {
Gdx.app.error(GAMESERVICE_ID, "Progress of saved game state higher than current one. Did not save.");
if (listener != null)
listener.onGameStateSaved(true, null);
return false;
}
// Write the new data to the snapshot
snapshot.getSnapshotContents().writeBytes(gameState);
// Change metadata
SnapshotMetadataChange.Builder metaDataBuilder = new SnapshotMetadataChange.Builder()
.fromMetadata(snapshot.getMetadata());
metaDataBuilder = setSaveGameMetaData(metaDataBuilder, id, gameState, progressValue);
SnapshotMetadataChange metadataChange = metaDataBuilder.build();
Snapshots.CommitSnapshotResult commit = Games.Snapshots.commitAndClose(
mGoogleApiClient, snapshot, metadataChange).await();
if (!commit.getStatus().isSuccess()) {
Gdx.app.log(GAMESERVICE_ID, "Failed to commit Snapshot:" + commit.getStatus().getStatusMessage());
if (listener != null)
listener.onGameStateSaved(false, commit.getStatus().getStatusMessage());
return false;
}
// No failures
Gdx.app.log(GAMESERVICE_ID, "Successfully saved gamestate with " + gameState.length + "B");
if (listener != null)
listener.onGameStateSaved(true, null);
return true;
}
示例13: savedGamesUpdate
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的package包/类
/**
* Update the Snapshot in the Saved Games service with new data. Metadata is not affected,
* however for your own application you will likely want to update metadata such as cover image,
* played time, and description with each Snapshot update. After update, the UI will
* be cleared.
*/
private void savedGamesUpdate() {
final String snapshotName = makeSnapshotName(APP_STATE_KEY);
final boolean createIfMissing = false;
// Use the data from the EditText as the new Snapshot data.
final byte[] data = getData().getBytes();
AsyncTask<Void, Void, Boolean> updateTask = new AsyncTask<Void, Void, Boolean>() {
@Override
protected void onPreExecute() {
showProgressDialog("Updating Saved Game");
}
@Override
protected Boolean doInBackground(Void... params) {
Snapshots.OpenSnapshotResult open = Games.Snapshots.open(
mGoogleApiClient, snapshotName, createIfMissing).await();
if (!open.getStatus().isSuccess()) {
Log.w(TAG, "Could not open Snapshot for update.");
return false;
}
// Change data but leave existing metadata
Snapshot snapshot = open.getSnapshot();
snapshot.getSnapshotContents().writeBytes(data);
Snapshots.CommitSnapshotResult commit = Games.Snapshots.commitAndClose(
mGoogleApiClient, snapshot, SnapshotMetadataChange.EMPTY_CHANGE).await();
if (!commit.getStatus().isSuccess()) {
Log.w(TAG, "Failed to commit Snapshot.");
return false;
}
// No failures
return true;
}
@Override
protected void onPostExecute(Boolean result) {
if (result) {
displayMessage(getString(R.string.saved_games_update_success), false);
} else {
displayMessage(getString(R.string.saved_games_update_failure), true);
}
dismissProgressDialog();
clearDataUI();
}
};
updateTask.execute();
}
示例14: savedGamesUpdate
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的package包/类
/**
* Update the Snapshot in the Saved Games service with new data. Metadata is not affected,
* however for your own application you will likely want to update metadata such as cover image,
* played time, and description with each Snapshot update. After update, the UI will
* be cleared.
*/
@Override
public void savedGamesUpdate(final String snapshotName, final byte[] data, final boolean createIfMissing) {
if (isSignedIn()) {
waitingToCloudUpdate = false;
AsyncTask<Void, Void, Boolean> updateTask = new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
Snapshots.OpenSnapshotResult open = Games.Snapshots.open(gameHelper.getApiClient(), snapshotName, createIfMissing).await();
if (!open.getStatus().isSuccess()) {
//Gdx.app.log(TAG, "Could not open Snapshot for update.");
gameServicesListener.savedGamesUpdateFailed();
return false;
}
// Change data but leave existing metadata
Snapshot snapshot = open.getSnapshot();
snapshot.getSnapshotContents().writeBytes(data);
Snapshots.CommitSnapshotResult commit = Games.Snapshots.commitAndClose(
gameHelper.getApiClient(), snapshot, SnapshotMetadataChange.EMPTY_CHANGE).await();
if (!commit.getStatus().isSuccess()) {
//Gdx.app.log(TAG, "Failed to commit Snapshot.");
gameServicesListener.savedGamesUpdateFailed();
return false;
}
// No failures
//Gdx.app.log(TAG, "No failures for Snapshot update.");
gameServicesListener.savedGamesUpdateSucceeded();
return true;
}
};
updateTask.execute();
} else {
gameHelper.beginUserInitiatedSignIn();
waitingToCloudUpdate = true;
waitingCloudUpdateBundle = new CloudUpdateBundle();
waitingCloudUpdateBundle.snapshotName = snapshotName;
waitingCloudUpdateBundle.data = data;
waitingCloudUpdateBundle.createIfMissing = createIfMissing;
}
}
示例15: send
import com.google.android.gms.games.snapshot.SnapshotMetadataChange; //导入依赖的package包/类
@Override
public void send(final byte[] data) {
if(data==null) {
return;
}
if(mGoogleApiClient.isConnected()) {
AsyncTask<Void, Void, Snapshots.OpenSnapshotResult> task =
new AsyncTask<Void, Void, Snapshots.OpenSnapshotResult>() {
@Override
protected Snapshots.OpenSnapshotResult doInBackground(Void... params) {
return Games.Snapshots.open(
mGoogleApiClient, SAVED_DATA, true).await();
}
@Override
protected void onPostExecute(Snapshots.OpenSnapshotResult result) {
try{
Snapshot toWrite = processSnapshotOpenResult(result, 0);
if(toWrite!=null) {
toWrite.getSnapshotContents().writeBytes(data);
SnapshotMetadataChange metadataChange = new SnapshotMetadataChange.Builder()
.setDescription(SAVED_DATA)
.build();
Games.Snapshots.commitAndClose(mGoogleApiClient, toWrite, metadataChange);
mHandler.post(new Runnable() {
@Override
public void run() {
mListener.onSyncProgress(CA.DATA_SENT);
}});
}
} catch(IllegalStateException e) {
mHandler.post(new Runnable() {
@Override
public void run() {
mListener.onSyncFailed(CA.DATA_SENT);
}
});
}
}
};
task.execute();
}
}