package o;

import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowInsets;
import android.widget.FrameLayout;
import androidx.appcompat.widget.ActionBarContextView;
import com.google.android.gms.common.R;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.WeakHashMap;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class H7 implements InterfaceC2904xT, InterfaceC1701km, InterfaceC0998dP {
    public final /* synthetic */ int l;
    public final /* synthetic */ S7 m;

    public /* synthetic */ H7(S7 s7, int i) {
        this.l = i;
        this.m = s7;
    }

    @Override // o.InterfaceC0998dP
    public void a(CO co, boolean z) {
        R7 r7;
        switch (this.l) {
            case 2:
                this.m.q(co);
                break;
            default:
                CO coK = co.k();
                int i = 0;
                boolean z2 = coK != co;
                if (z2) {
                    co = coK;
                }
                S7 s7 = this.m;
                R7[] r7Arr = s7.W;
                int length = r7Arr != null ? r7Arr.length : 0;
                while (true) {
                    if (i >= length) {
                        r7 = null;
                    } else {
                        r7 = r7Arr[i];
                        if (r7 == null || r7.h != co) {
                            i++;
                        }
                    }
                }
                if (r7 != null) {
                    if (!z2) {
                        s7.r(r7, z);
                        break;
                    } else {
                        s7.p(r7.a, r7, coK);
                        s7.r(r7, true);
                        break;
                    }
                }
                break;
        }
    }

    @Override // o.InterfaceC2904xT
    public Kl0 i(View view, Kl0 kl0) throws IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
        int i;
        boolean z;
        boolean z2;
        boolean z3;
        Kl0 kl0B = kl0;
        int iD = kl0B.d();
        S7 s7 = this.m;
        Context context = s7.v;
        int iD2 = kl0B.d();
        ActionBarContextView actionBarContextView = s7.G;
        if (actionBarContextView == null || !(actionBarContextView.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) {
            i = 0;
            z = false;
        } else {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) s7.G.getLayoutParams();
            if (s7.G.isShown()) {
                if (s7.n0 == null) {
                    s7.n0 = new Rect();
                    s7.o0 = new Rect();
                }
                Rect rect = s7.n0;
                Rect rect2 = s7.o0;
                rect.set(kl0B.b(), kl0B.d(), kl0B.c(), kl0B.a());
                ViewGroup viewGroup = s7.L;
                if (Build.VERSION.SDK_INT >= 29) {
                    boolean z4 = AbstractC2457sk0.a;
                    AbstractC2268qk0.a(viewGroup, rect, rect2);
                } else {
                    if (!AbstractC2457sk0.a) {
                        AbstractC2457sk0.a = true;
                        try {
                            Method declaredMethod = View.class.getDeclaredMethod("computeFitSystemWindows", Rect.class, Rect.class);
                            AbstractC2457sk0.b = declaredMethod;
                            if (!declaredMethod.isAccessible()) {
                                AbstractC2457sk0.b.setAccessible(true);
                            }
                        } catch (NoSuchMethodException unused) {
                        }
                    }
                    Method method = AbstractC2457sk0.b;
                    if (method != null) {
                        try {
                            method.invoke(viewGroup, rect, rect2);
                        } catch (Exception unused2) {
                        }
                    }
                }
                int i2 = rect.top;
                int i3 = rect.left;
                int i4 = rect.right;
                ViewGroup viewGroup2 = s7.L;
                WeakHashMap weakHashMap = Oj0.a;
                Kl0 kl0A = Hj0.a(viewGroup2);
                int iB = kl0A == null ? 0 : kl0A.b();
                int iC = kl0A == null ? 0 : kl0A.c();
                if (marginLayoutParams.topMargin == i2 && marginLayoutParams.leftMargin == i3 && marginLayoutParams.rightMargin == i4) {
                    z3 = false;
                } else {
                    marginLayoutParams.topMargin = i2;
                    marginLayoutParams.leftMargin = i3;
                    marginLayoutParams.rightMargin = i4;
                    z3 = true;
                }
                if (i2 <= 0 || s7.N != null) {
                    View view2 = s7.N;
                    if (view2 != null) {
                        ViewGroup.MarginLayoutParams marginLayoutParams2 = (ViewGroup.MarginLayoutParams) view2.getLayoutParams();
                        int i5 = marginLayoutParams2.height;
                        int i6 = marginLayoutParams.topMargin;
                        if (i5 != i6 || marginLayoutParams2.leftMargin != iB || marginLayoutParams2.rightMargin != iC) {
                            marginLayoutParams2.height = i6;
                            marginLayoutParams2.leftMargin = iB;
                            marginLayoutParams2.rightMargin = iC;
                            s7.N.setLayoutParams(marginLayoutParams2);
                        }
                    }
                } else {
                    View view3 = new View(context);
                    s7.N = view3;
                    view3.setVisibility(8);
                    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, marginLayoutParams.topMargin, 51);
                    layoutParams.leftMargin = iB;
                    layoutParams.rightMargin = iC;
                    s7.L.addView(s7.N, -1, layoutParams);
                }
                View view4 = s7.N;
                boolean z5 = view4 != null;
                if (z5 && view4.getVisibility() != 0) {
                    View view5 = s7.N;
                    view5.setBackgroundColor((view5.getWindowSystemUiVisibility() & 8192) != 0 ? context.getColor(R.color.abc_decor_view_status_guard_light) : context.getColor(R.color.abc_decor_view_status_guard));
                }
                if (!s7.S && z5) {
                    iD2 = 0;
                }
                z2 = z3;
                z = z5;
                i = 0;
            } else {
                i = 0;
                if (marginLayoutParams.topMargin != 0) {
                    marginLayoutParams.topMargin = 0;
                    z = false;
                    z2 = true;
                } else {
                    z = false;
                    z2 = false;
                }
            }
            if (z2) {
                s7.G.setLayoutParams(marginLayoutParams);
            }
        }
        View view6 = s7.N;
        if (view6 != null) {
            view6.setVisibility(z ? i : 8);
        }
        if (iD != iD2) {
            int iB2 = kl0B.b();
            int iC2 = kl0B.c();
            int iA = kl0B.a();
            int i7 = Build.VERSION.SDK_INT;
            AbstractC3124zl0 c3029yl0 = i7 >= 34 ? new C3029yl0(kl0B) : i7 >= 31 ? new C2934xl0(kl0B) : i7 >= 30 ? new C2839wl0(kl0B) : i7 >= 29 ? new C2744vl0(kl0B) : new C2649ul0(kl0B);
            c3029yl0.g(LH.b(iB2, iD2, iC2, iA));
            kl0B = c3029yl0.b();
        }
        WeakHashMap weakHashMap2 = Oj0.a;
        WindowInsets windowInsetsF = kl0B.f();
        if (windowInsetsF == null) {
            return kl0B;
        }
        WindowInsets windowInsetsB = Ej0.b(view, windowInsetsF);
        return !windowInsetsB.equals(windowInsetsF) ? Kl0.g(view, windowInsetsB) : kl0B;
    }

    @Override // o.InterfaceC0998dP
    public boolean k(CO co) {
        Window.Callback callback;
        switch (this.l) {
            case 2:
                Window.Callback callback2 = this.m.w.getCallback();
                if (callback2 != null) {
                    callback2.onMenuOpened(108, co);
                    break;
                }
                break;
            default:
                if (co == co.k()) {
                    S7 s7 = this.m;
                    if (s7.Q && (callback = s7.w.getCallback()) != null && !s7.b0) {
                        callback.onMenuOpened(108, co);
                        break;
                    }
                }
                break;
        }
        return true;
    }
}
