Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
ba414a3e
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,发现更多精彩内容 >>
提交
ba414a3e
编写于
5月 31, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generify Target.
上级
407cdc3d
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
49 addition
and
47 deletion
+49
-47
library/robolectric/src/com/bumptech/glide/GlideTest.java
library/robolectric/src/com/bumptech/glide/GlideTest.java
+7
-7
library/robolectric/src/com/bumptech/glide/request/BitmapRequestTest.java
...ric/src/com/bumptech/glide/request/BitmapRequestTest.java
+2
-3
library/src/com/bumptech/glide/GenericRequestBuilder.java
library/src/com/bumptech/glide/GenericRequestBuilder.java
+8
-8
library/src/com/bumptech/glide/Glide.java
library/src/com/bumptech/glide/Glide.java
+2
-2
library/src/com/bumptech/glide/ListPreloader.java
library/src/com/bumptech/glide/ListPreloader.java
+2
-2
library/src/com/bumptech/glide/request/bitmap/BitmapRequest.java
.../src/com/bumptech/glide/request/bitmap/BitmapRequest.java
+16
-16
library/src/com/bumptech/glide/request/target/BitmapImageViewTarget.java
.../bumptech/glide/request/target/BitmapImageViewTarget.java
+5
-4
library/src/com/bumptech/glide/request/target/Target.java
library/src/com/bumptech/glide/request/target/Target.java
+6
-4
library/src/com/bumptech/glide/request/target/ViewTarget.java
...ary/src/com/bumptech/glide/request/target/ViewTarget.java
+1
-1
未找到文件。
library/robolectric/src/com/bumptech/glide/GlideTest.java
浏览文件 @
ba414a3e
...
...
@@ -223,7 +223,7 @@ public class GlideTest {
Glide
.
with
(
getContext
()).
load
(
file
).
into
(
target
);
verify
(
target
).
on
ImageReady
(
any
(
Bitmap
.
class
));
verify
(
target
).
on
ResourceReady
(
any
(
Resource
.
class
));
verify
(
target
).
setRequest
((
Request
)
notNull
());
}
...
...
@@ -233,7 +233,7 @@ public class GlideTest {
Glide
.
with
(
getContext
()).
loadFromImage
(
url
).
into
(
target
);
verify
(
target
).
on
ImageReady
(
any
(
Bitmap
.
class
));
verify
(
target
).
on
ResourceReady
(
any
(
Resource
.
class
));
verify
(
target
).
setRequest
((
Request
)
notNull
());
}
...
...
@@ -260,7 +260,7 @@ public class GlideTest {
Glide
.
with
(
getContext
()).
load
(
uri
).
into
(
target
);
verify
(
target
).
on
ImageReady
(
any
(
Bitmap
.
class
));
verify
(
target
).
on
ResourceReady
(
any
(
Resource
.
class
));
verify
(
target
).
setRequest
((
Request
)
notNull
());
}
...
...
@@ -318,7 +318,7 @@ public class GlideTest {
private
void
runTestStringDefaultLoader
(
String
string
)
{
Glide
.
with
(
getContext
()).
load
(
string
).
into
(
target
);
verify
(
target
).
on
ImageReady
(
any
(
Bitmap
.
class
));
verify
(
target
).
on
ResourceReady
(
any
(
Resource
.
class
));
verify
(
target
).
setRequest
((
Request
)
notNull
());
}
...
...
@@ -345,7 +345,7 @@ public class GlideTest {
Glide
.
with
(
getContext
()).
load
(
integer
).
into
(
target
);
verify
(
target
).
on
ImageReady
(
any
(
Bitmap
.
class
));
verify
(
target
).
on
ResourceReady
(
any
(
Resource
.
class
));
verify
(
target
).
setRequest
((
Request
)
notNull
());
}
...
...
@@ -354,7 +354,7 @@ public class GlideTest {
byte
[]
bytes
=
new
byte
[
10
];
Glide
.
with
(
getContext
()).
loadFromImage
(
bytes
).
into
(
target
);
verify
(
target
).
on
ImageReady
(
any
(
Bitmap
.
class
));
verify
(
target
).
on
ResourceReady
(
any
(
Resource
.
class
));
verify
(
target
).
setRequest
((
Request
)
notNull
());
}
...
...
@@ -364,7 +364,7 @@ public class GlideTest {
String
id
=
"test"
;
Glide
.
with
(
getContext
()).
loadFromImage
(
bytes
,
id
).
into
(
target
);
verify
(
target
).
on
ImageReady
(
any
(
Bitmap
.
class
));
verify
(
target
).
on
ResourceReady
(
any
(
Resource
.
class
));
verify
(
target
).
setRequest
((
Request
)
notNull
());
}
...
...
library/robolectric/src/com/bumptech/glide/request/BitmapRequestTest.java
浏览文件 @
ba414a3e
...
...
@@ -93,7 +93,6 @@ public class BitmapRequestTest {
@Test
public
void
testResourceIsNotCompleteWhenAskingCoordinatorIfCanSetImage
()
{
RequestCoordinator
requestCoordinator
=
mock
(
RequestCoordinator
.
class
);
requestCoordinator
=
mock
(
RequestCoordinator
.
class
);
doAnswer
(
new
Answer
()
{
@Override
public
Object
answer
(
InvocationOnMock
invocation
)
throws
Throwable
{
...
...
@@ -274,11 +273,11 @@ public class BitmapRequestTest {
return
context
;
}
private
static
class
MockTarget
implements
Target
{
private
static
class
MockTarget
implements
Target
<
Object
>
{
private
Drawable
currentPlaceholder
;
@Override
public
void
on
ImageReady
(
Bitmap
bitmap
)
{
public
void
on
ResourceReady
(
Resource
<
Object
>
resource
)
{
currentPlaceholder
=
null
;
}
...
...
library/src/com/bumptech/glide/GenericRequestBuilder.java
浏览文件 @
ba414a3e
...
...
@@ -23,7 +23,7 @@ import com.bumptech.glide.request.RequestCoordinator;
import
com.bumptech.glide.request.ThumbnailRequestCoordinator
;
import
com.bumptech.glide.request.bitmap.BitmapRequest
;
import
com.bumptech.glide.request.bitmap.RequestListener
;
import
com.bumptech.glide.request.target.ImageViewTarget
;
import
com.bumptech.glide.request.target.
Bitmap
ImageViewTarget
;
import
com.bumptech.glide.request.target.Target
;
import
java.util.ArrayList
;
...
...
@@ -333,7 +333,7 @@ public class GenericRequestBuilder<ModelType, ImageResourceType, VideoResourceTy
* @param target The target to load te image for
* @return The given target.
*/
public
<
Y
extends
Target
>
Y
into
(
Y
target
)
{
public
<
Y
extends
Target
<
Bitmap
>
>
Y
into
(
Y
target
)
{
Request
previous
=
target
.
getRequest
();
if
(
previous
!=
null
)
{
previous
.
clear
();
...
...
@@ -354,13 +354,13 @@ public class GenericRequestBuilder<ModelType, ImageResourceType, VideoResourceTy
* @see Glide#clear(View)
*
* @param view The view to cancel previous loads for and load the new image into.
* @return The {@link ImageViewTarget} used to wrap the given {@link ImageView}.
* @return The {@link
Bitmap
ImageViewTarget} used to wrap the given {@link ImageView}.
*/
public
ImageViewTarget
into
(
ImageView
view
)
{
return
into
(
new
ImageViewTarget
(
view
));
public
Bitmap
ImageViewTarget
into
(
ImageView
view
)
{
return
into
(
new
Bitmap
ImageViewTarget
(
view
));
}
private
<
Y
extends
Target
>
Request
buildRequest
(
Y
target
)
{
private
Request
buildRequest
(
Target
<
Bitmap
>
target
)
{
final
Request
result
;
if
(
priority
==
null
)
{
...
...
@@ -417,7 +417,7 @@ public class GenericRequestBuilder<ModelType, ImageResourceType, VideoResourceTy
return
result
;
}
private
<
Y
extends
Target
>
Request
buildBitmapRequest
(
Y
target
,
float
sizeMultiplier
,
Priority
priority
,
private
Request
buildBitmapRequest
(
Target
<
Bitmap
>
target
,
float
sizeMultiplier
,
Priority
priority
,
RequestCoordinator
requestCoordinator
)
{
if
(
model
==
null
)
{
return
buildBitmapRequestForType
(
target
,
imageLoadProvider
,
sizeMultiplier
,
priority
,
null
);
...
...
@@ -437,7 +437,7 @@ public class GenericRequestBuilder<ModelType, ImageResourceType, VideoResourceTy
}
}
private
<
Y
extends
Target
,
Z
>
Request
buildBitmapRequestForType
(
Y
target
,
private
<
Z
>
Request
buildBitmapRequestForType
(
Target
<
Bitmap
>
target
,
LoadProvider
<
ModelType
,
Z
,
Bitmap
>
loadProvider
,
float
sizeMultiplier
,
Priority
priority
,
RequestCoordinator
requestCoordinator
)
{
return
new
BitmapRequest
<
ModelType
,
Z
>(
loadProvider
,
model
,
context
,
priority
,
target
,
sizeMultiplier
,
...
...
library/src/com/bumptech/glide/Glide.java
浏览文件 @
ba414a3e
...
...
@@ -674,13 +674,13 @@ public class Glide {
}
}
private
static
class
ClearTarget
extends
ViewTarget
<
View
>
{
private
static
class
ClearTarget
extends
ViewTarget
<
View
,
Object
>
{
public
ClearTarget
(
View
view
)
{
super
(
view
);
}
@Override
public
void
on
ImageReady
(
Bitmap
bitmap
)
{
}
public
void
on
ResourceReady
(
Resource
<
Object
>
resource
)
{
}
@Override
public
void
setPlaceholder
(
Drawable
placeholder
)
{
}
...
...
library/src/com/bumptech/glide/ListPreloader.java
浏览文件 @
ba414a3e
package
com.bumptech.glide
;
import
android.annotation.TargetApi
;
import
android.graphics.Bitmap
;
import
android.os.Build
;
import
android.widget.AbsListView
;
import
com.bumptech.glide.request.target.BaseTarget
;
...
...
@@ -170,7 +169,8 @@ public abstract class ListPreloader<T> implements AbsListView.OnScrollListener {
private
int
photoWidth
;
@Override
public
void
onImageReady
(
Bitmap
bitmap
)
{
}
public
void
onResourceReady
(
Resource
resource
)
{
}
@Override
public
void
getSize
(
SizeReadyCallback
cb
)
{
...
...
library/src/com/bumptech/glide/request/bitmap/BitmapRequest.java
浏览文件 @
ba414a3e
...
...
@@ -25,23 +25,23 @@ import java.io.InputStream;
/**
* A {@link Request} that loads an {@link Bitmap} into a given {@link Target}.
*
* @param <
T
> The type of the model that the {@link Bitmap} will be loaded from.
* @param <
Z
> The type of the resource that the {@link Bitmap} will be loaded from.
* @param <
A
> The type of the model that the {@link Bitmap} will be loaded from.
* @param <
T
> The type of the resource that the {@link Bitmap} will be loaded from.
*/
public
class
BitmapRequest
<
T
,
Z
>
implements
Request
,
Target
.
SizeReadyCallback
,
ResourceCallback
<
Bitmap
>
{
public
class
BitmapRequest
<
A
,
T
>
implements
Request
,
Target
.
SizeReadyCallback
,
ResourceCallback
<
Bitmap
>
{
private
static
final
String
TAG
=
"BitmapRequest"
;
private
final
int
placeholderResourceId
;
private
final
int
errorResourceId
;
private
final
Context
context
;
private
final
Transformation
<
Bitmap
>
transformation
;
private
final
LoadProvider
<
T
,
Z
,
Bitmap
>
loadProvider
;
private
final
LoadProvider
<
A
,
T
,
Bitmap
>
loadProvider
;
private
final
int
animationId
;
private
final
RequestCoordinator
requestCoordinator
;
private
final
T
model
;
private
final
A
model
;
private
Priority
priority
;
private
final
Target
target
;
private
final
RequestListener
<
T
>
requestListener
;
private
final
Target
<
Bitmap
>
target
;
private
final
RequestListener
<
A
>
requestListener
;
private
final
float
sizeMultiplier
;
private
final
Engine
engine
;
private
Animation
animation
;
...
...
@@ -53,10 +53,11 @@ public class BitmapRequest<T, Z> implements Request, Target.SizeReadyCallback, R
private
Resource
<
Bitmap
>
resource
;
private
Engine
.
LoadStatus
loadStatus
;
public
BitmapRequest
(
LoadProvider
<
T
,
Z
,
Bitmap
>
loadProvider
,
T
model
,
Context
context
,
Priority
priority
,
Target
target
,
float
sizeMultiplier
,
Drawable
placeholderDrawable
,
int
placeholderResourceId
,
Drawable
errorDrawable
,
int
errorResourceId
,
RequestListener
<
T
>
requestListener
,
int
animationId
,
Animation
animation
,
RequestCoordinator
requestCoordinator
,
Engine
engine
,
Transformation
<
Bitmap
>
transformation
)
{
public
BitmapRequest
(
LoadProvider
<
A
,
T
,
Bitmap
>
loadProvider
,
A
model
,
Context
context
,
Priority
priority
,
Target
<
Bitmap
>
target
,
float
sizeMultiplier
,
Drawable
placeholderDrawable
,
int
placeholderResourceId
,
Drawable
errorDrawable
,
int
errorResourceId
,
RequestListener
<
A
>
requestListener
,
int
animationId
,
Animation
animation
,
RequestCoordinator
requestCoordinator
,
Engine
engine
,
Transformation
<
Bitmap
>
transformation
)
{
this
.
loadProvider
=
loadProvider
;
this
.
model
=
model
;
this
.
context
=
context
;
...
...
@@ -148,12 +149,12 @@ public class BitmapRequest<T, Z> implements Request, Target.SizeReadyCallback, R
width
=
Math
.
round
(
sizeMultiplier
*
width
);
height
=
Math
.
round
(
sizeMultiplier
*
height
);
ResourceDecoder
<
InputStream
,
Bitmap
>
cacheDecoder
=
loadProvider
.
getCacheDecoder
();
ResourceDecoder
<
Z
,
Bitmap
>
decoder
=
loadProvider
.
getSourceDecoder
();
ResourceDecoder
<
T
,
Bitmap
>
decoder
=
loadProvider
.
getSourceDecoder
();
ResourceEncoder
<
Bitmap
>
encoder
=
loadProvider
.
getEncoder
();
ModelLoader
<
T
,
Z
>
modelLoader
=
loadProvider
.
getModelLoader
();
ModelLoader
<
A
,
T
>
modelLoader
=
loadProvider
.
getModelLoader
();
final
String
id
=
modelLoader
.
getId
(
model
);
final
ResourceFetcher
<
Z
>
resourceFetcher
=
modelLoader
.
getResourceFetcher
(
model
,
width
,
height
);
final
ResourceFetcher
<
T
>
resourceFetcher
=
modelLoader
.
getResourceFetcher
(
model
,
width
,
height
);
loadedFromMemoryCache
=
true
;
loadStatus
=
engine
.
load
(
id
,
width
,
height
,
cacheDecoder
,
resourceFetcher
,
decoder
,
transformation
,
...
...
@@ -179,8 +180,7 @@ public class BitmapRequest<T, Z> implements Request, Target.SizeReadyCallback, R
resource
.
release
();
return
;
}
Bitmap
loaded
=
resource
.
get
();
target
.
onImageReady
(
loaded
);
target
.
onResourceReady
(
resource
);
if
(!
loadedFromMemoryCache
&&
!
isAnyImageSet
())
{
if
(
animation
==
null
&&
animationId
>
0
)
{
animation
=
AnimationUtils
.
loadAnimation
(
context
,
animationId
);
...
...
library/src/com/bumptech/glide/request/target/ImageViewTarget.java
→
library/src/com/bumptech/glide/request/target/
Bitmap
ImageViewTarget.java
浏览文件 @
ba414a3e
...
...
@@ -3,21 +3,22 @@ package com.bumptech.glide.request.target;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.Drawable
;
import
android.widget.ImageView
;
import
com.bumptech.glide.Resource
;
/**
* A target wrapping an ImageView. Obtains the runtime dimensions of the ImageView.
*/
public
class
ImageViewTarget
extends
ViewTarget
<
ImageView
>
{
public
class
BitmapImageViewTarget
extends
ViewTarget
<
ImageView
,
Bitmap
>
{
private
final
ImageView
view
;
public
ImageViewTarget
(
ImageView
view
)
{
public
Bitmap
ImageViewTarget
(
ImageView
view
)
{
super
(
view
);
this
.
view
=
view
;
}
@Override
public
void
on
ImageReady
(
Bitmap
bitmap
)
{
view
.
setImageBitmap
(
bitmap
);
public
void
on
ResourceReady
(
Resource
<
Bitmap
>
resource
)
{
view
.
setImageBitmap
(
resource
.
get
()
);
}
@Override
...
...
library/src/com/bumptech/glide/request/target/Target.java
浏览文件 @
ba414a3e
package
com.bumptech.glide.request.target
;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.Drawable
;
import
android.view.animation.Animation
;
import
com.bumptech.glide.Resource
;
import
com.bumptech.glide.request.Request
;
/**
* An interface that Glide can load an image into
*
* @param <Z> The type of resource the target can display.
*/
public
interface
Target
{
public
interface
Target
<
Z
>
{
/**
* A callback that must be called when the target has determined its size. For fixed size targets it can
...
...
@@ -20,9 +22,9 @@ public interface Target {
/**
* The method that will be called when the image load has finished
* @param
bitmap The loaded image
* @param
resource the loaded resource.
*/
public
void
on
ImageReady
(
Bitmap
bitmap
);
public
void
on
ResourceReady
(
Resource
<
Z
>
resource
);
/**
* A method that can optionally be implemented to set any placeholder that might have been passed to Glide to
...
...
library/src/com/bumptech/glide/request/target/ViewTarget.java
浏览文件 @
ba414a3e
...
...
@@ -34,7 +34,7 @@ import java.util.Set;
*
* @param <T> The specific subclass of view wrapped by this target.
*/
public
abstract
class
ViewTarget
<
T
extends
View
>
implements
Target
{
public
abstract
class
ViewTarget
<
T
extends
View
,
Z
>
implements
Target
<
Z
>
{
private
static
final
String
TAG
=
"ViewTarget"
;
private
final
T
view
;
private
final
SizeDeterminer
sizeDeterminer
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录