FocusBorderView.java
7.12 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
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.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import com.gimi.common.cinema.utils.ScreenUtils;
import com.xgimi.gimicinema.R;
public class FocusBorderView extends Button {
private int moveCount;
private View nextView;
private Context mContext;
private static int TRAN_DUR_ANIM = 160;
private Drawable first_Drawable;
public FocusBorderView(Context context) {
super(context);
this.mContext = context;
initData();
}
public FocusBorderView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.mContext = context;
initData();
}
public FocusBorderView(Context context, AttributeSet attrs) {
super(context, attrs);
this.mContext = context;
initData();
}
public void runTranslateAnimation(View toView) {
runTranslateAnimation(toView, 1.03F, 1.05F);
}
private void initData() {
// boolean sqlEdition = XgimiDevice.isBusinessDevice() && (XgimiDB.queryInt(getContext(), XgimiDB.ID_launcheredition) == 0);
// setBackgroundResource(R.drawable.focus_bound);
first_Drawable = getBackground();
setFocusable(false);
setClickable(false);
}
public void runTranslateAnimation(View toView, final float scaleX, final float scaleY) {
if (toView instanceof AbsListView) {
AbsListView absListView = (AbsListView) toView;
absListView.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
runTranslateAnimation(view, scaleX, scaleY);
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
toView = absListView.getSelectedView();
}
Rect fromRect = findLocationWithView(this);
if (toView instanceof RelativeLayout || toView instanceof MovieItem || !(toView instanceof Button)) {
return;
}
if (toView == null) {
return;
}
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);
// Log.e("----widthwidth-", "xxxxx" + width);
// Log.e("----heightheight-", "xxxxx" + height);
// Log.e("x", "" + (x - deltaX));
// Log.e("y", "" + (y - deltaY));
if (Math.abs(ScreenUtils.getDensityInt(getContext(), 489) - width) > 5) {
deltaY += ScreenUtils.getDensityInt(getContext(), 15);
}
// if (toView.getId() == R.id.user_update_information) {
// height = 0;
// deltaY = 0;
// y = ScreenUtils.getDensityInt(getContext(), 400);
// }
switch (toView.getId()) {
// case R.id.settings_network:
// case R.id.settings_about:
// flyWhiteBorder(width + 25, height + 17, x - deltaX - 10, y - deltaY + 6);
// break;
// case R.id.settings_bluetooth:
// flyWhiteBorder(width + 12, height + 42, x - deltaX - 6, y - deltaY - 6);
// break;
// case R.id.settings_networka:
// case R.id.settings_xgimitv:
// flyWhiteBorder(width + 42, height + 40, x - deltaX - 22, y - deltaY - 6);
// break;
default:
flyWhiteBorder(width + getDimen(R.integer.default_width_add), height + getDimen(R.integer.default_height_add),
x + getDimen(R.integer.default_x_add), y + getDimen(R.integer.default_y_add));
// flyWhiteBorder(width + 20, height + 30, x - 20, y - 20);
}
// flyWhiteBorder(width , height, x - deltaX , y - deltaY );
}
private int getDimen(int id) {
return (int) mContext.getResources().getInteger(id);
}
/**
* 白色焦点框飞动、移动、变大
*
* @param width 白色框的宽(非放大后的)
* @param height 白色框的高(非放大后的)
* @param x x坐标偏移量,相对于初始的白色框的中心点
* @param y 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.setInterpolator(new DecelerateInterpolator());
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) {
moveCount++;
// if (nextView instanceof XgimiButton || nextView instanceof XgimiEditText) {
// setVisibility(View.INVISIBLE);
// } else {
setVisibility(View.VISIBLE);
// }
// if (nextView.getId() == R.id.user_update_information) {
// setVisibility(View.INVISIBLE);
// }
}
public void onAnimationRepeat(Animator arg0) {
}
public void onAnimationStart(Animator arg0) {
if (moveCount != 0 && getVisibility() != View.VISIBLE) {
setVisibility(View.VISIBLE);
}
// if (nextView.getId() == R.id.user_update_information) {
// setVisibility(View.INVISIBLE);
// }
}
};
}