127 lines
5.6 KiB
Java
127 lines
5.6 KiB
Java
|
package com.discord.utilities.textprocessing;
|
||
|
|
||
|
import android.graphics.Canvas;
|
||
|
import android.graphics.Paint;
|
||
|
import android.graphics.Path;
|
||
|
import android.graphics.RectF;
|
||
|
import android.text.style.ReplacementSpan;
|
||
|
import com.discord.utilities.string.StringUtilsKt;
|
||
|
import d0.g0.a;
|
||
|
import d0.g0.t;
|
||
|
import d0.g0.y;
|
||
|
import d0.z.d.m;
|
||
|
import kotlin.jvm.functions.Function1;
|
||
|
import kotlin.jvm.internal.DefaultConstructorMarker;
|
||
|
/* compiled from: SimpleRoundedBackgroundSpan.kt */
|
||
|
public final class SimpleRoundedBackgroundSpan extends ReplacementSpan {
|
||
|
private final int backgroundColor;
|
||
|
private final float cornerRadius;
|
||
|
private final int edgeHorizontalMargin;
|
||
|
private final int edgeHorizontalPadding;
|
||
|
private final int endIndex;
|
||
|
private final boolean isTrimEnabled;
|
||
|
private final int startIndex;
|
||
|
private final Integer textColor;
|
||
|
private final Function1<String, String> transformSpannedText;
|
||
|
|
||
|
/* JADX DEBUG: Multi-variable search result rejected for r9v0, resolved type: kotlin.jvm.functions.Function1<? super java.lang.String, java.lang.String> */
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
public SimpleRoundedBackgroundSpan(int i, int i2, int i3, int i4, int i5, float f, Integer num, boolean z2, Function1<? super String, String> function1) {
|
||
|
this.startIndex = i;
|
||
|
this.endIndex = i2;
|
||
|
this.edgeHorizontalPadding = i3;
|
||
|
this.edgeHorizontalMargin = i4;
|
||
|
this.backgroundColor = i5;
|
||
|
this.cornerRadius = f;
|
||
|
this.textColor = num;
|
||
|
this.isTrimEnabled = z2;
|
||
|
this.transformSpannedText = function1;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: this call moved to the top of the method (can break code semantics) */
|
||
|
public /* synthetic */ SimpleRoundedBackgroundSpan(int i, int i2, int i3, int i4, int i5, float f, Integer num, boolean z2, Function1 function1, int i6, DefaultConstructorMarker defaultConstructorMarker) {
|
||
|
this(i, i2, i3, i4, i5, f, (i6 & 64) != 0 ? null : num, (i6 & 128) != 0 ? true : z2, (i6 & 256) != 0 ? null : function1);
|
||
|
}
|
||
|
|
||
|
private final float[] calculateCornerRadius(int i, int i2, CharSequence charSequence) {
|
||
|
float f = 0.0f;
|
||
|
float f2 = i == this.startIndex ? this.cornerRadius : 0.0f;
|
||
|
if (isAtEndEdge(i2, charSequence)) {
|
||
|
f = this.cornerRadius;
|
||
|
}
|
||
|
return new float[]{f2, f2, f, f, f, f, f2, f2};
|
||
|
}
|
||
|
|
||
|
private final boolean isAtEndEdge(int i, CharSequence charSequence) {
|
||
|
Character orNull;
|
||
|
int i2 = this.endIndex;
|
||
|
if (i != i2) {
|
||
|
return this.isTrimEnabled && i2 - i == 1 && charSequence != null && (orNull = y.getOrNull(charSequence, i)) != null && a.isWhitespace(orNull.charValue());
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/* JADX WARNING: Removed duplicated region for block: B:19:0x0071 */
|
||
|
@Override // android.text.style.ReplacementSpan
|
||
|
public void draw(Canvas canvas, CharSequence charSequence, int i, int i2, float f, int i3, int i4, int i5, Paint paint) {
|
||
|
float f2;
|
||
|
Integer num;
|
||
|
int i6;
|
||
|
m.checkNotNullParameter(canvas, "canvas");
|
||
|
m.checkNotNullParameter(paint, "paint");
|
||
|
String str = null;
|
||
|
String transformOrEmpty = StringUtilsKt.transformOrEmpty(charSequence != null ? charSequence.subSequence(i, i2).toString() : null, this.transformSpannedText);
|
||
|
if (!t.isBlank(transformOrEmpty)) {
|
||
|
str = transformOrEmpty;
|
||
|
}
|
||
|
if (str != null) {
|
||
|
int i7 = this.edgeHorizontalPadding;
|
||
|
float measureText = paint.measureText(str);
|
||
|
if (i == this.startIndex) {
|
||
|
f += (float) this.edgeHorizontalMargin;
|
||
|
i6 = this.edgeHorizontalPadding;
|
||
|
} else if (f != 0.0f || i3 == 0) {
|
||
|
f2 = f;
|
||
|
RectF rectF = new RectF(f, (float) i3, measureText + f + ((float) i7), (float) i5);
|
||
|
Path path = new Path();
|
||
|
path.addRoundRect(rectF, calculateCornerRadius(i, i2, charSequence), Path.Direction.CW);
|
||
|
Paint paint2 = new Paint(paint);
|
||
|
paint2.setColor(this.backgroundColor);
|
||
|
canvas.drawPath(path, paint2);
|
||
|
num = this.textColor;
|
||
|
if (num != null) {
|
||
|
paint.setColor(num.intValue());
|
||
|
}
|
||
|
canvas.drawText(str, f2, (float) i4, paint);
|
||
|
} else {
|
||
|
i6 = this.edgeHorizontalPadding;
|
||
|
}
|
||
|
f2 = ((float) i6) + f;
|
||
|
i7 += i6;
|
||
|
RectF rectF = new RectF(f, (float) i3, measureText + f + ((float) i7), (float) i5);
|
||
|
Path path = new Path();
|
||
|
path.addRoundRect(rectF, calculateCornerRadius(i, i2, charSequence), Path.Direction.CW);
|
||
|
Paint paint2 = new Paint(paint);
|
||
|
paint2.setColor(this.backgroundColor);
|
||
|
canvas.drawPath(path, paint2);
|
||
|
num = this.textColor;
|
||
|
if (num != null) {
|
||
|
}
|
||
|
canvas.drawText(str, f2, (float) i4, paint);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // android.text.style.ReplacementSpan
|
||
|
public int getSize(Paint paint, CharSequence charSequence, int i, int i2, Paint.FontMetricsInt fontMetricsInt) {
|
||
|
m.checkNotNullParameter(paint, "paint");
|
||
|
int roundToInt = d0.a0.a.roundToInt(paint.measureText(StringUtilsKt.transformOrEmpty(charSequence != null ? charSequence.subSequence(i, i2).toString() : null, this.transformSpannedText)));
|
||
|
if (i == this.startIndex) {
|
||
|
roundToInt += this.edgeHorizontalMargin + this.edgeHorizontalPadding;
|
||
|
}
|
||
|
if (isAtEndEdge(i2, charSequence)) {
|
||
|
roundToInt += this.edgeHorizontalMargin;
|
||
|
}
|
||
|
return roundToInt + this.edgeHorizontalPadding;
|
||
|
}
|
||
|
}
|