package com.google.android.material.appbar;

import A3.a;
import M.B;
import M.J;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Pair;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import com.google.android.gms.internal.measurement.AbstractC0707u1;
import com.martsnew.tv.R;
import h3.AbstractC1031a;
import java.lang.reflect.Field;
import s3.k;
import x3.g;

/* JADX INFO: loaded from: classes.dex */
public class MaterialToolbar extends Toolbar {

    /* JADX INFO: renamed from: j0, reason: collision with root package name */
    public Integer f10101j0;

    /* JADX INFO: renamed from: k0, reason: collision with root package name */
    public boolean f10102k0;

    /* JADX INFO: renamed from: l0, reason: collision with root package name */
    public boolean f10103l0;

    public MaterialToolbar(Context context, AttributeSet attributeSet) {
        super(a.a(context, attributeSet, R.attr.toolbarStyle, R.style.Widget_MaterialComponents_Toolbar), attributeSet, 0);
        Context context2 = getContext();
        TypedArray typedArrayE = k.e(context2, attributeSet, AbstractC1031a.f13412s, R.attr.toolbarStyle, R.style.Widget_MaterialComponents_Toolbar, new int[0]);
        if (typedArrayE.hasValue(0)) {
            setNavigationIconTint(typedArrayE.getColor(0, -1));
        }
        this.f10102k0 = typedArrayE.getBoolean(2, false);
        this.f10103l0 = typedArrayE.getBoolean(1, false);
        typedArrayE.recycle();
        Drawable background = getBackground();
        if (background == null || (background instanceof ColorDrawable)) {
            g gVar = new g();
            gVar.i(ColorStateList.valueOf(background != null ? ((ColorDrawable) background).getColor() : 0));
            gVar.g(context2);
            Field field = J.f4065a;
            gVar.h(B.e(this));
            setBackground(gVar);
        }
    }

    @Override // androidx.appcompat.widget.Toolbar, android.view.ViewGroup, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        Drawable background = getBackground();
        if (background instanceof g) {
            AbstractC0707u1.m(this, (g) background);
        }
    }

    @Override // androidx.appcompat.widget.Toolbar, android.view.ViewGroup, android.view.View
    public final void onLayout(boolean z8, int i, int i5, int i8, int i9) {
        super.onLayout(z8, i, i5, i8, i9);
        if (this.f10102k0 || this.f10103l0) {
            TextView textViewD = k.d(this, getTitle());
            TextView textViewD2 = k.d(this, getSubtitle());
            if (textViewD == null && textViewD2 == null) {
                return;
            }
            int measuredWidth = getMeasuredWidth();
            int i10 = measuredWidth / 2;
            int paddingLeft = getPaddingLeft();
            int paddingRight = measuredWidth - getPaddingRight();
            for (int i11 = 0; i11 < getChildCount(); i11++) {
                View childAt = getChildAt(i11);
                if (childAt.getVisibility() != 8 && childAt != textViewD && childAt != textViewD2) {
                    if (childAt.getRight() < i10 && childAt.getRight() > paddingLeft) {
                        paddingLeft = childAt.getRight();
                    }
                    if (childAt.getLeft() > i10 && childAt.getLeft() < paddingRight) {
                        paddingRight = childAt.getLeft();
                    }
                }
            }
            Pair pair = new Pair(Integer.valueOf(paddingLeft), Integer.valueOf(paddingRight));
            if (this.f10102k0 && textViewD != null) {
                t(textViewD, pair);
            }
            if (!this.f10103l0 || textViewD2 == null) {
                return;
            }
            t(textViewD2, pair);
        }
    }

    @Override // android.view.View
    public void setElevation(float f3) {
        super.setElevation(f3);
        Drawable background = getBackground();
        if (background instanceof g) {
            ((g) background).h(f3);
        }
    }

    @Override // androidx.appcompat.widget.Toolbar
    public void setNavigationIcon(Drawable drawable) {
        Integer num;
        if (drawable != null && (num = this.f10101j0) != null) {
            drawable.setTint(num.intValue());
        }
        super.setNavigationIcon(drawable);
    }

    public void setNavigationIconTint(int i) {
        this.f10101j0 = Integer.valueOf(i);
        Drawable navigationIcon = getNavigationIcon();
        if (navigationIcon != null) {
            setNavigationIcon(navigationIcon);
        }
    }

    public void setSubtitleCentered(boolean z8) {
        if (this.f10103l0 != z8) {
            this.f10103l0 = z8;
            requestLayout();
        }
    }

    public void setTitleCentered(boolean z8) {
        if (this.f10102k0 != z8) {
            this.f10102k0 = z8;
            requestLayout();
        }
    }

    public final void t(TextView textView, Pair pair) {
        int measuredWidth = getMeasuredWidth();
        int measuredWidth2 = textView.getMeasuredWidth();
        int i = (measuredWidth / 2) - (measuredWidth2 / 2);
        int i5 = measuredWidth2 + i;
        int iMax = Math.max(Math.max(((Integer) pair.first).intValue() - i, 0), Math.max(i5 - ((Integer) pair.second).intValue(), 0));
        if (iMax > 0) {
            i += iMax;
            i5 -= iMax;
            textView.measure(View.MeasureSpec.makeMeasureSpec(i5 - i, 1073741824), textView.getMeasuredHeightAndState());
        }
        textView.layout(i, textView.getTop(), i5, textView.getBottom());
    }
}
