Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
b9a2d3b2
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,体验更适合开发者的 AI 搜索 >>
提交
b9a2d3b2
编写于
5月 01, 2015
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add method to set a resource id to use with setTag
Fixes #370
上级
ea0a17a7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
2 deletion
+48
-2
library/src/main/java/com/bumptech/glide/Glide.java
library/src/main/java/com/bumptech/glide/Glide.java
+1
-0
library/src/main/java/com/bumptech/glide/request/target/ViewTarget.java
...in/java/com/bumptech/glide/request/target/ViewTarget.java
+47
-2
未找到文件。
library/src/main/java/com/bumptech/glide/Glide.java
浏览文件 @
b9a2d3b2
...
...
@@ -419,6 +419,7 @@ public class Glide {
Request
request
=
target
.
getRequest
();
if
(
request
!=
null
)
{
request
.
clear
();
target
.
setRequest
(
null
);
}
}
...
...
library/src/main/java/com/bumptech/glide/request/target/ViewTarget.java
浏览文件 @
b9a2d3b2
...
...
@@ -39,10 +39,38 @@ import java.util.List;
*/
public
abstract
class
ViewTarget
<
T
extends
View
,
Z
>
extends
BaseTarget
<
Z
>
{
private
static
final
String
TAG
=
"ViewTarget"
;
private
static
boolean
isTagUsedAtLeastOnce
=
false
;
private
static
Integer
tagId
=
null
;
protected
final
T
view
;
private
final
SizeDeterminer
sizeDeterminer
;
/**
* Sets the android resource id to use in conjunction with {@link View#setTag(int, Object)}
* to store temporary state allowing loads to be automatically cancelled and resources re-used
* in scrolling lists.
*
* <p>
* If no tag id is set, Glide will use {@link View#setTag(Object)}.
* </p>
*
* <p>
* Warning: prior to Android 4.0 tags were stored in a static map. Using this method prior
* to Android 4.0 may cause memory leaks and isn't recommended. If you do use this method
* on older versions, be sure to call {@link com.bumptech.glide.Glide#clear(View)} on any view
* you start a load into to ensure that the static state is removed.
* </p>
*
* @param tagId The android resource to use.
*/
public
static
void
setTagId
(
int
tagId
)
{
if
(
ViewTarget
.
tagId
!=
null
||
isTagUsedAtLeastOnce
)
{
throw
new
IllegalArgumentException
(
"You cannot set the tag id more than once or change"
+
" the tag id after the first request has been made"
);
}
ViewTarget
.
tagId
=
tagId
;
}
public
ViewTarget
(
T
view
)
{
if
(
view
==
null
)
{
throw
new
NullPointerException
(
"View must not be null!"
);
...
...
@@ -79,7 +107,7 @@ public abstract class ViewTarget<T extends View, Z> extends BaseTarget<Z> {
*/
@Override
public
void
setRequest
(
Request
request
)
{
view
.
setTag
(
request
);
setTag
(
request
);
}
/**
...
...
@@ -96,7 +124,7 @@ public abstract class ViewTarget<T extends View, Z> extends BaseTarget<Z> {
*/
@Override
public
Request
getRequest
()
{
Object
tag
=
view
.
getTag
();
Object
tag
=
getTag
();
Request
request
=
null
;
if
(
tag
!=
null
)
{
if
(
tag
instanceof
Request
)
{
...
...
@@ -108,6 +136,23 @@ public abstract class ViewTarget<T extends View, Z> extends BaseTarget<Z> {
return
request
;
}
private
void
setTag
(
Object
tag
)
{
if
(
tagId
==
null
)
{
isTagUsedAtLeastOnce
=
true
;
view
.
setTag
(
tag
);
}
else
{
view
.
setTag
(
tagId
,
tag
);
}
}
private
Object
getTag
()
{
if
(
tagId
==
null
)
{
return
view
.
getTag
();
}
else
{
return
view
.
getTag
(
tagId
);
}
}
@Override
public
String
toString
()
{
return
"Target for: "
+
view
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录