抖阴.apk(点击下载) / SegmentTabLayout.java


package com.flyco.tablayout;

import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.OvershootInterpolator;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.flyco.tablayout.widget.MsgView;
import com.slzhibo.library.utils.picker.ImageSet;
import java.util.ArrayList;

public class SegmentTabLayout extends FrameLayout implements ValueAnimator.AnimatorUpdateListener {
    private static final int s1 = 0;
    private static final int t1 = 1;
    private static final int u1 = 2;
    private LinearLayout B0;
    private int C0;
    private int D0;
    private int E0;
    private Rect F0;
    private GradientDrawable G0;
    private GradientDrawable H0;
    private Paint I0;
    private float J0;
    private boolean K0;
    private float L0;
    private int M0;
    private float N0;
    private float O0;
    private float P0;
    private float Q0;
    private float R0;
    private float S0;
    private long T0;
    private boolean U0;
    private boolean V0;
    private int W0;
    private float X0;
    private float Y0;
    private float Z0;
    private int a1;
    private int b1;
    private int c1;
    private boolean d1;
    private int e1;
    private int f1;
    private float g1;
    private int h1;
    private ValueAnimator i1;
    private OvershootInterpolator j1;
    private com.flyco.tablayout.c.a k1;
    private float[] l1;
    private boolean m1;
    private Paint n1;
    private SparseArray<Boolean> o1;
    private com.flyco.tablayout.b.b p1;
    private b q1;
    private b r1;
    private Context t;
    private String[] u;

    /* access modifiers changed from: package-private */
    public class a implements View.OnClickListener {
        a() {
        }

        public void onClick(View view) {
            int intValue = ((Integer) view.getTag()).intValue();
            if (SegmentTabLayout.this.C0 != intValue) {
                SegmentTabLayout.this.setCurrentTab(intValue);
                if (SegmentTabLayout.this.p1 != null) {
                    SegmentTabLayout.this.p1.b(intValue);
                }
            } else if (SegmentTabLayout.this.p1 != null) {
                SegmentTabLayout.this.p1.a(intValue);
            }
        }
    }

    /* access modifiers changed from: package-private */
    public class b {
        public float a;

        /* renamed from: b  reason: collision with root package name */
        public float f1027b;

        b() {
        }
    }

    class c implements TypeEvaluator<b> {
        c() {
        }

        /* renamed from: a */
        public b evaluate(float f2, b bVar, b bVar2) {
            float f3 = bVar.a;
            float f4 = bVar.f1027b;
            float f5 = f4 + (f2 * (bVar2.f1027b - f4));
            b bVar3 = new b();
            bVar3.a = f3 + ((bVar2.a - f3) * f2);
            bVar3.f1027b = f5;
            return bVar3;
        }
    }

    public SegmentTabLayout(Context context) {
        this(context, null, 0);
    }

    private void f() {
        View childAt = this.B0.getChildAt(this.C0);
        Rect rect = this.F0;
        rect.left = (int) ((float) childAt.getLeft());
        rect.right = (int) ((float) childAt.getRight());
        if (!this.U0) {
            int i = this.C0;
            if (i == 0) {
                float[] fArr = this.l1;
                float f2 = this.O0;
                fArr[0] = f2;
                fArr[1] = f2;
                fArr[2] = 0.0f;
                fArr[3] = 0.0f;
                fArr[4] = 0.0f;
                fArr[5] = 0.0f;
                fArr[6] = f2;
                fArr[7] = f2;
            } else if (i == this.E0 - 1) {
                float[] fArr2 = this.l1;
                fArr2[0] = 0.0f;
                fArr2[1] = 0.0f;
                float f3 = this.O0;
                fArr2[2] = f3;
                fArr2[3] = f3;
                fArr2[4] = f3;
                fArr2[5] = f3;
                fArr2[6] = 0.0f;
                fArr2[7] = 0.0f;
            } else {
                float[] fArr3 = this.l1;
                fArr3[0] = 0.0f;
                fArr3[1] = 0.0f;
                fArr3[2] = 0.0f;
                fArr3[3] = 0.0f;
                fArr3[4] = 0.0f;
                fArr3[5] = 0.0f;
                fArr3[6] = 0.0f;
                fArr3[7] = 0.0f;
            }
        } else {
            float[] fArr4 = this.l1;
            float f4 = this.O0;
            fArr4[0] = f4;
            fArr4[1] = f4;
            fArr4[2] = f4;
            fArr4[3] = f4;
            fArr4[4] = f4;
            fArr4[5] = f4;
            fArr4[6] = f4;
            fArr4[7] = f4;
        }
    }

    private void g() {
        View childAt = this.B0.getChildAt(this.C0);
        this.q1.a = (float) childAt.getLeft();
        this.q1.f1027b = (float) childAt.getRight();
        View childAt2 = this.B0.getChildAt(this.D0);
        this.r1.a = (float) childAt2.getLeft();
        this.r1.f1027b = (float) childAt2.getRight();
        b bVar = this.r1;
        float f2 = bVar.a;
        b bVar2 = this.q1;
        if (f2 == bVar2.a && bVar.f1027b == bVar2.f1027b) {
            invalidate();
            return;
        }
        this.i1.setObjectValues(this.r1, this.q1);
        if (this.V0) {
            this.i1.setInterpolator(this.j1);
        }
        if (this.T0 < 0) {
            this.T0 = this.V0 ? 500 : 250;
        }
        this.i1.setDuration(this.T0);
        this.i1.start();
    }

    private void h() {
        int i = 0;
        while (i < this.E0) {
            View childAt = this.B0.getChildAt(i);
            float f2 = this.J0;
            childAt.setPadding((int) f2, 0, (int) f2, 0);
            TextView textView = (TextView) childAt.findViewById(R.id.tv_tab_title);
            textView.setTextColor(i == this.C0 ? this.a1 : this.b1);
            textView.setTextSize(0, this.Z0);
            if (this.d1) {
                textView.setText(textView.getText().toString().toUpperCase());
            }
            int i2 = this.c1;
            if (i2 == 2) {
                textView.getPaint().setFakeBoldText(true);
            } else if (i2 == 0) {
                textView.getPaint().setFakeBoldText(false);
            }
            i++;
        }
    }

    public boolean c() {
        return this.K0;
    }

    public boolean d() {
        return this.d1;
    }

    public void e() {
        this.B0.removeAllViews();
        this.E0 = this.u.length;
        for (int i = 0; i < this.E0; i++) {
            View inflate = View.inflate(this.t, R.layout.layout_tab_segment, null);
            inflate.setTag(Integer.valueOf(i));
            a(i, inflate);
        }
        h();
    }

    public int getCurrentTab() {
        return this.C0;
    }

    public int getDividerColor() {
        return this.W0;
    }

    public float getDividerPadding() {
        return this.Y0;
    }

    public float getDividerWidth() {
        return this.X0;
    }

    public long getIndicatorAnimDuration() {
        return this.T0;
    }

    public int getIndicatorColor() {
        return this.M0;
    }

    public float getIndicatorCornerRadius() {
        return this.O0;
    }

    public float getIndicatorHeight() {
        return this.N0;
    }

    public float getIndicatorMarginBottom() {
        return this.S0;
    }

    public float getIndicatorMarginLeft() {
        return this.P0;
    }

    public float getIndicatorMarginRight() {
        return this.R0;
    }

    public float getIndicatorMarginTop() {
        return this.Q0;
    }

    public int getTabCount() {
        return this.E0;
    }

    public float getTabPadding() {
        return this.J0;
    }

    public float getTabWidth() {
        return this.L0;
    }

    public int getTextBold() {
        return this.c1;
    }

    public int getTextSelectColor() {
        return this.a1;
    }

    public int getTextUnselectColor() {
        return this.b1;
    }

    public float getTextsize() {
        return this.Z0;
    }

    public void onAnimationUpdate(ValueAnimator valueAnimator) {
        b bVar = (b) valueAnimator.getAnimatedValue();
        Rect rect = this.F0;
        rect.left = (int) bVar.a;
        rect.right = (int) bVar.f1027b;
        invalidate();
    }

    /* access modifiers changed from: protected */
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (!isInEditMode() && this.E0 > 0) {
            int height = getHeight();
            int paddingLeft = getPaddingLeft();
            if (this.N0 < 0.0f) {
                this.N0 = (((float) height) - this.Q0) - this.S0;
            }
            float f2 = this.O0;
            if (f2 < 0.0f || f2 > this.N0 / 2.0f) {
                this.O0 = this.N0 / 2.0f;
            }
            this.H0.setColor(this.e1);
            this.H0.setStroke((int) this.g1, this.f1);
            this.H0.setCornerRadius(this.O0);
            this.H0.setBounds(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(), getHeight() - getPaddingBottom());
            this.H0.draw(canvas);
            if (!this.U0) {
                float f3 = this.X0;
                if (f3 > 0.0f) {
                    this.I0.setStrokeWidth(f3);
                    this.I0.setColor(this.W0);
                    for (int i = 0; i < this.E0 - 1; i++) {
                        View childAt = this.B0.getChildAt(i);
                        canvas.drawLine((float) (childAt.getRight() + paddingLeft), this.Y0, (float) (childAt.getRight() + paddingLeft), ((float) height) - this.Y0, this.I0);
                    }
                }
            }
            if (!this.U0) {
                f();
            } else if (this.m1) {
                this.m1 = false;
                f();
            }
            this.G0.setColor(this.M0);
            GradientDrawable gradientDrawable = this.G0;
            Rect rect = this.F0;
            int i2 = ((int) this.P0) + paddingLeft + rect.left;
            float f4 = this.Q0;
            gradientDrawable.setBounds(i2, (int) f4, (int) (((float) (paddingLeft + rect.right)) - this.R0), (int) (f4 + this.N0));
            this.G0.setCornerRadii(this.l1);
            this.G0.draw(canvas);
        }
    }

    /* access modifiers changed from: protected */
    public void onRestoreInstanceState(Parcelable parcelable) {
        if (parcelable instanceof Bundle) {
            Bundle bundle = (Bundle) parcelable;
            this.C0 = bundle.getInt("mCurrentTab");
            parcelable = bundle.getParcelable("instanceState");
            if (this.C0 != 0 && this.B0.getChildCount() > 0) {
                e(this.C0);
            }
        }
        super.onRestoreInstanceState(parcelable);
    }

    /* access modifiers changed from: protected */
    public Parcelable onSaveInstanceState() {
        Bundle bundle = new Bundle();
        bundle.putParcelable("instanceState", super.onSaveInstanceState());
        bundle.putInt("mCurrentTab", this.C0);
        return bundle;
    }

    public void setCurrentTab(int i) {
        this.D0 = this.C0;
        this.C0 = i;
        e(i);
        com.flyco.tablayout.c.a aVar = this.k1;
        if (aVar != null) {
            aVar.a(i);
        }
        if (this.U0) {
            g();
        } else {
            invalidate();
        }
    }

    public void setDividerColor(int i) {
        this.W0 = i;
        invalidate();
    }

    public void setDividerPadding(float f2) {
        this.Y0 = (float) a(f2);
        invalidate();
    }

    public void setDividerWidth(float f2) {
        this.X0 = (float) a(f2);
        invalidate();
    }

    public void setIndicatorAnimDuration(long j) {
        this.T0 = j;
    }

    public void setIndicatorAnimEnable(boolean z) {
        this.U0 = z;
    }

    public void setIndicatorBounceEnable(boolean z) {
        this.V0 = z;
    }

    public void setIndicatorColor(int i) {
        this.M0 = i;
        invalidate();
    }

    public void setIndicatorCornerRadius(float f2) {
        this.O0 = (float) a(f2);
        invalidate();
    }

    public void setIndicatorHeight(float f2) {
        this.N0 = (float) a(f2);
        invalidate();
    }

    public void setIndicatorMargin(float f2, float f3, float f4, float f5) {
        this.P0 = (float) a(f2);
        this.Q0 = (float) a(f3);
        this.R0 = (float) a(f4);
        this.S0 = (float) a(f5);
        invalidate();
    }

    public void setMsgMargin(int i, float f2, float f3) {
        int i2 = this.E0;
        if (i >= i2) {
            i = i2 - 1;
        }
        View childAt = this.B0.getChildAt(i);
        MsgView msgView = (MsgView) childAt.findViewById(R.id.rtv_msg_tip);
        if (msgView != null) {
            this.n1.setTextSize(this.Z0);
            this.n1.measureText(((TextView) childAt.findViewById(R.id.tv_tab_title)).getText().toString());
            float descent = this.n1.descent() - this.n1.ascent();
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) msgView.getLayoutParams();
            marginLayoutParams.leftMargin = a(f2);
            int i3 = this.h1;
            marginLayoutParams.topMargin = i3 > 0 ? (((int) (((float) i3) - descent)) / 2) - a(f3) : a(f3);
            msgView.setLayoutParams(marginLayoutParams);
        }
    }

    public void setOnTabSelectListener(com.flyco.tablayout.b.b bVar) {
        this.p1 = bVar;
    }

    public void setTabData(String[] strArr) {
        if (strArr == null || strArr.length == 0) {
            throw new IllegalStateException("Titles can not be NULL or EMPTY !");
        }
        this.u = strArr;
        e();
    }

    public void setTabPadding(float f2) {
        this.J0 = (float) a(f2);
        h();
    }

    public void setTabSpaceEqual(boolean z) {
        this.K0 = z;
        h();
    }

    public void setTabWidth(float f2) {
        this.L0 = (float) a(f2);
        h();
    }

    public void setTextAllCaps(boolean z) {
        this.d1 = z;
        h();
    }

    public void setTextBold(int i) {
        this.c1 = i;
        h();
    }

    public void setTextSelectColor(int i) {
        this.a1 = i;
        h();
    }

    public void setTextUnselectColor(int i) {
        this.b1 = i;
        h();
    }

    public void setTextsize(float f2) {
        this.Z0 = (float) b(f2);
        h();
    }

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

    private void a(Context context, AttributeSet attributeSet) {
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.SegmentTabLayout);
        this.M0 = obtainStyledAttributes.getColor(R.styleable.SegmentTabLayout_tl_indicator_color, Color.parseColor("#222831"));
        this.N0 = obtainStyledAttributes.getDimension(R.styleable.SegmentTabLayout_tl_indicator_height, -1.0f);
        this.O0 = obtainStyledAttributes.getDimension(R.styleable.SegmentTabLayout_tl_indicator_corner_radius, -1.0f);
        this.P0 = obtainStyledAttributes.getDimension(R.styleable.SegmentTabLayout_tl_indicator_margin_left, (float) a(0.0f));
        this.Q0 = obtainStyledAttributes.getDimension(R.styleable.SegmentTabLayout_tl_indicator_margin_top, 0.0f);
        this.R0 = obtainStyledAttributes.getDimension(R.styleable.SegmentTabLayout_tl_indicator_margin_right, (float) a(0.0f));
        this.S0 = obtainStyledAttributes.getDimension(R.styleable.SegmentTabLayout_tl_indicator_margin_bottom, 0.0f);
        this.U0 = obtainStyledAttributes.getBoolean(R.styleable.SegmentTabLayout_tl_indicator_anim_enable, false);
        this.V0 = obtainStyledAttributes.getBoolean(R.styleable.SegmentTabLayout_tl_indicator_bounce_enable, true);
        this.T0 = (long) obtainStyledAttributes.getInt(R.styleable.SegmentTabLayout_tl_indicator_anim_duration, -1);
        this.W0 = obtainStyledAttributes.getColor(R.styleable.SegmentTabLayout_tl_divider_color, this.M0);
        this.X0 = obtainStyledAttributes.getDimension(R.styleable.SegmentTabLayout_tl_divider_width, (float) a(1.0f));
        this.Y0 = obtainStyledAttributes.getDimension(R.styleable.SegmentTabLayout_tl_divider_padding, 0.0f);
        this.Z0 = obtainStyledAttributes.getDimension(R.styleable.SegmentTabLayout_tl_textsize, (float) b(13.0f));
        this.a1 = obtainStyledAttributes.getColor(R.styleable.SegmentTabLayout_tl_textSelectColor, Color.parseColor("#ffffff"));
        this.b1 = obtainStyledAttributes.getColor(R.styleable.SegmentTabLayout_tl_textUnselectColor, this.M0);
        this.c1 = obtainStyledAttributes.getInt(R.styleable.SegmentTabLayout_tl_textBold, 0);
        this.d1 = obtainStyledAttributes.getBoolean(R.styleable.SegmentTabLayout_tl_textAllCaps, false);
        this.K0 = obtainStyledAttributes.getBoolean(R.styleable.SegmentTabLayout_tl_tab_space_equal, true);
        this.L0 = obtainStyledAttributes.getDimension(R.styleable.SegmentTabLayout_tl_tab_width, (float) a(-1.0f));
        this.J0 = obtainStyledAttributes.getDimension(R.styleable.SegmentTabLayout_tl_tab_padding, (float) ((this.K0 || this.L0 > 0.0f) ? a(0.0f) : a(10.0f)));
        this.e1 = obtainStyledAttributes.getColor(R.styleable.SegmentTabLayout_tl_bar_color, 0);
        this.f1 = obtainStyledAttributes.getColor(R.styleable.SegmentTabLayout_tl_bar_stroke_color, this.M0);
        this.g1 = obtainStyledAttributes.getDimension(R.styleable.SegmentTabLayout_tl_bar_stroke_width, (float) a(1.0f));
        obtainStyledAttributes.recycle();
    }

    public boolean b() {
        return this.V0;
    }

    public void c(int i) {
        int i2 = this.E0;
        if (i >= i2) {
            i = i2 - 1;
        }
        MsgView msgView = (MsgView) this.B0.getChildAt(i).findViewById(R.id.rtv_msg_tip);
        if (msgView != null) {
            msgView.setVisibility(8);
        }
    }

    public void d(int i) {
        int i2 = this.E0;
        if (i >= i2) {
            i = i2 - 1;
        }
        a(i, 0);
    }

    public SegmentTabLayout(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.F0 = new Rect();
        this.G0 = new GradientDrawable();
        this.H0 = new GradientDrawable();
        this.I0 = new Paint(1);
        this.j1 = new OvershootInterpolator(0.8f);
        this.l1 = new float[8];
        this.m1 = true;
        this.n1 = new Paint(1);
        this.o1 = new SparseArray<>();
        this.q1 = new b();
        this.r1 = new b();
        setWillNotDraw(false);
        setClipChildren(false);
        setClipToPadding(false);
        this.t = context;
        this.B0 = new LinearLayout(context);
        addView(this.B0);
        a(context, attributeSet);
        String attributeValue = attributeSet.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_height");
        if (!attributeValue.equals(ImageSet.ID_ALL_MEDIA) && !attributeValue.equals("-2")) {
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, new int[]{16842997});
            this.h1 = obtainStyledAttributes.getDimensionPixelSize(0, -2);
            obtainStyledAttributes.recycle();
        }
        this.i1 = ValueAnimator.ofObject(new c(), this.r1, this.q1);
        this.i1.addUpdateListener(this);
    }

    public TextView b(int i) {
        return (TextView) this.B0.getChildAt(i).findViewById(R.id.tv_tab_title);
    }

    /* access modifiers changed from: protected */
    public int b(float f2) {
        return (int) ((f2 * this.t.getResources().getDisplayMetrics().scaledDensity) + 0.5f);
    }

    public void setTabData(String[] strArr, FragmentActivity fragmentActivity, int i, ArrayList<Fragment> arrayList) {
        this.k1 = new com.flyco.tablayout.c.a(fragmentActivity.getSupportFragmentManager(), i, arrayList);
        setTabData(strArr);
    }

    private void e(int i) {
        int i2 = 0;
        while (i2 < this.E0) {
            View childAt = this.B0.getChildAt(i2);
            boolean z = i2 == i;
            TextView textView = (TextView) childAt.findViewById(R.id.tv_tab_title);
            textView.setTextColor(z ? this.a1 : this.b1);
            if (this.c1 == 1) {
                textView.getPaint().setFakeBoldText(z);
            }
            i2++;
        }
    }

    private void a(int i, View view) {
        ((TextView) view.findViewById(R.id.tv_tab_title)).setText(this.u[i]);
        view.setOnClickListener(new a());
        LinearLayout.LayoutParams layoutParams = this.K0 ? new LinearLayout.LayoutParams(0, -1, 1.0f) : new LinearLayout.LayoutParams(-2, -1);
        float f2 = this.L0;
        if (f2 > 0.0f) {
            layoutParams = new LinearLayout.LayoutParams((int) f2, -1);
        }
        this.B0.addView(view, i, layoutParams);
    }

    public boolean a() {
        return this.U0;
    }

    public void a(int i, int i2) {
        int i3 = this.E0;
        if (i >= i3) {
            i = i3 - 1;
        }
        MsgView msgView = (MsgView) this.B0.getChildAt(i).findViewById(R.id.rtv_msg_tip);
        if (msgView != null) {
            com.flyco.tablayout.c.b.b(msgView, i2);
            if (this.o1.get(i) == null || !this.o1.get(i).booleanValue()) {
                setMsgMargin(i, 2.0f, 2.0f);
                this.o1.put(i, true);
            }
        }
    }

    public MsgView a(int i) {
        int i2 = this.E0;
        if (i >= i2) {
            i = i2 - 1;
        }
        return (MsgView) this.B0.getChildAt(i).findViewById(R.id.rtv_msg_tip);
    }

    /* access modifiers changed from: protected */
    public int a(float f2) {
        return (int) ((f2 * this.t.getResources().getDisplayMetrics().density) + 0.5f);
    }
}