diff --git a/pinentryedittext/src/main/java/com/alimuzaffar/lib/pin/PinEntryEditText.java b/pinentryedittext/src/main/java/com/alimuzaffar/lib/pin/PinEntryEditText.java index 09e4952..cbdc1e8 100755 --- a/pinentryedittext/src/main/java/com/alimuzaffar/lib/pin/PinEntryEditText.java +++ b/pinentryedittext/src/main/java/com/alimuzaffar/lib/pin/PinEntryEditText.java @@ -381,7 +381,7 @@ protected void onDraw(Canvas canvas) { } //The lines should be in front of the text (because that's how I want it). if (mPinBackground == null) { - updateColorForLines(i <= textLength); + updateColorForLines(i < textLength, i == textLength); canvas.drawLine(mLineCoords[i].left, mLineCoords[i].top, mLineCoords[i].right, mLineCoords[i].bottom, mLinesPaint); } } @@ -416,21 +416,28 @@ private int getColorForState(int... states) { } /** - * @param hasTextOrIsNext Is the color for a character that has been typed or is - * the next character to be typed? + * @param hasText Whether this position has text + * @param isNext Whether this position is the next to be typed */ - protected void updateColorForLines(boolean hasTextOrIsNext) { + protected void updateColorForLines(boolean hasText, boolean isNext) { if (mHasError) { mLinesPaint.setColor(getColorForState(android.R.attr.state_active)); } else if (isFocused()) { mLinesPaint.setStrokeWidth(mLineStrokeSelected); - mLinesPaint.setColor(getColorForState(android.R.attr.state_focused)); - if (hasTextOrIsNext) { - mLinesPaint.setColor(getColorForState(android.R.attr.state_selected)); + if (isNext) { + mLinesPaint.setColor(getColorForState(android.R.attr.state_focused, android.R.attr.state_selected)); + } else if (hasText) { + mLinesPaint.setColor(getColorForState(android.R.attr.state_focused, android.R.attr.state_checked)); + } else { + mLinesPaint.setColor(getColorForState(android.R.attr.state_focused)); } } else { mLinesPaint.setStrokeWidth(mLineStroke); - mLinesPaint.setColor(getColorForState(-android.R.attr.state_focused)); + if (hasText) { + mLinesPaint.setColor(getColorForState(-android.R.attr.state_focused, android.R.attr.state_checked)); + } else { + mLinesPaint.setColor(getColorForState(-android.R.attr.state_focused)); + } } } @@ -438,11 +445,12 @@ protected void updateDrawableState(boolean hasText, boolean isNext) { if (mHasError) { mPinBackground.setState(new int[]{android.R.attr.state_active}); } else if (isFocused()) { - mPinBackground.setState(new int[]{android.R.attr.state_focused}); if (isNext) { mPinBackground.setState(new int[]{android.R.attr.state_focused, android.R.attr.state_selected}); } else if (hasText) { mPinBackground.setState(new int[]{android.R.attr.state_focused, android.R.attr.state_checked}); + } else { + mPinBackground.setState(new int[]{android.R.attr.state_focused}); } } else { if (hasText) {