京东到家.apk(点击下载) / SlidingCommonTabLayout.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.PaintFlagsDrawFilter;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.OvershootInterpolator;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.flyco.tablayout.utils.FragmentChangeManager;
import com.flyco.tablayout.utils.UnreadMsgUtils;
import com.flyco.tablayout.widget.MsgView;
import java.util.ArrayList;

public class SlidingCommonTabLayout extends HorizontalScrollView implements ValueAnimator.AnimatorUpdateListener {
    private static final int STYLE_BLOCK = 2;
    private static final int STYLE_NORMAL = 0;
    private static final int STYLE_TRIANGLE = 1;
    public static final int TEXT_BOLD_BOTH = 2;
    public static final int TEXT_BOLD_NONE = 0;
    public static final int TEXT_BOLD_WHEN_SELECT = 1;
    private boolean invalidSelectIcon;
    private boolean isFilter;
    private Context mContext;
    private IndicatorPoint mCurrentP;
    private int mCurrentTab;
    private int mDividerColor;
    private float mDividerPadding;
    private Paint mDividerPaint;
    private float mDividerWidth;
    private FragmentChangeManager mFragmentChangeManager;
    private int mHeight;
    private int mIconGravity;
    private float mIconHeight;
    private float mIconMargin;
    private boolean mIconVisible;
    private float mIconWidth;
    private long mIndicatorAnimDuration;
    private boolean mIndicatorAnimEnable;
    private boolean mIndicatorBounceEnable;
    private int mIndicatorColor;
    private int mIndicatorColorEnd;
    private int mIndicatorColorStart;
    private float mIndicatorCornerRadius;
    private float mIndicatorCornerRadiusBottom;
    private float mIndicatorCornerRadiusLeft;
    private float mIndicatorCornerRadiusRight;
    private float mIndicatorCornerRadiusTop;
    private GradientDrawable mIndicatorDrawable;
    private int mIndicatorGravity;
    private float mIndicatorHeight;
    private float mIndicatorMarginBottom;
    private float mIndicatorMarginLeft;
    private float mIndicatorMarginRight;
    private float mIndicatorMarginTop;
    private Rect mIndicatorRect;
    private int mIndicatorStyle;
    private float mIndicatorWidth;
    private boolean mIndicatorWidthEqualTitle;
    private int mIndicatorWidthOverTitle;
    private SparseArray<Boolean> mInitSetMap;
    private OvershootInterpolator mInterpolator;
    private boolean mIsFirstDraw;
    private boolean mIsTextSizeChangeEnabled;
    private IndicatorPoint mLastP;
    private int mLastScrollX;
    private int mLastTab;
    private OnTabSelectListener mListener;
    private boolean mNeedFragmentSwitchAnimation;
    private boolean mNeedLazyLoad;
    private Paint mRectPaint;
    private boolean mShowTabBackground;
    private int mTabBgColor;
    private int mTabCount;
    private ArrayList<CustomTabEntity> mTabEntitys;
    private float mTabPadding;
    private Rect mTabRect;
    private boolean mTabSpaceEqual;
    private float mTabWidth;
    private LinearLayout mTabsContainer;
    private boolean mTextAllCaps;
    private int mTextBold;
    private Paint mTextPaint;
    private int mTextSelectColor;
    private float mTextSelectSize;
    private int mTextUnselectColor;
    private float mTextsize;
    private Paint mTrianglePaint;
    private Path mTrianglePath;
    private int mUnderlineColor;
    private int mUnderlineGravity;
    private float mUnderlineHeight;
    private ValueAnimator mValueAnimator;
    private int maxTabWidth;

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

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

    public SlidingCommonTabLayout(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.mTabEntitys = new ArrayList<>();
        this.mIndicatorRect = new Rect();
        this.mTabRect = new Rect();
        this.mIndicatorDrawable = new GradientDrawable();
        this.mRectPaint = new Paint(1);
        this.mDividerPaint = new Paint(1);
        this.mTrianglePaint = new Paint(1);
        this.mTrianglePath = new Path();
        this.mIndicatorStyle = 0;
        this.isFilter = false;
        this.mInterpolator = new OvershootInterpolator(1.5f);
        this.mIsFirstDraw = true;
        this.mTextPaint = new Paint(1);
        this.mInitSetMap = new SparseArray<>();
        this.mCurrentP = new IndicatorPoint();
        this.mLastP = new IndicatorPoint();
        setWillNotDraw(false);
        setClipChildren(false);
        setClipToPadding(false);
        this.mContext = context;
        this.mTabsContainer = new LinearLayout(context);
        addView(this.mTabsContainer);
        obtainAttributes(context, attributeSet);
        String attributeValue = attributeSet.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_height");
        if (!attributeValue.equals("-1") && !attributeValue.equals("-2")) {
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, new int[]{16842997});
            this.mHeight = obtainStyledAttributes.getDimensionPixelSize(0, -2);
            obtainStyledAttributes.recycle();
        }
        this.mValueAnimator = ValueAnimator.ofObject(new PointEvaluator(), this.mLastP, this.mCurrentP);
        this.mValueAnimator.addUpdateListener(this);
    }

    private void obtainAttributes(Context context, AttributeSet attributeSet) {
        float f;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.SlidingCommonTabLayout);
        this.mIndicatorStyle = obtainStyledAttributes.getInt(R.styleable.SlidingCommonTabLayout_tl_indicator_style, 0);
        this.mIndicatorColor = obtainStyledAttributes.getColor(R.styleable.SlidingCommonTabLayout_tl_indicator_color, Color.parseColor(this.mIndicatorStyle == 2 ? "#4B6A87" : "#ffffff"));
        this.mIndicatorColorStart = obtainStyledAttributes.getColor(R.styleable.SlidingCommonTabLayout_tl_indicator_start_color, -1);
        this.mIndicatorColorEnd = obtainStyledAttributes.getColor(R.styleable.SlidingCommonTabLayout_tl_indicator_end_color, -1);
        int i = R.styleable.SlidingCommonTabLayout_tl_indicator_height;
        int i2 = this.mIndicatorStyle;
        if (i2 == 1) {
            f = 4.0f;
        } else {
            f = (float) (i2 == 2 ? -1 : 2);
        }
        this.mIndicatorHeight = obtainStyledAttributes.getDimension(i, (float) dp2px(f));
        this.mIndicatorWidth = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_indicator_width, (float) dp2px(this.mIndicatorStyle == 1 ? 10.0f : -1.0f));
        this.mIndicatorCornerRadius = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_indicator_corner_radius, (float) dp2px(this.mIndicatorStyle == 2 ? -1.0f : 0.0f));
        this.mIndicatorCornerRadiusLeft = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_indicator_corner_radius_left, (float) dp2px(this.mIndicatorStyle == 2 ? -1.0f : 0.0f));
        this.mIndicatorCornerRadiusTop = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_indicator_corner_radius_top, (float) dp2px(this.mIndicatorStyle == 2 ? -1.0f : 0.0f));
        this.mIndicatorCornerRadiusRight = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_indicator_corner_radius_right, (float) dp2px(this.mIndicatorStyle == 2 ? -1.0f : 0.0f));
        this.mIndicatorCornerRadiusBottom = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_indicator_corner_radius_bottom, (float) dp2px(this.mIndicatorStyle == 2 ? -1.0f : 0.0f));
        this.mIndicatorMarginLeft = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_indicator_margin_left, (float) dp2px(0.0f));
        float f2 = 7.0f;
        this.mIndicatorMarginTop = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_indicator_margin_top, (float) dp2px(this.mIndicatorStyle == 2 ? 7.0f : 0.0f));
        this.mIndicatorMarginRight = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_indicator_margin_right, (float) dp2px(0.0f));
        int i3 = R.styleable.SlidingCommonTabLayout_tl_indicator_margin_bottom;
        if (this.mIndicatorStyle != 2) {
            f2 = 0.0f;
        }
        this.mIndicatorMarginBottom = obtainStyledAttributes.getDimension(i3, (float) dp2px(f2));
        this.mIndicatorAnimEnable = obtainStyledAttributes.getBoolean(R.styleable.SlidingCommonTabLayout_tl_indicator_anim_enable, true);
        this.mIndicatorBounceEnable = obtainStyledAttributes.getBoolean(R.styleable.SlidingCommonTabLayout_tl_indicator_bounce_enable, true);
        this.mIndicatorWidthEqualTitle = obtainStyledAttributes.getBoolean(R.styleable.SlidingCommonTabLayout_tl_indicator_width_equal_title, false);
        this.mIndicatorAnimDuration = (long) obtainStyledAttributes.getInt(R.styleable.SlidingCommonTabLayout_tl_indicator_anim_duration, -1);
        this.mIndicatorGravity = obtainStyledAttributes.getInt(R.styleable.SlidingCommonTabLayout_tl_indicator_gravity, 80);
        this.mUnderlineColor = obtainStyledAttributes.getColor(R.styleable.SlidingCommonTabLayout_tl_underline_color, Color.parseColor("#ffffff"));
        this.mUnderlineHeight = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_underline_height, (float) dp2px(0.0f));
        this.mUnderlineGravity = obtainStyledAttributes.getInt(R.styleable.SlidingCommonTabLayout_tl_underline_gravity, 80);
        this.mDividerColor = obtainStyledAttributes.getColor(R.styleable.SlidingCommonTabLayout_tl_divider_color, Color.parseColor("#ffffff"));
        this.mDividerWidth = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_divider_width, (float) dp2px(0.0f));
        this.mDividerPadding = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_divider_padding, (float) dp2px(12.0f));
        this.mTextsize = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_textsize, (float) sp2px(13.0f));
        this.mTextSelectSize = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_textSelectedSize, (float) sp2px(13.0f));
        this.mTextSelectColor = obtainStyledAttributes.getColor(R.styleable.SlidingCommonTabLayout_tl_textSelectColor, Color.parseColor("#ffffff"));
        this.mTextUnselectColor = obtainStyledAttributes.getColor(R.styleable.SlidingCommonTabLayout_tl_textUnselectColor, Color.parseColor("#AAffffff"));
        this.mTextBold = obtainStyledAttributes.getInt(R.styleable.SlidingCommonTabLayout_tl_textBold, 0);
        this.mTextAllCaps = obtainStyledAttributes.getBoolean(R.styleable.SlidingCommonTabLayout_tl_textAllCaps, false);
        this.mShowTabBackground = obtainStyledAttributes.getBoolean(R.styleable.SlidingCommonTabLayout_tl_show_tab_background, false);
        this.mTabBgColor = obtainStyledAttributes.getColor(R.styleable.SlidingCommonTabLayout_tl_tab_background_color, Color.parseColor("#ffffff"));
        this.mIconVisible = obtainStyledAttributes.getBoolean(R.styleable.SlidingCommonTabLayout_tl_iconVisible, true);
        this.mIconGravity = obtainStyledAttributes.getInt(R.styleable.SlidingCommonTabLayout_tl_iconGravity, 48);
        this.mIconWidth = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_iconWidth, (float) dp2px(0.0f));
        this.mIconHeight = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_iconHeight, (float) dp2px(0.0f));
        this.mIconMargin = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_iconMargin, (float) dp2px(2.5f));
        this.mTabSpaceEqual = obtainStyledAttributes.getBoolean(R.styleable.SlidingCommonTabLayout_tl_tab_space_equal, true);
        this.mTabWidth = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_tab_width, (float) dp2px(-1.0f));
        this.mTabPadding = obtainStyledAttributes.getDimension(R.styleable.SlidingCommonTabLayout_tl_tab_padding, (float) ((this.mTabSpaceEqual || this.mTabWidth > 0.0f) ? dp2px(0.0f) : dp2px(10.0f)));
        obtainStyledAttributes.recycle();
    }

    public boolean isNeedLazyLoad() {
        return this.mNeedLazyLoad;
    }

    public void setNeedLazyLoad(boolean z) {
        this.mNeedLazyLoad = z;
    }

    public void setFragmentSwitchAnimation(boolean z) {
        this.mNeedFragmentSwitchAnimation = z;
    }

    public void setTabData(ArrayList<CustomTabEntity> arrayList) {
        if (arrayList == null || arrayList.size() == 0) {
            throw new IllegalStateException("TabEntitys can not be NULL or EMPTY !");
        }
        this.mTabEntitys.clear();
        this.mTabEntitys.addAll(arrayList);
        notifyDataSetChanged();
    }

    public void setTabData(ArrayList<CustomTabEntity> arrayList, FragmentActivity fragmentActivity, int i, ArrayList<Fragment> arrayList2) {
        this.mFragmentChangeManager = new FragmentChangeManager(fragmentActivity.getSupportFragmentManager(), i, arrayList2);
        this.mFragmentChangeManager.setFragmentSwitchAnimation(this.mNeedFragmentSwitchAnimation);
        setTabData(arrayList);
    }

    public void setTabData(ArrayList<CustomTabEntity> arrayList, FragmentManager fragmentManager, int i, ArrayList<Fragment> arrayList2) {
        this.mFragmentChangeManager = new FragmentChangeManager(fragmentManager, i, arrayList2);
        this.mFragmentChangeManager.setFragmentSwitchAnimation(this.mNeedFragmentSwitchAnimation);
        setTabData(arrayList);
    }

    public void notifyDataSetChanged() {
        View view;
        this.mTabsContainer.removeAllViews();
        this.mTabCount = this.mTabEntitys.size();
        for (int i = 0; i < this.mTabCount; i++) {
            int i2 = this.mIconGravity;
            if (i2 == 3) {
                view = View.inflate(this.mContext, R.layout.layout_tab_left, null);
            } else if (i2 == 5) {
                view = View.inflate(this.mContext, R.layout.layout_tab_right, null);
            } else if (i2 == 80) {
                view = View.inflate(this.mContext, R.layout.layout_tab_bottom, null);
            } else {
                view = View.inflate(this.mContext, R.layout.layout_tab_top, null);
            }
            view.setTag(Integer.valueOf(i));
            addTab(i, view);
        }
        updateTabStyles();
    }

    public void setInvalidSelectIcon(boolean z) {
        this.invalidSelectIcon = z;
    }

    private void addTab(int i, View view) {
        TextView textView = (TextView) view.findViewById(R.id.tv_tab_title);
        textView.setText(this.mTabEntitys.get(i).getTabTitle());
        if (this.maxTabWidth > 0) {
            textView.setMaxLines(1);
            textView.setEllipsize(TextUtils.TruncateAt.END);
            textView.setMaxWidth(this.maxTabWidth);
        }
        ImageView imageView = (ImageView) view.findViewById(R.id.iv_tab_icon);
        if (!this.invalidSelectIcon) {
            imageView.setImageResource(this.mTabEntitys.get(i).getTabUnselectedIcon());
        }
        view.setOnClickListener(new View.OnClickListener() {
            /* class com.flyco.tablayout.SlidingCommonTabLayout.AnonymousClass1 */

            public void onClick(View view) {
                int intValue = ((Integer) view.getTag()).intValue();
                if (SlidingCommonTabLayout.this.mCurrentTab != intValue) {
                    SlidingCommonTabLayout.this.setCurrentTab(intValue);
                    if (SlidingCommonTabLayout.this.mListener != null) {
                        SlidingCommonTabLayout.this.mListener.onTabSelect(intValue);
                    }
                } else if (SlidingCommonTabLayout.this.mListener != null) {
                    SlidingCommonTabLayout.this.mListener.onTabReselect(intValue);
                }
            }
        });
        LinearLayout.LayoutParams layoutParams = this.mTabSpaceEqual ? new LinearLayout.LayoutParams(0, -1, 1.0f) : new LinearLayout.LayoutParams(-2, -1);
        float f = this.mTabWidth;
        if (f > 0.0f) {
            layoutParams = new LinearLayout.LayoutParams((int) f, -1);
        }
        this.mTabsContainer.addView(view, i, layoutParams);
    }

    private void updateTabStyles() {
        int i = 0;
        while (i < this.mTabCount) {
            View childAt = this.mTabsContainer.getChildAt(i);
            float f = this.mTabPadding;
            childAt.setPadding((int) f, 0, (int) f, 0);
            TextView textView = (TextView) childAt.findViewById(R.id.tv_tab_title);
            textView.setTextColor(i == this.mCurrentTab ? this.mTextSelectColor : this.mTextUnselectColor);
            if (this.mIsTextSizeChangeEnabled) {
                textView.setTextSize(0, i == this.mCurrentTab ? this.mTextSelectSize : this.mTextsize);
            } else {
                textView.setTextSize(0, this.mTextsize);
            }
            if (this.mTextAllCaps) {
                textView.setText(textView.getText().toString().toUpperCase());
            }
            int i2 = this.mTextBold;
            boolean z = true;
            if (i2 == 2) {
                textView.getPaint().setFakeBoldText(true);
            } else if (i2 == 0) {
                textView.getPaint().setFakeBoldText(false);
            } else if (i2 == 1) {
                TextPaint paint = textView.getPaint();
                if (i != getCurrentTab()) {
                    z = false;
                }
                paint.setFakeBoldText(z);
            }
            ImageView imageView = (ImageView) childAt.findViewById(R.id.iv_tab_icon);
            if (this.mIconVisible) {
                imageView.setVisibility(0);
                CustomTabEntity customTabEntity = this.mTabEntitys.get(i);
                if (!this.invalidSelectIcon) {
                    imageView.setImageResource(i == this.mCurrentTab ? customTabEntity.getTabSelectedIcon() : customTabEntity.getTabUnselectedIcon());
                    float f2 = this.mIconWidth;
                    int i3 = -2;
                    int i4 = f2 <= 0.0f ? -2 : (int) f2;
                    float f3 = this.mIconHeight;
                    if (f3 > 0.0f) {
                        i3 = (int) f3;
                    }
                    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(i4, i3);
                    int i5 = this.mIconGravity;
                    if (i5 == 3) {
                        layoutParams.rightMargin = (int) this.mIconMargin;
                    } else if (i5 == 5) {
                        layoutParams.leftMargin = (int) this.mIconMargin;
                    } else if (i5 == 80) {
                        layoutParams.topMargin = (int) this.mIconMargin;
                    } else {
                        layoutParams.bottomMargin = (int) this.mIconMargin;
                    }
                    imageView.setLayoutParams(layoutParams);
                }
            } else {
                imageView.setVisibility(8);
            }
            i++;
        }
    }

    private void updateTabSelection(int i) {
        int i2 = 0;
        while (i2 < this.mTabCount) {
            View childAt = this.mTabsContainer.getChildAt(i2);
            boolean z = i2 == i;
            TextView textView = (TextView) childAt.findViewById(R.id.tv_tab_title);
            textView.setTextColor(z ? this.mTextSelectColor : this.mTextUnselectColor);
            if (this.mIsTextSizeChangeEnabled) {
                textView.setTextSize(0, z ? this.mTextSelectSize : this.mTextsize);
            }
            ImageView imageView = (ImageView) childAt.findViewById(R.id.iv_tab_icon);
            CustomTabEntity customTabEntity = this.mTabEntitys.get(i2);
            if (!this.invalidSelectIcon) {
                imageView.setImageResource(z ? customTabEntity.getTabSelectedIcon() : customTabEntity.getTabUnselectedIcon());
            }
            if (this.mTextBold == 1) {
                textView.getPaint().setFakeBoldText(z);
            }
            i2++;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void calcOffset() {
        View childAt = this.mTabsContainer.getChildAt(this.mCurrentTab);
        this.mCurrentP.left = (float) childAt.getLeft();
        this.mCurrentP.right = (float) childAt.getRight();
        View childAt2 = this.mTabsContainer.getChildAt(this.mLastTab);
        this.mLastP.left = (float) childAt2.getLeft();
        this.mLastP.right = (float) childAt2.getRight();
        if (this.mLastP.left == this.mCurrentP.left && this.mLastP.right == this.mCurrentP.right) {
            invalidate();
            return;
        }
        this.mValueAnimator.setObjectValues(this.mLastP, this.mCurrentP);
        if (this.mIndicatorBounceEnable) {
            this.mValueAnimator.setInterpolator(this.mInterpolator);
        }
        if (this.mIndicatorAnimDuration < 0) {
            this.mIndicatorAnimDuration = this.mIndicatorBounceEnable ? 500 : 250;
        }
        this.mValueAnimator.setDuration(this.mIndicatorAnimDuration);
        this.mValueAnimator.start();
    }

    private void calcIndicatorRect() {
        View childAt = this.mTabsContainer.getChildAt(this.mCurrentTab);
        Rect rect = this.mIndicatorRect;
        int left = (int) ((float) childAt.getLeft());
        rect.left = left;
        int right = (int) ((float) childAt.getRight());
        rect.right = right;
        Rect rect2 = this.mTabRect;
        rect2.left = left;
        rect2.right = right;
        if (this.mIndicatorWidth < 0.0f) {
            handleEqualTitle();
            return;
        }
        float left2 = ((float) childAt.getLeft()) + ((((float) childAt.getWidth()) - this.mIndicatorWidth) / 2.0f);
        Rect rect3 = this.mIndicatorRect;
        rect3.left = (int) left2;
        rect3.right = (int) (((float) rect3.left) + this.mIndicatorWidth);
    }

    public void setIndicatorWidthOverTitle(int i) {
        this.mIndicatorWidthOverTitle = i;
    }

    private void handleEqualTitle() {
        if (this.mIndicatorWidthOverTitle > 0) {
            Rect rect = this.mIndicatorRect;
            rect.left = (int) (((float) rect.left) + (this.mTabPadding - ((float) this.mIndicatorWidthOverTitle)));
            Rect rect2 = this.mIndicatorRect;
            rect2.right = (int) (((float) rect2.right) - (this.mTabPadding - ((float) this.mIndicatorWidthOverTitle)));
        } else if (this.mIndicatorWidthEqualTitle) {
            Rect rect3 = this.mIndicatorRect;
            rect3.left = (int) (((float) rect3.left) + this.mTabPadding);
            Rect rect4 = this.mIndicatorRect;
            rect4.right = (int) (((float) rect4.right) - this.mTabPadding);
        }
    }

    public void onAnimationUpdate(ValueAnimator valueAnimator) {
        View childAt = this.mTabsContainer.getChildAt(this.mCurrentTab);
        IndicatorPoint indicatorPoint = (IndicatorPoint) valueAnimator.getAnimatedValue();
        this.mIndicatorRect.left = (int) indicatorPoint.left;
        this.mIndicatorRect.right = (int) indicatorPoint.right;
        if (this.mIndicatorWidth < 0.0f) {
            handleEqualTitle();
        } else {
            float width = indicatorPoint.left + ((((float) childAt.getWidth()) - this.mIndicatorWidth) / 2.0f);
            Rect rect = this.mIndicatorRect;
            rect.left = (int) width;
            rect.right = (int) (((float) rect.left) + this.mIndicatorWidth);
        }
        invalidate();
    }

    private boolean hasGradientColor() {
        return (this.mIndicatorColorEnd == -1 || this.mIndicatorColorStart == -1) ? false : true;
    }

    private void setIndicatorColor() {
        if (hasGradientColor()) {
            this.mIndicatorDrawable = new GradientDrawable(GradientDrawable.Orientation.TL_BR, new int[]{this.mIndicatorColorStart, this.mIndicatorColorEnd});
            return;
        }
        this.mIndicatorDrawable.setColor(this.mIndicatorColor);
    }

    private boolean useTheSameRadius() {
        float f = this.mIndicatorCornerRadius;
        return (f == -1.0f || f == 0.0f) ? false : true;
    }

    private void setIndicatorRadius() {
        if (useTheSameRadius()) {
            this.mIndicatorDrawable.setCornerRadius(this.mIndicatorCornerRadius);
            return;
        }
        this.mIndicatorDrawable.setShape(0);
        GradientDrawable gradientDrawable = this.mIndicatorDrawable;
        float f = this.mIndicatorCornerRadiusTop;
        float f2 = this.mIndicatorCornerRadiusRight;
        float f3 = this.mIndicatorCornerRadiusBottom;
        float f4 = this.mIndicatorCornerRadiusLeft;
        gradientDrawable.setCornerRadii(new float[]{f, f, f2, f2, f3, f3, f4, f4});
    }

    /* access modifiers changed from: protected */
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (!isInEditMode() && this.mTabCount > 0) {
            int height = getHeight();
            int paddingLeft = getPaddingLeft();
            float f = this.mDividerWidth;
            if (f > 0.0f) {
                this.mDividerPaint.setStrokeWidth(f);
                this.mDividerPaint.setColor(this.mDividerColor);
                for (int i = 0; i < this.mTabCount - 1; i++) {
                    View childAt = this.mTabsContainer.getChildAt(i);
                    canvas.drawLine((float) (childAt.getRight() + paddingLeft), this.mDividerPadding, (float) (childAt.getRight() + paddingLeft), ((float) height) - this.mDividerPadding, this.mDividerPaint);
                }
            }
            if (this.mUnderlineHeight > 0.0f) {
                this.mRectPaint.setColor(this.mUnderlineColor);
                if (this.mUnderlineGravity == 80) {
                    float f2 = (float) height;
                    canvas.drawRect((float) paddingLeft, f2 - this.mUnderlineHeight, (float) (this.mTabsContainer.getWidth() + paddingLeft), f2, this.mRectPaint);
                } else {
                    canvas.drawRect((float) paddingLeft, 0.0f, (float) (this.mTabsContainer.getWidth() + paddingLeft), this.mUnderlineHeight, this.mRectPaint);
                }
            }
            if (!this.mIndicatorAnimEnable) {
                calcIndicatorRect();
            } else if (this.mIsFirstDraw) {
                this.mIsFirstDraw = false;
                calcIndicatorRect();
            }
            int i2 = this.mIndicatorStyle;
            if (i2 == 1) {
                if (this.mIndicatorHeight > 0.0f) {
                    this.mTrianglePaint.setColor(this.mIndicatorColor);
                    this.mTrianglePath.reset();
                    float f3 = (float) height;
                    this.mTrianglePath.moveTo((float) (this.mIndicatorRect.left + paddingLeft), f3);
                    this.mTrianglePath.lineTo((float) ((this.mIndicatorRect.left / 2) + paddingLeft + (this.mIndicatorRect.right / 2)), f3 - this.mIndicatorHeight);
                    this.mTrianglePath.lineTo((float) (paddingLeft + this.mIndicatorRect.right), f3);
                    this.mTrianglePath.close();
                    canvas.drawPath(this.mTrianglePath, this.mTrianglePaint);
                }
            } else if (i2 == 2) {
                if (this.mIndicatorHeight < 0.0f) {
                    this.mIndicatorHeight = (((float) height) - this.mIndicatorMarginTop) - this.mIndicatorMarginBottom;
                }
                float f4 = this.mIndicatorHeight;
                if (f4 > 0.0f) {
                    float f5 = this.mIndicatorCornerRadius;
                    if (f5 < 0.0f || f5 > f4 / 2.0f) {
                        this.mIndicatorCornerRadius = this.mIndicatorHeight / 2.0f;
                    }
                    setIndicatorColor();
                    this.mIndicatorDrawable.setBounds(((int) this.mIndicatorMarginLeft) + paddingLeft + this.mIndicatorRect.left, (int) this.mIndicatorMarginTop, (int) (((float) (paddingLeft + this.mIndicatorRect.right)) - this.mIndicatorMarginRight), (int) (this.mIndicatorMarginTop + this.mIndicatorHeight));
                    setIndicatorRadius();
                    this.mIndicatorDrawable.draw(canvas);
                }
            } else {
                if (this.mShowTabBackground) {
                    drawTabBgIndicator(canvas, paddingLeft);
                }
                if (this.mIndicatorHeight > 0.0f) {
                    setIndicatorColor();
                    if (this.mIndicatorGravity == 80) {
                        this.mIndicatorDrawable.setBounds(((int) this.mIndicatorMarginLeft) + paddingLeft + this.mIndicatorRect.left, (height - ((int) this.mIndicatorHeight)) - ((int) this.mIndicatorMarginBottom), (paddingLeft + this.mIndicatorRect.right) - ((int) this.mIndicatorMarginRight), height - ((int) this.mIndicatorMarginBottom));
                    } else {
                        this.mIndicatorDrawable.setBounds(((int) this.mIndicatorMarginLeft) + paddingLeft + this.mIndicatorRect.left, (int) this.mIndicatorMarginTop, (paddingLeft + this.mIndicatorRect.right) - ((int) this.mIndicatorMarginRight), ((int) this.mIndicatorHeight) + ((int) this.mIndicatorMarginTop));
                    }
                    setIndicatorRadius();
                    this.mIndicatorDrawable.draw(canvas);
                }
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void changeFragment() {
        FragmentChangeManager fragmentChangeManager = this.mFragmentChangeManager;
        if (fragmentChangeManager != null) {
            fragmentChangeManager.setFragments(this.mCurrentTab);
        }
    }

    private void drawTabBgIndicator(Canvas canvas, int i) {
        int i2;
        GradientDrawable gradientDrawable = new GradientDrawable();
        gradientDrawable.setColor(this.mTabBgColor);
        try {
            View childAt = this.mTabsContainer.getChildAt(this.mCurrentTab);
            i2 = ((childAt.getRight() - childAt.getLeft()) - (this.mIndicatorRect.right - this.mIndicatorRect.left)) / 2;
        } catch (Exception e) {
            e.printStackTrace();
            i2 = 0;
        }
        float f = (float) i2;
        int i3 = (int) (((((float) i) + this.mIndicatorMarginLeft) + ((float) this.mIndicatorRect.left)) - f);
        int i4 = (int) ((((float) (i + this.mIndicatorRect.right)) - this.mIndicatorMarginRight) + f);
        gradientDrawable.setBounds(i3, this.mTabRect.top, i4, getHeight());
        float dp2px = (float) dp2px(6.0f);
        gradientDrawable.setShape(0);
        gradientDrawable.setCornerRadii(new float[]{dp2px, dp2px, dp2px, dp2px, 0.0f, 0.0f, 0.0f, 0.0f});
        gradientDrawable.draw(canvas);
        canvas.setDrawFilter(new PaintFlagsDrawFilter(0, 3));
        drawRightTabBgArc(canvas, i4, getHeight(), dp2px);
        drawLeftTabBgArc(canvas, i3, getHeight(), dp2px);
    }

    private void drawRightTabBgArc(Canvas canvas, int i, int i2, float f) {
        Paint paint = new Paint();
        paint.setColor(this.mTabBgColor);
        Path path = new Path();
        float f2 = (float) i;
        float f3 = (float) i2;
        path.moveTo(f2, f3);
        float f4 = f * 2.0f;
        float f5 = f3 - f4;
        path.lineTo(f2, f5);
        path.arcTo(new RectF(f2, f5, f4 + f2, f3), 180.0f, -90.0f);
        canvas.drawPath(path, paint);
    }

    private void drawLeftTabBgArc(Canvas canvas, int i, int i2, float f) {
        Paint paint = new Paint();
        paint.setColor(this.mTabBgColor);
        Path path = new Path();
        float f2 = (float) i;
        float f3 = (float) i2;
        path.moveTo(f2, f3);
        float f4 = f * 2.0f;
        float f5 = f3 - f4;
        path.lineTo(f2, f5);
        path.arcTo(new RectF(f2 - f4, f5, f2, f3), 0.0f, 90.0f);
        canvas.drawPath(path, paint);
    }

    public void setCurrentTab(int i) {
        this.mLastTab = this.mCurrentTab;
        this.mCurrentTab = i;
        updateTabSelection(this.mCurrentTab);
        scrollToCurrentTab();
        if (!this.mIndicatorAnimEnable) {
            invalidate();
        } else if (this.mIsTextSizeChangeEnabled) {
            new Handler().postDelayed(new Runnable() {
                /* class com.flyco.tablayout.SlidingCommonTabLayout.AnonymousClass2 */

                public void run() {
                    SlidingCommonTabLayout.this.calcOffset();
                }
            }, 50);
        } else {
            calcOffset();
        }
        if (this.mNeedLazyLoad) {
            new Handler().postDelayed(new Runnable() {
                /* class com.flyco.tablayout.SlidingCommonTabLayout.AnonymousClass3 */

                public void run() {
                    SlidingCommonTabLayout.this.changeFragment();
                }
            }, this.mIndicatorAnimDuration);
            return;
        }
        changeFragment();
    }

    public long getTabAnimationDuration() {
        return this.mIndicatorAnimDuration;
    }

    private void scrollToCurrentTab() {
        if (this.mTabCount > 0) {
            int left = this.mTabsContainer.getChildAt(this.mCurrentTab).getLeft();
            if (this.mCurrentTab > 0) {
                int width = left - ((getWidth() / 2) - getPaddingLeft());
                if (!this.mIsTextSizeChangeEnabled) {
                    calcIndicatorRect();
                }
                left = width + ((this.mTabRect.right - this.mTabRect.left) / 2);
            }
            if (left != this.mLastScrollX) {
                this.mLastScrollX = left;
                scrollTo(left, 0);
            }
        }
    }

    public void setIndicatorStyle(int i) {
        this.mIndicatorStyle = i;
        invalidate();
    }

    public void setTabPadding(float f) {
        this.mTabPadding = (float) dp2px(f);
        updateTabStyles();
    }

    public void setTabSpaceEqual(boolean z) {
        this.mTabSpaceEqual = z;
        updateTabStyles();
    }

    public void setTabWidth(float f) {
        this.mTabWidth = (float) dp2px(f);
        updateTabStyles();
    }

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

    public void setIndicatorHeight(float f) {
        this.mIndicatorHeight = (float) dp2px(f);
        invalidate();
    }

    public void setIndicatorWidth(float f) {
        this.mIndicatorWidth = (float) dp2px(f);
        invalidate();
    }

    public void setIndicatorCornerRadius(float f) {
        this.mIndicatorCornerRadius = (float) dp2px(f);
        invalidate();
    }

    public void setIndicatorGravity(int i) {
        this.mIndicatorGravity = i;
        invalidate();
    }

    public void setIndicatorMargin(float f, float f2, float f3, float f4) {
        this.mIndicatorMarginLeft = (float) dp2px(f);
        this.mIndicatorMarginTop = (float) dp2px(f2);
        this.mIndicatorMarginRight = (float) dp2px(f3);
        this.mIndicatorMarginBottom = (float) dp2px(f4);
        invalidate();
    }

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

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

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

    public void setUnderlineColor(int i) {
        this.mUnderlineColor = i;
        invalidate();
    }

    public void setUnderlineHeight(float f) {
        this.mUnderlineHeight = (float) dp2px(f);
        invalidate();
    }

    public void setUnderlineGravity(int i) {
        this.mUnderlineGravity = i;
        invalidate();
    }

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

    public void setDividerWidth(float f) {
        this.mDividerWidth = (float) dp2px(f);
        invalidate();
    }

    public void setDividerPadding(float f) {
        this.mDividerPadding = (float) dp2px(f);
        invalidate();
    }

    public void setTextsize(float f) {
        this.mTextsize = (float) sp2px(f);
        updateTabStyles();
    }

    public void setSelectedTextSize(float f, boolean z) {
        this.mTextSelectSize = (float) sp2px(f);
        this.mIsTextSizeChangeEnabled = z;
        updateTabStyles();
    }

    public void setTextSelectColor(int i) {
        this.mTextSelectColor = i;
        updateTabStyles();
    }

    public void setTextUnselectColor(int i) {
        this.mTextUnselectColor = i;
        updateTabStyles();
    }

    public void setTextBold(int i) {
        this.mTextBold = i;
        updateTabStyles();
    }

    public void setIconVisible(boolean z) {
        this.mIconVisible = z;
        updateTabStyles();
    }

    public void setIconGravity(int i) {
        this.mIconGravity = i;
        notifyDataSetChanged();
    }

    public void setIconWidth(float f) {
        this.mIconWidth = (float) dp2px(f);
        updateTabStyles();
    }

    public void setIconHeight(float f) {
        this.mIconHeight = (float) dp2px(f);
        updateTabStyles();
    }

    public void setIconMargin(float f) {
        this.mIconMargin = (float) dp2px(f);
        updateTabStyles();
    }

    public void setTextAllCaps(boolean z) {
        this.mTextAllCaps = z;
        updateTabStyles();
    }

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

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

    public int getIndicatorStyle() {
        return this.mIndicatorStyle;
    }

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

    public boolean isTabSpaceEqual() {
        return this.mTabSpaceEqual;
    }

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

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

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

    public float getIndicatorWidth() {
        return this.mIndicatorWidth;
    }

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

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

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

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

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

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

    public boolean isIndicatorAnimEnable() {
        return this.mIndicatorAnimEnable;
    }

    public boolean isIndicatorBounceEnable() {
        return this.mIndicatorBounceEnable;
    }

    public int getUnderlineColor() {
        return this.mUnderlineColor;
    }

    public float getUnderlineHeight() {
        return this.mUnderlineHeight;
    }

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

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

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

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

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

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

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

    public boolean isTextAllCaps() {
        return this.mTextAllCaps;
    }

    public int getIconGravity() {
        return this.mIconGravity;
    }

    public float getIconWidth() {
        return this.mIconWidth;
    }

    public float getIconHeight() {
        return this.mIconHeight;
    }

    public float getIconMargin() {
        return this.mIconMargin;
    }

    public boolean isIconVisible() {
        return this.mIconVisible;
    }

    public ImageView getIconView(int i) {
        return (ImageView) this.mTabsContainer.getChildAt(i).findViewById(R.id.iv_tab_icon);
    }

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

    public void showMsg(int i, int i2) {
        int i3 = this.mTabCount;
        if (i >= i3) {
            i = i3 - 1;
        }
        MsgView msgView = (MsgView) this.mTabsContainer.getChildAt(i).findViewById(R.id.rtv_msg_tip);
        if (msgView != null) {
            UnreadMsgUtils.show(msgView, i2);
            if (this.mInitSetMap.get(i) == null || !this.mInitSetMap.get(i).booleanValue()) {
                if (!this.mIconVisible) {
                    setMsgMargin(i, 2.0f, 2.0f);
                } else {
                    int i4 = this.mIconGravity;
                    setMsgMargin(i, 0.0f, (i4 == 3 || i4 == 5) ? 4.0f : 0.0f);
                }
                this.mInitSetMap.put(i, true);
            }
        }
    }

    public void showDot(int i) {
        int i2 = this.mTabCount;
        if (i >= i2) {
            i = i2 - 1;
        }
        showMsg(i, 0);
    }

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

    public void setMsgMargin(int i, float f, float f2) {
        int i2 = this.mTabCount;
        if (i >= i2) {
            i = i2 - 1;
        }
        View childAt = this.mTabsContainer.getChildAt(i);
        MsgView msgView = (MsgView) childAt.findViewById(R.id.rtv_msg_tip);
        if (msgView != null) {
            this.mTextPaint.setTextSize(this.mTextsize);
            this.mTextPaint.measureText(((TextView) childAt.findViewById(R.id.tv_tab_title)).getText().toString());
            float descent = this.mTextPaint.descent() - this.mTextPaint.ascent();
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) msgView.getLayoutParams();
            float f3 = this.mIconHeight;
            float f4 = 0.0f;
            if (this.mIconVisible) {
                if (f3 <= 0.0f) {
                    f3 = (float) this.mContext.getResources().getDrawable(this.mTabEntitys.get(i).getTabSelectedIcon()).getIntrinsicHeight();
                }
                f4 = this.mIconMargin;
            }
            int i3 = this.mIconGravity;
            if (i3 == 48 || i3 == 80) {
                marginLayoutParams.leftMargin = dp2px(f);
                int i4 = this.mHeight;
                marginLayoutParams.topMargin = i4 > 0 ? (((int) (((((float) i4) - descent) - f3) - f4)) / 2) - dp2px(f2) : dp2px(f2);
            } else {
                marginLayoutParams.leftMargin = dp2px(f);
                int i5 = this.mHeight;
                marginLayoutParams.topMargin = i5 > 0 ? (((int) (((float) i5) - Math.max(descent, f3))) / 2) - dp2px(f2) : dp2px(f2);
            }
            msgView.setLayoutParams(marginLayoutParams);
        }
    }

    public MsgView getMsgView(int i) {
        int i2 = this.mTabCount;
        if (i >= i2) {
            i = i2 - 1;
        }
        return (MsgView) this.mTabsContainer.getChildAt(i).findViewById(R.id.rtv_msg_tip);
    }

    public void setOnTabSelectListener(OnTabSelectListener onTabSelectListener) {
        this.mListener = onTabSelectListener;
    }

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

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

    public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        if (motionEvent.getAction() == 0 && Build.VERSION.SDK_INT >= 21) {
            startNestedScroll(2);
        }
        return super.onInterceptTouchEvent(motionEvent);
    }

    /* access modifiers changed from: package-private */
    public class IndicatorPoint {
        public float left;
        public float right;

        IndicatorPoint() {
        }
    }

    class PointEvaluator implements TypeEvaluator<IndicatorPoint> {
        PointEvaluator() {
        }

        public IndicatorPoint evaluate(float f, IndicatorPoint indicatorPoint, IndicatorPoint indicatorPoint2) {
            float f2 = indicatorPoint.left + ((indicatorPoint2.left - indicatorPoint.left) * f);
            float f3 = indicatorPoint.right + (f * (indicatorPoint2.right - indicatorPoint.right));
            IndicatorPoint indicatorPoint3 = new IndicatorPoint();
            indicatorPoint3.left = f2;
            indicatorPoint3.right = f3;
            return indicatorPoint3;
        }
    }

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

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

    public void setTabMaxWidth(int i) {
        this.maxTabWidth = i;
    }
}