Search in sources :

Example 21 with IPagerIndicator

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

the class BadgeTabExampleActivity 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) {
            final BadgePagerTitleView badgePagerTitleView = new BadgePagerTitleView(context);
            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);
                    // cancel badge when click tab
                    badgePagerTitleView.setBadgeView(null);
                }
            });
            badgePagerTitleView.setInnerPagerTitleView(simplePagerTitleView);
            // setup badge
            if (index != 2) {
                TextView badgeTextView = (TextView) LayoutInflater.from(context).inflate(R.layout.simple_count_badge_layout, null);
                badgeTextView.setText("" + (index + 1));
                badgePagerTitleView.setBadgeView(badgeTextView);
            } else {
                ImageView badgeImageView = (ImageView) LayoutInflater.from(context).inflate(R.layout.simple_red_dot_badge_layout, null);
                badgePagerTitleView.setBadgeView(badgeImageView);
            }
            // set badge position
            if (index == 0) {
                badgePagerTitleView.setXBadgeRule(new BadgeRule(BadgeAnchor.CONTENT_LEFT, -UIUtil.dip2px(context, 6)));
                badgePagerTitleView.setYBadgeRule(new BadgeRule(BadgeAnchor.CONTENT_TOP, 0));
            } else if (index == 1) {
                badgePagerTitleView.setXBadgeRule(new BadgeRule(BadgeAnchor.CONTENT_RIGHT, -UIUtil.dip2px(context, 6)));
                badgePagerTitleView.setYBadgeRule(new BadgeRule(BadgeAnchor.CONTENT_TOP, 0));
            } else if (index == 2) {
                badgePagerTitleView.setXBadgeRule(new BadgeRule(BadgeAnchor.CENTER_X, -UIUtil.dip2px(context, 3)));
                badgePagerTitleView.setYBadgeRule(new BadgeRule(BadgeAnchor.CONTENT_BOTTOM, UIUtil.dip2px(context, 2)));
            }
            // don't cancel badge when tab selected
            badgePagerTitleView.setAutoCancelBadge(false);
            return badgePagerTitleView;
        }

        @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) BadgeRule(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgeRule) 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) ImageView(android.widget.ImageView) ClipPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView) View(android.view.View) BadgePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgePagerTitleView) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) ColorTransitionPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView) TextView(android.widget.TextView) BadgePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgePagerTitleView) 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) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 22 with IPagerIndicator

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

the class BadgeTabExampleActivity method initMagicIndicator3.

private void initMagicIndicator3() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator3);
    magicIndicator.setBackgroundResource(R.drawable.round_indicator_bg);
    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) {
            BadgePagerTitleView badgePagerTitleView = new BadgePagerTitleView(context);
            ClipPagerTitleView clipPagerTitleView = new ClipPagerTitleView(context);
            clipPagerTitleView.setText(mDataList.get(index));
            clipPagerTitleView.setTextColor(Color.parseColor("#e94220"));
            clipPagerTitleView.setClipColor(Color.WHITE);
            clipPagerTitleView.setOnClickListener(new View.OnClickListener() {

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

        @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);
    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) ClipPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) ScaleTransitionPagerTitleView(net.lucode.hackware.magicindicatordemo.ext.titles.ScaleTransitionPagerTitleView) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ImageView(android.widget.ImageView) ClipPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView) View(android.view.View) BadgePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgePagerTitleView) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) ColorTransitionPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView) TextView(android.widget.TextView) BadgePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgePagerTitleView) 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)

Aggregations

Context (android.content.Context)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 IPagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView)22 MagicIndicator (net.lucode.hackware.magicindicator.MagicIndicator)21 View (android.view.View)20 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 TextView (android.widget.TextView)5 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)4 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)4 LinearLayout (android.widget.LinearLayout)4 BadgePagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgePagerTitleView)4 ColorDrawable (android.graphics.drawable.ColorDrawable)2