package xyz.stream.view.refresh.drawable;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.Region;
import androidx.annotation.NonNull;
import java.util.ArrayList;
import java.util.List;
import xyz.stream.view.refresh.drawable.path.PathParser;

/* JADX INFO: loaded from: classes3.dex */
public class PathsDrawable extends PaintDrawable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public Bitmap f36552a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public boolean f36553b;
    protected List<Integer> mColors;
    protected int mOriginHeight;
    protected int mOriginWidth;
    protected List<Path> mPaths;
    protected List<Path> mltOriginPath;
    protected List<String> mltOriginSvg;
    protected static final Region REGION = new Region();
    protected static final Region MAX_CLIP = new Region(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
    protected int mWidth = 1;
    protected int mHeight = 1;
    protected int mStartX = 0;
    protected int mStartY = 0;

    public void declareOriginal(int i10, int i11, int i12, int i13) {
        this.mStartX = i10;
        this.mStartY = i11;
        this.mWidth = i12;
        this.mOriginWidth = i12;
        this.mHeight = i13;
        this.mOriginHeight = i13;
        Rect bounds = getBounds();
        int i14 = bounds.left;
        int i15 = bounds.top;
        super.setBounds(i14, i15, i12 + i14, i13 + i15);
    }

    @Override // android.graphics.drawable.Drawable
    public void draw(@NonNull Canvas canvas) {
        Rect bounds = getBounds();
        int iWidth = bounds.width();
        int iHeight = bounds.height();
        if (this.mPaint.getAlpha() == 255) {
            canvas.save();
            canvas.translate(bounds.left - this.mStartX, bounds.top - this.mStartY);
            if (this.mPaths != null) {
                for (int i10 = 0; i10 < this.mPaths.size(); i10++) {
                    List<Integer> list = this.mColors;
                    if (list != null && i10 < list.size()) {
                        this.mPaint.setColor(this.mColors.get(i10).intValue());
                    }
                    canvas.drawPath(this.mPaths.get(i10), this.mPaint);
                }
                this.mPaint.setAlpha(255);
            }
            canvas.restore();
            return;
        }
        Bitmap bitmap = this.f36552a;
        if (bitmap == null || iWidth != bitmap.getWidth() || iHeight != this.f36552a.getHeight()) {
            this.f36552a = Bitmap.createBitmap(iWidth, iHeight, Bitmap.Config.ARGB_8888);
            this.f36553b = true;
        }
        if (this.f36553b) {
            this.f36552a.eraseColor(0);
            Canvas canvas2 = new Canvas(this.f36552a);
            canvas2.translate(-this.mStartX, -this.mStartY);
            if (this.mPaths != null) {
                for (int i11 = 0; i11 < this.mPaths.size(); i11++) {
                    List<Integer> list2 = this.mColors;
                    if (list2 != null && i11 < list2.size()) {
                        this.mPaint.setColor(this.mColors.get(i11).intValue());
                    }
                    canvas2.drawPath(this.mPaths.get(i11), this.mPaint);
                }
            }
            this.f36553b = false;
        }
        canvas.drawBitmap(this.f36552a, bounds.left, bounds.top, this.mPaint);
    }

    public boolean onMeasure() {
        Integer num;
        Integer numValueOf;
        Integer numValueOf2;
        int i10;
        List<Path> list = this.mPaths;
        Integer numValueOf3 = null;
        if (list != null) {
            Integer numValueOf4 = null;
            numValueOf = null;
            numValueOf2 = null;
            for (Path path : list) {
                Region region = REGION;
                region.setPath(path, MAX_CLIP);
                Rect bounds = region.getBounds();
                numValueOf3 = Integer.valueOf(Math.min(numValueOf3 == null ? bounds.top : numValueOf3.intValue(), bounds.top));
                numValueOf4 = Integer.valueOf(Math.min(numValueOf4 == null ? bounds.left : numValueOf4.intValue(), bounds.left));
                numValueOf = Integer.valueOf(Math.max(numValueOf == null ? bounds.right : numValueOf.intValue(), bounds.right));
                numValueOf2 = Integer.valueOf(Math.max(numValueOf2 == null ? bounds.bottom : numValueOf2.intValue(), bounds.bottom));
            }
            num = numValueOf3;
            numValueOf3 = numValueOf4;
        } else {
            num = null;
            numValueOf = null;
            numValueOf2 = null;
        }
        this.mStartX = numValueOf3 == null ? 0 : numValueOf3.intValue();
        this.mStartY = num == null ? 0 : num.intValue();
        this.mWidth = numValueOf == null ? 0 : numValueOf.intValue() - this.mStartX;
        int iIntValue = numValueOf2 == null ? 0 : numValueOf2.intValue() - this.mStartY;
        this.mHeight = iIntValue;
        if (this.mOriginWidth == 0) {
            this.mOriginWidth = this.mWidth;
        }
        if (this.mOriginHeight == 0) {
            this.mOriginHeight = iIntValue;
        }
        Rect bounds2 = getBounds();
        int i11 = this.mWidth;
        if (i11 != 0 && (i10 = this.mHeight) != 0) {
            int i12 = bounds2.left;
            int i13 = bounds2.top;
            super.setBounds(i12, i13, i11 + i12, i10 + i13);
            return true;
        }
        if (this.mOriginWidth == 0) {
            this.mOriginWidth = 1;
        }
        if (this.mOriginHeight == 0) {
            this.mOriginHeight = 1;
        }
        this.mHeight = 1;
        this.mWidth = 1;
        return false;
    }

    public void parserColors(int... iArr) {
        this.mColors = new ArrayList();
        for (int i10 : iArr) {
            this.mColors.add(Integer.valueOf(i10));
        }
    }

    public boolean parserPaths(String... strArr) {
        this.mOriginHeight = 0;
        this.mOriginWidth = 0;
        this.mltOriginSvg = new ArrayList();
        ArrayList arrayList = new ArrayList();
        this.mltOriginPath = arrayList;
        this.mPaths = arrayList;
        for (String str : strArr) {
            this.mltOriginSvg.add(str);
            this.mltOriginPath.add(PathParser.createPathFromPathData(str));
        }
        return onMeasure();
    }

    @Override // android.graphics.drawable.Drawable
    public void setBounds(int i10, int i11, int i12, int i13) {
        int i14 = i12 - i10;
        int i15 = i13 - i11;
        List<Path> list = this.mltOriginPath;
        if (list == null || list.isEmpty() || (i14 == this.mWidth && i15 == this.mHeight)) {
            super.setBounds(i10, i11, i12, i13);
            return;
        }
        int i16 = this.mStartX;
        int i17 = this.mStartY;
        float f10 = i14;
        float f11 = i15;
        this.mPaths = PathParser.transformScale((f10 * 1.0f) / this.mOriginWidth, (f11 * 1.0f) / this.mOriginHeight, this.mltOriginPath, this.mltOriginSvg);
        if (onMeasure()) {
            return;
        }
        this.mWidth = i14;
        this.mHeight = i15;
        this.mStartX = (int) (((i16 * 1.0f) * f10) / this.mOriginWidth);
        this.mStartY = (int) (((i17 * 1.0f) * f11) / this.mOriginHeight);
        super.setBounds(i10, i11, i12, i13);
    }

    public void setGeometricHeight(int i10) {
        Rect bounds = getBounds();
        float fHeight = (i10 * 1.0f) / bounds.height();
        setBounds((int) (bounds.left * fHeight), (int) (bounds.top * fHeight), (int) (bounds.right * fHeight), (int) (bounds.bottom * fHeight));
    }

    public void setGeometricWidth(int i10) {
        Rect bounds = getBounds();
        float fWidth = (i10 * 1.0f) / bounds.width();
        setBounds((int) (bounds.left * fWidth), (int) (bounds.top * fWidth), (int) (bounds.right * fWidth), (int) (bounds.bottom * fWidth));
    }

    @Override // android.graphics.drawable.Drawable
    public void setBounds(@NonNull Rect rect) {
        setBounds(rect.left, rect.top, rect.right, rect.bottom);
    }
}
