package androidx.leanback.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;
import defpackage.AbstractC0650;
import defpackage.AbstractC2746;
import defpackage.AbstractC3471;
import defpackage.C4930;

/* JADX INFO: loaded from: classes3.dex */
public class HorizontalGridView extends AbstractC0650 {

    /* JADX INFO: renamed from: ʾᵕˈ, reason: contains not printable characters */
    public boolean f450;

    /* JADX INFO: renamed from: ˆᵽᵯʣ, reason: contains not printable characters */
    public int f451;

    /* JADX INFO: renamed from: ˊˈᵲ, reason: contains not printable characters */
    public int f452;

    /* JADX INFO: renamed from: ᵖʽˈˏ, reason: contains not printable characters */
    public Bitmap f453;

    /* JADX INFO: renamed from: ᵙˁˇ, reason: contains not printable characters */
    public final Paint f454;

    /* JADX INFO: renamed from: ᵡˁᵦ, reason: contains not printable characters */
    public LinearGradient f455;

    /* JADX INFO: renamed from: ᵡᵱ, reason: contains not printable characters */
    public final Rect f456;

    /* JADX INFO: renamed from: ᵢᵝᵣ, reason: contains not printable characters */
    public int f457;

    /* JADX INFO: renamed from: ᵳˉᵴˆ, reason: contains not printable characters */
    public Bitmap f458;

    /* JADX INFO: renamed from: ᵶʟ, reason: contains not printable characters */
    public LinearGradient f459;

    /* JADX INFO: renamed from: ᵺᵫˎ, reason: contains not printable characters */
    public int f460;

    /* JADX INFO: renamed from: ᵼᵺᵬ, reason: contains not printable characters */
    public boolean f461;

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

    public HorizontalGridView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public HorizontalGridView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.f454 = new Paint();
        this.f456 = new Rect();
        this.f3040.m271(0);
        m2322(context, attributeSet);
        int[] iArr = AbstractC3471.f13372;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, iArr);
        AbstractC2746.m6646(this, context, iArr, attributeSet, typedArrayObtainStyledAttributes, 0);
        setRowHeight(typedArrayObtainStyledAttributes);
        setNumRows(typedArrayObtainStyledAttributes.getInt(0, 1));
        typedArrayObtainStyledAttributes.recycle();
        m336();
        Paint paint = new Paint();
        this.f454 = paint;
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    }

    private Bitmap getTempBitmapHigh() {
        Bitmap bitmap = this.f453;
        if (bitmap == null || bitmap.getWidth() != this.f460 || this.f453.getHeight() != getHeight()) {
            this.f453 = Bitmap.createBitmap(this.f460, getHeight(), Bitmap.Config.ARGB_8888);
        }
        return this.f453;
    }

    private Bitmap getTempBitmapLow() {
        Bitmap bitmap = this.f458;
        if (bitmap == null || bitmap.getWidth() != this.f451 || this.f458.getHeight() != getHeight()) {
            this.f458 = Bitmap.createBitmap(this.f451, getHeight(), Bitmap.Config.ARGB_8888);
        }
        return this.f458;
    }

    @Override // androidx.recyclerview.widget.RecyclerView, android.view.View
    public final void draw(Canvas canvas) {
        boolean z;
        boolean z2 = true;
        if (this.f461) {
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                View childAt = getChildAt(i);
                this.f3040.getClass();
                C4930 c4930 = (C4930) childAt.getLayoutParams();
                c4930.getClass();
                if (childAt.getLeft() + c4930.f18740 < getPaddingLeft() - this.f457) {
                    z = true;
                    break;
                }
            }
            z = false;
        } else {
            z = false;
        }
        if (this.f450) {
            for (int childCount2 = getChildCount() - 1; childCount2 >= 0; childCount2--) {
                View childAt2 = getChildAt(childCount2);
                this.f3040.getClass();
                C4930 c49302 = (C4930) childAt2.getLayoutParams();
                c49302.getClass();
                if (childAt2.getRight() - c49302.f18732 > (getWidth() - getPaddingRight()) + this.f452) {
                    break;
                }
            }
            z2 = false;
        } else {
            z2 = false;
        }
        if (!z) {
            this.f458 = null;
        }
        if (!z2) {
            this.f453 = null;
        }
        if (!z && !z2) {
            super.draw(canvas);
            return;
        }
        int paddingLeft = this.f461 ? (getPaddingLeft() - this.f457) - this.f451 : 0;
        int width = this.f450 ? (getWidth() - getPaddingRight()) + this.f452 + this.f460 : getWidth();
        int iSave = canvas.save();
        canvas.clipRect((this.f461 ? this.f451 : 0) + paddingLeft, 0, width - (this.f450 ? this.f460 : 0), getHeight());
        super.draw(canvas);
        canvas.restoreToCount(iSave);
        Canvas canvas2 = new Canvas();
        Rect rect = this.f456;
        rect.top = 0;
        rect.bottom = getHeight();
        Paint paint = this.f454;
        if (z && this.f451 > 0) {
            Bitmap tempBitmapLow = getTempBitmapLow();
            tempBitmapLow.eraseColor(0);
            canvas2.setBitmap(tempBitmapLow);
            int iSave2 = canvas2.save();
            canvas2.clipRect(0, 0, this.f451, getHeight());
            float f = -paddingLeft;
            canvas2.translate(f, 0.0f);
            super.draw(canvas2);
            canvas2.restoreToCount(iSave2);
            paint.setShader(this.f455);
            canvas2.drawRect(0.0f, 0.0f, this.f451, getHeight(), this.f454);
            rect.left = 0;
            rect.right = this.f451;
            canvas.translate(paddingLeft, 0.0f);
            canvas.drawBitmap(tempBitmapLow, rect, rect, (Paint) null);
            canvas.translate(f, 0.0f);
        }
        if (!z2 || this.f460 <= 0) {
            return;
        }
        Bitmap tempBitmapHigh = getTempBitmapHigh();
        tempBitmapHigh.eraseColor(0);
        canvas2.setBitmap(tempBitmapHigh);
        int iSave3 = canvas2.save();
        canvas2.clipRect(0, 0, this.f460, getHeight());
        canvas2.translate(-(width - this.f460), 0.0f);
        super.draw(canvas2);
        canvas2.restoreToCount(iSave3);
        paint.setShader(this.f459);
        canvas2.drawRect(0.0f, 0.0f, this.f460, getHeight(), this.f454);
        rect.left = 0;
        rect.right = this.f460;
        canvas.translate(width - r3, 0.0f);
        canvas.drawBitmap(tempBitmapHigh, rect, rect, (Paint) null);
        canvas.translate(-(width - this.f460), 0.0f);
    }

    public final boolean getFadingLeftEdge() {
        return this.f461;
    }

    public final int getFadingLeftEdgeLength() {
        return this.f451;
    }

    public final int getFadingLeftEdgeOffset() {
        return this.f457;
    }

    public final boolean getFadingRightEdge() {
        return this.f450;
    }

    public final int getFadingRightEdgeLength() {
        return this.f460;
    }

    public final int getFadingRightEdgeOffset() {
        return this.f452;
    }

    public int getNumRows() {
        GridLayoutManager gridLayoutManager = this.f3040;
        int i = gridLayoutManager.f395;
        return i != 0 ? i : gridLayoutManager.f415;
    }

    public final void setFadingLeftEdge(boolean z) {
        if (this.f461 != z) {
            this.f461 = z;
            if (!z) {
                this.f458 = null;
            }
            invalidate();
            m336();
        }
    }

    public final void setFadingLeftEdgeLength(int i) {
        if (this.f451 != i) {
            this.f451 = i;
            if (i != 0) {
                this.f455 = new LinearGradient(0.0f, 0.0f, this.f451, 0.0f, 0, -16777216, Shader.TileMode.CLAMP);
            } else {
                this.f455 = null;
            }
            invalidate();
        }
    }

    public final void setFadingLeftEdgeOffset(int i) {
        if (this.f457 != i) {
            this.f457 = i;
            invalidate();
        }
    }

    public final void setFadingRightEdge(boolean z) {
        if (this.f450 != z) {
            this.f450 = z;
            if (!z) {
                this.f453 = null;
            }
            invalidate();
            m336();
        }
    }

    public final void setFadingRightEdgeLength(int i) {
        if (this.f460 != i) {
            this.f460 = i;
            if (i != 0) {
                this.f459 = new LinearGradient(0.0f, 0.0f, this.f460, 0.0f, -16777216, 0, Shader.TileMode.CLAMP);
            } else {
                this.f459 = null;
            }
            invalidate();
        }
    }

    public final void setFadingRightEdgeOffset(int i) {
        if (this.f452 != i) {
            this.f452 = i;
            invalidate();
        }
    }

    public void setNumRows(int i) {
        GridLayoutManager gridLayoutManager = this.f3040;
        if (i >= 0) {
            gridLayoutManager.f415 = i;
            requestLayout();
        } else {
            gridLayoutManager.getClass();
            ᵷᵝˎ.ᵷᵺʾᵖ();
        }
    }

    public void setRowHeight(int i) {
        this.f3040.m264(i);
        requestLayout();
    }

    public void setRowHeight(TypedArray typedArray) {
        if (typedArray.peekValue(1) != null) {
            setRowHeight(typedArray.getLayoutDimension(1, 0));
        }
    }

    /* JADX INFO: renamed from: ᵕᵜʽᵰ, reason: contains not printable characters */
    public final void m336() {
        if (this.f461 || this.f450) {
            setLayerType(2, null);
            setWillNotDraw(false);
        } else {
            setLayerType(0, null);
            setWillNotDraw(true);
        }
    }
}
