AnimationUtil.java
6.52 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package com.sw.laryngoscope.utils;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import com.sw.laryngoscope.R;
public class AnimationUtil {
private final static String TAG = "AnimationUtils";
private Context mContext;
private View tmpSet;
private TranslateAnimation mShowSetAction;
private TranslateAnimation mCloseSetAction;
private View tmpPreview;
private TranslateAnimation mShowPreviewAction;
private TranslateAnimation mClosePreviewAction;
private Animation incAnimation;
public AnimationUtil(Context context ) {
mContext = context;
}
public void setTmpSet(View tmpSet) {
this.tmpSet = tmpSet;
}
public void setTmpPreview(View tmpPreview) {
this.tmpPreview = tmpPreview;
}
public void setAnimation() {
//设置显示时的动画
mShowSetAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 1.0f);
mShowSetAction.setDuration(300);
//设置隐藏时的动画,监听动画结束后隐藏选择框
mCloseSetAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 1.0f);
mCloseSetAction.setDuration(300);
mCloseSetAction.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
//
tmpSet.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
//设置显示时的动画
mShowPreviewAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
mShowPreviewAction.setDuration(300);
//设置隐藏时的动画,监听动画结束后隐藏选择框
mClosePreviewAction = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f,
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
mClosePreviewAction.setDuration(300);
mClosePreviewAction.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
//
tmpPreview.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
incAnimation = AnimationUtils.loadAnimation(mContext, R.anim.small_animation);
}
//显示
public void showSetView() {
if ( View.GONE == tmpSet.getVisibility() ) {
tmpSet.setVisibility(View.VISIBLE);//tmp背景色是暗的,所以看起来像是背景变暗
tmpSet.startAnimation(mShowSetAction);//为选择框设置动画
}
}
//关闭
public void closeSetView() {
if ( View.VISIBLE == tmpSet.getVisibility() ) {
tmpSet.startAnimation(mCloseSetAction);
}
}
//显示
public void showPreview() {
if ( View.GONE == tmpPreview.getVisibility() ) {
tmpPreview.setVisibility(View.VISIBLE);//tmp背景色是暗的,所以看起来像是背景变暗
tmpPreview.startAnimation(mShowPreviewAction);//为选择框设置动画
}
}
//关闭
public void closePreview() {
if ( View.VISIBLE == tmpPreview.getVisibility() ) {
tmpPreview.startAnimation(mClosePreviewAction);
}
}
public void incFileAnim(View view) {
view.startAnimation(incAnimation);//开始动画
incAnimation.setAnimationListener(new Animation.AnimationListener(){
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
view.clearAnimation();
}
});
}
private void setFlickerAnimation(View iv_chat_head) {
final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
animation.setDuration(500); // duration - half a second
animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
animation.setRepeatMode(Animation.REVERSE); //
iv_chat_head.setAnimation(animation);
}
private static final int MAX_LEVEL = 90;
public static void animateArrow(View view, boolean shouldRotateUp) {
int start = shouldRotateUp ? 0 : MAX_LEVEL;
int end = shouldRotateUp ? MAX_LEVEL : 0;
ObjectAnimator visibleToInVisable = ObjectAnimator.ofFloat(view, "rotation",
start, end);
// visibleToInVisable.setInterpolator(new LinearOutSlowInInterpolator());
visibleToInVisable.setInterpolator(new AccelerateInterpolator());
visibleToInVisable.setDuration(50);
visibleToInVisable.start();
}
/*private Drawable arrowDrawable;
private ObjectAnimator arrowAnimator = null;
private RotateAnimation rotate;*/
//@SuppressLint("ResourceType")
/*Animation animation = AnimationUtils.loadAnimation(getContext(),R.drawable.arrow);
img_lan_next.startAnimation(animation);*/
/*arrowAnimator = ObjectAnimator.ofInt(
getContext().getDrawable(R.drawable.arrow), "level", start, end);*/
/*rotate = new RotateAnimation(0, 90,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(1000);
img_lan_next.startAnimation(rotate);*/
}