package com.facebook.shimmer;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import androidx.annotation.Nullable;
import r6.a;
import r6.b;
import r6.c;
import r6.e;

/* JADX INFO: loaded from: classes2.dex */
public class ShimmerFrameLayout extends FrameLayout {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Paint f7684a;

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

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

    public ShimmerFrameLayout(Context context) {
        super(context);
        this.f7684a = new Paint();
        this.f7685b = new e();
        this.f7686c = true;
        init(context, null);
    }

    private void init(Context context, @Nullable AttributeSet attributeSet) {
        setWillNotDraw(false);
        this.f7685b.setCallback(this);
        if (attributeSet == null) {
            setShimmer(new b(0).e());
            return;
        }
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, a.ShimmerFrameLayout, 0, 0);
        try {
            int i10 = a.ShimmerFrameLayout_shimmer_colored;
            setShimmer(((typedArrayObtainStyledAttributes.hasValue(i10) && typedArrayObtainStyledAttributes.getBoolean(i10, false)) ? new b(1) : new b(0)).f(typedArrayObtainStyledAttributes).e());
            typedArrayObtainStyledAttributes.recycle();
        } catch (Throwable th) {
            typedArrayObtainStyledAttributes.recycle();
            throw th;
        }
    }

    public final void a() {
        if (this.f7686c) {
            this.f7685b.b();
            this.f7686c = false;
            invalidate();
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        if (this.f7686c) {
            this.f7685b.draw(canvas);
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        this.f7685b.a();
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        this.f7685b.b();
    }

    @Override // android.widget.FrameLayout, android.view.ViewGroup, android.view.View
    public final void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        super.onLayout(z10, i10, i11, i12, i13);
        this.f7685b.setBounds(0, 0, getWidth(), getHeight());
    }

    public ShimmerFrameLayout setShimmer(@Nullable c cVar) {
        this.f7685b.setShimmer(cVar);
        if (cVar == null || !cVar.f32496n) {
            setLayerType(0, null);
        } else {
            setLayerType(2, this.f7684a);
        }
        return this;
    }

    @Override // android.view.View
    public final boolean verifyDrawable(Drawable drawable) {
        return super.verifyDrawable(drawable) || drawable == this.f7685b;
    }

    public ShimmerFrameLayout(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f7684a = new Paint();
        this.f7685b = new e();
        this.f7686c = true;
        init(context, attributeSet);
    }

    public ShimmerFrameLayout(Context context, AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        this.f7684a = new Paint();
        this.f7685b = new e();
        this.f7686c = true;
        init(context, attributeSet);
    }
}
