package androidx.leanback.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import p037.p091.C2074;

/* JADX INFO: loaded from: classes.dex */
public class ThumbsBar extends LinearLayout {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public int f876;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public int f877;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public int f878;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public int f879;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public int f880;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public int f881;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public boolean f882;

    public ThumbsBar(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public ThumbsBar(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.f876 = -1;
        new SparseArray();
        this.f882 = false;
        this.f877 = context.getResources().getDimensionPixelSize(C2074.lb_playback_transport_thumbs_width);
        this.f878 = context.getResources().getDimensionPixelSize(C2074.lb_playback_transport_thumbs_height);
        this.f880 = context.getResources().getDimensionPixelSize(C2074.lb_playback_transport_hero_thumbs_width);
        this.f879 = context.getResources().getDimensionPixelSize(C2074.lb_playback_transport_hero_thumbs_height);
        this.f881 = context.getResources().getDimensionPixelSize(C2074.lb_playback_transport_thumbs_margin);
    }

    public int getHeroIndex() {
        return getChildCount() / 2;
    }

    @Override // android.widget.LinearLayout, android.view.ViewGroup, android.view.View
    public void onLayout(boolean z, int i, int i2, int i3, int i4) {
        super.onLayout(z, i, i2, i3, i4);
        int heroIndex = getHeroIndex();
        View childAt = getChildAt(heroIndex);
        int width = (getWidth() / 2) - (childAt.getMeasuredWidth() / 2);
        int measuredWidth = (childAt.getMeasuredWidth() / 2) + (getWidth() / 2);
        childAt.layout(width, getPaddingTop(), measuredWidth, childAt.getMeasuredHeight() + getPaddingTop());
        int measuredHeight = (childAt.getMeasuredHeight() / 2) + getPaddingTop();
        for (int i5 = heroIndex - 1; i5 >= 0; i5--) {
            int i6 = width - this.f881;
            View childAt2 = getChildAt(i5);
            childAt2.layout(i6 - childAt2.getMeasuredWidth(), measuredHeight - (childAt2.getMeasuredHeight() / 2), i6, (childAt2.getMeasuredHeight() / 2) + measuredHeight);
            width = i6 - childAt2.getMeasuredWidth();
        }
        while (true) {
            heroIndex++;
            if (heroIndex >= this.f876) {
                return;
            }
            int i7 = measuredWidth + this.f881;
            View childAt3 = getChildAt(heroIndex);
            childAt3.layout(i7, measuredHeight - (childAt3.getMeasuredHeight() / 2), childAt3.getMeasuredWidth() + i7, (childAt3.getMeasuredHeight() / 2) + measuredHeight);
            measuredWidth = i7 + childAt3.getMeasuredWidth();
        }
    }

    @Override // android.widget.LinearLayout, android.view.View
    public void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        int measuredWidth = getMeasuredWidth();
        if (this.f882) {
            return;
        }
        int i3 = measuredWidth - this.f879;
        int i4 = ((i3 + r3) - 1) / (this.f877 + this.f881);
        if (i4 < 2) {
            i4 = 2;
        } else if ((i4 & 1) != 0) {
            i4++;
        }
        int i5 = i4 + 1;
        if (this.f876 != i5) {
            this.f876 = i5;
            m311();
        }
    }

    public void setNumberOfThumbs(int i) {
        this.f882 = true;
        this.f876 = i;
        m311();
    }

    public void setThumbSpace(int i) {
        this.f881 = i;
        requestLayout();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m311() {
        while (getChildCount() > this.f876) {
            removeView(getChildAt(getChildCount() - 1));
        }
        while (getChildCount() < this.f876) {
            addView(new ImageView(getContext()), new LinearLayout.LayoutParams(this.f877, this.f878));
        }
        int heroIndex = getHeroIndex();
        for (int i = 0; i < getChildCount(); i++) {
            View childAt = getChildAt(i);
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) childAt.getLayoutParams();
            if (heroIndex == i) {
                layoutParams.width = this.f879;
                layoutParams.height = this.f880;
            } else {
                layoutParams.width = this.f877;
                layoutParams.height = this.f878;
            }
            childAt.setLayoutParams(layoutParams);
        }
    }
}
