forked from zilianliuxue/AndroidStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolAnimation.java
More file actions
125 lines (109 loc) · 3.38 KB
/
Copy pathToolAnimation.java
File metadata and controls
125 lines (109 loc) · 3.38 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
package com.richerpay.ryshop.util;
import com.richerpay.ryshop.log.KLog;
import android.graphics.ColorMatrixColorFilter;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
/**
* 控件点击效果动画工具类
*
*/
public class ToolAnimation {
/**
* 给试图添加点击效果,让背景变深
* */
public static void addTouchDrak(View view, boolean isClick) {
view.setOnTouchListener(VIEW_TOUCH_DARK);
if (!isClick) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
/**
* 给试图添加点击效果,让背景变暗
* */
public static void addTouchLight(View view, boolean isClick) {
view.setOnTouchListener(VIEW_TOUCH_LIGHT);
if (!isClick) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
/**
* 让控件点击时,颜色变深
* */
public static final OnTouchListener VIEW_TOUCH_DARK = new OnTouchListener() {
public final float[] BT_SELECTED = new float[] { 1, 0, 0, 0, -50, 0, 1,
0, 0, -50, 0, 0, 1, 0, -50, 0, 0, 0, 1, 0 };
public final float[] BT_NOT_SELECTED = new float[] { 1, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 };
@SuppressWarnings("deprecation")
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v instanceof ImageView) {
ImageView iv = (ImageView) v;
iv.setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
} else {
v.getBackground().setColorFilter(
new ColorMatrixColorFilter(BT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v instanceof ImageView) {
ImageView iv = (ImageView) v;
iv.setColorFilter(new ColorMatrixColorFilter(
BT_NOT_SELECTED));
} else {
v.getBackground().setColorFilter(
new ColorMatrixColorFilter(BT_NOT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
}
return false;
}
};
/**
* 让控件点击时,颜色变暗
* */
public static final OnTouchListener VIEW_TOUCH_LIGHT = new OnTouchListener() {
public final float[] BT_SELECTED = new float[] { 1, 0, 0, 0, 50, 0, 1,
0, 0, 50, 0, 0, 1, 0, 50, 0, 0, 0, 1, 0 };
public final float[] BT_NOT_SELECTED = new float[] { 1, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 };
@SuppressWarnings("deprecation")
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (v instanceof ImageView) {
ImageView iv = (ImageView) v;
iv.setDrawingCacheEnabled(true);
iv.setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
} else {
v.getBackground().setColorFilter(
new ColorMatrixColorFilter(BT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (v instanceof ImageView) {
ImageView iv = (ImageView) v;
iv.setColorFilter(new ColorMatrixColorFilter(
BT_NOT_SELECTED));
KLog.e("变回来");
} else {
v.getBackground().setColorFilter(
new ColorMatrixColorFilter(BT_NOT_SELECTED));
v.setBackgroundDrawable(v.getBackground());
}
}
return false;
}
};
}