本文整理汇总了Java中com.google.android.gms.games.snapshot.SnapshotMetadata类的典型用法代码示例。如果您正苦于以下问题:Java SnapshotMetadata类的具体用法?Java SnapshotMetadata怎么用?Java SnapshotMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SnapshotMetadata类属于com.google.android.gms.games.snapshot包,在下文中一共展示了SnapshotMetadata类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: delete
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的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");
}
}
示例2: selectSnapshotItem
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的package包/类
private void selectSnapshotItem(int requestCode, ArrayList<Snapshot> items,
String conflictId, int retryCount) {
ArrayList<SnapshotMetadata> snapshotList = new ArrayList<SnapshotMetadata>(items.size());
for (Snapshot m : items) {
snapshotList.add(m.getMetadata().freeze());
}
Intent intent = new Intent(this, SelectSnapshotActivity.class);
intent.putParcelableArrayListExtra(SelectSnapshotActivity.SNAPSHOT_METADATA_LIST,
snapshotList);
intent.putExtra(SelectSnapshotActivity.CONFLICT_ID, conflictId);
intent.putExtra(SelectSnapshotActivity.RETRY_COUNT, retryCount);
Log.d(TAG, "Starting activity to select snapshot");
startActivityForResult(intent, requestCode);
}
示例3: onCreate
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_snapshot);
//expect the intent to include the list of snapshots or snapshot metadatas to display
Intent intent = getIntent();
if (intent != null) {
ArrayList<SnapshotMetadata> snapshotMetadataList;
ListView vw = (ListView) findViewById(R.id.snapshot_list);
snapshotMetadataList = intent.getParcelableArrayListExtra(SNAPSHOT_METADATA_LIST);
// set a custom list adapter that can display the image and other
// information about a snapshot.
vw.setAdapter(
new SnapshotListAdapter<SnapshotMetadata>(this, snapshotMetadataList));
mConflictId = intent.getStringExtra(CONFLICT_ID);
mRetryCount = intent.getIntExtra(RETRY_COUNT, 0);
// register this class as the listener for when an item is selected
vw.setOnItemClickListener(this);
}
}
示例4: onItemClick
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的package包/类
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long listId) {
SnapshotMetadata selected = (SnapshotMetadata) adapterView.getItemAtPosition(position);
Intent intent = new Intent(Intent.ACTION_DEFAULT);
intent.putExtra(SNAPSHOT_METADATA, selected.freeze());
if (mConflictId != null) {
intent.putExtra(CONFLICT_ID, mConflictId);
intent.putExtra(RETRY_COUNT, mRetryCount);
}
Log.d(TAG, "Finishing item at position " + position + " clicked");
setResult(RESULT_OK, intent);
finish();
}
示例5: displaySnapshotMetadata
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的package包/类
/**
* Display metadata about Snapshot save data.
* @param metadata the SnapshotMetadata associated with the saved game.
*/
private void displaySnapshotMetadata(SnapshotMetadata metadata) {
TextView metaDataView = (TextView) findViewById(R.id.text_metadata);
if (metadata == null) {
metaDataView.setText("");
return;
}
String metadataStr = "Source: Saved Games" + '\n'
+ "Description: " + metadata.getDescription() + '\n'
+ "Name: " + metadata.getUniqueName() + '\n'
+ "Last Modified: " + String.valueOf(metadata.getLastModifiedTimestamp()) + '\n'
+ "Played Time: " + String.valueOf(metadata.getPlayedTime()) + '\n'
+ "Cover Image URL: " + metadata.getCoverImageUrl();
metaDataView.setText(metadataStr);
}
示例6: loadSnapshots
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的package包/类
public void loadSnapshots(@Nullable final Runnable doneCallback) {
if (isConnected()) {
Games.Snapshots.load(googleApiClient, false).setResultCallback(new ResultCallback<Snapshots.LoadSnapshotsResult>() {
@Override
public void onResult(@NonNull Snapshots.LoadSnapshotsResult result) {
if (result.getStatus().isSuccess()) {
Log.i("Play Games", "load ok!");
mSavedGamesNames = new ArrayList<>();
for (SnapshotMetadata m : result.getSnapshots()) {
mSavedGamesNames.add(m.getUniqueName());
}
} else {
EventCollector.logEvent("Play Games", "load " + result.getStatus().getStatusMessage());
}
if (doneCallback != null) {
doneCallback.run();
}
}
}, 3, TimeUnit.SECONDS);
}
}
示例7: selectSnapshotItem
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的package包/类
private void selectSnapshotItem(int requestCode,
ArrayList<Snapshot> items,
String conflictId,
int retryCount) {
ArrayList<SnapshotMetadata> snapshotList = new ArrayList<SnapshotMetadata>(items.size());
for (Snapshot m : items) {
snapshotList.add(m.getMetadata().freeze());
}
Intent intent = new Intent(this, SelectSnapshotActivity.class);
intent.putParcelableArrayListExtra(SelectSnapshotActivity.SNAPSHOT_METADATA_LIST,
snapshotList);
intent.putExtra(SelectSnapshotActivity.CONFLICT_ID, conflictId);
intent.putExtra(SelectSnapshotActivity.RETRY_COUNT, retryCount);
Log.d(TAG, "Starting activity to select snapshot");
startActivityForResult(intent, requestCode);
}
示例8: onCreate
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_select_snapshot);
//expect the intent to include the list of snapshots or snapshot metadatas to display
Intent intent = getIntent();
if (intent != null) {
ArrayList<SnapshotMetadata> snapshotMetadataList;
ListView vw = (ListView) findViewById(R.id.snapshot_list);
snapshotMetadataList = intent.getParcelableArrayListExtra(SNAPSHOT_METADATA_LIST);
// set a custom list adapter that can display the image and other
// information about a snapshot.
vw.setAdapter(
new SnapshotListAdapter<SnapshotMetadata>(this, snapshotMetadataList));
mConflictId = intent.getStringExtra(CONFLICT_ID);
mRetryCount = intent.getIntExtra(RETRY_COUNT, 0);
// register this class as the listener for when an item is selected
vw.setOnItemClickListener(this);
}
}
示例9: onItemClick
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的package包/类
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long listId) {
SnapshotMetadata selected = (SnapshotMetadata) adapterView.getItemAtPosition(position);
Intent intent = new Intent(Intent.ACTION_DEFAULT);
intent.putExtra(SNAPSHOT_METADATA, selected.freeze());
if (mConflictId != null) {
intent.putExtra(CONFLICT_ID, mConflictId);
intent.putExtra(RETRY_COUNT, mRetryCount);
}
Log.d(TAG, "Finishing item at position " + position + " clicked");
setResult(RESULT_OK, intent);
finish();
}
示例10: fetchGameStatesSync
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的package包/类
private boolean fetchGameStatesSync(IFetchGameStatesListResponseListener callback) {
if (!isSessionActive())
return false;
if (!driveApiEnabled)
throw new UnsupportedOperationException();
Snapshots.LoadSnapshotsResult loadResult = Games.Snapshots.load(mGoogleApiClient, forceRefresh).await();
if (!loadResult.getStatus().isSuccess()) {
Gdx.app.log(GAMESERVICE_ID, "Failed to fetch game states:" +
loadResult.getStatus().getStatusMessage());
callback.onFetchGameStatesListResponse(null);
return false;
}
SnapshotMetadataBuffer snapshots = loadResult.getSnapshots();
Array<String> gameStates = new Array<String>(snapshots.getCount());
for (SnapshotMetadata snapshot : snapshots) {
gameStates.add(snapshot.getTitle());
}
snapshots.release();
callback.onFetchGameStatesListResponse(gameStates);
return true;
}
示例11: open
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的package包/类
@Override
public PendingResult<OpenSnapshotResult> open(GoogleApiClient googleApiClient,
final SnapshotMetadata snapshotMetadata) {
// check if the file is already open
if (!isAlreadyOpen(snapshotMetadata.getUniqueName())) {
setIsOpening(snapshotMetadata.getUniqueName());
try {
return new CoordinatedPendingResult<>(
Games.Snapshots.open(googleApiClient, snapshotMetadata),
new ResultListener() {
@Override
public void onResult(Result result) {
// if open failed, set the file to closed, otherwise, keep it open.
if (!result.getStatus().isSuccess()) {
Log.d(TAG, "Open was not a success: " +
result.getStatus() + " for filename " +
snapshotMetadata.getUniqueName());
setClosed(snapshotMetadata.getUniqueName());
} else {
Log.d(TAG, "Open was successful: " +
snapshotMetadata.getUniqueName());
}
}
});
} catch (RuntimeException e) {
setClosed(snapshotMetadata.getUniqueName());
throw e;
}
} else {
throw new IllegalStateException(snapshotMetadata.getUniqueName() + " is already open");
}
}
示例12: load
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的package包/类
public void load(@Nullable final GoogleApiClient googleApiClient,
@NonNull final SnapshotMetadata snapshotMetadata,
@Nullable final SavegameManager.OnLoadResult onLoadResult) {
if (googleApiClient == null || !googleApiClient.isConnected()) {
// No connection; cannot load
if (onLoadResult != null) {
onLoadResult.onLoadFailure();
}
return;
}
new AsyncTask<Void, Void, Snapshot>() {
@Override
protected Snapshot doInBackground(Void... voids) {
return SavegameManager.load(googleApiClient, snapshotMetadata.getUniqueName());
}
@Override
protected void onPostExecute(Snapshot snapshot) {
if (snapshot == null) {
Log.e(TAG, "game state failed loading from Google Play Games");
if (onLoadResult != null) {
onLoadResult.onLoadFailure();
}
} else {
Log.d(TAG, "game state loaded from Google Play Games");
if (onLoadResult != null) {
onLoadResult.onLoadSuccess();
}
}
}
}.execute();
}
示例13: save
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的package包/类
public void save(@Nullable final GoogleApiClient googleApiClient,
@Nullable final SavegameManager.OnSaveResult onSaveResult) {
if (googleApiClient == null || !googleApiClient.isConnected()) {
// No connection; cannot save
if (onSaveResult != null) {
onSaveResult.onSaveFailure();
}
return;
}
// Create a new snapshot named with a unique string
new AsyncTask<Void, Void, SnapshotMetadata>() {
@Override
protected SnapshotMetadata doInBackground(Void... voids) {
return SavegameManager.save(googleApiClient);
}
@Override
protected void onPostExecute(SnapshotMetadata snapshot) {
if (snapshot == null) {
Log.e(TAG, "game state failed saving to Google Play Games");
if (onSaveResult != null) {
onSaveResult.onSaveFailure();
}
} else {
Log.d(TAG, "game state saved to Google Play Games");
if (onSaveResult != null) {
onSaveResult.onSaveSuccess();
}
}
}
}.execute();
}
示例14: save
import com.google.android.gms.games.snapshot.SnapshotMetadata; //导入依赖的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;
}