-
Notifications
You must be signed in to change notification settings - Fork 451
/
Copy pathCustomAnimation.java
78 lines (59 loc) · 2.69 KB
/
CustomAnimation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.nightonke.wowoviewpagerexample;
import android.animation.TimeInterpolator;
import android.os.Build;
import android.view.View;
import com.nightonke.wowoviewpager.Animation.PageAnimation;
/**
* Created by Weiping Huang at 13:13 on 2017/4/2
* For Personal Open Source
* Contact me at [email protected] or [email protected]
* For more projects: https://github.com/Nightonke
*/
public class CustomAnimation extends PageAnimation {
private float fromElevation;
private float toElevation;
private CustomAnimation(int page, float startOffset, float endOffset, int ease, TimeInterpolator interpolator, boolean useSameEaseEnumBack, float fromElevation, float toElevation) {
super(page, startOffset, endOffset, ease, interpolator, useSameEaseEnumBack);
this.fromElevation = fromElevation;
this.toElevation = toElevation;
}
@Override
protected void toStartState(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.setElevation(fromElevation);
}
}
@Override
protected void toMiddleState(View view, float offset) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.setElevation(fromElevation + (toElevation - fromElevation) * offset);
}
}
@Override
protected void toEndState(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
view.setElevation(toElevation);
}
}
public static Builder builder() {
return new Builder();
}
public static class Builder extends PageAnimation.Builder<CustomAnimation.Builder> {
private float fromElevation = UNINITIALIZED_VALUE;
private float toElevation = UNINITIALIZED_VALUE;
public Builder from(float fromElevation) { this.fromElevation = fromElevation; return this; }
public Builder to(float toElevation) { this.toElevation = toElevation; return this; }
public Builder from(double fromElevation) { return from((float) fromElevation); }
public Builder to(double toElevation) { return to((float) toElevation); }
public CustomAnimation build() {
checkUninitializedAttributes();
return new CustomAnimation(page, startOffset, endOffset, ease, interpolator, useSameEaseEnumBack, fromElevation, toElevation);
}
@Override
protected void checkUninitializedAttributes() {
// Check the uninitialized attributes here if needed.
if (fromElevation == UNINITIALIZED_VALUE) uninitializedAttributeException("fromElevation");
if (toElevation == UNINITIALIZED_VALUE) uninitializedAttributeException("toElevation");
}
}
}