Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
8a6067fb
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,发现更多精彩内容 >>
提交
8a6067fb
编写于
6月 15, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add RequestManagers based on lifecycle events.
上级
512fcec1
变更
32
显示空白变更内容
内联
并排
Showing
32 changed file
with
1115 addition
and
60 deletion
+1115
-60
library/libs/android-support-v4.jar
library/libs/android-support-v4.jar
+0
-0
library/pom.xml
library/pom.xml
+0
-1
library/src/main/java/com/bumptech/glide/BitmapRequestBuilder.java
...rc/main/java/com/bumptech/glide/BitmapRequestBuilder.java
+3
-2
library/src/main/java/com/bumptech/glide/BitmapTypeRequest.java
...y/src/main/java/com/bumptech/glide/BitmapTypeRequest.java
+6
-3
library/src/main/java/com/bumptech/glide/DrawableRequestBuilder.java
.../main/java/com/bumptech/glide/DrawableRequestBuilder.java
+4
-4
library/src/main/java/com/bumptech/glide/DrawableTypeRequest.java
...src/main/java/com/bumptech/glide/DrawableTypeRequest.java
+11
-5
library/src/main/java/com/bumptech/glide/GenericRequestBuilder.java
...c/main/java/com/bumptech/glide/GenericRequestBuilder.java
+7
-1
library/src/main/java/com/bumptech/glide/GenericTranscodeRequest.java
...main/java/com/bumptech/glide/GenericTranscodeRequest.java
+6
-3
library/src/main/java/com/bumptech/glide/GifRequestBuilder.java
...y/src/main/java/com/bumptech/glide/GifRequestBuilder.java
+3
-2
library/src/main/java/com/bumptech/glide/GifTypeRequest.java
library/src/main/java/com/bumptech/glide/GifTypeRequest.java
+8
-3
library/src/main/java/com/bumptech/glide/Glide.java
library/src/main/java/com/bumptech/glide/Glide.java
+30
-1
library/src/main/java/com/bumptech/glide/ModelRequest.java
library/src/main/java/com/bumptech/glide/ModelRequest.java
+31
-16
library/src/main/java/com/bumptech/glide/manager/LifecycleRequestManager.java
...a/com/bumptech/glide/manager/LifecycleRequestManager.java
+43
-0
library/src/main/java/com/bumptech/glide/manager/NullRequestManager.java
...n/java/com/bumptech/glide/manager/NullRequestManager.java
+13
-0
library/src/main/java/com/bumptech/glide/manager/RequestManager.java
.../main/java/com/bumptech/glide/manager/RequestManager.java
+10
-0
library/src/main/java/com/bumptech/glide/manager/RequestManagerFragment.java
...va/com/bumptech/glide/manager/RequestManagerFragment.java
+39
-0
library/src/main/java/com/bumptech/glide/manager/RequestManagerLifecycleFragment.java
...mptech/glide/manager/RequestManagerLifecycleFragment.java
+14
-0
library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java
...a/com/bumptech/glide/manager/RequestManagerRetriever.java
+87
-0
library/src/main/java/com/bumptech/glide/manager/SupportRequestManagerFragment.java
...bumptech/glide/manager/SupportRequestManagerFragment.java
+39
-0
library/src/main/java/com/bumptech/glide/request/GenericRequest.java
.../main/java/com/bumptech/glide/request/GenericRequest.java
+12
-2
library/src/main/java/com/bumptech/glide/request/Request.java
...ary/src/main/java/com/bumptech/glide/request/Request.java
+5
-0
library/src/main/java/com/bumptech/glide/request/ThumbnailRequestCoordinator.java
...m/bumptech/glide/request/ThumbnailRequestCoordinator.java
+9
-2
library/src/test/java/com/bumptech/glide/GenericRequestBuilderTest.java
...st/java/com/bumptech/glide/GenericRequestBuilderTest.java
+37
-4
library/src/test/java/com/bumptech/glide/manager/LifecycleRequestManagerTest.java
...m/bumptech/glide/manager/LifecycleRequestManagerTest.java
+136
-0
library/src/test/java/com/bumptech/glide/manager/RequestManagerFragmentTest.java
...om/bumptech/glide/manager/RequestManagerFragmentTest.java
+170
-0
library/src/test/java/com/bumptech/glide/manager/RequestManagerRetrieverTest.java
...m/bumptech/glide/manager/RequestManagerRetrieverTest.java
+255
-0
library/src/test/java/com/bumptech/glide/request/GenericRequestTest.java
...t/java/com/bumptech/glide/request/GenericRequestTest.java
+43
-2
library/src/test/java/com/bumptech/glide/request/ThumbnailRequestCoordinatorTest.java
...mptech/glide/request/ThumbnailRequestCoordinatorTest.java
+83
-0
library/src/test/java/com/bumptech/glide/tests/TestFragmentActivity.java
...t/java/com/bumptech/glide/tests/TestFragmentActivity.java
+6
-0
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
...va/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
+1
-1
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
...va/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
+1
-1
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrSearchActivity.java
...m/bumptech/glide/samples/flickr/FlickrSearchActivity.java
+3
-7
未找到文件。
library/libs/android-support-v4.jar
0 → 100644
浏览文件 @
8a6067fb
文件已添加
library/pom.xml
浏览文件 @
8a6067fb
...
...
@@ -18,7 +18,6 @@
<groupId>
android.support
</groupId>
<artifactId>
compatibility-v4
</artifactId>
<version>
19.1.0
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.roboguice
</groupId>
...
...
library/src/main/java/com/bumptech/glide/BitmapRequestBuilder.java
浏览文件 @
8a6067fb
...
...
@@ -19,6 +19,7 @@ import com.bumptech.glide.load.resource.bitmap.VideoBitmapDecoder;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
;
import
com.bumptech.glide.load.model.ImageVideoWrapper
;
import
com.bumptech.glide.manager.RequestManager
;
import
com.bumptech.glide.provider.LoadProvider
;
import
com.bumptech.glide.request.RequestListener
;
...
...
@@ -42,8 +43,8 @@ public class BitmapRequestBuilder<ModelType, TranscodeType> extends GenericReque
BitmapRequestBuilder
(
Context
context
,
ModelType
model
,
LoadProvider
<
ModelType
,
ImageVideoWrapper
,
Bitmap
,
TranscodeType
>
streamLoadProvider
,
Class
<
TranscodeType
>
transcodeClass
,
Glide
glide
)
{
super
(
context
,
model
,
streamLoadProvider
,
transcodeClass
,
glide
);
Class
<
TranscodeType
>
transcodeClass
,
Glide
glide
,
RequestManager
requestManager
)
{
super
(
context
,
model
,
streamLoadProvider
,
transcodeClass
,
glide
,
requestManager
);
this
.
bitmapPool
=
glide
.
getBitmapPool
();
imageDecoder
=
new
StreamBitmapDecoder
(
bitmapPool
);
...
...
library/src/main/java/com/bumptech/glide/BitmapTypeRequest.java
浏览文件 @
8a6067fb
...
...
@@ -8,6 +8,7 @@ import com.bumptech.glide.load.model.ImageVideoWrapper;
import
com.bumptech.glide.load.model.ModelLoader
;
import
com.bumptech.glide.load.resource.transcode.BitmapBytesTranscoder
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.manager.RequestManager
;
import
com.bumptech.glide.provider.FixedLoadProvider
;
import
java.io.InputStream
;
...
...
@@ -18,6 +19,7 @@ public class BitmapTypeRequest<A> extends BitmapRequestBuilder<A, Bitmap> {
private
final
ModelLoader
<
A
,
InputStream
>
streamModelLoader
;
private
ModelLoader
<
A
,
ParcelFileDescriptor
>
fileDescriptorModelLoader
;
private
final
Glide
glide
;
private
RequestManager
requestManager
;
private
static
<
A
,
R
>
FixedLoadProvider
<
A
,
ImageVideoWrapper
,
Bitmap
,
R
>
buildProvider
(
Glide
glide
,
ModelLoader
<
A
,
InputStream
>
streamModelLoader
,
...
...
@@ -34,22 +36,23 @@ public class BitmapTypeRequest<A> extends BitmapRequestBuilder<A, Bitmap> {
BitmapTypeRequest
(
Context
context
,
A
model
,
ModelLoader
<
A
,
InputStream
>
streamModelLoader
,
ModelLoader
<
A
,
ParcelFileDescriptor
>
fileDescriptorModelLoader
,
Glide
glide
)
{
Glide
glide
,
RequestManager
requestManager
)
{
super
(
context
,
model
,
buildProvider
(
glide
,
streamModelLoader
,
fileDescriptorModelLoader
,
Bitmap
.
class
,
null
),
Bitmap
.
class
,
glide
);
glide
,
requestManager
);
this
.
context
=
context
;
this
.
model
=
model
;
this
.
streamModelLoader
=
streamModelLoader
;
this
.
fileDescriptorModelLoader
=
fileDescriptorModelLoader
;
this
.
glide
=
glide
;
this
.
requestManager
=
requestManager
;
}
public
<
R
>
BitmapRequestBuilder
<
A
,
R
>
transcode
(
ResourceTranscoder
<
Bitmap
,
R
>
transcoder
,
Class
<
R
>
transcodeClass
)
{
return
new
BitmapRequestBuilder
<
A
,
R
>(
context
,
model
,
buildProvider
(
glide
,
streamModelLoader
,
fileDescriptorModelLoader
,
transcodeClass
,
transcoder
),
transcodeClass
,
glide
);
transcodeClass
,
glide
,
requestManager
);
}
public
BitmapRequestBuilder
<
A
,
byte
[]>
toBytes
()
{
...
...
library/src/main/java/com/bumptech/glide/DrawableRequestBuilder.java
浏览文件 @
8a6067fb
...
...
@@ -13,6 +13,7 @@ import com.bumptech.glide.load.resource.bitmap.FitCenter;
import
com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapper
;
import
com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperTransformation
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.manager.RequestManager
;
import
com.bumptech.glide.provider.LoadProvider
;
import
com.bumptech.glide.request.RequestListener
;
...
...
@@ -20,13 +21,12 @@ import java.io.InputStream;
public
class
DrawableRequestBuilder
<
ModelType
>
extends
GenericRequestBuilder
<
ModelType
,
ImageVideoWrapper
,
GifBitmapWrapper
,
Drawable
>
{
private
final
Context
context
;
private
final
Glide
glide
;
DrawableRequestBuilder
(
Context
context
,
ModelType
model
,
LoadProvider
<
ModelType
,
ImageVideoWrapper
,
GifBitmapWrapper
,
Drawable
>
loadProvider
,
Glide
glide
)
{
super
(
context
,
model
,
loadProvider
,
Drawable
.
class
,
glide
);
this
.
context
=
context
;
LoadProvider
<
ModelType
,
ImageVideoWrapper
,
GifBitmapWrapper
,
Drawable
>
loadProvider
,
Glide
glide
,
RequestManager
requestManager
)
{
super
(
context
,
model
,
loadProvider
,
Drawable
.
class
,
glide
,
requestManager
)
;
this
.
glide
=
glide
;
}
...
...
library/src/main/java/com/bumptech/glide/DrawableTypeRequest.java
浏览文件 @
8a6067fb
...
...
@@ -8,6 +8,7 @@ import com.bumptech.glide.load.model.ImageVideoWrapper;
import
com.bumptech.glide.load.model.ModelLoader
;
import
com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapper
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.manager.RequestManager
;
import
com.bumptech.glide.provider.FixedLoadProvider
;
import
java.io.InputStream
;
...
...
@@ -17,6 +18,7 @@ public class DrawableTypeRequest<A> extends DrawableRequestBuilder<A> {
private
final
ModelLoader
<
A
,
ParcelFileDescriptor
>
fileDescriptorModelLoader
;
private
final
Context
context
;
private
final
Glide
glide
;
private
RequestManager
requestManager
;
private
final
A
model
;
private
static
<
A
,
Z
,
R
>
FixedLoadProvider
<
A
,
ImageVideoWrapper
,
Z
,
R
>
buildProvider
(
Glide
glide
,
...
...
@@ -33,22 +35,26 @@ public class DrawableTypeRequest<A> extends DrawableRequestBuilder<A> {
DrawableTypeRequest
(
A
model
,
ModelLoader
<
A
,
InputStream
>
streamModelLoader
,
ModelLoader
<
A
,
ParcelFileDescriptor
>
fileDescriptorModelLoader
,
Context
context
,
Glide
glide
)
{
ModelLoader
<
A
,
ParcelFileDescriptor
>
fileDescriptorModelLoader
,
Context
context
,
Glide
glide
,
RequestManager
requestManager
)
{
super
(
context
,
model
,
buildProvider
(
glide
,
streamModelLoader
,
fileDescriptorModelLoader
,
GifBitmapWrapper
.
class
,
Drawable
.
class
,
null
),
glide
);
buildProvider
(
glide
,
streamModelLoader
,
fileDescriptorModelLoader
,
GifBitmapWrapper
.
class
,
Drawable
.
class
,
null
),
glide
,
requestManager
);
this
.
model
=
model
;
this
.
streamModelLoader
=
streamModelLoader
;
this
.
fileDescriptorModelLoader
=
fileDescriptorModelLoader
;
this
.
context
=
context
;
this
.
glide
=
glide
;
this
.
requestManager
=
requestManager
;
}
public
BitmapTypeRequest
<
A
>
asBitmap
()
{
return
new
BitmapTypeRequest
<
A
>(
context
,
model
,
streamModelLoader
,
fileDescriptorModelLoader
,
glide
);
return
new
BitmapTypeRequest
<
A
>(
context
,
model
,
streamModelLoader
,
fileDescriptorModelLoader
,
glide
,
requestManager
);
}
public
GifTypeRequest
<
A
>
asGif
()
{
return
new
GifTypeRequest
<
A
>(
context
,
model
,
streamModelLoader
,
glide
);
return
new
GifTypeRequest
<
A
>(
context
,
model
,
streamModelLoader
,
glide
,
requestManager
);
}
}
library/src/main/java/com/bumptech/glide/GenericRequestBuilder.java
浏览文件 @
8a6067fb
...
...
@@ -13,6 +13,7 @@ import com.bumptech.glide.load.Transformation;
import
com.bumptech.glide.load.model.ModelLoader
;
import
com.bumptech.glide.load.resource.bitmap.BitmapDecoder
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.manager.RequestManager
;
import
com.bumptech.glide.provider.ChildLoadProvider
;
import
com.bumptech.glide.provider.LoadProvider
;
import
com.bumptech.glide.request.Request
;
...
...
@@ -44,6 +45,7 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
private
final
ChildLoadProvider
<
ModelType
,
DataType
,
ResourceType
,
TranscodeType
>
loadProvider
;
private
final
Class
<
TranscodeType
>
transcodeClass
;
private
final
Glide
glide
;
private
final
RequestManager
requestManager
;
private
int
animationId
;
private
Animation
animation
;
private
int
placeholderId
;
...
...
@@ -61,9 +63,10 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
GenericRequestBuilder
(
Context
context
,
ModelType
model
,
LoadProvider
<
ModelType
,
DataType
,
ResourceType
,
TranscodeType
>
loadProvider
,
Class
<
TranscodeType
>
transcodeClass
,
Glide
glide
)
{
Class
<
TranscodeType
>
transcodeClass
,
Glide
glide
,
RequestManager
requestManager
)
{
this
.
transcodeClass
=
transcodeClass
;
this
.
glide
=
glide
;
this
.
requestManager
=
requestManager
;
this
.
loadProvider
=
loadProvider
!=
null
?
new
ChildLoadProvider
<
ModelType
,
DataType
,
ResourceType
,
TranscodeType
>(
loadProvider
)
:
null
;
preSkipEncoder
=
loadProvider
!=
null
?
loadProvider
.
getEncoder
()
:
null
;
...
...
@@ -398,12 +401,15 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
*/
public
<
Y
extends
Target
<
TranscodeType
>>
Y
into
(
Y
target
)
{
Request
previous
=
target
.
getRequest
();
if
(
previous
!=
null
)
{
previous
.
clear
();
requestManager
.
removeRequest
(
previous
);
}
Request
request
=
buildRequest
(
target
);
target
.
setRequest
(
request
);
requestManager
.
addRequest
(
request
);
if
(
request
!=
null
)
{
request
.
run
();
}
...
...
library/src/main/java/com/bumptech/glide/GenericTranscodeRequest.java
浏览文件 @
8a6067fb
...
...
@@ -4,6 +4,7 @@ import android.content.Context;
import
com.bumptech.glide.load.model.ModelLoader
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.load.resource.transcode.UnitTranscoder
;
import
com.bumptech.glide.manager.RequestManager
;
import
com.bumptech.glide.provider.FixedLoadProvider
;
import
com.bumptech.glide.provider.LoadProvider
;
...
...
@@ -14,24 +15,26 @@ public class GenericTranscodeRequest<A, T, Z> extends GenericRequestBuilder<A, T
private
final
ModelLoader
<
A
,
T
>
modelLoader
;
private
final
Class
<
T
>
dataClass
;
private
final
Class
<
Z
>
resourceClass
;
private
RequestManager
requestManager
;
GenericTranscodeRequest
(
Context
context
,
Glide
glide
,
A
model
,
ModelLoader
<
A
,
T
>
modelLoader
,
Class
<
T
>
dataClass
,
Class
<
Z
>
resourceClass
)
{
Class
<
T
>
dataClass
,
Class
<
Z
>
resourceClass
,
RequestManager
requestManager
)
{
super
(
context
,
model
,
build
(
glide
,
modelLoader
,
dataClass
,
resourceClass
,
(
ResourceTranscoder
<
Z
,
Z
>)
null
),
resourceClass
,
glide
);
resourceClass
,
glide
,
requestManager
);
this
.
context
=
context
;
this
.
model
=
model
;
this
.
glide
=
glide
;
this
.
modelLoader
=
modelLoader
;
this
.
dataClass
=
dataClass
;
this
.
resourceClass
=
resourceClass
;
this
.
requestManager
=
requestManager
;
}
public
<
R
>
GenericRequestBuilder
<
A
,
T
,
Z
,
R
>
transcode
(
ResourceTranscoder
<
Z
,
R
>
transcoder
,
Class
<
R
>
transcodeClass
)
{
return
new
GenericRequestBuilder
<
A
,
T
,
Z
,
R
>(
context
,
model
,
build
(
glide
,
modelLoader
,
dataClass
,
resourceClass
,
transcoder
),
transcodeClass
,
glide
);
resourceClass
,
transcoder
),
transcodeClass
,
glide
,
requestManager
);
}
private
static
<
A
,
T
,
Z
,
R
>
LoadProvider
<
A
,
T
,
Z
,
R
>
build
(
Glide
glide
,
ModelLoader
<
A
,
T
>
modelLoader
,
...
...
library/src/main/java/com/bumptech/glide/GifRequestBuilder.java
浏览文件 @
8a6067fb
...
...
@@ -12,6 +12,7 @@ import com.bumptech.glide.load.resource.bitmap.FitCenter;
import
com.bumptech.glide.load.resource.gif.GifData
;
import
com.bumptech.glide.load.resource.gif.GifDataTransformation
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.manager.RequestManager
;
import
com.bumptech.glide.provider.LoadProvider
;
import
com.bumptech.glide.request.RequestListener
;
...
...
@@ -23,8 +24,8 @@ public class GifRequestBuilder<ModelType, TranscodeType>
GifRequestBuilder
(
Context
context
,
ModelType
model
,
LoadProvider
<
ModelType
,
InputStream
,
GifData
,
TranscodeType
>
loadProvider
,
Class
<
TranscodeType
>
transcodeClass
,
Glide
glide
)
{
super
(
context
,
model
,
loadProvider
,
transcodeClass
,
glide
);
Class
<
TranscodeType
>
transcodeClass
,
Glide
glide
,
RequestManager
requestManager
)
{
super
(
context
,
model
,
loadProvider
,
transcodeClass
,
glide
,
requestManager
);
this
.
glide
=
glide
;
}
...
...
library/src/main/java/com/bumptech/glide/GifTypeRequest.java
浏览文件 @
8a6067fb
...
...
@@ -6,6 +6,7 @@ import com.bumptech.glide.load.resource.gif.GifData;
import
com.bumptech.glide.load.resource.gif.GifDrawable
;
import
com.bumptech.glide.load.resource.transcode.GifDataBytesTranscoder
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.manager.RequestManager
;
import
com.bumptech.glide.provider.FixedLoadProvider
;
import
java.io.InputStream
;
...
...
@@ -15,6 +16,7 @@ public class GifTypeRequest<A> extends GifRequestBuilder<A, GifDrawable> {
private
final
A
model
;
private
final
ModelLoader
<
A
,
InputStream
>
streamModelLoader
;
private
final
Glide
glide
;
private
RequestManager
requestManager
;
private
static
<
A
,
R
>
FixedLoadProvider
<
A
,
InputStream
,
GifData
,
R
>
buildProvider
(
Glide
glide
,
ModelLoader
<
A
,
InputStream
>
streamModelLoader
,
Class
<
R
>
transcodeClass
,
...
...
@@ -28,18 +30,21 @@ public class GifTypeRequest<A> extends GifRequestBuilder<A, GifDrawable> {
}
GifTypeRequest
(
Context
context
,
A
model
,
ModelLoader
<
A
,
InputStream
>
streamModelLoader
,
Glide
glide
){
GifTypeRequest
(
Context
context
,
A
model
,
ModelLoader
<
A
,
InputStream
>
streamModelLoader
,
Glide
glide
,
RequestManager
requestManager
){
super
(
context
,
model
,
buildProvider
(
glide
,
streamModelLoader
,
GifDrawable
.
class
,
null
),
GifDrawable
.
class
,
glide
);
glide
,
requestManager
);
this
.
context
=
context
;
this
.
model
=
model
;
this
.
streamModelLoader
=
streamModelLoader
;
this
.
glide
=
glide
;
this
.
requestManager
=
requestManager
;
}
public
<
R
>
GifRequestBuilder
<
A
,
R
>
transcode
(
ResourceTranscoder
<
GifData
,
R
>
transcoder
,
Class
<
R
>
transcodeClass
)
{
return
new
GifRequestBuilder
<
A
,
R
>(
context
,
model
,
buildProvider
(
glide
,
streamModelLoader
,
transcodeClass
,
transcoder
),
transcodeClass
,
glide
);
buildProvider
(
glide
,
streamModelLoader
,
transcodeClass
,
transcoder
),
transcodeClass
,
glide
,
requestManager
);
}
/**
...
...
library/src/main/java/com/bumptech/glide/Glide.java
浏览文件 @
8a6067fb
package
com.bumptech.glide
;
import
android.app.Activity
;
import
android.content.ComponentCallbacks2
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
...
...
@@ -7,6 +8,8 @@ import android.graphics.drawable.BitmapDrawable;
import
android.graphics.drawable.Drawable
;
import
android.net.Uri
;
import
android.os.ParcelFileDescriptor
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentActivity
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.ImageView
;
...
...
@@ -44,6 +47,9 @@ import com.bumptech.glide.load.resource.transcode.GifBitmapWrapperDrawableTransc
import
com.bumptech.glide.load.resource.transcode.GifDataDrawableTranscoder
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.load.resource.transcode.TranscoderFactory
;
import
com.bumptech.glide.manager.NullRequestManager
;
import
com.bumptech.glide.manager.RequestManager
;
import
com.bumptech.glide.manager.RequestManagerRetriever
;
import
com.bumptech.glide.provider.DataLoadProviderFactory
;
import
com.bumptech.glide.request.Request
;
import
com.bumptech.glide.request.target.ImageViewTargetFactory
;
...
...
@@ -79,6 +85,7 @@ public class Glide {
private
final
ImageViewTargetFactory
imageViewTargetFactory
=
new
ImageViewTargetFactory
();
private
final
TranscoderFactory
transcoderFactory
=
new
TranscoderFactory
();
private
final
DataLoadProviderFactory
dataLoadProviderFactory
;
private
final
NullRequestManager
requestManager
=
new
NullRequestManager
();
/**
* Try to get the external cache directory if available and default to the internal. Use a default name for the
...
...
@@ -438,7 +445,29 @@ public class Glide {
* @return A model request to pass in the object representing the image to be loaded.
*/
public
static
ModelRequest
with
(
Context
context
)
{
return
new
ModelRequest
(
context
,
Glide
.
get
(
context
));
return
new
ModelRequest
(
context
,
Glide
.
get
(
context
),
Glide
.
get
(
context
).
requestManager
);
}
public
static
ModelRequest
with
(
Activity
activity
)
{
RequestManager
requestManager
=
RequestManagerRetriever
.
get
(
activity
);
return
new
ModelRequest
(
activity
,
Glide
.
get
(
activity
),
requestManager
);
}
public
static
ModelRequest
with
(
FragmentActivity
activity
)
{
RequestManager
requestManager
=
RequestManagerRetriever
.
get
(
activity
);
return
new
ModelRequest
(
activity
,
Glide
.
get
(
activity
),
requestManager
);
}
public
static
ModelRequest
with
(
android
.
app
.
Fragment
fragment
)
{
RequestManager
requestManager
=
RequestManagerRetriever
.
get
(
fragment
);
Context
context
=
fragment
.
getActivity
();
return
new
ModelRequest
(
context
,
Glide
.
get
(
context
),
requestManager
);
}
public
static
ModelRequest
with
(
Fragment
fragment
)
{
RequestManager
requestManager
=
RequestManagerRetriever
.
get
(
fragment
);
Context
context
=
fragment
.
getActivity
();
return
new
ModelRequest
(
context
,
Glide
.
get
(
context
),
requestManager
);
}
private
static
class
ClearTarget
extends
ViewTarget
<
View
,
Object
>
{
...
...
library/src/main/java/com/bumptech/glide/ModelRequest.java
浏览文件 @
8a6067fb
...
...
@@ -12,6 +12,7 @@ import com.bumptech.glide.load.model.stream.StreamModelLoader;
import
com.bumptech.glide.load.model.stream.StreamResourceLoader
;
import
com.bumptech.glide.load.model.stream.StreamStringLoader
;
import
com.bumptech.glide.load.model.stream.StreamUriLoader
;
import
com.bumptech.glide.manager.RequestManager
;
import
com.bumptech.glide.volley.VolleyUrlLoader
;
import
java.io.File
;
...
...
@@ -25,14 +26,16 @@ import java.util.UUID;
public
class
ModelRequest
{
private
final
Context
context
;
private
Glide
glide
;
private
RequestManager
requestManager
;
ModelRequest
(
Context
context
,
Glide
glide
)
{
ModelRequest
(
Context
context
,
Glide
glide
,
RequestManager
requestManager
)
{
this
.
context
=
context
;
this
.
glide
=
glide
;
this
.
requestManager
=
requestManager
;
}
public
<
A
,
T
>
GenericModelRequest
<
A
,
T
>
using
(
ModelLoader
<
A
,
T
>
modelLoader
,
Class
<
T
>
dataClass
)
{
return
new
GenericModelRequest
<
A
,
T
>(
context
,
glide
,
modelLoader
,
dataClass
);
return
new
GenericModelRequest
<
A
,
T
>(
context
,
glide
,
modelLoader
,
dataClass
,
requestManager
);
}
public
static
class
GenericModelRequest
<
A
,
T
>
{
...
...
@@ -40,16 +43,19 @@ public class ModelRequest {
private
final
Glide
glide
;
private
final
ModelLoader
<
A
,
T
>
modelLoader
;
private
final
Class
<
T
>
dataClass
;
private
RequestManager
requestManager
;
private
GenericModelRequest
(
Context
context
,
Glide
glide
,
ModelLoader
<
A
,
T
>
modelLoader
,
Class
<
T
>
dataClass
)
{
private
GenericModelRequest
(
Context
context
,
Glide
glide
,
ModelLoader
<
A
,
T
>
modelLoader
,
Class
<
T
>
dataClass
,
RequestManager
requestManager
)
{
this
.
context
=
context
;
this
.
glide
=
glide
;
this
.
modelLoader
=
modelLoader
;
this
.
dataClass
=
dataClass
;
this
.
requestManager
=
requestManager
;
}
public
GenericTypeRequest
<
A
,
T
>
load
(
A
model
)
{
return
new
GenericTypeRequest
<
A
,
T
>(
context
,
glide
,
model
,
modelLoader
,
dataClass
);
return
new
GenericTypeRequest
<
A
,
T
>(
context
,
glide
,
model
,
modelLoader
,
dataClass
,
requestManager
);
}
public
static
class
GenericTypeRequest
<
A
,
T
>
{
...
...
@@ -58,19 +64,21 @@ public class ModelRequest {
private
final
A
model
;
private
final
ModelLoader
<
A
,
T
>
modelLoader
;
private
final
Class
<
T
>
dataClass
;
private
RequestManager
requestManager
;
private
GenericTypeRequest
(
Context
context
,
Glide
glide
,
A
model
,
ModelLoader
<
A
,
T
>
modelLoader
,
Class
<
T
>
dataClass
)
{
Class
<
T
>
dataClass
,
RequestManager
requestManager
)
{
this
.
context
=
context
;
this
.
glide
=
glide
;
this
.
model
=
model
;
this
.
modelLoader
=
modelLoader
;
this
.
dataClass
=
dataClass
;
this
.
requestManager
=
requestManager
;
}
public
<
Z
>
GenericTranscodeRequest
<
A
,
T
,
Z
>
as
(
Class
<
Z
>
resourceClass
)
{
return
new
GenericTranscodeRequest
<
A
,
T
,
Z
>(
context
,
glide
,
model
,
modelLoader
,
dataClass
,
resourceClass
);
resourceClass
,
requestManager
);
}
}
}
...
...
@@ -84,7 +92,7 @@ public class ModelRequest {
* @return A new {@link ImageModelRequest}.
*/
public
<
T
>
ImageModelRequest
<
T
>
using
(
final
StreamModelLoader
<
T
>
modelLoader
)
{
return
new
ImageModelRequest
<
T
>(
context
,
modelLoader
,
glide
);
return
new
ImageModelRequest
<
T
>(
context
,
modelLoader
,
glide
,
requestManager
);
}
/**
...
...
@@ -94,7 +102,7 @@ public class ModelRequest {
* @return A new {@link ImageModelRequest}.
*/
public
ImageModelRequest
<
byte
[]>
using
(
StreamByteArrayLoader
modelLoader
)
{
return
new
ImageModelRequest
<
byte
[]>(
context
,
modelLoader
,
glide
);
return
new
ImageModelRequest
<
byte
[]>(
context
,
modelLoader
,
glide
,
requestManager
);
}
/**
...
...
@@ -106,7 +114,7 @@ public class ModelRequest {
* @return A new {@link VideoModelRequest}.
*/
public
<
T
>
VideoModelRequest
<
T
>
using
(
final
FileDescriptorModelLoader
<
T
>
modelLoader
)
{
return
new
VideoModelRequest
<
T
>(
context
,
modelLoader
,
glide
);
return
new
VideoModelRequest
<
T
>(
context
,
modelLoader
,
glide
,
requestManager
);
}
/**
...
...
@@ -216,7 +224,7 @@ public class ModelRequest {
return
id
;
}
};
return
new
DrawableTypeRequest
<
byte
[]>(
model
,
loader
,
null
,
context
,
glide
);
return
new
DrawableTypeRequest
<
byte
[]>(
model
,
loader
,
null
,
context
,
glide
,
requestManager
);
}
/**
...
...
@@ -263,7 +271,8 @@ public class ModelRequest {
ModelLoader
<
T
,
InputStream
>
streamModelLoader
=
Glide
.
buildStreamModelLoader
(
model
,
context
);
ModelLoader
<
T
,
ParcelFileDescriptor
>
fileDescriptorModelLoader
=
Glide
.
buildFileDescriptorModelLoader
(
model
,
context
);
return
new
DrawableTypeRequest
<
T
>(
model
,
streamModelLoader
,
fileDescriptorModelLoader
,
context
,
glide
);
return
new
DrawableTypeRequest
<
T
>(
model
,
streamModelLoader
,
fileDescriptorModelLoader
,
context
,
glide
,
requestManager
);
}
/**
...
...
@@ -276,15 +285,18 @@ public class ModelRequest {
private
final
Context
context
;
private
final
ModelLoader
<
T
,
ParcelFileDescriptor
>
loader
;
private
Glide
glide
;
private
RequestManager
requestManager
;
private
VideoModelRequest
(
Context
context
,
ModelLoader
<
T
,
ParcelFileDescriptor
>
loader
,
Glide
glide
)
{
private
VideoModelRequest
(
Context
context
,
ModelLoader
<
T
,
ParcelFileDescriptor
>
loader
,
Glide
glide
,
RequestManager
requestManager
)
{
this
.
context
=
context
;
this
.
loader
=
loader
;
this
.
glide
=
glide
;
this
.
requestManager
=
requestManager
;
}
public
Drawable
TypeRequest
<
T
>
loadFromVideo
(
T
model
)
{
return
new
DrawableTypeRequest
<
T
>(
model
,
null
,
loader
,
context
,
glide
);
public
Bitmap
TypeRequest
<
T
>
loadFromVideo
(
T
model
)
{
return
new
BitmapTypeRequest
<
T
>(
context
,
model
,
null
,
loader
,
glide
,
requestManager
);
}
}
...
...
@@ -298,15 +310,18 @@ public class ModelRequest {
private
final
Context
context
;
private
final
ModelLoader
<
T
,
InputStream
>
loader
;
private
Glide
glide
;
private
RequestManager
requestManager
;
private
ImageModelRequest
(
Context
context
,
ModelLoader
<
T
,
InputStream
>
loader
,
Glide
glide
)
{
private
ImageModelRequest
(
Context
context
,
ModelLoader
<
T
,
InputStream
>
loader
,
Glide
glide
,
RequestManager
requestManager
)
{
this
.
context
=
context
;
this
.
loader
=
loader
;
this
.
glide
=
glide
;
this
.
requestManager
=
requestManager
;
}
public
DrawableTypeRequest
<
T
>
load
(
T
model
)
{
return
new
DrawableTypeRequest
<
T
>(
model
,
loader
,
null
,
context
,
glide
);
return
new
DrawableTypeRequest
<
T
>(
model
,
loader
,
null
,
context
,
glide
,
requestManager
);
}
}
}
library/src/main/java/com/bumptech/glide/manager/LifecycleRequestManager.java
0 → 100644
浏览文件 @
8a6067fb
package
com.bumptech.glide.manager
;
import
com.bumptech.glide.request.Request
;
import
java.util.HashSet
;
import
java.util.Set
;
public
class
LifecycleRequestManager
implements
RequestManager
{
private
final
Set
<
Request
>
requests
=
new
HashSet
<
Request
>();
@Override
public
void
addRequest
(
Request
request
)
{
requests
.
add
(
request
);
}
@Override
public
void
removeRequest
(
Request
request
)
{
requests
.
remove
(
request
);
}
public
void
onStart
()
{
for
(
Request
request
:
requests
)
{
if
(!
request
.
isComplete
()
&&
!
request
.
isRunning
())
{
request
.
run
();
}
}
}
public
void
onStop
()
{
for
(
Request
request
:
requests
)
{
if
(!
request
.
isComplete
()
&&
!
request
.
isFailed
())
{
request
.
clear
();
}
}
}
public
void
onDestroy
()
{
for
(
Request
request
:
requests
)
{
request
.
clear
();
}
}
}
library/src/main/java/com/bumptech/glide/manager/NullRequestManager.java
0 → 100644
浏览文件 @
8a6067fb
package
com.bumptech.glide.manager
;
import
com.bumptech.glide.request.Request
;
public
class
NullRequestManager
implements
RequestManager
{
@Override
public
void
addRequest
(
Request
request
)
{
}
@Override
public
void
removeRequest
(
Request
request
)
{
}
}
library/src/main/java/com/bumptech/glide/manager/RequestManager.java
0 → 100644
浏览文件 @
8a6067fb
package
com.bumptech.glide.manager
;
import
com.bumptech.glide.request.Request
;
public
interface
RequestManager
{
public
void
addRequest
(
Request
request
);
public
void
removeRequest
(
Request
request
);
}
library/src/main/java/com/bumptech/glide/manager/RequestManagerFragment.java
0 → 100644
浏览文件 @
8a6067fb
package
com.bumptech.glide.manager
;
import
android.app.Fragment
;
public
class
RequestManagerFragment
extends
Fragment
{
private
LifecycleRequestManager
requestManager
;
public
void
setRequestManager
(
LifecycleRequestManager
requestManager
)
{
this
.
requestManager
=
requestManager
;
}
public
LifecycleRequestManager
getRequestManager
()
{
return
requestManager
;
}
@Override
public
void
onStart
()
{
super
.
onStart
();
if
(
requestManager
!=
null
)
{
requestManager
.
onStart
();
}
}
@Override
public
void
onStop
()
{
super
.
onStop
();
if
(
requestManager
!=
null
)
{
requestManager
.
onStop
();
}
}
@Override
public
void
onDestroy
()
{
super
.
onDestroy
();
if
(
requestManager
!=
null
)
{
requestManager
.
onDestroy
();
}
}
}
library/src/main/java/com/bumptech/glide/manager/RequestManagerLifecycleFragment.java
0 → 100644
浏览文件 @
8a6067fb
package
com.bumptech.glide.manager
;
public
interface
RequestManagerLifecycleFragment
{
public
void
setRequestManager
(
LifecycleRequestManager
requestManager
);
public
LifecycleRequestManager
getRequestManager
();
public
void
onStart
();
public
void
onStop
();
public
void
onDestroy
();
}
library/src/main/java/com/bumptech/glide/manager/RequestManagerRetriever.java
0 → 100644
浏览文件 @
8a6067fb
package
com.bumptech.glide.manager
;
import
android.app.Activity
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentActivity
;
import
android.support.v4.app.FragmentManager
;
public
class
RequestManagerRetriever
{
static
final
String
TAG
=
"com.bumptech.glide.manager"
;
public
static
RequestManager
get
(
FragmentActivity
activity
)
{
if
(
activity
.
isDestroyed
())
{
throw
new
IllegalArgumentException
(
"You cannot start a load for a destroyed activity"
);
}
FragmentManager
fm
=
activity
.
getSupportFragmentManager
();
return
supportFragmentGet
(
fm
);
}
public
static
RequestManager
get
(
Fragment
fragment
)
{
if
(
fragment
.
getActivity
()
==
null
)
{
throw
new
IllegalArgumentException
(
"You cannot start a load on a fragment before it is attached"
);
}
if
(
fragment
.
isDetached
())
{
throw
new
IllegalArgumentException
(
"You cannot start a load on a detached fragment"
);
}
FragmentManager
fm
=
fragment
.
getChildFragmentManager
();
return
supportFragmentGet
(
fm
);
}
public
static
RequestManager
get
(
Activity
activity
)
{
if
(
activity
.
isDestroyed
())
{
throw
new
IllegalArgumentException
(
"You cannot start a load for a destroyed activity"
);
}
android
.
app
.
FragmentManager
fm
=
activity
.
getFragmentManager
();
return
fragmentGet
(
fm
);
}
public
static
RequestManager
get
(
android
.
app
.
Fragment
fragment
)
{
if
(
fragment
.
getActivity
()
==
null
)
{
throw
new
IllegalArgumentException
(
"You cannot start a load on a fragment before it is attached"
);
}
if
(
fragment
.
isDetached
())
{
throw
new
IllegalArgumentException
(
"You cannot start a load on a detached fragment"
);
}
android
.
app
.
FragmentManager
fm
=
fragment
.
getChildFragmentManager
();
return
fragmentGet
(
fm
);
}
static
RequestManager
fragmentGet
(
android
.
app
.
FragmentManager
fm
)
{
RequestManagerFragment
current
=
(
RequestManagerFragment
)
fm
.
findFragmentByTag
(
TAG
);
if
(
current
==
null
)
{
current
=
new
RequestManagerFragment
();
fm
.
beginTransaction
().
add
(
current
,
TAG
).
commitAllowingStateLoss
();
// Normally fragment transactions are posted to the main thread. Since we may start multiple requests within
// a single synchronous call, we need to make sure that we only add a single fragment for the first call. To
// do so, we use executePendingTransactions to skip the post and synchronously add the new fragment so that
// the next synchronous request will retrieve it rather than creating a new one.
fm
.
executePendingTransactions
();
}
LifecycleRequestManager
requestManager
=
current
.
getRequestManager
();
if
(
requestManager
==
null
)
{
requestManager
=
new
LifecycleRequestManager
();
current
.
setRequestManager
(
requestManager
);
}
return
requestManager
;
}
static
RequestManager
supportFragmentGet
(
FragmentManager
fm
)
{
SupportRequestManagerFragment
current
=
(
SupportRequestManagerFragment
)
fm
.
findFragmentByTag
(
TAG
);
if
(
current
==
null
)
{
current
=
new
SupportRequestManagerFragment
();
fm
.
beginTransaction
().
add
(
current
,
TAG
).
commitAllowingStateLoss
();
// Normally fragment transactions are posted to the main thread. Since we may start multiple requests within
// a single synchronous call, we need to make sure that we only add a single fragment for the first call. To
// do so, we use executePendingTransactions to skip the post and synchronously add the new fragment so that
// the next synchronous request will retrieve it rather than creating a new one.
fm
.
executePendingTransactions
();
}
LifecycleRequestManager
requestManager
=
current
.
getRequestManager
();
if
(
requestManager
==
null
)
{
requestManager
=
new
LifecycleRequestManager
();
current
.
setRequestManager
(
requestManager
);
}
return
requestManager
;
}
}
library/src/main/java/com/bumptech/glide/manager/SupportRequestManagerFragment.java
0 → 100644
浏览文件 @
8a6067fb
package
com.bumptech.glide.manager
;
import
android.support.v4.app.Fragment
;
public
class
SupportRequestManagerFragment
extends
Fragment
{
private
LifecycleRequestManager
requestManager
;
public
void
setRequestManager
(
LifecycleRequestManager
requestManager
)
{
this
.
requestManager
=
requestManager
;
}
public
LifecycleRequestManager
getRequestManager
()
{
return
requestManager
;
}
@Override
public
void
onStart
()
{
super
.
onStart
();
if
(
requestManager
!=
null
)
{
requestManager
.
onStart
();
}
}
@Override
public
void
onStop
()
{
super
.
onStop
();
if
(
requestManager
!=
null
)
{
requestManager
.
onStop
();
}
}
@Override
public
void
onDestroy
()
{
super
.
onDestroy
();
if
(
requestManager
!=
null
)
{
requestManager
.
onDestroy
();
}
}
}
library/src/main/java/com/bumptech/glide/request/GenericRequest.java
浏览文件 @
8a6067fb
...
...
@@ -52,6 +52,7 @@ public class GenericRequest<A, T, Z, R> implements Request, Target.SizeReadyCall
private
boolean
loadedFromMemoryCache
;
private
Resource
resource
;
private
Engine
.
LoadStatus
loadStatus
;
private
boolean
isRunning
;
public
GenericRequest
(
LoadProvider
<
A
,
T
,
Z
,
R
>
loadProvider
,
A
model
,
Context
context
,
Priority
priority
,
Target
<
R
>
target
,
float
sizeMultiplier
,
Drawable
placeholderDrawable
,
int
placeholderResourceId
,
...
...
@@ -110,10 +111,12 @@ public class GenericRequest<A, T, Z, R> implements Request, Target.SizeReadyCall
if
(!
isComplete
()
&&
!
isFailed
())
{
setPlaceHolder
();
isRunning
=
true
;
}
}
public
void
cancel
()
{
isRunning
=
false
;
isCancelled
=
true
;
if
(
loadStatus
!=
null
)
{
loadStatus
.
cancel
();
...
...
@@ -131,6 +134,11 @@ public class GenericRequest<A, T, Z, R> implements Request, Target.SizeReadyCall
}
}
@Override
public
boolean
isRunning
()
{
return
isRunning
;
}
@Override
public
boolean
isComplete
()
{
return
resource
!=
null
;
...
...
@@ -200,6 +208,7 @@ public class GenericRequest<A, T, Z, R> implements Request, Target.SizeReadyCall
@Override
public
void
onResourceReady
(
Resource
resource
)
{
isRunning
=
false
;
if
(!
canSetImage
())
{
resource
.
release
();
return
;
...
...
@@ -231,10 +240,11 @@ public class GenericRequest<A, T, Z, R> implements Request, Target.SizeReadyCall
@Override
public
void
onException
(
Exception
e
)
{
//
if (Log.isLoggable(TAG, Log.DEBUG)) {
if
(
Log
.
isLoggable
(
TAG
,
Log
.
DEBUG
))
{
Log
.
d
(
TAG
,
"load failed"
,
e
);
//
}
}
isRunning
=
false
;
isError
=
true
;
setErrorPlaceholder
();
...
...
library/src/main/java/com/bumptech/glide/request/Request.java
浏览文件 @
8a6067fb
...
...
@@ -18,6 +18,11 @@ public interface Request {
*/
public
void
clear
();
/**
* Returns true if this request is running and has not completed or failed.
*/
public
boolean
isRunning
();
/**
* Returns true if the request has successfully completed.
*/
...
...
library/src/main/java/com/bumptech/glide/request/ThumbnailRequestCoordinator.java
浏览文件 @
8a6067fb
...
...
@@ -30,8 +30,10 @@ public class ThumbnailRequestCoordinator implements RequestCoordinator, Request
@Override
public
void
run
()
{
if
(!
full
.
isRunning
())
{
full
.
run
();
if
(!
full
.
isComplete
())
{
}
if
(!
full
.
isComplete
()
&&
!
thumb
.
isRunning
())
{
thumb
.
run
();
}
}
...
...
@@ -42,6 +44,11 @@ public class ThumbnailRequestCoordinator implements RequestCoordinator, Request
thumb
.
clear
();
}
@Override
public
boolean
isRunning
()
{
return
full
.
isRunning
();
}
@Override
public
boolean
isComplete
()
{
return
full
.
isComplete
();
...
...
library/src/test/java/com/bumptech/glide/GenericRequestBuilderTest.java
浏览文件 @
8a6067fb
...
...
@@ -2,33 +2,48 @@ package com.bumptech.glide;
import
com.bumptech.glide.load.ResourceDecoder
;
import
com.bumptech.glide.load.ResourceEncoder
;
import
com.bumptech.glide.manager.RequestManager
;
import
com.bumptech.glide.provider.LoadProvider
;
import
com.bumptech.glide.request.Request
;
import
com.bumptech.glide.request.target.Target
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.Robolectric
;
import
org.robolectric.RobolectricTestRunner
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@SuppressWarnings
(
"unchecked"
)
@RunWith
(
RobolectricTestRunner
.
class
)
public
class
GenericRequestBuilderTest
{
private
RequestManager
requestManager
;
@Before
public
void
setUp
()
{
requestManager
=
mock
(
RequestManager
.
class
);
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testThrowsIfContextIsNull
()
{
new
GenericRequestBuilder
(
null
,
new
Object
(),
mock
(
LoadProvider
.
class
),
Object
.
class
,
mock
(
Glide
.
class
));
new
Object
(),
mock
(
LoadProvider
.
class
),
Object
.
class
,
mock
(
Glide
.
class
)
,
requestManager
);
}
@Test
(
expected
=
NullPointerException
.
class
)
public
void
testThrowsIfNonNullModelAndNullLoadProvider
()
{
new
GenericRequestBuilder
(
Robolectric
.
application
,
new
Object
(),
null
,
Object
.
class
,
mock
(
Glide
.
class
));
new
GenericRequestBuilder
(
Robolectric
.
application
,
new
Object
(),
null
,
Object
.
class
,
mock
(
Glide
.
class
),
requestManager
);
}
@Test
public
void
testDoesNotThrowWhenModelAndLoaderNull
()
{
new
GenericRequestBuilder
(
Robolectric
.
application
,
null
,
null
,
Object
.
class
,
mock
(
Glide
.
class
));
new
GenericRequestBuilder
(
Robolectric
.
application
,
null
,
null
,
Object
.
class
,
mock
(
Glide
.
class
),
requestManager
);
}
@Test
...
...
@@ -56,7 +71,25 @@ public class GenericRequestBuilderTest {
getNullModelRequest
().
into
(
mock
(
Target
.
class
));
}
@Test
public
void
testAddsNewRequestToRequestManager
()
{
getNullModelRequest
().
into
(
mock
(
Target
.
class
));
verify
(
requestManager
).
addRequest
(
any
(
Request
.
class
));
}
@Test
public
void
testRemovesPreviousRequestFromRequestManager
()
{
Request
previous
=
mock
(
Request
.
class
);
Target
target
=
mock
(
Target
.
class
);
when
(
target
.
getRequest
()).
thenReturn
(
previous
);
getNullModelRequest
().
into
(
target
);
verify
(
requestManager
).
removeRequest
(
eq
(
previous
));
}
private
GenericRequestBuilder
getNullModelRequest
()
{
return
new
GenericRequestBuilder
(
Robolectric
.
application
,
null
,
null
,
Object
.
class
,
mock
(
Glide
.
class
));
return
new
GenericRequestBuilder
(
Robolectric
.
application
,
null
,
null
,
Object
.
class
,
mock
(
Glide
.
class
),
requestManager
);
}
}
library/src/test/java/com/bumptech/glide/manager/LifecycleRequestManagerTest.java
0 → 100644
浏览文件 @
8a6067fb
package
com.bumptech.glide.manager
;
import
com.bumptech.glide.request.Request
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
class
LifecycleRequestManagerTest
{
private
LifecycleRequestManager
manager
;
@Before
public
void
setUp
()
{
manager
=
new
LifecycleRequestManager
();
}
@Test
public
void
testCancelsRequestsOnStop
()
{
Request
request
=
mock
(
Request
.
class
);
manager
.
addRequest
(
request
);
manager
.
onStop
();
verify
(
request
).
clear
();
}
@Test
public
void
testCanAddAndRemoveRequest
()
{
Request
request
=
mock
(
Request
.
class
);
manager
.
addRequest
(
request
);
manager
.
removeRequest
(
request
);
manager
.
onStop
();
verify
(
request
,
never
()).
clear
();
}
@Test
public
void
testCanAddMultipleRequests
()
{
Request
first
=
mock
(
Request
.
class
);
Request
second
=
mock
(
Request
.
class
);
manager
.
addRequest
(
first
);
manager
.
addRequest
(
second
);
manager
.
onStop
();
verify
(
first
).
clear
();
verify
(
second
).
clear
();
}
@Test
public
void
testDoesNotClearCompleteRequestsOnStop
()
{
Request
request
=
mock
(
Request
.
class
);
when
(
request
.
isComplete
()).
thenReturn
(
true
);
manager
.
addRequest
(
request
);
manager
.
onStop
();
verify
(
request
,
never
()).
clear
();
}
@Test
public
void
testDoesNotClearFailedRequestsOnStop
()
{
Request
request
=
mock
(
Request
.
class
);
when
(
request
.
isFailed
()).
thenReturn
(
true
);
manager
.
addRequest
(
request
);
manager
.
onStop
();
verify
(
request
,
never
()).
clear
();
}
@Test
public
void
testRestartsStoppedRequestOnStart
()
{
Request
request
=
mock
(
Request
.
class
);
manager
.
addRequest
(
request
);
manager
.
onStart
();
verify
(
request
).
run
();
}
@Test
public
void
testDoesNotRestartCompletedRequestsOnStart
()
{
Request
request
=
mock
(
Request
.
class
);
when
(
request
.
isComplete
()).
thenReturn
(
true
);
manager
.
addRequest
(
request
);
manager
.
onStart
();
verify
(
request
,
never
()).
run
();
}
@Test
public
void
testDoesRestartFailedRequestsOnStart
()
{
Request
request
=
mock
(
Request
.
class
);
when
(
request
.
isFailed
()).
thenReturn
(
true
);
manager
.
addRequest
(
request
);
manager
.
onStart
();
verify
(
request
).
run
();
}
@Test
public
void
testDoesNotStartStartedRequestsOnStart
()
{
Request
request
=
mock
(
Request
.
class
);
when
(
request
.
isRunning
()).
thenReturn
(
true
);
manager
.
addRequest
(
request
);
manager
.
onStart
();
verify
(
request
,
never
()).
run
();
}
@Test
public
void
testClearsAllRequestsOnDestroy
()
{
Request
first
=
mock
(
Request
.
class
);
Request
second
=
mock
(
Request
.
class
);
when
(
second
.
isComplete
()).
thenReturn
(
true
);
Request
third
=
mock
(
Request
.
class
);
when
(
third
.
isFailed
()).
thenReturn
(
true
);
manager
.
addRequest
(
first
);
manager
.
addRequest
(
second
);
manager
.
addRequest
(
third
);
manager
.
onDestroy
();
verify
(
first
).
clear
();
verify
(
second
).
clear
();
verify
(
third
).
clear
();
}
}
library/src/test/java/com/bumptech/glide/manager/RequestManagerFragmentTest.java
0 → 100644
浏览文件 @
8a6067fb
package
com.bumptech.glide.manager
;
import
android.app.Activity
;
import
android.support.v4.app.FragmentActivity
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.Robolectric
;
import
org.robolectric.RobolectricTestRunner
;
import
org.robolectric.annotation.Config
;
import
org.robolectric.util.ActivityController
;
import
static
junit
.
framework
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
@RunWith
(
RobolectricTestRunner
.
class
)
@Config
(
manifest
=
Config
.
NONE
)
public
class
RequestManagerFragmentTest
{
private
static
final
String
TAG
=
"tag"
;
private
Harness
[]
harnesses
;
@Before
public
void
setUp
()
{
harnesses
=
new
Harness
[]
{
new
RequestManagerHarness
(),
new
SupportRequestManagerHarness
()
};
}
@Test
public
void
testSupportCanSetAndGetRequestManager
()
{
for
(
Harness
harness
:
harnesses
)
{
LifecycleRequestManager
manager
=
mock
(
LifecycleRequestManager
.
class
);
harness
.
setRequestManager
(
manager
);
assertEquals
(
manager
,
harness
.
getManager
());
}
}
@Test
public
void
testCallsRequestManagerStart
()
{
for
(
Harness
harness
:
harnesses
)
{
harness
.
getController
().
start
();
verify
(
harness
.
getManager
()).
onStart
();
}
}
@Test
public
void
testIgnoresNullRequestManagerOnStart
()
{
for
(
Harness
harness
:
harnesses
)
{
harness
.
setRequestManager
(
null
);
harness
.
getController
().
start
();
}
}
@Test
public
void
testCallsRequestManagerStop
()
{
for
(
Harness
harness
:
harnesses
)
{
harness
.
getController
().
start
().
resume
().
pause
().
stop
();
verify
(
harness
.
getManager
()).
onStop
();
}
}
@Test
public
void
testIgnoresNullRequestManagerOnStop
()
{
for
(
Harness
harness
:
harnesses
)
{
harness
.
setRequestManager
(
null
);
harness
.
getController
().
start
().
stop
();
}
}
@Test
public
void
testCallsRequestManagerDestroy
()
{
for
(
Harness
harness
:
harnesses
)
{
harness
.
getController
().
start
().
resume
().
pause
().
stop
().
destroy
();
verify
(
harness
.
getManager
()).
onDestroy
();
}
}
@Test
public
void
testIgnoresNullRequestManagerOnDestroy
()
{
for
(
Harness
harness
:
harnesses
)
{
harness
.
setRequestManager
(
null
);
harness
.
getController
().
start
().
resume
().
pause
().
stop
().
destroy
();
}
}
private
interface
Harness
{
public
LifecycleRequestManager
getManager
();
public
void
setRequestManager
(
LifecycleRequestManager
manager
);
public
ActivityController
getController
();
}
private
static
class
RequestManagerHarness
implements
Harness
{
private
final
ActivityController
<
Activity
>
controller
;
private
final
RequestManagerFragment
fragment
;
private
final
LifecycleRequestManager
manager
;
public
RequestManagerHarness
()
{
fragment
=
new
RequestManagerFragment
();
controller
=
Robolectric
.
buildActivity
(
Activity
.
class
).
create
();
controller
.
get
()
.
getFragmentManager
()
.
beginTransaction
()
.
add
(
fragment
,
TAG
)
.
commit
();
controller
.
get
().
getFragmentManager
().
executePendingTransactions
();
this
.
manager
=
mock
(
LifecycleRequestManager
.
class
);
fragment
.
setRequestManager
(
manager
);
}
@Override
public
LifecycleRequestManager
getManager
()
{
return
fragment
.
getRequestManager
();
}
@Override
public
void
setRequestManager
(
LifecycleRequestManager
requestManager
)
{
fragment
.
setRequestManager
(
requestManager
);
}
@Override
public
ActivityController
getController
()
{
return
controller
;
}
}
private
static
class
SupportRequestManagerHarness
implements
Harness
{
private
final
SupportRequestManagerFragment
supportFragment
;
private
final
ActivityController
<
FragmentActivity
>
supportController
;
private
final
LifecycleRequestManager
manager
;
public
SupportRequestManagerHarness
()
{
supportFragment
=
new
SupportRequestManagerFragment
();
supportController
=
Robolectric
.
buildActivity
(
FragmentActivity
.
class
).
create
();
supportController
.
get
()
.
getSupportFragmentManager
()
.
beginTransaction
()
.
add
(
supportFragment
,
TAG
)
.
commit
();
supportController
.
get
().
getSupportFragmentManager
().
executePendingTransactions
();
this
.
manager
=
mock
(
LifecycleRequestManager
.
class
);
supportFragment
.
setRequestManager
(
manager
);
}
@Override
public
LifecycleRequestManager
getManager
()
{
return
supportFragment
.
getRequestManager
();
}
@Override
public
void
setRequestManager
(
LifecycleRequestManager
manager
)
{
supportFragment
.
setRequestManager
(
manager
);
}
@Override
public
ActivityController
getController
()
{
return
supportController
;
}
}
}
library/src/test/java/com/bumptech/glide/manager/RequestManagerRetrieverTest.java
0 → 100644
浏览文件 @
8a6067fb
package
com.bumptech.glide.manager
;
import
android.app.Activity
;
import
android.os.Looper
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentActivity
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.Robolectric
;
import
org.robolectric.RobolectricTestRunner
;
import
org.robolectric.annotation.Config
;
import
org.robolectric.shadows.ShadowLooper
;
import
org.robolectric.util.ActivityController
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
mock
;
@RunWith
(
RobolectricTestRunner
.
class
)
@Config
(
manifest
=
Config
.
NONE
)
public
class
RequestManagerRetrieverTest
{
private
static
final
String
PARENT_TAG
=
"parent"
;
private
RetrieverHarness
[]
harnesses
;
@Before
public
void
setUp
()
{
harnesses
=
new
RetrieverHarness
[]
{
new
DefaultRetrieverHarness
(),
new
SupportRetrieverHarness
()
};
// If we don't pause the looper, fragment transactions are executed synchronously which is not how they would
// normally behave.
ShadowLooper
shadowLooper
=
Robolectric
.
shadowOf
(
Looper
.
getMainLooper
());
shadowLooper
.
pause
();
}
@Test
public
void
testCreatesNewFragmentIfNoneExists
()
{
for
(
RetrieverHarness
harness
:
harnesses
)
{
harness
.
doGet
();
assertTrue
(
harness
.
hasFragmentWithTag
(
RequestManagerRetriever
.
TAG
));
}
}
@Test
public
void
testReturnsNewManagerIfNoneExists
()
{
for
(
RetrieverHarness
harness
:
harnesses
)
{
assertNotNull
(
harness
.
doGet
());
}
}
@Test
public
void
testReturnsExistingRequestManagerIfExists
()
{
for
(
RetrieverHarness
harness
:
harnesses
)
{
LifecycleRequestManager
requestManager
=
mock
(
LifecycleRequestManager
.
class
);
harness
.
addFragmentWithTag
(
RequestManagerRetriever
.
TAG
,
requestManager
);
assertEquals
(
requestManager
,
harness
.
doGet
());
}
}
@Test
public
void
testReturnsNewRequestManagerIfFragmentExistsButHasNoRequestManager
()
{
for
(
RetrieverHarness
harness
:
harnesses
)
{
harness
.
addFragmentWithTag
(
RequestManagerRetriever
.
TAG
,
null
);
assertNotNull
(
harness
.
doGet
());
}
}
@Test
public
void
testSavesNewRequestManagerToFragmentIfCreatesRequestManagerForExistingFragment
()
{
for
(
RetrieverHarness
harness
:
harnesses
)
{
harness
.
addFragmentWithTag
(
RequestManagerRetriever
.
TAG
,
null
);
RequestManager
first
=
harness
.
doGet
();
RequestManager
second
=
harness
.
doGet
();
assertEquals
(
first
,
second
);
}
}
@Test
public
void
testHasValidTag
()
{
assertEquals
(
RequestManagerRetriever
.
class
.
getPackage
().
getName
(),
RequestManagerRetriever
.
TAG
);
}
@Test
public
void
testCanGetRequestManagerFromActivity
()
{
Activity
activity
=
Robolectric
.
buildActivity
(
Activity
.
class
).
create
().
start
().
get
();
RequestManager
manager
=
RequestManagerRetriever
.
get
(
activity
);
assertEquals
(
manager
,
RequestManagerRetriever
.
get
(
activity
));
}
@Test
public
void
testSupportCanGetRequestManagerFromActivity
()
{
FragmentActivity
fragmentActivity
=
Robolectric
.
buildActivity
(
FragmentActivity
.
class
).
create
().
start
().
get
();
RequestManager
manager
=
RequestManagerRetriever
.
get
(
fragmentActivity
);
assertEquals
(
manager
,
RequestManagerRetriever
.
get
(
fragmentActivity
));
}
@Test
public
void
testCanGetRequestManagerFromFragment
()
{
Activity
activity
=
Robolectric
.
buildActivity
(
Activity
.
class
).
create
().
start
().
resume
().
get
();
android
.
app
.
Fragment
fragment
=
new
android
.
app
.
Fragment
();
activity
.
getFragmentManager
()
.
beginTransaction
()
.
add
(
fragment
,
PARENT_TAG
)
.
commit
();
activity
.
getFragmentManager
().
executePendingTransactions
();
RequestManager
manager
=
RequestManagerRetriever
.
get
(
fragment
);
assertEquals
(
manager
,
RequestManagerRetriever
.
get
(
fragment
));
}
@Test
public
void
testSupportCanGetRequestManagerFromFragment
()
{
FragmentActivity
activity
=
Robolectric
.
buildActivity
(
FragmentActivity
.
class
).
create
().
start
().
resume
().
get
();
Fragment
fragment
=
new
Fragment
();
activity
.
getSupportFragmentManager
()
.
beginTransaction
()
.
add
(
fragment
,
PARENT_TAG
)
.
commit
();
activity
.
getSupportFragmentManager
().
executePendingTransactions
();
RequestManager
manager
=
RequestManagerRetriever
.
get
(
fragment
);
assertEquals
(
manager
,
RequestManagerRetriever
.
get
(
fragment
));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testThrowsIfFragmentNotAttached
()
{
android
.
app
.
Fragment
fragment
=
new
android
.
app
.
Fragment
();
RequestManagerRetriever
.
get
(
fragment
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testThrowsIfSupportFragmentNotAttached
()
{
Fragment
fragment
=
new
Fragment
();
RequestManagerRetriever
.
get
(
fragment
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testDoesNotThrowIfActivityDestroyed
()
{
DefaultRetrieverHarness
harness
=
new
DefaultRetrieverHarness
();
harness
.
getController
().
pause
().
stop
().
destroy
();
harness
.
doGet
();
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testThrowsIfFragmentActivityDestroyed
()
{
SupportRetrieverHarness
harness
=
new
SupportRetrieverHarness
();
harness
.
getController
().
pause
().
stop
().
destroy
();
harness
.
doGet
();
}
private
interface
RetrieverHarness
{
public
ActivityController
getController
();
public
RequestManager
doGet
();
public
boolean
hasFragmentWithTag
(
String
tag
);
public
void
addFragmentWithTag
(
String
tag
,
LifecycleRequestManager
manager
);
}
public
class
DefaultRetrieverHarness
implements
RetrieverHarness
{
private
final
ActivityController
<
Activity
>
controller
=
Robolectric
.
buildActivity
(
Activity
.
class
);
private
final
android
.
app
.
Fragment
parent
;
public
DefaultRetrieverHarness
()
{
this
.
parent
=
new
android
.
app
.
Fragment
();
controller
.
create
();
controller
.
get
().
getFragmentManager
()
.
beginTransaction
()
.
add
(
parent
,
PARENT_TAG
)
.
commitAllowingStateLoss
();
controller
.
get
().
getFragmentManager
().
executePendingTransactions
();
controller
.
start
().
resume
();
}
@Override
public
ActivityController
getController
()
{
return
controller
;
}
@Override
public
RequestManager
doGet
()
{
return
RequestManagerRetriever
.
get
(
controller
.
get
());
}
@Override
public
boolean
hasFragmentWithTag
(
String
tag
)
{
return
controller
.
get
().
getFragmentManager
().
findFragmentByTag
(
RequestManagerRetriever
.
TAG
)
!=
null
;
}
@Override
public
void
addFragmentWithTag
(
String
tag
,
LifecycleRequestManager
requestManager
)
{
RequestManagerFragment
fragment
=
new
RequestManagerFragment
();
fragment
.
setRequestManager
(
requestManager
);
controller
.
get
().
getFragmentManager
()
.
beginTransaction
()
.
add
(
fragment
,
RequestManagerRetriever
.
TAG
)
.
commitAllowingStateLoss
();
controller
.
get
().
getFragmentManager
().
executePendingTransactions
();
}
}
public
class
SupportRetrieverHarness
implements
RetrieverHarness
{
private
final
ActivityController
<
FragmentActivity
>
controller
=
Robolectric
.
buildActivity
(
FragmentActivity
.
class
);
private
final
Fragment
parent
;
public
SupportRetrieverHarness
()
{
this
.
parent
=
new
Fragment
();
controller
.
create
();
controller
.
get
().
getSupportFragmentManager
()
.
beginTransaction
()
.
add
(
parent
,
PARENT_TAG
)
.
commitAllowingStateLoss
();
controller
.
get
().
getSupportFragmentManager
().
executePendingTransactions
();
controller
.
start
().
resume
();
}
@Override
public
ActivityController
getController
()
{
return
controller
;
}
@Override
public
RequestManager
doGet
()
{
return
RequestManagerRetriever
.
get
(
controller
.
get
());
}
@Override
public
boolean
hasFragmentWithTag
(
String
tag
)
{
return
controller
.
get
().
getSupportFragmentManager
().
findFragmentByTag
(
RequestManagerRetriever
.
TAG
)
!=
null
;
}
@Override
public
void
addFragmentWithTag
(
String
tag
,
LifecycleRequestManager
manager
)
{
SupportRequestManagerFragment
fragment
=
new
SupportRequestManagerFragment
();
fragment
.
setRequestManager
(
manager
);
controller
.
get
().
getSupportFragmentManager
()
.
beginTransaction
()
.
add
(
fragment
,
RequestManagerRetriever
.
TAG
)
.
commitAllowingStateLoss
();
controller
.
get
().
getSupportFragmentManager
().
executePendingTransactions
();
}
}
}
library/src/test/java/com/bumptech/glide/request/GenericRequestTest.java
浏览文件 @
8a6067fb
...
...
@@ -11,10 +11,10 @@ import com.bumptech.glide.Resource;
import
com.bumptech.glide.load.ResourceDecoder
;
import
com.bumptech.glide.load.ResourceEncoder
;
import
com.bumptech.glide.load.Transformation
;
import
com.bumptech.glide.load.
resource.transcode.ResourceTranscod
er
;
import
com.bumptech.glide.load.
data.DataFetch
er
;
import
com.bumptech.glide.load.engine.Engine
;
import
com.bumptech.glide.load.model.ModelLoader
;
import
com.bumptech.glide.load.
data.DataFetch
er
;
import
com.bumptech.glide.load.
resource.transcode.ResourceTranscod
er
;
import
com.bumptech.glide.provider.LoadProvider
;
import
com.bumptech.glide.request.target.Target
;
import
org.junit.Before
;
...
...
@@ -71,6 +71,8 @@ public class GenericRequestTest {
when
(
loadProvider
.
getSourceDecoder
()).
thenReturn
(
sourceDecoder
);
when
(
loadProvider
.
getEncoder
()).
thenReturn
(
encoder
);
when
(
loadProvider
.
getTranscoder
()).
thenReturn
(
transcoder
);
when
(
resource
.
get
()).
thenReturn
(
new
Object
());
}
public
GenericRequest
<
Object
,
Object
,
Object
,
Object
>
getRequest
()
{
...
...
@@ -322,6 +324,45 @@ public class GenericRequestTest {
assertEquals
(
errorPlaceholder
,
target
.
currentPlaceholder
);
}
@Test
public
void
testIsNotRunningBeforeRunCalled
()
{
assertFalse
(
harness
.
getRequest
().
isRunning
());
}
@Test
public
void
testIsRunningAfterRunCalled
()
{
Request
request
=
harness
.
getRequest
();
request
.
run
();
assertTrue
(
request
.
isRunning
());
}
@Test
public
void
testIsNotRunningAfterComplete
()
{
GenericRequest
<
Object
,
Object
,
Object
,
Object
>
request
=
harness
.
getRequest
();
request
.
run
();
request
.
onResourceReady
(
harness
.
resource
);
assertFalse
(
request
.
isRunning
());
}
@Test
public
void
testIsNotRunningAfterFailing
()
{
GenericRequest
<
Object
,
Object
,
Object
,
Object
>
request
=
harness
.
getRequest
();
request
.
run
();
request
.
onException
(
new
RuntimeException
(
"Test"
));
assertFalse
(
request
.
isRunning
());
}
@Test
public
void
testIsNotRunningAfterClear
()
{
GenericRequest
<
Object
,
Object
,
Object
,
Object
>
request
=
harness
.
getRequest
();
request
.
run
();
request
.
clear
();
assertFalse
(
request
.
isRunning
());
}
private
Context
mockContextToReturn
(
int
resourceId
,
Drawable
drawable
)
{
Resources
resources
=
mock
(
Resources
.
class
);
Context
context
=
mock
(
Context
.
class
);
...
...
library/src/test/java/com/bumptech/glide/request/ThumbnailRequestCoordinatorTest.java
0 → 100644
浏览文件 @
8a6067fb
package
com.bumptech.glide.request
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
junit
.
framework
.
Assert
.
assertFalse
;
import
static
junit
.
framework
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
class
ThumbnailRequestCoordinatorTest
{
private
Request
full
;
private
Request
thumb
;
private
ThumbnailRequestCoordinator
coordinator
;
@Before
public
void
setUp
()
{
full
=
mock
(
Request
.
class
);
thumb
=
mock
(
Request
.
class
);
coordinator
=
new
ThumbnailRequestCoordinator
();
coordinator
.
setRequests
(
full
,
thumb
);
}
@Test
public
void
testIsRunningIsFalseIfNeitherRequestIsRunning
()
{
assertFalse
(
coordinator
.
isRunning
());
}
@Test
public
void
testIsRunningIsTrueIfFullIsRunning
()
{
when
(
full
.
isRunning
()).
thenReturn
(
true
);
assertTrue
(
coordinator
.
isRunning
());
}
@Test
public
void
testIsNotRunningIfFullIsNotRunningButThumbIs
()
{
when
(
full
.
isRunning
()).
thenReturn
(
false
);
when
(
thumb
.
isRunning
()).
thenReturn
(
true
);
assertFalse
(
coordinator
.
isRunning
());
}
@Test
public
void
testStartsFullOnRunIfNotRunning
()
{
when
(
full
.
isRunning
()).
thenReturn
(
false
);
coordinator
.
run
();
verify
(
full
).
run
();
}
@Test
public
void
testStartsThumbOnRunIfNotRunning
()
{
when
(
thumb
.
isRunning
()).
thenReturn
(
false
);
coordinator
.
run
();
verify
(
thumb
).
run
();
}
@Test
public
void
testDoesNotStartThumbOnRunIfFullCompletesSynchronously
()
{
when
(
full
.
isComplete
()).
thenReturn
(
true
);
coordinator
.
run
();
verify
(
thumb
,
never
()).
run
();
}
@Test
public
void
testDoesNotStartFullOnRunIfRunning
()
{
when
(
full
.
isRunning
()).
thenReturn
(
true
);
coordinator
.
run
();
verify
(
full
,
never
()).
run
();
}
@Test
public
void
testDoesNotStartThumbOnRunIfRunning
()
{
when
(
thumb
.
isRunning
()).
thenReturn
(
true
);
coordinator
.
run
();
verify
(
thumb
,
never
()).
run
();
}
}
library/src/test/java/com/bumptech/glide/tests/TestFragmentActivity.java
0 → 100644
浏览文件 @
8a6067fb
package
com.bumptech.glide.tests
;
import
android.support.v4.app.FragmentActivity
;
public
class
TestFragmentActivity
extends
FragmentActivity
{
}
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoGrid.java
浏览文件 @
8a6067fb
...
...
@@ -127,7 +127,7 @@ public class FlickrPhotoGrid extends SherlockFragment implements PhotoViewer {
imageView
=
(
ImageView
)
view
;
}
Glide
.
with
(
getActivity
()
)
Glide
.
with
(
FlickrPhotoGrid
.
this
)
.
loadFromImage
(
current
)
.
animate
(
R
.
anim
.
fade_in
)
.
centerCrop
()
...
...
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrPhotoList.java
浏览文件 @
8a6067fb
...
...
@@ -147,7 +147,7 @@ public class FlickrPhotoList extends SherlockFragment implements PhotoViewer {
viewHolder
=
(
ViewHolder
)
view
.
getTag
();
}
Glide
.
with
(
getActivity
()
)
Glide
.
with
(
FlickrPhotoList
.
this
)
.
loadFromImage
(
current
)
.
thumbnail
(
0.1f
)
.
centerCrop
()
...
...
samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrSearchActivity.java
浏览文件 @
8a6067fb
...
...
@@ -53,10 +53,7 @@ public class FlickrSearchActivity extends SherlockFragmentActivity {
@Override
public
void
onAttachFragment
(
Fragment
fragment
)
{
super
.
onAttachFragment
(
fragment
);
if
(!(
fragment
instanceof
PhotoViewer
))
{
throw
new
IllegalStateException
(
"Fragment class "
+
fragment
.
getClass
()
+
" does not implement PhotoViewer"
);
}
else
{
if
(
fragment
instanceof
PhotoViewer
)
{
PhotoViewer
photoViewer
=
(
PhotoViewer
)
fragment
;
photoViewer
.
onPhotosUpdated
(
currentPhotos
);
if
(!
photoViewers
.
contains
(
photoViewer
))
{
...
...
@@ -69,14 +66,13 @@ public class FlickrSearchActivity extends SherlockFragmentActivity {
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
Glide
.
get
(
this
).
register
(
Photo
.
class
,
InputStream
.
class
,
new
FlickrModelLoader
.
Factory
());
setContentView
(
R
.
layout
.
flickr_search_activity
);
StrictMode
.
setThreadPolicy
(
new
StrictMode
.
ThreadPolicy
.
Builder
()
.
detectAll
()
.
penaltyLog
()
.
build
());
Glide
.
get
(
this
).
register
(
Photo
.
class
,
InputStream
.
class
,
new
FlickrModelLoader
.
Factory
());
searching
=
findViewById
(
R
.
id
.
searching
);
searchLoading
=
findViewById
(
R
.
id
.
search_loading
);
searchTerm
=
(
TextView
)
findViewById
(
R
.
id
.
search_term
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录