diff --git a/pinview/src/main/java/com/chaos/view/PinView.java b/pinview/src/main/java/com/chaos/view/PinView.java index e5ff1fa..42eaae7 100644 --- a/pinview/src/main/java/com/chaos/view/PinView.java +++ b/pinview/src/main/java/com/chaos/view/PinView.java @@ -45,12 +45,12 @@ * @author Chaos Leong * 01/04/2017 * - *
- * XML attributes - *
- * See EditText Attributes, - * TextView Attributes, - * View Attributes + *
+ * XML attributes + *
+ * See EditText Attributes, + * TextView Attributes, + * View Attributes * @attr ref R.styleable#PinView_boxCount * @attr ref R.styleable#PinView_boxHeight * @attr ref R.styleable#PinView_boxRadius @@ -247,38 +247,24 @@ protected void drawableStateChanged() { protected void onDraw(Canvas canvas) { canvas.save(); + updatePaints(); + drawPinView(canvas); + + canvas.restore(); + } + + private void updatePaints() { mPaint.setColor(mCurBorderColor); mPaint.setStrokeWidth(mBorderWidth); mTextPaint.setColor(getCurrentTextColor()); - - drawPinBox(canvas); - - canvas.restore(); } - private void drawPinBox(Canvas canvas) { + private void drawPinView(Canvas canvas) { for (int i = 0; i < mPinBoxCount; i++) { updateBoxRectF(i); updateCenterPoint(); - boolean l, r; - l = r = true; - if (mPinBoxMargin == 0) { - if (mPinBoxCount > 1) { - if (i == 0) { - // draw only left round - r = false; - } else if (i == mPinBoxCount - 1) { - // draw only right round - l = false; - } else { - // draw rect - l = r = false; - } - } - } - updateRoundRectPath(mBoxBorderRect, mPinBoxRadius, mPinBoxRadius, l, r); - canvas.drawPath(mPath, mPaint); + drawPinBox(canvas, i); if (getText().length() > i) { if (DBG) { @@ -294,6 +280,27 @@ private void drawPinBox(Canvas canvas) { } } + private void drawPinBox(Canvas canvas, int i) { + boolean l, r; + l = r = true; + if (mPinBoxMargin == 0) { + if (mPinBoxCount > 1) { + if (i == 0) { + // draw only left round + r = false; + } else if (i == mPinBoxCount - 1) { + // draw only right round + l = false; + } else { + // draw rect + l = r = false; + } + } + } + updateRoundRectPath(mBoxBorderRect, mPinBoxRadius, mPinBoxRadius, l, r); + canvas.drawPath(mPath, mPaint); + } + private void updateRoundRectPath(RectF rectF, float rx, float ry, boolean l, boolean r) { updateRoundRectPath(rectF, rx, ry, l, r, r, l); }