From e26bf7a6e6a3020c51c857db3f36ba0acb7dae66 Mon Sep 17 00:00:00 2001 From: paynd Date: Mon, 25 Sep 2017 16:05:02 +0300 Subject: [PATCH] Fix for 4-digits card number visibility --- .../creditcardentry/internal/CreditCardEntry.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CreditCardEntry/src/com/devmarvel/creditcardentry/internal/CreditCardEntry.java b/CreditCardEntry/src/com/devmarvel/creditcardentry/internal/CreditCardEntry.java index 2d02e9f..38a096d 100644 --- a/CreditCardEntry/src/com/devmarvel/creditcardentry/internal/CreditCardEntry.java +++ b/CreditCardEntry/src/com/devmarvel/creditcardentry/internal/CreditCardEntry.java @@ -8,7 +8,9 @@ import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; +import android.graphics.Paint; import android.graphics.Point; +import android.graphics.Rect; import android.graphics.Typeface; import android.os.Build; import android.os.Handler; @@ -82,6 +84,7 @@ public class CreditCardEntry extends HorizontalScrollView implements private boolean animateOnError = true; private CardValidCallback onCardValidCallback; + private int textSize; @SuppressWarnings("deprecation") public CreditCardEntry(Context context, boolean includeExp, boolean includeSecurity, boolean includeZip, AttributeSet attrs, @SuppressWarnings("UnusedParameters") int style) { @@ -95,7 +98,7 @@ public CreditCardEntry(Context context, boolean includeExp, boolean includeSecur } else { textColor = null; } - int textSize = typedArray.getDimensionPixelSize(R.styleable.CreditCardForm_text_size, 19); + textSize = typedArray.getDimensionPixelSize(R.styleable.CreditCardForm_text_size, 19); typedArray.recycle(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); @@ -137,6 +140,7 @@ public CreditCardEntry(Context context, boolean includeExp, boolean includeSecur if (textColor != null) { textFourDigits.setTextColor(textColor); } + textFourDigits.setMinWidth(measureTextWidth(textFourDigits, "4242")); container.addView(textFourDigits); expDateText = new ExpDateText(context, attrs); @@ -380,6 +384,15 @@ public void focusOnPreviousField(CreditEntryFieldBase field) { } } + private int measureTextWidth(TextView textView, String text){ + Paint p = new Paint(); + Rect bounds = new Rect(); + p.setTextSize(textSize); + p.getTextBounds(text, 0, text.length(), bounds); + textView.setText(text); + return bounds.width(); + } + public void setCardNumberHint(String hint) { creditCardText.setHint(hint); }