mirror of
https://github.com/k0shk0sh/FastHub.git
synced 2025-12-08 19:05:54 +00:00
more improvement for #92
This commit is contained in:
parent
07fc6d1fdd
commit
7ead042c71
@ -135,9 +135,11 @@ public class ViewHelper {
|
||||
}
|
||||
|
||||
@ColorInt public static int generateTextColor(int color) {
|
||||
return Color.rgb(255 - Color.red(color),
|
||||
255 - Color.green(color),
|
||||
255 - Color.blue(color));
|
||||
int red = Color.red(color);
|
||||
int green = Color.green(color);
|
||||
int blue = Color.blue(color);
|
||||
double lum = (((0.299 * red) + ((0.587 * green) + (0.114 * blue))));
|
||||
return lum > 186 ? 0xFF000000 : 0xFFFFFFFF;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -59,9 +59,7 @@ public class IssueTimelineViewHolder extends BaseViewHolder<IssueEventAdapterMod
|
||||
int color = Color.parseColor("#" + labelModel.getColor());
|
||||
spannableBuilder
|
||||
.append(" ")
|
||||
.background(SpannableBuilder.builder()
|
||||
.append(" " + labelModel.getName() + " ",
|
||||
new RoundBackgroundSpan(color, 4)), color);
|
||||
.append(" " + labelModel.getName() + " ", new RoundBackgroundSpan(color, 5));
|
||||
} else if (event == IssueEventType.assigned || event == IssueEventType.unassigned) {
|
||||
spannableBuilder
|
||||
.append(" ")
|
||||
|
||||
@ -59,9 +59,7 @@ public class PullRequestTimelineViewHolder extends BaseViewHolder<PullRequestAda
|
||||
int color = Color.parseColor("#" + labelModel.getColor());
|
||||
spannableBuilder
|
||||
.append(" ")
|
||||
.background(SpannableBuilder.builder()
|
||||
.append(" " + labelModel.getName() + " ",
|
||||
new RoundBackgroundSpan(color, 4)), color);
|
||||
.append(" " + labelModel.getName() + " ", new RoundBackgroundSpan(color, 5));
|
||||
} else if (event == IssueEventType.assigned || event == IssueEventType.unassigned) {
|
||||
spannableBuilder
|
||||
.append(" ")
|
||||
|
||||
@ -7,26 +7,29 @@ import android.graphics.RectF;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.style.ReplacementSpan;
|
||||
|
||||
public class RoundBackgroundSpan extends ReplacementSpan {
|
||||
private Paint mPaint = new Paint();
|
||||
private float mRadius;
|
||||
private RectF mRectF = new RectF();
|
||||
private int mWidth = -1;
|
||||
import com.fastaccess.helper.ViewHelper;
|
||||
|
||||
public RoundBackgroundSpan(int i, float f) {
|
||||
this.mPaint.setColor(i);
|
||||
this.mPaint.setAntiAlias(true);
|
||||
this.mRadius = f;
|
||||
public class RoundBackgroundSpan extends ReplacementSpan {
|
||||
private Paint paint = new Paint();
|
||||
private Paint empty = new Paint();
|
||||
private float radius;
|
||||
private int width = -1;
|
||||
|
||||
public RoundBackgroundSpan(int color, float radius) {
|
||||
this.paint.setColor(color);
|
||||
this.paint.setAntiAlias(true);
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public int getSize(@NonNull Paint paint, CharSequence charSequence, int i, int i2, FontMetricsInt fontMetricsInt) {
|
||||
this.mWidth = Math.round((float) ((int) paint.measureText(charSequence, i, i2)));
|
||||
this.mWidth = (int) (((float) this.mWidth) + (this.mRadius * 4.0f));
|
||||
return this.mWidth;
|
||||
this.width = Math.round((float) ((int) paint.measureText(charSequence, i, i2)));
|
||||
this.width = (int) (((float) this.width) + (this.radius * 4.0f));
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public void draw(@NonNull Canvas canvas, CharSequence charSequence, int i, int i2, float f, int i3, int i4, int i5, @NonNull Paint paint) {
|
||||
canvas.drawRoundRect(new RectF(f, (float) i3, ((float) this.mWidth) + f, (float) i5), this.mRadius, this.mRadius, this.mPaint);
|
||||
canvas.drawText(charSequence, i, i2, f + (this.mRadius * 2.0f), (float) i4, paint);
|
||||
canvas.drawRoundRect(new RectF(f, (float) i3, ((float) this.width) + f, (float) i5), this.radius, this.radius, this.paint);
|
||||
paint.setColor(ViewHelper.generateTextColor(this.paint.getColor()));
|
||||
canvas.drawText(charSequence, i, i2, f + (this.radius * 2.0f), (float) i4, paint);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user