package X6FRs_4.JZJr_16;

import android.annotation.SuppressLint;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
/* compiled from: GhostViewApi14.java */
@SuppressLint({"ViewConstructor"})
/* loaded from: classes.dex */
public class X6FRs_4 extends View implements IMuAHx_6 {
    public int KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public Matrix f593KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final View f594KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public ViewGroup f595KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final ViewTreeObserver.OnPreDrawListener f596KQgRr5e_0;
    public int PGPF6hQ_2;
    public int QxJ9d_1;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public final Matrix f597QxJ9d_1;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public View f598QxJ9d_1;

    /* compiled from: GhostViewApi14.java */
    /* loaded from: classes.dex */
    public class KQgRr5e_0 implements ViewTreeObserver.OnPreDrawListener {
        public KQgRr5e_0() {
        }

        @Override // android.view.ViewTreeObserver.OnPreDrawListener
        public boolean onPreDraw() {
            View view;
            X6FRs_4 x6FRs_4 = X6FRs_4.this;
            x6FRs_4.f593KQgRr5e_0 = x6FRs_4.f594KQgRr5e_0.getMatrix();
            X6FRs_4.IMuAHx_6.EuDEkJe_12.ZzDuCHW_20.m262KQgRr5e_0((View) X6FRs_4.this);
            X6FRs_4 x6FRs_42 = X6FRs_4.this;
            ViewGroup viewGroup = x6FRs_42.f595KQgRr5e_0;
            if (viewGroup == null || (view = x6FRs_42.f598QxJ9d_1) == null) {
                return true;
            }
            viewGroup.endViewTransition(view);
            X6FRs_4.IMuAHx_6.EuDEkJe_12.ZzDuCHW_20.m262KQgRr5e_0((View) X6FRs_4.this.f595KQgRr5e_0);
            X6FRs_4 x6FRs_43 = X6FRs_4.this;
            x6FRs_43.f595KQgRr5e_0 = null;
            x6FRs_43.f598QxJ9d_1 = null;
            return true;
        }
    }

    public X6FRs_4(View view) {
        super(view.getContext());
        this.f597QxJ9d_1 = new Matrix();
        this.f596KQgRr5e_0 = new KQgRr5e_0();
        this.f594KQgRr5e_0 = view;
        setLayerType(2, null);
    }

    public static IMuAHx_6 KQgRr5e_0(View view, ViewGroup viewGroup) {
        X6FRs_4 KQgRr5e_02 = KQgRr5e_0(view);
        if (KQgRr5e_02 == null) {
            FrameLayout KQgRr5e_03 = KQgRr5e_0(viewGroup);
            if (KQgRr5e_03 == null) {
                return null;
            }
            KQgRr5e_02 = new X6FRs_4(view);
            KQgRr5e_03.addView(KQgRr5e_02);
        }
        KQgRr5e_02.KQgRr5e_0++;
        return KQgRr5e_02;
    }

    @Override // android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        KQgRr5e_0(this.f594KQgRr5e_0, this);
        int[] iArr = new int[2];
        getLocationOnScreen(iArr);
        this.f594KQgRr5e_0.getLocationOnScreen(r0);
        int[] iArr2 = {(int) (iArr2[0] - this.f594KQgRr5e_0.getTranslationX()), (int) (iArr2[1] - this.f594KQgRr5e_0.getTranslationY())};
        this.QxJ9d_1 = iArr2[0] - iArr[0];
        this.PGPF6hQ_2 = iArr2[1] - iArr[1];
        this.f594KQgRr5e_0.getViewTreeObserver().addOnPreDrawListener(this.f596KQgRr5e_0);
        this.f594KQgRr5e_0.setVisibility(4);
    }

    @Override // android.view.View
    public void onDetachedFromWindow() {
        this.f594KQgRr5e_0.getViewTreeObserver().removeOnPreDrawListener(this.f596KQgRr5e_0);
        this.f594KQgRr5e_0.setVisibility(0);
        KQgRr5e_0(this.f594KQgRr5e_0, (X6FRs_4) null);
        super.onDetachedFromWindow();
    }

    @Override // android.view.View
    public void onDraw(Canvas canvas) {
        this.f597QxJ9d_1.set(this.f593KQgRr5e_0);
        this.f597QxJ9d_1.postTranslate(this.QxJ9d_1, this.PGPF6hQ_2);
        canvas.setMatrix(this.f597QxJ9d_1);
        this.f594KQgRr5e_0.draw(canvas);
    }

    @Override // android.view.View, X6FRs_4.JZJr_16.IMuAHx_6
    public void setVisibility(int i) {
        super.setVisibility(i);
        this.f594KQgRr5e_0.setVisibility(i == 0 ? 4 : 0);
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static void m354KQgRr5e_0(View view) {
        X6FRs_4 KQgRr5e_02 = KQgRr5e_0(view);
        if (KQgRr5e_02 != null) {
            int i = KQgRr5e_02.KQgRr5e_0 - 1;
            KQgRr5e_02.KQgRr5e_0 = i;
            if (i <= 0) {
                ViewParent parent = KQgRr5e_02.getParent();
                if (parent instanceof ViewGroup) {
                    ViewGroup viewGroup = (ViewGroup) parent;
                    viewGroup.endViewTransition(KQgRr5e_02);
                    viewGroup.removeView(KQgRr5e_02);
                }
            }
        }
    }

    public static FrameLayout KQgRr5e_0(ViewGroup viewGroup) {
        while (!(viewGroup instanceof FrameLayout)) {
            ViewParent parent = viewGroup.getParent();
            if (!(parent instanceof ViewGroup)) {
                return null;
            }
            viewGroup = (ViewGroup) parent;
        }
        return (FrameLayout) viewGroup;
    }

    @Override // X6FRs_4.JZJr_16.IMuAHx_6
    public void KQgRr5e_0(ViewGroup viewGroup, View view) {
        this.f595KQgRr5e_0 = viewGroup;
        this.f598QxJ9d_1 = view;
    }

    public static void KQgRr5e_0(View view, X6FRs_4 x6FRs_4) {
        view.setTag(WwEq_13.ghost_view, x6FRs_4);
    }

    public static X6FRs_4 KQgRr5e_0(View view) {
        return (X6FRs_4) view.getTag(WwEq_13.ghost_view);
    }
}
