@Override
    public void onPageSelected(int position) {
        if (isAttachedToWindow) {
            setSelectedPage(position);
            // this is the main event we're interested in!
        } else {
            // when not attached, don't animate the move, just store immediately
            setCurrentPageImmediate();
        }
    }
An ink inspired widget for indicating pages in a {@link ViewPager}.
library/src/main/java/com/heinrichreimersoftware/materialintro/view/InkPageIndicator.java