package X6FRs_4.JZJr_16;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import java.util.ArrayList;
/* compiled from: ViewOverlayApi14.java */
/* loaded from: classes.dex */
public class DtqPmDY_31 implements ViqFd_33 {
    public KQgRr5e_0 KQgRr5e_0;

    public DtqPmDY_31(Context context, ViewGroup viewGroup, View view) {
        this.KQgRr5e_0 = new KQgRr5e_0(context, viewGroup, view, this);
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public static ViewGroup m349KQgRr5e_0(View view) {
        while (view != null) {
            if (view.getId() == 16908290 && (view instanceof ViewGroup)) {
                return (ViewGroup) view;
            }
            if (view.getParent() instanceof ViewGroup) {
                view = (ViewGroup) view.getParent();
            }
        }
        return null;
    }

    @Override // X6FRs_4.JZJr_16.ViqFd_33
    public void QxJ9d_1(Drawable drawable) {
        this.KQgRr5e_0.QxJ9d_1(drawable);
    }

    /* compiled from: ViewOverlayApi14.java */
    /* loaded from: classes.dex */
    public static class KQgRr5e_0 extends ViewGroup {
        public DtqPmDY_31 KQgRr5e_0;

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

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

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public ArrayList<Drawable> f555KQgRr5e_0;

        static {
            try {
                ViewGroup.class.getDeclaredMethod("invalidateChildInParentFast", Integer.TYPE, Integer.TYPE, Rect.class);
            } catch (NoSuchMethodException unused) {
            }
        }

        public KQgRr5e_0(Context context, ViewGroup viewGroup, View view, DtqPmDY_31 dtqPmDY_31) {
            super(context);
            this.f555KQgRr5e_0 = null;
            this.f554KQgRr5e_0 = viewGroup;
            this.f553KQgRr5e_0 = view;
            setRight(viewGroup.getWidth());
            setBottom(viewGroup.getHeight());
            viewGroup.addView(this);
            this.KQgRr5e_0 = dtqPmDY_31;
        }

        public void KQgRr5e_0(Drawable drawable) {
            if (this.f555KQgRr5e_0 == null) {
                this.f555KQgRr5e_0 = new ArrayList<>();
            }
            if (this.f555KQgRr5e_0.contains(drawable)) {
                return;
            }
            this.f555KQgRr5e_0.add(drawable);
            invalidate(drawable.getBounds());
            drawable.setCallback(this);
        }

        public void QxJ9d_1(Drawable drawable) {
            ArrayList<Drawable> arrayList = this.f555KQgRr5e_0;
            if (arrayList != null) {
                arrayList.remove(drawable);
                invalidate(drawable.getBounds());
                drawable.setCallback(null);
            }
        }

        @Override // android.view.ViewGroup, android.view.View
        public void dispatchDraw(Canvas canvas) {
            int[] iArr = new int[2];
            int[] iArr2 = new int[2];
            this.f554KQgRr5e_0.getLocationOnScreen(iArr);
            this.f553KQgRr5e_0.getLocationOnScreen(iArr2);
            canvas.translate(iArr2[0] - iArr[0], iArr2[1] - iArr[1]);
            canvas.clipRect(new Rect(0, 0, this.f553KQgRr5e_0.getWidth(), this.f553KQgRr5e_0.getHeight()));
            super.dispatchDraw(canvas);
            ArrayList<Drawable> arrayList = this.f555KQgRr5e_0;
            int size = arrayList == null ? 0 : arrayList.size();
            for (int i = 0; i < size; i++) {
                this.f555KQgRr5e_0.get(i).draw(canvas);
            }
        }

        @Override // android.view.ViewGroup, android.view.View
        public boolean dispatchTouchEvent(MotionEvent motionEvent) {
            return false;
        }

        @Override // android.view.ViewGroup, android.view.ViewParent
        public ViewParent invalidateChildInParent(int[] iArr, Rect rect) {
            if (this.f554KQgRr5e_0 != null) {
                rect.offset(iArr[0], iArr[1]);
                if (this.f554KQgRr5e_0 instanceof ViewGroup) {
                    iArr[0] = 0;
                    iArr[1] = 0;
                    int[] iArr2 = new int[2];
                    KQgRr5e_0(iArr2);
                    rect.offset(iArr2[0], iArr2[1]);
                    return super.invalidateChildInParent(iArr, rect);
                }
                invalidate(rect);
                return null;
            }
            return null;
        }

        @Override // android.view.View, android.graphics.drawable.Drawable.Callback
        public void invalidateDrawable(Drawable drawable) {
            invalidate(drawable.getBounds());
        }

        @Override // android.view.ViewGroup, android.view.View
        public void onLayout(boolean z, int i, int i2, int i3, int i4) {
        }

        @Override // android.view.View
        public boolean verifyDrawable(Drawable drawable) {
            ArrayList<Drawable> arrayList;
            return super.verifyDrawable(drawable) || ((arrayList = this.f555KQgRr5e_0) != null && arrayList.contains(drawable));
        }

        public void QxJ9d_1(View view) {
            super.removeView(view);
            if (KQgRr5e_0()) {
                this.f554KQgRr5e_0.removeView(this);
            }
        }

        public void KQgRr5e_0(View view) {
            if (view.getParent() instanceof ViewGroup) {
                ViewGroup viewGroup = (ViewGroup) view.getParent();
                if (viewGroup != this.f554KQgRr5e_0 && viewGroup.getParent() != null && X6FRs_4.IMuAHx_6.EuDEkJe_12.ZzDuCHW_20.m250IMuAHx_6((View) viewGroup)) {
                    int[] iArr = new int[2];
                    int[] iArr2 = new int[2];
                    viewGroup.getLocationOnScreen(iArr);
                    this.f554KQgRr5e_0.getLocationOnScreen(iArr2);
                    X6FRs_4.IMuAHx_6.EuDEkJe_12.ZzDuCHW_20.Mqv2r_3(view, iArr[0] - iArr2[0]);
                    X6FRs_4.IMuAHx_6.EuDEkJe_12.ZzDuCHW_20.X6FRs_4(view, iArr[1] - iArr2[1]);
                }
                viewGroup.removeView(view);
                if (view.getParent() != null) {
                    viewGroup.removeView(view);
                }
            }
            super.addView(view, getChildCount() - 1);
        }

        public boolean KQgRr5e_0() {
            ArrayList<Drawable> arrayList;
            return getChildCount() == 0 && ((arrayList = this.f555KQgRr5e_0) == null || arrayList.size() == 0);
        }

        public final void KQgRr5e_0(int[] iArr) {
            int[] iArr2 = new int[2];
            int[] iArr3 = new int[2];
            this.f554KQgRr5e_0.getLocationOnScreen(iArr2);
            this.f553KQgRr5e_0.getLocationOnScreen(iArr3);
            iArr[0] = iArr3[0] - iArr2[0];
            iArr[1] = iArr3[1] - iArr2[1];
        }
    }

    public static DtqPmDY_31 KQgRr5e_0(View view) {
        ViewGroup m349KQgRr5e_0 = m349KQgRr5e_0(view);
        if (m349KQgRr5e_0 != null) {
            int childCount = m349KQgRr5e_0.getChildCount();
            for (int i = 0; i < childCount; i++) {
                View childAt = m349KQgRr5e_0.getChildAt(i);
                if (childAt instanceof KQgRr5e_0) {
                    return ((KQgRr5e_0) childAt).KQgRr5e_0;
                }
            }
            return new KVtv3R_25(m349KQgRr5e_0.getContext(), m349KQgRr5e_0, view);
        }
        return null;
    }

    @Override // X6FRs_4.JZJr_16.ViqFd_33
    public void KQgRr5e_0(Drawable drawable) {
        this.KQgRr5e_0.KQgRr5e_0(drawable);
    }
}
