package com.google.android.material.appbar;

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.ifpdos.udi.service.core.pc.R;
import d.h.j.y;
import g.e.a.a.a0.a.a;
import g.e.a.a.b;
import g.e.a.a.r.k;
import g.e.a.a.w.g;
import io.netty.util.internal.shaded.org.jctools.util.Pow2;
import java.util.concurrent.atomic.AtomicInteger;

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

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public Integer f1004d0;
    public boolean e0;
    public boolean f0;

    public MaterialToolbar(Context context, AttributeSet attributeSet) {
        super(a.a(context, attributeSet, R.attr.toolbarStyle, 2131886805), attributeSet, R.attr.toolbarStyle);
        Context context2 = getContext();
        TypedArray typedArrayD = k.d(context2, attributeSet, b.f3556u, R.attr.toolbarStyle, 2131886805, new int[0]);
        if (typedArrayD.hasValue(0)) {
            setNavigationIconTint(typedArrayD.getColor(0, -1));
        }
        this.e0 = typedArrayD.getBoolean(2, false);
        this.f0 = typedArrayD.getBoolean(1, false);
        typedArrayD.recycle();
        Drawable background = getBackground();
        if (background == null || (background instanceof ColorDrawable)) {
            g gVar = new g();
            gVar.p(ColorStateList.valueOf(background != null ? ((ColorDrawable) background).getColor() : 0));
            gVar.f3851n.f3864b = new g.e.a.a.o.a(context2);
            gVar.w();
            AtomicInteger atomicInteger = y.a;
            gVar.o(y.h.i(this));
            y.c.q(this, gVar);
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        Drawable background = getBackground();
        if (background instanceof g) {
            g.e.a.a.a.I(this, (g) background);
        }
    }

    @Override // androidx.appcompat.widget.Toolbar, android.view.ViewGroup, android.view.View
    public void onLayout(boolean z2, int i2, int i3, int i4, int i5) {
        super.onLayout(z2, i2, i3, i4, i5);
        if (this.e0 || this.f0) {
            TextView textViewN = g.e.a.a.a.n(this, getTitle());
            TextView textViewN2 = g.e.a.a.a.n(this, getSubtitle());
            if (textViewN == null && textViewN2 == null) {
                return;
            }
            int measuredWidth = getMeasuredWidth();
            int i6 = measuredWidth / 2;
            int paddingLeft = getPaddingLeft();
            int paddingRight = measuredWidth - getPaddingRight();
            for (int i7 = 0; i7 < getChildCount(); i7++) {
                View childAt = getChildAt(i7);
                if (childAt.getVisibility() != 8 && childAt != textViewN && childAt != textViewN2) {
                    if (childAt.getRight() < i6 && childAt.getRight() > paddingLeft) {
                        paddingLeft = childAt.getRight();
                    }
                    if (childAt.getLeft() > i6 && childAt.getLeft() < paddingRight) {
                        paddingRight = childAt.getLeft();
                    }
                }
            }
            Pair<Integer, Integer> pair = new Pair<>(Integer.valueOf(paddingLeft), Integer.valueOf(paddingRight));
            if (this.e0 && textViewN != null) {
                w(textViewN, pair);
            }
            if (!this.f0 || textViewN2 == null) {
                return;
            }
            w(textViewN2, pair);
        }
    }

    @Override // android.view.View
    public void setElevation(float f2) {
        super.setElevation(f2);
        g.e.a.a.a.H(this, f2);
    }

    @Override // androidx.appcompat.widget.Toolbar
    public void setNavigationIcon(Drawable drawable) {
        Integer num;
        if (drawable != null && (num = this.f1004d0) != null) {
            d.h.d.k.b.g(drawable, num.intValue());
        }
        super.setNavigationIcon(drawable);
    }

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

    public void setSubtitleCentered(boolean z2) {
        if (this.f0 != z2) {
            this.f0 = z2;
            requestLayout();
        }
    }

    public void setTitleCentered(boolean z2) {
        if (this.e0 != z2) {
            this.e0 = z2;
            requestLayout();
        }
    }

    public final void w(View view, Pair<Integer, Integer> pair) {
        int measuredWidth = getMeasuredWidth();
        int measuredWidth2 = view.getMeasuredWidth();
        int i2 = (measuredWidth / 2) - (measuredWidth2 / 2);
        int i3 = measuredWidth2 + i2;
        int iMax = Math.max(Math.max(((Integer) pair.first).intValue() - i2, 0), Math.max(i3 - ((Integer) pair.second).intValue(), 0));
        if (iMax > 0) {
            i2 += iMax;
            i3 -= iMax;
            view.measure(View.MeasureSpec.makeMeasureSpec(i3 - i2, Pow2.MAX_POW2), view.getMeasuredHeightAndState());
        }
        view.layout(i2, view.getTop(), i3, view.getBottom());
    }
}
