-
Notifications
You must be signed in to change notification settings - Fork 411
/
ViewTranslationWrapper.java
90 lines (76 loc) · 2.57 KB
/
ViewTranslationWrapper.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
79
80
81
82
83
84
85
86
87
88
89
90
package agency.tango.materialintroscreen.animations;
import android.support.annotation.AnimRes;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import agency.tango.materialintroscreen.animations.translations.NoTranslation;
@SuppressWarnings("WeakerAccess")
public class ViewTranslationWrapper {
private View view;
private IViewTranslation enterTranslation;
private IViewTranslation exitTranslation;
private IViewTranslation defaultTranslation;
private Animation errorAnimation;
public ViewTranslationWrapper(View view) {
this.view = view;
enterTranslation = new NoTranslation();
exitTranslation = new NoTranslation();
setErrorAnimation(0);
}
/**
* Set translation after passing first slide
*
* @param enterTranslation new translation
* @return ViewTranslationWrapper object
*/
public ViewTranslationWrapper setEnterTranslation(IViewTranslation enterTranslation) {
this.enterTranslation = enterTranslation;
return this;
}
/**
* Set translation after passing last slide
*
* @param exitTranslation new translation
* @return ViewTranslationWrapper object
*/
public ViewTranslationWrapper setExitTranslation(IViewTranslation exitTranslation) {
this.exitTranslation = exitTranslation;
return this;
}
/**
* Set default translation
*
* @param defaultTranslation new translation
* @return ViewTranslationWrapper object
*/
public ViewTranslationWrapper setDefaultTranslation(IViewTranslation defaultTranslation) {
this.defaultTranslation = defaultTranslation;
return this;
}
/**
* Set view on error animation
*
* @param errorAnimation new animation
* @return ViewTranslationWrapper object
*/
public ViewTranslationWrapper setErrorAnimation(@AnimRes int errorAnimation) {
if (errorAnimation != 0) {
this.errorAnimation = AnimationUtils.loadAnimation(view.getContext(), errorAnimation);
}
return this;
}
public void enterTranslate(float percentage) {
enterTranslation.translate(view, percentage);
}
public void exitTranslate(float percentage) {
exitTranslation.translate(view, percentage);
}
public void defaultTranslate(float percentage) {
defaultTranslation.translate(view, percentage);
}
public void error() {
if (errorAnimation != null) {
view.startAnimation(errorAnimation);
}
}
}