Search in sources :

Example 6 with PositionData

use of net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData in project MagicIndicator by hackware1993.

the class WrapPagerIndicator method onPageScrolled.

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    if (mPositionDataList == null || mPositionDataList.isEmpty()) {
        return;
    }
    // 计算锚点位置
    PositionData current = FragmentContainerHelper.getImitativePositionData(mPositionDataList, position);
    PositionData next = FragmentContainerHelper.getImitativePositionData(mPositionDataList, position + 1);
    mRect.left = current.mContentLeft - mHorizontalPadding + (next.mContentLeft - current.mContentLeft) * mEndInterpolator.getInterpolation(positionOffset);
    mRect.top = current.mContentTop - mVerticalPadding;
    mRect.right = current.mContentRight + mHorizontalPadding + (next.mContentRight - current.mContentRight) * mStartInterpolator.getInterpolation(positionOffset);
    mRect.bottom = current.mContentBottom + mVerticalPadding;
    if (!mRoundRadiusSet) {
        mRoundRadius = mRect.height() / 2;
    }
    invalidate();
}
Also used : PositionData(net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData)

Example 7 with PositionData

use of net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData in project MagicIndicator by hackware1993.

the class DotPagerIndicator method onPageSelected.

@Override
public void onPageSelected(int position) {
    if (mDataList == null || mDataList.isEmpty()) {
        return;
    }
    PositionData data = mDataList.get(position);
    mCircleCenterX = data.mLeft + data.width() / 2;
    invalidate();
}
Also used : PositionData(net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData)

Example 8 with PositionData

use of net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData in project MagicIndicator by hackware1993.

the class FragmentContainerHelper method getImitativePositionData.

/**
     * IPagerIndicator支持弹性效果的辅助方法
     *
     * @param positionDataList
     * @param index
     * @return
     */
public static PositionData getImitativePositionData(List<PositionData> positionDataList, int index) {
    if (index >= 0 && index <= positionDataList.size() - 1) {
        // 越界后,返回假的PositionData
        return positionDataList.get(index);
    } else {
        PositionData result = new PositionData();
        PositionData referenceData;
        int offset;
        if (index < 0) {
            offset = index;
            referenceData = positionDataList.get(0);
        } else {
            offset = index - positionDataList.size() + 1;
            referenceData = positionDataList.get(positionDataList.size() - 1);
        }
        result.mLeft = referenceData.mLeft + offset * referenceData.width();
        result.mTop = referenceData.mTop;
        result.mRight = referenceData.mRight + offset * referenceData.width();
        result.mBottom = referenceData.mBottom;
        result.mContentLeft = referenceData.mContentLeft + offset * referenceData.width();
        result.mContentTop = referenceData.mContentTop;
        result.mContentRight = referenceData.mContentRight + offset * referenceData.width();
        result.mContentBottom = referenceData.mContentBottom;
        return result;
    }
}
Also used : PositionData(net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData)

Example 9 with PositionData

use of net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData in project MagicIndicator by hackware1993.

the class CommonNavigator method onPageScrolled.

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    if (mAdapter != null) {
        mNavigatorHelper.onPageScrolled(position, positionOffset, positionOffsetPixels);
        if (mIndicator != null) {
            mIndicator.onPageScrolled(position, positionOffset, positionOffsetPixels);
        }
        // 手指跟随滚动
        if (mScrollView != null && mPositionDataList.size() > 0 && position >= 0 && position < mPositionDataList.size()) {
            if (mFollowTouch) {
                int currentPosition = Math.min(mPositionDataList.size() - 1, position);
                int nextPosition = Math.min(mPositionDataList.size() - 1, position + 1);
                PositionData current = mPositionDataList.get(currentPosition);
                PositionData next = mPositionDataList.get(nextPosition);
                float scrollTo = current.horizontalCenter() - mScrollView.getWidth() * mScrollPivotX;
                float nextScrollTo = next.horizontalCenter() - mScrollView.getWidth() * mScrollPivotX;
                mScrollView.scrollTo((int) (scrollTo + (nextScrollTo - scrollTo) * positionOffset), 0);
            } else if (!mEnablePivotScroll) {
            // TODO 实现待选中项完全显示出来
            }
        }
    }
}
Also used : PositionData(net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData)

Example 10 with PositionData

use of net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData in project MagicIndicator by hackware1993.

the class LinePagerIndicator method onPageScrolled.

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    if (mPositionDataList == null || mPositionDataList.isEmpty()) {
        return;
    }
    // 计算颜色
    if (mColors != null && mColors.size() > 0) {
        int currentColor = mColors.get(Math.abs(position) % mColors.size());
        int nextColor = mColors.get(Math.abs(position + 1) % mColors.size());
        int color = ArgbEvaluatorHolder.eval(positionOffset, currentColor, nextColor);
        mPaint.setColor(color);
    }
    // 计算锚点位置
    PositionData current = FragmentContainerHelper.getImitativePositionData(mPositionDataList, position);
    PositionData next = FragmentContainerHelper.getImitativePositionData(mPositionDataList, position + 1);
    float leftX;
    float nextLeftX;
    float rightX;
    float nextRightX;
    if (mMode == MODE_MATCH_EDGE) {
        leftX = current.mLeft + mXOffset;
        nextLeftX = next.mLeft + mXOffset;
        rightX = current.mRight - mXOffset;
        nextRightX = next.mRight - mXOffset;
    } else if (mMode == MODE_WRAP_CONTENT) {
        leftX = current.mContentLeft + mXOffset;
        nextLeftX = next.mContentLeft + mXOffset;
        rightX = current.mContentRight - mXOffset;
        nextRightX = next.mContentRight - mXOffset;
    } else {
        // MODE_EXACTLY
        leftX = current.mLeft + (current.width() - mLineWidth) / 2;
        nextLeftX = next.mLeft + (next.width() - mLineWidth) / 2;
        rightX = current.mLeft + (current.width() + mLineWidth) / 2;
        nextRightX = next.mLeft + (next.width() + mLineWidth) / 2;
    }
    mLineRect.left = leftX + (nextLeftX - leftX) * mStartInterpolator.getInterpolation(positionOffset);
    mLineRect.right = rightX + (nextRightX - rightX) * mEndInterpolator.getInterpolation(positionOffset);
    mLineRect.top = getHeight() - mLineHeight - mYOffset;
    mLineRect.bottom = getHeight() - mYOffset;
    invalidate();
}
Also used : PositionData(net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData) Paint(android.graphics.Paint)

Aggregations

PositionData (net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData)11 Paint (android.graphics.Paint)2 View (android.view.View)2 HorizontalScrollView (android.widget.HorizontalScrollView)2 IMeasurablePagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IMeasurablePagerTitleView)2 IPagerTitleView (net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView)2