package com.google.android.material.internal;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.core.view.f3;
import androidx.core.view.s1;

/* JADX INFO: loaded from: classes2.dex */
@RestrictTo({RestrictTo.Scope.f556b})
public class ScrimInsetsFrameLayout extends FrameLayout {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Rect f22685b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f22686c;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public boolean f22688e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f22689f;

    @Nullable
    Drawable insetForeground;

    public ScrimInsetsFrameLayout(@NonNull Context context) {
        this(context, null);
    }

    @Override // android.view.View
    public final void draw(Canvas canvas) {
        super.draw(canvas);
        int width = getWidth();
        int height = getHeight();
        if (this.f22684a == null || this.insetForeground == null) {
            return;
        }
        int iSave = canvas.save();
        canvas.translate(getScrollX(), getScrollY());
        boolean z10 = this.f22686c;
        Rect rect = this.f22685b;
        if (z10) {
            rect.set(0, 0, width, this.f22684a.top);
            this.insetForeground.setBounds(rect);
            this.insetForeground.draw(canvas);
        }
        if (this.f22687d) {
            rect.set(0, height - this.f22684a.bottom, width, height);
            this.insetForeground.setBounds(rect);
            this.insetForeground.draw(canvas);
        }
        if (this.f22688e) {
            Rect rect2 = this.f22684a;
            rect.set(0, rect2.top, rect2.left, height - rect2.bottom);
            this.insetForeground.setBounds(rect);
            this.insetForeground.draw(canvas);
        }
        if (this.f22689f) {
            Rect rect3 = this.f22684a;
            rect.set(width - rect3.right, rect3.top, width, height - rect3.bottom);
            this.insetForeground.setBounds(rect);
            this.insetForeground.draw(canvas);
        }
        canvas.restoreToCount(iSave);
    }

    public void e(f3 f3Var) {
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        Drawable drawable = this.insetForeground;
        if (drawable != null) {
            drawable.setCallback(this);
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        Drawable drawable = this.insetForeground;
        if (drawable != null) {
            drawable.setCallback(null);
        }
    }

    public void setDrawBottomInsetForeground(boolean z10) {
        this.f22687d = z10;
    }

    public void setDrawLeftInsetForeground(boolean z10) {
        this.f22688e = z10;
    }

    public void setDrawRightInsetForeground(boolean z10) {
        this.f22689f = z10;
    }

    public void setDrawTopInsetForeground(boolean z10) {
        this.f22686c = z10;
    }

    public void setScrimInsetForeground(@Nullable Drawable drawable) {
        this.insetForeground = drawable;
    }

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

    public ScrimInsetsFrameLayout(@NonNull Context context, @Nullable AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        this.f22685b = new Rect();
        this.f22686c = true;
        this.f22687d = true;
        this.f22688e = true;
        this.f22689f = true;
        TypedArray typedArrayC = q0.c(context, attributeSet, x8.m.ScrimInsetsFrameLayout, i10, x8.l.Widget_Design_ScrimInsetsFrameLayout, new int[0]);
        this.insetForeground = typedArrayC.getDrawable(x8.m.ScrimInsetsFrameLayout_insetForeground);
        typedArrayC.recycle();
        setWillNotDraw(true);
        s1.setOnApplyWindowInsetsListener(this, new j0(this));
    }
}
