VideoFocusBorderView.java
4.53 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
package com.xgimi.gimicinema.view;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnHoverListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import com.xgimi.gimicinema.R;
public class VideoFocusBorderView extends Button implements OnHoverListener{
private String TAG = "FocusBorderView";
private Drawable first_Drawable;
private View nextView;
private static int TRAN_DUR_ANIM = 0;//160;
public VideoFocusBorderView(Context context) {
super(context);
loseFocuse();
}
public VideoFocusBorderView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
loseFocuse();
}
public VideoFocusBorderView(Context context, AttributeSet attrs) {
super(context, attrs);
loseFocuse();
}
private void loseFocuse() {
setBorderViewBackground();
setFocusable(false);
setClickable(false);
setFocusableInTouchMode(false);
}
public void runTranslateAnimation(View toView) {
runTranslateAnimation(toView, 1.0F, 1.0F);
}
public void runTranslateAnimation(View toView, View fromView) {
Rect fromRect = findLocationWithView(fromView);
if (toView == null)
return;
Rect toRect = findLocationWithView(toView);
int x = toRect.left - fromRect.left;
int y = toRect.top - fromRect.top;
int width = toView.getWidth();
int height = toView.getWidth();
flyWhiteBorder(width, height, x , y );
}
/**
* 重新设置borderView 的颜色
*/
public void setBorderViewBackground(){
setBackgroundResource(R.drawable.focus_bound);
// setBackgroundResource(R.drawable.ic_dark_shadow);
first_Drawable = getBackground();
}
public void runTranslateAnimation(View toView, float scaleX, float scaleY) {
if (toView == null){
Log.e(TAG,"toView =================================null");
setBackgroundColor(Color.TRANSPARENT);
return;
}
if (!(toView instanceof HomeItemContainer)) {
return;
}
setBackground(first_Drawable);
Rect fromRect = findLocationWithView(this);
Rect toRect = findLocationWithView(toView);
nextView = toView;
int x = toRect.left - fromRect.left;
int y = toRect.top - fromRect.top;
int width = (int) (toView.getWidth() * scaleX);
int height = (int) (toView.getHeight() * scaleY);
int deltaX = (int) ((toView.getWidth() * Math.abs(scaleX - 1)) / 2.0f);
int deltaY = (int) ((toView.getHeight() * Math.abs(scaleY - 1)) / 2.0f);
flyWhiteBorder(width, height, x - deltaX - 16, y - deltaY);
}
/**
* 白色焦点框飞动、移动、变大
*
* @param width
* 白色框的宽(非放大后的)
* @param height
* 白色框的高(非放大后的)
* @param width
* x坐标偏移量,相对于初始的白色框的中心点
* @param height
* y坐标偏移量,相对于初始的白色框的中心点
* */
@SuppressLint("NewApi")
private void flyWhiteBorder(int width, int height, float x, float y) {
AnimatorSet animSet = new AnimatorSet();
animSet.play(ObjectAnimator.ofFloat(this, "x", x)).with(ObjectAnimator.ofFloat(this, "y", y))
.with(ObjectAnimator.ofInt(this, "width", this.getWidth(), width))
.with(ObjectAnimator.ofInt(this, "height", this.getHeight(), height));
animSet.addListener(flyListener);
animSet.setDuration(TRAN_DUR_ANIM).start();
}
/**
* 获取View的位置
*
* @param view
* 获取的控件
* @return 位置
*/
public Rect findLocationWithView(View view) {
ViewGroup root = (ViewGroup) this.getParent();
Rect rect = new Rect();
root.offsetDescendantRectToMyCoords(view, rect);
if (view instanceof EditText) {
int[] location = new int[2];
view.getLocationOnScreen(location);
rect.left = location[0];
}
return rect;
}
private Animator.AnimatorListener flyListener = new Animator.AnimatorListener() {
public void onAnimationCancel(Animator arg0) {
}
public void onAnimationEnd(Animator arg0) {
setVisibility(View.VISIBLE);
}
public void onAnimationRepeat(Animator arg0) {
}
public void onAnimationStart(Animator arg0) {
}
};
@Override
public boolean onHover(View v, MotionEvent event) {
// Auto-generated method stub
this.setVisibility(View.INVISIBLE);
return false;
}
}