|
|
@@ -60,31 +60,29 @@ public class MainBannerViewItemDotIndicator extends RecyclerView.ItemDecoration
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
|
|
- super.onDrawOver(c, parent, state);
|
|
|
+ public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
|
|
|
+ super.onDrawOver(canvas, parent, state);
|
|
|
|
|
|
int itemCount = parent.getAdapter().getItemCount();
|
|
|
|
|
|
- Log.e("APP# MainBannerViewItemDotIndicator | onDrawOver", "|" + itemCount);
|
|
|
float totalLength = mIndicatorItemLength * itemCount;
|
|
|
float paddingBetweenItems = Math.max(0, itemCount - 1) * mIndicatorItemPadding;
|
|
|
float indicatorTotalWidth = totalLength + paddingBetweenItems;
|
|
|
float indicatorStartX = (parent.getWidth() - indicatorTotalWidth) / 2F;
|
|
|
float indicatorPosY = parent.getHeight() - mIndicatorHeight / 2F;
|
|
|
|
|
|
- drawInactiveIndicators(c, indicatorStartX, indicatorPosY, itemCount);
|
|
|
+ drawInactiveIndicators(canvas, indicatorStartX, indicatorPosY, itemCount);
|
|
|
|
|
|
// find active page (which should be highlighted)
|
|
|
LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
|
|
|
int activePosition = layoutManager.findFirstVisibleItemPosition();
|
|
|
- Log.e("APP# MainBannerViewItemDotIndicator | onDrawOver", "|" + activePosition);
|
|
|
+ Log.e("APP# MainBannerViewItemDotIndicator | onDrawOver", "| activePosition: " + activePosition);
|
|
|
+
|
|
|
if (activePosition == RecyclerView.NO_POSITION) {
|
|
|
return;
|
|
|
}
|
|
|
- if(activePosition !=0){
|
|
|
|
|
|
- drawHighlights(c, indicatorStartX, indicatorPosY, activePosition, itemCount);
|
|
|
- }
|
|
|
+ drawHighlights(canvas, indicatorStartX, indicatorPosY, activePosition, itemCount);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -104,23 +102,20 @@ public class MainBannerViewItemDotIndicator extends RecyclerView.ItemDecoration
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void drawHighlights(Canvas c, float indicatorStartX, float indicatorPosY,
|
|
|
+ private void drawHighlights(Canvas canvas, float indicatorStartX, float indicatorPosY,
|
|
|
int highlightPosition, int itemCount) {
|
|
|
mPaint.setColor(colorActive);
|
|
|
|
|
|
// width of item indicator including padding
|
|
|
final float itemWidth = mIndicatorItemLength + mIndicatorItemPadding;
|
|
|
- Log.e("APP# MainBannerViewItemDotIndicator | drawHighlights", "|" + highlightPosition);
|
|
|
-
|
|
|
- // no swipe, draw a normal indicator
|
|
|
- float highlightStart = indicatorStartX + itemWidth * highlightPosition;
|
|
|
- c.drawCircle(highlightStart, indicatorPosY, mIndicatorItemLength / 2F, mPaint);
|
|
|
|
|
|
- // draw the highlight overlapping to the next item as well
|
|
|
- if (highlightPosition < itemCount - 1) {
|
|
|
- highlightStart += itemWidth;
|
|
|
- c.drawCircle(highlightStart, indicatorPosY, mIndicatorItemLength / 2F, mPaint);
|
|
|
+ float start = indicatorStartX;
|
|
|
+ for (int i = 0; i < itemCount; i++) {
|
|
|
+ if (i == highlightPosition) {
|
|
|
+ canvas.drawCircle(start, indicatorPosY, mIndicatorItemLength / 2F, mPaint);
|
|
|
}
|
|
|
+ start += itemWidth;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
}
|