Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
69aee752
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,发现更多精彩内容 >>
提交
69aee752
编写于
11月 02, 2014
作者:
S
Sam Judd
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make AnimationFactorys top level and add tests.
上级
34f797ba
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
336 addition
and
185 deletion
+336
-185
library/src/androidTest/java/com/bumptech/glide/request/animation/DrawableCrossFadeFactoryTest.java
...glide/request/animation/DrawableCrossFadeFactoryTest.java
+43
-0
library/src/androidTest/java/com/bumptech/glide/request/animation/ViewAnimationFactoryTest.java
...ech/glide/request/animation/ViewAnimationFactoryTest.java
+56
-0
library/src/androidTest/java/com/bumptech/glide/request/animation/ViewPropertyAnimationFactoryTest.java
...e/request/animation/ViewPropertyAnimationFactoryTest.java
+37
-0
library/src/main/java/com/bumptech/glide/DrawableRequestBuilder.java
.../main/java/com/bumptech/glide/DrawableRequestBuilder.java
+5
-5
library/src/main/java/com/bumptech/glide/GenericRequestBuilder.java
...c/main/java/com/bumptech/glide/GenericRequestBuilder.java
+6
-5
library/src/main/java/com/bumptech/glide/GifRequestBuilder.java
...y/src/main/java/com/bumptech/glide/GifRequestBuilder.java
+5
-5
library/src/main/java/com/bumptech/glide/request/animation/DrawableCrossFadeFactory.java
...ech/glide/request/animation/DrawableCrossFadeFactory.java
+72
-0
library/src/main/java/com/bumptech/glide/request/animation/DrawableCrossFadeViewAnimation.java
...ide/request/animation/DrawableCrossFadeViewAnimation.java
+0
-68
library/src/main/java/com/bumptech/glide/request/animation/ViewAnimation.java
...a/com/bumptech/glide/request/animation/ViewAnimation.java
+0
-72
library/src/main/java/com/bumptech/glide/request/animation/ViewAnimationFactory.java
...umptech/glide/request/animation/ViewAnimationFactory.java
+78
-0
library/src/main/java/com/bumptech/glide/request/animation/ViewPropertyAnimation.java
...mptech/glide/request/animation/ViewPropertyAnimation.java
+0
-30
library/src/main/java/com/bumptech/glide/request/animation/ViewPropertyAnimationFactory.java
...glide/request/animation/ViewPropertyAnimationFactory.java
+34
-0
未找到文件。
library/src/androidTest/java/com/bumptech/glide/request/animation/DrawableCrossFadeFactoryTest.java
0 → 100644
浏览文件 @
69aee752
package
com.bumptech.glide.request.animation
;
import
android.graphics.drawable.Drawable
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.robolectric.RobolectricTestRunner
;
import
org.robolectric.annotation.Config
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotEquals
;
import
static
org
.
mockito
.
Mockito
.
mock
;
@RunWith
(
RobolectricTestRunner
.
class
)
@Config
(
manifest
=
Config
.
NONE
,
emulateSdk
=
18
)
public
class
DrawableCrossFadeFactoryTest
{
private
DrawableCrossFadeFactory
<
Drawable
>
factory
;
@SuppressWarnings
(
"unchecked"
)
@Before
public
void
setUp
()
{
ViewAnimationFactory
<
Drawable
>
viewAnimationFactory
=
mock
(
ViewAnimationFactory
.
class
);
factory
=
new
DrawableCrossFadeFactory
<
Drawable
>(
viewAnimationFactory
,
100
/*duration*/
);
}
@Test
public
void
testReturnsNoAnimationIfFromMemoryCache
()
{
assertEquals
(
NoAnimation
.<
Drawable
>
get
(),
factory
.
build
(
true
/*isFromMemoryCache*/
,
true
/*isFirstResource*/
));
}
@Test
public
void
testReturnsReturnsAnimationIfNotFromMemoryCacheAndIsFirstResource
()
{
assertNotEquals
(
NoAnimation
.<
Drawable
>
get
(),
factory
.
build
(
false
/*isFromMemoryCache*/
,
true
/*isFirstResource*/
));
}
@Test
public
void
testReturnsAnimationIfNotFromMemocyCacheAndNotIsFirstResource
()
{
assertNotEquals
(
NoAnimation
.<
Drawable
>
get
(),
factory
.
build
(
false
/*isFromMemoryCache*/
,
false
/*isFirstResource*/
));
}
}
\ No newline at end of file
library/src/androidTest/java/com/bumptech/glide/request/animation/ViewAnimationFactoryTest.java
0 → 100644
浏览文件 @
69aee752
package
com.bumptech.glide.request.animation
;
import
android.view.View
;
import
android.view.animation.Animation
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.JUnit4
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
never
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
JUnit4
.
class
)
public
class
ViewAnimationFactoryTest
{
private
ViewAnimation
.
AnimationFactory
animationFactory
;
private
ViewAnimationFactory
<
Object
>
factory
;
@Before
public
void
setUp
()
{
animationFactory
=
mock
(
ViewAnimation
.
AnimationFactory
.
class
);
factory
=
new
ViewAnimationFactory
<
Object
>(
animationFactory
);
}
@Test
public
void
testFactoryReturnsNoAnimationIfFromMemoryCache
()
{
GlideAnimation
<
Object
>
animation
=
factory
.
build
(
true
/*isFromMemoryCache*/
,
true
/*isFirstResource*/
);
assertEquals
(
NoAnimation
.
get
(),
animation
);
verify
(
animationFactory
,
never
()).
build
();
}
@Test
public
void
testFactoryReturnsNoAnimationIfNotFirstResource
()
{
GlideAnimation
<
Object
>
animation
=
factory
.
build
(
false
/*isFromMemoryCache*/
,
false
/*isFirstResource*/
);
assertEquals
(
NoAnimation
.
get
(),
animation
);
verify
(
animationFactory
,
never
()).
build
();
}
@Test
public
void
testFactoryReturnsActualAnimationIfNotIsFromMemoryCacheAndIsFirstResource
()
{
GlideAnimation
<
Object
>
glideAnimation
=
factory
.
build
(
false
/*isFromMemoryCache*/
,
true
/*isFirstResource*/
);
Animation
animation
=
mock
(
Animation
.
class
);
when
(
animationFactory
.
build
()).
thenReturn
(
animation
);
GlideAnimation
.
ViewAdapter
adapter
=
mock
(
GlideAnimation
.
ViewAdapter
.
class
);
View
view
=
mock
(
View
.
class
);
when
(
adapter
.
getView
()).
thenReturn
(
view
);
glideAnimation
.
animate
(
new
Object
(),
adapter
);
verify
(
view
).
startAnimation
(
eq
(
animation
));
}
}
\ No newline at end of file
library/src/androidTest/java/com/bumptech/glide/request/animation/ViewPropertyAnimationFactoryTest.java
0 → 100644
浏览文件 @
69aee752
package
com.bumptech.glide.request.animation
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.JUnit4
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotEquals
;
import
static
org
.
mockito
.
Mockito
.
mock
;
@RunWith
(
JUnit4
.
class
)
public
class
ViewPropertyAnimationFactoryTest
{
private
ViewPropertyAnimationFactory
<
Object
>
factory
;
@Before
public
void
setUp
()
{
ViewPropertyAnimation
.
Animator
animator
=
mock
(
ViewPropertyAnimation
.
Animator
.
class
);
factory
=
new
ViewPropertyAnimationFactory
<
Object
>(
animator
);
}
@Test
public
void
testReturnsNoAnimationIfFromMemoryCache
()
{
assertEquals
(
NoAnimation
.
get
(),
factory
.
build
(
true
/*isFromMemoryCache*/
,
true
/*isFirstResource*/
));
}
@Test
public
void
testReturnsNoAnimationIfNotFirstResource
()
{
assertEquals
(
NoAnimation
.
get
(),
factory
.
build
(
false
/*isFromMemoryCache*/
,
false
/*isFirstResource*/
));
}
@Test
public
void
testReturnsAnimationIfNotFromMemoryCacheAndFirstResource
()
{
assertNotEquals
(
NoAnimation
.
get
(),
factory
.
build
(
false
/*isFromMemoryCache*/
,
true
/*isFirstResource*/
));
}
}
\ No newline at end of file
library/src/main/java/com/bumptech/glide/DrawableRequestBuilder.java
浏览文件 @
69aee752
...
...
@@ -21,7 +21,7 @@ import com.bumptech.glide.manager.Lifecycle;
import
com.bumptech.glide.manager.RequestTracker
;
import
com.bumptech.glide.provider.LoadProvider
;
import
com.bumptech.glide.request.RequestListener
;
import
com.bumptech.glide.request.animation.DrawableCrossFade
ViewAnimation
;
import
com.bumptech.glide.request.animation.DrawableCrossFade
Factory
;
import
com.bumptech.glide.request.animation.ViewPropertyAnimation
;
import
com.bumptech.glide.request.target.Target
;
...
...
@@ -242,7 +242,7 @@ public class DrawableRequestBuilder<ModelType>
* {@inheritDoc}
*/
public
final
DrawableRequestBuilder
<
ModelType
>
crossFade
()
{
super
.
animate
(
new
DrawableCrossFade
ViewAnimation
.
DrawableCrossFade
Factory
<
GlideDrawable
>());
super
.
animate
(
new
DrawableCrossFadeFactory
<
GlideDrawable
>());
return
this
;
}
...
...
@@ -250,7 +250,7 @@ public class DrawableRequestBuilder<ModelType>
* {@inheritDoc}
*/
public
DrawableRequestBuilder
<
ModelType
>
crossFade
(
int
duration
)
{
super
.
animate
(
new
DrawableCrossFade
ViewAnimation
.
DrawableCrossFade
Factory
<
GlideDrawable
>(
duration
));
super
.
animate
(
new
DrawableCrossFadeFactory
<
GlideDrawable
>(
duration
));
return
this
;
}
...
...
@@ -259,7 +259,7 @@ public class DrawableRequestBuilder<ModelType>
*/
@Deprecated
public
DrawableRequestBuilder
<
ModelType
>
crossFade
(
Animation
animation
,
int
duration
)
{
super
.
animate
(
new
DrawableCrossFade
ViewAnimation
.
DrawableCrossFade
Factory
<
GlideDrawable
>(
animation
,
duration
));
super
.
animate
(
new
DrawableCrossFadeFactory
<
GlideDrawable
>(
animation
,
duration
));
return
this
;
}
...
...
@@ -267,7 +267,7 @@ public class DrawableRequestBuilder<ModelType>
* {@inheritDoc}
*/
public
DrawableRequestBuilder
<
ModelType
>
crossFade
(
int
animationId
,
int
duration
)
{
super
.
animate
(
new
DrawableCrossFade
ViewAnimation
.
DrawableCrossFade
Factory
<
GlideDrawable
>(
context
,
animationId
,
super
.
animate
(
new
DrawableCrossFadeFactory
<
GlideDrawable
>(
context
,
animationId
,
duration
));
return
this
;
}
...
...
library/src/main/java/com/bumptech/glide/GenericRequestBuilder.java
浏览文件 @
69aee752
...
...
@@ -4,7 +4,6 @@ import android.content.Context;
import
android.graphics.drawable.Drawable
;
import
android.view.animation.Animation
;
import
android.widget.ImageView
;
import
com.bumptech.glide.signature.EmptySignature
;
import
com.bumptech.glide.load.Encoder
;
import
com.bumptech.glide.load.Key
;
import
com.bumptech.glide.load.MultiTransformation
;
...
...
@@ -27,10 +26,12 @@ import com.bumptech.glide.request.RequestListener;
import
com.bumptech.glide.request.ThumbnailRequestCoordinator
;
import
com.bumptech.glide.request.animation.GlideAnimationFactory
;
import
com.bumptech.glide.request.animation.NoAnimation
;
import
com.bumptech.glide.request.animation.ViewAnimation
;
import
com.bumptech.glide.request.animation.ViewAnimation
Factory
;
import
com.bumptech.glide.request.animation.ViewPropertyAnimation
;
import
com.bumptech.glide.request.animation.ViewPropertyAnimationFactory
;
import
com.bumptech.glide.request.target.PreloadTarget
;
import
com.bumptech.glide.request.target.Target
;
import
com.bumptech.glide.signature.EmptySignature
;
import
com.bumptech.glide.util.Util
;
import
java.io.File
;
...
...
@@ -367,7 +368,7 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
* @return This request builder.
*/
public
GenericRequestBuilder
<
ModelType
,
DataType
,
ResourceType
,
TranscodeType
>
animate
(
int
animationId
)
{
return
animate
(
new
ViewAnimation
.
ViewAnimation
Factory
<
TranscodeType
>(
context
,
animationId
));
return
animate
(
new
ViewAnimationFactory
<
TranscodeType
>(
context
,
animationId
));
}
/**
...
...
@@ -387,7 +388,7 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
*/
@Deprecated
public
GenericRequestBuilder
<
ModelType
,
DataType
,
ResourceType
,
TranscodeType
>
animate
(
Animation
animation
)
{
return
animate
(
new
ViewAnimation
.
ViewAnimation
Factory
<
TranscodeType
>(
animation
));
return
animate
(
new
ViewAnimationFactory
<
TranscodeType
>(
animation
));
}
/**
...
...
@@ -400,7 +401,7 @@ public class GenericRequestBuilder<ModelType, DataType, ResourceType, TranscodeT
*/
public
GenericRequestBuilder
<
ModelType
,
DataType
,
ResourceType
,
TranscodeType
>
animate
(
ViewPropertyAnimation
.
Animator
animator
)
{
return
animate
(
new
ViewPropertyAnimation
.
ViewPropertyAnimation
Factory
<
TranscodeType
>(
animator
));
return
animate
(
new
ViewPropertyAnimationFactory
<
TranscodeType
>(
animator
));
}
GenericRequestBuilder
<
ModelType
,
DataType
,
ResourceType
,
TranscodeType
>
animate
(
...
...
library/src/main/java/com/bumptech/glide/GifRequestBuilder.java
浏览文件 @
69aee752
...
...
@@ -15,7 +15,7 @@ import com.bumptech.glide.load.resource.gif.GifDrawableTransformation;
import
com.bumptech.glide.load.resource.transcode.ResourceTranscoder
;
import
com.bumptech.glide.provider.LoadProvider
;
import
com.bumptech.glide.request.RequestListener
;
import
com.bumptech.glide.request.animation.DrawableCrossFade
ViewAnimation
;
import
com.bumptech.glide.request.animation.DrawableCrossFade
Factory
;
import
com.bumptech.glide.request.animation.ViewPropertyAnimation
;
import
java.io.File
;
...
...
@@ -229,7 +229,7 @@ public class GifRequestBuilder<ModelType>
*/
@Override
public
GifRequestBuilder
<
ModelType
>
crossFade
()
{
super
.
animate
(
new
DrawableCrossFade
ViewAnimation
.
DrawableCrossFade
Factory
<
GifDrawable
>());
super
.
animate
(
new
DrawableCrossFadeFactory
<
GifDrawable
>());
return
this
;
}
...
...
@@ -238,7 +238,7 @@ public class GifRequestBuilder<ModelType>
*/
@Override
public
GifRequestBuilder
<
ModelType
>
crossFade
(
int
duration
)
{
super
.
animate
(
new
DrawableCrossFade
ViewAnimation
.
DrawableCrossFade
Factory
<
GifDrawable
>(
duration
));
super
.
animate
(
new
DrawableCrossFadeFactory
<
GifDrawable
>(
duration
));
return
this
;
}
...
...
@@ -248,7 +248,7 @@ public class GifRequestBuilder<ModelType>
@Deprecated
@Override
public
GifRequestBuilder
<
ModelType
>
crossFade
(
Animation
animation
,
int
duration
)
{
super
.
animate
(
new
DrawableCrossFade
ViewAnimation
.
DrawableCrossFade
Factory
<
GifDrawable
>(
animation
,
duration
));
super
.
animate
(
new
DrawableCrossFadeFactory
<
GifDrawable
>(
animation
,
duration
));
return
this
;
}
...
...
@@ -257,7 +257,7 @@ public class GifRequestBuilder<ModelType>
*/
@Override
public
GifRequestBuilder
<
ModelType
>
crossFade
(
int
animationId
,
int
duration
)
{
super
.
animate
(
new
DrawableCrossFade
ViewAnimation
.
DrawableCrossFade
Factory
<
GifDrawable
>(
context
,
animationId
,
super
.
animate
(
new
DrawableCrossFadeFactory
<
GifDrawable
>(
context
,
animationId
,
duration
));
return
this
;
}
...
...
library/src/main/java/com/bumptech/glide/request/animation/DrawableCrossFadeFactory.java
0 → 100644
浏览文件 @
69aee752
package
com.bumptech.glide.request.animation
;
import
android.content.Context
;
import
android.graphics.drawable.Drawable
;
import
android.view.animation.AlphaAnimation
;
import
android.view.animation.Animation
;
/**
* A factory class that produces a new {@link com.bumptech.glide.request.animation.GlideAnimation} that varies depending
* on whether or not the drawable was loaded from the memory cache and whether or not the drawable is the first
* image to be set on the target.
*
* <p>
* Resources are usually loaded from the memory cache just before the user can see the view,
* for example when the user changes screens or scrolls back and forth in a list. In those cases the user
* typically does not expect to see an animation. As a result, when the resource is loaded from the memory
* cache this factory produces an {@link com.bumptech.glide.request.animation.NoAnimation}.
* </p>
*
* @param <T> The type of the {@link android.graphics.drawable.Drawable} that will be animated.
*/
public
class
DrawableCrossFadeFactory
<
T
extends
Drawable
>
implements
GlideAnimationFactory
<
T
>
{
private
static
final
int
DEFAULT_DURATION_MS
=
300
;
private
final
ViewAnimationFactory
<
T
>
animationFactory
;
private
final
int
duration
;
private
DrawableCrossFadeViewAnimation
<
T
>
animation
;
public
DrawableCrossFadeFactory
()
{
this
(
DEFAULT_DURATION_MS
);
}
public
DrawableCrossFadeFactory
(
int
duration
)
{
this
(
new
ViewAnimationFactory
<
T
>(
new
DefaultAnimationFactory
()),
duration
);
}
public
DrawableCrossFadeFactory
(
Context
context
,
int
defaultAnimationId
,
int
duration
)
{
this
(
new
ViewAnimationFactory
<
T
>(
context
,
defaultAnimationId
),
duration
);
}
public
DrawableCrossFadeFactory
(
Animation
defaultAnimation
,
int
duration
)
{
this
(
new
ViewAnimationFactory
<
T
>(
defaultAnimation
),
duration
);
}
DrawableCrossFadeFactory
(
ViewAnimationFactory
<
T
>
animationFactory
,
int
duration
)
{
this
.
animationFactory
=
animationFactory
;
this
.
duration
=
duration
;
}
@Override
public
GlideAnimation
<
T
>
build
(
boolean
isFromMemoryCache
,
boolean
isFirstResource
)
{
if
(
isFromMemoryCache
)
{
return
NoAnimation
.
get
();
}
if
(
animation
==
null
)
{
GlideAnimation
<
T
>
defaultAnimation
=
animationFactory
.
build
(
false
,
isFirstResource
);
animation
=
new
DrawableCrossFadeViewAnimation
<
T
>(
defaultAnimation
,
duration
);
}
return
animation
;
}
private
static
class
DefaultAnimationFactory
implements
ViewAnimation
.
AnimationFactory
{
@Override
public
Animation
build
()
{
AlphaAnimation
animation
=
new
AlphaAnimation
(
0
f
,
1
f
);
animation
.
setDuration
(
DEFAULT_DURATION_MS
/
2
);
return
animation
;
}
}
}
library/src/main/java/com/bumptech/glide/request/animation/DrawableCrossFadeViewAnimation.java
浏览文件 @
69aee752
package
com.bumptech.glide.request.animation
;
import
android.content.Context
;
import
android.graphics.drawable.Drawable
;
import
android.graphics.drawable.TransitionDrawable
;
import
android.view.animation.AlphaAnimation
;
import
android.view.animation.Animation
;
/**
* A cross fade {@link GlideAnimation} for {@link android.graphics.drawable.Drawable}s
...
...
@@ -15,64 +12,9 @@ import android.view.animation.Animation;
* @param <T> The type of the {@link android.graphics.drawable.Drawable} that will be animated.
*/
public
class
DrawableCrossFadeViewAnimation
<
T
extends
Drawable
>
implements
GlideAnimation
<
T
>
{
// 150 ms.
public
static
final
int
DEFAULT_DURATION
=
300
;
private
final
GlideAnimation
<
T
>
defaultAnimation
;
private
final
int
duration
;
/**
* A factory class that produces a new {@link GlideAnimation} that varies depending
* on whether or not the drawable was loaded from the memory cache and whether or not the drawable is the first
* image to be set on the target.
*
* <p>
* Resources are usually loaded from the memory cache just before the user can see the view,
* for example when the user changes screens or scrolls back and forth in a list. In those cases the user
* typically does not expect to see an animation. As a result, when the resource is loaded from the memory
* cache this factory producdes an {@link NoAnimation}.
* </p>
*/
public
static
class
DrawableCrossFadeFactory
<
T
extends
Drawable
>
implements
GlideAnimationFactory
<
T
>
{
private
final
ViewAnimation
.
ViewAnimationFactory
<
T
>
animationFactory
;
private
final
int
duration
;
private
DrawableCrossFadeViewAnimation
<
T
>
animation
;
public
DrawableCrossFadeFactory
()
{
this
(
DEFAULT_DURATION
);
}
public
DrawableCrossFadeFactory
(
int
duration
)
{
this
(
new
ViewAnimation
.
ViewAnimationFactory
<
T
>(
new
DefaultAnimationFactory
()),
duration
);
}
public
DrawableCrossFadeFactory
(
Context
context
,
int
defaultAnimationId
,
int
duration
)
{
this
(
new
ViewAnimation
.
ViewAnimationFactory
<
T
>(
context
,
defaultAnimationId
),
duration
);
}
public
DrawableCrossFadeFactory
(
Animation
defaultAnimation
,
int
duration
)
{
this
(
new
ViewAnimation
.
ViewAnimationFactory
<
T
>(
defaultAnimation
),
duration
);
}
DrawableCrossFadeFactory
(
ViewAnimation
.
ViewAnimationFactory
<
T
>
animationFactory
,
int
duration
)
{
this
.
animationFactory
=
animationFactory
;
this
.
duration
=
duration
;
}
@Override
public
GlideAnimation
<
T
>
build
(
boolean
isFromMemoryCache
,
boolean
isFirstResource
)
{
if
(
isFromMemoryCache
)
{
return
NoAnimation
.
get
();
}
if
(
animation
==
null
)
{
GlideAnimation
<
T
>
defaultAnimation
=
animationFactory
.
build
(
false
,
isFirstResource
);
animation
=
new
DrawableCrossFadeViewAnimation
<
T
>(
defaultAnimation
,
duration
);
}
return
animation
;
}
}
/**
* Constructor that takes a default animation and a duration in milliseconds that the cross fade animation should
* last.
...
...
@@ -111,14 +53,4 @@ public class DrawableCrossFadeViewAnimation<T extends Drawable> implements Glide
return
false
;
}
}
private
static
class
DefaultAnimationFactory
implements
ViewAnimation
.
AnimationFactory
{
@Override
public
Animation
build
()
{
AlphaAnimation
animation
=
new
AlphaAnimation
(
0
f
,
1
f
);
animation
.
setDuration
(
DEFAULT_DURATION
/
2
);
return
animation
;
}
}
}
library/src/main/java/com/bumptech/glide/request/animation/ViewAnimation.java
浏览文件 @
69aee752
package
com.bumptech.glide.request.animation
;
import
android.content.Context
;
import
android.view.View
;
import
android.view.animation.Animation
;
import
android.view.animation.AnimationUtils
;
/**
* A {@link com.bumptech.glide.request.animation.GlideAnimation GlideAnimation} that can apply a
...
...
@@ -45,76 +43,6 @@ public class ViewAnimation<R> implements GlideAnimation<R> {
return
false
;
}
/**
* A {@link com.bumptech.glide.request.animation.GlideAnimationFactory} that produces ViewAnimations.
*/
public
static
class
ViewAnimationFactory
<
R
>
implements
GlideAnimationFactory
<
R
>
{
private
final
AnimationFactory
animationFactory
;
private
GlideAnimation
<
R
>
glideAnimation
;
public
ViewAnimationFactory
(
Animation
animation
)
{
this
(
new
ConcreteAnimationFactory
(
animation
));
}
public
ViewAnimationFactory
(
Context
context
,
int
animationId
)
{
this
(
new
ResourceAnimationFactory
(
context
,
animationId
));
}
ViewAnimationFactory
(
AnimationFactory
animationFactory
)
{
this
.
animationFactory
=
animationFactory
;
}
/**
* Returns a new {@link com.bumptech.glide.request.animation.GlideAnimation} for the given arguments. If
* isFromMemoryCache is {@code true} or isFirstImage is {@code false}, returns a
* {@link com.bumptech.glide.request.animation.NoAnimation} and otherwise returns a new
* {@link com.bumptech.glide.request.animation.ViewAnimation}.
*
* @param isFromMemoryCache {@inheritDoc}
* @param isFirstResource {@inheritDoc}
*/
@Override
public
GlideAnimation
<
R
>
build
(
boolean
isFromMemoryCache
,
boolean
isFirstResource
)
{
if
(
isFromMemoryCache
||
!
isFirstResource
)
{
return
NoAnimation
.
get
();
}
if
(
glideAnimation
==
null
)
{
glideAnimation
=
new
ViewAnimation
<
R
>(
animationFactory
);
}
return
glideAnimation
;
}
}
private
static
class
ConcreteAnimationFactory
implements
AnimationFactory
{
private
final
Animation
animation
;
public
ConcreteAnimationFactory
(
Animation
animation
)
{
this
.
animation
=
animation
;
}
@Override
public
Animation
build
()
{
return
animation
;
}
}
private
static
class
ResourceAnimationFactory
implements
AnimationFactory
{
private
final
Context
context
;
private
final
int
animationId
;
public
ResourceAnimationFactory
(
Context
context
,
int
animationId
)
{
this
.
context
=
context
.
getApplicationContext
();
this
.
animationId
=
animationId
;
}
@Override
public
Animation
build
()
{
return
AnimationUtils
.
loadAnimation
(
context
,
animationId
);
}
}
interface
AnimationFactory
{
Animation
build
();
}
...
...
library/src/main/java/com/bumptech/glide/request/animation/ViewAnimationFactory.java
0 → 100644
浏览文件 @
69aee752
package
com.bumptech.glide.request.animation
;
import
android.content.Context
;
import
android.view.animation.Animation
;
import
android.view.animation.AnimationUtils
;
/**
* A {@link com.bumptech.glide.request.animation.GlideAnimationFactory} that produces
* {@link com.bumptech.glide.request.animation.ViewAnimation}s.
*
* @param <R> The type of the resource displayed in the view that is animated
*/
public
class
ViewAnimationFactory
<
R
>
implements
GlideAnimationFactory
<
R
>
{
private
final
ViewAnimation
.
AnimationFactory
animationFactory
;
private
GlideAnimation
<
R
>
glideAnimation
;
public
ViewAnimationFactory
(
Animation
animation
)
{
this
(
new
ConcreteAnimationFactory
(
animation
));
}
public
ViewAnimationFactory
(
Context
context
,
int
animationId
)
{
this
(
new
ResourceAnimationFactory
(
context
,
animationId
));
}
ViewAnimationFactory
(
ViewAnimation
.
AnimationFactory
animationFactory
)
{
this
.
animationFactory
=
animationFactory
;
}
/**
* Returns a new {@link com.bumptech.glide.request.animation.GlideAnimation} for the given arguments. If
* isFromMemoryCache is {@code true} or isFirstImage is {@code false}, returns a
* {@link com.bumptech.glide.request.animation.NoAnimation} and otherwise returns a new
* {@link com.bumptech.glide.request.animation.ViewAnimation}.
*
* @param isFromMemoryCache {@inheritDoc}
* @param isFirstResource {@inheritDoc}
*/
@Override
public
GlideAnimation
<
R
>
build
(
boolean
isFromMemoryCache
,
boolean
isFirstResource
)
{
if
(
isFromMemoryCache
||
!
isFirstResource
)
{
return
NoAnimation
.
get
();
}
if
(
glideAnimation
==
null
)
{
glideAnimation
=
new
ViewAnimation
<
R
>(
animationFactory
);
}
return
glideAnimation
;
}
private
static
class
ConcreteAnimationFactory
implements
ViewAnimation
.
AnimationFactory
{
private
final
Animation
animation
;
public
ConcreteAnimationFactory
(
Animation
animation
)
{
this
.
animation
=
animation
;
}
@Override
public
Animation
build
()
{
return
animation
;
}
}
private
static
class
ResourceAnimationFactory
implements
ViewAnimation
.
AnimationFactory
{
private
final
Context
context
;
private
final
int
animationId
;
public
ResourceAnimationFactory
(
Context
context
,
int
animationId
)
{
this
.
context
=
context
.
getApplicationContext
();
this
.
animationId
=
animationId
;
}
@Override
public
Animation
build
()
{
return
AnimationUtils
.
loadAnimation
(
context
,
animationId
);
}
}
}
library/src/main/java/com/bumptech/glide/request/animation/ViewPropertyAnimation.java
浏览文件 @
69aee752
...
...
@@ -54,34 +54,4 @@ public class ViewPropertyAnimation<R> implements GlideAnimation<R> {
void
animate
(
View
view
);
}
/**
* A {@link com.bumptech.glide.request.animation.GlideAnimationFactory} that produces ViewPropertyAnimations.
*/
public
static
class
ViewPropertyAnimationFactory
<
R
>
implements
GlideAnimationFactory
<
R
>
{
private
final
Animator
animator
;
private
ViewPropertyAnimation
<
R
>
animation
;
public
ViewPropertyAnimationFactory
(
Animator
animator
)
{
this
.
animator
=
animator
;
}
/**
* Returns a new {@link com.bumptech.glide.request.animation.GlideAnimation} for the given arguments. If
* isMemoryCache is {@code true} or isFirstImage is {@code false}, returns a
* {@link com.bumptech.glide.request.animation.NoAnimation} and otherwise returns a new
* {@link com.bumptech.glide.request.animation.ViewPropertyAnimation} for the
* {@link com.bumptech.glide.request.animation.ViewPropertyAnimation.Animator} provided in the constructor.
*/
@Override
public
GlideAnimation
<
R
>
build
(
boolean
isFromMemoryCache
,
boolean
isFirstResource
)
{
if
(
isFromMemoryCache
||
!
isFirstResource
)
{
return
NoAnimation
.
get
();
}
if
(
animation
==
null
)
{
animation
=
new
ViewPropertyAnimation
<
R
>(
animator
);
}
return
animation
;
}
}
}
library/src/main/java/com/bumptech/glide/request/animation/ViewPropertyAnimationFactory.java
0 → 100644
浏览文件 @
69aee752
package
com.bumptech.glide.request.animation
;
/**
* A {@link GlideAnimationFactory} that produces ViewPropertyAnimations.
*
* @param <R> The type of the resource displayed in the view that is animated
*/
public
class
ViewPropertyAnimationFactory
<
R
>
implements
GlideAnimationFactory
<
R
>
{
private
final
ViewPropertyAnimation
.
Animator
animator
;
private
ViewPropertyAnimation
<
R
>
animation
;
public
ViewPropertyAnimationFactory
(
ViewPropertyAnimation
.
Animator
animator
)
{
this
.
animator
=
animator
;
}
/**
* Returns a new {@link GlideAnimation} for the given arguments. If
* isMemoryCache is {@code true} or isFirstImage is {@code false}, returns a
* {@link NoAnimation} and otherwise returns a new
* {@link ViewPropertyAnimation} for the
* {@link com.bumptech.glide.request.animation.ViewPropertyAnimation.Animator} provided in the constructor.
*/
@Override
public
GlideAnimation
<
R
>
build
(
boolean
isFromMemoryCache
,
boolean
isFirstResource
)
{
if
(
isFromMemoryCache
||
!
isFirstResource
)
{
return
NoAnimation
.
get
();
}
if
(
animation
==
null
)
{
animation
=
new
ViewPropertyAnimation
<
R
>(
animator
);
}
return
animation
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录