得物.apk(点击下载) / SlidingTabLayout.java


package com.flyco.tablayout;

import a1.a;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
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.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.sensorsdata.analytics.android.sdk.SensorsDataAutoTrackHelper;
import com.sensorsdata.analytics.android.sdk.SensorsDataInstrumented;
import com.shizhuang.duapp.R;
import o5.i;

public class SlidingTabLayout extends HorizontalScrollView implements ViewPager.OnPageChangeListener {
    public int A;
    public boolean B;
    public int C;
    public float D;
    public int E;
    public int F;
    public float G;
    public float H;
    public float I;
    public int J;
    public int K;
    public boolean L;
    public boolean M;
    public int N;
    public float O;
    public Paint P;
    public OnTabSelectListener Q;
    public Context b;

    /* renamed from: c  reason: collision with root package name */
    public ViewPager f4358c;
    public LinearLayout d;
    public int e;
    public float f;

    /* renamed from: g  reason: collision with root package name */
    public int f4359g;

    /* renamed from: h  reason: collision with root package name */
    public Rect f4360h;
    public Rect i;
    public GradientDrawable j;
    public Paint k;
    public Paint l;
    public Paint m;
    public Path n;
    public int o;
    public float p;

    /* renamed from: q  reason: collision with root package name */
    public boolean f4361q;
    public float r;
    public int s;
    public float t;

    /* renamed from: u  reason: collision with root package name */
    public float f4362u;

    /* renamed from: v  reason: collision with root package name */
    public float f4363v;
    public float w;
    public float x;
    public float y;
    public float z;

    public interface CustomTabProvider {
        View getCustomTabView(ViewGroup viewGroup, int i);

        void tabSelect(View view);

        void tabUnselect(View view);
    }

    public class InnerPagerAdapter extends FragmentPagerAdapter {
        @Override // androidx.viewpager.widget.PagerAdapter, androidx.fragment.app.FragmentPagerAdapter
        public void destroyItem(ViewGroup viewGroup, int i, Object obj) {
        }

        @Override // androidx.viewpager.widget.PagerAdapter
        public int getCount() {
            throw null;
        }

        @Override // androidx.fragment.app.FragmentPagerAdapter
        public Fragment getItem(int i) {
            throw null;
        }

        @Override // androidx.viewpager.widget.PagerAdapter
        public int getItemPosition(Object obj) {
            return -2;
        }

        @Override // androidx.viewpager.widget.PagerAdapter
        public CharSequence getPageTitle(int i) {
            throw null;
        }
    }

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

    public final void a() {
        View childAt = this.d.getChildAt(this.e);
        float left = (float) childAt.getLeft();
        float right = (float) childAt.getRight();
        if (this.o == 0 && this.B) {
            this.P.setTextSize(this.I);
            this.O = ((right - left) - this.P.measureText(((TextView) childAt.findViewById(R.id.tv_tab_title)).getText().toString())) / 2.0f;
        }
        int i3 = this.e;
        if (i3 < this.f4359g - 1) {
            View childAt2 = this.d.getChildAt(i3 + 1);
            float left2 = (float) childAt2.getLeft();
            float right2 = (float) childAt2.getRight();
            float f12 = this.f;
            left = a.b(left2, left, f12, left);
            right = a.b(right2, right, f12, right);
            if (this.o == 0 && this.B) {
                this.P.setTextSize(this.I);
                float f13 = this.O;
                this.O = a.b(((right2 - left2) - this.P.measureText(((TextView) childAt2.findViewById(R.id.tv_tab_title)).getText().toString())) / 2.0f, f13, this.f, f13);
            }
        }
        Rect rect = this.f4360h;
        int i12 = (int) left;
        rect.left = i12;
        int i13 = (int) right;
        rect.right = i13;
        if (this.o == 0 && this.B) {
            float f14 = this.O;
            rect.left = (int) ((left + f14) - 1.0f);
            rect.right = (int) ((right - f14) - 1.0f);
        }
        Rect rect2 = this.i;
        rect2.left = i12;
        rect2.right = i13;
        if (this.f4362u >= i.f36333a) {
            float a5 = h.a.a((float) childAt.getWidth(), this.f4362u, 2.0f, (float) childAt.getLeft());
            int i14 = this.e;
            if (i14 < this.f4359g - 1) {
                View childAt3 = this.d.getChildAt(i14 + 1);
                a5 += this.f * ((float) ((childAt3.getWidth() / 2) + (childAt.getWidth() / 2)));
            }
            Rect rect3 = this.f4360h;
            int i15 = (int) a5;
            rect3.left = i15;
            rect3.right = (int) (((float) i15) + this.f4362u);
        }
    }

    public int b(float f12) {
        return (int) ((f12 * this.b.getResources().getDisplayMetrics().density) + 0.5f);
    }

    public TextView c(int i3) {
        return (TextView) this.d.getChildAt(i3).findViewById(R.id.tv_tab_title);
    }

    public final void d() {
        if (this.f4359g > 0) {
            int width = (int) (this.f * ((float) this.d.getChildAt(this.e).getWidth()));
            int left = this.d.getChildAt(this.e).getLeft() + width;
            if (this.e > 0 || width > 0) {
                int width2 = left - ((getWidth() / 2) - getPaddingLeft());
                a();
                Rect rect = this.i;
                left = a2.a.c(rect.right, rect.left, 2, width2);
            }
            if (left != this.N) {
                this.N = left;
                scrollTo(left, 0);
            }
        }
    }

    public int e(float f12) {
        return (int) ((f12 * this.b.getResources().getDisplayMetrics().scaledDensity) + 0.5f);
    }

    public final void f(int i3) {
        int i12 = 0;
        while (i12 < this.f4359g) {
            View childAt = this.d.getChildAt(i12);
            boolean z4 = i12 == i3;
            TextView textView = (TextView) childAt.findViewById(R.id.tv_tab_title);
            if (textView != null) {
                textView.setTextColor(z4 ? this.J : this.K);
            }
            if (this.f4358c.getAdapter() instanceof CustomTabProvider) {
                if (z4) {
                    ((CustomTabProvider) this.f4358c.getAdapter()).tabSelect(childAt);
                } else {
                    ((CustomTabProvider) this.f4358c.getAdapter()).tabUnselect(childAt);
                }
            }
            i12++;
        }
    }

    public final void g() {
        int i3 = 0;
        while (i3 < this.f4359g) {
            TextView textView = (TextView) this.d.getChildAt(i3).findViewById(R.id.tv_tab_title);
            if (textView != null) {
                textView.setTextColor(i3 == this.e ? this.J : this.K);
                textView.setTextSize(0, this.I);
                float f12 = this.p;
                textView.setPadding((int) f12, 0, (int) f12, 0);
                if (this.M) {
                    textView.setText(textView.getText().toString().toUpperCase());
                }
                if (this.L) {
                    textView.getPaint().setFakeBoldText(this.L);
                }
            }
            i3++;
        }
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (!isInEditMode() && this.f4359g > 0) {
            int height = getHeight();
            int paddingLeft = getPaddingLeft();
            float f12 = this.G;
            if (f12 > i.f36333a) {
                this.l.setStrokeWidth(f12);
                this.l.setColor(this.F);
                for (int i3 = 0; i3 < this.f4359g - 1; i3++) {
                    View childAt = this.d.getChildAt(i3);
                    canvas.drawLine((float) (childAt.getRight() + paddingLeft), this.H, (float) (childAt.getRight() + paddingLeft), ((float) height) - this.H, this.l);
                }
            }
            if (this.D > i.f36333a) {
                this.k.setColor(this.C);
                if (this.E == 80) {
                    float f13 = (float) height;
                    canvas.drawRect((float) paddingLeft, f13 - this.D, (float) (this.d.getWidth() + paddingLeft), f13, this.k);
                } else {
                    canvas.drawRect((float) paddingLeft, i.f36333a, (float) (this.d.getWidth() + paddingLeft), this.D, this.k);
                }
            }
            a();
            int i12 = this.o;
            if (i12 == 1) {
                if (this.t > i.f36333a) {
                    this.m.setColor(this.s);
                    this.n.reset();
                    float f14 = (float) height;
                    this.n.moveTo((float) (this.f4360h.left + paddingLeft), f14);
                    Path path = this.n;
                    Rect rect = this.f4360h;
                    path.lineTo((float) ((rect.right / 2) + (rect.left / 2) + paddingLeft), f14 - this.t);
                    this.n.lineTo((float) (paddingLeft + this.f4360h.right), f14);
                    this.n.close();
                    canvas.drawPath(this.n, this.m);
                }
            } else if (i12 == 2) {
                if (this.t < i.f36333a) {
                    this.t = (((float) height) - this.x) - this.z;
                }
                float f15 = this.t;
                if (f15 > i.f36333a) {
                    float f16 = this.f4363v;
                    if (f16 < i.f36333a || f16 > f15 / 2.0f) {
                        this.f4363v = f15 / 2.0f;
                    }
                    this.j.setColor(this.s);
                    GradientDrawable gradientDrawable = this.j;
                    Rect rect2 = this.f4360h;
                    int i13 = ((int) this.w) + paddingLeft + rect2.left;
                    float f17 = this.x;
                    gradientDrawable.setBounds(i13, (int) f17, (int) (((float) (paddingLeft + rect2.right)) - this.y), (int) (f17 + this.t));
                    this.j.setCornerRadius(this.f4363v);
                    this.j.draw(canvas);
                }
            } else if (this.t > i.f36333a) {
                this.j.setColor(this.s);
                if (this.A == 80) {
                    GradientDrawable gradientDrawable2 = this.j;
                    Rect rect3 = this.f4360h;
                    float f18 = this.z;
                    gradientDrawable2.setBounds(((int) this.w) + paddingLeft + rect3.left, (height - ((int) this.t)) - ((int) f18), (paddingLeft + rect3.right) - ((int) this.y), height - ((int) f18));
                } else {
                    GradientDrawable gradientDrawable3 = this.j;
                    Rect rect4 = this.f4360h;
                    int i14 = ((int) this.w) + paddingLeft + rect4.left;
                    float f19 = this.x;
                    gradientDrawable3.setBounds(i14, (int) f19, (paddingLeft + rect4.right) - ((int) this.y), ((int) this.t) + ((int) f19));
                }
                this.j.setCornerRadius(this.f4363v);
                this.j.draw(canvas);
            }
        }
    }

    @Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
    public void onPageScrollStateChanged(int i3) {
    }

    @Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
    public void onPageScrolled(int i3, float f12, int i12) {
        this.e = i3;
        this.f = f12;
        d();
        invalidate();
    }

    @Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
    public void onPageSelected(int i3) {
        f(i3);
    }

    public void onRestoreInstanceState(Parcelable parcelable) {
        if (parcelable instanceof Bundle) {
            Bundle bundle = (Bundle) parcelable;
            this.e = bundle.getInt("mCurrentTab");
            parcelable = bundle.getParcelable("instanceState");
            if (this.e != 0 && this.d.getChildCount() > 0) {
                f(this.e);
                d();
            }
        }
        super.onRestoreInstanceState(parcelable);
    }

    public Parcelable onSaveInstanceState() {
        Bundle bundle = new Bundle();
        bundle.putParcelable("instanceState", super.onSaveInstanceState());
        bundle.putInt("mCurrentTab", this.e);
        return bundle;
    }

    public void setCurrentTab(int i3) {
        this.e = i3;
        this.f4358c.setCurrentItem(i3);
    }

    public void setDividerColor(int i3) {
        this.F = i3;
        invalidate();
    }

    public void setDividerPadding(float f12) {
        this.H = (float) b(f12);
        invalidate();
    }

    public void setDividerWidth(float f12) {
        this.G = (float) b(f12);
        invalidate();
    }

    public void setIndicatorColor(int i3) {
        this.s = i3;
        invalidate();
    }

    public void setIndicatorCornerRadius(float f12) {
        this.f4363v = (float) b(f12);
        invalidate();
    }

    public void setIndicatorGravity(int i3) {
        this.A = i3;
        invalidate();
    }

    public void setIndicatorHeight(float f12) {
        this.t = (float) b(f12);
        invalidate();
    }

    public void setIndicatorStyle(int i3) {
        this.o = i3;
        invalidate();
    }

    public void setIndicatorWidth(float f12) {
        this.f4362u = (float) b(f12);
        invalidate();
    }

    public void setIndicatorWidthEqualTitle(boolean z4) {
        this.B = z4;
        invalidate();
    }

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

    public void setTabPadding(float f12) {
        this.p = (float) b(f12);
        g();
    }

    public void setTabSpaceEqual(boolean z4) {
        this.f4361q = z4;
        g();
    }

    public void setTabWidth(float f12) {
        this.r = (float) b(f12);
        g();
    }

    public void setTextAllCaps(boolean z4) {
        this.M = z4;
        g();
    }

    public void setTextBold(boolean z4) {
        this.L = z4;
        g();
    }

    public void setTextSelectColor(int i3) {
        this.J = i3;
        g();
    }

    public void setTextUnselectColor(int i3) {
        this.K = i3;
        g();
    }

    public void setTextsize(float f12) {
        this.I = (float) e(f12);
        g();
    }

    public void setUnderlineColor(int i3) {
        this.C = i3;
        invalidate();
    }

    public void setUnderlineGravity(int i3) {
        this.E = i3;
        invalidate();
    }

    public void setUnderlineHeight(float f12) {
        this.D = (float) b(f12);
        invalidate();
    }

    public void setViewPager(ViewPager viewPager) {
        View view;
        if (viewPager == null || viewPager.getAdapter() == null) {
            throw new IllegalStateException("ViewPager or ViewPager adapter can not be NULL !");
        }
        this.f4358c = viewPager;
        viewPager.removeOnPageChangeListener(this);
        this.f4358c.addOnPageChangeListener(this);
        this.d.removeAllViews();
        this.f4359g = this.f4358c.getAdapter().getCount();
        for (final int i3 = 0; i3 < this.f4359g; i3++) {
            if (this.f4358c.getAdapter() instanceof CustomTabProvider) {
                view = ((CustomTabProvider) this.f4358c.getAdapter()).getCustomTabView(this, i3);
            } else {
                view = View.inflate(this.b, R.layout.layout_tab, null);
            }
            String charSequence = this.f4358c.getAdapter().getPageTitle(i3).toString();
            TextView textView = (TextView) view.findViewById(R.id.tv_tab_title);
            if (!(textView == null || charSequence == null)) {
                textView.setText(charSequence);
            }
            view.setOnClickListener(new View.OnClickListener() {
                /* class com.flyco.tablayout.SlidingTabLayout.AnonymousClass1 */

                @SensorsDataInstrumented
                public void onClick(View view) {
                    int currentItem = SlidingTabLayout.this.f4358c.getCurrentItem();
                    int i = i3;
                    if (currentItem != i) {
                        SlidingTabLayout.this.f4358c.setCurrentItem(i);
                        OnTabSelectListener onTabSelectListener = SlidingTabLayout.this.Q;
                        if (onTabSelectListener != null) {
                            onTabSelectListener.onTabSelect(i3);
                        }
                    } else {
                        OnTabSelectListener onTabSelectListener2 = SlidingTabLayout.this.Q;
                        if (onTabSelectListener2 != null) {
                            onTabSelectListener2.onTabReselect(i);
                        }
                    }
                    SensorsDataAutoTrackHelper.trackViewOnClick(view);
                }
            });
            LinearLayout.LayoutParams layoutParams = this.f4361q ? new LinearLayout.LayoutParams(0, -1, 1.0f) : new LinearLayout.LayoutParams(-2, -1);
            if (this.r > i.f36333a) {
                layoutParams = new LinearLayout.LayoutParams((int) this.r, -1);
            }
            this.d.addView(view, i3, layoutParams);
        }
        g();
    }

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

    public SlidingTabLayout(Context context, AttributeSet attributeSet, int i3) {
        super(context, attributeSet, i3);
        float f12;
        this.f4360h = new Rect();
        this.i = new Rect();
        this.j = new GradientDrawable();
        this.k = new Paint(1);
        this.l = new Paint(1);
        this.m = new Paint(1);
        this.n = new Path();
        this.o = 0;
        this.P = new Paint(1);
        new SparseArray();
        setFillViewport(true);
        setWillNotDraw(false);
        setClipChildren(false);
        setClipToPadding(false);
        this.b = context;
        LinearLayout linearLayout = new LinearLayout(context);
        this.d = linearLayout;
        addView(linearLayout);
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, new int[]{R.attr.indicatorColor, R.attr.indicatorDrawable, R.attr.indicatorHeight, R.attr.indicatorLeftMargin, R.attr.indicatorRightMargin, R.attr.indicatorWidth, R.attr.tl_divider_color, R.attr.tl_divider_padding, R.attr.tl_divider_width, R.attr.tl_indicator_color, R.attr.tl_indicator_corner_radius, R.attr.tl_indicator_gravity, R.attr.tl_indicator_height, R.attr.tl_indicator_margin_bottom, R.attr.tl_indicator_margin_left, R.attr.tl_indicator_margin_right, R.attr.tl_indicator_margin_top, R.attr.tl_indicator_style, R.attr.tl_indicator_width, R.attr.tl_indicator_width_equal_title, R.attr.tl_tab_padding, R.attr.tl_tab_space_equal, R.attr.tl_tab_width, R.attr.tl_textAllCaps, R.attr.tl_textBold, R.attr.tl_textSelectColor, R.attr.tl_textUnselectColor, R.attr.tl_textsize, R.attr.tl_underline_color, R.attr.tl_underline_gravity, R.attr.tl_underline_height});
        int i12 = obtainStyledAttributes.getInt(17, 0);
        this.o = i12;
        this.s = obtainStyledAttributes.getColor(9, Color.parseColor(i12 == 2 ? "#4B6A87" : "#ffffff"));
        int i13 = this.o;
        if (i13 == 1) {
            f12 = 4.0f;
        } else {
            f12 = (float) (i13 == 2 ? -1 : 2);
        }
        this.t = obtainStyledAttributes.getDimension(12, (float) b(f12));
        this.f4362u = obtainStyledAttributes.getDimension(18, (float) b(this.o == 1 ? 10.0f : -1.0f));
        this.f4363v = obtainStyledAttributes.getDimension(10, (float) b(this.o == 2 ? -1.0f : i.f36333a));
        this.w = obtainStyledAttributes.getDimension(14, (float) b(i.f36333a));
        float f13 = 7.0f;
        this.x = obtainStyledAttributes.getDimension(16, (float) b(this.o == 2 ? 7.0f : i.f36333a));
        this.y = obtainStyledAttributes.getDimension(15, (float) b(i.f36333a));
        this.z = obtainStyledAttributes.getDimension(13, (float) b(this.o != 2 ? i.f36333a : f13));
        this.A = obtainStyledAttributes.getInt(11, 80);
        this.B = obtainStyledAttributes.getBoolean(19, false);
        this.C = obtainStyledAttributes.getColor(28, Color.parseColor("#ffffff"));
        this.D = obtainStyledAttributes.getDimension(30, (float) b(i.f36333a));
        this.E = obtainStyledAttributes.getInt(29, 80);
        this.F = obtainStyledAttributes.getColor(6, Color.parseColor("#ffffff"));
        this.G = obtainStyledAttributes.getDimension(8, (float) b(i.f36333a));
        this.H = obtainStyledAttributes.getDimension(7, (float) b(12.0f));
        this.I = obtainStyledAttributes.getDimension(27, (float) e(14.0f));
        this.J = obtainStyledAttributes.getColor(25, Color.parseColor("#ffffff"));
        this.K = obtainStyledAttributes.getColor(26, Color.parseColor("#AAffffff"));
        this.L = obtainStyledAttributes.getBoolean(24, false);
        this.M = obtainStyledAttributes.getBoolean(23, false);
        this.f4361q = obtainStyledAttributes.getBoolean(21, false);
        float dimension = obtainStyledAttributes.getDimension(22, (float) b(-1.0f));
        this.r = dimension;
        this.p = obtainStyledAttributes.getDimension(20, (float) ((this.f4361q || dimension > i.f36333a) ? b(i.f36333a) : b(20.0f)));
        obtainStyledAttributes.recycle();
        String attributeValue = attributeSet.getAttributeValue("http://schemas.android.com/apk/res/android", "layout_height");
        if (!attributeValue.equals("-1") && !attributeValue.equals("-2")) {
            TypedArray obtainStyledAttributes2 = context.obtainStyledAttributes(attributeSet, new int[]{16842997});
            obtainStyledAttributes2.getDimensionPixelSize(0, -2);
            obtainStyledAttributes2.recycle();
        }
    }
}