Search in sources :

Example 1 with CommonNavigator

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

the class BadgeTabExampleActivity 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) {
            BadgePagerTitleView badgePagerTitleView = new BadgePagerTitleView(context);
            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);
                }
            });
            badgePagerTitleView.setInnerPagerTitleView(simplePagerTitleView);
            return badgePagerTitleView;
        }

        @Override
        public IPagerIndicator getIndicator(Context context) {
            LinePagerIndicator linePagerIndicator = new LinePagerIndicator(context);
            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(BadgeTabExampleActivity.this, 15);
        }
    });
    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) 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) 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 2 with CommonNavigator

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

the class BadgeTabExampleActivity method initMagicIndicator2.

private void initMagicIndicator2() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator2);
    magicIndicator.setBackgroundColor(Color.WHITE);
    CommonNavigator commonNavigator = new CommonNavigator(this);
    commonNavigator.setAdjustMode(true);
    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);
            SimplePagerTitleView simplePagerTitleView = new ScaleTransitionPagerTitleView(context);
            simplePagerTitleView.setText(mDataList.get(index));
            simplePagerTitleView.setTextSize(18);
            simplePagerTitleView.setNormalColor(Color.parseColor("#616161"));
            simplePagerTitleView.setSelectedColor(Color.parseColor("#f57c00"));
            simplePagerTitleView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    mViewPager.setCurrentItem(index);
                }
            });
            badgePagerTitleView.setInnerPagerTitleView(simplePagerTitleView);
            // setup badge
            if (index == 1) {
                ImageView badgeImageView = (ImageView) LayoutInflater.from(context).inflate(R.layout.simple_red_dot_badge_layout, null);
                badgePagerTitleView.setBadgeView(badgeImageView);
                badgePagerTitleView.setXBadgeRule(new BadgeRule(BadgeAnchor.CENTER_X, -UIUtil.dip2px(context, 3)));
                badgePagerTitleView.setYBadgeRule(new BadgeRule(BadgeAnchor.CONTENT_BOTTOM, UIUtil.dip2px(context, 2)));
            }
            // cancel badge when click tab, default true
            badgePagerTitleView.setAutoCancelBadge(true);
            return badgePagerTitleView;
        }

        @Override
        public IPagerIndicator getIndicator(Context context) {
            LinePagerIndicator indicator = new LinePagerIndicator(context);
            indicator.setStartInterpolator(new AccelerateInterpolator());
            indicator.setEndInterpolator(new DecelerateInterpolator(1.6f));
            indicator.setYOffset(UIUtil.dip2px(context, 39));
            indicator.setLineHeight(UIUtil.dip2px(context, 1));
            indicator.setColors(Color.parseColor("#f57c00"));
            return indicator;
        }

        @Override
        public float getTitleWeight(Context context, int index) {
            if (index == 0) {
                return 2.0f;
            } else if (index == 1) {
                return 1.2f;
            } else {
                return 1.0f;
            }
        }
    });
    magicIndicator.setNavigator(commonNavigator);
    ViewPagerHelper.bind(magicIndicator, mViewPager);
}
Also used : Context(android.content.Context) BadgeRule(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.badge.BadgeRule) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) CommonNavigator(net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) IPagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ScaleTransitionPagerTitleView(net.lucode.hackware.magicindicatordemo.ext.titles.ScaleTransitionPagerTitleView) 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) ImageView(android.widget.ImageView)

Example 3 with CommonNavigator

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

the class DynamicTabExampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dynamic_tab_example_layout);
    mViewPager = (ViewPager) findViewById(R.id.view_pager);
    mViewPager.setAdapter(mExamplePagerAdapter);
    mMagicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator1);
    mMagicIndicator.setBackgroundColor(Color.parseColor("#d43d3d"));
    mCommonNavigator = new CommonNavigator(this);
    mCommonNavigator.setSkimOver(true);
    mCommonNavigator.setAdapter(new CommonNavigatorAdapter() {

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

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

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

        @Override
        public IPagerIndicator getIndicator(Context context) {
            return null;
        }
    });
    mMagicIndicator.setNavigator(mCommonNavigator);
    ViewPagerHelper.bind(mMagicIndicator, mViewPager);
    mToast = Toast.makeText(this, "", Toast.LENGTH_SHORT);
}
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) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) ClipPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView) View(android.view.View)

Example 4 with CommonNavigator

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

the class FixedTabExampleActivity 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) {
            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);
                }
            });
            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);
    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) ClipPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) LinePagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator) 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)

Example 5 with CommonNavigator

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

the class FixedTabExampleActivity method initMagicIndicator2.

private void initMagicIndicator2() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator2);
    magicIndicator.setBackgroundColor(Color.WHITE);
    CommonNavigator commonNavigator = new CommonNavigator(this);
    commonNavigator.setAdjustMode(true);
    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 ScaleTransitionPagerTitleView(context);
            simplePagerTitleView.setText(mDataList.get(index));
            simplePagerTitleView.setTextSize(18);
            simplePagerTitleView.setNormalColor(Color.parseColor("#616161"));
            simplePagerTitleView.setSelectedColor(Color.parseColor("#f57c00"));
            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.setStartInterpolator(new AccelerateInterpolator());
            indicator.setEndInterpolator(new DecelerateInterpolator(1.6f));
            indicator.setYOffset(UIUtil.dip2px(context, 39));
            indicator.setLineHeight(UIUtil.dip2px(context, 1));
            indicator.setColors(Color.parseColor("#f57c00"));
            return indicator;
        }

        @Override
        public float getTitleWeight(Context context, int index) {
            if (index == 0) {
                return 2.0f;
            } else if (index == 1) {
                return 1.2f;
            } else {
                return 1.0f;
            }
        }
    });
    magicIndicator.setNavigator(commonNavigator);
    ViewPagerHelper.bind(magicIndicator, mViewPager);
}
Also used : Context(android.content.Context) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) CommonNavigator(net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) IPagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) SimplePagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView) ScaleTransitionPagerTitleView(net.lucode.hackware.magicindicatordemo.ext.titles.ScaleTransitionPagerTitleView) 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)

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