package xyz.stream.view;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.FrameLayout;
import android.widget.PopupWindow;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Objects;

/* JADX INFO: loaded from: classes3.dex */
public class MaskOverLay {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static volatile MaskOverLay f36303b;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final HashMap f36304a = new HashMap();

    public static MaskOverLay getInstance() {
        if (f36303b == null) {
            synchronized (MaskOverLay.class) {
                try {
                    if (f36303b == null) {
                        f36303b = new MaskOverLay();
                    }
                } finally {
                }
            }
        }
        return f36303b;
    }

    public void backgroundAlpha(Object obj, float f10) {
        View contentView;
        try {
            View view = null;
            Window window = obj instanceof Activity ? ((Activity) obj).getWindow() : obj instanceof Dialog ? ((Dialog) obj).getWindow() : ((obj instanceof PopupWindow) && (contentView = ((PopupWindow) obj).getContentView()) != null && (contentView.getContext() instanceof Activity)) ? ((Activity) contentView.getContext()).getWindow() : null;
            if (window == null) {
                return;
            }
            ViewGroup viewGroup = (ViewGroup) window.getDecorView();
            HashMap map = this.f36304a;
            if (map.containsKey(Integer.valueOf(window.hashCode()))) {
                WeakReference weakReference = (WeakReference) map.get(Integer.valueOf(window.hashCode()));
                Objects.requireNonNull(weakReference);
                view = (View) weakReference.get();
            }
            if (f10 >= 1.0f) {
                if (view != null) {
                    viewGroup.removeView(view);
                    map.remove(Integer.valueOf(window.hashCode()));
                    return;
                }
                return;
            }
            if (view == null) {
                View view2 = new View(window.getContext());
                view2.setLayoutParams(new FrameLayout.LayoutParams(UiUtils.dp2px(1920.0f), UiUtils.dp2px(1080.0f)));
                view2.setBackgroundColor(Color.argb((int) ((1.0f - f10) * 255.0f), 0, 0, 0));
                view2.setClickable(true);
                viewGroup.addView(view2);
                map.put(Integer.valueOf(window.hashCode()), new WeakReference(view2));
            }
        } catch (Exception unused) {
        }
    }
}
