Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
a23b64f5
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,发现更多精彩内容 >>
提交
a23b64f5
编写于
7月 09, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add constant state to GifDrawable.
上级
29bc834c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
115 addition
and
15 deletion
+115
-15
library/src/main/java/com/bumptech/glide/load/resource/gif/GifData.java
...in/java/com/bumptech/glide/load/resource/gif/GifData.java
+2
-6
library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawable.java
...ava/com/bumptech/glide/load/resource/gif/GifDrawable.java
+85
-9
library/src/test/java/com/bumptech/glide/load/resource/gif/GifDataTest.java
...ava/com/bumptech/glide/load/resource/gif/GifDataTest.java
+2
-0
library/src/test/java/com/bumptech/glide/load/resource/gif/GifDrawableTest.java
...com/bumptech/glide/load/resource/gif/GifDrawableTest.java
+26
-0
未找到文件。
library/src/main/java/com/bumptech/glide/load/resource/gif/GifData.java
浏览文件 @
a23b64f5
...
...
@@ -84,12 +84,8 @@ public class GifData {
* the wrapped GIF.
*/
public
GifDrawable
getDrawable
()
{
GifDecoder
gifDecoder
=
new
GifDecoder
(
bitmapProvider
);
gifDecoder
.
setData
(
gifId
,
header
,
data
);
GifFrameManager
frameManager
=
new
GifFrameManager
(
context
,
gifDecoder
,
getFrameTransformation
(),
targetWidth
,
targetHeight
);
GifDrawable
result
=
new
GifDrawable
(
gifDecoder
,
frameManager
);
GifDrawable
result
=
new
GifDrawable
(
gifId
,
header
,
data
,
context
,
getFrameTransformation
(),
targetWidth
,
targetHeight
,
bitmapProvider
);
drawables
.
add
(
result
);
return
result
;
}
...
...
library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawable.java
浏览文件 @
a23b64f5
package
com.bumptech.glide.load.resource.gif
;
import
android.annotation.TargetApi
;
import
android.content.Context
;
import
android.content.res.Resources
;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
import
android.graphics.ColorFilter
;
...
...
@@ -11,30 +13,47 @@ import android.graphics.drawable.Drawable;
import
android.os.Build
;
import
com.bumptech.glide.gifdecoder.GifDecoder
;
import
com.bumptech.glide.gifdecoder.GifHeader
;
import
com.bumptech.glide.load.Transformation
;
/**
* An animated {@link android.graphics.drawable.Drawable} that plays the frames of an animated GIF.
*/
public
class
GifDrawable
extends
Drawable
implements
Animatable
,
GifFrameManager
.
FrameCallback
{
private
final
Paint
paint
;
private
final
GifFrameManager
frameManager
;
private
int
width
;
private
int
height
;
private
final
Paint
paint
=
new
Paint
();
private
GifFrameManager
frameManager
;
private
GifState
state
;
private
int
width
=
-
1
;
private
int
height
=
-
1
;
private
GifDecoder
decoder
;
private
boolean
isRunning
;
private
Bitmap
currentFrame
;
private
boolean
isRecycled
;
public
GifDrawable
(
GifDecoder
decoder
,
GifFrameManager
frameManager
)
{
public
GifDrawable
(
String
id
,
GifHeader
gifHeader
,
byte
[]
data
,
Context
context
,
Transformation
<
Bitmap
>
frameTransformation
,
int
targetWidth
,
int
targetHeight
,
GifDecoder
.
BitmapProvider
bitmapProvider
)
{
this
(
new
GifState
(
id
,
gifHeader
,
data
,
context
,
frameTransformation
,
targetWidth
,
targetHeight
,
bitmapProvider
));
}
private
GifDrawable
(
GifState
state
)
{
this
.
state
=
state
;
this
.
decoder
=
new
GifDecoder
(
state
.
bitmapProvider
);
decoder
.
setData
(
state
.
id
,
state
.
gifHeader
,
state
.
data
);
frameManager
=
new
GifFrameManager
(
state
.
context
,
decoder
,
state
.
frameTransformation
,
state
.
targetWidth
,
state
.
targetHeight
);
}
// For testing.
GifDrawable
(
GifDecoder
decoder
,
GifFrameManager
frameManager
)
{
this
.
decoder
=
decoder
;
this
.
frameManager
=
frameManager
;
width
=
-
1
;
height
=
-
1
;
paint
=
new
Paint
();
this
.
state
=
new
GifState
(
null
);
}
@Override
public
void
start
()
{
if
(!
isRunning
)
{
...
...
@@ -126,6 +145,11 @@ public class GifDrawable extends Drawable implements Animatable, GifFrameManager
frameManager
.
getNextFrame
(
this
);
}
@Override
public
ConstantState
getConstantState
()
{
return
state
;
}
/**
* Clears any resources for loading frames that are currently held on to by this object.
*/
...
...
@@ -137,4 +161,56 @@ public class GifDrawable extends Drawable implements Animatable, GifFrameManager
boolean
isRecycled
()
{
return
isRecycled
;
}
static
class
GifState
extends
ConstantState
{
String
id
;
GifHeader
gifHeader
;
byte
[]
data
;
Context
context
;
Transformation
<
Bitmap
>
frameTransformation
;
int
targetWidth
;
int
targetHeight
;
GifDecoder
.
BitmapProvider
bitmapProvider
;
public
GifState
(
String
id
,
GifHeader
header
,
byte
[]
data
,
Context
context
,
Transformation
<
Bitmap
>
frameTransformation
,
int
targetWidth
,
int
targetHeight
,
GifDecoder
.
BitmapProvider
provider
)
{
this
.
id
=
id
;
gifHeader
=
header
;
this
.
data
=
data
;
this
.
context
=
context
.
getApplicationContext
();
this
.
frameTransformation
=
frameTransformation
;
this
.
targetWidth
=
targetWidth
;
this
.
targetHeight
=
targetHeight
;
bitmapProvider
=
provider
;
}
public
GifState
(
GifState
original
)
{
if
(
original
!=
null
)
{
id
=
original
.
id
;
gifHeader
=
original
.
gifHeader
;
data
=
original
.
data
;
context
=
original
.
context
;
frameTransformation
=
original
.
frameTransformation
;
targetWidth
=
original
.
targetWidth
;
targetHeight
=
original
.
targetHeight
;
bitmapProvider
=
original
.
bitmapProvider
;
}
}
@Override
public
Drawable
newDrawable
(
Resources
res
)
{
return
super
.
newDrawable
(
res
);
}
@Override
public
Drawable
newDrawable
()
{
return
new
GifDrawable
(
this
);
}
@Override
public
int
getChangingConfigurations
()
{
return
0
;
}
}
}
library/src/test/java/com/bumptech/glide/load/resource/gif/GifDataTest.java
浏览文件 @
a23b64f5
package
com.bumptech.glide.load.resource.gif
;
import
android.graphics.Bitmap
;
import
com.bumptech.glide.gifdecoder.GifHeader
;
import
com.bumptech.glide.load.Transformation
;
import
com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
;
import
com.bumptech.glide.tests.GlideShadowLooper
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
...
...
library/src/test/java/com/bumptech/glide/load/resource/gif/GifDrawableTest.java
浏览文件 @
a23b64f5
...
...
@@ -5,14 +5,22 @@ import android.graphics.Canvas;
import
android.graphics.Paint
;
import
android.graphics.PixelFormat
;
import
android.graphics.drawable.Drawable
;
import
com.bumptech.glide.gifdecoder.GifDecoder
;
import
com.bumptech.glide.gifdecoder.GifHeader
;
import
com.bumptech.glide.load.Transformation
;
import
com.bumptech.glide.tests.GlideShadowLooper
;
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
static
junit
.
framework
.
Assert
.
assertEquals
;
import
static
junit
.
framework
.
Assert
.
assertFalse
;
import
static
junit
.
framework
.
Assert
.
assertNotNull
;
import
static
junit
.
framework
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anyInt
;
...
...
@@ -25,6 +33,7 @@ import static org.mockito.Mockito.verify;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
RobolectricTestRunner
.
class
)
@Config
(
shadows
=
GlideShadowLooper
.
class
)
public
class
GifDrawableTest
{
private
GifDecoder
gifDecoder
;
private
GifDrawable
drawable
;
...
...
@@ -210,4 +219,21 @@ public class GifDrawableTest {
assertTrue
(
drawable
.
isRecycled
());
}
@Test
public
void
testReturnsNonNullConstantState
()
{
assertNotNull
(
drawable
.
getConstantState
());
}
@Test
public
void
testReturnsNewDrawableFromConstantState
()
{
GifHeader
gifHeader
=
mock
(
GifHeader
.
class
);
Transformation
<
Bitmap
>
transformation
=
mock
(
Transformation
.
class
);
GifDecoder
.
BitmapProvider
provider
=
mock
(
GifDecoder
.
BitmapProvider
.
class
);
drawable
=
new
GifDrawable
(
"fakeId"
,
gifHeader
,
new
byte
[
0
],
Robolectric
.
application
,
transformation
,
100
,
100
,
provider
);
assertNotNull
(
drawable
.
getConstantState
().
newDrawable
());
assertNotNull
(
drawable
.
getConstantState
().
newDrawable
(
Robolectric
.
application
.
getResources
()));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录