diff --git a/pinentry/src/main/java/me/philio/pinentry/PinEntryView.java b/pinentry/src/main/java/me/philio/pinentry/PinEntryView.java index 4f6902d..71f5294 100644 --- a/pinentry/src/main/java/me/philio/pinentry/PinEntryView.java +++ b/pinentry/src/main/java/me/philio/pinentry/PinEntryView.java @@ -71,6 +71,7 @@ public class PinEntryView extends ViewGroup { private int digitSpacing; private int digitTextSize; private int digitTextColor; + private int digitPlaceholderTextColor; private int digitElevation; /** @@ -85,6 +86,10 @@ public class PinEntryView extends ViewGroup { */ private String mask = "*"; + /** + * String to store the placeholder, if any + */ + private String placeholder; /** * Edit text to handle input */ @@ -151,6 +156,10 @@ public PinEntryView(Context context, AttributeSet attrs, int defStyle) { accentColor.resourceId > 0 ? getResources().getColor(accentColor.resourceId) : accentColor.data); + // Placeholder Text color, currently defaults to material design secondary color + digitPlaceholderTextColor = + getResources().getColor(R.color.abc_secondary_text_material_light); + // Mask character String maskCharacter = array.getString(R.styleable.PinEntryView_mask); if (maskCharacter != null) { @@ -180,7 +189,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int height = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY); // Measure children - for (int i = 0; i < getChildCount(); i ++) { + for (int i = 0; i < getChildCount(); i++) { getChildAt(i).measure(width, height); } } @@ -282,6 +291,20 @@ public void setText(CharSequence text) { editText.setText(text); } + /** + * Set a placeholder text to digitViews + * + * @param text + */ + public void setPlaceholderText(String text) { + placeholder = text; + for (int i = 0; i < digits; ++i) { + TextView view = (TextView) getChildAt(i); + view.setText(String.valueOf(placeholder.charAt(i))); + view.setTextColor(digitPlaceholderTextColor); + } + } + /** * Clear pin input */ @@ -295,7 +318,7 @@ public void clearText() { private void addViews() { // Add a digit view for each digit for (int i = 0; i < digits; i++) { - DigitView digitView = new DigitView(getContext() ); + DigitView digitView = new DigitView(getContext()); digitView.setWidth(digitWidth); digitView.setHeight(digitHeight); digitView.setBackgroundResource(digitBackground); @@ -353,8 +376,15 @@ public void afterTextChanged(Editable s) { String mask = PinEntryView.this.mask == null || PinEntryView.this.mask.length() == 0 ? String.valueOf(s.charAt(i)) : PinEntryView.this.mask; ((TextView) getChildAt(i)).setText(mask); + ((TextView) getChildAt(i)).setTextColor(digitTextColor); } else { - ((TextView) getChildAt(i)).setText(""); + if (placeholder == null) { + ((TextView) getChildAt(i)).setText(""); + } else { + ((TextView) getChildAt(i)) + .setText(String.valueOf(placeholder.charAt(i))); + ((TextView) getChildAt(i)).setTextColor(digitPlaceholderTextColor); + } } if (editText.hasFocus()) { getChildAt(i).setSelected(accentType == ACCENT_ALL ||