Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from tipsi/cc_short_number_visibility_fix
Browse files Browse the repository at this point in the history
Fix for 4-digits card number visibility
  • Loading branch information
paynd authored Sep 25, 2017
2 parents 25f0302 + e26bf7a commit 3eb0f16
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 3eb0f16

Please sign in to comment.