From 76696cc14b15fcb786e8f10b468124cd4ca9fa59 Mon Sep 17 00:00:00 2001 From: Nikita Olifer Date: Wed, 22 Aug 2018 19:17:41 +0300 Subject: [PATCH] Corner case fix. --- .../ScrollingPagerIndicator.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scrollingpagerindicator/src/main/java/ru/tinkoff/scrollingpagerindicator/ScrollingPagerIndicator.java b/scrollingpagerindicator/src/main/java/ru/tinkoff/scrollingpagerindicator/ScrollingPagerIndicator.java index 0fa68b2..1765cc0 100644 --- a/scrollingpagerindicator/src/main/java/ru/tinkoff/scrollingpagerindicator/ScrollingPagerIndicator.java +++ b/scrollingpagerindicator/src/main/java/ru/tinkoff/scrollingpagerindicator/ScrollingPagerIndicator.java @@ -377,7 +377,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @Override protected void onDraw(Canvas canvas) { - if (getDotCount() < visibleDotThreshold) { + int dotCount = getDotCount(); + if (dotCount < visibleDotThreshold) { return; } @@ -391,6 +392,12 @@ protected void onDraw(Canvas canvas) { + (int) (visibleFramePosition + visibleFrameWidth - getDotOffsetAt(firstVisibleDotPos)) / spaceBetweenDotCenters; + // If real dots count is less than we can draw inside visible frame, we move lastVisibleDotPos + // to the last item + if (firstVisibleDotPos == 0 && lastVisibleDotPos + 1 > dotCount) { + lastVisibleDotPos = dotCount - 1; + } + for (int i = firstVisibleDotPos; i <= lastVisibleDotPos; i++) { float dot = getDotOffsetAt(i); if (dot >= visibleFramePosition && dot < visibleFramePosition + visibleFrameWidth) { @@ -417,7 +424,7 @@ protected void onDraw(Canvas canvas) { // Additional scale for dots at corners if (itemCount > visibleDotCount) { float currentScaleDistance; - if (!looped && (i == 0 || i == getDotCount() - 1)) { + if (!looped && (i == 0 || i == dotCount - 1)) { currentScaleDistance = smallScaleDistance; } else { currentScaleDistance = scaleDistance;