package com.bytedance.adsdk.ugeno.jnr;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.SparseIntArray;
import android.view.View;
import android.view.ViewGroup;
import com.bytedance.adsdk.ugeno.jnr.yz;
import com.bytedance.adsdk.ugeno.wsy.wsy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import okhttp3.internal.http2.Http2Connection;

/* JADX INFO: loaded from: classes.dex */
public class jnr extends ViewGroup implements com.bytedance.adsdk.ugeno.jnr.fm {
    private int ajl;
    private int[] dsz;
    private int duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private int f6358ef;
    private yz fhx;
    private int fm;
    private yz.fm gof;
    private List<lb> irt;
    private int jnr;
    private int ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private int f6359lb;
    private SparseIntArray onz;
    private com.bytedance.adsdk.ugeno.yz qhl;
    private int ro;
    private int vt;
    private Drawable wsy;
    private Drawable wu;
    private int yz;

    public static class fm extends ViewGroup.MarginLayoutParams implements ro {
        public static final Parcelable.Creator<fm> CREATOR = new Parcelable.Creator<fm>() { // from class: com.bytedance.adsdk.ugeno.jnr.jnr.fm.1
            @Override // android.os.Parcelable.Creator
            /* JADX INFO: renamed from: fm, reason: merged with bridge method [inline-methods] */
            public fm createFromParcel(Parcel parcel) {
                return new fm(parcel);
            }

            @Override // android.os.Parcelable.Creator
            /* JADX INFO: renamed from: fm, reason: merged with bridge method [inline-methods] */
            public fm[] newArray(int i10) {
                return new fm[i10];
            }
        };
        private int ajl;

        /* JADX INFO: renamed from: ef, reason: collision with root package name */
        private int f6360ef;
        private int fm;
        private float jnr;

        /* JADX INFO: renamed from: lb, reason: collision with root package name */
        private float f6361lb;
        private float ro;
        private boolean vt;
        private int wsy;
        private int wu;
        private int yz;

        public fm(fm fmVar) {
            super((ViewGroup.MarginLayoutParams) fmVar);
            this.fm = 1;
            this.ro = 0.0f;
            this.f6361lb = 0.0f;
            this.yz = -1;
            this.jnr = -1.0f;
            this.ajl = -1;
            this.wsy = -1;
            this.wu = 16777215;
            this.f6360ef = 16777215;
            this.fm = fmVar.fm;
            this.ro = fmVar.ro;
            this.f6361lb = fmVar.f6361lb;
            this.yz = fmVar.yz;
            this.jnr = fmVar.jnr;
            this.ajl = fmVar.ajl;
            this.wsy = fmVar.wsy;
            this.wu = fmVar.wu;
            this.f6360ef = fmVar.f6360ef;
            this.vt = fmVar.vt;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public int ajl() {
            return this.yz;
        }

        @Override // android.os.Parcelable
        public int describeContents() {
            return 0;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public int dsz() {
            return ((ViewGroup.MarginLayoutParams) this).leftMargin;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public float duv() {
            return this.jnr;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public int ef() {
            return this.wu;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public int fhx() {
            return ((ViewGroup.MarginLayoutParams) this).rightMargin;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public int fm() {
            return ((ViewGroup.MarginLayoutParams) this).width;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public int irt() {
            return ((ViewGroup.MarginLayoutParams) this).bottomMargin;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public float jnr() {
            return this.f6361lb;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public boolean ku() {
            return this.vt;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public int lb() {
            return this.fm;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public int onz() {
            return ((ViewGroup.MarginLayoutParams) this).topMargin;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public int ro() {
            return ((ViewGroup.MarginLayoutParams) this).height;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public int vt() {
            return this.f6360ef;
        }

        @Override // android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i10) {
            parcel.writeInt(this.fm);
            parcel.writeFloat(this.ro);
            parcel.writeFloat(this.f6361lb);
            parcel.writeInt(this.yz);
            parcel.writeFloat(this.jnr);
            parcel.writeInt(this.ajl);
            parcel.writeInt(this.wsy);
            parcel.writeInt(this.wu);
            parcel.writeInt(this.f6360ef);
            parcel.writeByte(this.vt ? (byte) 1 : (byte) 0);
            parcel.writeInt(((ViewGroup.MarginLayoutParams) this).bottomMargin);
            parcel.writeInt(((ViewGroup.MarginLayoutParams) this).leftMargin);
            parcel.writeInt(((ViewGroup.MarginLayoutParams) this).rightMargin);
            parcel.writeInt(((ViewGroup.MarginLayoutParams) this).topMargin);
            parcel.writeInt(((ViewGroup.MarginLayoutParams) this).height);
            parcel.writeInt(((ViewGroup.MarginLayoutParams) this).width);
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public int wsy() {
            return this.ajl;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public int wu() {
            return this.wsy;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public float yz() {
            return this.ro;
        }

        public void fm(float f10) {
            this.ro = f10;
        }

        public void lb(float f10) {
            this.jnr = f10;
        }

        public void ro(float f10) {
            this.f6361lb = f10;
        }

        public void yz(int i10) {
            this.yz = i10;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public void fm(int i10) {
            this.ajl = i10;
        }

        public void lb(int i10) {
            this.fm = i10;
        }

        @Override // com.bytedance.adsdk.ugeno.jnr.ro
        public void ro(int i10) {
            this.wsy = i10;
        }

        public fm(ViewGroup.LayoutParams layoutParams) {
            super(layoutParams);
            this.fm = 1;
            this.ro = 0.0f;
            this.f6361lb = 0.0f;
            this.yz = -1;
            this.jnr = -1.0f;
            this.ajl = -1;
            this.wsy = -1;
            this.wu = 16777215;
            this.f6360ef = 16777215;
        }

        public fm(int i10, int i11) {
            super(new ViewGroup.LayoutParams(i10, i11));
            this.fm = 1;
            this.ro = 0.0f;
            this.f6361lb = 0.0f;
            this.yz = -1;
            this.jnr = -1.0f;
            this.ajl = -1;
            this.wsy = -1;
            this.wu = 16777215;
            this.f6360ef = 16777215;
        }

        public fm(ViewGroup.MarginLayoutParams marginLayoutParams) {
            super(marginLayoutParams);
            this.fm = 1;
            this.ro = 0.0f;
            this.f6361lb = 0.0f;
            this.yz = -1;
            this.jnr = -1.0f;
            this.ajl = -1;
            this.wsy = -1;
            this.wu = 16777215;
            this.f6360ef = 16777215;
        }

        public fm(Parcel parcel) {
            super(0, 0);
            this.fm = 1;
            this.ro = 0.0f;
            this.f6361lb = 0.0f;
            this.yz = -1;
            this.jnr = -1.0f;
            this.ajl = -1;
            this.wsy = -1;
            this.wu = 16777215;
            this.f6360ef = 16777215;
            this.fm = parcel.readInt();
            this.ro = parcel.readFloat();
            this.f6361lb = parcel.readFloat();
            this.yz = parcel.readInt();
            this.jnr = parcel.readFloat();
            this.ajl = parcel.readInt();
            this.wsy = parcel.readInt();
            this.wu = parcel.readInt();
            this.f6360ef = parcel.readInt();
            this.vt = parcel.readByte() != 0;
            ((ViewGroup.MarginLayoutParams) this).bottomMargin = parcel.readInt();
            ((ViewGroup.MarginLayoutParams) this).leftMargin = parcel.readInt();
            ((ViewGroup.MarginLayoutParams) this).rightMargin = parcel.readInt();
            ((ViewGroup.MarginLayoutParams) this).topMargin = parcel.readInt();
            ((ViewGroup.MarginLayoutParams) this).height = parcel.readInt();
            ((ViewGroup.MarginLayoutParams) this).width = parcel.readInt();
        }
    }

    public jnr(Context context) {
        super(context, null);
        this.ajl = -1;
        this.fhx = new yz(this);
        this.irt = new ArrayList();
        this.gof = new yz.fm();
    }

    private boolean ajl(int i10) {
        if (i10 >= 0 && i10 < this.irt.size()) {
            for (int i11 = i10 + 1; i11 < this.irt.size(); i11++) {
                if (this.irt.get(i11).ro() > 0) {
                    return false;
                }
            }
            if (fm()) {
                return (this.f6358ef & 4) != 0;
            }
            if ((this.vt & 4) != 0) {
                return true;
            }
        }
        return false;
    }

    private boolean jnr(int i10, int i11) {
        for (int i12 = 1; i12 <= i11; i12++) {
            View viewLb = lb(i10 - i12);
            if (viewLb != null && viewLb.getVisibility() != 8) {
                return false;
            }
        }
        return true;
    }

    private boolean yz(int i10, int i11) {
        return jnr(i10, i11) ? fm() ? (this.vt & 1) != 0 : (this.f6358ef & 1) != 0 : fm() ? (this.vt & 2) != 0 : (this.f6358ef & 2) != 0;
    }

    @Override // android.view.ViewGroup
    public void addView(View view, int i10, ViewGroup.LayoutParams layoutParams) {
        if (this.onz == null) {
            this.onz = new SparseIntArray(getChildCount());
        }
        this.dsz = this.fhx.fm(view, i10, layoutParams, this.onz);
        super.addView(view, i10, layoutParams);
    }

    @Override // android.view.ViewGroup
    public boolean checkLayoutParams(ViewGroup.LayoutParams layoutParams) {
        return layoutParams instanceof fm;
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public int fm(View view) {
        return 0;
    }

    @Override // android.view.ViewGroup
    public ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams layoutParams) {
        return layoutParams instanceof fm ? new fm((fm) layoutParams) : layoutParams instanceof ViewGroup.MarginLayoutParams ? new fm((ViewGroup.MarginLayoutParams) layoutParams) : new fm(layoutParams);
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public int getAlignContent() {
        return this.jnr;
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public int getAlignItems() {
        return this.yz;
    }

    public Drawable getDividerDrawableHorizontal() {
        return this.wsy;
    }

    public Drawable getDividerDrawableVertical() {
        return this.wu;
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public int getFlexDirection() {
        return this.fm;
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public int getFlexItemCount() {
        return getChildCount();
    }

    public List<lb> getFlexLines() {
        ArrayList arrayList = new ArrayList(this.irt.size());
        for (lb lbVar : this.irt) {
            if (lbVar.ro() != 0) {
                arrayList.add(lbVar);
            }
        }
        return arrayList;
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public List<lb> getFlexLinesInternal() {
        return this.irt;
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public int getFlexWrap() {
        return this.ro;
    }

    public int getJustifyContent() {
        return this.f6359lb;
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public int getLargestMainSize() {
        Iterator<lb> it = this.irt.iterator();
        int iMax = Integer.MIN_VALUE;
        while (it.hasNext()) {
            iMax = Math.max(iMax, it.next().jnr);
        }
        return iMax;
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public int getMaxLine() {
        return this.ajl;
    }

    public int getShowDividerHorizontal() {
        return this.f6358ef;
    }

    public int getShowDividerVertical() {
        return this.vt;
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public int getSumOfCrossSize() {
        int size = this.irt.size();
        int i10 = 0;
        for (int i11 = 0; i11 < size; i11++) {
            lb lbVar = this.irt.get(i11);
            if (yz(i11)) {
                i10 += fm() ? this.ku : this.duv;
            }
            if (ajl(i11)) {
                i10 += fm() ? this.ku : this.duv;
            }
            i10 += lbVar.wsy;
        }
        return i10;
    }

    public View lb(int i10) {
        if (i10 < 0) {
            return null;
        }
        int[] iArr = this.dsz;
        if (i10 >= iArr.length) {
            return null;
        }
        return getChildAt(iArr[i10]);
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        com.bytedance.adsdk.ugeno.yz yzVar = this.qhl;
        if (yzVar != null) {
            yzVar.wsy();
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        com.bytedance.adsdk.ugeno.yz yzVar = this.qhl;
        if (yzVar != null) {
            yzVar.wu();
        }
    }

    @Override // android.view.View
    public void onDraw(Canvas canvas) {
        if (this.wu == null && this.wsy == null) {
            return;
        }
        if (this.f6358ef == 0 && this.vt == 0) {
            return;
        }
        int iFm = wsy.fm(this);
        int i10 = this.fm;
        if (i10 == 0) {
            fm(canvas, iFm == 1, this.ro == 2);
            return;
        }
        if (i10 == 1) {
            fm(canvas, iFm != 1, this.ro == 2);
            return;
        }
        if (i10 == 2) {
            boolean z10 = iFm == 1;
            if (this.ro == 2) {
                z10 = !z10;
            }
            ro(canvas, z10, false);
            return;
        }
        if (i10 != 3) {
            return;
        }
        boolean z11 = iFm == 1;
        if (this.ro == 2) {
            z11 = !z11;
        }
        ro(canvas, z11, true);
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        boolean z11;
        com.bytedance.adsdk.ugeno.yz yzVar = this.qhl;
        if (yzVar != null) {
            yzVar.ajl();
        }
        int iFm = wsy.fm(this);
        int i14 = this.fm;
        if (i14 == 0) {
            fm(iFm == 1, i10, i11, i12, i13);
        } else if (i14 == 1) {
            fm(iFm != 1, i10, i11, i12, i13);
        } else if (i14 == 2) {
            z11 = iFm == 1;
            fm(this.ro == 2 ? !z11 : z11, false, i10, i11, i12, i13);
        } else {
            if (i14 != 3) {
                throw new IllegalStateException("Invalid flex direction is set: " + this.fm);
            }
            z11 = iFm == 1;
            fm(this.ro == 2 ? !z11 : z11, true, i10, i11, i12, i13);
        }
        com.bytedance.adsdk.ugeno.yz yzVar2 = this.qhl;
        if (yzVar2 != null) {
            yzVar2.fm(i10, i11, i12, i13);
        }
    }

    @Override // android.view.View
    public void onMeasure(int i10, int i11) {
        com.bytedance.adsdk.ugeno.yz yzVar = this.qhl;
        if (yzVar != null) {
            int[] iArrFm = yzVar.fm(i10, i11);
            fm(iArrFm[0], iArrFm[1]);
        } else {
            fm(i10, i11);
        }
        com.bytedance.adsdk.ugeno.yz yzVar2 = this.qhl;
        if (yzVar2 != null) {
            yzVar2.jnr();
        }
    }

    @Override // android.view.View
    public void onSizeChanged(int i10, int i11, int i12, int i13) {
        super.onSizeChanged(i10, i11, i12, i13);
        com.bytedance.adsdk.ugeno.yz yzVar = this.qhl;
        if (yzVar != null) {
            yzVar.ro(i10, i11, i12, i13);
        }
    }

    @Override // android.view.View
    public void onWindowFocusChanged(boolean z10) {
        super.onWindowFocusChanged(z10);
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public View ro(int i10) {
        return lb(i10);
    }

    public void setAlignContent(int i10) {
        if (this.jnr != i10) {
            this.jnr = i10;
            requestLayout();
        }
    }

    public void setAlignItems(int i10) {
        if (this.yz != i10) {
            this.yz = i10;
            requestLayout();
        }
    }

    public void setDividerDrawable(Drawable drawable) {
        setDividerDrawableHorizontal(drawable);
        setDividerDrawableVertical(drawable);
    }

    public void setDividerDrawableHorizontal(Drawable drawable) {
        if (drawable == this.wsy) {
            return;
        }
        this.wsy = drawable;
        if (drawable != null) {
            this.ku = drawable.getIntrinsicHeight();
        } else {
            this.ku = 0;
        }
        ro();
        requestLayout();
    }

    public void setDividerDrawableVertical(Drawable drawable) {
        if (drawable == this.wu) {
            return;
        }
        this.wu = drawable;
        if (drawable != null) {
            this.duv = drawable.getIntrinsicWidth();
        } else {
            this.duv = 0;
        }
        ro();
        requestLayout();
    }

    public void setFlexDirection(int i10) {
        if (this.fm != i10) {
            this.fm = i10;
            requestLayout();
        }
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public void setFlexLines(List<lb> list) {
        this.irt = list;
    }

    public void setFlexWrap(int i10) {
        if (this.ro != i10) {
            this.ro = i10;
            requestLayout();
        }
    }

    public void setJustifyContent(int i10) {
        if (this.f6359lb != i10) {
            this.f6359lb = i10;
            requestLayout();
        }
    }

    public void setMaxLine(int i10) {
        if (this.ajl != i10) {
            this.ajl = i10;
            requestLayout();
        }
    }

    public void setShowDivider(int i10) {
        setShowDividerVertical(i10);
        setShowDividerHorizontal(i10);
    }

    public void setShowDividerHorizontal(int i10) {
        if (i10 != this.f6358ef) {
            this.f6358ef = i10;
            requestLayout();
        }
    }

    public void setShowDividerVertical(int i10) {
        if (i10 != this.vt) {
            this.vt = i10;
            requestLayout();
        }
    }

    private void ro(int i10, int i11) {
        this.irt.clear();
        this.gof.fm();
        this.fhx.fm(this.gof, i10, i11);
        this.irt = this.gof.fm;
        this.fhx.fm(i10, i11);
        if (this.yz == 3) {
            for (lb lbVar : this.irt) {
                int iMax = Integer.MIN_VALUE;
                for (int i12 = 0; i12 < lbVar.wu; i12++) {
                    View viewLb = lb(lbVar.fhx + i12);
                    if (viewLb != null && viewLb.getVisibility() != 8) {
                        fm fmVar = (fm) viewLb.getLayoutParams();
                        iMax = this.ro != 2 ? Math.max(iMax, viewLb.getMeasuredHeight() + Math.max(lbVar.duv - viewLb.getBaseline(), ((ViewGroup.MarginLayoutParams) fmVar).topMargin) + ((ViewGroup.MarginLayoutParams) fmVar).bottomMargin) : Math.max(iMax, viewLb.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) fmVar).topMargin + Math.max(viewLb.getBaseline() + (lbVar.duv - viewLb.getMeasuredHeight()), ((ViewGroup.MarginLayoutParams) fmVar).bottomMargin));
                    }
                }
                lbVar.wsy = iMax;
            }
        }
        this.fhx.ro(i10, i11, getPaddingBottom() + getPaddingTop());
        this.fhx.fm();
        fm(this.fm, i10, i11, this.gof.ro);
    }

    public void fm(com.bytedance.adsdk.ugeno.ro.lb lbVar) {
        this.qhl = lbVar;
    }

    private boolean jnr(int i10) {
        for (int i11 = 0; i11 < i10; i11++) {
            if (this.irt.get(i11).ro() > 0) {
                return false;
            }
        }
        return true;
    }

    private void lb(int i10, int i11) {
        this.irt.clear();
        this.gof.fm();
        this.fhx.ro(this.gof, i10, i11);
        this.irt = this.gof.fm;
        this.fhx.fm(i10, i11);
        this.fhx.ro(i10, i11, getPaddingRight() + getPaddingLeft());
        this.fhx.fm();
        fm(this.fm, i10, i11, this.gof.ro);
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public boolean fm() {
        int i10 = this.fm;
        return i10 == 0 || i10 == 1;
    }

    private void fm(int i10, int i11) {
        if (this.onz == null) {
            this.onz = new SparseIntArray(getChildCount());
        }
        if (this.fhx.ro(this.onz)) {
            this.dsz = this.fhx.fm(this.onz);
        }
        int i12 = this.fm;
        if (i12 == 0 || i12 == 1) {
            ro(i10, i11);
        } else {
            if (i12 != 2 && i12 != 3) {
                throw new IllegalStateException("Invalid value for the flex direction is set: " + this.fm);
            }
            lb(i10, i11);
        }
    }

    private boolean yz(int i10) {
        if (i10 >= 0 && i10 < this.irt.size()) {
            if (jnr(i10)) {
                return fm() ? (this.f6358ef & 1) != 0 : (this.vt & 1) != 0;
            }
            if (fm()) {
                return (this.f6358ef & 2) != 0;
            }
            if ((this.vt & 2) != 0) {
                return true;
            }
        }
        return false;
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public View fm(int i10) {
        return getChildAt(i10);
    }

    private void fm(int i10, int i11, int i12, int i13) {
        int paddingBottom;
        int largestMainSize;
        int iResolveSizeAndState;
        int iResolveSizeAndState2;
        int mode = View.MeasureSpec.getMode(i11);
        int size = View.MeasureSpec.getSize(i11);
        int mode2 = View.MeasureSpec.getMode(i12);
        int size2 = View.MeasureSpec.getSize(i12);
        if (i10 == 0 || i10 == 1) {
            paddingBottom = getPaddingBottom() + getPaddingTop() + getSumOfCrossSize();
            largestMainSize = getLargestMainSize();
        } else {
            if (i10 != 2 && i10 != 3) {
                throw new IllegalArgumentException("Invalid flex direction: ".concat(String.valueOf(i10)));
            }
            paddingBottom = getLargestMainSize();
            largestMainSize = getPaddingRight() + getPaddingLeft() + getSumOfCrossSize();
        }
        if (mode == Integer.MIN_VALUE) {
            if (size < largestMainSize) {
                i13 = View.combineMeasuredStates(i13, Http2Connection.OKHTTP_CLIENT_WINDOW_SIZE);
            } else {
                size = largestMainSize;
            }
            iResolveSizeAndState = View.resolveSizeAndState(size, i11, i13);
        } else if (mode == 0) {
            iResolveSizeAndState = View.resolveSizeAndState(largestMainSize, i11, i13);
        } else if (mode == 1073741824) {
            if (size < largestMainSize) {
                i13 = View.combineMeasuredStates(i13, Http2Connection.OKHTTP_CLIENT_WINDOW_SIZE);
            }
            iResolveSizeAndState = View.resolveSizeAndState(size, i11, i13);
        } else {
            throw new IllegalStateException("Unknown width mode is set: ".concat(String.valueOf(mode)));
        }
        if (mode2 == Integer.MIN_VALUE) {
            if (size2 < paddingBottom) {
                i13 = View.combineMeasuredStates(i13, 256);
            } else {
                size2 = paddingBottom;
            }
            iResolveSizeAndState2 = View.resolveSizeAndState(size2, i12, i13);
        } else if (mode2 == 0) {
            iResolveSizeAndState2 = View.resolveSizeAndState(paddingBottom, i12, i13);
        } else if (mode2 == 1073741824) {
            if (size2 < paddingBottom) {
                i13 = View.combineMeasuredStates(i13, 256);
            }
            iResolveSizeAndState2 = View.resolveSizeAndState(size2, i12, i13);
        } else {
            throw new IllegalStateException("Unknown height mode is set: ".concat(String.valueOf(mode2)));
        }
        setMeasuredDimension(iResolveSizeAndState, iResolveSizeAndState2);
    }

    private void ro(Canvas canvas, boolean z10, boolean z11) {
        int i10;
        int i11;
        int bottom;
        int top;
        int paddingTop = getPaddingTop();
        int iMax = Math.max(0, (getHeight() - getPaddingBottom()) - paddingTop);
        int size = this.irt.size();
        for (int i12 = 0; i12 < size; i12++) {
            lb lbVar = this.irt.get(i12);
            for (int i13 = 0; i13 < lbVar.wu; i13++) {
                int i14 = lbVar.fhx + i13;
                View viewLb = lb(i14);
                if (viewLb != null && viewLb.getVisibility() != 8) {
                    fm fmVar = (fm) viewLb.getLayoutParams();
                    if (yz(i14, i13)) {
                        if (z11) {
                            top = viewLb.getBottom() + ((ViewGroup.MarginLayoutParams) fmVar).bottomMargin;
                        } else {
                            top = (viewLb.getTop() - ((ViewGroup.MarginLayoutParams) fmVar).topMargin) - this.ku;
                        }
                        ro(canvas, lbVar.fm, top, lbVar.wsy);
                    }
                    if (i13 == lbVar.wu - 1 && (this.f6358ef & 4) > 0) {
                        if (z11) {
                            bottom = (viewLb.getTop() - ((ViewGroup.MarginLayoutParams) fmVar).topMargin) - this.ku;
                        } else {
                            bottom = viewLb.getBottom() + ((ViewGroup.MarginLayoutParams) fmVar).bottomMargin;
                        }
                        ro(canvas, lbVar.fm, bottom, lbVar.wsy);
                    }
                }
            }
            if (yz(i12)) {
                if (z10) {
                    i11 = lbVar.f6363lb;
                } else {
                    i11 = lbVar.fm - this.duv;
                }
                fm(canvas, i11, paddingTop, iMax);
            }
            if (ajl(i12) && (this.vt & 4) > 0) {
                if (z10) {
                    i10 = lbVar.fm - this.duv;
                } else {
                    i10 = lbVar.f6363lb;
                }
                fm(canvas, i10, paddingTop, iMax);
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:41:0x00d3  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x0122  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0181  */
    /* JADX WARN: Removed duplicated region for block: B:67:0x01e4  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x01f1  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void fm(boolean z10, int i10, int i11, int i12, int i13) {
        float measuredWidth;
        float f10;
        float f11;
        int i14;
        int i15;
        int i16;
        int i17;
        char c6;
        float f12;
        int i18;
        char c10;
        fm fmVar;
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        int i19 = i12 - i10;
        int paddingBottom = (i13 - i11) - getPaddingBottom();
        int paddingTop = getPaddingTop();
        int size = this.irt.size();
        int i20 = 0;
        while (i20 < size) {
            lb lbVar = this.irt.get(i20);
            if (yz(i20)) {
                int i21 = this.ku;
                paddingBottom -= i21;
                paddingTop += i21;
            }
            int i22 = this.f6359lb;
            char c11 = 4;
            int i23 = 1;
            if (i22 == 0) {
                measuredWidth = paddingLeft;
                f10 = i19 - paddingRight;
            } else if (i22 == 1) {
                int i24 = lbVar.jnr;
                f10 = i24 - paddingLeft;
                measuredWidth = (i19 - i24) + paddingRight;
            } else if (i22 == 2) {
                int i25 = lbVar.jnr;
                measuredWidth = paddingLeft + ((i19 - i25) / 2.0f);
                f10 = (i19 - paddingRight) - ((i19 - i25) / 2.0f);
            } else {
                if (i22 == 3) {
                    measuredWidth = paddingLeft;
                    f11 = (i19 - lbVar.jnr) / (lbVar.ro() != 1 ? r10 - 1 : 1.0f);
                    f10 = i19 - paddingRight;
                } else if (i22 == 4) {
                    int iRo = lbVar.ro();
                    f11 = iRo != 0 ? (i19 - lbVar.jnr) / iRo : 0.0f;
                    float f13 = f11 / 2.0f;
                    measuredWidth = paddingLeft + f13;
                    f10 = (i19 - paddingRight) - f13;
                } else if (i22 == 5) {
                    f11 = lbVar.ro() != 0 ? (i19 - lbVar.jnr) / (r7 + 1) : 0.0f;
                    measuredWidth = paddingLeft + f11;
                    f10 = (i19 - paddingRight) - f11;
                } else {
                    throw new IllegalStateException("Invalid justifyContent is set: " + this.f6359lb);
                }
                float fMax = Math.max(f11, 0.0f);
                i14 = 0;
                while (i14 < lbVar.wu) {
                    int i26 = lbVar.fhx + i14;
                    View viewLb = lb(i26);
                    if (viewLb == null) {
                        i15 = paddingLeft;
                        i16 = i23;
                        i17 = i14;
                        c6 = c11;
                    } else if (viewLb.getVisibility() != 8) {
                        fm fmVar2 = (fm) viewLb.getLayoutParams();
                        float f14 = measuredWidth + ((ViewGroup.MarginLayoutParams) fmVar2).leftMargin;
                        float f15 = f10 - ((ViewGroup.MarginLayoutParams) fmVar2).rightMargin;
                        if (yz(i26, i14)) {
                            int i27 = this.duv;
                            float f16 = i27;
                            f14 += f16;
                            i18 = i27;
                            f12 = f15 - f16;
                        } else {
                            f12 = f15;
                            i18 = 0;
                        }
                        if (i14 == lbVar.wu - i23) {
                            c10 = 4;
                            int i28 = (this.vt & 4) > 0 ? this.duv : 0;
                            if (this.ro == 2) {
                                i15 = paddingLeft;
                                i16 = i23;
                                i17 = i14;
                                fmVar = fmVar2;
                                c6 = c10;
                                if (z10) {
                                    this.fhx.fm(viewLb, lbVar, Math.round(f12) - viewLb.getMeasuredWidth(), paddingTop, Math.round(f12), viewLb.getMeasuredHeight() + paddingTop);
                                } else {
                                    this.fhx.fm(viewLb, lbVar, Math.round(f14), paddingTop, viewLb.getMeasuredWidth() + Math.round(f14), viewLb.getMeasuredHeight() + paddingTop);
                                }
                            } else if (z10) {
                                i16 = i23;
                                i17 = i14;
                                i15 = paddingLeft;
                                fmVar = fmVar2;
                                c6 = c10;
                                this.fhx.fm(viewLb, lbVar, Math.round(f12) - viewLb.getMeasuredWidth(), paddingBottom - viewLb.getMeasuredHeight(), Math.round(f12), paddingBottom);
                            } else {
                                i15 = paddingLeft;
                                i16 = i23;
                                i17 = i14;
                                fmVar = fmVar2;
                                c6 = c10;
                                this.fhx.fm(viewLb, lbVar, Math.round(f14), paddingBottom - viewLb.getMeasuredHeight(), viewLb.getMeasuredWidth() + Math.round(f14), paddingBottom);
                            }
                            measuredWidth = f14 + viewLb.getMeasuredWidth() + fMax + ((ViewGroup.MarginLayoutParams) fmVar).rightMargin;
                            float measuredWidth2 = f12 - ((viewLb.getMeasuredWidth() + fMax) + ((ViewGroup.MarginLayoutParams) fmVar).leftMargin);
                            if (!z10) {
                                lbVar.fm(viewLb, i28, 0, i18, 0);
                            } else {
                                lbVar.fm(viewLb, i18, 0, i28, 0);
                            }
                            f10 = measuredWidth2;
                        } else {
                            c10 = 4;
                        }
                        if (this.ro == 2) {
                        }
                        measuredWidth = f14 + viewLb.getMeasuredWidth() + fMax + ((ViewGroup.MarginLayoutParams) fmVar).rightMargin;
                        float measuredWidth22 = f12 - ((viewLb.getMeasuredWidth() + fMax) + ((ViewGroup.MarginLayoutParams) fmVar).leftMargin);
                        if (!z10) {
                        }
                        f10 = measuredWidth22;
                    } else {
                        i15 = paddingLeft;
                        i16 = i23;
                        i17 = i14;
                        c6 = 4;
                    }
                    i14 = i17 + 1;
                    c11 = c6;
                    i23 = i16;
                    paddingLeft = i15;
                }
                int i29 = paddingLeft;
                int i30 = lbVar.wsy;
                paddingTop += i30;
                paddingBottom -= i30;
                i20++;
                paddingLeft = i29;
            }
            f11 = 0.0f;
            float fMax2 = Math.max(f11, 0.0f);
            i14 = 0;
            while (i14 < lbVar.wu) {
            }
            int i292 = paddingLeft;
            int i302 = lbVar.wsy;
            paddingTop += i302;
            paddingBottom -= i302;
            i20++;
            paddingLeft = i292;
        }
    }

    private void ro(Canvas canvas, int i10, int i11, int i12) {
        Drawable drawable = this.wsy;
        if (drawable == null) {
            return;
        }
        drawable.setBounds(i10, i11, i12 + i10, this.ku + i11);
        this.wsy.draw(canvas);
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public int ro(int i10, int i11, int i12) {
        return ViewGroup.getChildMeasureSpec(i10, i11, i12);
    }

    private void ro() {
        if (this.wsy == null && this.wu == null) {
            setWillNotDraw(true);
        } else {
            setWillNotDraw(false);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:42:0x00d1  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x0122  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x017b  */
    /* JADX WARN: Removed duplicated region for block: B:67:0x01de  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x01eb  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void fm(boolean z10, boolean z11, int i10, int i11, int i12, int i13) {
        float f10;
        int i14;
        float f11;
        float f12;
        int i15;
        int i16;
        boolean z12;
        char c6;
        float f13;
        float f14;
        int i17;
        char c10;
        fm fmVar;
        int paddingTop = getPaddingTop();
        int paddingBottom = getPaddingBottom();
        int paddingRight = getPaddingRight();
        int paddingLeft = getPaddingLeft();
        int i18 = i13 - i11;
        int i19 = (i12 - i10) - paddingRight;
        int size = this.irt.size();
        for (int i20 = 0; i20 < size; i20++) {
            lb lbVar = this.irt.get(i20);
            if (yz(i20)) {
                int i21 = this.duv;
                paddingLeft += i21;
                i19 -= i21;
            }
            int i22 = this.f6359lb;
            char c11 = 4;
            boolean z13 = true;
            if (i22 == 0) {
                f10 = paddingTop;
                i14 = i18 - paddingBottom;
            } else if (i22 == 1) {
                int i23 = lbVar.jnr;
                f10 = (i18 - i23) + paddingBottom;
                i14 = i23 - paddingTop;
            } else if (i22 == 2) {
                int i24 = lbVar.jnr;
                f11 = (i18 - paddingBottom) - ((i18 - i24) / 2.0f);
                f10 = paddingTop + ((i18 - i24) / 2.0f);
                f12 = 0.0f;
                float fMax = Math.max(f12, 0.0f);
                i15 = 0;
                while (i15 < lbVar.wu) {
                }
                int i25 = lbVar.wsy;
                paddingLeft += i25;
                i19 -= i25;
            } else {
                if (i22 == 3) {
                    f10 = paddingTop;
                    f12 = (i18 - lbVar.jnr) / (lbVar.ro() != 1 ? r7 - 1 : 1.0f);
                    f11 = i18 - paddingBottom;
                } else if (i22 == 4) {
                    int iRo = lbVar.ro();
                    f12 = iRo != 0 ? (i18 - lbVar.jnr) / iRo : 0.0f;
                    float f15 = f12 / 2.0f;
                    f10 = paddingTop + f15;
                    f11 = (i18 - paddingBottom) - f15;
                } else if (i22 == 5) {
                    f12 = lbVar.ro() != 0 ? (i18 - lbVar.jnr) / (r10 + 1) : 0.0f;
                    f10 = paddingTop + f12;
                    f11 = (i18 - paddingBottom) - f12;
                } else {
                    throw new IllegalStateException("Invalid justifyContent is set: " + this.f6359lb);
                }
                float fMax2 = Math.max(f12, 0.0f);
                i15 = 0;
                while (i15 < lbVar.wu) {
                    int i26 = lbVar.fhx + i15;
                    View viewLb = lb(i26);
                    if (viewLb == null) {
                        i16 = i15;
                        z12 = z13;
                        c6 = c11;
                    } else if (viewLb.getVisibility() != 8) {
                        fm fmVar2 = (fm) viewLb.getLayoutParams();
                        float f16 = f10 + ((ViewGroup.MarginLayoutParams) fmVar2).topMargin;
                        float f17 = f11 - ((ViewGroup.MarginLayoutParams) fmVar2).bottomMargin;
                        if (yz(i26, i15)) {
                            int i27 = this.ku;
                            float f18 = i27;
                            f13 = f16 + f18;
                            i17 = i27;
                            f14 = f17 - f18;
                        } else {
                            f13 = f16;
                            f14 = f17;
                            i17 = 0;
                        }
                        if (i15 == lbVar.wu - 1) {
                            c10 = 4;
                            int i28 = (this.f6358ef & 4) > 0 ? this.ku : 0;
                            if (z10) {
                                i16 = i15;
                                z12 = true;
                                fmVar = fmVar2;
                                c6 = c10;
                                if (z11) {
                                    this.fhx.fm(viewLb, lbVar, false, paddingLeft, Math.round(f14) - viewLb.getMeasuredHeight(), viewLb.getMeasuredWidth() + paddingLeft, Math.round(f14));
                                } else {
                                    this.fhx.fm(viewLb, lbVar, false, paddingLeft, Math.round(f13), viewLb.getMeasuredWidth() + paddingLeft, viewLb.getMeasuredHeight() + Math.round(f13));
                                }
                            } else if (z11) {
                                i16 = i15;
                                z12 = true;
                                fmVar = fmVar2;
                                c6 = c10;
                                this.fhx.fm(viewLb, lbVar, true, i19 - viewLb.getMeasuredWidth(), Math.round(f14) - viewLb.getMeasuredHeight(), i19, Math.round(f14));
                            } else {
                                i16 = i15;
                                z12 = true;
                                fmVar = fmVar2;
                                c6 = c10;
                                this.fhx.fm(viewLb, lbVar, true, i19 - viewLb.getMeasuredWidth(), Math.round(f13), i19, viewLb.getMeasuredHeight() + Math.round(f13));
                            }
                            fm fmVar3 = fmVar;
                            float measuredHeight = viewLb.getMeasuredHeight() + fMax2 + ((ViewGroup.MarginLayoutParams) fmVar3).bottomMargin + f13;
                            float measuredHeight2 = f14 - ((viewLb.getMeasuredHeight() + fMax2) + ((ViewGroup.MarginLayoutParams) fmVar3).topMargin);
                            if (!z11) {
                                lbVar.fm(viewLb, 0, i28, 0, i17);
                            } else {
                                lbVar.fm(viewLb, 0, i17, 0, i28);
                            }
                            f10 = measuredHeight;
                            f11 = measuredHeight2;
                        } else {
                            c10 = 4;
                        }
                        if (z10) {
                        }
                        fm fmVar32 = fmVar;
                        float measuredHeight3 = viewLb.getMeasuredHeight() + fMax2 + ((ViewGroup.MarginLayoutParams) fmVar32).bottomMargin + f13;
                        float measuredHeight22 = f14 - ((viewLb.getMeasuredHeight() + fMax2) + ((ViewGroup.MarginLayoutParams) fmVar32).topMargin);
                        if (!z11) {
                        }
                        f10 = measuredHeight3;
                        f11 = measuredHeight22;
                    } else {
                        i16 = i15;
                        z12 = true;
                        c6 = 4;
                    }
                    i15 = i16 + 1;
                    z13 = z12;
                    c11 = c6;
                }
                int i252 = lbVar.wsy;
                paddingLeft += i252;
                i19 -= i252;
            }
            f11 = i14;
            f12 = 0.0f;
            float fMax22 = Math.max(f12, 0.0f);
            i15 = 0;
            while (i15 < lbVar.wu) {
            }
            int i2522 = lbVar.wsy;
            paddingLeft += i2522;
            i19 -= i2522;
        }
    }

    private void fm(Canvas canvas, boolean z10, boolean z11) {
        int i10;
        int i11;
        int right;
        int left;
        int paddingLeft = getPaddingLeft();
        int iMax = Math.max(0, (getWidth() - getPaddingRight()) - paddingLeft);
        int size = this.irt.size();
        for (int i12 = 0; i12 < size; i12++) {
            lb lbVar = this.irt.get(i12);
            for (int i13 = 0; i13 < lbVar.wu; i13++) {
                int i14 = lbVar.fhx + i13;
                View viewLb = lb(i14);
                if (viewLb != null && viewLb.getVisibility() != 8) {
                    fm fmVar = (fm) viewLb.getLayoutParams();
                    if (yz(i14, i13)) {
                        if (z10) {
                            left = viewLb.getRight() + ((ViewGroup.MarginLayoutParams) fmVar).rightMargin;
                        } else {
                            left = (viewLb.getLeft() - ((ViewGroup.MarginLayoutParams) fmVar).leftMargin) - this.duv;
                        }
                        fm(canvas, left, lbVar.ro, lbVar.wsy);
                    }
                    if (i13 == lbVar.wu - 1 && (this.vt & 4) > 0) {
                        if (z10) {
                            right = (viewLb.getLeft() - ((ViewGroup.MarginLayoutParams) fmVar).leftMargin) - this.duv;
                        } else {
                            right = viewLb.getRight() + ((ViewGroup.MarginLayoutParams) fmVar).rightMargin;
                        }
                        fm(canvas, right, lbVar.ro, lbVar.wsy);
                    }
                }
            }
            if (yz(i12)) {
                if (z11) {
                    i11 = lbVar.yz;
                } else {
                    i11 = lbVar.ro - this.ku;
                }
                ro(canvas, paddingLeft, i11, iMax);
            }
            if (ajl(i12) && (this.f6358ef & 4) > 0) {
                if (z11) {
                    i10 = lbVar.ro - this.ku;
                } else {
                    i10 = lbVar.yz;
                }
                ro(canvas, paddingLeft, i10, iMax);
            }
        }
    }

    private void fm(Canvas canvas, int i10, int i11, int i12) {
        Drawable drawable = this.wu;
        if (drawable == null) {
            return;
        }
        drawable.setBounds(i10, i11, this.duv + i10, i12 + i11);
        this.wu.draw(canvas);
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public int fm(View view, int i10, int i11) {
        int i12;
        int i13;
        if (fm()) {
            i12 = yz(i10, i11) ? this.duv : 0;
            if ((this.vt & 4) <= 0) {
                return i12;
            }
            i13 = this.duv;
        } else {
            i12 = yz(i10, i11) ? this.ku : 0;
            if ((this.f6358ef & 4) <= 0) {
                return i12;
            }
            i13 = this.ku;
        }
        return i12 + i13;
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public void fm(lb lbVar) {
        if (fm()) {
            if ((this.vt & 4) > 0) {
                int i10 = lbVar.jnr;
                int i11 = this.duv;
                lbVar.jnr = i10 + i11;
                lbVar.ajl += i11;
                return;
            }
            return;
        }
        if ((this.f6358ef & 4) > 0) {
            int i12 = lbVar.jnr;
            int i13 = this.ku;
            lbVar.jnr = i12 + i13;
            lbVar.ajl += i13;
        }
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public int fm(int i10, int i11, int i12) {
        return ViewGroup.getChildMeasureSpec(i10, i11, i12);
    }

    @Override // com.bytedance.adsdk.ugeno.jnr.fm
    public void fm(View view, int i10, int i11, lb lbVar) {
        if (yz(i10, i11)) {
            if (fm()) {
                int i12 = lbVar.jnr;
                int i13 = this.duv;
                lbVar.jnr = i12 + i13;
                lbVar.ajl += i13;
                return;
            }
            int i14 = lbVar.jnr;
            int i15 = this.ku;
            lbVar.jnr = i14 + i15;
            lbVar.ajl += i15;
        }
    }
}
