Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
44b89ba4
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,发现更多精彩内容 >>
提交
44b89ba4
编写于
6月 13, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix shared gif drawables
上级
50f743d6
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
61 addition
and
121 deletion
+61
-121
library/src/main/java/com/bumptech/glide/Glide.java
library/src/main/java/com/bumptech/glide/Glide.java
+4
-2
library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableResource.java
...ch/glide/load/resource/bitmap/BitmapDrawableResource.java
+1
-1
library/src/main/java/com/bumptech/glide/load/resource/drawable/DrawableResource.java
...mptech/glide/load/resource/drawable/DrawableResource.java
+0
-29
library/src/main/java/com/bumptech/glide/load/resource/transcode/BitmapDrawableTranscoder.java
...ide/load/resource/transcode/BitmapDrawableTranscoder.java
+1
-1
library/src/main/java/com/bumptech/glide/load/resource/transcode/GifBitmapWrapperDrawableTranscoder.java
...esource/transcode/GifBitmapWrapperDrawableTranscoder.java
+39
-0
library/src/test/java/com/bumptech/glide/load/resource/bitmap/BitmapDrawableResourceTest.java
...lide/load/resource/bitmap/BitmapDrawableResourceTest.java
+1
-1
library/src/test/java/com/bumptech/glide/load/resource/drawable/DrawableResourceTest.java
...ch/glide/load/resource/drawable/DrawableResourceTest.java
+0
-47
library/src/test/java/com/bumptech/glide/load/resource/transcode/GifBitmapWrapperDrawableTranscoderTest.java
...rce/transcode/GifBitmapWrapperDrawableTranscoderTest.java
+15
-40
未找到文件。
library/src/main/java/com/bumptech/glide/Glide.java
浏览文件 @
44b89ba4
...
...
@@ -38,7 +38,8 @@ import com.bumptech.glide.load.resource.gif.GifDataLoadProvider;
import
com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapper
;
import
com.bumptech.glide.load.resource.gifbitmap.ImageVideoGifDataLoadProvider
;
import
com.bumptech.glide.load.resource.transcode.BitmapDrawableTranscoder
;
import
com.bumptech.glide.load.resource.transcode.GifBitmapDrawableTranscoder
;
import
com.bumptech.glide.load.resource.transcode.GifBitmapWrapperDrawableTranscoder
;
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.provider.DataLoadProviderFactory
;
...
...
@@ -188,7 +189,8 @@ public class Glide {
transcoderFactory
.
register
(
Bitmap
.
class
,
BitmapDrawable
.
class
,
new
BitmapDrawableTranscoder
(
context
.
getResources
(),
bitmapPool
));
transcoderFactory
.
register
(
GifBitmapWrapper
.
class
,
Drawable
.
class
,
new
GifBitmapDrawableTranscoder
(
context
));
new
GifBitmapWrapperDrawableTranscoder
(
new
BitmapDrawableTranscoder
(
context
.
getResources
(),
bitmapPool
),
new
GifDataDrawableTranscoder
()));
}
public
BitmapPool
getBitmapPool
()
{
...
...
library/src/main/java/com/bumptech/glide/load/resource/
drawable
/BitmapDrawableResource.java
→
library/src/main/java/com/bumptech/glide/load/resource/
bitmap
/BitmapDrawableResource.java
浏览文件 @
44b89ba4
package
com.bumptech.glide.load.resource.
drawable
;
package
com.bumptech.glide.load.resource.
bitmap
;
import
android.graphics.drawable.BitmapDrawable
;
import
com.bumptech.glide.Resource
;
...
...
library/src/main/java/com/bumptech/glide/load/resource/drawable/DrawableResource.java
已删除
100644 → 0
浏览文件 @
50f743d6
package
com.bumptech.glide.load.resource.drawable
;
import
android.graphics.drawable.Drawable
;
import
com.bumptech.glide.Resource
;
public
class
DrawableResource
extends
Resource
<
Drawable
>
{
private
final
Drawable
drawable
;
private
final
Resource
wrapped
;
public
DrawableResource
(
Drawable
drawable
,
Resource
wrapped
)
{
this
.
drawable
=
drawable
;
this
.
wrapped
=
wrapped
;
}
@Override
public
Drawable
get
()
{
return
drawable
;
}
@Override
public
int
getSize
()
{
return
wrapped
.
getSize
();
}
@Override
protected
void
recycleInternal
()
{
wrapped
.
recycle
();
}
}
library/src/main/java/com/bumptech/glide/load/resource/transcode/BitmapDrawableTranscoder.java
浏览文件 @
44b89ba4
...
...
@@ -4,7 +4,7 @@ import android.content.res.Resources;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.BitmapDrawable
;
import
com.bumptech.glide.Resource
;
import
com.bumptech.glide.load.resource.
drawable
.BitmapDrawableResource
;
import
com.bumptech.glide.load.resource.
bitmap
.BitmapDrawableResource
;
import
com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
;
public
class
BitmapDrawableTranscoder
implements
ResourceTranscoder
<
Bitmap
,
BitmapDrawable
>
{
...
...
library/src/main/java/com/bumptech/glide/load/resource/transcode/GifBitmapDrawableTranscoder.java
→
library/src/main/java/com/bumptech/glide/load/resource/transcode/GifBitmap
Wrapper
DrawableTranscoder.java
浏览文件 @
44b89ba4
package
com.bumptech.glide.load.resource.transcode
;
import
android.content.Context
;
import
android.content.res.Resources
;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.graphics.drawable.Drawable
;
import
com.bumptech.glide.Resource
;
import
com.bumptech.glide.load.resource.
drawable.DrawableResource
;
import
com.bumptech.glide.load.resource.
gif.GifData
;
import
com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapper
;
public
class
GifBitmapDrawableTranscoder
implements
ResourceTranscoder
<
GifBitmapWrapper
,
Drawable
>
{
private
final
Resources
resources
;
public
class
GifBitmapWrapperDrawableTranscoder
implements
ResourceTranscoder
<
GifBitmapWrapper
,
Drawable
>
{
private
final
ResourceTranscoder
<
Bitmap
,
?
extends
Drawable
>
bitmapDrawableResourceTranscoder
;
private
final
ResourceTranscoder
<
GifData
,
?
extends
Drawable
>
gifDrawableResourceTranscoder
;
public
GifBitmapDrawableTranscoder
(
Context
context
)
{
resources
=
context
.
getResources
();
public
GifBitmapWrapperDrawableTranscoder
(
ResourceTranscoder
<
Bitmap
,
?
extends
Drawable
>
bitmapDrawableResourceTranscoder
,
ResourceTranscoder
<
GifData
,
?
extends
Drawable
>
gifDrawableResourceTranscoder
)
{
this
.
bitmapDrawableResourceTranscoder
=
bitmapDrawableResourceTranscoder
;
this
.
gifDrawableResourceTranscoder
=
gifDrawableResourceTranscoder
;
}
@SuppressWarnings
(
"unchecked"
)
@Override
public
Resource
<
Drawable
>
transcode
(
Resource
<
GifBitmapWrapper
>
toTranscode
)
{
GifBitmapWrapper
gifBitmap
=
toTranscode
.
get
();
Resource
<
Bitmap
>
bitmapResource
=
gifBitmap
.
getBitmapResource
();
final
Resource
resource
;
final
Drawable
drawable
;
final
Resource
<?
extends
Drawable
>
result
;
if
(
bitmapResource
!=
null
)
{
resource
=
bitmapResource
;
drawable
=
new
BitmapDrawable
(
resources
,
bitmapResource
.
get
());
result
=
bitmapDrawableResourceTranscoder
.
transcode
(
bitmapResource
);
}
else
{
resource
=
gifBitmap
.
getGifResource
();
drawable
=
gifBitmap
.
getGifResource
().
get
().
getDrawable
();
result
=
gifDrawableResourceTranscoder
.
transcode
(
gifBitmap
.
getGifResource
());
}
return
new
DrawableResource
(
drawable
,
resource
);
// This is unchecked but always safe, anything that extends a Drawable can be safely cast to a Drawable.
return
(
Resource
<
Drawable
>)
result
;
}
@Override
public
String
getId
()
{
return
"GifBitmapDrawableTranscoder.com.bumptech.glide.load.resource.transcode"
;
return
"GifBitmap
Wrapper
DrawableTranscoder.com.bumptech.glide.load.resource.transcode"
;
}
}
library/src/test/java/com/bumptech/glide/load/resource/
drawable
/BitmapDrawableResourceTest.java
→
library/src/test/java/com/bumptech/glide/load/resource/
bitmap
/BitmapDrawableResourceTest.java
浏览文件 @
44b89ba4
package
com.bumptech.glide.load.resource.
drawable
;
package
com.bumptech.glide.load.resource.
bitmap
;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.BitmapDrawable
;
...
...
library/src/test/java/com/bumptech/glide/load/resource/drawable/DrawableResourceTest.java
已删除
100644 → 0
浏览文件 @
50f743d6
package
com.bumptech.glide.load.resource.drawable
;
import
android.graphics.Color
;
import
android.graphics.drawable.ColorDrawable
;
import
com.bumptech.glide.Resource
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.RobolectricTestRunner
;
import
static
junit
.
framework
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
RobolectricTestRunner
.
class
)
public
class
DrawableResourceTest
{
private
ColorDrawable
drawable
;
private
DrawableResource
resource
;
private
Resource
wrapped
;
@Before
public
void
setUp
()
{
drawable
=
new
ColorDrawable
(
Color
.
RED
);
wrapped
=
mock
(
Resource
.
class
);
resource
=
new
DrawableResource
(
drawable
,
wrapped
);
}
@Test
public
void
testReturnsGivenSize
()
{
final
int
size
=
100
;
when
(
wrapped
.
getSize
()).
thenReturn
(
size
);
assertEquals
(
size
,
resource
.
getSize
());
}
@Test
public
void
testGetReturnsGivenDrawable
()
{
assertEquals
(
drawable
,
resource
.
get
());
}
@Test
public
void
testRecyclesWrappedWhenRecycled
()
{
resource
.
recycleInternal
();
verify
(
wrapped
).
recycle
();
}
}
library/src/test/java/com/bumptech/glide/load/resource/transcode/GifBitmapDrawableTranscoderTest.java
→
library/src/test/java/com/bumptech/glide/load/resource/transcode/GifBitmap
Wrapper
DrawableTranscoderTest.java
浏览文件 @
44b89ba4
package
com.bumptech.glide.load.resource.transcode
;
import
android.graphics.Bitmap
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.graphics.drawable.Drawable
;
import
com.bumptech.glide.Resource
;
import
com.bumptech.glide.load.resource.gif.GifData
;
import
com.bumptech.glide.load.resource.gif.GifDrawable
;
import
com.bumptech.glide.load.resource.gifbitmap.GifBitmapWrapper
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.Robolectric
;
import
org.robolectric.RobolectricTestRunner
;
import
static
junit
.
framework
.
Assert
.
assertEquals
;
import
static
junit
.
framework
.
Assert
.
assertNotNull
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
RobolectricTestRunner
.
class
)
public
class
GifBitmapDrawableTranscoderTest
{
private
GifBitmapDrawableTranscoder
transcoder
;
public
class
GifBitmapWrapperDrawableTranscoderTest
{
private
GifBitmapWrapperDrawableTranscoder
transcoder
;
private
ResourceTranscoder
<
Bitmap
,
Drawable
>
bitmapTranscoder
;
private
ResourceTranscoder
<
GifData
,
Drawable
>
gifDataTranscoder
;
@Before
public
void
setUp
()
{
transcoder
=
new
GifBitmapDrawableTranscoder
(
Robolectric
.
application
);
bitmapTranscoder
=
mock
(
ResourceTranscoder
.
class
);
gifDataTranscoder
=
mock
(
ResourceTranscoder
.
class
);
transcoder
=
new
GifBitmapWrapperDrawableTranscoder
(
bitmapTranscoder
,
gifDataTranscoder
);
}
@Test
public
void
testReturns
BitmapDrawable
IfGifBitmapHasBitmap
()
{
public
void
testReturns
DrawableFromBitmapTranscoder
IfGifBitmapHasBitmap
()
{
GifBitmapWithBitmapHarness
harness
=
new
GifBitmapWithBitmapHarness
();
when
(
bitmapTranscoder
.
transcode
(
eq
(
harness
.
bitmapResource
))).
thenReturn
(
harness
.
expected
);
BitmapDrawable
transcoded
=
(
BitmapDrawable
)
transcoder
.
transcode
(
harness
.
gifBitmapResource
).
get
();
assertEquals
(
harness
.
expected
,
transcoded
.
getBitmap
());
}
@Test
public
void
testReturnedResourceHasBitmapSizeIfGifBitmapHasBitmap
()
{
final
int
size
=
100
;
GifBitmapWithBitmapHarness
harness
=
new
GifBitmapWithBitmapHarness
();
when
(
harness
.
bitmapResource
.
getSize
()).
thenReturn
(
size
);
Resource
<
Drawable
>
transcoded
=
transcoder
.
transcode
(
harness
.
gifBitmapResource
);
assertEquals
(
size
,
transcoded
.
getSize
());
assertEquals
(
harness
.
expected
,
transcoder
.
transcode
(
harness
.
gifBitmapResource
));
}
@Test
public
void
testReturns
GifDrawable
IfGifBitmapHasGif
()
{
public
void
testReturns
DrawableFromGifTranscoder
IfGifBitmapHasGif
()
{
GifBitmapWithGifHarness
harness
=
new
GifBitmapWithGifHarness
();
when
(
gifDataTranscoder
.
transcode
(
eq
(
harness
.
gifResource
))).
thenReturn
(
harness
.
expected
);
Drawable
transcoded
=
transcoder
.
transcode
(
harness
.
gifBitmapResource
).
get
();
assertEquals
(
harness
.
expected
,
transcoded
);
}
@Test
public
void
testReturnedResourceHasGifDrawableSizeIfGifBitmapHasGif
()
{
final
int
size
=
200
;
GifBitmapWithGifHarness
harness
=
new
GifBitmapWithGifHarness
();
when
(
harness
.
gifResource
.
getSize
()).
thenReturn
(
size
);
Resource
<
Drawable
>
transcoded
=
transcoder
.
transcode
(
harness
.
gifBitmapResource
);
assertEquals
(
size
,
transcoded
.
getSize
());
assertEquals
(
harness
.
expected
,
transcoder
.
transcode
(
harness
.
gifBitmapResource
));
}
@Test
...
...
@@ -75,6 +53,7 @@ public class GifBitmapDrawableTranscoderTest {
private
static
class
TranscoderHarness
{
Resource
<
GifBitmapWrapper
>
gifBitmapResource
=
mock
(
Resource
.
class
);
GifBitmapWrapper
gifBitmap
=
mock
(
GifBitmapWrapper
.
class
);
Resource
<
Drawable
>
expected
=
mock
(
Resource
.
class
);
public
TranscoderHarness
()
{
when
(
gifBitmapResource
.
get
()).
thenReturn
(
gifBitmap
);
...
...
@@ -82,24 +61,20 @@ public class GifBitmapDrawableTranscoderTest {
}
private
static
class
GifBitmapWithBitmapHarness
extends
TranscoderHarness
{
Bitmap
expected
=
Bitmap
.
createBitmap
(
100
,
200
,
Bitmap
.
Config
.
ARGB_8888
);
Resource
<
Bitmap
>
bitmapResource
=
mock
(
Resource
.
class
);
public
GifBitmapWithBitmapHarness
()
{
super
();
when
(
bitmapResource
.
get
()).
thenReturn
(
expected
);
when
(
gifBitmap
.
getBitmapResource
()).
thenReturn
(
bitmapResource
);
}
}
private
static
class
GifBitmapWithGifHarness
extends
TranscoderHarness
{
GifDrawable
expected
=
mock
(
GifDrawable
.
class
);
GifData
gifData
=
mock
(
GifData
.
class
);
Resource
<
GifData
>
gifResource
=
mock
(
Resource
.
class
);
public
GifBitmapWithGifHarness
()
{
super
();
when
(
gifData
.
getDrawable
()).
thenReturn
(
expected
);
when
(
gifResource
.
get
()).
thenReturn
(
gifData
);
when
(
gifBitmap
.
getGifResource
()).
thenReturn
(
gifResource
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录