Aegis/app/src/main/java/me/impy/aegis/helpers/TextDrawableHelper.java
2018-06-07 15:23:23 +02:00

28 lines
842 B
Java

package me.impy.aegis.helpers;
import android.view.View;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
public class TextDrawableHelper {
private TextDrawableHelper() {
}
public static TextDrawable generate(String text, String fallback, View view) {
if (text == null || text.isEmpty()) {
if (fallback == null || fallback.isEmpty()) {
return null;
}
text = fallback;
}
int color = ColorGenerator.MATERIAL.getColor(text);
return TextDrawable.builder().beginConfig()
.width(view.getLayoutParams().width)
.height(view.getLayoutParams().height)
.endConfig()
.buildRect(text.substring(0, 1).toUpperCase(), color);
}
}