package xyz.stream.view;

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/* JADX INFO: loaded from: classes3.dex */
public class PlayingView extends View {

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public static final /* synthetic */ int f36323h = 0;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Paint f36324a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final float[] f36325b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final ValueAnimator[] f36326c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public long f36327d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final float f36328e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final float f36329f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final float f36330g;

    public PlayingView(Context context) {
        this(context, null);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void setBarColor(int i10) {
        this.f36324a.setColor(i10);
        invalidate();
    }

    @Override // android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        start();
    }

    @Override // android.view.View
    public void onDetachedFromWindow() {
        stop();
        super.onDetachedFromWindow();
    }

    @Override // android.view.View
    public void onDraw(@NonNull Canvas canvas) {
        super.onDraw(canvas);
        float paddingLeft = getPaddingLeft();
        float width = getWidth();
        float paddingLeft2 = (width - getPaddingLeft()) - getPaddingRight();
        float height = (getHeight() - getPaddingTop()) - getPaddingBottom();
        float fMax = (getLayoutParams() == null || getLayoutParams().height != -2) ? Math.max(0.0f, height) : Math.max(0.0f, (getMeasuredHeight() - getPaddingTop()) - getPaddingBottom());
        float f10 = this.f36328e;
        float f11 = this.f36329f;
        float f12 = (f11 * 2.0f) + (3.0f * f10);
        float f13 = f12 > 0.0f ? paddingLeft2 / f12 : 1.0f;
        float f14 = this.f36330g;
        float fMax2 = Math.max(Math.min(f13, f14 > 0.0f ? fMax / f14 : 1.0f), 0.1f);
        float f15 = f10 * fMax2;
        float f16 = f11 * fMax2;
        float f17 = f14 * fMax2;
        float paddingTop = ((height - f17) / 2.0f) + getPaddingTop();
        float f18 = 0.3f * f15;
        for (int i10 = 0; i10 < 3; i10++) {
            float f19 = this.f36325b[i10] * f17;
            float f20 = ((f17 - f19) / 2.0f) + paddingTop;
            canvas.drawRoundRect(new RectF(paddingLeft, f20, paddingLeft + f15, f19 + f20), f18, f18, this.f36324a);
            paddingLeft += f15 + f16;
        }
    }

    @Override // android.view.View
    public void onMeasure(int i10, int i11) {
        int paddingRight = getPaddingRight() + getPaddingLeft();
        int paddingBottom = getPaddingBottom() + getPaddingTop();
        float f10 = (this.f36329f * 2.0f) + (this.f36328e * 3.0f);
        int iResolveSize = View.resolveSize(((int) f10) + paddingRight, i10);
        ViewGroup.LayoutParams layoutParams = getLayoutParams();
        float f11 = this.f36330g;
        if (layoutParams == null || getLayoutParams().height != -2) {
            setMeasuredDimension(iResolveSize, View.resolveSize(paddingBottom + ((int) f11), i11));
        } else {
            setMeasuredDimension(iResolveSize, paddingBottom + ((int) (f11 * Math.max(f10 > 0.0f ? Math.max(0, iResolveSize - paddingRight) / f10 : 1.0f, 0.1f))));
        }
    }

    public void setBarColorRes(@ColorRes int i10) {
        Context context = getContext();
        Object obj = g0.d.f26125a;
        int color = context.getColor(i10);
        if (Looper.myLooper() == Looper.getMainLooper()) {
            setBarColor(color);
        } else {
            post(new i0.o(color, 17, this));
        }
    }

    public void setDuration(long j10) {
        this.f36327d = j10;
        for (ValueAnimator valueAnimator : this.f36326c) {
            if (valueAnimator != null) {
                valueAnimator.setDuration(j10);
            }
        }
    }

    public void start() {
        for (ValueAnimator valueAnimator : this.f36326c) {
            if (valueAnimator != null && !valueAnimator.isStarted()) {
                valueAnimator.start();
            }
        }
    }

    public void stop() {
        for (ValueAnimator valueAnimator : this.f36326c) {
            if (valueAnimator != null) {
                valueAnimator.cancel();
            }
        }
    }

    public PlayingView(Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public PlayingView(Context context, @Nullable AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        Paint paint = new Paint(1);
        this.f36324a = paint;
        this.f36325b = new float[3];
        this.f36326c = new ValueAnimator[3];
        this.f36327d = 700L;
        paint.setColor(-1);
        float f10 = getResources().getDisplayMetrics().density;
        float f11 = 6.0f * f10;
        this.f36328e = f11;
        this.f36329f = f11;
        this.f36330g = f10 * 24.0f;
        for (int i11 = 0; i11 < 3; i11++) {
            this.f36325b[i11] = (i11 * 0.2f) + 0.4f;
        }
        for (final int i12 = 0; i12 < 3; i12++) {
            ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.3f, 1.0f, 0.4f);
            valueAnimatorOfFloat.setDuration(this.f36327d);
            valueAnimatorOfFloat.setRepeatCount(-1);
            valueAnimatorOfFloat.setRepeatMode(1);
            valueAnimatorOfFloat.setInterpolator(new LinearInterpolator());
            valueAnimatorOfFloat.setStartDelay(((long) i12) * 160);
            valueAnimatorOfFloat.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: xyz.stream.view.g
                @Override // android.animation.ValueAnimator.AnimatorUpdateListener
                public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                    int i13 = PlayingView.f36323h;
                    PlayingView playingView = this.f36495a;
                    playingView.getClass();
                    playingView.f36325b[i12] = ((Float) valueAnimator.getAnimatedValue()).floatValue();
                    playingView.invalidate();
                }
            });
            this.f36326c[i12] = valueAnimatorOfFloat;
        }
    }
}
