package com.vungle.warren.ui.view; import android.R; import android.content.Context; import android.content.ContextWrapper; import android.content.res.Resources; import android.graphics.Bitmap; import android.media.MediaPlayer; import android.net.Uri; import android.os.Build; import android.util.Log; import android.util.TypedValue; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowInsets; import android.view.WindowInsetsController; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.VideoView; import com.google.android.gms.ads.RequestConfiguration; import com.unity3d.services.core.device.MimeTypes; import com.vungle.warren.utility.ViewUtility; import java.util.HashMap; import java.util.Map; /* loaded from: classes2.dex */ public class f extends RelativeLayout { /* renamed from: w, reason: collision with root package name */ private static final String f8477w = "f"; /* renamed from: a, reason: collision with root package name */ private Map f8478a; /* renamed from: b, reason: collision with root package name */ private final RelativeLayout.LayoutParams f8479b; /* renamed from: c, reason: collision with root package name */ private final Window f8480c; /* renamed from: d, reason: collision with root package name */ public final VideoView f8481d; /* renamed from: e, reason: collision with root package name */ private final RelativeLayout f8482e; /* renamed from: f, reason: collision with root package name */ private WebView f8483f; /* renamed from: g, reason: collision with root package name */ private final ProgressBar f8484g; /* renamed from: h, reason: collision with root package name */ private final ImageView f8485h; /* renamed from: i, reason: collision with root package name */ private final ImageView f8486i; /* renamed from: j, reason: collision with root package name */ private final ImageView f8487j; /* renamed from: k, reason: collision with root package name */ private final ImageView f8488k; /* renamed from: l, reason: collision with root package name */ private l f8489l; /* renamed from: m, reason: collision with root package name */ private com.vungle.warren.ui.view.k f8490m; /* renamed from: n, reason: collision with root package name */ private MediaPlayer.OnPreparedListener f8491n; /* renamed from: o, reason: collision with root package name */ private MediaPlayer.OnErrorListener f8492o; /* renamed from: p, reason: collision with root package name */ private MediaPlayer.OnCompletionListener f8493p; /* renamed from: q, reason: collision with root package name */ private int f8494q; /* renamed from: r, reason: collision with root package name */ private GestureDetector f8495r; /* renamed from: s, reason: collision with root package name */ private Runnable f8496s; /* renamed from: t, reason: collision with root package name */ private GestureDetector.SimpleOnGestureListener f8497t; /* renamed from: u, reason: collision with root package name */ ViewTreeObserver.OnGlobalLayoutListener f8498u; /* renamed from: v, reason: collision with root package name */ private View.OnClickListener f8499v; class a implements Runnable { a() { } @Override // java.lang.Runnable public void run() { f.this.r(); } } class b extends GestureDetector.SimpleOnGestureListener { b() { } @Override // android.view.GestureDetector.SimpleOnGestureListener, android.view.GestureDetector.OnDoubleTapListener public boolean onSingleTapConfirmed(MotionEvent motionEvent) { f.this.f8499v.onClick(f.this.f8482e); return true; } } class c implements View.OnTouchListener { c() { } @Override // android.view.View.OnTouchListener public boolean onTouch(View view, MotionEvent motionEvent) { f.this.f8495r.onTouchEvent(motionEvent); return true; } } class d implements MediaPlayer.OnPreparedListener { d() { } @Override // android.media.MediaPlayer.OnPreparedListener public void onPrepared(MediaPlayer mediaPlayer) { if (Build.VERSION.SDK_INT >= 26) { mediaPlayer.seekTo(f.this.f8494q, 3); } if (f.this.f8491n != null) { f.this.f8491n.onPrepared(mediaPlayer); } f.this.f8485h.setVisibility(0); } } class e implements MediaPlayer.OnErrorListener { e() { } @Override // android.media.MediaPlayer.OnErrorListener public boolean onError(MediaPlayer mediaPlayer, int i10, int i11) { if (f.this.f8492o != null) { return f.this.f8492o.onError(mediaPlayer, i10, i11); } return false; } } /* renamed from: com.vungle.warren.ui.view.f$f, reason: collision with other inner class name */ class C0126f implements MediaPlayer.OnCompletionListener { C0126f() { } @Override // android.media.MediaPlayer.OnCompletionListener public void onCompletion(MediaPlayer mediaPlayer) { if (f.this.f8493p != null) { f.this.f8493p.onCompletion(mediaPlayer); } f.this.f8485h.setEnabled(false); } } class g implements View.OnTouchListener { g() { } @Override // android.view.View.OnTouchListener public boolean onTouch(View view, MotionEvent motionEvent) { if (f.this.f8490m != null) { return f.this.f8490m.a(motionEvent); } return false; } } class h implements ViewTreeObserver.OnGlobalLayoutListener { h() { } @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener public void onGlobalLayout() { f.this.A(); f.this.r(); } } class i implements View.OnClickListener { i() { } @Override // android.view.View.OnClickListener public void onClick(View view) { if (f.this.f8489l != null) { f.this.f8489l.a(f.this.u(view)); } } } public static class j extends ContextWrapper { public j(Context context) { super(context); } @Override // android.content.ContextWrapper, android.content.Context public Object getSystemService(String str) { return MimeTypes.BASE_TYPE_AUDIO.equals(str) ? getApplicationContext().getSystemService(str) : super.getSystemService(str); } } private static class k implements Runnable { /* renamed from: a, reason: collision with root package name */ private WebView f8509a; k(WebView webView) { this.f8509a = webView; } @Override // java.lang.Runnable public void run() { this.f8509a.stopLoading(); this.f8509a.setWebViewClient(null); if (Build.VERSION.SDK_INT >= 29) { this.f8509a.setWebViewRenderProcessClient(null); } this.f8509a.loadData(RequestConfiguration.MAX_AD_CONTENT_RATING_UNSPECIFIED, null, null); this.f8509a.destroy(); } } public interface l { void a(int i10); } public f(Context context, Window window) { super(context); this.f8478a = new HashMap(); this.f8497t = new b(); this.f8498u = new h(); this.f8499v = new i(); this.f8480c = window; Resources resources = getResources(); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(-1, -1); this.f8479b = layoutParams; setLayoutParams(layoutParams); this.f8496s = new a(); VideoView videoView = new VideoView(new j(context)); this.f8481d = videoView; RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(-1, -1); layoutParams2.addRule(13); videoView.setLayoutParams(layoutParams2); RelativeLayout relativeLayout = new RelativeLayout(context); this.f8482e = relativeLayout; relativeLayout.setTag("videoViewContainer"); relativeLayout.setLayoutParams(layoutParams); relativeLayout.addView(videoView, layoutParams2); addView(relativeLayout, layoutParams); this.f8495r = new GestureDetector(context, this.f8497t); WebView c10 = ViewUtility.c(context); this.f8483f = c10; c10.setLayoutParams(layoutParams); this.f8483f.setTag("webView"); addView(this.f8483f, layoutParams); ProgressBar progressBar = new ProgressBar(context, null, R.attr.progressBarStyleHorizontal); this.f8484g = progressBar; RelativeLayout.LayoutParams layoutParams3 = new RelativeLayout.LayoutParams(-1, (int) TypedValue.applyDimension(1, 4.0f, resources.getDisplayMetrics())); layoutParams3.addRule(12); progressBar.setLayoutParams(layoutParams3); progressBar.setMax(100); progressBar.setIndeterminate(false); progressBar.setVisibility(4); addView(progressBar); int applyDimension = (int) TypedValue.applyDimension(1, 24.0f, resources.getDisplayMetrics()); RelativeLayout.LayoutParams layoutParams4 = new RelativeLayout.LayoutParams(applyDimension, applyDimension); int applyDimension2 = (int) TypedValue.applyDimension(1, 12.0f, resources.getDisplayMetrics()); layoutParams4.setMargins(applyDimension2, applyDimension2, applyDimension2, applyDimension2); ImageView imageView = new ImageView(context); this.f8485h = imageView; imageView.setImageBitmap(ViewUtility.b(ViewUtility.Asset.unMute, context)); imageView.setLayoutParams(layoutParams4); imageView.setVisibility(8); addView(imageView); RelativeLayout.LayoutParams layoutParams5 = new RelativeLayout.LayoutParams(applyDimension, applyDimension); layoutParams5.setMargins(applyDimension2, applyDimension2, applyDimension2, applyDimension2); ImageView imageView2 = new ImageView(context); this.f8486i = imageView2; imageView2.setTag("closeButton"); imageView2.setImageBitmap(ViewUtility.b(ViewUtility.Asset.close, context)); layoutParams5.addRule(11); imageView2.setLayoutParams(layoutParams5); imageView2.setVisibility(8); addView(imageView2); RelativeLayout.LayoutParams layoutParams6 = new RelativeLayout.LayoutParams(applyDimension, applyDimension); layoutParams6.addRule(12); layoutParams6.addRule(11); layoutParams6.setMargins(applyDimension2, applyDimension2, applyDimension2, applyDimension2); ImageView imageView3 = new ImageView(context); this.f8487j = imageView3; imageView3.setTag("ctaOverlay"); imageView3.setLayoutParams(layoutParams6); imageView3.setImageBitmap(ViewUtility.b(ViewUtility.Asset.cta, getContext())); imageView3.setVisibility(8); addView(imageView3); RelativeLayout.LayoutParams layoutParams7 = new RelativeLayout.LayoutParams(applyDimension, applyDimension); layoutParams7.addRule(12); layoutParams7.addRule(9); layoutParams7.setMargins(applyDimension2, applyDimension2, applyDimension2, applyDimension2); ImageView imageView4 = new ImageView(context); this.f8488k = imageView4; imageView4.setLayoutParams(layoutParams7); imageView4.setVisibility(8); addView(imageView4); o(); y(); } /* JADX INFO: Access modifiers changed from: private */ public void A() { getViewTreeObserver().removeOnGlobalLayoutListener(this.f8498u); } private void n(View view, int i10) { this.f8478a.put(view, Integer.valueOf(i10)); view.setOnClickListener(this.f8499v); } private void o() { n(this.f8486i, 1); n(this.f8487j, 2); n(this.f8485h, 3); n(this.f8488k, 4); this.f8478a.put(this.f8482e, 5); this.f8482e.setOnTouchListener(new c()); this.f8481d.setOnPreparedListener(new d()); this.f8481d.setOnErrorListener(new e()); this.f8481d.setOnCompletionListener(new C0126f()); WebView webView = this.f8483f; if (webView != null) { webView.setOnTouchListener(new g()); } } /* JADX INFO: Access modifiers changed from: private */ public void r() { WindowInsetsController insetsController; int statusBars; int navigationBars; if (Build.VERSION.SDK_INT < 30) { this.f8480c.getDecorView().setSystemUiVisibility(5894); return; } this.f8480c.setDecorFitsSystemWindows(false); insetsController = this.f8480c.getInsetsController(); if (insetsController != null) { statusBars = WindowInsets.Type.statusBars(); navigationBars = WindowInsets.Type.navigationBars(); insetsController.hide(statusBars | navigationBars); insetsController.setSystemBarsBehavior(2); } } /* JADX INFO: Access modifiers changed from: private */ public int u(View view) { Integer num = (Integer) this.f8478a.get(view); if (num == null) { return -1; } return num.intValue(); } private void y() { WebView webView = this.f8483f; if (webView != null) { webView.getSettings().setMediaPlaybackRequiresUserGesture(false); this.f8483f.setVisibility(8); } this.f8482e.setVisibility(8); } public void B() { WebView webView = this.f8483f; if (webView != null) { webView.onResume(); } post(this.f8496s); } public void C() { getViewTreeObserver().addOnGlobalLayoutListener(this.f8498u); } public void D(int i10, float f10) { this.f8484g.setMax((int) f10); this.f8484g.setProgress(i10); } public void E(boolean z10) { this.f8486i.setVisibility(z10 ? 0 : 8); } public void F(String str) { if (this.f8483f == null) { return; } Log.d(f8477w, "loadJs: " + str); this.f8483f.loadUrl(str); this.f8483f.setVisibility(0); this.f8482e.setVisibility(8); this.f8482e.setOnClickListener(null); this.f8484g.setVisibility(8); this.f8486i.setVisibility(8); this.f8485h.setVisibility(8); this.f8487j.setVisibility(8); this.f8488k.setVisibility(8); } public boolean G(int i10) { if (!this.f8481d.isPlaying()) { this.f8481d.requestFocus(); this.f8494q = i10; if (Build.VERSION.SDK_INT < 26) { this.f8481d.seekTo(i10); } this.f8481d.start(); } return this.f8481d.isPlaying(); } public void H() { this.f8481d.stopPlayback(); } public void I() { this.f8480c.setFlags(1024, 1024); this.f8480c.getDecorView().setBackgroundColor(-16777216); } public int getCurrentVideoPosition() { return this.f8481d.getCurrentPosition(); } public String getUrl() { WebView webView = this.f8483f; if (webView == null) { return null; } return webView.getUrl(); } public int getVideoDuration() { return this.f8481d.getDuration(); } WebView getWebView() { return this.f8483f; } public void p(long j10) { WebView webView = this.f8483f; if (webView == null) { return; } webView.removeJavascriptInterface("Android"); this.f8483f.setWebChromeClient(null); removeView(this.f8483f); this.f8483f.removeAllViews(); if (j10 <= 0) { new k(this.f8483f).run(); } else { new com.vungle.warren.utility.k().b(new k(this.f8483f), j10); } this.f8483f = null; } public boolean q() { return this.f8483f != null; } public boolean s() { return this.f8481d.isPlaying(); } public void setCtaEnabled(boolean z10) { this.f8487j.setVisibility(z10 ? 0 : 8); } public void setMuted(boolean z10) { Bitmap b10 = ViewUtility.b(ViewUtility.Asset.mute, getContext()); Bitmap b11 = ViewUtility.b(ViewUtility.Asset.unMute, getContext()); ImageView imageView = this.f8485h; if (!z10) { b10 = b11; } imageView.setImageBitmap(b10); } public void setOnCompletionListener(MediaPlayer.OnCompletionListener onCompletionListener) { this.f8493p = onCompletionListener; } public void setOnErrorListener(MediaPlayer.OnErrorListener onErrorListener) { this.f8492o = onErrorListener; } public void setOnItemClickListener(l lVar) { this.f8489l = lVar; } public void setOnPreparedListener(MediaPlayer.OnPreparedListener onPreparedListener) { this.f8491n = onPreparedListener; } public void setOnViewTouchListener(com.vungle.warren.ui.view.k kVar) { this.f8490m = kVar; } public void t(WebViewClient webViewClient, l8.d dVar) { WebView webView = this.f8483f; if (webView == null) { return; } o.a(webView); this.f8483f.setWebViewClient(webViewClient); this.f8483f.addJavascriptInterface(dVar, "Android"); } public void v() { this.f8481d.pause(); } public void w() { WebView webView = this.f8483f; if (webView != null) { webView.onPause(); } A(); removeCallbacks(this.f8496s); } public void x(Uri uri, int i10) { this.f8482e.setVisibility(0); this.f8481d.setVideoURI(uri); this.f8488k.setImageBitmap(ViewUtility.b(ViewUtility.Asset.privacy, getContext())); this.f8488k.setVisibility(0); this.f8484g.setVisibility(0); this.f8484g.setMax(this.f8481d.getDuration()); G(i10); } public void z(long j10) { this.f8481d.stopPlayback(); this.f8481d.setOnCompletionListener(null); this.f8481d.setOnErrorListener(null); this.f8481d.setOnPreparedListener(null); this.f8481d.suspend(); p(j10); } }