package com.bytedance.sdk.openadsdk.component.reward.fm;

import android.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Build;
import android.view.View;
import android.view.Window;
import com.bytedance.sdk.component.utils.mq;
import com.bytedance.sdk.component.utils.wey;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.utils.zan;

/* JADX INFO: loaded from: classes2.dex */
public class duv {
    private boolean ajl;
    protected int fm;
    private int jnr;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private Activity f6911lb;
    private boolean ro;
    private lse yz;

    public static abstract class fm implements View.OnLayoutChangeListener {
        private int fm;
        private int ro;

        private fm() {
        }

        public abstract void fm(int i10, int i11);

        @Override // android.view.View.OnLayoutChangeListener
        public void onLayoutChange(View view, int i10, int i11, int i12, int i13, int i14, int i15, int i16, int i17) {
            int i18 = i12 - i10;
            int i19 = i13 - i11;
            if (i18 == this.fm && i19 == this.ro) {
                return;
            }
            this.fm = i18;
            this.ro = i19;
            fm(i18, i19);
        }
    }

    public duv(com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar) {
        this(roVar.xgn, roVar.ro, roVar.kwx, roVar.daz, roVar.vvj, roVar);
    }

    private static boolean fm(int i10, int i11) {
        return i10 == 2 && i11 == 2;
    }

    private float lb() {
        return zan.lb(this.f6911lb, zan.dsz(this.f6911lb));
    }

    private float[] ro(int i10) {
        float fYz = yz();
        float fLb = lb();
        int i11 = this.jnr;
        if ((i11 == 1) != (fYz > fLb)) {
            float f10 = fYz + fLb;
            fLb = f10 - fLb;
            fYz = f10 - fLb;
        }
        if (i11 == 1) {
            fYz -= i10;
        } else {
            fLb -= i10;
        }
        return new float[]{fLb, fYz};
    }

    private float yz() {
        return zan.lb(this.f6911lb, zan.duv(this.f6911lb));
    }

    public duv(Activity activity, lse lseVar, int i10, boolean z10, boolean z11, com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar) {
        this.fm = 0;
        this.f6911lb = activity;
        this.yz = lseVar;
        this.ro = z10;
        this.ajl = z11;
        if (roVar != null) {
            fm(roVar);
            i10 = roVar.kwx;
        }
        this.jnr = i10;
        try {
            this.fm = zan.lb(activity, zan.fm());
            if (!activity.getWindow().hasFeature(1)) {
                activity.requestWindowFeature(1);
            }
            activity.getWindow().addFlags(16777344);
            if (this.jnr == 2 || !zan.lb(activity)) {
                activity.getWindow().addFlags(1024);
            }
        } catch (Throwable unused) {
        }
    }

    public static class ro {
        private fm fm;

        public void fm(Activity activity) {
            Window window;
            if (this.fm == null || activity == null || (window = activity.getWindow()) == null) {
                return;
            }
            window.getDecorView().removeOnLayoutChangeListener(this.fm);
            this.fm = null;
        }

        public void fm(final Activity activity, final int i10, final float f10, final boolean z10) {
            if (this.fm != null) {
                return;
            }
            try {
                final boolean z11 = com.bytedance.sdk.openadsdk.core.gof.yz().lz() == 1;
                final boolean zLb = zan.lb(activity);
                if (zLb || z11) {
                    this.fm = new fm() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.duv.ro.1
                        boolean fm;

                        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
                        {
                            super();
                        }

                        private void ro() {
                            try {
                                int iLb = duv.lb(activity, i10);
                                View decorView = activity.getWindow().getDecorView();
                                if (iLb == 0) {
                                    int[] iArrRo = duv.ro(activity, decorView, i10, zLb, z11);
                                    if (iArrRo[4] == 1) {
                                        this.fm = duv.ro(decorView, iArrRo[0], iArrRo[1], iArrRo[2], iArrRo[3], f10);
                                    }
                                } else if (this.fm) {
                                    decorView.setPadding(decorView.getPaddingLeft(), 0, decorView.getPaddingRight(), decorView.getPaddingBottom());
                                    this.fm = false;
                                }
                            } catch (Throwable unused) {
                            }
                        }

                        @Override // com.bytedance.sdk.openadsdk.component.reward.fm.duv.fm
                        public void fm(int i11, int i12) {
                            if (z10) {
                                ro();
                            } else {
                                fm();
                            }
                        }

                        /* JADX WARN: Removed duplicated region for block: B:28:0x00a7 A[Catch: all -> 0x00c4, TryCatch #0 {all -> 0x00c4, blocks: (B:2:0x0000, B:4:0x0005, B:6:0x0013, B:8:0x0046, B:10:0x005e, B:12:0x0067, B:14:0x0075, B:15:0x0079, B:26:0x00a1, B:28:0x00a7, B:29:0x00ac, B:31:0x00b4, B:16:0x007c, B:18:0x0080, B:20:0x008e, B:22:0x0092, B:23:0x0098, B:25:0x009c, B:33:0x00ba, B:35:0x00be, B:7:0x002d), top: B:38:0x0000 }] */
                        /* JADX WARN: Removed duplicated region for block: B:31:0x00b4 A[Catch: all -> 0x00c4, TryCatch #0 {all -> 0x00c4, blocks: (B:2:0x0000, B:4:0x0005, B:6:0x0013, B:8:0x0046, B:10:0x005e, B:12:0x0067, B:14:0x0075, B:15:0x0079, B:26:0x00a1, B:28:0x00a7, B:29:0x00ac, B:31:0x00b4, B:16:0x007c, B:18:0x0080, B:20:0x008e, B:22:0x0092, B:23:0x0098, B:25:0x009c, B:33:0x00ba, B:35:0x00be, B:7:0x002d), top: B:38:0x0000 }] */
                        /* JADX WARN: Removed duplicated region for block: B:39:? A[RETURN, SYNTHETIC] */
                        /*
                            Code decompiled incorrectly, please refer to instructions dump.
                        */
                        private void fm() {
                            int iAbs;
                            float fFm;
                            try {
                                if (i10 == 2 && activity.getResources().getConfiguration().orientation == 2) {
                                    iAbs = Math.abs(zan.dsz(activity) - activity.getWindow().getDecorView().getWidth());
                                } else {
                                    iAbs = Math.abs(zan.duv(activity) - activity.getWindow().getDecorView().getHeight());
                                }
                                View decorView = activity.getWindow().getDecorView();
                                int paddingLeft = decorView.getPaddingLeft();
                                int paddingRight = decorView.getPaddingRight();
                                int paddingBottom = decorView.getPaddingBottom();
                                if (iAbs != 0) {
                                    if (this.fm) {
                                        decorView.setPadding(paddingLeft, 0, paddingRight, paddingBottom);
                                        this.fm = false;
                                        return;
                                    }
                                    return;
                                }
                                int paddingTop = decorView.getPaddingTop();
                                if (i10 == 1 && activity.getResources().getConfiguration().orientation == 1) {
                                    fFm = zan.fm();
                                } else {
                                    if (i10 == 2 && activity.getResources().getConfiguration().orientation == 2) {
                                        if (zLb) {
                                            paddingLeft += (int) zan.fm();
                                        }
                                        if (z11) {
                                            fFm = zan.fm();
                                        }
                                    }
                                    if (decorView.isAttachedToWindow()) {
                                        decorView.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
                                        this.fm = true;
                                    }
                                    if (f10 != 100.0f) {
                                        decorView.setBackgroundColor(-16777216);
                                        return;
                                    }
                                    return;
                                }
                                paddingTop += (int) fFm;
                                if (decorView.isAttachedToWindow()) {
                                }
                                if (f10 != 100.0f) {
                                }
                            } catch (Throwable unused) {
                            }
                        }
                    };
                    activity.getWindow().getDecorView().addOnLayoutChangeListener(this.fm);
                }
            } catch (Exception unused) {
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static int lb(Activity activity, int i10) {
        int i11 = activity.getResources().getConfiguration().orientation;
        View decorView = activity.getWindow().getDecorView();
        if (fm(i10, i11)) {
            return Math.abs(zan.dsz(activity) - decorView.getWidth());
        }
        return Math.abs(zan.duv(activity) - decorView.getHeight());
    }

    @SuppressLint({"SourceLockedOrientationActivity"})
    private void ro() {
        if (this.jnr != 2) {
            ro(this.f6911lb, 1);
        } else if (this.ajl) {
            ro(this.f6911lb, 8);
        } else {
            ro(this.f6911lb, 0);
        }
    }

    private static void ro(Activity activity, int i10) {
        if (activity.getRequestedOrientation() == i10) {
            return;
        }
        int i11 = activity.getResources().getConfiguration().orientation;
        activity.setRequestedOrientation(i10);
    }

    public void fm(mq mqVar) {
        if (mqVar == null) {
            return;
        }
        mqVar.postDelayed(new Runnable() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.duv.1
            @Override // java.lang.Runnable
            public void run() {
                View viewFindViewById;
                try {
                    View decorView = duv.this.f6911lb.getWindow().getDecorView();
                    if (decorView == null || (viewFindViewById = decorView.findViewById(R.id.statusBarBackground)) == null) {
                        return;
                    }
                    viewFindViewById.setVisibility(8);
                } catch (Exception unused) {
                }
            }
        }, 300L);
    }

    private void fm(com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar) {
        roVar.bkb = roVar.ro.lvj();
        roVar.kwx = fm(roVar.xgn, roVar.ro);
    }

    public static int fm(Activity activity, lse lseVar) {
        if (26 == Build.VERSION.SDK_INT) {
            return activity.getResources().getConfiguration().orientation == 1 ? 1 : 2;
        }
        return lseVar.nnq();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static boolean ro(View view, int i10, int i11, int i12, int i13, float f10) {
        if (!view.isAttachedToWindow()) {
            return false;
        }
        view.setPadding(i10, i11, i12, i13);
        if (f10 != 100.0f) {
            return true;
        }
        view.setBackgroundColor(-16777216);
        return true;
    }

    /* JADX WARN: Removed duplicated region for block: B:36:0x009c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void fm(com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar, boolean z10) {
        float fMin;
        float fMax;
        int iMax;
        int iMax2;
        int i10;
        int i11 = Build.VERSION.SDK_INT;
        if (i11 != 26) {
            if (i11 == 27) {
                try {
                    ro();
                } catch (Throwable unused) {
                }
            } else {
                ro();
            }
        }
        float fLb = lb();
        float fYz = yz();
        if (this.jnr == 2) {
            fMin = Math.max(fLb, fYz);
            fMax = Math.min(fLb, fYz);
        } else {
            fMin = Math.min(fLb, fYz);
            fMax = Math.max(fLb, fYz);
        }
        int iLb = zan.lb(this.f6911lb, zan.fm());
        if (this.jnr != 2) {
            if (zan.lb(this.f6911lb)) {
                fMax -= iLb;
            }
        } else if (zan.lb(this.f6911lb)) {
            fMin -= iLb;
        }
        if (z10) {
            roVar.lmk = (int) fMin;
            roVar.mpp = (int) fMax;
            return;
        }
        int i12 = 20;
        if (this.jnr != 2) {
            float f10 = roVar.bkb;
            if (f10 == 0.0f || f10 == 100.0f) {
                i12 = 0;
                iMax = 0;
                iMax2 = 0;
                i10 = 0;
            } else {
                iMax2 = (int) Math.max((fMax - (((fMin - 20.0f) - 20.0f) / f10)) / 2.0f, 0.0f);
                i10 = iMax2;
                iMax = 20;
            }
        } else {
            float f11 = roVar.bkb;
            if (f11 != 0.0f && f11 != 100.0f) {
                iMax = (int) Math.max((fMin - (((fMax - 20.0f) - 20.0f) * f11)) / 2.0f, 0.0f);
                iMax2 = 20;
                i10 = 20;
                i12 = iMax;
            }
        }
        float f12 = i12;
        float f13 = iMax;
        roVar.lmk = (int) ((fMin - f12) - f13);
        float f14 = iMax2;
        float f15 = i10;
        roVar.mpp = (int) ((fMax - f14) - f15);
        com.bytedance.sdk.openadsdk.activity.single.wu wuVar = roVar.zow;
        if (wuVar == null || wuVar.vt == 0) {
            this.f6911lb.getWindow().getDecorView().setPadding(zan.ro(this.f6911lb, f12), zan.ro(this.f6911lb, f14), zan.ro(this.f6911lb, f13), zan.ro(this.f6911lb, f15));
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static int[] ro(Activity activity, View view, int i10, boolean z10, boolean z11) {
        int paddingLeft;
        int paddingBottom;
        int paddingTop;
        int paddingRight;
        float fFm;
        int[] iArr = new int[5];
        int i11 = 1;
        int i12 = 0;
        if (activity == null || view == null) {
            if (view != null) {
                paddingLeft = view.getPaddingLeft();
                paddingTop = view.getPaddingTop();
                paddingRight = view.getPaddingRight();
                paddingBottom = view.getPaddingBottom();
            } else {
                paddingLeft = 0;
                paddingBottom = 0;
                paddingTop = 0;
                paddingRight = 0;
            }
            iArr[0] = paddingLeft;
            iArr[1] = paddingTop;
            iArr[2] = paddingRight;
            iArr[3] = paddingBottom;
            iArr[4] = 0;
            return iArr;
        }
        int i13 = activity.getResources().getConfiguration().orientation;
        int paddingLeft2 = view.getPaddingLeft();
        int paddingTop2 = view.getPaddingTop();
        int paddingRight2 = view.getPaddingRight();
        int paddingBottom2 = view.getPaddingBottom();
        if (i10 != 1) {
            if (i10 == 2) {
                if (i13 == 2) {
                    if (z10) {
                        paddingLeft2 += (int) zan.fm();
                        i12 = 1;
                    }
                    if (z11) {
                        fFm = zan.fm();
                        paddingTop2 += (int) fFm;
                    }
                } else {
                    paddingTop2 += (int) zan.fm();
                }
            }
            i11 = i12;
        } else if (i13 == 1) {
            fFm = zan.fm();
            paddingTop2 += (int) fFm;
        } else {
            paddingLeft2 += (int) zan.fm();
            i11 = i12;
        }
        return new int[]{paddingLeft2, paddingTop2, paddingRight2, paddingBottom2, i11};
    }

    public void fm(boolean z10) {
        int i10 = Build.VERSION.SDK_INT;
        if (i10 != 26) {
            if (i10 == 27) {
                try {
                    ro();
                } catch (Throwable unused) {
                }
            } else {
                ro();
            }
        }
    }

    public float[] fm(int i10) {
        return fm(i10, this.f6911lb, this.yz);
    }

    public float[] fm(int i10, Activity activity, lse lseVar) {
        float[] fArrRo = new float[2];
        View decorView = activity.getWindow().getDecorView();
        int paddingLeft = decorView.getPaddingLeft();
        int paddingTop = decorView.getPaddingTop();
        if (this.ro && paddingLeft == 0 && paddingTop == 0 && lb(activity, i10) == 0) {
            int[] iArrRo = ro(activity, decorView, i10, zan.lb(activity), com.bytedance.sdk.openadsdk.core.gof.yz().lz() == 1);
            int i11 = iArrRo[0];
            paddingTop = iArrRo[1];
            paddingLeft = i11;
        }
        int i12 = Build.VERSION.SDK_INT;
        if (i12 >= 35 && lseVar.lvj() == 100.0f) {
            fArrRo[0] = decorView.getWidth() - paddingLeft;
            fArrRo[1] = decorView.getHeight() - paddingTop;
        } else {
            fArrRo[0] = decorView.getWidth() - (paddingLeft * 2);
            fArrRo[1] = decorView.getHeight() - (paddingTop * 2);
        }
        fArrRo[0] = zan.lb(activity, fArrRo[0]);
        float fLb = zan.lb(activity, fArrRo[1]);
        fArrRo[1] = fLb;
        if (fArrRo[0] < 10.0f || fLb < 10.0f) {
            fArrRo = ro(this.fm);
        }
        if (i12 != 26 && i12 != 27) {
            if (activity.getResources() != null && activity.getResources().getConfiguration() != null) {
                if ((activity.getResources().getConfiguration().orientation == 2 ? 2 : 1) != i10) {
                    if (i10 == 2) {
                        float f10 = fArrRo[0];
                        float f11 = fArrRo[1];
                        if (f10 < f11) {
                            fArrRo[1] = f10;
                            fArrRo[0] = f11;
                        }
                    } else {
                        float f12 = fArrRo[0];
                        float f13 = fArrRo[1];
                        if (f12 > f13) {
                            fArrRo[1] = f12;
                            fArrRo[0] = f13;
                        }
                    }
                }
            }
            float f14 = fArrRo[0];
            float f15 = fArrRo[1];
        }
        return fArrRo;
    }

    public static float[] fm(int i10, Activity activity, lse lseVar, boolean z10) {
        float[] fArr = new float[2];
        View decorView = activity.getWindow().getDecorView();
        int paddingLeft = decorView.getPaddingLeft();
        int paddingTop = decorView.getPaddingTop();
        if (z10 && paddingLeft == 0 && paddingTop == 0 && lb(activity, i10) == 0) {
            int[] iArrRo = ro(activity, decorView, i10, zan.lb(activity), com.bytedance.sdk.openadsdk.core.gof.yz().lz() == 1);
            paddingLeft = iArrRo[0];
            paddingTop = iArrRo[1];
        }
        int i11 = Build.VERSION.SDK_INT;
        if (i11 >= 35 && lseVar.lvj() == 100.0f) {
            fArr[0] = decorView.getWidth() - paddingLeft;
            fArr[1] = decorView.getHeight() - paddingTop;
        } else {
            fArr[0] = decorView.getWidth() - (paddingLeft * 2);
            fArr[1] = decorView.getHeight() - (paddingTop * 2);
        }
        fArr[0] = zan.lb(activity, fArr[0]);
        fArr[1] = zan.lb(activity, fArr[1]);
        if (i11 != 26 && i11 != 27 && activity.getResources() != null && activity.getResources().getConfiguration() != null) {
            if ((activity.getResources().getConfiguration().orientation == 2 ? 2 : 1) != i10) {
                if (i10 == 2) {
                    float f10 = fArr[0];
                    float f11 = fArr[1];
                    if (f10 < f11) {
                        fArr[1] = f10;
                        fArr[0] = f11;
                    }
                } else {
                    float f12 = fArr[0];
                    float f13 = fArr[1];
                    if (f12 > f13) {
                        fArr[1] = f12;
                        fArr[0] = f13;
                    }
                }
            }
        }
        return fArr;
    }

    public void fm() {
        zan.fm(this.f6911lb);
        this.f6911lb.getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.duv.2
            @Override // android.view.View.OnSystemUiVisibilityChangeListener
            public void onSystemUiVisibilityChange(int i10) {
                if (i10 == 0) {
                    try {
                        if (duv.this.f6911lb.isFinishing()) {
                            return;
                        }
                        duv.this.f6911lb.getWindow().getDecorView().postDelayed(new Runnable() { // from class: com.bytedance.sdk.openadsdk.component.reward.fm.duv.2.1
                            @Override // java.lang.Runnable
                            public void run() {
                                zan.fm(duv.this.f6911lb);
                            }
                        }, 2500L);
                    } catch (Exception e10) {
                        wey.lb("TTAD.RFSM", e10.getMessage());
                    }
                }
            }
        });
    }
}
