package androidx.leanback.widget;

import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.martsnew.tv.R;
import d5.AbstractC0844a;
import java.lang.reflect.Field;

/* JADX INFO: loaded from: classes.dex */
public class SearchOrbView extends FrameLayout implements View.OnClickListener {

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    public static final /* synthetic */ int f8562I = 0;

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final float f8563A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public ValueAnimator f8564B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public boolean f8565C;
    public boolean D;

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public final ArgbEvaluator f8566E;

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public final C0487r0 f8567F;

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public ValueAnimator f8568G;
    public final C0487r0 H;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public View.OnClickListener f8569q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final View f8570r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final View f8571s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final ImageView f8572t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public Drawable f8573u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public s0 f8574v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final float f8575w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final int f8576x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final int f8577y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final float f8578z;

    public SearchOrbView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, R.attr.searchOrbViewStyle);
    }

    public final void a(boolean z8) {
        float f3 = z8 ? this.f8575w : 1.0f;
        ViewPropertyAnimator viewPropertyAnimatorScaleY = this.f8570r.animate().scaleX(f3).scaleY(f3);
        long j8 = this.f8577y;
        viewPropertyAnimatorScaleY.setDuration(j8).start();
        if (this.f8568G == null) {
            ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
            this.f8568G = valueAnimatorOfFloat;
            valueAnimatorOfFloat.addUpdateListener(this.H);
        }
        if (z8) {
            this.f8568G.start();
        } else {
            this.f8568G.reverse();
        }
        this.f8568G.setDuration(j8);
        this.f8565C = z8;
        b();
    }

    public final void b() {
        ValueAnimator valueAnimator = this.f8564B;
        if (valueAnimator != null) {
            valueAnimator.end();
            this.f8564B = null;
        }
        if (this.f8565C && this.D) {
            ValueAnimator valueAnimatorOfObject = ValueAnimator.ofObject(this.f8566E, Integer.valueOf(this.f8574v.f8712a), Integer.valueOf(this.f8574v.f8713b), Integer.valueOf(this.f8574v.f8712a));
            this.f8564B = valueAnimatorOfObject;
            valueAnimatorOfObject.setRepeatCount(-1);
            this.f8564B.setDuration(this.f8576x * 2);
            this.f8564B.addUpdateListener(this.f8567F);
            this.f8564B.start();
        }
    }

    public float getFocusedZoom() {
        return this.f8575w;
    }

    public int getLayoutResourceId() {
        return R.layout.lb_search_orb;
    }

    public int getOrbColor() {
        return this.f8574v.f8712a;
    }

    public s0 getOrbColors() {
        return this.f8574v;
    }

    public Drawable getOrbIcon() {
        return this.f8573u;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        this.D = true;
        b();
    }

    @Override // android.view.View.OnClickListener
    public final void onClick(View view) {
        View.OnClickListener onClickListener = this.f8569q;
        if (onClickListener != null) {
            onClickListener.onClick(view);
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onDetachedFromWindow() {
        this.D = false;
        b();
        super.onDetachedFromWindow();
    }

    @Override // android.view.View
    public final void onFocusChanged(boolean z8, int i, Rect rect) {
        super.onFocusChanged(z8, i, rect);
        a(z8);
    }

    public void setOnOrbClickedListener(View.OnClickListener onClickListener) {
        this.f8569q = onClickListener;
    }

    public void setOrbColor(int i) {
        setOrbColors(new s0(i, i, 0));
    }

    public void setOrbColors(s0 s0Var) {
        this.f8574v = s0Var;
        this.f8572t.setColorFilter(s0Var.f8714c);
        if (this.f8564B == null) {
            setOrbViewColor(this.f8574v.f8712a);
        } else {
            this.f8565C = true;
            b();
        }
    }

    public void setOrbIcon(Drawable drawable) {
        this.f8573u = drawable;
        this.f8572t.setImageDrawable(drawable);
    }

    public void setOrbViewColor(int i) {
        View view = this.f8571s;
        if (view.getBackground() instanceof GradientDrawable) {
            ((GradientDrawable) view.getBackground()).setColor(i);
        }
    }

    public void setSearchOrbZ(float f3) {
        float f7 = this.f8563A;
        float f8 = this.f8578z;
        float f9 = AbstractC0844a.f(f7, f8, f3, f8);
        Field field = M.J.f4065a;
        M.B.l(this.f8571s, f9);
    }

    /* JADX WARN: Type inference failed for: r0v1, types: [androidx.leanback.widget.r0] */
    /* JADX WARN: Type inference failed for: r0v2, types: [androidx.leanback.widget.r0] */
    public SearchOrbView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.f8566E = new ArgbEvaluator();
        final int i5 = 0;
        this.f8567F = new ValueAnimator.AnimatorUpdateListener(this) { // from class: androidx.leanback.widget.r0

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ SearchOrbView f8710b;

            {
                this.f8710b = this;
            }

            @Override // android.animation.ValueAnimator.AnimatorUpdateListener
            public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                SearchOrbView searchOrbView = this.f8710b;
                switch (i5) {
                    case n4.u0.f15495q /* 0 */:
                        int i8 = SearchOrbView.f8562I;
                        searchOrbView.getClass();
                        searchOrbView.setOrbViewColor(((Integer) valueAnimator.getAnimatedValue()).intValue());
                        break;
                    default:
                        int i9 = SearchOrbView.f8562I;
                        searchOrbView.getClass();
                        searchOrbView.setSearchOrbZ(valueAnimator.getAnimatedFraction());
                        break;
                }
            }
        };
        final int i8 = 1;
        this.H = new ValueAnimator.AnimatorUpdateListener(this) { // from class: androidx.leanback.widget.r0

            /* JADX INFO: renamed from: b, reason: collision with root package name */
            public final /* synthetic */ SearchOrbView f8710b;

            {
                this.f8710b = this;
            }

            @Override // android.animation.ValueAnimator.AnimatorUpdateListener
            public final void onAnimationUpdate(ValueAnimator valueAnimator) {
                SearchOrbView searchOrbView = this.f8710b;
                switch (i8) {
                    case n4.u0.f15495q /* 0 */:
                        int i82 = SearchOrbView.f8562I;
                        searchOrbView.getClass();
                        searchOrbView.setOrbViewColor(((Integer) valueAnimator.getAnimatedValue()).intValue());
                        break;
                    default:
                        int i9 = SearchOrbView.f8562I;
                        searchOrbView.getClass();
                        searchOrbView.setSearchOrbZ(valueAnimator.getAnimatedFraction());
                        break;
                }
            }
        };
        Resources resources = context.getResources();
        View viewInflate = ((LayoutInflater) context.getSystemService("layout_inflater")).inflate(getLayoutResourceId(), (ViewGroup) this, true);
        this.f8570r = viewInflate;
        this.f8571s = viewInflate.findViewById(R.id.search_orb);
        ImageView imageView = (ImageView) viewInflate.findViewById(R.id.icon);
        this.f8572t = imageView;
        this.f8575w = context.getResources().getFraction(R.fraction.lb_search_orb_focused_zoom, 1, 1);
        this.f8576x = context.getResources().getInteger(R.integer.lb_search_orb_pulse_duration_ms);
        this.f8577y = context.getResources().getInteger(R.integer.lb_search_orb_scale_duration_ms);
        float dimensionPixelSize = context.getResources().getDimensionPixelSize(R.dimen.lb_search_orb_focused_z);
        this.f8563A = dimensionPixelSize;
        this.f8578z = context.getResources().getDimensionPixelSize(R.dimen.lb_search_orb_unfocused_z);
        int[] iArr = k0.a.f13746g;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, iArr, i, 0);
        M.J.i(this, context, iArr, attributeSet, typedArrayObtainStyledAttributes, i);
        Drawable drawable = typedArrayObtainStyledAttributes.getDrawable(2);
        setOrbIcon(drawable == null ? resources.getDrawable(R.drawable.lb_ic_in_app_search) : drawable);
        int color = typedArrayObtainStyledAttributes.getColor(1, resources.getColor(R.color.lb_default_search_color));
        setOrbColors(new s0(color, typedArrayObtainStyledAttributes.getColor(0, color), typedArrayObtainStyledAttributes.getColor(3, 0)));
        typedArrayObtainStyledAttributes.recycle();
        setFocusable(true);
        setClipChildren(false);
        setOnClickListener(this);
        setSoundEffectsEnabled(false);
        setSearchOrbZ(0.0f);
        M.B.l(imageView, dimensionPixelSize);
    }
}
