-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathAnimHelper.java
More file actions
90 lines (73 loc) · 3.95 KB
/
AnimHelper.java
File metadata and controls
90 lines (73 loc) · 3.95 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
package com.realmo.utils;
import android.content.Context;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
public class AnimHelper {
private AnimHelper() {
throw new RuntimeException("AnimHelper cannot be initialized!");
}
public static final Interpolator INTERPOLATOR = new FastOutSlowInInterpolator();
public static final int DURATION = 300;
public static void scaleShow(View view, ViewPropertyAnimatorListener listener) {
ViewCompat.animate(view).scaleX(1.0f).scaleY(1.0f).alpha(1.0f).setDuration(DURATION).setListener(listener).setInterpolator(INTERPOLATOR).withLayer().start();
}
public static void scaleHide(View view, ViewPropertyAnimatorListener listener) {
ViewCompat.animate(view).scaleX(0f).scaleY(0f).alpha(0f).setDuration(DURATION).setListener(listener).setInterpolator(INTERPOLATOR).withLayer().start();
}
public static void alphaShow(View view, ViewPropertyAnimatorListener listener) {
ViewCompat.animate(view).alpha(1.0f).setDuration(DURATION).setListener(listener).setInterpolator(INTERPOLATOR).withLayer().start();
}
public static void alphaHide(View view, ViewPropertyAnimatorListener listener) {
ViewCompat.animate(view).alpha(0f).setDuration(DURATION).setListener(listener).setInterpolator(INTERPOLATOR).withLayer().start();
}
public static void translateUp(View view, ViewPropertyAnimatorListener listener) {
ViewCompat.animate(view).translationY(0).setDuration(DURATION).setListener(listener).setInterpolator(INTERPOLATOR).withLayer().start();
}
public static void translateDown(View view, ViewPropertyAnimatorListener listener) {
int height = view.getHeight();
ViewGroup.LayoutParams params = view.getLayoutParams();
ViewGroup.MarginLayoutParams layoutParams = params instanceof ViewGroup.MarginLayoutParams ? ((ViewGroup.MarginLayoutParams) params) : null;
if (layoutParams != null) height += layoutParams.bottomMargin;
ViewCompat.animate(view).translationY(height).setDuration(DURATION).setListener(listener).setInterpolator(INTERPOLATOR).withLayer().start();
}
public static float floatEvaluator(float originalSize, float finalSize, float percent) {
return (finalSize - originalSize) * percent + originalSize;
}
public static int argbEvaluator(int startColor, int endColor, float percent) {
int startA = (startColor >> 24) & 0xff;
int startR = (startColor >> 16) & 0xff;
int startG = (startColor >> 8) & 0xff;
int startB = startColor & 0xff;
int endA = (endColor >> 24) & 0xff;
int endR = (endColor >> 16) & 0xff;
int endG = (endColor >> 8) & 0xff;
int endB = endColor & 0xff;
return ((startA + (int) (percent * (endA - startA))) << 24) |
((startR + (int) (percent * (endR - startR))) << 16) |
((startG + (int) (percent * (endG - startG))) << 8) |
((startB + (int) (percent * (endB - startB))));
}
public static float scaleEvaluator(float originalSize, float finalSize, float percent) {
float calcSize = (finalSize - originalSize) * percent + originalSize;
return calcSize / originalSize;
}
/*
// 获得状态栏的高度
public static int getStatusBarHeight(Context context) {
int statusHeight = -1;
try {
Class<?> clazz = Class.forName("com.android.internal.R$dimen");
Object object = clazz.newInstance();
int height = Integer.parseInt(clazz.getField("status_bar_height").get(object).toString());
statusHeight = context.getResources().getDimensionPixelSize(height);
} catch (Exception e) {
e.printStackTrace();
}
return statusHeight;
}
*/
}