Class SimpleCarousel


  • public class SimpleCarousel
    extends java.lang.Object
    Class for creating a simple image carousel.
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleCarousel​(android.content.Context context, androidx.viewpager.widget.ViewPager viewPager, android.widget.LinearLayout pageIndicatorLinearLayout)  
    • Constructor Detail

      • SimpleCarousel

        public SimpleCarousel​(android.content.Context context,
                              androidx.viewpager.widget.ViewPager viewPager,
                              android.widget.LinearLayout pageIndicatorLinearLayout)
    • Method Detail

      • init

        public void init​(boolean isAutoScrollEnabled)
        Initialize carousel with default parameters.
        Parameters:
        isAutoScrollEnabled - true to enable autoscrolling, else false
      • updateAutoScrollDuration

        public void updateAutoScrollDuration​(int autoScrollDuration)
        Updates the carousel speed
        Parameters:
        autoScrollDuration - duration of auto scroll
      • initPageIndicator

        public void initPageIndicator()
        Initializes the page indicator.
      • getCurrentItem

        public int getCurrentItem()
        Returns:
        the currently selected page.
      • setCurrentItem

        public void setCurrentItem​(int position)
        Sets the currently selected page.
        Parameters:
        position - current position to select
      • setCurrentItem

        public void setCurrentItem​(int position,
                                   boolean smoothScroll)
        Sets the currently selected page.
        Parameters:
        position - current position to select
        smoothScroll - true to smooth scroll, else false
      • getAdapter

        public androidx.viewpager.widget.PagerAdapter getAdapter()
        Returns:
        Fetches the pager adapter.
      • setAdapter

        public void setAdapter​(androidx.viewpager.widget.PagerAdapter adapter)
        Sets the adapter that provides the data and the views in this carousel.
        Parameters:
        adapter - instance of PagerAdapter to use for the view pager
      • setPageIndicatorMargin

        public void setPageIndicatorMargin​(int marginInPx)
        Sets the page indicator margin.
        Parameters:
        marginInPx - margin size between each page indicators
      • setTimedScrollerDuration

        public void setTimedScrollerDuration​(int animationDuration)
        Sets the scroll animation duration.
        Parameters:
        animationDuration - duration of the scroll animation
      • setAutoScroll

        public void setAutoScroll​(boolean isEnabled)
        Determines whether carousel is allowed to autoscroll.
        Parameters:
        isEnabled - True if allowed to autoscroll, else false.
      • setCarouselSwipeListener

        public void setCarouselSwipeListener​(Carousel.CarouselSwipeListener mCarouselSwipeListener)
        Registers the swipe listener for the carousel.
        Parameters:
        mCarouselSwipeListener - listener for handling swipe gestures