package com.applovin.exoplayer2.ui; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.os.Looper; import android.os.SystemClock; import android.util.AttributeSet; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.Nullable; import com.applovin.exoplayer2.ui.i; import com.applovin.impl.b1; import com.applovin.impl.f8; import com.applovin.impl.fo; import com.applovin.impl.qh; import com.applovin.impl.t2; import com.applovin.impl.t4; import com.applovin.impl.u5; import com.applovin.impl.ui; import com.applovin.impl.xp; import com.applovin.sdk.R; import com.mbridge.msdk.playercommon.exoplayer2.C; import java.util.Arrays; import java.util.Formatter; import java.util.Iterator; import java.util.Locale; import java.util.concurrent.CopyOnWriteArrayList; /* loaded from: classes.dex */ public class d extends FrameLayout { private final String A; private final Drawable B; private final Drawable C; private final float D; private final float E; private final String F; private final String G; private qh H; private t4 I; private boolean J; private boolean K; private boolean L; private boolean M; private int N; private int O; private int P; private boolean Q; private boolean R; private boolean S; private boolean T; private boolean U; private long V; private long[] W; private final c a; private boolean[] a0; private final CopyOnWriteArrayList b; private long[] b0; private final View c; private boolean[] c0; private final View d; private long d0; private long e0; private final View f; private long f0; private final View g; private final View h; private final View i; private final ImageView j; private final ImageView k; private final View l; private final TextView m; private final TextView n; private final i o; private final StringBuilder p; private final Formatter q; private final fo.b r; private final fo.d s; private final Runnable t; private final Runnable u; private final Drawable v; private final Drawable w; private final Drawable x; private final String y; private final String z; public static final class b { public static boolean a(View view) { return view.isAccessibilityFocused(); } } /* renamed from: com.applovin.exoplayer2.ui.d$d, reason: collision with other inner class name */ public interface InterfaceC0011d { } public interface e { void d(int i); } static { f8.a("goog.exo.ui"); } public d(Context context, AttributeSet attributeSet, int i, AttributeSet attributeSet2) { super(context, attributeSet, i); int i2 = R.layout.applovin_exo_player_control_view; this.N = 5000; this.P = 0; this.O = 200; this.V = C.TIME_UNSET; this.Q = true; this.R = true; this.S = true; this.T = true; this.U = false; if (attributeSet2 != null) { TypedArray obtainStyledAttributes = context.getTheme().obtainStyledAttributes(attributeSet2, R.styleable.AppLovinPlayerControlView, i, 0); try { this.N = obtainStyledAttributes.getInt(R.styleable.AppLovinPlayerControlView_al_show_timeout, this.N); i2 = obtainStyledAttributes.getResourceId(R.styleable.AppLovinPlayerControlView_al_controller_layout_id, i2); this.P = a(obtainStyledAttributes, this.P); this.Q = obtainStyledAttributes.getBoolean(R.styleable.AppLovinPlayerControlView_al_show_rewind_button, this.Q); this.R = obtainStyledAttributes.getBoolean(R.styleable.AppLovinPlayerControlView_al_show_fastforward_button, this.R); this.S = obtainStyledAttributes.getBoolean(R.styleable.AppLovinPlayerControlView_al_show_previous_button, this.S); this.T = obtainStyledAttributes.getBoolean(R.styleable.AppLovinPlayerControlView_al_show_next_button, this.T); this.U = obtainStyledAttributes.getBoolean(R.styleable.AppLovinPlayerControlView_al_show_shuffle_button, this.U); setTimeBarMinUpdateInterval(obtainStyledAttributes.getInt(R.styleable.AppLovinPlayerControlView_al_time_bar_min_update_interval, this.O)); } finally { obtainStyledAttributes.recycle(); } } this.b = new CopyOnWriteArrayList(); this.r = new fo.b(); this.s = new fo.d(); StringBuilder sb = new StringBuilder(); this.p = sb; this.q = new Formatter(sb, Locale.getDefault()); this.W = new long[0]; this.a0 = new boolean[0]; this.b0 = new long[0]; this.c0 = new boolean[0]; c cVar = new c(); this.a = cVar; this.I = new u5(); this.t = new Runnable() { // from class: com.applovin.exoplayer2.ui.d$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { d.this.k(); } }; this.u = new Runnable() { // from class: com.applovin.exoplayer2.ui.d$$ExternalSyntheticLambda1 @Override // java.lang.Runnable public final void run() { d.this.a(); } }; LayoutInflater.from(context).inflate(i2, this); setDescendantFocusability(262144); i iVar = (i) findViewById(R.id.al_exo_progress); View findViewById = findViewById(R.id.al_exo_progress_placeholder); if (iVar != null) { this.o = iVar; } else if (findViewById != null) { com.applovin.exoplayer2.ui.b bVar = new com.applovin.exoplayer2.ui.b(context, null, 0, attributeSet2); bVar.setId(R.id.al_exo_progress); bVar.setLayoutParams(findViewById.getLayoutParams()); ViewGroup viewGroup = (ViewGroup) findViewById.getParent(); int indexOfChild = viewGroup.indexOfChild(findViewById); viewGroup.removeView(findViewById); viewGroup.addView(bVar, indexOfChild); this.o = bVar; } else { this.o = null; } this.m = (TextView) findViewById(R.id.al_exo_duration); this.n = (TextView) findViewById(R.id.al_exo_position); i iVar2 = this.o; if (iVar2 != null) { iVar2.a(cVar); } View findViewById2 = findViewById(R.id.al_exo_play); this.f = findViewById2; if (findViewById2 != null) { findViewById2.setOnClickListener(cVar); } View findViewById3 = findViewById(R.id.al_exo_pause); this.g = findViewById3; if (findViewById3 != null) { findViewById3.setOnClickListener(cVar); } View findViewById4 = findViewById(R.id.al_exo_prev); this.c = findViewById4; if (findViewById4 != null) { findViewById4.setOnClickListener(cVar); } View findViewById5 = findViewById(R.id.al_exo_next); this.d = findViewById5; if (findViewById5 != null) { findViewById5.setOnClickListener(cVar); } View findViewById6 = findViewById(R.id.al_exo_rew); this.i = findViewById6; if (findViewById6 != null) { findViewById6.setOnClickListener(cVar); } View findViewById7 = findViewById(R.id.al_exo_ffwd); this.h = findViewById7; if (findViewById7 != null) { findViewById7.setOnClickListener(cVar); } ImageView imageView = (ImageView) findViewById(R.id.al_exo_repeat_toggle); this.j = imageView; if (imageView != null) { imageView.setOnClickListener(cVar); } ImageView imageView2 = (ImageView) findViewById(R.id.al_exo_shuffle); this.k = imageView2; if (imageView2 != null) { imageView2.setOnClickListener(cVar); } View findViewById8 = findViewById(R.id.al_exo_vr); this.l = findViewById8; setShowVrButton(false); a(false, false, findViewById8); Resources resources = context.getResources(); this.D = resources.getInteger(R.integer.al_exo_media_button_opacity_percentage_enabled) / 100.0f; this.E = resources.getInteger(R.integer.al_exo_media_button_opacity_percentage_disabled) / 100.0f; this.v = resources.getDrawable(R.drawable.al_exo_controls_repeat_off); this.w = resources.getDrawable(R.drawable.al_exo_controls_repeat_one); this.x = resources.getDrawable(R.drawable.al_exo_controls_repeat_all); this.B = resources.getDrawable(R.drawable.al_exo_controls_shuffle_on); this.C = resources.getDrawable(R.drawable.al_exo_controls_shuffle_off); this.y = resources.getString(R.string.al_exo_controls_repeat_off_description); this.z = resources.getString(R.string.al_exo_controls_repeat_one_description); this.A = resources.getString(R.string.al_exo_controls_repeat_all_description); this.F = resources.getString(R.string.al_exo_controls_shuffle_on_description); this.G = resources.getString(R.string.al_exo_controls_shuffle_off_description); } private static boolean a(int i) { return i == 90 || i == 89 || i == 85 || i == 79 || i == 126 || i == 127 || i == 87 || i == 88; } @Override // android.view.ViewGroup, android.view.View public boolean dispatchKeyEvent(KeyEvent keyEvent) { return a(keyEvent) || super.dispatchKeyEvent(keyEvent); } @Override // android.view.ViewGroup, android.view.View public final boolean dispatchTouchEvent(MotionEvent motionEvent) { if (motionEvent.getAction() == 0) { removeCallbacks(this.u); } else if (motionEvent.getAction() == 1) { b(); } return super.dispatchTouchEvent(motionEvent); } @Nullable public qh getPlayer() { return this.H; } public int getRepeatToggleModes() { return this.P; } public boolean getShowShuffleButton() { return this.U; } public int getShowTimeoutMs() { return this.N; } public boolean getShowVrButton() { View view = this.l; return view != null && view.getVisibility() == 0; } @Override // android.view.ViewGroup, android.view.View public void onAttachedToWindow() { super.onAttachedToWindow(); this.J = true; long j = this.V; if (j != C.TIME_UNSET) { long uptimeMillis = j - SystemClock.uptimeMillis(); if (uptimeMillis <= 0) { a(); } else { postDelayed(this.u, uptimeMillis); } } else if (c()) { b(); } h(); } @Override // android.view.ViewGroup, android.view.View public void onDetachedFromWindow() { super.onDetachedFromWindow(); this.J = false; removeCallbacks(this.t); removeCallbacks(this.u); } public void setPlayer(@Nullable qh qhVar) { b1.b(Looper.myLooper() == Looper.getMainLooper()); b1.a(qhVar == null || qhVar.p() == Looper.getMainLooper()); qh qhVar2 = this.H; if (qhVar2 == qhVar) { return; } if (qhVar2 != null) { qhVar2.a(this.a); } this.H = qhVar; if (qhVar != null) { qhVar.b(this.a); } h(); } public void setProgressUpdateListener(@Nullable InterfaceC0011d interfaceC0011d) { } public void setTimeBarMinUpdateInterval(int i) { this.O = xp.a(i, 16, 1000); } private void d() { View view; View view2; boolean f = f(); if (!f && (view2 = this.f) != null) { view2.sendAccessibilityEvent(8); } else { if (!f || (view = this.g) == null) { return; } view.sendAccessibilityEvent(8); } } private void h() { j(); i(); l(); m(); n(); } /* JADX INFO: Access modifiers changed from: private */ public void i() { boolean z; boolean z2; boolean z3; boolean z4; if (c() && this.J) { qh qhVar = this.H; boolean z5 = false; if (qhVar != null) { boolean b2 = qhVar.b(4); boolean b3 = qhVar.b(6); z4 = qhVar.b(10) && this.I.b(); if (qhVar.b(11) && this.I.a()) { z5 = true; } z2 = qhVar.b(8); z = z5; z5 = b3; z3 = b2; } else { z = false; z2 = false; z3 = false; z4 = false; } a(this.S, z5, this.c); a(this.Q, z4, this.i); a(this.R, z, this.h); a(this.T, z2, this.d); i iVar = this.o; if (iVar != null) { iVar.setEnabled(z3); } } } /* JADX INFO: Access modifiers changed from: private */ public void j() { boolean z; boolean z2; if (c() && this.J) { boolean f = f(); View view = this.f; boolean z3 = true; if (view != null) { z = f && view.isFocused(); z2 = xp.a < 21 ? z : f && b.a(this.f); this.f.setVisibility(f ? 8 : 0); } else { z = false; z2 = false; } View view2 = this.g; if (view2 != null) { z |= !f && view2.isFocused(); if (xp.a < 21) { z3 = z; } else if (f || !b.a(this.g)) { z3 = false; } z2 |= z3; this.g.setVisibility(f ? 0 : 8); } if (z) { e(); } if (z2) { d(); } } } /* JADX INFO: Access modifiers changed from: private */ public void k() { long j; long j2; if (c() && this.J) { qh qhVar = this.H; if (qhVar != null) { j = this.d0 + qhVar.g(); j2 = this.d0 + qhVar.s(); } else { j = 0; j2 = 0; } boolean z = j != this.e0; this.e0 = j; this.f0 = j2; TextView textView = this.n; if (textView != null && !this.M && z) { textView.setText(xp.a(this.p, this.q, j)); } i iVar = this.o; if (iVar != null) { iVar.setPosition(j); this.o.setBufferedPosition(j2); } removeCallbacks(this.t); int o = qhVar == null ? 1 : qhVar.o(); if (qhVar == null || !qhVar.isPlaying()) { if (o == 4 || o == 1) { return; } postDelayed(this.t, 1000L); return; } i iVar2 = this.o; long min = Math.min(iVar2 != null ? iVar2.getPreferredUpdateDelay() : 1000L, 1000 - (j % 1000)); float f = qhVar.a().a; postDelayed(this.t, xp.b(f > 0.0f ? (long) (min / f) : 1000L, this.O, 1000L)); } } /* JADX INFO: Access modifiers changed from: private */ public void l() { ImageView imageView; if (c() && this.J && (imageView = this.j) != null) { if (this.P == 0) { a(false, false, (View) imageView); return; } qh qhVar = this.H; if (qhVar == null) { a(true, false, (View) imageView); this.j.setImageDrawable(this.v); this.j.setContentDescription(this.y); return; } a(true, true, (View) imageView); int m = qhVar.m(); if (m == 0) { this.j.setImageDrawable(this.v); this.j.setContentDescription(this.y); } else if (m == 1) { this.j.setImageDrawable(this.w); this.j.setContentDescription(this.z); } else if (m == 2) { this.j.setImageDrawable(this.x); this.j.setContentDescription(this.A); } this.j.setVisibility(0); } } /* JADX INFO: Access modifiers changed from: private */ public void m() { ImageView imageView; if (c() && this.J && (imageView = this.k) != null) { qh qhVar = this.H; if (!this.U) { a(false, false, (View) imageView); return; } if (qhVar == null) { a(true, false, (View) imageView); this.k.setImageDrawable(this.C); this.k.setContentDescription(this.G); } else { a(true, true, (View) imageView); this.k.setImageDrawable(qhVar.r() ? this.B : this.C); this.k.setContentDescription(qhVar.r() ? this.F : this.G); } } } public void g() { if (!c()) { setVisibility(0); Iterator it = this.b.iterator(); while (it.hasNext()) { ((e) it.next()).d(getVisibility()); } h(); e(); d(); } b(); } public void setShowFastForwardButton(boolean z) { this.R = z; i(); } public void setShowMultiWindowTimeBar(boolean z) { this.K = z; n(); } public void setShowNextButton(boolean z) { this.T = z; i(); } public void setShowPreviousButton(boolean z) { this.S = z; i(); } public void setShowRewindButton(boolean z) { this.Q = z; i(); } public void setShowShuffleButton(boolean z) { this.U = z; m(); } public void setShowTimeoutMs(int i) { this.N = i; if (c()) { b(); } } public void setShowVrButton(boolean z) { View view = this.l; if (view != null) { view.setVisibility(z ? 0 : 8); } } public void setVrButtonListener(@Nullable View.OnClickListener onClickListener) { View view = this.l; if (view != null) { view.setOnClickListener(onClickListener); a(getShowVrButton(), onClickListener != null, this.l); } } private boolean f() { qh qhVar = this.H; return (qhVar == null || qhVar.o() == 4 || this.H.o() == 1 || !this.H.l()) ? false : true; } public void setRepeatToggleModes(int i) { this.P = i; qh qhVar = this.H; if (qhVar != null) { int m = qhVar.m(); if (i == 0 && m != 0) { this.I.a(this.H, 0); } else if (i == 1 && m == 2) { this.I.a(this.H, 1); } else if (i == 2 && m == 1) { this.I.a(this.H, 2); } } l(); } /* JADX INFO: Access modifiers changed from: private */ public void n() { int i; fo.d dVar; qh qhVar = this.H; if (qhVar == null) { return; } boolean z = true; this.L = this.K && a(qhVar.n(), this.s); long j = 0; this.d0 = 0L; fo n = qhVar.n(); if (n.c()) { i = 0; } else { int t = qhVar.t(); boolean z2 = this.L; int i2 = z2 ? 0 : t; int b2 = z2 ? n.b() - 1 : t; long j2 = 0; i = 0; while (true) { if (i2 > b2) { break; } if (i2 == t) { this.d0 = t2.b(j2); } n.a(i2, this.s); fo.d dVar2 = this.s; if (dVar2.o == C.TIME_UNSET) { b1.b(this.L ^ z); break; } int i3 = dVar2.p; while (true) { dVar = this.s; if (i3 <= dVar.q) { n.a(i3, this.r); int a2 = this.r.a(); for (int f = this.r.f(); f < a2; f++) { long b3 = this.r.b(f); if (b3 == Long.MIN_VALUE) { long j3 = this.r.d; if (j3 != C.TIME_UNSET) { b3 = j3; } } long e2 = b3 + this.r.e(); if (e2 >= 0) { long[] jArr = this.W; if (i == jArr.length) { int length = jArr.length == 0 ? 1 : jArr.length * 2; this.W = Arrays.copyOf(jArr, length); this.a0 = Arrays.copyOf(this.a0, length); } this.W[i] = t2.b(j2 + e2); this.a0[i] = this.r.e(f); i++; } } i3++; } } j2 += dVar.o; i2++; z = true; } j = j2; } long b4 = t2.b(j); TextView textView = this.m; if (textView != null) { textView.setText(xp.a(this.p, this.q, b4)); } i iVar = this.o; if (iVar != null) { iVar.setDuration(b4); int length2 = this.b0.length; int i4 = i + length2; long[] jArr2 = this.W; if (i4 > jArr2.length) { this.W = Arrays.copyOf(jArr2, i4); this.a0 = Arrays.copyOf(this.a0, i4); } System.arraycopy(this.b0, 0, this.W, i, length2); System.arraycopy(this.c0, 0, this.a0, i, length2); this.o.a(this.W, this.a0, i4); } k(); } private void e() { View view; View view2; boolean f = f(); if (!f && (view2 = this.f) != null) { view2.requestFocus(); } else { if (!f || (view = this.g) == null) { return; } view.requestFocus(); } } @Deprecated public void setControlDispatcher(t4 t4Var) { if (this.I != t4Var) { this.I = t4Var; i(); } } public final class c implements qh.e, i.a, View.OnClickListener { private c() { } @Override // com.applovin.exoplayer2.ui.i.a public void b(i iVar, long j) { if (d.this.n != null) { d.this.n.setText(xp.a(d.this.p, d.this.q, j)); } } @Override // android.view.View.OnClickListener public void onClick(View view) { qh qhVar = d.this.H; if (qhVar == null) { return; } if (d.this.d == view) { d.this.I.a(qhVar); return; } if (d.this.c == view) { d.this.I.e(qhVar); return; } if (d.this.h == view) { if (qhVar.o() != 4) { d.this.I.d(qhVar); return; } return; } if (d.this.i == view) { d.this.I.c(qhVar); return; } if (d.this.f == view) { d.this.b(qhVar); return; } if (d.this.g == view) { d.this.a(qhVar); } else if (d.this.j == view) { d.this.I.a(qhVar, ui.a(qhVar.m(), d.this.P)); } else if (d.this.k == view) { d.this.I.a(qhVar, !qhVar.r()); } } @Override // com.applovin.impl.qh.e, com.applovin.impl.qh.c public void a(qh qhVar, qh.d dVar) { if (dVar.a(4, 5)) { d.this.j(); } if (dVar.a(4, 5, 7)) { d.this.k(); } if (dVar.a(8)) { d.this.l(); } if (dVar.a(9)) { d.this.m(); } if (dVar.a(8, 9, 11, 0, 13)) { d.this.i(); } if (dVar.a(11, 0)) { d.this.n(); } } @Override // com.applovin.exoplayer2.ui.i.a public void a(i iVar, long j) { d.this.M = true; if (d.this.n != null) { d.this.n.setText(xp.a(d.this.p, d.this.q, j)); } } @Override // com.applovin.exoplayer2.ui.i.a public void a(i iVar, long j, boolean z) { d.this.M = false; if (z || d.this.H == null) { return; } d dVar = d.this; dVar.a(dVar.H, j); } } private void c(qh qhVar) { int o = qhVar.o(); if (o != 1 && o != 4 && qhVar.l()) { a(qhVar); } else { b(qhVar); } } public boolean c() { return getVisibility() == 0; } /* JADX INFO: Access modifiers changed from: private */ public void b(qh qhVar) { int o = qhVar.o(); if (o == 1) { this.I.b(qhVar); } else if (o == 4) { a(qhVar, qhVar.t(), C.TIME_UNSET); } this.I.b(qhVar, true); } public void b(e eVar) { this.b.remove(eVar); } private void b() { removeCallbacks(this.u); if (this.N <= 0) { this.V = C.TIME_UNSET; return; } long uptimeMillis = SystemClock.uptimeMillis(); long j = this.N; this.V = uptimeMillis + j; if (this.J) { postDelayed(this.u, j); } } private static boolean a(fo foVar, fo.d dVar) { if (foVar.b() > 100) { return false; } int b2 = foVar.b(); for (int i = 0; i < b2; i++) { if (foVar.a(i, dVar).o == C.TIME_UNSET) { return false; } } return true; } /* JADX INFO: Access modifiers changed from: private */ public void a(qh qhVar) { this.I.b(qhVar, false); } private boolean a(qh qhVar, int i, long j) { return this.I.a(qhVar, i, j); } /* JADX INFO: Access modifiers changed from: private */ public void a(qh qhVar, long j) { int t; fo n = qhVar.n(); if (this.L && !n.c()) { int b2 = n.b(); t = 0; while (true) { long d = n.a(t, this.s).d(); if (j < d) { break; } if (t == b2 - 1) { j = d; break; } else { j -= d; t++; } } } else { t = qhVar.t(); } a(qhVar, t, j); k(); } public void a(e eVar) { b1.a(eVar); this.b.add(eVar); } public void a() { if (c()) { setVisibility(8); Iterator it = this.b.iterator(); while (it.hasNext()) { ((e) it.next()).d(getVisibility()); } removeCallbacks(this.t); removeCallbacks(this.u); this.V = C.TIME_UNSET; } } private void a(boolean z, boolean z2, View view) { if (view == null) { return; } view.setEnabled(z2); view.setAlpha(z2 ? this.D : this.E); view.setVisibility(z ? 0 : 8); } public boolean a(KeyEvent keyEvent) { int keyCode = keyEvent.getKeyCode(); qh qhVar = this.H; if (qhVar == null || !a(keyCode)) { return false; } if (keyEvent.getAction() != 0) { return true; } if (keyCode == 90) { if (qhVar.o() == 4) { return true; } this.I.d(qhVar); return true; } if (keyCode == 89) { this.I.c(qhVar); return true; } if (keyEvent.getRepeatCount() != 0) { return true; } if (keyCode == 79 || keyCode == 85) { c(qhVar); return true; } if (keyCode == 87) { this.I.a(qhVar); return true; } if (keyCode == 88) { this.I.e(qhVar); return true; } if (keyCode == 126) { b(qhVar); return true; } if (keyCode != 127) { return true; } a(qhVar); return true; } private static int a(TypedArray typedArray, int i) { return typedArray.getInt(R.styleable.AppLovinPlayerControlView_al_repeat_toggle_modes, i); } }