Java Code Examples for com.google.android.gms.games.SnapshotsClient#DataOrConflict
The following examples show how to use
com.google.android.gms.games.SnapshotsClient#DataOrConflict .
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: SnapshotCoordinator.java From android-basic-samples with Apache License 2.0 | 6 votes |
@NonNull private OnCompleteListener<SnapshotsClient.DataOrConflict<Snapshot>> createOpenListener(final String filename) { return new OnCompleteListener<SnapshotsClient.DataOrConflict<Snapshot>>() { @Override public void onComplete(@NonNull Task<SnapshotsClient.DataOrConflict<Snapshot>> task) { // if open failed, set the file to closed, otherwise, keep it open. if (!task.isSuccessful()) { Exception e = task.getException(); Log.e(TAG, "Open was not a success for filename " + filename, e); setClosed(filename); } else { SnapshotsClient.DataOrConflict<Snapshot> result = task.getResult(); if (result.isConflict()) { Log.d(TAG, "Open successful: " + filename + ", but with a conflict"); } else { Log.d(TAG, "Open successful: " + filename); } } } }; }
Example 2
Source File: MainActivity.java From android-basic-samples with Apache License 2.0 | 5 votes |
/** * Conflict resolution for when Snapshots are opened. * * @param requestCode - the request currently being processed. This is used to forward on the * information to another activity, or to send the result intent. * @param result The open snapshot result to resolve on open. * @param retryCount - the current iteration of the retry. The first retry should be 0. * @return The opened Snapshot on success; otherwise, returns null. */ Snapshot processOpenDataOrConflict(int requestCode, SnapshotsClient.DataOrConflict<Snapshot> result, int retryCount) { retryCount++; if (!result.isConflict()) { return result.getData(); } Log.i(TAG, "Open resulted in a conflict!"); SnapshotsClient.SnapshotConflict conflict = result.getConflict(); final Snapshot snapshot = conflict.getSnapshot(); final Snapshot conflictSnapshot = conflict.getConflictingSnapshot(); ArrayList<Snapshot> snapshotList = new ArrayList<Snapshot>(2); snapshotList.add(snapshot); snapshotList.add(conflictSnapshot); // Display both snapshots to the user and allow them to select the one to resolve. selectSnapshotItem(requestCode, snapshotList, conflict.getConflictId(), retryCount); // Since we are waiting on the user for input, there is no snapshot available; return null. return null; }
Example 3
Source File: SnapshotCoordinator.java From android-basic-samples with Apache License 2.0 | 5 votes |
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."); }
Example 4
Source File: SnapshotCoordinator.java From android-basic-samples with Apache License 2.0 | 5 votes |
public Task<SnapshotsClient.DataOrConflict<Snapshot>> open(final SnapshotsClient snapshotsClient, final String filename, final boolean createIfNotFound) { return setIsOpeningTask(filename).continueWithTask(new Continuation<Void, Task<SnapshotsClient.DataOrConflict<Snapshot>>>() { @Override public Task<SnapshotsClient.DataOrConflict<Snapshot>> then(@NonNull Task<Void> task) throws Exception { return snapshotsClient.open(filename, createIfNotFound) .addOnCompleteListener(createOpenListener(filename)); } }); }
Example 5
Source File: SnapshotCoordinator.java From android-basic-samples with Apache License 2.0 | 5 votes |
public Task<SnapshotsClient.DataOrConflict<Snapshot>> open(final SnapshotsClient snapshotsClient, final String filename, final boolean createIfNotFound, final int conflictPolicy) { return setIsOpeningTask(filename).continueWithTask(new Continuation<Void, Task<SnapshotsClient.DataOrConflict<Snapshot>>>() { @Override public Task<SnapshotsClient.DataOrConflict<Snapshot>> then(@NonNull Task<Void> task) throws Exception { return snapshotsClient.open(filename, createIfNotFound, conflictPolicy) .addOnCompleteListener(createOpenListener(filename)); } }); }
Example 6
Source File: SnapshotCoordinator.java From android-basic-samples with Apache License 2.0 | 5 votes |
public Task<SnapshotsClient.DataOrConflict<Snapshot>> open(final SnapshotsClient snapshotsClient, final SnapshotMetadata snapshotMetadata) { final String filename = snapshotMetadata.getUniqueName(); return setIsOpeningTask(filename).continueWithTask(new Continuation<Void, Task<SnapshotsClient.DataOrConflict<Snapshot>>>() { @Override public Task<SnapshotsClient.DataOrConflict<Snapshot>> then(@NonNull Task<Void> task) throws Exception { return snapshotsClient.open(snapshotMetadata) .addOnCompleteListener(createOpenListener(filename)); } }); }
Example 7
Source File: SnapshotCoordinator.java From android-basic-samples with Apache License 2.0 | 5 votes |
public Task<SnapshotsClient.DataOrConflict<Snapshot>> open(final SnapshotsClient snapshotsClient, final SnapshotMetadata snapshotMetadata, final int conflictPolicy) { final String filename = snapshotMetadata.getUniqueName(); return setIsOpeningTask(filename).continueWithTask(new Continuation<Void, Task<SnapshotsClient.DataOrConflict<Snapshot>>>() { @Override public Task<SnapshotsClient.DataOrConflict<Snapshot>> then(@NonNull Task<Void> task) throws Exception { return snapshotsClient.open(snapshotMetadata, conflictPolicy) .addOnCompleteListener(createOpenListener(filename)); } }); }