package io.flutter.view;

import android.graphics.Rect;
import android.opengl.Matrix;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.LocaleSpan;
import android.text.style.TtsSpan;
import androidx.annotation.Nullable;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

/* JADX INFO: loaded from: classes.dex */
public final class g {
    public int B;
    public int C;
    public int D;
    public int E;
    public float F;
    public String G;
    public String H;
    public float I;
    public float J;
    public float K;
    public float L;
    public float[] M;
    public g N;
    public ArrayList Q;
    public d R;
    public d S;
    public float[] U;
    public float[] W;
    public Rect X;

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f28378d;

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public int f28381g;

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public int f28383i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public int f28384j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public int f28385k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public float f28386l;

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

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public float f28388n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public String f28389o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public String f28390p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public ArrayList f28391q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public String f28392r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public List f28393s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public String f28394t;

    @Nullable
    private String tooltip;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public ArrayList f28395u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public String f28396v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public ArrayList f28397w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public String f28398x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public ArrayList f28399y;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f28376b = -1;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public int f28400z = -1;
    public boolean A = false;
    public final ArrayList O = new ArrayList();
    public final ArrayList P = new ArrayList();
    public boolean T = true;
    public boolean V = true;

    public g(j jVar) {
        this.f28375a = jVar;
    }

    public static boolean a(g gVar, AccessibilityBridge$Action accessibilityBridge$Action) {
        return (gVar.f28378d & accessibilityBridge$Action.value) != 0;
    }

    public static CharSequence b(g gVar) {
        CharSequence[] charSequenceArr = {g(gVar.f28392r, gVar.f28393s), g(gVar.f28390p, gVar.f28391q), g(gVar.f28398x, gVar.f28399y)};
        CharSequence charSequenceConcat = null;
        for (int i10 = 0; i10 < 3; i10++) {
            CharSequence charSequence = charSequenceArr[i10];
            if (charSequence != null && charSequence.length() > 0) {
                charSequenceConcat = (charSequenceConcat == null || charSequenceConcat.length() == 0) ? charSequence : TextUtils.concat(charSequenceConcat, ", ", charSequence);
            }
        }
        return charSequenceConcat;
    }

    public static void d(g gVar, ByteBuffer byteBuffer, String[] strArr, ByteBuffer[] byteBufferArr) {
        j jVar;
        gVar.A = true;
        gVar.G = gVar.f28392r;
        gVar.H = gVar.f28390p;
        gVar.B = gVar.f28377c;
        gVar.C = gVar.f28378d;
        gVar.D = gVar.f28381g;
        gVar.E = gVar.f28382h;
        gVar.F = gVar.f28386l;
        gVar.f28377c = byteBuffer.getInt();
        gVar.f28378d = byteBuffer.getInt();
        gVar.f28379e = byteBuffer.getInt();
        gVar.f28380f = byteBuffer.getInt();
        gVar.f28381g = byteBuffer.getInt();
        gVar.f28382h = byteBuffer.getInt();
        gVar.f28383i = byteBuffer.getInt();
        gVar.f28384j = byteBuffer.getInt();
        gVar.f28385k = byteBuffer.getInt();
        gVar.f28386l = byteBuffer.getFloat();
        gVar.f28387m = byteBuffer.getFloat();
        gVar.f28388n = byteBuffer.getFloat();
        int i10 = byteBuffer.getInt();
        gVar.f28389o = i10 == -1 ? null : strArr[i10];
        int i11 = byteBuffer.getInt();
        gVar.f28390p = i11 == -1 ? null : strArr[i11];
        gVar.f28391q = i(byteBuffer, byteBufferArr);
        int i12 = byteBuffer.getInt();
        gVar.f28392r = i12 == -1 ? null : strArr[i12];
        gVar.f28393s = i(byteBuffer, byteBufferArr);
        int i13 = byteBuffer.getInt();
        gVar.f28394t = i13 == -1 ? null : strArr[i13];
        gVar.f28395u = i(byteBuffer, byteBufferArr);
        int i14 = byteBuffer.getInt();
        gVar.f28396v = i14 == -1 ? null : strArr[i14];
        gVar.f28397w = i(byteBuffer, byteBufferArr);
        int i15 = byteBuffer.getInt();
        gVar.f28398x = i15 == -1 ? null : strArr[i15];
        gVar.f28399y = i(byteBuffer, byteBufferArr);
        int i16 = byteBuffer.getInt();
        gVar.tooltip = i16 == -1 ? null : strArr[i16];
        byteBuffer.getInt();
        gVar.I = byteBuffer.getFloat();
        gVar.J = byteBuffer.getFloat();
        gVar.K = byteBuffer.getFloat();
        gVar.L = byteBuffer.getFloat();
        if (gVar.M == null) {
            gVar.M = new float[16];
        }
        for (int i17 = 0; i17 < 16; i17++) {
            gVar.M[i17] = byteBuffer.getFloat();
        }
        gVar.T = true;
        gVar.V = true;
        int i18 = byteBuffer.getInt();
        ArrayList arrayList = gVar.O;
        arrayList.clear();
        ArrayList arrayList2 = gVar.P;
        arrayList2.clear();
        int i19 = 0;
        while (true) {
            jVar = gVar.f28375a;
            if (i19 >= i18) {
                break;
            }
            g gVarE = jVar.e(byteBuffer.getInt());
            gVarE.N = gVar;
            arrayList.add(gVarE);
            i19++;
        }
        for (int i20 = 0; i20 < i18; i20++) {
            g gVarE2 = jVar.e(byteBuffer.getInt());
            gVarE2.N = gVar;
            arrayList2.add(gVarE2);
        }
        int i21 = byteBuffer.getInt();
        if (i21 == 0) {
            gVar.Q = null;
            return;
        }
        ArrayList arrayList3 = gVar.Q;
        if (arrayList3 == null) {
            gVar.Q = new ArrayList(i21);
        } else {
            arrayList3.clear();
        }
        for (int i22 = 0; i22 < i21; i22++) {
            d dVarD = jVar.d(byteBuffer.getInt());
            int i23 = dVarD.f28371c;
            if (i23 == AccessibilityBridge$Action.TAP.value) {
                gVar.R = dVarD;
            } else if (i23 == AccessibilityBridge$Action.LONG_PRESS.value) {
                gVar.S = dVarD;
            } else {
                gVar.Q.add(dVarD);
            }
            gVar.Q.add(dVarD);
        }
    }

    public static boolean e(g gVar, AccessibilityBridge$Action accessibilityBridge$Action) {
        return (gVar.C & accessibilityBridge$Action.value) != 0;
    }

    public static SpannableString g(String str, List list) {
        if (str == null) {
            return null;
        }
        SpannableString spannableString = new SpannableString(str);
        if (list != null) {
            Iterator it = list.iterator();
            while (it.hasNext()) {
                i iVar = (i) it.next();
                int iOrdinal = iVar.f28403c.ordinal();
                if (iOrdinal == 0) {
                    spannableString.setSpan(new TtsSpan.Builder("android.type.verbatim").build(), iVar.f28401a, iVar.f28402b, 0);
                } else if (iOrdinal == 1) {
                    spannableString.setSpan(new LocaleSpan(Locale.forLanguageTag(((e) iVar).f28374d)), iVar.f28401a, iVar.f28402b, 0);
                }
            }
        }
        return spannableString;
    }

    public static ArrayList i(ByteBuffer byteBuffer, ByteBuffer[] byteBufferArr) {
        int i10 = byteBuffer.getInt();
        if (i10 == -1) {
            return null;
        }
        ArrayList arrayList = new ArrayList(i10);
        for (int i11 = 0; i11 < i10; i11++) {
            int i12 = byteBuffer.getInt();
            int i13 = byteBuffer.getInt();
            AccessibilityBridge$StringAttributeType accessibilityBridge$StringAttributeType = AccessibilityBridge$StringAttributeType.values()[byteBuffer.getInt()];
            int iOrdinal = accessibilityBridge$StringAttributeType.ordinal();
            if (iOrdinal == 0) {
                byteBuffer.getInt();
                h hVar = new h();
                hVar.f28401a = i12;
                hVar.f28402b = i13;
                hVar.f28403c = accessibilityBridge$StringAttributeType;
                arrayList.add(hVar);
            } else if (iOrdinal == 1) {
                ByteBuffer byteBuffer2 = byteBufferArr[byteBuffer.getInt()];
                e eVar = new e();
                eVar.f28401a = i12;
                eVar.f28402b = i13;
                eVar.f28403c = accessibilityBridge$StringAttributeType;
                eVar.f28374d = Charset.forName("UTF-8").decode(byteBuffer2).toString();
                arrayList.add(eVar);
            }
        }
        return arrayList;
    }

    public static void m(float[] fArr, float[] fArr2, float[] fArr3) {
        Matrix.multiplyMV(fArr, 0, fArr2, 0, fArr3, 0);
        float f10 = fArr[3];
        fArr[0] = fArr[0] / f10;
        fArr[1] = fArr[1] / f10;
        fArr[2] = fArr[2] / f10;
        fArr[3] = 0.0f;
    }

    public final void f(ArrayList arrayList) {
        if (j(AccessibilityBridge$Flag.SCOPES_ROUTE)) {
            arrayList.add(this);
        }
        Iterator it = this.O.iterator();
        while (it.hasNext()) {
            ((g) it.next()).f(arrayList);
        }
    }

    public final String h() {
        String str;
        if (j(AccessibilityBridge$Flag.NAMES_ROUTE) && (str = this.f28390p) != null && !str.isEmpty()) {
            return this.f28390p;
        }
        Iterator it = this.O.iterator();
        while (it.hasNext()) {
            String strH = ((g) it.next()).h();
            if (strH != null && !strH.isEmpty()) {
                return strH;
            }
        }
        return null;
    }

    public final boolean j(AccessibilityBridge$Flag accessibilityBridge$Flag) {
        return (accessibilityBridge$Flag.value & this.f28377c) != 0;
    }

    public final g k(float[] fArr, boolean z10) {
        float f10 = fArr[3];
        boolean z11 = false;
        float f11 = fArr[0] / f10;
        float f12 = fArr[1] / f10;
        if (f11 < this.I || f11 >= this.K || f12 < this.J || f12 >= this.L) {
            return null;
        }
        float[] fArr2 = new float[4];
        for (g gVar : this.P) {
            if (!gVar.j(AccessibilityBridge$Flag.IS_HIDDEN)) {
                if (gVar.T) {
                    gVar.T = false;
                    if (gVar.U == null) {
                        gVar.U = new float[16];
                    }
                    if (!Matrix.invertM(gVar.U, 0, gVar.M, 0)) {
                        Arrays.fill(gVar.U, 0.0f);
                    }
                }
                Matrix.multiplyMV(fArr2, 0, gVar.U, 0, fArr, 0);
                g gVarK = gVar.k(fArr2, z10);
                if (gVarK != null) {
                    return gVarK;
                }
            }
        }
        if (z10 && this.f28383i != -1) {
            z11 = true;
        }
        if (l() || z11) {
            return this;
        }
        return null;
    }

    public final boolean l() {
        String str;
        String str2;
        String str3;
        if (j(AccessibilityBridge$Flag.SCOPES_ROUTE)) {
            return false;
        }
        if (j(AccessibilityBridge$Flag.IS_FOCUSABLE)) {
            return true;
        }
        return ((this.f28378d & (~j.f28404u)) == 0 && (this.f28377c & j.f28405v) == 0 && ((str = this.f28390p) == null || str.isEmpty()) && (((str2 = this.f28392r) == null || str2.isEmpty()) && ((str3 = this.f28398x) == null || str3.isEmpty()))) ? false : true;
    }

    public final void n(float[] fArr, HashSet hashSet, boolean z10) {
        hashSet.add(this);
        if (this.V) {
            z10 = true;
        }
        if (z10) {
            if (this.W == null) {
                this.W = new float[16];
            }
            if (this.M == null) {
                this.M = new float[16];
            }
            Matrix.multiplyMM(this.W, 0, fArr, 0, this.M, 0);
            float[] fArr2 = {this.I, this.J, 0.0f, 1.0f};
            float[] fArr3 = new float[4];
            float[] fArr4 = new float[4];
            float[] fArr5 = new float[4];
            float[] fArr6 = new float[4];
            m(fArr3, this.W, fArr2);
            fArr2[0] = this.K;
            fArr2[1] = this.J;
            m(fArr4, this.W, fArr2);
            fArr2[0] = this.K;
            fArr2[1] = this.L;
            m(fArr5, this.W, fArr2);
            fArr2[0] = this.I;
            fArr2[1] = this.L;
            m(fArr6, this.W, fArr2);
            if (this.X == null) {
                this.X = new Rect();
            }
            this.X.set(Math.round(Math.min(fArr3[0], Math.min(fArr4[0], Math.min(fArr5[0], fArr6[0])))), Math.round(Math.min(fArr3[1], Math.min(fArr4[1], Math.min(fArr5[1], fArr6[1])))), Math.round(Math.max(fArr3[0], Math.max(fArr4[0], Math.max(fArr5[0], fArr6[0])))), Math.round(Math.max(fArr3[1], Math.max(fArr4[1], Math.max(fArr5[1], fArr6[1])))));
            this.V = false;
        }
        int i10 = -1;
        for (g gVar : this.O) {
            gVar.f28400z = i10;
            i10 = gVar.f28376b;
            gVar.n(this.W, hashSet, z10);
        }
    }
}
