Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
95482113
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 搜索 >>
提交
95482113
编写于
5月 01, 2015
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a fallback Drawable to display for null models
Fixes #268
上级
b9a2d3b2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
141 addition
and
10 deletion
+141
-10
library/src/androidTest/java/com/bumptech/glide/request/GenericRequestTest.java
...t/java/com/bumptech/glide/request/GenericRequestTest.java
+36
-9
library/src/main/java/com/bumptech/glide/BitmapRequestBuilder.java
...rc/main/java/com/bumptech/glide/BitmapRequestBuilder.java
+12
-0
library/src/main/java/com/bumptech/glide/DrawableRequestBuilder.java
.../main/java/com/bumptech/glide/DrawableRequestBuilder.java
+12
-0
library/src/main/java/com/bumptech/glide/GenericRequestBuilder.java
...c/main/java/com/bumptech/glide/GenericRequestBuilder.java
+47
-0
library/src/main/java/com/bumptech/glide/GifRequestBuilder.java
...y/src/main/java/com/bumptech/glide/GifRequestBuilder.java
+12
-0
library/src/main/java/com/bumptech/glide/request/GenericRequest.java
.../main/java/com/bumptech/glide/request/GenericRequest.java
+22
-1
未找到文件。
library/src/androidTest/java/com/bumptech/glide/request/GenericRequestTest.java
浏览文件 @
95482113
...
...
@@ -77,6 +77,8 @@ public class GenericRequestTest {
int
placeholderResourceId
=
0
;
Drawable
placeholderDrawable
=
null
;
int
errorResourceId
=
0
;
Drawable
fallbackDrawable
=
null
;
int
fallbackResourceId
=
0
;
Transformation
transformation
=
mock
(
Transformation
.
class
);
Drawable
errorDrawable
=
null
;
LoadProvider
<
Number
,
Object
,
Object
,
List
>
loadProvider
=
mock
(
LoadProvider
.
class
);
...
...
@@ -122,6 +124,8 @@ public class GenericRequestTest {
placeholderResourceId
,
errorDrawable
,
errorResourceId
,
fallbackDrawable
,
fallbackResourceId
,
requestListener
,
requestCoordinator
,
engine
,
...
...
@@ -331,7 +335,8 @@ public class GenericRequestTest {
assertTrue
(
request
.
isFailed
());
verify
(
harness
.
requestListener
)
.
onException
(
any
(
Exception
.
class
),
any
(
Number
.
class
),
eq
(
harness
.
target
),
anyBoolean
());
.
onException
(
any
(
Exception
.
class
),
any
(
Number
.
class
),
eq
(
harness
.
target
),
anyBoolean
());
}
@Test
...
...
@@ -357,7 +362,8 @@ public class GenericRequestTest {
assertTrue
(
request
.
isFailed
());
verify
(
harness
.
engine
).
release
(
eq
(
harness
.
resource
));
verify
(
harness
.
requestListener
)
.
onException
(
any
(
Exception
.
class
),
any
(
Number
.
class
),
eq
(
harness
.
target
),
anyBoolean
());
.
onException
(
any
(
Exception
.
class
),
any
(
Number
.
class
),
eq
(
harness
.
target
),
anyBoolean
());
}
@Test
...
...
@@ -483,9 +489,10 @@ public class GenericRequestTest {
request
.
onSizeReady
(
100
,
100
);
request
.
onSizeReady
(
100
,
100
);
verify
(
harness
.
engine
,
times
(
1
)).
load
(
eq
(
harness
.
signature
),
eq
(
100
),
eq
(
100
),
any
(
DataFetcher
.
class
),
any
(
DataLoadProvider
.
class
),
any
(
Transformation
.
class
),
any
(
ResourceTranscoder
.
class
),
any
(
Priority
.
class
),
anyBoolean
(),
any
(
DiskCacheStrategy
.
class
),
any
(
ResourceCallback
.
class
));
verify
(
harness
.
engine
,
times
(
1
)).
load
(
eq
(
harness
.
signature
),
eq
(
100
),
eq
(
100
),
any
(
DataFetcher
.
class
),
any
(
DataLoadProvider
.
class
),
any
(
Transformation
.
class
),
any
(
ResourceTranscoder
.
class
),
any
(
Priority
.
class
),
anyBoolean
(),
any
(
DiskCacheStrategy
.
class
),
any
(
ResourceCallback
.
class
));
}
@Test
...
...
@@ -506,8 +513,8 @@ public class GenericRequestTest {
request
.
onSizeReady
(
100
,
100
);
verify
(
harness
.
engine
).
load
(
any
(
Key
.
class
),
anyInt
(),
anyInt
(),
any
(
DataFetcher
.
class
),
any
(
DataLoadProvider
.
class
),
any
(
Transformation
.
class
),
any
(
ResourceTranscoder
.
class
),
eq
(
expected
),
anyBoolean
(),
any
(
DiskCacheStrategy
.
class
),
any
(
ResourceCallback
.
class
));
any
(
DataLoadProvider
.
class
),
any
(
Transformation
.
class
),
any
(
ResourceTranscoder
.
class
),
eq
(
expected
),
anyBoolean
(),
any
(
DiskCacheStrategy
.
class
),
any
(
ResourceCallback
.
class
));
}
@Test
...
...
@@ -602,7 +609,7 @@ public class GenericRequestTest {
}
@Test
public
void
setTestPlaceholderDrawableSetOnNullModel
()
{
public
void
testPlaceholderDrawableSetOnNullModelWithNoErrorDrawable
()
{
Drawable
placeholder
=
new
ColorDrawable
(
Color
.
RED
);
MockTarget
target
=
new
MockTarget
();
...
...
@@ -618,7 +625,7 @@ public class GenericRequestTest {
}
@Test
public
void
testErrorDrawableSetOnNullModel
()
{
public
void
testErrorDrawableSetOnNullModel
WithErrorDrawable
()
{
Drawable
placeholder
=
new
ColorDrawable
(
Color
.
RED
);
Drawable
errorPlaceholder
=
new
ColorDrawable
(
Color
.
GREEN
);
...
...
@@ -635,6 +642,26 @@ public class GenericRequestTest {
assertEquals
(
errorPlaceholder
,
target
.
currentPlaceholder
);
}
@Test
public
void
testFallbackDrawableSetOnNullModelWithErrorAndFallbackDrawables
()
{
Drawable
placeholder
=
new
ColorDrawable
(
Color
.
RED
);
Drawable
errorPlaceholder
=
new
ColorDrawable
(
Color
.
GREEN
);
Drawable
fallback
=
new
ColorDrawable
(
Color
.
BLUE
);
MockTarget
target
=
new
MockTarget
();
harness
.
placeholderDrawable
=
placeholder
;
harness
.
errorDrawable
=
errorPlaceholder
;
harness
.
fallbackDrawable
=
fallback
;
harness
.
target
=
target
;
harness
.
model
=
null
;
GenericRequest
request
=
harness
.
getRequest
();
request
.
begin
();
assertEquals
(
fallback
,
target
.
currentPlaceholder
);
}
@Test
public
void
testIsNotRunningBeforeRunCalled
()
{
assertFalse
(
harness
.
getRequest
().
isRunning
());
...
...
library/src/main/java/com/bumptech/glide/BitmapRequestBuilder.java
浏览文件 @
95482113
...
...
@@ -369,6 +369,18 @@ public class BitmapRequestBuilder<ModelType, TranscodeType>
return
this
;
}
@Override
public
BitmapRequestBuilder
<
ModelType
,
TranscodeType
>
fallback
(
Drawable
drawable
)
{
super
.
fallback
(
drawable
);
return
this
;
}
@Override
public
BitmapRequestBuilder
<
ModelType
,
TranscodeType
>
fallback
(
int
resourceId
)
{
super
.
fallback
(
resourceId
);
return
this
;
}
/**
* {@inheritDoc}
*/
...
...
library/src/main/java/com/bumptech/glide/DrawableRequestBuilder.java
浏览文件 @
95482113
...
...
@@ -329,6 +329,18 @@ public class DrawableRequestBuilder<ModelType>
return
this
;
}
@Override
public
DrawableRequestBuilder
<
ModelType
>
fallback
(
Drawable
drawable
)
{
super
.
fallback
(
drawable
);
return
this
;
}
@Override
public
DrawableRequestBuilder
<
ModelType
>
fallback
(
int
resourceId
)
{
super
.
fallback
(
resourceId
);
return
this
;
}
/**
* {@inheritDoc}
*/
...
...
library/src/main/java/com/bumptech/glide/GenericRequestBuilder.java
浏览文件 @
95482113
...
...
@@ -77,6 +77,8 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
private
Transformation
<
ResourceType
>
transformation
=
UnitTransformation
.
get
();
private
boolean
isTransformationSet
;
private
boolean
isThumbnailBuilt
;
private
Drawable
fallbackDrawable
;
private
int
fallbackResource
;
GenericRequestBuilder
(
LoadProvider
<
ModelType
,
DataType
,
ResourceType
,
TranscodeType
>
loadProvider
,
Class
<
TranscodeType
>
transcodeClass
,
GenericRequestBuilder
<
ModelType
,
?,
?,
?>
other
)
{
...
...
@@ -447,6 +449,49 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
return
this
;
}
/**
* Sets an {@link android.graphics.drawable.Drawable} to display if the model provided to
* {@link #load(Object)} is {@code null}.
*
* <p>
* If a fallback is not set, null models will cause the error drawable to be displayed. If
* the error drawable is not set, the placeholder will be displayed.
* </p>
*
* @see #placeholder(Drawable)
* @see #placeholder(int)
*
* @param drawable The drawable to display as a placeholder.
* @return This request builder.
*/
public
GenericRequestBuilder
<
ModelType
,
DataType
,
ResourceType
,
TranscodeType
>
fallback
(
Drawable
drawable
)
{
this
.
fallbackDrawable
=
drawable
;
return
this
;
}
/**
* Sets a resource to display if the model provided to {@link #load(Object)} is {@code null}.
*
* <p>
* If a fallback is not set, null models will cause the error drawable to be displayed. If
* the error drawable is not set, the placeholder will be displayed.
* </p>
*
* @see #placeholder(Drawable)
* @see #placeholder(int)
*
* @param resourceId The id of the resource to use as a fallback.
* @return This request builder.
*/
public
GenericRequestBuilder
<
ModelType
,
DataType
,
ResourceType
,
TranscodeType
>
fallback
(
int
resourceId
)
{
this
.
fallbackResource
=
resourceId
;
return
this
;
}
/**
* Sets a resource to display if a load fails.
*
...
...
@@ -802,6 +847,8 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
placeholderId
,
errorPlaceholder
,
errorId
,
fallbackDrawable
,
fallbackResource
,
requestListener
,
requestCoordinator
,
glide
.
getEngine
(),
...
...
library/src/main/java/com/bumptech/glide/GifRequestBuilder.java
浏览文件 @
95482113
...
...
@@ -319,6 +319,18 @@ public class GifRequestBuilder<ModelType>
return
this
;
}
@Override
public
GifRequestBuilder
<
ModelType
>
fallback
(
Drawable
drawable
)
{
super
.
fallback
(
drawable
);
return
this
;
}
@Override
public
GifRequestBuilder
<
ModelType
>
fallback
(
int
resourceId
)
{
super
.
fallback
(
resourceId
);
return
this
;
}
/**
* {@inheritDoc}
*/
...
...
library/src/main/java/com/bumptech/glide/request/GenericRequest.java
浏览文件 @
95482113
...
...
@@ -59,6 +59,8 @@ public final class GenericRequest<A, T, Z, R> implements Request, SizeReadyCallb
private
final
String
tag
=
String
.
valueOf
(
hashCode
());
private
Key
signature
;
private
Drawable
fallbackDrawable
;
private
int
fallbackResourceId
;
private
int
placeholderResourceId
;
private
int
errorResourceId
;
private
Context
context
;
...
...
@@ -99,6 +101,8 @@ public final class GenericRequest<A, T, Z, R> implements Request, SizeReadyCallb
int
placeholderResourceId
,
Drawable
errorDrawable
,
int
errorResourceId
,
Drawable
fallbackDrawable
,
int
fallbackResourceId
,
RequestListener
<?
super
A
,
R
>
requestListener
,
RequestCoordinator
requestCoordinator
,
Engine
engine
,
...
...
@@ -125,6 +129,8 @@ public final class GenericRequest<A, T, Z, R> implements Request, SizeReadyCallb
placeholderResourceId
,
errorDrawable
,
errorResourceId
,
fallbackDrawable
,
fallbackResourceId
,
requestListener
,
requestCoordinator
,
engine
,
...
...
@@ -150,6 +156,7 @@ public final class GenericRequest<A, T, Z, R> implements Request, SizeReadyCallb
target
=
null
;
placeholderDrawable
=
null
;
errorDrawable
=
null
;
fallbackDrawable
=
null
;
requestListener
=
null
;
requestCoordinator
=
null
;
transformation
=
null
;
...
...
@@ -171,6 +178,8 @@ public final class GenericRequest<A, T, Z, R> implements Request, SizeReadyCallb
int
placeholderResourceId
,
Drawable
errorDrawable
,
int
errorResourceId
,
Drawable
fallbackDrawable
,
int
fallbackResourceId
,
RequestListener
<?
super
A
,
R
>
requestListener
,
RequestCoordinator
requestCoordinator
,
Engine
engine
,
...
...
@@ -184,6 +193,8 @@ public final class GenericRequest<A, T, Z, R> implements Request, SizeReadyCallb
this
.
loadProvider
=
loadProvider
;
this
.
model
=
model
;
this
.
signature
=
signature
;
this
.
fallbackDrawable
=
fallbackDrawable
;
this
.
fallbackResourceId
=
fallbackResourceId
;
this
.
context
=
context
.
getApplicationContext
();
this
.
priority
=
priority
;
this
.
target
=
target
;
...
...
@@ -371,12 +382,22 @@ public final class GenericRequest<A, T, Z, R> implements Request, SizeReadyCallb
return
status
==
Status
.
FAILED
;
}
private
Drawable
getFallbackDrawable
()
{
if
(
fallbackDrawable
==
null
&&
fallbackResourceId
>
0
)
{
fallbackDrawable
=
context
.
getResources
().
getDrawable
(
fallbackResourceId
);
}
return
fallbackDrawable
;
}
private
void
setErrorPlaceholder
(
Exception
e
)
{
if
(!
canNotifyStatusChanged
())
{
return
;
}
Drawable
error
=
getErrorDrawable
();
Drawable
error
=
model
==
null
?
getFallbackDrawable
()
:
null
;
if
(
error
==
null
)
{
error
=
getErrorDrawable
();
}
if
(
error
==
null
)
{
error
=
getPlaceholderDrawable
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录