2018-01-02 21:50:07 +01:00
|
|
|
package me.impy.aegis.helpers;
|
|
|
|
|
2018-06-06 23:53:33 +02:00
|
|
|
import android.view.View;
|
|
|
|
|
2018-01-02 21:50:07 +01:00
|
|
|
import com.amulyakhare.textdrawable.TextDrawable;
|
|
|
|
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
|
|
|
|
|
|
|
public class TextDrawableHelper {
|
|
|
|
private TextDrawableHelper() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-07 12:27:42 +02:00
|
|
|
public static TextDrawable generate(String text, String fallback, View view) {
|
2018-06-06 16:27:56 +02:00
|
|
|
if (text == null || text.isEmpty()) {
|
|
|
|
if (fallback == null || fallback.isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
text = fallback;
|
2018-01-02 21:50:07 +01:00
|
|
|
}
|
|
|
|
|
2018-06-07 14:33:33 +02:00
|
|
|
int color = ColorGenerator.MATERIAL.getColor(text);
|
2018-06-06 21:57:38 +02:00
|
|
|
return TextDrawable.builder().beginConfig()
|
2018-06-07 15:23:23 +02:00
|
|
|
.width(view.getLayoutParams().width)
|
|
|
|
.height(view.getLayoutParams().height)
|
2018-06-07 14:33:33 +02:00
|
|
|
.endConfig()
|
|
|
|
.buildRect(text.substring(0, 1).toUpperCase(), color);
|
2018-01-02 21:50:07 +01:00
|
|
|
}
|
|
|
|
}
|