Spotbug: Simple field is used like an enum

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-12-28 14:44:38 +01:00
parent f48575bfec
commit a33f3fe400
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B

View File

@ -42,9 +42,9 @@ import androidx.core.content.res.ResourcesCompat;
*/
public class StatusDrawable extends Drawable {
private String text;
private @DrawableRes int icon = -1;
private StatusDrawableType icon = StatusDrawableType.UNDEFINED;
private Paint textPaint;
private int backgroundColor;
private final int backgroundColor;
private final float radius;
private Context context;
@ -54,17 +54,17 @@ public class StatusDrawable extends Drawable {
if ("dnd".equals(status)) {
icon = R.drawable.ic_user_status_dnd;
icon = StatusDrawableType.DND;
this.context = context;
} else if (TextUtils.isEmpty(statusIcon) && status != null) {
switch (status) {
case "online":
icon = R.drawable.online_status;
icon = StatusDrawableType.ONLINE;
this.context = context;
break;
case "away":
icon = R.drawable.ic_user_status_away;
icon = StatusDrawableType.AWAY;
this.context = context;
break;
@ -95,7 +95,7 @@ public class StatusDrawable extends Drawable {
canvas.drawText(text, radius, radius - ((textPaint.descent() + textPaint.ascent()) / 2), textPaint);
}
if (icon != -1) {
if (icon != StatusDrawableType.UNDEFINED) {
Paint backgroundPaint = new Paint();
backgroundPaint.setStyle(Paint.Style.FILL);
@ -104,7 +104,7 @@ public class StatusDrawable extends Drawable {
canvas.drawCircle(radius, radius, radius, backgroundPaint);
Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), icon, null);
Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), icon.drawableId, null);
if (drawable != null) {
drawable.setBounds(0,
@ -130,4 +130,18 @@ public class StatusDrawable extends Drawable {
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}
private enum StatusDrawableType {
DND(R.drawable.ic_user_status_dnd),
ONLINE(R.drawable.online_status),
AWAY(R.drawable.ic_user_status_away),
UNDEFINED(-1);
@DrawableRes
private final int drawableId;
StatusDrawableType(int drawableId) {
this.drawableId = drawableId;
}
}
}