Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
dcfc33ff
G
glide
项目概览
沉迷打码的小凳子
/
glide
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dcfc33ff
编写于
10月 05, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add an API for preloading resources.
上级
accb2312
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
84 addition
and
0 deletion
+84
-0
library/src/androidTest/java/com/bumptech/glide/request/target/PreloadTargetTest.java
.../com/bumptech/glide/request/target/PreloadTargetTest.java
+35
-0
library/src/main/java/com/bumptech/glide/GenericRequestBuilder.java
...c/main/java/com/bumptech/glide/GenericRequestBuilder.java
+16
-0
library/src/main/java/com/bumptech/glide/request/target/PreloadTarget.java
...java/com/bumptech/glide/request/target/PreloadTarget.java
+33
-0
未找到文件。
library/src/androidTest/java/com/bumptech/glide/request/target/PreloadTargetTest.java
0 → 100644
浏览文件 @
dcfc33ff
package
com.bumptech.glide.request.target
;
import
com.bumptech.glide.request.Request
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.RobolectricTestRunner
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
@RunWith
(
RobolectricTestRunner
.
class
)
public
class
PreloadTargetTest
{
@Test
public
void
testCallsSizeReadyWithGivenDimensions
()
{
int
width
=
1234
;
int
height
=
456
;
PreloadTarget
<
Object
>
target
=
PreloadTarget
.
obtain
(
width
,
height
);
SizeReadyCallback
cb
=
mock
(
SizeReadyCallback
.
class
);
target
.
getSize
(
cb
);
verify
(
cb
).
onSizeReady
(
eq
(
width
),
eq
(
height
));
}
@Test
public
void
testClearsTargetInOnResourceReady
()
{
Request
request
=
mock
(
Request
.
class
);
PreloadTarget
<
Object
>
target
=
PreloadTarget
.
obtain
(
100
,
100
);
target
.
setRequest
(
request
);
target
.
onResourceReady
(
new
Object
(),
null
);
verify
(
request
).
clear
();
}
}
\ No newline at end of file
library/src/main/java/com/bumptech/glide/GenericRequestBuilder.java
浏览文件 @
dcfc33ff
...
...
@@ -28,6 +28,7 @@ import com.bumptech.glide.request.animation.GlideAnimationFactory;
import
com.bumptech.glide.request.animation.NoAnimation
;
import
com.bumptech.glide.request.animation.ViewAnimation
;
import
com.bumptech.glide.request.animation.ViewPropertyAnimation
;
import
com.bumptech.glide.request.target.PreloadTarget
;
import
com.bumptech.glide.request.target.Target
;
import
com.bumptech.glide.util.Util
;
...
...
@@ -598,6 +599,21 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
return
target
;
}
/**
* Preloads the resource into the cache using the given width and height.
*
* <p>
* Pre-loading is useful for making sure that resources you are going to to want in the near future are
* available quickly.
* </p>
*
* @see com.bumptech.glide.ListPreloader
*/
public
Target
<
TranscodeType
>
preload
(
int
width
,
int
height
)
{
final
PreloadTarget
<
TranscodeType
>
target
=
PreloadTarget
.
obtain
(
width
,
height
);
return
into
(
target
);
}
void
applyCenterCrop
()
{
// To be implemented by subclasses when possible.
}
...
...
library/src/main/java/com/bumptech/glide/request/target/PreloadTarget.java
0 → 100644
浏览文件 @
dcfc33ff
package
com.bumptech.glide.request.target
;
import
com.bumptech.glide.Glide
;
import
com.bumptech.glide.request.animation.GlideAnimation
;
/**
* A one time use {@link com.bumptech.glide.request.target.Target} class that loads a resource into memory and then
* clears itself.
*
* @param <Z> The type of resource that will be loaded into memory.
*/
public
final
class
PreloadTarget
<
Z
>
extends
SimpleTarget
<
Z
>
{
/**
* Returns a PreloadTarget.
*
* @param width The width of the desired resourece.
* @param height The height of the desired resource.
* @param <Z> The type of the desired resource.
*/
public
static
<
Z
>
PreloadTarget
<
Z
>
obtain
(
int
width
,
int
height
)
{
return
new
PreloadTarget
<
Z
>(
width
,
height
);
}
private
PreloadTarget
(
int
width
,
int
height
)
{
super
(
width
,
height
);
}
@Override
public
void
onResourceReady
(
Z
resource
,
GlideAnimation
<?
super
Z
>
glideAnimation
)
{
Glide
.
clear
(
this
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录