CardNumberTransformation implements TransformationMethod { @Override public CharSequence getTransformation(final CharSequence source, View view) { if (source.length() >= 9) { StringBuilder result = new StringBuilder() .append(FOUR_DOTS) .append(" ") .append(source.subSequence(source.length() - 4, source.length())); char[] padding = new char[source.length() - result.length()]; Arrays.fill(padding, Character.MIN_VALUE); result.insert(0, padding); return result.toString(); } return source; }  @Override CharSequence getTransformation(final CharSequence source, View view); @Override void onFocusChanged(View view, CharSequence sourceText, boolean focused, int direction, Rect previouslyFocusedRect);  }
@Test public void masksCardNumber() { String transformed = (String) mTransform.getTransformation("4111111111111111", null); assertEquals("\u0000\u0000\u0000\u0000\u0000\u0000\u0000•••• 1111", transformed); }
@Test public void doesNotMaskCardNumbersSmallerThanNineCharacters() { String transformed = (String) mTransform.getTransformation("41111111", null); assertEquals("41111111", transformed); }