use of net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData in project MagicIndicator by hackware1993.
the class CommonNavigator method preparePositionData.
/**
* 获取title的位置信息,为打造不同的指示器、各种效果提供可能
*/
private void preparePositionData() {
mPositionDataList.clear();
for (int i = 0, j = mNavigatorHelper.getTotalCount(); i < j; i++) {
PositionData data = new PositionData();
View v = mTitleContainer.getChildAt(i);
if (v != null) {
data.mLeft = v.getLeft();
data.mTop = v.getTop();
data.mRight = v.getRight();
data.mBottom = v.getBottom();
if (v instanceof IMeasurablePagerTitleView) {
IMeasurablePagerTitleView view = (IMeasurablePagerTitleView) v;
data.mContentLeft = view.getContentLeft();
data.mContentTop = view.getContentTop();
data.mContentRight = view.getContentRight();
data.mContentBottom = view.getContentBottom();
} else {
data.mContentLeft = data.mLeft;
data.mContentTop = data.mTop;
data.mContentRight = data.mRight;
data.mContentBottom = data.mBottom;
}
}
mPositionDataList.add(data);
}
}
use of net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData in project MagicIndicator by hackware1993.
the class CommonNavigator method onSelected.
@Override
public void onSelected(int index, int totalCount) {
if (mTitleContainer == null) {
return;
}
View v = mTitleContainer.getChildAt(index);
if (v instanceof IPagerTitleView) {
((IPagerTitleView) v).onSelected(index, totalCount);
}
if (!mAdjustMode && !mFollowTouch && mScrollView != null && mPositionDataList.size() > 0) {
int currentIndex = Math.min(mPositionDataList.size() - 1, index);
PositionData current = mPositionDataList.get(currentIndex);
if (mEnablePivotScroll) {
float scrollTo = current.horizontalCenter() - mScrollView.getWidth() * mScrollPivotX;
if (mSmoothScroll) {
mScrollView.smoothScrollTo((int) (scrollTo), 0);
} else {
mScrollView.scrollTo((int) (scrollTo), 0);
}
} else {
// 如果当前项被部分遮挡,则滚动显示完全
if (mScrollView.getScrollX() > current.mLeft) {
if (mSmoothScroll) {
mScrollView.smoothScrollTo(current.mLeft, 0);
} else {
mScrollView.scrollTo(current.mLeft, 0);
}
} else if (mScrollView.getScrollX() + getWidth() < current.mRight) {
if (mSmoothScroll) {
mScrollView.smoothScrollTo(current.mRight - getWidth(), 0);
} else {
mScrollView.scrollTo(current.mRight - getWidth(), 0);
}
}
}
}
}
use of net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData in project MagicIndicator by hackware1993.
the class BezierPagerIndicator 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 = current.mLeft + (current.mRight - current.mLeft) / 2;
float rightX = next.mLeft + (next.mRight - next.mLeft) / 2;
mLeftCircleX = leftX + (rightX - leftX) * mStartInterpolator.getInterpolation(positionOffset);
mRightCircleX = leftX + (rightX - leftX) * mEndInterpolator.getInterpolation(positionOffset);
mLeftCircleRadius = mMaxCircleRadius + (mMinCircleRadius - mMaxCircleRadius) * mEndInterpolator.getInterpolation(positionOffset);
mRightCircleRadius = mMinCircleRadius + (mMaxCircleRadius - mMinCircleRadius) * mStartInterpolator.getInterpolation(positionOffset);
invalidate();
}
use of net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData in project MagicIndicator by hackware1993.
the class CommonPagerIndicator method onPageScrolled.
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (mIndicatorDrawable == null) {
return;
}
if (mPositionDataList == null || mPositionDataList.isEmpty()) {
return;
}
// 计算锚点位置
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;
mDrawableRect.top = (int) mYOffset;
mDrawableRect.bottom = (int) (getHeight() - mYOffset);
} else if (mMode == MODE_WRAP_CONTENT) {
leftX = current.mContentLeft + mXOffset;
nextLeftX = next.mContentLeft + mXOffset;
rightX = current.mContentRight - mXOffset;
nextRightX = next.mContentRight - mXOffset;
mDrawableRect.top = (int) (current.mContentTop - mYOffset);
mDrawableRect.bottom = (int) (current.mContentBottom + mYOffset);
} else {
// MODE_EXACTLY
leftX = current.mLeft + (current.width() - mDrawableWidth) / 2;
nextLeftX = next.mLeft + (next.width() - mDrawableWidth) / 2;
rightX = current.mLeft + (current.width() + mDrawableWidth) / 2;
nextRightX = next.mLeft + (next.width() + mDrawableWidth) / 2;
mDrawableRect.top = (int) (getHeight() - mDrawableHeight - mYOffset);
mDrawableRect.bottom = (int) (getHeight() - mYOffset);
}
mDrawableRect.left = (int) (leftX + (nextLeftX - leftX) * mStartInterpolator.getInterpolation(positionOffset));
mDrawableRect.right = (int) (rightX + (nextRightX - rightX) * mEndInterpolator.getInterpolation(positionOffset));
mIndicatorDrawable.setBounds(mDrawableRect);
invalidate();
}
use of net.lucode.hackware.magicindicator.buildins.commonnavigator.model.PositionData in project MagicIndicator by hackware1993.
the class TestPagerIndicator 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);
mOutRect.left = current.mLeft + (next.mLeft - current.mLeft) * positionOffset;
mOutRect.top = current.mTop + (next.mTop - current.mTop) * positionOffset;
mOutRect.right = current.mRight + (next.mRight - current.mRight) * positionOffset;
mOutRect.bottom = current.mBottom + (next.mBottom - current.mBottom) * positionOffset;
mInnerRect.left = current.mContentLeft + (next.mContentLeft - current.mContentLeft) * positionOffset;
mInnerRect.top = current.mContentTop + (next.mContentTop - current.mContentTop) * positionOffset;
mInnerRect.right = current.mContentRight + (next.mContentRight - current.mContentRight) * positionOffset;
mInnerRect.bottom = current.mContentBottom + (next.mContentBottom - current.mContentBottom) * positionOffset;
invalidate();
}
Aggregations