admin
2020-10-10 8039a1b2fbfa3471b6f726d3e839d7867c81a84f
library-ViewPagerIndicator/src/com/viewpagerindicator/FoundTabPageIndicator.java
File was renamed from library-ViewPagerIndicator/src/com/viewpagerindicator/FoundPageIndicator.java
@@ -1,3 +1,19 @@
/*
 * Copyright (C) 2011 The Android Open Source Project
 * Copyright (C) 2011 Jake Wharton
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.viewpagerindicator;
import android.annotation.SuppressLint;
@@ -6,29 +22,25 @@
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.lcjian.library.widget.IsPad;
import com.lcjian.library.util.common.DimenUtils;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
/**
 * 发现页面的导航
 * This widget implements the dynamic action bar tab behavior that can change
 * across different configurations or circumstances.
 */
public class FoundPageIndicator extends HorizontalScrollView implements
public class FoundTabPageIndicator extends HorizontalScrollView implements
        PageIndicator {
    /**
     * Title text used when no title is provided by the adapter.
     */
@@ -72,16 +84,16 @@
    private OnTabReselectedListener mTabReselectedListener;
    public FoundPageIndicator(Context context) {
    public FoundTabPageIndicator(Context context) {
        this(context, null);
    }
    public FoundPageIndicator(Context context, AttributeSet attrs) {
    public FoundTabPageIndicator(Context context, AttributeSet attrs) {
        super(context, attrs);
        setHorizontalScrollBarEnabled(false);
        mTabLayout = new IcsLinearLayout(context,
                R.attr.vpiTitlePageIndicatorStyle);
                R.attr.vpiTabPageIndicatorStyle);
        addView(mTabLayout, new ViewGroup.LayoutParams(WRAP_CONTENT,
                MATCH_PARENT));
    }
@@ -129,24 +141,15 @@
        if (mTabSelector != null) {
            removeCallbacks(mTabSelector);
        }
//      Drawable mReview = getResources().getDrawable(R.drawable.video_review);
//      mReview.setBounds(0, 0, mReview.getMinimumWidth(),
//            mReview.getMinimumHeight());
        for (int i = 0; i < mTabLayout.getChildCount(); i++) {
            ((TextView) mTabLayout.getChildAt(i)).setTextColor(Color.argb(255,
                    0, 0, 0));
            if (i == 1) {
                SpannableStringBuilder builder = new SpannableStringBuilder(((TextView) tabView).getText().toString());
                ForegroundColorSpan span = new ForegroundColorSpan(Color.argb(255, 255, 115, 0));
                builder.setSpan(span, 2, ((TextView) tabView).getText().toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                ((TextView) tabView).setText(builder);
            }
            ((TextView) mTabLayout.getChildAt(i)).setTextSize(
                    TypedValue.COMPLEX_UNIT_SP, 15);
            ((TextView) mTabLayout.getChildAt(i)).setTextColor(Color.parseColor("#999999"));
        }
        ((TextView) tabView).setTextColor(Color.argb(255, 0, 0, 0));//豆豆系列
//      ((TextView) tabView).setTextColor(Color.argb(255, 255, 115, 0));// 木瓜系列
        ((TextView) tabView).setTextColor(Color.WHITE);
        ((TextView) tabView).setTextSize(
                TypedValue.COMPLEX_UNIT_SP, 20);
//        ((TextView) tabView).setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT,WRAP_CONTENT));
        mTabSelector = new Runnable() {
            public void run() {
                final int scrollPos = tabView.getLeft()
@@ -156,9 +159,9 @@
                mTabSelector = null;
            }
        };
        post(mTabSelector);
    }
    @Override
    public void onAttachedToWindow() {
@@ -184,35 +187,30 @@
     * @param text
     * @param iconResId
     */
    @SuppressLint("ResourceAsColor")
    private void addTab(int index, CharSequence text, int iconResId) {
        final TabView tabView = new TabView(getContext());
        tabView.mIndex = index;
        tabView.setFocusable(true);
        tabView.setOnClickListener(mTabClickListener);
        if (IsPad.isPad(tabView.getContext()))
            tabView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25);
        tabView.setText(text);
        int width = ((WindowManager) getContext().getSystemService(
                Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();
        tabView.setTextColor(R.color.black1);
        tabView.setBackgroundResource(R.drawable.found__tab_indicator);
        tabView.setPadding(0,0,0,DimenUtils.dip2px(getContext(), 6));
        if (iconResId != 0) {
            tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
        }
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(WRAP_CONTENT,
                MATCH_PARENT, 1);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                width / 3, LayoutParams.WRAP_CONTENT);
        // params.setMargins(20, 0, 20, 0);
        mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0,
                LayoutParams.MATCH_PARENT, 1));
        switch (index) {
            case 1:
                SpannableStringBuilder builder = new SpannableStringBuilder(((TextView) tabView).getText().toString());
                ForegroundColorSpan span = new ForegroundColorSpan(Color.argb(255, 255, 115, 0));
                builder.setSpan(span, 2, ((TextView) tabView).getText().toString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                ((TextView) tabView).setText(builder);
                break;
            default:
                break;
        }
        mTabLayout.addView(tabView, params);
        MarginLayoutParams marginLayoutParams = (MarginLayoutParams) tabView.getLayoutParams();
        if (index == 0)
            marginLayoutParams.leftMargin = 0;
        else
            marginLayoutParams.leftMargin = DimenUtils.dip2px(getContext(), 21);
    }
    @Override
@@ -320,7 +318,7 @@
        private int mIndex;
        public TabView(Context context) {
            super(context, null, R.attr.lxyTabPageIndicatorStyle);
            super(context, null, R.attr.vpiTabPageIndicatorStyle);
        }
        @Override
@@ -337,13 +335,5 @@
        public int getIndex() {
            return mIndex;
        }
    }
    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     */
    public static int dip2px(Context context, float dpValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }
}