package com.chartboost.sdk.impl;

import android.view.View;
import android.view.ViewGroup;
import com.chartboost.sdk.impl.ec;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import org.json.JSONObject;
/* loaded from: classes2.dex */
public class cd implements ec {

    /* renamed from: a  reason: collision with root package name */
    public final int[] f1672a = new int[2];

    @Override // com.chartboost.sdk.impl.ec
    public JSONObject a(View view) {
        if (view == null) {
            return xc.a(0, 0, 0, 0);
        }
        int width = view.getWidth();
        int height = view.getHeight();
        view.getLocationOnScreen(this.f1672a);
        int[] iArr = this.f1672a;
        return xc.a(iArr[0], iArr[1], width, height);
    }

    public final void b(ViewGroup viewGroup, JSONObject jSONObject, ec.a aVar, boolean z) {
        HashMap hashMap = new HashMap();
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View childAt = viewGroup.getChildAt(i);
            ArrayList arrayList = (ArrayList) hashMap.get(Float.valueOf(childAt.getZ()));
            if (arrayList == null) {
                arrayList = new ArrayList();
                hashMap.put(Float.valueOf(childAt.getZ()), arrayList);
            }
            arrayList.add(childAt);
        }
        ArrayList arrayList2 = new ArrayList(hashMap.keySet());
        Collections.sort(arrayList2);
        Iterator it = arrayList2.iterator();
        while (it.hasNext()) {
            Iterator it2 = ((ArrayList) hashMap.get((Float) it.next())).iterator();
            while (it2.hasNext()) {
                aVar.a((View) it2.next(), this, jSONObject, z);
            }
        }
    }

    @Override // com.chartboost.sdk.impl.ec
    public void a(View view, JSONObject jSONObject, ec.a aVar, boolean z, boolean z2) {
        if (view instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) view;
            if (z) {
                b(viewGroup, jSONObject, aVar, z2);
            } else {
                a(viewGroup, jSONObject, aVar, z2);
            }
        }
    }

    public final void a(ViewGroup viewGroup, JSONObject jSONObject, ec.a aVar, boolean z) {
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            aVar.a(viewGroup.getChildAt(i), this, jSONObject, z);
        }
    }
}
