Search in sources :

Example 11 with IPagerTitleView

use of net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView in project MagicIndicator by hackware1993.

the class CommonNavigator method onSelected.

@Override
public void onSelected(int index, int totalCount) {
    if (mTitleContainer == null) {
        return;
    }
    View v = mTitleContainer.getChildAt(index);
    if (v instanceof IPagerTitleView) {
        ((IPagerTitleView) v).onSelected(index, totalCount);
    }
    if (!mAdjustMode && !mFollowTouch && mScrollView != null && mPositionDataList.size() > 0) {
        int currentIndex = Math.min(mPositionDataList.size() - 1, index);
        PositionData current = mPositionDataList.get(currentIndex);
        if (mEnablePivotScroll) {
            float scrollTo = current.horizontalCenter() - mScrollView.getWidth() * mScrollPivotX;
            if (mSmoothScroll) {
                mScrollView.smoothScrollTo((int) (scrollTo), 0);
            } else {
                mScrollView.scrollTo((int) (scrollTo), 0);
            }
        } else {
            // 如果当前项被部分遮挡,则滚动显示完全
            if (mScrollView.getScrollX() > current.mLeft) {
                if (mSmoothScroll) {
                    mScrollView.smoothScrollTo(current.mLeft, 0);
                } else {
                    mScrollView.scrollTo(current.mLeft, 0);
                }
            } else if (mScrollView.getScrollX() + getWidth() < current.mRight) {
                if (mSmoothScroll) {
                    mScrollView.smoothScrollTo(current.mRight - getWidth(), 0);
                } else {
                    mScrollView.scrollTo(current.mRight - getWidth(), 0);
                }
            }
        }
    }
}
Also used : IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) PositionData(net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData) IMeasurablePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IMeasurablePagerTitleView) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View)

Example 12 with IPagerTitleView

use of net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView in project MagicIndicator by hackware1993.

the class FixedTabExampleActivity method initMagicIndicator4.

private void initMagicIndicator4() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator4);
    CommonNavigator commonNavigator = new CommonNavigator(this);
    commonNavigator.setAdapter(new CommonNavigatorAdapter() {

        @Override
        public int getCount() {
            return mDataList.size();
        }

        @Override
        public IPagerTitleView getTitleView(Context context, final int index) {
            SimplePagerTitleView simplePagerTitleView = new ColorTransitionPagerTitleView(context);
            simplePagerTitleView.setNormalColor(Color.GRAY);
            simplePagerTitleView.setSelectedColor(Color.WHITE);
            simplePagerTitleView.setText(mDataList.get(index));
            simplePagerTitleView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mViewPager.setCurrentItem(index);
                }
            });
            return simplePagerTitleView;
        }

        @Override
        public IPagerIndicator getIndicator(Context context) {
            LinePagerIndicator linePagerIndicator = new LinePagerIndicator(context);
            linePagerIndicator.setMode(LinePagerIndicator.MODE_EXACTLY);
            linePagerIndicator.setLineWidth(UIUtil.dip2px(context, 10));
            linePagerIndicator.setColors(Color.WHITE);
            return linePagerIndicator;
        }
    });
    magicIndicator.setNavigator(commonNavigator);
    // must after setNavigator
    LinearLayout titleContainer = commonNavigator.getTitleContainer();
    titleContainer.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    titleContainer.setDividerDrawable(new ColorDrawable() {

        @Override
        public int getIntrinsicWidth() {
            return UIUtil.dip2px(FixedTabExampleActivity.this, 15);
        }
    });
    final FragmentContainerHelper fragmentContainerHelper = new FragmentContainerHelper(magicIndicator);
    fragmentContainerHelper.setInterpolator(new OvershootInterpolator(2.0f));
    fragmentContainerHelper.setDuration(300);
    mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            fragmentContainerHelper.handlePageSelected(position);
        }
    });
}
Also used : Context(android.content.Context) CommonNavigator(net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator) OvershootInterpolator(android.view.animation.OvershootInterpolator) IPagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ColorTransitionPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView) ScaleTransitionPagerTitleView(net.lucode.hackware.magicindicatordemo.ext.titles.ScaleTransitionPagerTitleView) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ClipPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView) View(android.view.View) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) ColorTransitionPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView) ViewPager(android.support.v4.view.ViewPager) CommonNavigatorAdapter(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter) FragmentContainerHelper(net.lucode.hackware.magicindicator.FragmentContainerHelper) ColorDrawable(android.graphics.drawable.ColorDrawable) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) LinePagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator) LinearLayout(android.widget.LinearLayout)

Example 13 with IPagerTitleView

use of net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView in project MagicIndicator by hackware1993.

the class FixedTabExampleActivity method initMagicIndicator1.

private void initMagicIndicator1() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator1);
    CommonNavigator commonNavigator = new CommonNavigator(this);
    commonNavigator.setAdapter(new CommonNavigatorAdapter() {

        @Override
        public int getCount() {
            return mDataList == null ? 0 : mDataList.size();
        }

        @Override
        public IPagerTitleView getTitleView(Context context, final int index) {
            SimplePagerTitleView simplePagerTitleView = new ColorTransitionPagerTitleView(context);
            simplePagerTitleView.setText(mDataList.get(index));
            simplePagerTitleView.setNormalColor(Color.parseColor("#88ffffff"));
            simplePagerTitleView.setSelectedColor(Color.WHITE);
            simplePagerTitleView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mViewPager.setCurrentItem(index);
                }
            });
            return simplePagerTitleView;
        }

        @Override
        public IPagerIndicator getIndicator(Context context) {
            LinePagerIndicator indicator = new LinePagerIndicator(context);
            indicator.setColors(Color.parseColor("#40c4ff"));
            return indicator;
        }
    });
    magicIndicator.setNavigator(commonNavigator);
    // must after setNavigator
    LinearLayout titleContainer = commonNavigator.getTitleContainer();
    titleContainer.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
    titleContainer.setDividerPadding(UIUtil.dip2px(this, 15));
    titleContainer.setDividerDrawable(getResources().getDrawable(R.drawable.simple_splitter));
    ViewPagerHelper.bind(magicIndicator, mViewPager);
}
Also used : Context(android.content.Context) CommonNavigator(net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator) IPagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ColorTransitionPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView) ScaleTransitionPagerTitleView(net.lucode.hackware.magicindicatordemo.ext.titles.ScaleTransitionPagerTitleView) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ClipPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView) View(android.view.View) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) ColorTransitionPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView) CommonNavigatorAdapter(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) LinePagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator) LinearLayout(android.widget.LinearLayout)

Example 14 with IPagerTitleView

use of net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView in project MagicIndicator by hackware1993.

the class FragmentContainerExampleActivity method initMagicIndicator1.

private void initMagicIndicator1() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator1);
    magicIndicator.setBackgroundResource(R.drawable.round_indicator_bg);
    CommonNavigator commonNavigator = new CommonNavigator(this);
    commonNavigator.setAdapter(new CommonNavigatorAdapter() {

        @Override
        public int getCount() {
            return CHANNELS.length;
        }

        @Override
        public IPagerTitleView getTitleView(Context context, final int index) {
            ClipPagerTitleView clipPagerTitleView = new ClipPagerTitleView(context);
            clipPagerTitleView.setText(CHANNELS[index]);
            clipPagerTitleView.setTextColor(Color.parseColor("#e94220"));
            clipPagerTitleView.setClipColor(Color.WHITE);
            clipPagerTitleView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mFragmentContainerHelper.handlePageSelected(index);
                    switchPages(index);
                }
            });
            return clipPagerTitleView;
        }

        @Override
        public IPagerIndicator getIndicator(Context context) {
            LinePagerIndicator indicator = new LinePagerIndicator(context);
            float navigatorHeight = context.getResources().getDimension(R.dimen.common_navigator_height);
            float borderWidth = UIUtil.dip2px(context, 1);
            float lineHeight = navigatorHeight - 2 * borderWidth;
            indicator.setLineHeight(lineHeight);
            indicator.setRoundRadius(lineHeight / 2);
            indicator.setYOffset(borderWidth);
            indicator.setColors(Color.parseColor("#bc2a2a"));
            return indicator;
        }
    });
    magicIndicator.setNavigator(commonNavigator);
    mFragmentContainerHelper.attachMagicIndicator(magicIndicator);
}
Also used : Context(android.content.Context) CommonNavigator(net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator) CommonNavigatorAdapter(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter) IPagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) ClipPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) LinePagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) ClipPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView) View(android.view.View)

Example 15 with IPagerTitleView

use of net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView in project MagicIndicator by hackware1993.

the class ScrollableTabExampleActivity method initMagicIndicator2.

private void initMagicIndicator2() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator2);
    magicIndicator.setBackgroundColor(Color.parseColor("#00c853"));
    CommonNavigator commonNavigator = new CommonNavigator(this);
    commonNavigator.setScrollPivotX(0.25f);
    commonNavigator.setAdapter(new CommonNavigatorAdapter() {

        @Override
        public int getCount() {
            return mDataList == null ? 0 : mDataList.size();
        }

        @Override
        public IPagerTitleView getTitleView(Context context, final int index) {
            SimplePagerTitleView simplePagerTitleView = new SimplePagerTitleView(context);
            simplePagerTitleView.setText(mDataList.get(index));
            simplePagerTitleView.setNormalColor(Color.parseColor("#c8e6c9"));
            simplePagerTitleView.setSelectedColor(Color.WHITE);
            simplePagerTitleView.setTextSize(12);
            simplePagerTitleView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mViewPager.setCurrentItem(index);
                }
            });
            return simplePagerTitleView;
        }

        @Override
        public IPagerIndicator getIndicator(Context context) {
            LinePagerIndicator indicator = new LinePagerIndicator(context);
            indicator.setMode(LinePagerIndicator.MODE_EXACTLY);
            indicator.setYOffset(UIUtil.dip2px(context, 3));
            indicator.setColors(Color.parseColor("#ffffff"));
            return indicator;
        }
    });
    magicIndicator.setNavigator(commonNavigator);
    ViewPagerHelper.bind(magicIndicator, mViewPager);
}
Also used : Context(android.content.Context) CommonNavigator(net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator) CommonNavigatorAdapter(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter) IPagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) LinePagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ColorFlipPagerTitleView(net.lucode.hackware.magicindicatordemo.ext.titles.ColorFlipPagerTitleView) ScaleTransitionPagerTitleView(net.lucode.hackware.magicindicatordemo.ext.titles.ScaleTransitionPagerTitleView) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ClipPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView) View(android.view.View) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) ColorTransitionPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView)

Aggregations

IPagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView)24 Context (android.content.Context)22 View (android.view.View)22 CommonNavigator (net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator)22 CommonNavigatorAdapter (net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter)22 IPagerIndicator (net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator)22 MagicIndicator (net.lucode.hackware.magicindicator.MagicIndicator)21 ClipPagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView)19 ColorTransitionPagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView)17 SimplePagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView)17 ScaleTransitionPagerTitleView (net.lucode.hackware.magicindicatordemo.ext.titles.ScaleTransitionPagerTitleView)17 LinePagerIndicator (net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator)15 ColorFlipPagerTitleView (net.lucode.hackware.magicindicatordemo.ext.titles.ColorFlipPagerTitleView)9 ImageView (android.widget.ImageView)5 LinearLayout (android.widget.LinearLayout)5 TextView (android.widget.TextView)5 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)4 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)4 BadgePagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgePagerTitleView)4 ColorDrawable (android.graphics.drawable.ColorDrawable)2