本文整理汇总了Java中com.bumptech.glide.request.FutureTarget类的典型用法代码示例。如果您正苦于以下问题:Java FutureTarget类的具体用法?Java FutureTarget怎么用?Java FutureTarget使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FutureTarget类属于com.bumptech.glide.request包,在下文中一共展示了FutureTarget类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: submit
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
/**
* Returns a future that can be used to do a blocking get on a background thread.
*
* @param width The desired width in pixels, or {@link Target#SIZE_ORIGINAL}. This will be
* overridden by
* {@link com.bumptech.glide.request.RequestOptions#override(int, int)} if
* previously called.
* @param height The desired height in pixels, or {@link Target#SIZE_ORIGINAL}. This will be
* overridden by
* {@link com.bumptech.glide.request.RequestOptions#override(int, int)}} if
* previously called).
*/
public FutureTarget<TranscodeType> submit(int width, int height) {
final RequestFutureTarget<TranscodeType> target =
new RequestFutureTarget<>(context.getMainHandler(), width, height);
if (Util.isOnBackgroundThread()) {
context.getMainHandler().post(new Runnable() {
@Override
public void run() {
if (!target.isCancelled()) {
into(target);
}
}
});
} else {
into(target);
}
return target;
}
示例2: clear_withNonOwningRequestManager_onBackgroundTHread_doesNotThrow
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
/**
* Tests b/69361054.
*/
@Test
public void clear_withNonOwningRequestManager_onBackgroundTHread_doesNotThrow() {
concurrency.runOnMainThread(new Runnable() {
@Override
public void run() {
requestManager.onDestroy();
}
});
final FutureTarget<Drawable> target =
concurrency.wait(requestManager.load(raw.canonical).submit());
concurrency.runOnMainThread(new Runnable() {
@Override
public void run() {
Glide.with(context).clear(target);
}
});
}
示例3: submit_withDisabledMemoryCache_andResourceInActiveResources_loadsFromMemory
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
@Test
public void submit_withDisabledMemoryCache_andResourceInActiveResources_loadsFromMemory() {
Glide.init(
context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter()));
FutureTarget<Drawable> first =
GlideApp.with(context)
.load(raw.canonical)
.submit();
concurrency.get(first);
concurrency.get(
GlideApp.with(context)
.load(ResourceIds.raw.canonical)
.listener(requestListener)
.submit());
verify(requestListener)
.onResourceReady(
anyDrawable(),
any(),
anyTarget(),
eq(DataSource.MEMORY_CACHE),
anyBoolean());
}
示例4: submit
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
/**
* Returns a future that can be used to do a blocking get on a background thread.
*
* @param width The desired width in pixels, or {@link Target#SIZE_ORIGINAL}. This will be
* overridden by
* {@link com.bumptech.glide.request.RequestOptions#override(int, int)} if
* previously called.
* @param height The desired height in pixels, or {@link Target#SIZE_ORIGINAL}. This will be
* overridden by
* {@link com.bumptech.glide.request.RequestOptions#override(int, int)}} if
* previously called).
*/
public FutureTarget<TranscodeType> submit(int width, int height) {
final RequestFutureTarget<TranscodeType> target =
new RequestFutureTarget<>(glideContext.getMainHandler(), width, height);
if (Util.isOnBackgroundThread()) {
glideContext.getMainHandler().post(new Runnable() {
@Override
public void run() {
if (!target.isCancelled()) {
into(target, target);
}
}
});
} else {
into(target, target);
}
return target;
}
示例5: doInBackground
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
@SafeVarargs
@Override protected final File doInBackground(FutureTarget<File>... params) {
try {
File file = params[0].get();
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
File result = new File(dir, targetName);
Utils.copy(file, result);
return result;
} catch (Exception e) {
return null;
}
}
示例6: run
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
public void run() {
for (int n = 0; n < original_list.size(); n++) {
//WORKAROUND TO PRE-CACHE ICONS
try {
FutureTarget<GlideDrawable> future = Glide
.with(context)
.load("http://onepiece-treasurecruise.com/wp-content/uploads/f" + convertID(n + 1) + ".png")
.dontTransform()
.override(thumbnail_width, thumbnail_height)
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.into(thumbnail_width, thumbnail_height);
GlideDrawable cacheFile = future.get();
} catch (Exception e) {
Log.e("ERR", "Pic not found");
}
}
}
示例7: getImagePath
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
/**
* Glide 获得图片缓存路径
*/
private String getImagePath(String imgUrl) {
String path = null;
FutureTarget<File> future = Glide.with(ViewBigImageActivity.this)
.load(imgUrl)
.downloadOnly(500, 500);
try {
File cacheFile = future.get();
path = cacheFile.getAbsolutePath();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return path;
}
示例8: submit_withPreviousRequestClearedFromMemory_completesFromDataDiskCache
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
@Test
public void submit_withPreviousRequestClearedFromMemory_completesFromDataDiskCache()
throws InterruptedException, ExecutionException, TimeoutException {
FutureTarget<Drawable> future = GlideApp.with(context)
.load(ResourceIds.raw.canonical)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.submit(IMAGE_SIZE_PIXELS, IMAGE_SIZE_PIXELS);
concurrency.get(future);
GlideApp.with(context).clear(future);
clearMemoryCacheOnMainThread();
concurrency.get(
GlideApp.with(context)
.load(ResourceIds.raw.canonical)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.listener(requestListener)
.submit(IMAGE_SIZE_PIXELS, IMAGE_SIZE_PIXELS));
verify(requestListener)
.onResourceReady(
anyDrawable(),
any(),
anyTarget(),
eq(DataSource.DATA_DISK_CACHE),
anyBoolean());
}
示例9: submit_withPreviousButNoLongerReferencedIdenticalRequest_doesNotRecycleBitmap
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
@Test
public void submit_withPreviousButNoLongerReferencedIdenticalRequest_doesNotRecycleBitmap()
throws InterruptedException, TimeoutException, ExecutionException {
// We can't allow any mocks (RequestListener, Target etc) to reference this request or the test
// will fail due to the transient strong reference to the request.
Bitmap bitmap =
concurrency.get(
GlideApp.with(context)
.asBitmap()
.load(ResourceIds.raw.canonical)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.submit(IMAGE_SIZE_PIXELS, IMAGE_SIZE_PIXELS));
// Force the collection of weak references now that the listener/request in the first load is no
// longer referenced.
Runtime.getRuntime().gc();
concurrency.pokeMainThread();
FutureTarget<Bitmap> future = GlideApp.with(context)
.asBitmap()
.load(ResourceIds.raw.canonical)
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.submit(IMAGE_SIZE_PIXELS, IMAGE_SIZE_PIXELS);
concurrency.get(future);
Glide.with(context).clear(future);
clearMemoryCacheOnMainThread();
BitmapSubject.assertThat(bitmap).isNotRecycled();
}
示例10: clearDiskCache_doesNotPreventFutureLoads
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
@Test
public void clearDiskCache_doesNotPreventFutureLoads()
throws ExecutionException, InterruptedException, TimeoutException {
FutureTarget<Drawable> future = GlideApp.with(context)
.load(ResourceIds.raw.canonical)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.submit(IMAGE_SIZE_PIXELS, IMAGE_SIZE_PIXELS);
concurrency.get(future);
GlideApp.with(context).clear(future);
clearMemoryCacheOnMainThread();
GlideApp.get(context).clearDiskCache();
future = GlideApp.with(context)
.load(ResourceIds.raw.canonical)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.submit(IMAGE_SIZE_PIXELS, IMAGE_SIZE_PIXELS);
concurrency.get(future);
GlideApp.with(context).clear(future);
clearMemoryCacheOnMainThread();
concurrency.get(
GlideApp.with(context)
.load(ResourceIds.raw.canonical)
.listener(requestListener)
.diskCacheStrategy(DiskCacheStrategy.DATA)
.submit(IMAGE_SIZE_PIXELS, IMAGE_SIZE_PIXELS));
verify(requestListener)
.onResourceReady(
anyDrawable(),
any(),
anyTarget(),
eq(DataSource.DATA_DISK_CACHE),
anyBoolean());
}
示例11: getImagePath
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
/**
* Glide 获得图片缓存路径
*/
public static String getImagePath(String imgUrl) {
String path = null;
FutureTarget<File> future = Glide.with(VideoApplication.getInstance())
.load(imgUrl)
.downloadOnly(500, 500);
try {
File cacheFile = future.get();
path = cacheFile.getAbsolutePath();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return path;
}
示例12: sharePic
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
public void sharePic(final Context context, final String picUrl) {
Observable.just(picUrl)
.subscribeOn(Schedulers.newThread())
.map(new Func1<String, Uri>() {
@Override
public Uri call(String url) {
FutureTarget<File> future = Glide.with(mContext)
.load(url)
.downloadOnly(500, 500);
File cacheFile = null;
try {
cacheFile = future.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return Uri.fromFile(cacheFile);
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<Uri>() {
@Override
public void call(Uri uri) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
sendIntent.setType("image/*");
context.startActivity(Intent.createChooser(sendIntent, "发送神♂秘图片"));
}
});
}
示例13: doInBackground
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Override protected Result doInBackground(String... params) {
@SuppressWarnings("unchecked")
FutureTarget<File>[] requests = new FutureTarget[params.length];
// fire everything into Glide queue
for (int i = 0; i < params.length; i++) {
if (isCancelled()) {
break;
}
requests[i] = glide
.load(params[i])
.downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
;
}
// wait for each item
Result result = new Result();
for (int i = 0; i < params.length; i++) {
if (isCancelled()) {
for (int j = i; j < params.length; j++) {
if (requests[i] != null) {
Glide.clear(requests[i]);
}
result.failures.put(params[j], new CancellationException());
}
break;
}
try {
File file = requests[i].get(10, TimeUnit.SECONDS);
result.success.put(params[i], file);
} catch (Exception e) {
result.failures.put(params[i], e);
} finally {
Glide.clear(requests[i]);
}
publishProgress(params[i]);
}
return result;
}
示例14: getAvatarFile
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
public static File getAvatarFile(Context ctx, String avatarUrl) {
File f = null;
try {
FutureTarget<File> future = Glide.with(ctx)
.load(avatarUrl)
.downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
f = future.get();
Glide.clear(future);
} catch (Exception e) {
Logger.e(e);
}
return f;
}
示例15: submit_withRequestClearedFromMemory_doesNotLoadFromMemory
import com.bumptech.glide.request.FutureTarget; //导入依赖的package包/类
@Test
public void submit_withRequestClearedFromMemory_doesNotLoadFromMemory() {
Glide.init(
context, new GlideBuilder().setMemoryCache(new MemoryCacheAdapter()));
FutureTarget<Drawable> first =
GlideApp.with(context)
.load(raw.canonical)
.submit();
concurrency.get(first);
// Allow first to be GCed and removed from active resources.
//noinspection UnusedAssignment
first = null;
// De-flake by allowing multiple tries
for (int j = 0; j < 10; j++) {
Runtime.getRuntime().gc();
concurrency.pokeMainThread();
try {
// Loading again here won't shuffle our resource around because it only changes our
// reference count from 1 to 2 and back. The reference we're waiting for will only be
// decremented when the target is GCed.
FutureTarget<Drawable> target =
concurrency.wait(
GlideApp.with(context)
.load(ResourceIds.raw.canonical)
.onlyRetrieveFromCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.submit());
GlideApp.with(context).clear(target);
} catch (RuntimeException e) {
// The item has been cleared from active resources.
break;
}
}
concurrency.get(
GlideApp.with(context)
.load(ResourceIds.raw.canonical)
.listener(requestListener)
.submit());
verify(requestListener)
.onResourceReady(
anyDrawable(),
any(),
anyTarget(),
not(eq(DataSource.MEMORY_CACHE)),
anyBoolean());
}