|
13 | 13 |
|
14 | 14 | import com.allen.androidcustomview.R; |
15 | 15 |
|
16 | | - |
17 | 16 | import static android.graphics.Paint.ANTI_ALIAS_FLAG; |
18 | 17 |
|
19 | 18 | /** |
@@ -83,8 +82,9 @@ public class PayPsdInputView extends EditText { |
83 | 82 | * 竖直分割线的颜色 |
84 | 83 | */ |
85 | 84 | private int divideLineColor = Color.GRAY; |
| 85 | + private int focusedColor = Color.BLUE; |
86 | 86 | private RectF rectF = new RectF(); |
87 | | - |
| 87 | + private RectF focusedRecF = new RectF(); |
88 | 88 | private int psdType = 0; |
89 | 89 | private final static int psdType_weChat = 0; |
90 | 90 | private final static int psdType_bottomLine = 1; |
@@ -111,6 +111,11 @@ public class PayPsdInputView extends EditText { |
111 | 111 | */ |
112 | 112 | private String mComparePassword = null; |
113 | 113 |
|
| 114 | + /** |
| 115 | + * 当前输入的位置索引 |
| 116 | + */ |
| 117 | + private int position = 0; |
| 118 | + |
114 | 119 | private onPasswordListener mListener; |
115 | 120 |
|
116 | 121 | public PayPsdInputView(Context context, AttributeSet attrs) { |
@@ -137,6 +142,7 @@ private void getAtt(AttributeSet attrs) { |
137 | 142 | divideLineColor = typedArray.getColor(R.styleable.PayPsdInputView_divideLineColor, divideLineColor); |
138 | 143 | psdType = typedArray.getInt(R.styleable.PayPsdInputView_psdType, psdType); |
139 | 144 | rectAngle = typedArray.getDimensionPixelOffset(R.styleable.PayPsdInputView_rectAngle, rectAngle); |
| 145 | + focusedColor = typedArray.getColor(R.styleable.PayPsdInputView_focusedColor, focusedColor); |
140 | 146 |
|
141 | 147 | typedArray.recycle(); |
142 | 148 | } |
@@ -174,7 +180,6 @@ private Paint getPaint(int strokeWidth, Paint.Style style, int color) { |
174 | 180 | return paint; |
175 | 181 | } |
176 | 182 |
|
177 | | - |
178 | 183 | @Override |
179 | 184 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
180 | 185 | super.onSizeChanged(w, h, oldw, oldh); |
@@ -195,11 +200,12 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) { |
195 | 200 | @Override |
196 | 201 | protected void onDraw(Canvas canvas) { |
197 | 202 | //不删除的画会默认绘制输入的文字 |
198 | | -// super.onDraw(canvas); |
| 203 | +// super.onDraw(canvas); |
199 | 204 |
|
200 | 205 | switch (psdType) { |
201 | 206 | case psdType_weChat: |
202 | 207 | drawWeChatBorder(canvas); |
| 208 | + drawItemFocused(canvas, position); |
203 | 209 | break; |
204 | 210 | case psdType_bottomLine: |
205 | 211 | drawBottomBorder(canvas); |
@@ -209,7 +215,6 @@ protected void onDraw(Canvas canvas) { |
209 | 215 | drawPsdCircle(canvas); |
210 | 216 | } |
211 | 217 |
|
212 | | - |
213 | 218 | /** |
214 | 219 | * 画微信支付密码的样式 |
215 | 220 | * |
@@ -229,6 +234,14 @@ private void drawWeChatBorder(Canvas canvas) { |
229 | 234 |
|
230 | 235 | } |
231 | 236 |
|
| 237 | + private void drawItemFocused(Canvas canvas, int position) { |
| 238 | + if (position > maxCount - 1) { |
| 239 | + return; |
| 240 | + } |
| 241 | + focusedRecF.set(position * divideLineWStartX, 0, (position + 1) * divideLineWStartX, |
| 242 | + height); |
| 243 | + canvas.drawRoundRect(focusedRecF, rectAngle, rectAngle, getPaint(3, Paint.Style.STROKE, focusedColor)); |
| 244 | + } |
232 | 245 |
|
233 | 246 | /** |
234 | 247 | * 画底部显示的分割线 |
@@ -263,6 +276,7 @@ private void drawPsdCircle(Canvas canvas) { |
263 | 276 | @Override |
264 | 277 | protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) { |
265 | 278 | super.onTextChanged(text, start, lengthBefore, lengthAfter); |
| 279 | + this.position = start + lengthAfter; |
266 | 280 | textLength = text.toString().length(); |
267 | 281 |
|
268 | 282 | if (mComparePassword != null && textLength == maxCount) { |
@@ -295,6 +309,11 @@ public String getPasswordString() { |
295 | 309 | return getText().toString().trim(); |
296 | 310 | } |
297 | 311 |
|
| 312 | + public void setComparePassword(String comparePassword, onPasswordListener listener) { |
| 313 | + mComparePassword = comparePassword; |
| 314 | + mListener = listener; |
| 315 | + } |
| 316 | + |
298 | 317 | /** |
299 | 318 | * 密码比较监听 |
300 | 319 | */ |
@@ -303,9 +322,4 @@ public interface onPasswordListener { |
303 | 322 |
|
304 | 323 | void onEqual(String psd); |
305 | 324 | } |
306 | | - |
307 | | - public void setComparePassword(String comparePassword, onPasswordListener listener) { |
308 | | - mComparePassword = comparePassword; |
309 | | - mListener = listener; |
310 | | - } |
311 | 325 | } |