mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-27 09:16:08 +00:00
parent
86580e38af
commit
f9b4e8fa3e
1 changed files with 14 additions and 1 deletions
|
@ -5,6 +5,7 @@ import android.view.View;
|
||||||
import com.amulyakhare.textdrawable.TextDrawable;
|
import com.amulyakhare.textdrawable.TextDrawable;
|
||||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||||
|
|
||||||
|
import java.text.BreakIterator;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class TextDrawableHelper {
|
public class TextDrawableHelper {
|
||||||
|
@ -48,6 +49,18 @@ public class TextDrawableHelper {
|
||||||
.width(view.getLayoutParams().width)
|
.width(view.getLayoutParams().width)
|
||||||
.height(view.getLayoutParams().height)
|
.height(view.getLayoutParams().height)
|
||||||
.endConfig()
|
.endConfig()
|
||||||
.buildRound(text.substring(0, 1).toUpperCase(), color);
|
.buildRound(getFirstGrapheme(text).toUpperCase(), color);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getFirstGrapheme(String text) {
|
||||||
|
BreakIterator iter = BreakIterator.getCharacterInstance();
|
||||||
|
iter.setText(text);
|
||||||
|
|
||||||
|
int start = iter.first(), end = iter.next();
|
||||||
|
if (end == BreakIterator.DONE) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return text.substring(start, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue