本文整理了Java中bolts.Task.call()
方法的一些代码示例,展示了Task.call()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Task.call()
方法的具体详情如下:
包路径:bolts.Task
类名称:Task
方法名:call
[英]Invokes the callable on the current thread, producing a Task.
[中]调用当前线程上的可调用项,生成一个任务。
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public void close() {
// Basically close _eventually_.
Task.call(new Callable<Void>() {
@Override
public Void call() {
cursor.close();
return null;
}
}, executor);
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<Void> setAsync(final T object) {
return Task.call(new Callable<Void>() {
@Override
public Void call() {
saveToDisk(coder, object, file);
//TODO (grantland): check to see if this failed? We currently don't for legacy reasons.
return null;
}
}, ParseExecutors.io());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<T> getAsync() {
return Task.call(new Callable<T>() {
@Override
public T call() {
if (!file.exists()) {
return null;
}
return getFromDisk(coder, file, ParseObject.State.newBuilder(className));
}
}, ParseExecutors.io());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<Boolean> existsAsync() {
return Task.call(new Callable<Boolean>() {
@Override
public Boolean call() {
return file.exists();
}
}, ParseExecutors.io());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
public Task<Void> setCurrentConfigAsync(final ParseConfig config) {
return Task.call(new Callable<Void>() {
@Override
public Void call() {
synchronized (currentConfigMutex) {
currentConfig = config;
saveToDisk(config);
}
return null;
}
}, ParseExecutors.io());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public void done(final Integer percentDone) {
Task.call(new Callable<Void>() {
@Override
public Void call() {
progressCallback.done(percentDone);
return null;
}
}, ParseExecutors.main());
}
};
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<Void> deleteAsync() {
return Task.call(new Callable<Void>() {
@Override
public Void call() {
if (file.exists() && !ParseFileUtils.deleteQuietly(file)) {
throw new RuntimeException("Unable to delete");
}
return null;
}
}, ParseExecutors.io());
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
public Task<ParseConfig> getCurrentConfigAsync() {
return Task.call(new Callable<ParseConfig>() {
@Override
public ParseConfig call() {
synchronized (currentConfigMutex) {
if (currentConfig == null) {
ParseConfig config = getFromDisk();
currentConfig = (config != null) ? config : new ParseConfig();
}
}
return currentConfig;
}
}, ParseExecutors.io());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
public Task<Boolean> restoreAuthenticationAsync(String authType, final Map<String, String> authData) {
final AuthenticationCallback callback;
synchronized (lock) {
callback = this.callbacks.get(authType);
}
if (callback == null) {
return Task.forResult(true);
}
return Task.call(new Callable<Boolean>() {
@Override
public Boolean call() {
return callback.onRestore(authData);
}
}, ParseExecutors.io());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
public Task<Void> deauthenticateAsync(String authType) {
final AuthenticationCallback callback;
synchronized (lock) {
callback = this.callbacks.get(authType);
}
if (callback != null) {
return Task.call(new Callable<Void>() {
@Override
public Void call() {
callback.onRestore(null);
return null;
}
}, ParseExecutors.io());
}
return Task.forResult(null);
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public void networkConnectivityStatusChanged(Context context, Intent intent) {
final boolean connectionLost =
intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
final boolean isConnected = ConnectivityNotifier.isConnected(context);
/*
Hack to avoid blocking the UI thread with disk I/O
setConnected uses the same lock we use for synchronizing disk I/O, so there's a possibility
that we can block the UI thread on disk I/O, so we're going to bump the lock usage to a
different thread.
TODO(grantland): Convert to TaskQueue, similar to ParsePinningEventuallyQueue
*/
Task.call(new Callable<Void>() {
@Override
public Void call() {
if (connectionLost) {
setConnected(false);
} else {
setConnected(isConnected);
}
return null;
}
}, ParseExecutors.io());
}
};
代码示例来源:origin: parse-community/Parse-SDK-Android
/**
* Retrieves the results of the last time {@link ParseQuery#find()} was called on a query
* identical to this one.
*
* @param sessionToken The user requesting access.
* @return A list of {@link ParseObject}s corresponding to this query. Returns null if there is no
* cache for this query.
*/
private <T extends ParseObject> Task<List<T>> findFromCacheAsync(
final ParseQuery.State<T> state, String sessionToken) {
final String cacheKey = ParseRESTQueryCommand.findCommand(state, sessionToken).getCacheKey();
return Task.call(new Callable<List<T>>() {
@Override
public List<T> call() throws Exception {
JSONObject cached = ParseKeyValueCache.jsonFromKeyValueCache(cacheKey, state.maxCacheAge());
if (cached == null) {
throw new ParseException(ParseException.CACHE_MISS, "results not cached");
}
try {
return networkController.convertFindResponse(state, cached);
} catch (JSONException e) {
throw new ParseException(ParseException.CACHE_MISS, "the cache contains corrupted json");
}
}
}, Task.BACKGROUND_EXECUTOR);
}
代码示例来源:origin: parse-community/Parse-SDK-Android
/**
* Retrieves the results of the last time {@link ParseQuery#count()} was called on a query
* identical to this one.
*
* @param sessionToken The user requesting access.
* @return A list of {@link ParseObject}s corresponding to this query. Returns null if there is no
* cache for this query.
*/
private <T extends ParseObject> Task<Integer> countFromCacheAsync(
final ParseQuery.State<T> state, String sessionToken) {
final String cacheKey = ParseRESTQueryCommand.countCommand(state, sessionToken).getCacheKey();
return Task.call(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
JSONObject cached = ParseKeyValueCache.jsonFromKeyValueCache(cacheKey, state.maxCacheAge());
if (cached == null) {
throw new ParseException(ParseException.CACHE_MISS, "results not cached");
}
try {
return cached.getInt("count");
} catch (JSONException e) {
throw new ParseException(ParseException.CACHE_MISS, "the cache contains corrupted json");
}
}
}, Task.BACKGROUND_EXECUTOR);
}
代码示例来源:origin: parse-community/Parse-SDK-Android
return Task.call(new Callable<Void>() {
@Override
public Void call() throws Exception {
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testMultipleAsynchronousWrites() throws ParseException {
int max = 100;
ParseKeyValueCache.maxKeyValueCacheFiles = max;
// Max out KeyValueCache
for (int i = 0; i < max; i++) {
ParseKeyValueCache.saveToKeyValueCache("key " + i, "test");
}
List<Task<Void>> tasks = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
tasks.add(Task.call(new Callable<Void>() {
@Override
public Void call() {
ParseKeyValueCache.saveToKeyValueCache("foo", "test");
return null;
}
}, Task.BACKGROUND_EXECUTOR));
}
ParseTaskUtils.wait(Task.whenAll(tasks));
}
代码示例来源:origin: parse-community/Parse-SDK-Android
return Task.call(new Callable<Boolean>() {
@Override
public Boolean call() {
代码示例来源:origin: fr.avianey/bolts-android-api
/**
* Invokes the callable on a background thread, returning a Task to represent the operation.
*/
public static <TResult> Task<TResult> callInBackground(Callable<TResult> callable) {
return call(callable, BACKGROUND_EXECUTOR);
}
代码示例来源:origin: fr.avianey/bolts-android-api
/**
* Invokes the callable on the current thread, producing a Task.
*/
public static <TResult> Task<TResult> call(final Callable<TResult> callable) {
return call(callable, IMMEDIATE_EXECUTOR);
}
代码示例来源:origin: developerHaoz/SleepHelper
/**
* 通过图片的缓存地址来初始化界面
*/
private void initViewWithCache(final int position) {
Task.call(new Callable<List<String>>() {
@Override
public List<String> call() throws Exception {
for (String imageUrl : mImageUrlList) {
mCachePathList.add(GlideHelper.getImagePathFromCache(imageUrl, DetailActivity.this));
}
return mCachePathList;
}
}, Task.BACKGROUND_EXECUTOR).continueWith(new Continuation<List<String>, Object>() {
@Override
public Object then(Task<List<String>> task) throws Exception {
List<String> mCachePathList = task.getResult();
if(!Check.isEmpty(mCachePathList)){
for (String cachePath : mCachePathList) {
DetailFragment fragment = DetailFragment.newInstance(cachePath);
mFragments.add(fragment);
}
CommonPagerAdapter adapter = new CommonPagerAdapter(getSupportFragmentManager(), mFragments);
mVpShowPhoto.setAdapter(adapter);
mVpShowPhoto.setCurrentItem(position);
}
return null;
}
}, Task.UI_THREAD_EXECUTOR);
}
内容来源于网络,如有侵权,请联系作者删除!