From 7c00e3aef9e754d00d2a061a541492a4f3f9e90d Mon Sep 17 00:00:00 2001 From: Benjamin Abramovitch Date: Fri, 14 Jun 2019 14:35:36 -0700 Subject: [PATCH] Resizing view after setMaxLength called Fixing two issues with setMaxLength if you call it after the view has been initialized. When you call setMaxLength it now calls onSizeChanged to update all the values. In onSizeChanged the width and height is recorded for future use if setMaxLength is called. 1 - If number is larger than the initialized number, it will crash with an out of bounds exception. E.g 4 -> 5 2 - If the number is smaller than initialized number, the view will retain the width of the initial number, and the smaller entry dashes will be displayed starting from the left and then stopping mid way through the screen. --- .../java/com/alimuzaffar/lib/pin/PinEntryEditText.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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..67cd54f 100755 --- a/pinentryedittext/src/main/java/com/alimuzaffar/lib/pin/PinEntryEditText.java +++ b/pinentryedittext/src/main/java/com/alimuzaffar/lib/pin/PinEntryEditText.java @@ -61,6 +61,8 @@ public class PinEntryEditText extends AppCompatEditText { protected int mMaxLength = 4; protected RectF[] mLineCoords; protected float[] mCharBottom; + protected int mWidth = 0; + protected int mHeight = 0; protected Paint mCharPaint; protected Paint mLastCharPaint; protected Paint mSingleCharPaint; @@ -112,8 +114,10 @@ public void setMaxLength(final int maxLength) { mNumChars = maxLength; setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxLength)}); - setText(null); + + onSizeChanged(mWidth, mHeight , mWidth, mHeight); + invalidate(); } @@ -251,6 +255,8 @@ public void setInputType(int type) { @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { + mWidth = w; + mHeight = h; super.onSizeChanged(w, h, oldw, oldh); mOriginalTextColors = getTextColors(); if (mOriginalTextColors != null) { @@ -626,4 +632,4 @@ public void setOnPinEnteredListener(OnPinEnteredListener l) { public interface OnPinEnteredListener { void onPinEntered(CharSequence str); } -} \ No newline at end of file +}