discord-jadx/app/src/main/java/com/discord/views/NumericBadgingView.java

161 lines
6.1 KiB
Java

package com.discord.views;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import androidx.core.content.ContextCompat;
import com.airbnb.lottie.parser.AnimatableValueParser;
import com.discord.R;
import com.discord.utilities.dimen.DimenUtils;
import com.discord.utilities.font.FontUtils;
import com.discord.views.CutoutView;
import d0.z.d.m;
/* compiled from: NumericBadgingView.kt */
public final class NumericBadgingView extends CutoutView {
public float p = ((float) DimenUtils.dpToPixels(12));
public int q = DimenUtils.dpToPixels(8);
public float r = ((float) DimenUtils.dpToPixels(4));
/* renamed from: s reason: collision with root package name */
public RectF f2132s = new RectF();
public String t = "";
public final Paint u;
public final Paint v;
/* compiled from: NumericBadgingView.kt */
public static final class a implements CutoutView.a {
public final RectF a;
public final float b;
public a(RectF rectF, float f) {
m.checkNotNullParameter(rectF, "badgeRect");
this.a = rectF;
this.b = f;
}
@Override // com.discord.views.CutoutView.a
public Path a(Context context, int i, int i2) {
m.checkNotNullParameter(context, "context");
RectF rectF = new RectF(0.0f, 0.0f, this.a.width(), this.a.height());
if (AnimatableValueParser.p1(context)) {
rectF.offset(((float) i) - this.a.width(), 0.0f);
}
float f = this.b;
rectF.inset(-f, -f);
Path path = new Path();
float height = ((((float) 2) * this.b) + this.a.height()) / 2.0f;
path.addRoundRect(rectF, height, height, Path.Direction.CW);
Path path2 = new Path();
path2.addRect(0.0f, 0.0f, (float) i, (float) i2, Path.Direction.CW);
Path path3 = new Path(path2);
path3.op(path, Path.Op.DIFFERENCE);
return path3;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof a)) {
return false;
}
a aVar = (a) obj;
return m.areEqual(this.a, aVar.a) && Float.compare(this.b, aVar.b) == 0;
}
public int hashCode() {
RectF rectF = this.a;
return Float.floatToIntBits(this.b) + ((rectF != null ? rectF.hashCode() : 0) * 31);
}
public String toString() {
StringBuilder K = c.d.b.a.a.K("BadgeRectStyle(badgeRect=");
K.append(this.a);
K.append(", insetPx=");
K.append(this.b);
K.append(")");
return K.toString();
}
}
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public NumericBadgingView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
m.checkNotNullParameter(context, "context");
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor((int) 4294901760L);
this.u = paint;
Paint paint2 = new Paint();
paint2.setAntiAlias(true);
paint2.setTextAlign(Paint.Align.CENTER);
paint2.setTextSize(this.p);
paint2.setColor((int) 4294967295L);
this.v = paint2;
setWillNotDraw(false);
int[] iArr = R.a.NumericBadgingView;
m.checkNotNullExpressionValue(iArr, "R.styleable.NumericBadgingView");
Context context2 = getContext();
m.checkNotNullExpressionValue(context2, "context");
TypedArray obtainStyledAttributes = context2.obtainStyledAttributes(attributeSet, iArr);
m.checkNotNullExpressionValue(obtainStyledAttributes, "obtainStyledAttributes(attrs, styleable)");
paint.setColor(obtainStyledAttributes.getColor(0, 0));
if (paint.getColor() == 0) {
paint.setColor(ContextCompat.getColor(context, 2131100324));
}
paint2.setColor(obtainStyledAttributes.getColor(1, 0));
if (paint2.getColor() == 0) {
paint2.setColor(ContextCompat.getColor(context, 2131100428));
}
paint2.setTypeface(FontUtils.INSTANCE.getThemedFont(context, 2130969326));
obtainStyledAttributes.recycle();
}
@Override // com.discord.views.CutoutView, android.view.View
public void draw(Canvas canvas) {
m.checkNotNullParameter(canvas, "canvas");
super.draw(canvas);
if (!(this.t.length() == 0)) {
Context context = getContext();
m.checkNotNullExpressionValue(context, "context");
float measuredWidth = AnimatableValueParser.p1(context) ? ((float) getMeasuredWidth()) - (this.f2132s.width() / 2.0f) : this.f2132s.width() / 2.0f;
int save = canvas.save();
canvas.translate(measuredWidth, this.f2132s.height() / 2.0f);
try {
float height = this.f2132s.height() / 2.0f;
canvas.drawRoundRect(this.f2132s, height, height, this.u);
canvas.drawText(this.t, 0.0f, -((this.v.descent() + this.v.ascent()) / 2.0f), this.v);
} finally {
canvas.restoreToCount(save);
}
}
}
@Override // com.discord.views.CutoutView, android.view.View
public void onFinishInflate() {
super.onFinishInflate();
if (isInEditMode()) {
setBadgeNumber(42);
}
}
public final void setBadgeNumber(int i) {
if (i <= 0) {
this.t = "";
setStyle(CutoutView.a.d.a);
return;
}
this.t = i >= 100 ? "99+" : String.valueOf(i);
float textSize = this.v.getTextSize() + ((float) this.q);
float f = textSize / 2.0f;
float measureText = i >= 10 ? (this.v.measureText(this.t) + textSize) / 2.0f : f;
this.f2132s.set(-measureText, -f, measureText, f);
setStyle(new a(this.f2132s, this.r));
invalidate();
}
}