本文整理汇总了Java中com.google.android.gms.tasks.Tasks.forResult方法的典型用法代码示例。如果您正苦于以下问题:Java Tasks.forResult方法的具体用法?Java Tasks.forResult怎么用?Java Tasks.forResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.tasks.Tasks
的用法示例。
在下文中一共展示了Tasks.forResult方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
when(mockStorageHelpers.getApiKeyFromManifest(any(Context.class), eq(StorageHelpers
.DIGITS_CONSUMER_KEY_KEY))).thenReturn(DIGITS_CONSUMER_KEY);
when(mockStorageHelpers.getApiKeyFromManifest(any(Context.class), eq(StorageHelpers
.DIGITS_CONSUMER_SECRET_KEY))).thenReturn(DIGITS_CONSUMER_SECRET);
when(mockStorageHelpers.getApiKeyFromManifest(any(Context.class), eq(StorageHelpers
.FABRIC_API_KEY_KEY))).thenReturn(FABRIC_API_KEY);
authResult = new AuthResult() {
@Override
public FirebaseUser getUser() {
return mockFirebaseUser;
}
@Override
public AdditionalUserInfo getAdditionalUserInfo() {
return null;
}
};
authResultTask = Tasks.forResult(authResult);
}
示例2: logout
import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
/**
* Logs out the current user.
*
* @return A task that can be resolved upon completion of logout.
*/
public Task<Void> logout() {
if (!isAuthenticated()) {
return Tasks.forResult(null);
}
return executeRequest(Request.Method.DELETE, routes.AUTH_SESSION, null, false, true).continueWith(new Continuation<String, Void>() {
@Override
public Void then(@NonNull final Task<String> task) throws Exception {
if (task.isSuccessful()) {
clearAuth();
return null;
}
throw task.getException();
}
});
}
示例3: initializeFolderView
import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
/**
* Initializes the folder view after the given task completes.
*
* @return Task which resolves after the view has been initialized
*/
private Task<Void> initializeFolderView() {
Task<DriveFolder> folderTask;
if (mNavigationPath.isEmpty()) {
folderTask = mDriveResourceClient.getRootFolder();
} else {
folderTask = Tasks.forResult(mNavigationPath.peek().asDriveFolder());
}
Task<Void> initFolderTask = folderTask.continueWith(new Continuation<DriveFolder, Void>() {
@Override
public Void then(@NonNull Task<DriveFolder> task) throws Exception {
DriveId id = task.getResult().getDriveId();
if (mNavigationPath.isEmpty()) {
mNavigationPath.push(id);
}
return null;
}
});
return updateUiAfterTask(initFolderTask);
}
示例4: continueWith
import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
@NonNull
@Override
public <TContinuationResult> Task<TContinuationResult> continueWith(
@NonNull Continuation<TResult, TContinuationResult> continuation) {
try {
return Tasks.forResult(continuation.then(Tasks.forResult(mResult)));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: logInWithProvider
import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
/**
* Logs the current user in using a specific auth provider.
*
* @param authProvider The provider that will handle the login.
* @return A task containing an {@link AuthInfo} session that can be resolved on completion of log in.
*/
public Task<String> logInWithProvider(AuthProvider authProvider) {
if (isAuthenticated()) {
Log.d(TAG, "Already logged in. Returning cached token");
return Tasks.forResult(_auth.getAuthInfo().getUserId());
}
final TaskCompletionSource<String> future = new TaskCompletionSource<>();
final JsonStringRequest request = new JsonStringRequest(
Request.Method.POST,
getResourcePath(routes.getAuthProvidersLoginRoute(authProvider.getType())),
getAuthRequest(authProvider).toJson(),
new Response.Listener<String>() {
@Override
public void onResponse(final String response) {
try {
_auth = new Auth(
StitchClient.this,
_objMapper.readValue(response, AuthInfo.class));
final RefreshTokenHolder refreshToken =
_objMapper.readValue(response, RefreshTokenHolder.class);
_preferences.edit().putString(PREF_AUTH_JWT_NAME, response).apply();
_preferences.edit().putString(PREF_AUTH_REFRESH_TOKEN_NAME, refreshToken.getToken()).apply();
_preferences.edit().putString(PREF_DEVICE_ID_NAME, _auth.getAuthInfo().getDeviceId()).apply();
future.setResult(_auth.getAuthInfo().getUserId());
onLogin();
} catch (final IOException e) {
Log.e(TAG, "Error parsing auth response", e);
future.setException(new StitchException(e));
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(final VolleyError error) {
Log.e(TAG, "Error while logging in with auth provider", error);
future.setException(parseRequestError(error));
}
});
request.setTag(this);
_queue.add(request);
return future.getTask();
}
示例6: doSomething
import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
private Task<String> doSomething(AuthResult authResult) {
// [START_EXCLUDE]
return Tasks.forResult("Hello, World!");
// [END_EXCLUDE]
}
示例7: makeGooglePlayServicesAvailable
import com.google.android.gms.tasks.Tasks; //导入方法依赖的package包/类
/**
* Attempts to make Google Play services available on this device. If Play Services is already
* available, the returned {@link Task} may complete immediately.
* <p/>
* If it is necessary to display UI in order to complete this request (e.g. sending the user
* to the Google Play store) the passed {@link Activity} will be used to display this UI.
* <p/>
* It is recommended to call this method from {@link Activity#onCreate(Bundle)}.
* If the passed {@link Activity} completes before the returned {@link Task} completes, the
* Task will fail with a {@link java.util.concurrent.CancellationException}.
* <p/>
* This method must be called from the main thread.
*
* @return A {@link Task}. If this Task completes without throwing an exception, Play Services
* is available on this device.
*/
public Task<Void> makeGooglePlayServicesAvailable(Activity activity) {
int status = isGooglePlayServicesAvailable(activity);
if (status == SUCCESS) {
return Tasks.forResult(null);
}
// TODO
return Tasks.forResult(null);
}