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.os.Build;
import android.util.AttributeSet;
import android.view.View;
import p037.p091.C2083;
import p037.p091.p095.AbstractC2112;
import p037.p091.p095.C2127;

/* JADX INFO: loaded from: classes.dex */
public class HorizontalGridView extends AbstractC2112 {

    /* JADX INFO: renamed from: ʻ, reason: contains not printable characters */
    public Bitmap f711;

    /* JADX INFO: renamed from: ʽ, reason: contains not printable characters */
    public int f712;

    /* JADX INFO: renamed from: ˀ, reason: contains not printable characters */
    public Rect f713;

    /* JADX INFO: renamed from: ˁ, reason: contains not printable characters */
    public int f714;

    /* JADX INFO: renamed from: ˆ, reason: contains not printable characters */
    public boolean f715;

    /* JADX INFO: renamed from: ˇ, reason: contains not printable characters */
    public boolean f716;

    /* JADX INFO: renamed from: ˈ, reason: contains not printable characters */
    public LinearGradient f717;

    /* JADX INFO: renamed from: ˉ, reason: contains not printable characters */
    public Paint f718;

    /* JADX INFO: renamed from: ՙ, reason: contains not printable characters */
    public int f719;

    /* JADX INFO: renamed from: ࠚ, reason: contains not printable characters */
    public int f720;

    /* JADX INFO: renamed from: ࠤ, reason: contains not printable characters */
    public LinearGradient f721;

    /* JADX INFO: renamed from: ࠨ, reason: contains not printable characters */
    public Bitmap f722;

    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.f718 = new Paint();
        this.f713 = new Rect();
        this.f6875.m4135(0);
        m4077(context, attributeSet);
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, C2083.lbHorizontalGridView);
        if (Build.VERSION.SDK_INT >= 29) {
            saveAttributeDataForStyleable(context, C2083.lbHorizontalGridView, attributeSet, typedArrayObtainStyledAttributes, 0, 0);
        }
        setRowHeight(typedArrayObtainStyledAttributes);
        setNumRows(typedArrayObtainStyledAttributes.getInt(C2083.lbHorizontalGridView_numberOfRows, 1));
        typedArrayObtainStyledAttributes.recycle();
        m277();
        Paint paint = new Paint();
        this.f718 = paint;
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
    }

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

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

    @Override // androidx.recyclerview.widget.RecyclerView, android.view.View
    public void draw(Canvas canvas) {
        boolean z;
        boolean z2 = true;
        if (this.f715) {
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                View childAt = getChildAt(i);
                if (this.f6875 == null) {
                    throw null;
                }
                C2127.C2131 c2131 = (C2127.C2131) childAt.getLayoutParams();
                if (c2131 == null) {
                    throw null;
                }
                if (childAt.getLeft() + c2131.f6949 < getPaddingLeft() - this.f720) {
                    z = true;
                    break;
                }
            }
            z = false;
        } else {
            z = false;
        }
        if (this.f716) {
            for (int childCount2 = getChildCount() - 1; childCount2 >= 0; childCount2--) {
                View childAt2 = getChildAt(childCount2);
                if (this.f6875 == null) {
                    throw null;
                }
                C2127.C2131 c21312 = (C2127.C2131) childAt2.getLayoutParams();
                if (c21312 == null) {
                    throw null;
                }
                if (childAt2.getRight() - c21312.f6951 > (getWidth() - getPaddingRight()) + this.f714) {
                    break;
                }
            }
            z2 = false;
        } else {
            z2 = false;
        }
        if (!z) {
            this.f722 = null;
        }
        if (!z2) {
            this.f711 = null;
        }
        if (!z && !z2) {
            super.draw(canvas);
            return;
        }
        int paddingLeft = this.f715 ? (getPaddingLeft() - this.f720) - this.f712 : 0;
        int width = this.f716 ? (getWidth() - getPaddingRight()) + this.f714 + this.f719 : getWidth();
        int iSave = canvas.save();
        canvas.clipRect((this.f715 ? this.f712 : 0) + paddingLeft, 0, width - (this.f716 ? this.f719 : 0), getHeight());
        super.draw(canvas);
        canvas.restoreToCount(iSave);
        Canvas canvas2 = new Canvas();
        Rect rect = this.f713;
        rect.top = 0;
        rect.bottom = getHeight();
        if (z && this.f712 > 0) {
            Bitmap tempBitmapLow = getTempBitmapLow();
            tempBitmapLow.eraseColor(0);
            canvas2.setBitmap(tempBitmapLow);
            int iSave2 = canvas2.save();
            canvas2.clipRect(0, 0, this.f712, getHeight());
            float f = -paddingLeft;
            canvas2.translate(f, 0.0f);
            super.draw(canvas2);
            canvas2.restoreToCount(iSave2);
            this.f718.setShader(this.f721);
            canvas2.drawRect(0.0f, 0.0f, this.f712, getHeight(), this.f718);
            Rect rect2 = this.f713;
            rect2.left = 0;
            rect2.right = this.f712;
            canvas.translate(paddingLeft, 0.0f);
            Rect rect3 = this.f713;
            canvas.drawBitmap(tempBitmapLow, rect3, rect3, (Paint) null);
            canvas.translate(f, 0.0f);
        }
        if (!z2 || this.f719 <= 0) {
            return;
        }
        Bitmap tempBitmapHigh = getTempBitmapHigh();
        tempBitmapHigh.eraseColor(0);
        canvas2.setBitmap(tempBitmapHigh);
        int iSave3 = canvas2.save();
        canvas2.clipRect(0, 0, this.f719, getHeight());
        canvas2.translate(-(width - this.f719), 0.0f);
        super.draw(canvas2);
        canvas2.restoreToCount(iSave3);
        this.f718.setShader(this.f717);
        canvas2.drawRect(0.0f, 0.0f, this.f719, getHeight(), this.f718);
        Rect rect4 = this.f713;
        rect4.left = 0;
        rect4.right = this.f719;
        canvas.translate(width - r5, 0.0f);
        Rect rect5 = this.f713;
        canvas.drawBitmap(tempBitmapHigh, rect5, rect5, (Paint) null);
        canvas.translate(-(width - this.f719), 0.0f);
    }

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

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

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

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

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

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

    public final void setFadingLeftEdge(boolean z) {
        if (this.f715 != z) {
            this.f715 = z;
            if (!z) {
                this.f722 = null;
            }
            invalidate();
            m277();
        }
    }

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

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

    public final void setFadingRightEdge(boolean z) {
        if (this.f716 != z) {
            this.f716 = z;
            if (!z) {
                this.f711 = null;
            }
            invalidate();
            m277();
        }
    }

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

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

    public void setNumRows(int i) {
        C2127 c2127 = this.f6875;
        if (c2127 == null) {
            throw null;
        }
        if (i < 0) {
            throw new IllegalArgumentException();
        }
        c2127.f6933 = i;
        requestLayout();
    }

    public void setRowHeight(int i) {
        this.f6875.m4137(i);
        requestLayout();
    }

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

    /* JADX INFO: renamed from: ޗ, reason: contains not printable characters */
    public final void m277() {
        if (this.f715 || this.f716) {
            setLayerType(2, null);
            setWillNotDraw(false);
        } else {
            setLayerType(0, null);
            setWillNotDraw(true);
        }
    }
}
