EnchantedViewPager

Additional

Language
Java
Version
N/A
Created
Nov 21, 2016
Updated
Jul 8, 2019 (Retired)
Owner
TiagoSantos (TMSantos)
Contributor
TiagoSantos (TMSantos)
1
Activity
Badge
Generate
Download
Source code

enchantedviewpager

EchantedViewPager is a custom ViewPager that provides some custom and usefull functionalities, such as, scalling scroll, alpha scroll and swipe to dismiss option.

Usage

Inside your pager adapter you must do this whenever you instantiate a view:

@Override
    public Object instantiateItem(ViewGroup container, int position) {
        (...)
        mCurrentView.setTag(EnchantedViewPager.ENCHANTED_VIEWPAGER_POSITION + position);
        container.addView(mCurrentView);

        return mCurrentView;
    }
<com.tiagosantos.enchantedviewpager.EnchantedViewPager
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

Scale scroll

 final EnchantedViewPager mViewPager = (EnchantedViewPager) findViewById(R.id.viewpager);
 mViewPager.useScale();

Alpha scroll

 final EnchantedViewPager mViewPager = (EnchantedViewPager) findViewById(R.id.viewpager);
 mViewPager.useAlpha();

Swipe to dismiss

 final EnchantedViewPager mViewPager = (EnchantedViewPager) findViewById(R.id.viewpager);
 mViewPager.addSwipeToDismiss(new EnchantedViewPager.EnchantedViewPagerSwipeListener() {
                        @Override
                        public void onSwipeFinished(int position) {
                            //execute code to remove the swiped item
                        }
                    });

Carrousell / Infinite loop mode

First, your pager adapter must extend EchantedPagerAdapter:
    SomePagerAdapter extends EnchantedViewPagerAdapter
    public SomePagerAdapter(Context context,ArrayList<AlbumArt> albumList) {
        super(albumList);
        (...)
    }
And make sure you don't implement getCount() method, since it must be controlled by EnchantedPagerAdapter.

Then you just need to activate/diasble carrousel mode:
    echantedAdapter.enableCarrousel();
    echantedAdapter.disableCarrousel();
If you want to have carrousel for both sides, you need to set your viewpager position on the middle:
    mViewPager.setCurrentItem(echantedAdapter.getMiddlePosition());

Gradle

compile 'com.tiagosantos:enchantedviewpager:1.1.0'

License

Copyright 2017 Tiago Santos

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.