LetterTileDrawable extends Drawable { static char findFirstUsableCharacter(final @NonNull String identifier) { int idx = 0; while (!isEnglishLetter(identifier.charAt(idx))) { if (++idx == identifier.length()) { return '@'; } } if (idx == 0 && identifier.length() > 1 && identifier.charAt(0) == '0' && isDigit(identifier.charAt(1))) { return findFirstUsableCharacter(identifier.substring(1)); } return identifier.charAt(idx); } LetterTileDrawable(final Resources res); static LetterTileDrawable fromText(Resources res, String identifier); @Override void draw(final Canvas canvas); @Override void setAlpha(final int alpha); @Override void setColorFilter(final ColorFilter cf); @Override int getOpacity(); void setScale(float scale); void setOffset(float offset); LetterTileDrawable setText(final String identifier); void setIsCircular(boolean isCircle);  }
@Test public void testFindFirstUsableLetter() { char c = LetterTileDrawable.findFirstUsableCharacter("@$$%#2138457"); assertThat(c).isEqualTo('2'); c = LetterTileDrawable.findFirstUsableCharacter("★"); assertThat(c).isEqualTo('@'); c = LetterTileDrawable.findFirstUsableCharacter("drew"); assertThat(c).isEqualTo('d'); c = LetterTileDrawable.findFirstUsableCharacter("01 File 1"); assertThat(c).isEqualTo('1'); c = LetterTileDrawable.findFirstUsableCharacter("001 File 1"); assertThat(c).isEqualTo('1'); c = LetterTileDrawable.findFirstUsableCharacter("000 Track 0"); assertThat(c).isEqualTo('0'); c = LetterTileDrawable.findFirstUsableCharacter("000"); assertThat(c).isEqualTo('0'); c = LetterTileDrawable.findFirstUsableCharacter("00"); assertThat(c).isEqualTo('0'); c = LetterTileDrawable.findFirstUsableCharacter("0"); assertThat(c).isEqualTo('0'); c = LetterTileDrawable.findFirstUsableCharacter("0-File1"); assertThat(c).isEqualTo('0'); c = LetterTileDrawable.findFirstUsableCharacter("00File1"); assertThat(c).isEqualTo('0'); c = LetterTileDrawable.findFirstUsableCharacter("0File1"); assertThat(c).isEqualTo('0'); c = LetterTileDrawable.findFirstUsableCharacter("000.txt"); assertThat(c).isEqualTo('0'); }