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

The following examples show how to use androidx.viewpager.widget.ViewPager#SCROLL_STATE_SETTLING . 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: DeviceDetailPagerAdapter.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onPageScrollStateChanged(final int state) {
    handleScrollState(state);
    mScrollState = state;

    int nextIndex = mCurrentPosition + 1 == getCount() ? 0 : mCurrentPosition + 1;
    int prevIndex = mCurrentPosition - 1 < 0 ? getCount() - 1 : mCurrentPosition - 1;

    final ArcusProductFragment fragment = (ArcusProductFragment) instantiateItem(mViewPager, mCurrentSelectedPosition);
    final ArcusProductFragment next = (ArcusProductFragment) instantiateItem(mViewPager, nextIndex);
    final ArcusProductFragment prev = (ArcusProductFragment) instantiateItem(mViewPager, prevIndex);

    switch (state) {
        case ViewPager.SCROLL_STATE_DRAGGING:
            fragment.setNavThumbsVisible(false);
            next.setNavThumbsVisible(false);
            prev.setNavThumbsVisible(false);
            break;
        case ViewPager.SCROLL_STATE_IDLE:
            fragment.setNavThumbsVisible(true);
            next.setNavThumbsVisible(true);
            prev.setNavThumbsVisible(true);
            break;
        case ViewPager.SCROLL_STATE_SETTLING:
            fragment.setNavThumbsVisible(false);
            next.setNavThumbsVisible(false);
            prev.setNavThumbsVisible(false);
            break;
        default:
            fragment.setNavThumbsVisible(true);
            next.setNavThumbsVisible(true);
            prev.setNavThumbsVisible(true);
            break;
    }
}
 
Example 2
Source File: TabStripHelper.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
void updateView(boolean force) {
    if (force) {
        mLastPosition = mPosition;
        mLastOffset = mOffset;
        onViewPagerChanged(mPosition, mOffset);
    } else {
        if (mLastPosition != mPosition || mLastOffset != mOffset) {
            if (mScrollState == ViewPager.SCROLL_STATE_SETTLING && mOffset != 0) {
                if (mPosition >= mLastPosition) {
                    mLastPosition = mPosition;
                    if (mOffset > 0) {
                        mLastOffset = mOffset;
                        onViewPagerChanged(mPosition, mOffset);
                    } else {
                        // 忽略为负的情况,其为不正常回调
                        mOffset = mLastOffset;
                    }
                } else {
                    if (mPosition >= mPager.getCurrentItem()) {
                        mLastPosition = mPosition;
                        mLastOffset = mOffset;
                        onViewPagerChanged(mPosition, mOffset);
                    } else {
                        // 忽略超出当前子项位置的情况,其为不正常回调
                        mPosition = mLastPosition;
                        mOffset = mLastOffset;
                    }
                }
            } else {
                mLastPosition = mPosition;
                mLastOffset = mOffset;
                onViewPagerChanged(mPosition, mOffset);
            }
        }
    }
}
 
Example 3
Source File: TabLayoutHelper.java    From android-tablayouthelper with Apache License 2.0 5 votes vote down vote up
@Override
public void onPageScrolled(int position, float positionOffset,
                           int positionOffsetPixels) {
    final TabLayout tabLayout = mTabLayoutRef.get();
    if (tabLayout != null) {
        if (shouldUpdateScrollPosition()) {
            // Update the scroll position, only update the text selection if we're being
            // dragged (or we're settling after a drag)
            final boolean updateText = (mScrollState == ViewPager.SCROLL_STATE_DRAGGING)
                    || (mScrollState == ViewPager.SCROLL_STATE_SETTLING
                    && mPreviousScrollState == ViewPager.SCROLL_STATE_DRAGGING);
            tabLayout.setScrollPosition(position, positionOffset, updateText);
        }
    }
}
 
Example 4
Source File: TabIndicatorView.java    From material with Apache License 2.0 5 votes vote down vote up
@Override
public void onPageScrollStateChanged(int state) {
    switch (state){
        case ViewPager.SCROLL_STATE_IDLE:
            notifyTabScrollStateChanged(SCROLL_STATE_IDLE);
            break;
        case ViewPager.SCROLL_STATE_DRAGGING:
            notifyTabScrollStateChanged(SCROLL_STATE_DRAGGING);
            break;
        case ViewPager.SCROLL_STATE_SETTLING:
            notifyTabScrollStateChanged(SCROLL_STATE_SETTLING);
            break;
    }
}
 
Example 5
Source File: DeviceDetailPagerAdapter.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
private boolean isScrollStateSettling() {
    return mScrollState == ViewPager.SCROLL_STATE_SETTLING;
}
 
Example 6
Source File: TabLayoutHelper.java    From android-tablayouthelper with Apache License 2.0 4 votes vote down vote up
private boolean shouldUpdateScrollPosition() {
    return (mScrollState == ViewPager.SCROLL_STATE_DRAGGING) ||
            ((mScrollState == ViewPager.SCROLL_STATE_SETTLING) && (mPreviousScrollState == ViewPager.SCROLL_STATE_DRAGGING));
}