2018-01-02 21:50:07 +01:00
|
|
|
package me.impy.aegis.helpers;
|
|
|
|
|
|
|
|
import com.amulyakhare.textdrawable.TextDrawable;
|
|
|
|
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
|
|
|
|
|
|
|
public class TextDrawableHelper {
|
|
|
|
private TextDrawableHelper() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-06 16:27:56 +02:00
|
|
|
public static TextDrawable generate(String text, String fallback) {
|
|
|
|
if (text == null || text.isEmpty()) {
|
|
|
|
if (fallback == null || fallback.isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
text = fallback;
|
2018-01-02 21:50:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ColorGenerator generator = ColorGenerator.MATERIAL;
|
2018-06-06 16:27:56 +02:00
|
|
|
int color = generator.getColor(text);
|
|
|
|
return TextDrawable.builder().buildRound(text.substring(0, 1).toUpperCase(), color);
|
2018-01-02 21:50:07 +01:00
|
|
|
}
|
|
|
|
}
|