Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
5c3697ff
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 搜索 >>
提交
5c3697ff
编写于
8月 06, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use explicit GlideDrawable class.
上级
193e2f8f
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
155 addition
and
74 deletion
+155
-74
library/src/main/java/com/bumptech/glide/DrawableRequestBuilder.java
.../main/java/com/bumptech/glide/DrawableRequestBuilder.java
+26
-25
library/src/main/java/com/bumptech/glide/DrawableTypeRequest.java
...src/main/java/com/bumptech/glide/DrawableTypeRequest.java
+2
-2
library/src/main/java/com/bumptech/glide/Glide.java
library/src/main/java/com/bumptech/glide/Glide.java
+3
-2
library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java
...com/bumptech/glide/load/resource/gif/GifFrameManager.java
+1
-1
library/src/main/java/com/bumptech/glide/load/resource/transcode/GifBitmapWrapperDrawableTranscoder.java
...esource/transcode/GifBitmapWrapperDrawableTranscoder.java
+8
-7
library/src/main/java/com/bumptech/glide/load/resource/transcode/GlideBitmapDrawableTranscoder.java
...oad/resource/transcode/GlideBitmapDrawableTranscoder.java
+1
-1
library/src/main/java/com/bumptech/glide/request/RequestFutureTarget.java
.../java/com/bumptech/glide/request/RequestFutureTarget.java
+1
-1
library/src/main/java/com/bumptech/glide/request/target/DrawableImageViewTarget.java
...umptech/glide/request/target/DrawableImageViewTarget.java
+33
-14
library/src/main/java/com/bumptech/glide/request/target/ImageViewTarget.java
...va/com/bumptech/glide/request/target/ImageViewTarget.java
+1
-1
library/src/main/java/com/bumptech/glide/request/target/SquaringDrawable.java
...a/com/bumptech/glide/request/target/SquaringDrawable.java
+31
-4
library/src/main/java/com/bumptech/glide/request/target/Target.java
...c/main/java/com/bumptech/glide/request/target/Target.java
+1
-1
library/src/test/java/com/bumptech/glide/GlideTest.java
library/src/test/java/com/bumptech/glide/GlideTest.java
+3
-2
library/src/test/java/com/bumptech/glide/load/resource/transcode/GifBitmapWrapperDrawableTranscoderTest.java
...rce/transcode/GifBitmapWrapperDrawableTranscoderTest.java
+3
-3
library/src/test/java/com/bumptech/glide/request/target/DrawableImageViewTargetTest.java
...ech/glide/request/target/DrawableImageViewTargetTest.java
+41
-10
未找到文件。
library/src/main/java/com/bumptech/glide/DrawableRequestBuilder.java
浏览文件 @
5c3697ff
...
...
@@ -13,34 +13,35 @@ import com.bumptech.glide.load.Transformation;
import
com.bumptech.glide.load.engine.DiskCacheStrategy
;
import
com.bumptech.glide.load.model.ImageVideoWrapper
;
import
com.bumptech.glide.load.resource.bitmap.BitmapTransformation
;
import
com.bumptech.glide.load.resource.drawable.GlideDrawable
;
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.Lifecycle
;
import
com.bumptech.glide.manager.RequestTracker
;
import
com.bumptech.glide.provider.LoadProvider
;
import
com.bumptech.glide.request.animation.DrawableCrossFadeViewAnimation
;
import
com.bumptech.glide.request.RequestListener
;
import
com.bumptech.glide.request.animation.DrawableCrossFadeViewAnimation
;
import
com.bumptech.glide.request.animation.ViewPropertyAnimation
;
import
com.bumptech.glide.request.target.Target
;
import
java.io.File
;
/**
* A class for creating a request to load a {@link
android.graphics.drawable.
Drawable}.
* A class for creating a request to load a {@link
Glide
Drawable}.
*
* @param <ModelType> The type of model that will be loaded into the target.
*/
public
class
DrawableRequestBuilder
<
ModelType
>
extends
GenericRequestBuilder
<
ModelType
,
ImageVideoWrapper
,
GifBitmapWrapper
,
Drawable
>
extends
GenericRequestBuilder
<
ModelType
,
ImageVideoWrapper
,
GifBitmapWrapper
,
Glide
Drawable
>
implements
BitmapOptions
,
DrawableOptions
{
private
final
Glide
glide
;
private
final
Context
context
;
DrawableRequestBuilder
(
Context
context
,
ModelType
model
,
LoadProvider
<
ModelType
,
ImageVideoWrapper
,
GifBitmapWrapper
,
Drawable
>
loadProvider
,
Glide
glide
,
LoadProvider
<
ModelType
,
ImageVideoWrapper
,
GifBitmapWrapper
,
Glide
Drawable
>
loadProvider
,
Glide
glide
,
RequestTracker
requestTracker
,
Lifecycle
lifecycle
)
{
super
(
context
,
model
,
loadProvider
,
Drawable
.
class
,
glide
,
requestTracker
,
lifecycle
);
super
(
context
,
model
,
loadProvider
,
Glide
Drawable
.
class
,
glide
,
requestTracker
,
lifecycle
);
this
.
context
=
context
;
this
.
glide
=
glide
;
...
...
@@ -49,17 +50,17 @@ public class DrawableRequestBuilder<ModelType>
}
/**
* Loads and displays the {@link Drawable} retrieved by the given thumbnail request if it finishes before this
* request. Best used for loading thumbnail {@link Drawable}s that are smaller and will be loaded more quickly
* than the fullsize {@link
Drawable}. There are no guarantees about the order in which the requests will actually
*
finish. However, if the thumb request completes after the full request, the thumb {@link Drawable} will never
* replace the full image.
* Loads and displays the {@link
Glide
Drawable} retrieved by the given thumbnail request if it finishes before this
* request. Best used for loading thumbnail {@link
Glide
Drawable}s that are smaller and will be loaded more quickly
* than the fullsize {@link
GlideDrawable}. There are no guarantees about the order in which the requests will
*
actually finish. However, if the thumb request completes after the full request, the thumb {@link GlideDrawable}
*
will never
replace the full image.
*
* @see #thumbnail(float)
*
* <p>
* Note - Any options on the main request will not be passed on to the thumbnail request. For example, if
* you want an animation to occur when either the full {@link Drawable} loads or the thumbnail loads,
* you want an animation to occur when either the full {@link
Glide
Drawable} loads or the thumbnail loads,
* you need to call {@link #animate(int)} on both the thumb and the full request. For a simpler thumbnail
* option where these options are applied to the humbnail as well, see {@link #thumbnail(float)}.
* </p>
...
...
@@ -82,7 +83,7 @@ public class DrawableRequestBuilder<ModelType>
*/
@Override
public
DrawableRequestBuilder
<
ModelType
>
thumbnail
(
GenericRequestBuilder
<
ModelType
,
ImageVideoWrapper
,
GifBitmapWrapper
,
Drawable
>
thumbnailRequest
)
{
GenericRequestBuilder
<
ModelType
,
ImageVideoWrapper
,
GifBitmapWrapper
,
Glide
Drawable
>
thumbnailRequest
)
{
super
.
thumbnail
(
thumbnailRequest
);
return
this
;
}
...
...
@@ -142,7 +143,7 @@ public class DrawableRequestBuilder<ModelType>
}
/**
* Transform {@link
android.graphics.drawable.
Drawable}s using the given
* Transform {@link
Glide
Drawable}s using the given
* {@link com.bumptech.glide.load.resource.bitmap.BitmapTransformation}s.
*
* <p>
...
...
@@ -163,7 +164,7 @@ public class DrawableRequestBuilder<ModelType>
}
/**
* Transform {@link Drawable}s using {@link com.bumptech.glide.load.resource.bitmap.CenterCrop}.
* Transform {@link
Glide
Drawable}s using {@link com.bumptech.glide.load.resource.bitmap.CenterCrop}.
*
* @see #fitCenter()
* @see #transform(com.bumptech.glide.load.resource.bitmap.BitmapTransformation...)
...
...
@@ -177,8 +178,7 @@ public class DrawableRequestBuilder<ModelType>
}
/**
* Transform {@link android.graphics.drawable.Drawable}s using
* {@link com.bumptech.glide.load.resource.bitmap.FitCenter}.
* Transform {@link GlideDrawable}s using {@link com.bumptech.glide.load.resource.bitmap.FitCenter}.
*
* @see #centerCrop()
* @see #transform(com.bumptech.glide.load.resource.bitmap.BitmapTransformation...)
...
...
@@ -192,8 +192,8 @@ public class DrawableRequestBuilder<ModelType>
}
/**
* Transform {@link
android.graphics.drawable.Drawable}s using the given {@link android.graphics.Bitmap}
*
transformations. Replaces any
previous transformations.
* Transform {@link
GlideDrawable}s using the given {@link android.graphics.Bitmap} transformations. Replaces any
* previous transformations.
*
* @see #fitCenter()
* @see #centerCrop()
...
...
@@ -228,7 +228,8 @@ public class DrawableRequestBuilder<ModelType>
* {@inheritDoc}
*/
@Override
public
DrawableRequestBuilder
<
ModelType
>
transcoder
(
ResourceTranscoder
<
GifBitmapWrapper
,
Drawable
>
transcoder
)
{
public
DrawableRequestBuilder
<
ModelType
>
transcoder
(
ResourceTranscoder
<
GifBitmapWrapper
,
GlideDrawable
>
transcoder
)
{
super
.
transcoder
(
transcoder
);
return
this
;
}
...
...
@@ -237,7 +238,7 @@ public class DrawableRequestBuilder<ModelType>
* {@inheritDoc}
*/
public
DrawableRequestBuilder
<
ModelType
>
crossFade
()
{
super
.
animate
(
new
DrawableCrossFadeViewAnimation
.
DrawableCrossFadeFactory
<
Drawable
>());
super
.
animate
(
new
DrawableCrossFadeViewAnimation
.
DrawableCrossFadeFactory
<
Glide
Drawable
>());
return
this
;
}
...
...
@@ -245,7 +246,7 @@ public class DrawableRequestBuilder<ModelType>
* {@inheritDoc}
*/
public
DrawableRequestBuilder
<
ModelType
>
crossFade
(
int
duration
)
{
super
.
animate
(
new
DrawableCrossFadeViewAnimation
.
DrawableCrossFadeFactory
<
Drawable
>(
duration
));
super
.
animate
(
new
DrawableCrossFadeViewAnimation
.
DrawableCrossFadeFactory
<
Glide
Drawable
>(
duration
));
return
this
;
}
...
...
@@ -253,7 +254,7 @@ public class DrawableRequestBuilder<ModelType>
* {@inheritDoc}
*/
public
DrawableRequestBuilder
<
ModelType
>
crossFade
(
Animation
animation
,
int
duration
)
{
super
.
animate
(
new
DrawableCrossFadeViewAnimation
.
DrawableCrossFadeFactory
<
Drawable
>(
animation
,
duration
));
super
.
animate
(
new
DrawableCrossFadeViewAnimation
.
DrawableCrossFadeFactory
<
Glide
Drawable
>(
animation
,
duration
));
return
this
;
}
...
...
@@ -261,7 +262,7 @@ public class DrawableRequestBuilder<ModelType>
* {@inheritDoc}
*/
public
DrawableRequestBuilder
<
ModelType
>
crossFade
(
int
animationId
,
int
duration
)
{
super
.
animate
(
new
DrawableCrossFadeViewAnimation
.
DrawableCrossFadeFactory
<
Drawable
>(
context
,
animationId
,
super
.
animate
(
new
DrawableCrossFadeViewAnimation
.
DrawableCrossFadeFactory
<
Glide
Drawable
>(
context
,
animationId
,
duration
));
return
this
;
}
...
...
@@ -342,7 +343,7 @@ public class DrawableRequestBuilder<ModelType>
* {@inheritDoc}
*/
@Override
public
DrawableRequestBuilder
<
ModelType
>
listener
(
RequestListener
<
ModelType
,
Drawable
>
requestListener
)
{
public
DrawableRequestBuilder
<
ModelType
>
listener
(
RequestListener
<
ModelType
,
Glide
Drawable
>
requestListener
)
{
super
.
listener
(
requestListener
);
return
this
;
}
...
...
@@ -405,7 +406,7 @@ public class DrawableRequestBuilder<ModelType>
* @return {@inheritDoc}
*/
@Override
public
Target
<
Drawable
>
into
(
ImageView
view
)
{
public
Target
<
Glide
Drawable
>
into
(
ImageView
view
)
{
return
super
.
into
(
view
);
}
...
...
library/src/main/java/com/bumptech/glide/DrawableTypeRequest.java
浏览文件 @
5c3697ff
package
com.bumptech.glide
;
import
android.content.Context
;
import
android.graphics.drawable.Drawable
;
import
android.os.ParcelFileDescriptor
;
import
com.bumptech.glide.load.model.ImageVideoModelLoader
;
import
com.bumptech.glide.load.model.ImageVideoWrapper
;
import
com.bumptech.glide.load.model.ModelLoader
;
import
com.bumptech.glide.load.resource.drawable.GlideDrawable
;
import
com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapper
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.manager.Lifecycle
;
...
...
@@ -61,7 +61,7 @@ public class DrawableTypeRequest<ModelType> extends DrawableRequestBuilder<Model
RequestTracker
requestTracker
,
Lifecycle
lifecycle
,
RequestManager
.
OptionsApplier
optionsApplier
)
{
super
(
context
,
model
,
buildProvider
(
glide
,
streamModelLoader
,
fileDescriptorModelLoader
,
GifBitmapWrapper
.
class
,
Drawable
.
class
,
null
),
Glide
Drawable
.
class
,
null
),
glide
,
requestTracker
,
lifecycle
);
this
.
model
=
model
;
this
.
streamModelLoader
=
streamModelLoader
;
...
...
library/src/main/java/com/bumptech/glide/Glide.java
浏览文件 @
5c3697ff
...
...
@@ -39,14 +39,15 @@ import com.bumptech.glide.load.resource.bitmap.FitCenter;
import
com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable
;
import
com.bumptech.glide.load.resource.bitmap.ImageVideoDataLoadProvider
;
import
com.bumptech.glide.load.resource.bitmap.StreamBitmapDataLoadProvider
;
import
com.bumptech.glide.load.resource.drawable.GlideDrawable
;
import
com.bumptech.glide.load.resource.file.StreamFileDataLoadProvider
;
import
com.bumptech.glide.load.resource.gif.GifDrawable
;
import
com.bumptech.glide.load.resource.gif.GifDrawableLoadProvider
;
import
com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapper
;
import
com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapperTransformation
;
import
com.bumptech.glide.load.resource.gifbitmap.ImageVideoGifDrawableLoadProvider
;
import
com.bumptech.glide.load.resource.transcode.GlideBitmapDrawableTranscoder
;
import
com.bumptech.glide.load.resource.transcode.GifBitmapWrapperDrawableTranscoder
;
import
com.bumptech.glide.load.resource.transcode.GlideBitmapDrawableTranscoder
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.load.resource.transcode.TranscoderRegistry
;
import
com.bumptech.glide.manager.RequestManagerRetriever
;
...
...
@@ -211,7 +212,7 @@ public class Glide {
transcoderRegistry
.
register
(
Bitmap
.
class
,
GlideBitmapDrawable
.
class
,
new
GlideBitmapDrawableTranscoder
(
context
.
getResources
(),
bitmapPool
));
transcoderRegistry
.
register
(
GifBitmapWrapper
.
class
,
Drawable
.
class
,
transcoderRegistry
.
register
(
GifBitmapWrapper
.
class
,
Glide
Drawable
.
class
,
new
GifBitmapWrapperDrawableTranscoder
(
new
GlideBitmapDrawableTranscoder
(
context
.
getResources
(),
bitmapPool
)));
...
...
library/src/main/java/com/bumptech/glide/load/resource/gif/GifFrameManager.java
浏览文件 @
5c3697ff
...
...
@@ -151,7 +151,7 @@ class GifFrameManager {
}
@Override
public
void
onResourceReady
(
final
Bitmap
resource
,
GlideAnimation
<
Bitmap
>
glideAnimation
)
{
public
void
onResourceReady
(
final
Bitmap
resource
,
GlideAnimation
<
?
super
Bitmap
>
glideAnimation
)
{
this
.
resource
=
resource
;
mainHandler
.
postAtTime
(
this
,
targetTime
);
}
...
...
library/src/main/java/com/bumptech/glide/load/resource/transcode/GifBitmapWrapperDrawableTranscoder.java
浏览文件 @
5c3697ff
package
com.bumptech.glide.load.resource.transcode
;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.Drawable
;
import
com.bumptech.glide.load.engine.Resource
;
import
com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable
;
import
com.bumptech.glide.load.resource.drawable.GlideDrawable
;
import
com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapper
;
/**
...
...
@@ -11,28 +12,28 @@ import com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapper;
* {@link Bitmap} or an {@link com.bumptech.glide.load.resource.gif.GifDrawable} into an
* {@link android.graphics.drawable.Drawable}.
*/
public
class
GifBitmapWrapperDrawableTranscoder
implements
ResourceTranscoder
<
GifBitmapWrapper
,
Drawable
>
{
private
final
ResourceTranscoder
<
Bitmap
,
?
extends
Drawable
>
bitmapDrawableResourceTranscoder
;
public
class
GifBitmapWrapperDrawableTranscoder
implements
ResourceTranscoder
<
GifBitmapWrapper
,
Glide
Drawable
>
{
private
final
ResourceTranscoder
<
Bitmap
,
GlideBitmap
Drawable
>
bitmapDrawableResourceTranscoder
;
public
GifBitmapWrapperDrawableTranscoder
(
ResourceTranscoder
<
Bitmap
,
?
extends
Drawable
>
bitmapDrawableResourceTranscoder
)
{
ResourceTranscoder
<
Bitmap
,
GlideBitmap
Drawable
>
bitmapDrawableResourceTranscoder
)
{
this
.
bitmapDrawableResourceTranscoder
=
bitmapDrawableResourceTranscoder
;
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
Resource
<
Drawable
>
transcode
(
Resource
<
GifBitmapWrapper
>
toTranscode
)
{
public
Resource
<
Glide
Drawable
>
transcode
(
Resource
<
GifBitmapWrapper
>
toTranscode
)
{
GifBitmapWrapper
gifBitmap
=
toTranscode
.
get
();
Resource
<
Bitmap
>
bitmapResource
=
gifBitmap
.
getBitmapResource
();
final
Resource
<?
extends
Drawable
>
result
;
final
Resource
<?
extends
Glide
Drawable
>
result
;
if
(
bitmapResource
!=
null
)
{
result
=
bitmapDrawableResourceTranscoder
.
transcode
(
bitmapResource
);
}
else
{
result
=
gifBitmap
.
getGifResource
();
}
// This is unchecked but always safe, anything that extends a Drawable can be safely cast to a Drawable.
return
(
Resource
<
Drawable
>)
result
;
return
(
Resource
<
Glide
Drawable
>)
result
;
}
@Override
...
...
library/src/main/java/com/bumptech/glide/load/resource/transcode/GlideBitmapDrawableTranscoder.java
浏览文件 @
5c3697ff
...
...
@@ -29,6 +29,6 @@ public class GlideBitmapDrawableTranscoder implements ResourceTranscoder<Bitmap,
@Override
public
String
getId
()
{
return
"BitmapDrawableTranscoder.com.bumptech.glide.load.resource.transcode"
;
return
"
Glide
BitmapDrawableTranscoder.com.bumptech.glide.load.resource.transcode"
;
}
}
library/src/main/java/com/bumptech/glide/request/RequestFutureTarget.java
浏览文件 @
5c3697ff
...
...
@@ -176,7 +176,7 @@ public class RequestFutureTarget<T, R> implements FutureTarget<R>, Runnable {
* A callback that should never be invoked directly.
*/
@Override
public
synchronized
void
onResourceReady
(
R
resource
,
GlideAnimation
<
R
>
glideAnimation
)
{
public
synchronized
void
onResourceReady
(
R
resource
,
GlideAnimation
<
?
super
R
>
glideAnimation
)
{
// We might get a null result.
resultReceived
=
true
;
this
.
resource
=
resource
;
...
...
library/src/main/java/com/bumptech/glide/request/target/DrawableImageViewTarget.java
浏览文件 @
5c3697ff
package
com.bumptech.glide.request.target
;
import
android.graphics.drawable.Animatable
;
import
android.graphics.drawable.Drawable
;
import
android.widget.ImageView
;
import
com.bumptech.glide.load.resource.drawable.GlideDrawable
;
import
com.bumptech.glide.request.animation.GlideAnimation
;
/**
* A {@link com.bumptech.glide.request.target.Target} that can display an {@link android.graphics.drawable.Drawable} in
* an {@link android.widget.ImageView}.
*/
public
class
DrawableImageViewTarget
extends
ImageViewTarget
<
Drawable
>
{
public
class
DrawableImageViewTarget
extends
ImageViewTarget
<
Glide
Drawable
>
{
private
static
final
float
SQUARE_RATIO_MARGIN
=
0.05f
;
private
final
ImageView
view
;
private
Drawable
resource
;
private
int
maxLoopCount
;
private
GlideDrawable
resource
;
/**
* Constructor for an {@link com.bumptech.glide.request.target.Target} that can display an
* {@link com.bumptech.glide.load.resource.drawable.GlideDrawable} in an {@link android.widget.ImageView}.
*
* @param view The view to display the drawable in.
*/
public
DrawableImageViewTarget
(
ImageView
view
)
{
this
(
view
,
GlideDrawable
.
LOOP_FOREVER
);
}
/**
* Constructor for an {@link com.bumptech.glide.request.target.Target} that can display an
* {@link com.bumptech.glide.load.resource.drawable.GlideDrawable} in an {@link android.widget.ImageView}.
*
* @param view The view to display the drawable in.
* @param maxLoopCount A value to pass to to {@link com.bumptech.glide.load.resource.drawable.GlideDrawable}s
* indicating how many times they should repeat their animation (if they have one). See
* {@link com.bumptech.glide.load.resource.drawable.GlideDrawable#setLoopCount(int)}.
*/
public
DrawableImageViewTarget
(
ImageView
view
,
int
maxLoopCount
)
{
super
(
view
);
this
.
view
=
view
;
this
.
maxLoopCount
=
maxLoopCount
;
}
/**
...
...
@@ -30,8 +50,8 @@ public class DrawableImageViewTarget extends ImageViewTarget<Drawable> {
* @param animation {@inheritDoc}
*/
@Override
public
void
onResourceReady
(
Drawable
resource
,
GlideAnimation
<
Drawable
>
animation
)
{
if
(!
(
resource
instanceof
Animatable
))
{
public
void
onResourceReady
(
GlideDrawable
resource
,
GlideAnimation
<?
super
Glide
Drawable
>
animation
)
{
if
(!
resource
.
isAnimated
(
))
{
//TODO: Try to generalize this to other sizes/shapes.
// This is a dirty hack that tries to make loading square thumbnails and then square full images less costly
// by forcing both the smaller thumb and the larger version to have exactly the same intrinsic dimensions.
...
...
@@ -47,9 +67,8 @@ public class DrawableImageViewTarget extends ImageViewTarget<Drawable> {
}
super
.
onResourceReady
(
resource
,
animation
);
this
.
resource
=
resource
;
if
(
resource
instanceof
Animatable
)
{
((
Animatable
)
resource
).
start
();
}
resource
.
setLoopCount
(
maxLoopCount
);
resource
.
start
();
}
/**
...
...
@@ -59,21 +78,21 @@ public class DrawableImageViewTarget extends ImageViewTarget<Drawable> {
* @param resource The {@link android.graphics.drawable.Drawable} to display in the view.
*/
@Override
protected
void
setResource
(
Drawable
resource
)
{
protected
void
setResource
(
Glide
Drawable
resource
)
{
view
.
setImageDrawable
(
resource
);
}
@Override
public
void
onStart
()
{
if
(
resource
instanceof
Animatable
)
{
((
Animatable
)
resource
)
.
start
();
if
(
resource
!=
null
)
{
resource
.
start
();
}
}
@Override
public
void
onStop
()
{
if
(
resource
instanceof
Animatable
)
{
((
Animatable
)
resource
)
.
stop
();
if
(
resource
!=
null
)
{
resource
.
stop
();
}
}
}
library/src/main/java/com/bumptech/glide/request/target/ImageViewTarget.java
浏览文件 @
5c3697ff
...
...
@@ -71,7 +71,7 @@ public abstract class ImageViewTarget<Z> extends ViewTarget<ImageView, Z> implem
}
@Override
public
void
onResourceReady
(
Z
resource
,
GlideAnimation
<
Z
>
glideAnimation
)
{
public
void
onResourceReady
(
Z
resource
,
GlideAnimation
<
?
super
Z
>
glideAnimation
)
{
if
(
glideAnimation
==
null
||
!
glideAnimation
.
animate
(
resource
,
this
))
{
setResource
(
resource
);
}
...
...
library/src/main/java/com/bumptech/glide/request/target/SquaringDrawable.java
浏览文件 @
5c3697ff
...
...
@@ -7,17 +7,19 @@ import android.graphics.PorterDuff;
import
android.graphics.Rect
;
import
android.graphics.drawable.Drawable
;
import
com.bumptech.glide.load.resource.drawable.GlideDrawable
;
/**
* A wrapper drawable to square the wrapped drawable so that it expands to fill a square with exactly the given side
* length. The goal of this drawable is to ensure that square thumbnail drawables always match the size of the view
* they will be displayed in to avoid a costly requestLayout call. This class should not be used with views or drawables
* that are not square.
*/
public
class
SquaringDrawable
extends
Drawable
{
private
final
Drawable
wrapped
;
private
int
side
;
public
class
SquaringDrawable
extends
Glide
Drawable
{
private
final
Glide
Drawable
wrapped
;
private
final
int
side
;
public
SquaringDrawable
(
Drawable
wrapped
,
int
side
)
{
public
SquaringDrawable
(
Glide
Drawable
wrapped
,
int
side
)
{
this
.
wrapped
=
wrapped
;
this
.
side
=
side
;
}
...
...
@@ -146,4 +148,29 @@ public class SquaringDrawable extends Drawable {
public
int
getOpacity
()
{
return
wrapped
.
getOpacity
();
}
@Override
public
boolean
isAnimated
()
{
return
wrapped
.
isAnimated
();
}
@Override
public
void
setLoopCount
(
int
loopCount
)
{
wrapped
.
setLoopCount
(
loopCount
);
}
@Override
public
void
start
()
{
wrapped
.
start
();
}
@Override
public
void
stop
()
{
wrapped
.
stop
();
}
@Override
public
boolean
isRunning
()
{
return
wrapped
.
isRunning
();
}
}
library/src/main/java/com/bumptech/glide/request/target/Target.java
浏览文件 @
5c3697ff
...
...
@@ -64,7 +64,7 @@ public interface Target<R> extends LifecycleListener {
*
* @param resource the loaded resource.
*/
public
void
onResourceReady
(
R
resource
,
GlideAnimation
<
R
>
glideAnimation
);
public
void
onResourceReady
(
R
resource
,
GlideAnimation
<
?
super
R
>
glideAnimation
);
/**
* A lifecycle callback that is called when a load is cancelled and its resources are freed.
...
...
library/src/test/java/com/bumptech/glide/GlideTest.java
浏览文件 @
5c3697ff
...
...
@@ -29,6 +29,7 @@ import com.bumptech.glide.load.model.ModelLoaderFactory;
import
com.bumptech.glide.load.model.stream.StreamModelLoader
;
import
com.bumptech.glide.load.resource.bitmap.BitmapResource
;
import
com.bumptech.glide.load.resource.bytes.BytesResource
;
import
com.bumptech.glide.load.resource.drawable.GlideDrawable
;
import
com.bumptech.glide.load.resource.gif.GifDrawable
;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.request.Request
;
...
...
@@ -392,7 +393,7 @@ public class GlideTest {
private
void
runTestStringDefaultLoader
(
String
string
)
{
Glide
.
with
(
getContext
())
.
load
(
string
)
.
listener
(
new
RequestListener
<
String
,
Drawable
>()
{
.
listener
(
new
RequestListener
<
String
,
Glide
Drawable
>()
{
@Override
public
boolean
onException
(
Exception
e
,
String
model
,
Target
target
,
boolean
isFirstResource
)
{
if
(!(
e
instanceof
IOException
))
{
...
...
@@ -402,7 +403,7 @@ public class GlideTest {
}
@Override
public
boolean
onResourceReady
(
Drawable
resource
,
String
model
,
Target
target
,
public
boolean
onResourceReady
(
Glide
Drawable
resource
,
String
model
,
Target
target
,
boolean
isFromMemoryCache
,
boolean
isFirstResource
)
{
return
false
;
...
...
library/src/test/java/com/bumptech/glide/load/resource/transcode/GifBitmapWrapperDrawableTranscoderTest.java
浏览文件 @
5c3697ff
package
com.bumptech.glide.load.resource.transcode
;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.Drawable
;
import
com.bumptech.glide.load.engine.Resource
;
import
com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable
;
import
com.bumptech.glide.load.resource.gif.GifDrawable
;
import
com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapper
;
import
com.bumptech.glide.tests.Util
;
...
...
@@ -21,7 +21,7 @@ import static org.mockito.Mockito.when;
@RunWith
(
RobolectricTestRunner
.
class
)
public
class
GifBitmapWrapperDrawableTranscoderTest
{
private
GifBitmapWrapperDrawableTranscoder
transcoder
;
private
ResourceTranscoder
<
Bitmap
,
Drawable
>
bitmapTranscoder
;
private
ResourceTranscoder
<
Bitmap
,
GlideBitmap
Drawable
>
bitmapTranscoder
;
@Before
public
void
setUp
()
{
...
...
@@ -52,7 +52,7 @@ public class GifBitmapWrapperDrawableTranscoderTest {
private
static
class
TranscoderHarness
{
Resource
<
GifBitmapWrapper
>
gifBitmapResource
=
mock
(
Resource
.
class
);
GifBitmapWrapper
gifBitmap
=
mock
(
GifBitmapWrapper
.
class
);
Resource
<
Drawable
>
expected
=
mock
(
Resource
.
class
);
Resource
<
GlideBitmap
Drawable
>
expected
=
mock
(
Resource
.
class
);
public
TranscoderHarness
()
{
when
(
gifBitmapResource
.
get
()).
thenReturn
(
gifBitmap
);
...
...
library/src/test/java/com/bumptech/glide/request/target/DrawableImageViewTargetTest.java
浏览文件 @
5c3697ff
package
com.bumptech.glide.request.target
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.ColorFilter
;
import
android.graphics.drawable.Animatable
;
import
android.graphics.drawable.AnimationDrawable
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.graphics.drawable.ColorDrawable
;
import
android.graphics.drawable.Drawable
;
import
android.widget.ImageView
;
import
com.bumptech.glide.load.resource.drawable.GlideDrawable
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.invocation.InvocationOnMock
;
...
...
@@ -33,7 +31,7 @@ public class DrawableImageViewTargetTest {
public
void
testSetsDrawableOnViewInSetResource
()
{
ImageView
view
=
new
ImageView
(
Robolectric
.
application
);
DrawableImageViewTarget
target
=
new
DrawableImageViewTarget
(
view
);
Drawable
expected
=
new
ColorDrawable
(
Color
.
GRAY
);
GlideDrawable
expected
=
new
MockAnimatedDrawable
(
);
target
.
setResource
(
expected
);
...
...
@@ -46,7 +44,7 @@ public class DrawableImageViewTargetTest {
when
(
mockView
.
getWidth
()).
thenReturn
(
100
);
when
(
mockView
.
getHeight
()).
thenReturn
(
100
);
DrawableImageViewTarget
target
=
new
DrawableImageViewTarget
(
mockView
);
Drawable
drawable
=
new
ColorDrawable
(
Color
.
RED
)
{
GlideDrawable
drawable
=
new
MockAnimatedDrawable
(
)
{
@Override
public
int
getIntrinsicHeight
()
{
return
100
;
...
...
@@ -78,7 +76,7 @@ public class DrawableImageViewTargetTest {
when
(
mockView
.
getWidth
()).
thenReturn
(
100
);
when
(
mockView
.
getHeight
()).
thenReturn
(
100
);
DrawableImageViewTarget
target
=
new
DrawableImageViewTarget
(
mockView
);
Drawable
drawable
=
new
Animation
Drawable
()
{
GlideDrawable
drawable
=
new
MockAnimated
Drawable
()
{
@Override
public
int
getIntrinsicHeight
()
{
return
100
;
...
...
@@ -108,7 +106,7 @@ public class DrawableImageViewTargetTest {
when
(
mockView
.
getWidth
()).
thenReturn
(
100
);
when
(
mockView
.
getHeight
()).
thenReturn
(
100
);
DrawableImageViewTarget
target
=
new
DrawableImageViewTarget
(
mockView
);
Drawable
drawable
=
new
ColorDrawable
(
Color
.
RED
)
{
GlideDrawable
drawable
=
new
MockAnimatedDrawable
(
)
{
@Override
public
int
getIntrinsicHeight
()
{
return
100
;
...
...
@@ -138,7 +136,7 @@ public class DrawableImageViewTargetTest {
when
(
mockView
.
getWidth
()).
thenReturn
(
100
);
when
(
mockView
.
getHeight
()).
thenReturn
(
150
);
DrawableImageViewTarget
target
=
new
DrawableImageViewTarget
(
mockView
);
Drawable
drawable
=
new
ColorDrawable
(
Color
.
RED
)
{
GlideDrawable
drawable
=
new
MockAnimatedDrawable
(
)
{
@Override
public
int
getIntrinsicHeight
()
{
return
100
;
...
...
@@ -182,6 +180,12 @@ public class DrawableImageViewTargetTest {
assertTrue
(
drawable
.
isStarted
);
}
@Test
public
void
testDoesNotStartNullDrawablesOnStart
()
{
DrawableImageViewTarget
target
=
new
DrawableImageViewTarget
(
new
ImageView
(
Robolectric
.
application
));
target
.
onStart
();
}
@Test
public
void
testStopsAnimatedDrawablesOnStop
()
{
MockAnimatedDrawable
drawable
=
new
MockAnimatedDrawable
();
...
...
@@ -192,8 +196,25 @@ public class DrawableImageViewTargetTest {
assertFalse
(
drawable
.
isStarted
);
}
private
static
class
MockAnimatedDrawable
extends
Drawable
implements
Animatable
{
@Test
public
void
testDoesNotStopNullDrawablesOnStop
()
{
DrawableImageViewTarget
target
=
new
DrawableImageViewTarget
(
new
ImageView
(
Robolectric
.
application
));
target
.
onStop
();
}
@Test
public
void
testSetsLoopCountOnDrawable
()
{
int
maxLoopCount
=
6
;
MockAnimatedDrawable
drawable
=
new
MockAnimatedDrawable
();
DrawableImageViewTarget
target
=
new
DrawableImageViewTarget
(
new
ImageView
(
Robolectric
.
application
),
maxLoopCount
);
target
.
onResourceReady
(
drawable
,
null
);
assertEquals
(
maxLoopCount
,
drawable
.
loopCount
);
}
private
static
class
MockAnimatedDrawable
extends
GlideDrawable
{
private
boolean
isStarted
;
private
int
loopCount
;
@Override
public
void
start
()
{
...
...
@@ -229,5 +250,15 @@ public class DrawableImageViewTargetTest {
public
int
getOpacity
()
{
return
0
;
}
@Override
public
boolean
isAnimated
()
{
return
false
;
}
@Override
public
void
setLoopCount
(
int
loopCount
)
{
this
.
loopCount
=
loopCount
;
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录