package vc;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.renderscript.Allocation;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import androidx.annotation.Nullable;
import e1.l;
import eightbitlab.com.blurview.BlurTarget;
import eightbitlab.com.blurview.BlurView;

/* JADX INFO: loaded from: classes.dex */
public final class e implements a {

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

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

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

    @Nullable
    private Drawable frameClearDrawable;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final View f33781g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final int f33782h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final ViewGroup f33783i;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public float f33775a = 16.0f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final int[] f33784j = new int[2];

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final int[] f33785k = new int[2];

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final d0.e f33786l = new d0.e(this, 1);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final float f33777c = 4.0f;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final boolean f33778d = true;

    public e(BlurView blurView, BlurTarget blurTarget, int i10, h hVar) {
        this.f33783i = blurTarget;
        this.f33781g = blurView;
        this.f33782h = i10;
        this.f33776b = hVar;
        e(blurView.getMeasuredWidth(), blurView.getMeasuredHeight());
    }

    @Override // vc.c
    public final c a(boolean z10) {
        ViewGroup viewGroup = this.f33783i;
        ViewTreeObserver viewTreeObserver = viewGroup.getViewTreeObserver();
        d0.e eVar = this.f33786l;
        viewTreeObserver.removeOnPreDrawListener(eVar);
        View view = this.f33781g;
        view.getViewTreeObserver().removeOnPreDrawListener(eVar);
        if (z10) {
            viewGroup.getViewTreeObserver().addOnPreDrawListener(eVar);
            if (viewGroup.getWindowId() != view.getWindowId()) {
                view.getViewTreeObserver().addOnPreDrawListener(eVar);
            }
        }
        return this;
    }

    @Override // vc.c
    public final c b() {
        this.f33775a = 10.0f;
        return this;
    }

    @Override // vc.a
    public final void c() {
        View view = this.f33781g;
        e(view.getMeasuredWidth(), view.getMeasuredHeight());
    }

    @Override // vc.a
    public final boolean d(Canvas canvas) {
        if (!this.f33787m) {
            return true;
        }
        if (canvas instanceof b) {
            return false;
        }
        View view = this.f33781g;
        float width = view.getWidth() / this.f33780f.getWidth();
        canvas.save();
        canvas.scale(width, view.getHeight() / this.f33780f.getHeight());
        canvas.drawBitmap(this.f33780f, 0.0f, 0.0f, this.f33776b.f33801a);
        canvas.restore();
        if (this.f33778d) {
            ua.b.b(canvas, view.getContext(), view.getWidth(), view.getHeight());
        }
        int i10 = this.f33782h;
        if (i10 != 0) {
            canvas.drawColor(i10);
        }
        return true;
    }

    @Override // vc.a
    public final void destroy() {
        a(false);
        h hVar = this.f33776b;
        hVar.f33803c.destroy();
        hVar.f33802b.destroy();
        Allocation allocation = hVar.f33804d;
        if (allocation != null) {
            allocation.destroy();
        }
        this.f33787m = false;
    }

    public final void e(int i10, int i11) {
        a(true);
        l lVar = new l(this.f33777c);
        int iCeil = (int) Math.ceil(i11 / r2);
        View view = this.f33781g;
        if (iCeil == 0 || ((int) Math.ceil(i10 / r2)) == 0) {
            view.setWillNotDraw(true);
            return;
        }
        view.setWillNotDraw(false);
        i iVarA = lVar.a(i10, i11);
        this.f33776b.getClass();
        this.f33780f = Bitmap.createBitmap(iVarA.f33807a, iVarA.f33808b, Bitmap.Config.ARGB_8888);
        this.f33779e = new b(this.f33780f);
        this.f33787m = true;
        f();
    }

    public final void f() {
        if (this.f33787m) {
            Drawable drawable = this.frameClearDrawable;
            if (drawable == null) {
                this.f33780f.eraseColor(0);
            } else {
                drawable.draw(this.f33779e);
            }
            this.f33779e.save();
            ViewGroup viewGroup = this.f33783i;
            int[] iArr = this.f33784j;
            viewGroup.getLocationOnScreen(iArr);
            View view = this.f33781g;
            int[] iArr2 = this.f33785k;
            view.getLocationOnScreen(iArr2);
            int i10 = iArr2[0] - iArr[0];
            int i11 = iArr2[1] - iArr[1];
            float height = view.getHeight() / this.f33780f.getHeight();
            float width = view.getWidth() / this.f33780f.getWidth();
            this.f33779e.translate((-i10) / width, (-i11) / height);
            this.f33779e.scale(1.0f / width, 1.0f / height);
            try {
                viewGroup.draw(this.f33779e);
            } catch (Exception unused) {
            }
            this.f33779e.restore();
            Bitmap bitmap = this.f33780f;
            this.f33776b.a(bitmap, this.f33775a);
            this.f33780f = bitmap;
        }
    }

    @Override // vc.a, vc.c
    public c setFrameClearDrawable(@Nullable Drawable drawable) {
        this.frameClearDrawable = drawable;
        return this;
    }
}
