Java Code Examples for androidx.viewpager.widget.ViewPager#OnPageChangeListener

The following examples show how to use androidx.viewpager.widget.ViewPager#OnPageChangeListener . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OmegaPagerRecyclerView.java    From OmegaRecyclerView with MIT License 5 votes vote down vote up
/**
 * Set a listener that will be invoked whenever the page changes or is incrementally
 * scrolled. See {@link ViewPager.OnPageChangeListener}.
 *
 * @param listener Listener to set
 * @deprecated Use {@link #addOnPageChangeListener(ViewPager.OnPageChangeListener)}
 * and {@link #removeOnPageChangeListener(ViewPager.OnPageChangeListener)} instead.
 */
@Deprecated
public void setOnPageChangeListener(@Nullable ViewPager.OnPageChangeListener listener) {
    if (listener != null) {
        addOnPageChangeListener(listener);
    } else {
        mViewPagerOnPageChangeListeners.clear();
    }
}
 
Example 2
Source File: OmegaPagerRecyclerView.java    From OmegaRecyclerView with MIT License 5 votes vote down vote up
@Override
public void onScroll(float currentViewPosition) {
    ViewPagerLayoutManager layoutManager = getLayoutManager();
    if (layoutManager == null) return;

    int currentIndex = getCurrentItem();
    int newIndex = layoutManager.getNextPosition();
    if (currentIndex != newIndex) {
        notifyScroll(currentViewPosition, currentIndex, newIndex,
                getViewHolder(currentIndex), getViewHolder(newIndex));

        if (!mViewPagerOnPageChangeListeners.isEmpty()) {
            float positionOffset;

            if (newIndex > currentIndex) {
                positionOffset = -currentViewPosition;
                if (positionOffset == 1) {
                    positionOffset = 0;
                    currentIndex += 1;
                }
            } else {
                positionOffset = 1 - currentViewPosition;
                currentIndex -= 1;
            }

            for (ViewPager.OnPageChangeListener listener : mViewPagerOnPageChangeListeners) {
                listener.onPageScrolled(currentIndex, positionOffset, 0);
            }
        }
    }
}
 
Example 3
Source File: TitlePageIndicator.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
@Override
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
    mListener = listener;
}
 
Example 4
Source File: PagerSlidingTabStrip.java    From EmojiChat with Apache License 2.0 4 votes vote down vote up
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
    this.delegatePageListener = listener;
}
 
Example 5
Source File: CirclePageIndicator.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
    mListener = listener;
}
 
Example 6
Source File: IntroActivity.java    From material-intro with MIT License 4 votes vote down vote up
@SuppressWarnings("unused")
public void removeOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
    if (listener != this.listener)
        miPager.removeOnPageChangeListener(listener);
}
 
Example 7
Source File: CirclePageIndicator.java    From Kore with Apache License 2.0 4 votes vote down vote up
@Override
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
    mListener = listener;
}
 
Example 8
Source File: IntroActivity.java    From material-intro with MIT License 4 votes vote down vote up
@SuppressWarnings("unused")
public void addOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
    miPager.addOnPageChangeListener(listener);
}
 
Example 9
Source File: ViewPagerAttacher.java    From ScrollingPagerIndicator with Apache License 2.0 4 votes vote down vote up
@Override
public void attachToPager(@NonNull final ScrollingPagerIndicator indicator, @NonNull final ViewPager pager) {
    attachedAdapter = pager.getAdapter();
    if (attachedAdapter == null) {
        throw new IllegalStateException("Set adapter before call attachToPager() method");
    }

    this.pager = pager;

    updateIndicatorDotsAndPosition(indicator);

    dataSetObserver = new DataSetObserver() {
        @Override
        public void onChanged() {
            indicator.reattach();
        }

        @Override
        public void onInvalidated() {
            onChanged();
        }
    };
    attachedAdapter.registerDataSetObserver(dataSetObserver);

    onPageChangeListener = new ViewPager.OnPageChangeListener() {

        boolean idleState = true;

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixel) {
            updateIndicatorOnPagerScrolled(indicator, position, positionOffset);
        }

        @Override
        public void onPageSelected(int position) {
            if (idleState) {
                updateIndicatorDotsAndPosition(indicator);
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            idleState = state == ViewPager.SCROLL_STATE_IDLE;
        }
    };
    pager.addOnPageChangeListener(onPageChangeListener);
}
 
Example 10
Source File: HoodDebugPageView.java    From under-the-hood with Apache License 2.0 4 votes vote down vote up
public void addViewPagerChangeListener(ViewPager.OnPageChangeListener listener) {
    checkPreconditions();
    viewPager.addOnPageChangeListener(listener);
}
 
Example 11
Source File: LinePageIndicator.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
@Override
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
    mListener = listener;
}
 
Example 12
Source File: CirclePageIndicator.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
@Override
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
    mListener = listener;
}
 
Example 13
Source File: SlidingTabLayout.java    From android-test with Apache License 2.0 2 votes vote down vote up
/**
 * Set the {@link ViewPager.OnPageChangeListener}. When using {@link SlidingTabLayout} you are
 * required to set any {@link ViewPager.OnPageChangeListener} through this method. This is so that
 * the layout can update it's scroll position correctly.
 *
 * @see ViewPager#setOnPageChangeListener(ViewPager.OnPageChangeListener)
 */
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
  mViewPagerPageChangeListener = listener;
}
 
Example 14
Source File: SlidingTabLayout.java    From arcusandroid with Apache License 2.0 2 votes vote down vote up
/**
 * Set the {@link ViewPager.OnPageChangeListener}. When using {@link arcus.app.common.view.SlidingTabLayout} you are
 * required to set any {@link ViewPager.OnPageChangeListener} through this method. This is so
 * that the layout can update it's scroll position correctly.
 *
 * @see ViewPager#setOnPageChangeListener(ViewPager.OnPageChangeListener)
 */
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
    mViewPagerPageChangeListener = listener;
}
 
Example 15
Source File: TabPageIndicator.java    From material with Apache License 2.0 2 votes vote down vote up
/**
    * Set a listener will be called when the current page is changed.
    * @param listener The {@link ViewPager.OnPageChangeListener} will be called.
    */
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
       mListener = listener;
   }
 
Example 16
Source File: VerticalViewPager.java    From DKVideoPlayer with Apache License 2.0 2 votes vote down vote up
/**
 * Set a separate OnPageChangeListener for internal use by the support library.
 *
 * @param listener Listener to set
 * @return The old listener that was set, if any.
 */
ViewPager.OnPageChangeListener setInternalPageChangeListener(ViewPager.OnPageChangeListener listener) {
    ViewPager.OnPageChangeListener oldListener = mInternalPageChangeListener;
    mInternalPageChangeListener = listener;
    return oldListener;
}
 
Example 17
Source File: OmegaPagerRecyclerView.java    From OmegaRecyclerView with MIT License 2 votes vote down vote up
/**
 * Remove a listener that was previously added via
 * {@link #addOnPageChangeListener(ViewPager.OnPageChangeListener)}.
 *
 * @param listener listener to remove
 */
public void removeOnPageChangeListener(@Nullable ViewPager.OnPageChangeListener listener) {
    mViewPagerOnPageChangeListeners.remove(listener);
}
 
Example 18
Source File: SmartTabLayout.java    From SmartTabLayout with Apache License 2.0 2 votes vote down vote up
/**
 * Set the {@link ViewPager.OnPageChangeListener}. When using {@link SmartTabLayout} you are
 * required to set any {@link ViewPager.OnPageChangeListener} through this method. This is so
 * that the layout can update it's scroll position correctly.
 *
 * @see ViewPager#setOnPageChangeListener(ViewPager.OnPageChangeListener)
 */
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
  viewPagerPageChangeListener = listener;
}
 
Example 19
Source File: PageIndicator.java    From Kore with Apache License 2.0 2 votes vote down vote up
/**
 * Set a page change listener which will receive forwarded events.
 *
 * @param listener
 */
void setOnPageChangeListener(ViewPager.OnPageChangeListener listener);
 
Example 20
Source File: OmegaPagerRecyclerView.java    From OmegaRecyclerView with MIT License 2 votes vote down vote up
/**
 * Add a listener that will be invoked whenever the page changes or is incrementally
 * scrolled. See {@link ViewPager.OnPageChangeListener}.
 * <p>
 * <p>Components that add a listener should take care to remove it when finished.
 * Other components that take ownership of a view may call {@link #clearOnPageChangeListeners()}
 * to remove all attached listeners.</p>
 *
 * @param listener listener to add
 */
public void addOnPageChangeListener(@Nullable ViewPager.OnPageChangeListener listener) {
    mViewPagerOnPageChangeListeners.add(listener);
}