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

import android.content.Context;
import android.graphics.Outline;
import android.view.View;
import android.view.ViewOutlineProvider;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;

/* JADX INFO: loaded from: classes2.dex */
public class ro extends com.bytedance.sdk.openadsdk.core.ajl.lb {
    private com.bytedance.sdk.openadsdk.activity.single.wu ajl;
    private final boolean fm;
    private float jnr;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private com.bytedance.sdk.openadsdk.core.ajl.lb f6989lb;
    private final boolean ro;
    private boolean wsy;
    private float yz;

    public ro(@NonNull Context context, boolean z10, boolean z11, final int i10) {
        super(context);
        this.fm = z10;
        this.ro = z11;
        if (z10) {
            setOutlineProvider(new ViewOutlineProvider() { // from class: com.bytedance.sdk.openadsdk.component.reward.view.ro.2
                @Override // android.view.ViewOutlineProvider
                public void getOutline(View view, Outline outline) {
                    outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), i10);
                }
            });
            setClipToOutline(true);
            return;
        }
        this.f6989lb = new com.bytedance.sdk.openadsdk.core.ajl.lb(context);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -1);
        layoutParams.gravity = 17;
        addView(this.f6989lb, layoutParams);
        this.f6989lb.setOutlineProvider(new ViewOutlineProvider() { // from class: com.bytedance.sdk.openadsdk.component.reward.view.ro.1
            @Override // android.view.ViewOutlineProvider
            public void getOutline(View view, Outline outline) {
                outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), i10);
            }
        });
        this.f6989lb.setClipToOutline(true);
    }

    public void fm(wu wuVar, FrameLayout.LayoutParams layoutParams) {
        com.bytedance.sdk.openadsdk.core.ajl.lb lbVar = this.f6989lb;
        if (lbVar != null) {
            lbVar.addView(wuVar, layoutParams);
        } else {
            addView(wuVar, layoutParams);
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        com.bytedance.sdk.openadsdk.activity.single.wu wuVar;
        com.bytedance.sdk.openadsdk.component.reward.fm.ro roVarHlt;
        super.onAttachedToWindow();
        if (this.wsy || (wuVar = this.ajl) == null || (roVarHlt = wuVar.hlt()) == null) {
            return;
        }
        roVarHlt.nt.ro(true);
        this.wsy = true;
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        com.bytedance.sdk.openadsdk.activity.single.wu wuVar;
        com.bytedance.sdk.openadsdk.component.reward.fm.ro roVarHlt;
        super.onDetachedFromWindow();
        if (!this.wsy || (wuVar = this.ajl) == null || (roVarHlt = wuVar.hlt()) == null) {
            return;
        }
        roVarHlt.nt.ro(false);
        this.wsy = false;
    }

    @Override // com.bytedance.sdk.openadsdk.core.ajl.lb, android.widget.FrameLayout, android.view.View
    public void onMeasure(int i10, int i11) {
        int size = View.MeasureSpec.getSize(i10);
        int size2 = View.MeasureSpec.getSize(i11);
        if (this.ro) {
            float f10 = this.yz;
            if (f10 > 0.0f) {
                int iMax = Math.max(0, (size - ((int) (size2 * f10))) / 2);
                setPadding(iMax, 0, iMax, 0);
            } else {
                float f11 = this.jnr;
                if (f11 > 0.0f) {
                    int iMax2 = Math.max(0, (size - ((int) (size * f11))) / 2);
                    setPadding(iMax2, 0, iMax2, 0);
                }
            }
        } else if (this.fm) {
            float f12 = this.yz;
            if (f12 > 0.0f) {
                i11 = View.MeasureSpec.makeMeasureSpec((int) (size / f12), 1073741824);
            } else {
                float f13 = this.jnr;
                if (f13 > 0.0f) {
                    i11 = View.MeasureSpec.makeMeasureSpec((int) (size2 * f13), 1073741824);
                }
            }
        } else {
            float f14 = this.yz;
            if (f14 > 0.0f) {
                int iMax3 = Math.max(0, (size - ((int) (size2 * f14))) / 2);
                setPadding(iMax3, 0, iMax3, 0);
            } else {
                float f15 = this.jnr;
                if (f15 > 0.0f) {
                    int iMax4 = Math.max(0, (size - ((int) (size * f15))) / 2);
                    setPadding(iMax4, 0, iMax4, 0);
                }
            }
        }
        super.onMeasure(i10, i11);
    }

    @Override // android.view.View
    public void onWindowFocusChanged(boolean z10) {
        com.bytedance.sdk.openadsdk.activity.single.wu wuVar;
        com.bytedance.sdk.openadsdk.component.reward.fm.ro roVarHlt;
        super.onWindowFocusChanged(z10);
        if (this.wsy == z10 || (wuVar = this.ajl) == null || (roVarHlt = wuVar.hlt()) == null) {
            return;
        }
        roVarHlt.nt.ro(z10);
    }

    public void setScene(com.bytedance.sdk.openadsdk.activity.single.wu wuVar) {
        this.ajl = wuVar;
    }

    public void setWidthAndHeightRatio(float f10) {
        this.yz = f10;
    }

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

    public void fm() {
        com.bytedance.sdk.openadsdk.core.ajl.lb lbVar = this.f6989lb;
        if (lbVar != null) {
            lbVar.removeAllViews();
        } else {
            removeAllViews();
        }
    }
}
