package com.bytedance.adsdk.ugeno.ef.yz;

import a3.r;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.widget.ImageView;
import com.google.android.gms.measurement.internal.u1;
import java.util.HashSet;

/* JADX INFO: loaded from: classes.dex */
public class ro extends Drawable {
    private final int ajl;
    private Shader.TileMode dsz;
    private Shader.TileMode duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private final Paint f6336ef;
    private float fhx;
    private float gof;
    private ColorStateList gqi;
    private final boolean[] irt;
    private final Paint jnr;
    private final RectF ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private final RectF f6337lb;
    private boolean onz;
    private boolean qhl;
    private final Matrix vt;
    private ImageView.ScaleType wey;
    private final int wsy;
    private final RectF wu;
    private final Bitmap yz;
    private final RectF fm = new RectF();
    private final RectF ro = new RectF();

    /* JADX INFO: renamed from: com.bytedance.adsdk.ugeno.ef.yz.ro$1, reason: invalid class name */
    public static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] fm;

        static {
            int[] iArr = new int[ImageView.ScaleType.values().length];
            fm = iArr;
            try {
                iArr[ImageView.ScaleType.CENTER.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                fm[ImageView.ScaleType.CENTER_CROP.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                fm[ImageView.ScaleType.CENTER_INSIDE.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                fm[ImageView.ScaleType.FIT_CENTER.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                fm[ImageView.ScaleType.FIT_END.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                fm[ImageView.ScaleType.FIT_START.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                fm[ImageView.ScaleType.FIT_XY.ordinal()] = 7;
            } catch (NoSuchFieldError unused7) {
            }
        }
    }

    public ro(Bitmap bitmap) {
        RectF rectF = new RectF();
        this.f6337lb = rectF;
        this.wu = new RectF();
        this.vt = new Matrix();
        this.ku = new RectF();
        Shader.TileMode tileMode = Shader.TileMode.CLAMP;
        this.duv = tileMode;
        this.dsz = tileMode;
        this.onz = true;
        this.fhx = 0.0f;
        this.irt = new boolean[]{true, true, true, true};
        this.qhl = false;
        this.gof = 0.0f;
        this.gqi = ColorStateList.valueOf(-16777216);
        this.wey = ImageView.ScaleType.FIT_CENTER;
        this.yz = bitmap;
        int width = bitmap.getWidth();
        this.ajl = width;
        int height = bitmap.getHeight();
        this.wsy = height;
        rectF.set(0.0f, 0.0f, width, height);
        Paint paint = new Paint();
        this.jnr = paint;
        paint.setStyle(Paint.Style.FILL);
        paint.setAntiAlias(true);
        Paint paint2 = new Paint();
        this.f6336ef = paint2;
        paint2.setStyle(Paint.Style.STROKE);
        paint2.setAntiAlias(true);
        paint2.setColor(this.gqi.getColorForState(getState(), -16777216));
        paint2.setStrokeWidth(this.gof);
    }

    public static Bitmap ro(Drawable drawable) {
        if (drawable == null) {
            return null;
        }
        if (drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        }
        try {
            Bitmap bitmapCreateBitmap = Bitmap.createBitmap(Math.max(drawable.getIntrinsicWidth(), 2), Math.max(drawable.getIntrinsicHeight(), 2), Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(bitmapCreateBitmap);
            drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            drawable.draw(canvas);
            return bitmapCreateBitmap;
        } catch (Throwable unused) {
            return null;
        }
    }

    @Override // android.graphics.drawable.Drawable
    public void draw(Canvas canvas) {
        if (this.onz) {
            BitmapShader bitmapShader = new BitmapShader(this.yz, this.duv, this.dsz);
            Shader.TileMode tileMode = this.duv;
            Shader.TileMode tileMode2 = Shader.TileMode.CLAMP;
            if (tileMode == tileMode2 && this.dsz == tileMode2) {
                bitmapShader.setLocalMatrix(this.vt);
            }
            this.jnr.setShader(bitmapShader);
            this.onz = false;
        }
        if (this.qhl) {
            if (this.gof <= 0.0f) {
                canvas.drawOval(this.ro, this.jnr);
                return;
            } else {
                canvas.drawOval(this.ro, this.jnr);
                canvas.drawOval(this.wu, this.f6336ef);
                return;
            }
        }
        if (!fm(this.irt)) {
            canvas.drawRect(this.ro, this.jnr);
            if (this.gof > 0.0f) {
                canvas.drawRect(this.wu, this.f6336ef);
                return;
            }
            return;
        }
        float f10 = this.fhx;
        if (this.gof <= 0.0f) {
            canvas.drawRoundRect(this.ro, f10, f10, this.jnr);
            fm(canvas);
        } else {
            canvas.drawRoundRect(this.ro, f10, f10, this.jnr);
            canvas.drawRoundRect(this.wu, f10, f10, this.f6336ef);
            fm(canvas);
            ro(canvas);
        }
    }

    public ro fm(boolean z10) {
        this.qhl = z10;
        return this;
    }

    @Override // android.graphics.drawable.Drawable
    public int getAlpha() {
        return this.jnr.getAlpha();
    }

    @Override // android.graphics.drawable.Drawable
    public ColorFilter getColorFilter() {
        return this.jnr.getColorFilter();
    }

    @Override // android.graphics.drawable.Drawable
    public int getIntrinsicHeight() {
        return this.wsy;
    }

    @Override // android.graphics.drawable.Drawable
    public int getIntrinsicWidth() {
        return this.ajl;
    }

    @Override // android.graphics.drawable.Drawable
    public int getOpacity() {
        return -3;
    }

    @Override // android.graphics.drawable.Drawable
    public boolean isStateful() {
        return this.gqi.isStateful();
    }

    @Override // android.graphics.drawable.Drawable
    public void onBoundsChange(Rect rect) {
        super.onBoundsChange(rect);
        this.fm.set(rect);
        fm();
    }

    @Override // android.graphics.drawable.Drawable
    public boolean onStateChange(int[] iArr) {
        int colorForState = this.gqi.getColorForState(iArr, 0);
        if (this.f6336ef.getColor() == colorForState) {
            return super.onStateChange(iArr);
        }
        this.f6336ef.setColor(colorForState);
        return true;
    }

    @Override // android.graphics.drawable.Drawable
    public void setAlpha(int i10) {
        this.jnr.setAlpha(i10);
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public void setColorFilter(ColorFilter colorFilter) {
        this.jnr.setColorFilter(colorFilter);
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public void setDither(boolean z10) {
        this.jnr.setDither(z10);
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public void setFilterBitmap(boolean z10) {
        this.jnr.setFilterBitmap(z10);
        invalidateSelf();
    }

    public static ro fm(Bitmap bitmap) {
        if (bitmap != null) {
            return new ro(bitmap);
        }
        return null;
    }

    public static Drawable fm(Drawable drawable) {
        if (drawable != null) {
            if (drawable instanceof ro) {
                return drawable;
            }
            if (Build.VERSION.SDK_INT >= 28 && r.D(drawable)) {
                return drawable;
            }
            if (drawable instanceof LayerDrawable) {
                Drawable.ConstantState constantState = drawable.mutate().getConstantState();
                if (constantState != null) {
                    drawable = constantState.newDrawable();
                }
                LayerDrawable layerDrawable = (LayerDrawable) drawable;
                int numberOfLayers = layerDrawable.getNumberOfLayers();
                for (int i10 = 0; i10 < numberOfLayers; i10++) {
                    layerDrawable.setDrawableByLayerId(layerDrawable.getId(i10), fm(layerDrawable.getDrawable(i10)));
                }
                return layerDrawable;
            }
        }
        Bitmap bitmapRo = ro(drawable);
        return bitmapRo != null ? new ro(bitmapRo) : drawable;
    }

    private void ro(Canvas canvas) {
        float f10;
        if (ro(this.irt) || this.fhx == 0.0f) {
            return;
        }
        RectF rectF = this.ro;
        float f11 = rectF.left;
        float f12 = rectF.top;
        float fWidth = rectF.width() + f11;
        float fHeight = this.ro.height() + f12;
        float f13 = this.fhx;
        float f14 = this.gof / 2.0f;
        if (!this.irt[0]) {
            canvas.drawLine(f11 - f14, f12, f11 + f13, f12, this.f6336ef);
            canvas.drawLine(f11, f12 - f14, f11, f12 + f13, this.f6336ef);
        }
        if (!this.irt[1]) {
            canvas.drawLine((fWidth - f13) - f14, f12, fWidth, f12, this.f6336ef);
            canvas.drawLine(fWidth, f12 - f14, fWidth, f12 + f13, this.f6336ef);
        }
        if (this.irt[2]) {
            f10 = f13;
        } else {
            f10 = f13;
            canvas.drawLine((fWidth - f13) - f14, fHeight, fWidth + f14, fHeight, this.f6336ef);
            canvas.drawLine(fWidth, fHeight - f10, fWidth, fHeight, this.f6336ef);
        }
        if (this.irt[3]) {
            return;
        }
        canvas.drawLine(f11 - f14, fHeight, f11 + f10, fHeight, this.f6336ef);
        canvas.drawLine(f11, fHeight - f10, f11, fHeight, this.f6336ef);
    }

    private void fm() {
        float fWidth;
        float fHeight;
        int i10 = AnonymousClass1.fm[this.wey.ordinal()];
        if (i10 == 1) {
            this.wu.set(this.fm);
            RectF rectF = this.wu;
            float f10 = this.gof;
            rectF.inset(f10 / 2.0f, f10 / 2.0f);
            this.vt.reset();
            this.vt.setTranslate((int) u1.a(this.wu.width(), this.ajl, 0.5f, 0.5f), (int) u1.a(this.wu.height(), this.wsy, 0.5f, 0.5f));
        } else if (i10 == 2) {
            this.wu.set(this.fm);
            RectF rectF2 = this.wu;
            float f11 = this.gof;
            rectF2.inset(f11 / 2.0f, f11 / 2.0f);
            this.vt.reset();
            float fWidth2 = 0.0f;
            if (this.wu.height() * this.ajl > this.wu.width() * this.wsy) {
                fWidth = this.wu.height() / this.wsy;
                fHeight = 0.0f;
                fWidth2 = (this.wu.width() - (this.ajl * fWidth)) * 0.5f;
            } else {
                fWidth = this.wu.width() / this.ajl;
                fHeight = (this.wu.height() - (this.wsy * fWidth)) * 0.5f;
            }
            this.vt.setScale(fWidth, fWidth);
            Matrix matrix = this.vt;
            float f12 = this.gof;
            matrix.postTranslate((f12 / 2.0f) + ((int) (fWidth2 + 0.5f)), (f12 / 2.0f) + ((int) (fHeight + 0.5f)));
        } else if (i10 == 3) {
            this.vt.reset();
            float fMin = (((float) this.ajl) > this.fm.width() || ((float) this.wsy) > this.fm.height()) ? Math.min(this.fm.width() / this.ajl, this.fm.height() / this.wsy) : 1.0f;
            float fWidth3 = (int) (((this.fm.width() - (this.ajl * fMin)) * 0.5f) + 0.5f);
            float fHeight2 = (int) (((this.fm.height() - (this.wsy * fMin)) * 0.5f) + 0.5f);
            this.vt.setScale(fMin, fMin);
            this.vt.postTranslate(fWidth3, fHeight2);
            this.wu.set(this.f6337lb);
            this.vt.mapRect(this.wu);
            RectF rectF3 = this.wu;
            float f13 = this.gof;
            rectF3.inset(f13 / 2.0f, f13 / 2.0f);
            this.vt.setRectToRect(this.f6337lb, this.wu, Matrix.ScaleToFit.FILL);
        } else if (i10 == 5) {
            this.wu.set(this.f6337lb);
            this.vt.setRectToRect(this.f6337lb, this.fm, Matrix.ScaleToFit.END);
            this.vt.mapRect(this.wu);
            RectF rectF4 = this.wu;
            float f14 = this.gof;
            rectF4.inset(f14 / 2.0f, f14 / 2.0f);
            this.vt.setRectToRect(this.f6337lb, this.wu, Matrix.ScaleToFit.FILL);
        } else if (i10 == 6) {
            this.wu.set(this.f6337lb);
            this.vt.setRectToRect(this.f6337lb, this.fm, Matrix.ScaleToFit.START);
            this.vt.mapRect(this.wu);
            RectF rectF5 = this.wu;
            float f15 = this.gof;
            rectF5.inset(f15 / 2.0f, f15 / 2.0f);
            this.vt.setRectToRect(this.f6337lb, this.wu, Matrix.ScaleToFit.FILL);
        } else if (i10 != 7) {
            this.wu.set(this.f6337lb);
            this.vt.setRectToRect(this.f6337lb, this.fm, Matrix.ScaleToFit.CENTER);
            this.vt.mapRect(this.wu);
            RectF rectF6 = this.wu;
            float f16 = this.gof;
            rectF6.inset(f16 / 2.0f, f16 / 2.0f);
            this.vt.setRectToRect(this.f6337lb, this.wu, Matrix.ScaleToFit.FILL);
        } else {
            this.wu.set(this.fm);
            RectF rectF7 = this.wu;
            float f17 = this.gof;
            rectF7.inset(f17 / 2.0f, f17 / 2.0f);
            this.vt.reset();
            this.vt.setRectToRect(this.f6337lb, this.wu, Matrix.ScaleToFit.FILL);
        }
        this.ro.set(this.wu);
        this.onz = true;
    }

    public ro ro(Shader.TileMode tileMode) {
        if (this.dsz != tileMode) {
            this.dsz = tileMode;
            this.onz = true;
            invalidateSelf();
        }
        return this;
    }

    private static boolean ro(boolean[] zArr) {
        for (boolean z10 : zArr) {
            if (z10) {
                return false;
            }
        }
        return true;
    }

    private void fm(Canvas canvas) {
        if (ro(this.irt) || this.fhx == 0.0f) {
            return;
        }
        RectF rectF = this.ro;
        float f10 = rectF.left;
        float f11 = rectF.top;
        float fWidth = rectF.width() + f10;
        float fHeight = this.ro.height() + f11;
        float f12 = this.fhx;
        if (!this.irt[0]) {
            this.ku.set(f10, f11, f10 + f12, f11 + f12);
            canvas.drawRect(this.ku, this.jnr);
        }
        if (!this.irt[1]) {
            this.ku.set(fWidth - f12, f11, fWidth, f12);
            canvas.drawRect(this.ku, this.jnr);
        }
        if (!this.irt[2]) {
            this.ku.set(fWidth - f12, fHeight - f12, fWidth, fHeight);
            canvas.drawRect(this.ku, this.jnr);
        }
        if (this.irt[3]) {
            return;
        }
        this.ku.set(f10, fHeight - f12, f12 + f10, fHeight);
        canvas.drawRect(this.ku, this.jnr);
    }

    public ro fm(float f10, float f11, float f12, float f13) {
        HashSet hashSet = new HashSet(4);
        hashSet.add(Float.valueOf(f10));
        hashSet.add(Float.valueOf(f11));
        hashSet.add(Float.valueOf(f12));
        hashSet.add(Float.valueOf(f13));
        hashSet.remove(Float.valueOf(0.0f));
        if (hashSet.size() <= 1) {
            if (hashSet.isEmpty()) {
                this.fhx = 0.0f;
            } else {
                float fFloatValue = ((Float) hashSet.iterator().next()).floatValue();
                if (Float.isInfinite(fFloatValue) || Float.isNaN(fFloatValue) || fFloatValue < 0.0f) {
                    throw new IllegalArgumentException("Invalid radius value: ".concat(String.valueOf(fFloatValue)));
                }
                this.fhx = fFloatValue;
            }
            boolean[] zArr = this.irt;
            zArr[0] = f10 > 0.0f;
            zArr[1] = f11 > 0.0f;
            zArr[2] = f12 > 0.0f;
            zArr[3] = f13 > 0.0f;
            return this;
        }
        throw new IllegalArgumentException("Multiple nonzero corner radii not yet supported.");
    }

    public ro fm(float f10) {
        this.gof = f10;
        this.f6336ef.setStrokeWidth(f10);
        return this;
    }

    public ro fm(ColorStateList colorStateList) {
        if (colorStateList == null) {
            colorStateList = ColorStateList.valueOf(0);
        }
        this.gqi = colorStateList;
        this.f6336ef.setColor(colorStateList.getColorForState(getState(), -16777216));
        return this;
    }

    public ro fm(ImageView.ScaleType scaleType) {
        if (scaleType == null) {
            scaleType = ImageView.ScaleType.FIT_CENTER;
        }
        if (this.wey != scaleType) {
            this.wey = scaleType;
            fm();
        }
        return this;
    }

    public ro fm(Shader.TileMode tileMode) {
        if (this.duv != tileMode) {
            this.duv = tileMode;
            this.onz = true;
            invalidateSelf();
        }
        return this;
    }

    private static boolean fm(boolean[] zArr) {
        for (boolean z10 : zArr) {
            if (z10) {
                return true;
            }
        }
        return false;
    }
}
