Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Badge for "special" repos #86

Closed
janheinrichmerker opened this issue Mar 8, 2017 · 2 comments
Closed

Badge for "special" repos #86

janheinrichmerker opened this issue Mar 8, 2017 · 2 comments

Comments

@janheinrichmerker
Copy link
Contributor

Would be nice to use some sort of badge to identify forked/mirrored/private repos in the repo list. Maybe this could be achieved by using a separate TextView with a border (with rounded corners) around it or even using a custom Spannable to use the "badge" in the same TextView

@k0shk0sh
Copy link
Owner

k0shk0sh commented Mar 8, 2017

Yup, this would be great, i'll see what I could do about it.

@janheinrichmerker
Copy link
Contributor Author

After a bit of investigation I think an improved version of this Stackoverflow question could work:

public class RoundedBorderSpan extends ReplacementSpan {

    private static final int BORDER_WIDTH = 1; // in dp
    private static final int CORNER_RADIUS = 2; // in dp
    private static final int PADDING_X = 8; // in dp

    private int   borderColor;
    private int   textColor;

    public RoundedBorderSpan(int borderColor, int textColor) {
        tgis.borderColor = borderColor;
        this.textColor = textColor;
    }

    @Override
    public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
        return (int) (PADDING_X + paint.measureText(text.subSequence(start, end).toString()) + PADDING_X);
    }

    @Override
    public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
        float width = paint.measureText(text.subSequence(start, end).toString());
        RectF rect = new RectF(x, top, x + width + 2 * PADDING_X, bottom);
        paint.setColor(borderColor);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(BORDER_SIZE);
        canvas.drawRoundRect(rect, CORNER_RADIUS, CORNER_RADIUS, paint);
        paint.setColor(textColor);
        paint.setStyle(Paint.Style.FILL);
        canvas.drawText(text, start, end, x + PADDING_X, y, paint);
    }
}

Not sure if that'll work but you get the idea.

(One known issue with this is that the styling will break if the text in the span contains a line break. That should never happen anyway because the badges would be the first "words" displayed in the TextView)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants