Search in sources :

Example 6 with MagicIndicator

use of net.lucode.hackware.magicindicator.MagicIndicator 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)

Example 7 with MagicIndicator

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

the class LoadCustomLayoutExampleActivity method initMagicIndicator1.

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

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

        @Override
        public IPagerTitleView getTitleView(Context context, final int index) {
            CommonPagerTitleView commonPagerTitleView = new CommonPagerTitleView(context);
            // load custom layout
            View customLayout = LayoutInflater.from(context).inflate(R.layout.simple_pager_title_layout, null);
            final ImageView titleImg = (ImageView) customLayout.findViewById(R.id.title_img);
            final TextView titleText = (TextView) customLayout.findViewById(R.id.title_text);
            titleImg.setImageResource(R.mipmap.ic_launcher);
            titleText.setText(mDataList.get(index));
            commonPagerTitleView.setContentView(customLayout);
            commonPagerTitleView.setOnPagerTitleChangeListener(new CommonPagerTitleView.OnPagerTitleChangeListener() {

                @Override
                public void onSelected(int index, int totalCount) {
                    titleText.setTextColor(Color.WHITE);
                }

                @Override
                public void onDeselected(int index, int totalCount) {
                    titleText.setTextColor(Color.LTGRAY);
                }

                @Override
                public void onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) {
                    titleImg.setScaleX(1.3f + (0.8f - 1.3f) * leavePercent);
                    titleImg.setScaleY(1.3f + (0.8f - 1.3f) * leavePercent);
                }

                @Override
                public void onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) {
                    titleImg.setScaleX(0.8f + (1.3f - 0.8f) * enterPercent);
                    titleImg.setScaleY(0.8f + (1.3f - 0.8f) * enterPercent);
                }
            });
            commonPagerTitleView.setOnClickListener(new View.OnClickListener() {

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

        @Override
        public IPagerIndicator getIndicator(Context context) {
            return null;
        }
    });
    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) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) ImageView(android.widget.ImageView) CommonPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.CommonPagerTitleView) TextView(android.widget.TextView) View(android.view.View) CommonNavigatorAdapter(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter) CommonPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.CommonPagerTitleView) IPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 8 with MagicIndicator

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

the class NoTabOnlyIndicatorExampleActivity method initMagicIndicator1.

private void initMagicIndicator1() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator1);
    magicIndicator.setBackgroundColor(Color.LTGRAY);
    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) {
            return new DummyPagerTitleView(context);
        }

        @Override
        public IPagerIndicator getIndicator(Context context) {
            LinePagerIndicator indicator = new LinePagerIndicator(context);
            float lineHeight = context.getResources().getDimension(R.dimen.small_navigator_height);
            indicator.setLineHeight(lineHeight);
            indicator.setColors(Color.parseColor("#40c4ff"));
            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) DummyPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.DummyPagerTitleView) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) LinePagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator)

Example 9 with MagicIndicator

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

the class NoTabOnlyIndicatorExampleActivity method initMagicIndicator2.

private void initMagicIndicator2() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator2);
    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) {
            return new DummyPagerTitleView(context);
        }

        @Override
        public IPagerIndicator getIndicator(Context context) {
            TriangularPagerIndicator indicator = new TriangularPagerIndicator(context);
            indicator.setReverse(true);
            float smallNavigatorHeight = context.getResources().getDimension(R.dimen.small_navigator_height);
            indicator.setLineHeight(UIUtil.dip2px(context, 2));
            indicator.setTriangleHeight((int) smallNavigatorHeight);
            indicator.setLineColor(Color.parseColor("#e94220"));
            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) DummyPagerTitleView(net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.DummyPagerTitleView) MagicIndicator(net.lucode.hackware.magicindicator.MagicIndicator) TriangularPagerIndicator(net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.TriangularPagerIndicator)

Example 10 with MagicIndicator

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

the class ScrollableTabExampleActivity method initMagicIndicator5.

private void initMagicIndicator5() {
    MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator5);
    magicIndicator.setBackgroundColor(Color.WHITE);
    CommonNavigator commonNavigator = new CommonNavigator(this);
    commonNavigator.setScrollPivotX(0.8f);
    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;
        }
    });
    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) 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) 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

MagicIndicator (net.lucode.hackware.magicindicator.MagicIndicator)24 Context (android.content.Context)21 CommonNavigator (net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator)21 CommonNavigatorAdapter (net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter)21 IPagerIndicator (net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator)21 IPagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView)21 View (android.view.View)19 ClipPagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ClipPagerTitleView)18 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 ScaleCircleNavigator (net.lucode.hackware.magicindicatordemo.ext.navigator.ScaleCircleNavigator)3