Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
38ced22f
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 搜索 >>
提交
38ced22f
编写于
10月 20, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Apply gravity in GifDrawable.
Fixes #206
上级
3ea7f151
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
9 deletion
+35
-9
library/src/androidTest/java/com/bumptech/glide/load/resource/gif/GifDrawableTest.java
...com/bumptech/glide/load/resource/gif/GifDrawableTest.java
+16
-8
library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawable.java
...ava/com/bumptech/glide/load/resource/gif/GifDrawable.java
+19
-1
未找到文件。
library/src/androidTest/java/com/bumptech/glide/load/resource/gif/GifDrawableTest.java
浏览文件 @
38ced22f
...
...
@@ -4,6 +4,7 @@ import android.graphics.Bitmap;
import
android.graphics.Canvas
;
import
android.graphics.Paint
;
import
android.graphics.PixelFormat
;
import
android.graphics.Rect
;
import
android.graphics.drawable.Drawable
;
import
com.bumptech.glide.gifdecoder.GifDecoder
;
import
com.bumptech.glide.gifdecoder.GifHeader
;
...
...
@@ -23,7 +24,6 @@ import static org.junit.Assert.assertFalse;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Matchers
.
anyInt
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Matchers
.
isNull
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -60,7 +60,7 @@ public class GifDrawableTest {
Canvas
canvas
=
mock
(
Canvas
.
class
);
drawable
.
draw
(
canvas
);
verify
(
canvas
).
drawBitmap
(
eq
(
firstFrame
),
any
Int
(),
anyInt
(),
any
(
Paint
.
class
));
verify
(
canvas
).
drawBitmap
(
eq
(
firstFrame
),
any
Rect
(),
anyRect
(),
anyPaint
(
));
}
@Test
...
...
@@ -71,8 +71,8 @@ public class GifDrawableTest {
when
(
frameManager
.
getCurrentFrame
()).
thenReturn
(
null
);
drawable
.
draw
(
canvas
);
verify
(
canvas
).
drawBitmap
(
eq
(
firstFrame
),
any
Int
(),
anyInt
(),
any
(
Paint
.
class
));
verify
(
canvas
,
never
()).
drawBitmap
((
Bitmap
)
isNull
(),
any
Int
(),
anyInt
(),
any
(
Paint
.
class
));
verify
(
canvas
).
drawBitmap
(
eq
(
firstFrame
),
any
Rect
(),
anyRect
(),
anyPaint
(
));
verify
(
canvas
,
never
()).
drawBitmap
((
Bitmap
)
isNull
(),
any
Rect
(),
anyRect
(),
anyPaint
(
));
}
@Test
...
...
@@ -80,7 +80,7 @@ public class GifDrawableTest {
drawable
=
new
GifDrawable
(
gifDecoder
,
frameManager
,
null
,
bitmapPool
);
Canvas
canvas
=
mock
(
Canvas
.
class
);
verify
(
canvas
,
never
()).
drawBitmap
(
any
(
Bitmap
.
class
),
any
Int
(),
anyInt
(),
any
(
Paint
.
class
));
verify
(
canvas
,
never
()).
drawBitmap
(
any
(
Bitmap
.
class
),
any
Rect
(),
anyRect
(),
anyPaint
(
));
}
@Test
...
...
@@ -90,8 +90,8 @@ public class GifDrawableTest {
when
(
frameManager
.
getCurrentFrame
()).
thenReturn
(
currentFrame
);
drawable
.
draw
(
canvas
);
verify
(
canvas
).
drawBitmap
(
eq
(
currentFrame
),
any
Int
(),
anyInt
(),
any
(
Paint
.
class
));
verify
(
canvas
,
never
()).
drawBitmap
(
eq
(
firstFrame
),
any
Int
(),
anyInt
(),
any
(
Paint
.
class
));
verify
(
canvas
).
drawBitmap
(
eq
(
currentFrame
),
any
Rect
(),
anyRect
(),
anyPaint
(
));
verify
(
canvas
,
never
()).
drawBitmap
(
eq
(
firstFrame
),
any
Rect
(),
anyRect
(),
anyPaint
(
));
}
@Test
...
...
@@ -459,7 +459,15 @@ public class GifDrawableTest {
drawable
.
recycle
();
Canvas
canvas
=
mock
(
Canvas
.
class
);
drawable
.
draw
(
canvas
);
verify
(
canvas
,
never
()).
drawBitmap
(
any
(
Bitmap
.
class
),
anyInt
(),
anyInt
(),
any
(
Paint
.
class
));
verify
(
canvas
,
never
()).
drawBitmap
(
any
(
Bitmap
.
class
),
anyRect
(),
anyRect
(),
anyPaint
());
}
private
static
Paint
anyPaint
()
{
return
any
(
Paint
.
class
);
}
private
static
Rect
anyRect
()
{
return
any
(
Rect
.
class
);
}
private
void
runLoops
(
int
loopCount
,
int
frameCount
)
{
...
...
library/src/main/java/com/bumptech/glide/load/resource/gif/GifDrawable.java
浏览文件 @
38ced22f
...
...
@@ -8,9 +8,11 @@ import android.graphics.Canvas;
import
android.graphics.ColorFilter
;
import
android.graphics.Paint
;
import
android.graphics.PixelFormat
;
import
android.graphics.Rect
;
import
android.graphics.drawable.Drawable
;
import
android.os.Build
;
import
android.view.Gravity
;
import
com.bumptech.glide.gifdecoder.GifDecoder
;
import
com.bumptech.glide.gifdecoder.GifHeader
;
import
com.bumptech.glide.load.Transformation
;
...
...
@@ -22,6 +24,7 @@ import com.bumptech.glide.load.resource.drawable.GlideDrawable;
*/
public
class
GifDrawable
extends
GlideDrawable
implements
GifFrameManager
.
FrameCallback
{
private
final
Paint
paint
=
new
Paint
();
private
final
Rect
destRect
=
new
Rect
();
private
final
GifFrameManager
frameManager
;
private
final
GifState
state
;
private
final
GifDecoder
decoder
;
...
...
@@ -43,6 +46,8 @@ public class GifDrawable extends GlideDrawable implements GifFrameManager.FrameC
/** The number of times to loop through the gif animation. */
private
int
maxLoopCount
=
LOOP_FOREVER
;
private
boolean
applyGravity
;
/**
* Constructor for GifDrawable.
*
...
...
@@ -177,14 +182,26 @@ public class GifDrawable extends GlideDrawable implements GifFrameManager.FrameC
this
.
isRunning
=
isRunning
;
}
@Override
protected
void
onBoundsChange
(
Rect
bounds
)
{
super
.
onBoundsChange
(
bounds
);
applyGravity
=
true
;
}
@Override
public
void
draw
(
Canvas
canvas
)
{
if
(
isRecycled
)
{
return
;
}
if
(
applyGravity
)
{
Gravity
.
apply
(
GifState
.
GRAVITY
,
getIntrinsicWidth
(),
getIntrinsicHeight
(),
getBounds
(),
destRect
);
applyGravity
=
false
;
}
Bitmap
currentFrame
=
frameManager
.
getCurrentFrame
();
Bitmap
toDraw
=
currentFrame
!=
null
?
currentFrame
:
state
.
firstFrame
;
canvas
.
drawBitmap
(
toDraw
,
0
,
0
,
paint
);
canvas
.
drawBitmap
(
toDraw
,
null
,
destRect
,
paint
);
}
@Override
...
...
@@ -266,6 +283,7 @@ public class GifDrawable extends GlideDrawable implements GifFrameManager.FrameC
}
static
class
GifState
extends
ConstantState
{
private
static
final
int
GRAVITY
=
Gravity
.
FILL
;
String
id
;
GifHeader
gifHeader
;
byte
[]
data
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录