diff --git a/README.md b/README.md index 791e8ff..008b6ae 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ Supports ViewPager, RecyclerView and attaching to custom pagers. ![preview](readmeAssets/demo.gif) ![preview](readmeAssets/demo-horizontal.gif) +![Custom drawables](readmeAssets/custom-drawables.gif) ## Getting started Add dependency to Gradle script: @@ -108,18 +109,20 @@ And then you can attach your pager like this: indicator.attachToPager(pager, new ViewPagerAttacher()); ``` ## Customization -| Attribute| Explanation| Default Value | -|-----------------------|-----------------------|--------| -| spi_dotSize| The diameter of a dot.| ```6dp```| -| spi_dotSelectedSize| The diameter of a currently selected dot.| ```10dp```| -| spi_dotColor | The color of a dot. | ```@android:color/darker_gray```| -| spi_dotSelectedColor| The color of the currently selected dot.| ```@android:color/darker_gray``` | -| spi_dotSpacing | The distance from center to center of each dot. | ```8dp``` | -| spi_visibleDotCount | The maximum number of dots which will be visible at the same time. If pager has more pages than visible_dot_count, indicator will scroll to show extra dots. Must be odd number. | ```5``` | -| spi_visibleDotThreshold | The minimum number of dots which should be visible. If pager has less pages than visibleDotThreshold, no dots will be shown. | ```2``` | -| spi_looped | The mode for looped pagers support. You should make indicator looped if your custom pager is looped too. If pager has less items than ```spi_visibleDotCount```, indicator will work as usual; otherwise it will always be in infinite state. | ```false```| -| spi_dotMinimumSize | The minimum dot size for the corner dots. This size is lower or equal to ```spi_dotSize``` and greater or equal to the internal calculation for the corner dots. | Internal calculation based on ```spi_dotSize```, ```spi_dotSelectedSize``` and ```spi_dotSpacing``` | -| spi_orientation | Visible orientation of the dots | LinearLayoutManager.HORIZONTAL | +| Attribute | Explanation | Default Value | +|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------| +| spi_dotSize | The diameter of a dot. | ```6dp``` | +| spi_dotSelectedSize | The diameter of a currently selected dot. | ```10dp``` | +| spi_dotColor | The color of a dot. | ```@android:color/darker_gray``` | +| spi_dotSelectedColor | The color of the currently selected dot. | ```@android:color/darker_gray``` | +| spi_dotSpacing | The distance from center to center of each dot. | ```8dp``` | +| spi_visibleDotCount | The maximum number of dots which will be visible at the same time. If pager has more pages than visible_dot_count, indicator will scroll to show extra dots. Must be odd number. | ```5``` | +| spi_visibleDotThreshold | The minimum number of dots which should be visible. If pager has less pages than visibleDotThreshold, no dots will be shown. | ```2``` | +| spi_looped | The mode for looped pagers support. You should make indicator looped if your custom pager is looped too. If pager has less items than ```spi_visibleDotCount```, indicator will work as usual; otherwise it will always be in infinite state. | ```false``` | +| spi_dotMinimumSize | The minimum dot size for the corner dots. This size is lower or equal to ```spi_dotSize``` and greater or equal to the internal calculation for the corner dots. | Internal calculation based on ```spi_dotSize```, ```spi_dotSelectedSize``` and ```spi_dotSpacing``` | +| spi_orientation | Visible orientation of the dots | LinearLayoutManager.HORIZONTAL | +| spi_firstDotDrawable | Custom drawable of the first dot, color is tinted and size is changed like standard dots. If first dot is also the last one then this value is taken into account. | `null` | +| spi_lastDotDrawable | Custom drawable of the last dot, color is tinted and size is changed like standard dots. | `null` | ## TODO 1. Some extreme customizations may work incorrect. diff --git a/changelog.md b/changelog.md index 11ea239..e82096c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +## 1.2.4 +- Add support for custom first and last page indicators + ## 1.2.3 - updated target sdk version to 31 diff --git a/demo/src/main/java/ru/tinkoff/scrollingpagerindicator/demo/MainActivity.java b/demo/src/main/java/ru/tinkoff/scrollingpagerindicator/demo/MainActivity.java index 13a57c7..59b5a1a 100644 --- a/demo/src/main/java/ru/tinkoff/scrollingpagerindicator/demo/MainActivity.java +++ b/demo/src/main/java/ru/tinkoff/scrollingpagerindicator/demo/MainActivity.java @@ -54,8 +54,10 @@ protected void onCreate(Bundle savedInstanceState) { recyclerView.setPadding(screenWidth / 3, 0, screenWidth / 3, 0); ScrollingPagerIndicator recyclerIndicator = findViewById(R.id.recycler_indicator); + ScrollingPagerIndicator customRecyclerIndicator = findViewById(R.id.custom_recycler_indicator); // Consider page in the middle current recyclerIndicator.attachToRecyclerView(recyclerView); + customRecyclerIndicator.attachToRecyclerView(recyclerView); SnapHelper snapHelper = new PagerSnapHelper(); snapHelper.attachToRecyclerView(recyclerView); diff --git a/demo/src/main/res/drawable/baseline_accessibility_new_24.xml b/demo/src/main/res/drawable/baseline_accessibility_new_24.xml new file mode 100644 index 0000000..2fce7c6 --- /dev/null +++ b/demo/src/main/res/drawable/baseline_accessibility_new_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/demo/src/main/res/drawable/baseline_free_breakfast_24.xml b/demo/src/main/res/drawable/baseline_free_breakfast_24.xml new file mode 100644 index 0000000..c0bcb52 --- /dev/null +++ b/demo/src/main/res/drawable/baseline_free_breakfast_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/demo/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml index ec09193..059541b 100644 --- a/demo/src/main/res/layout/activity_main.xml +++ b/demo/src/main/res/layout/activity_main.xml @@ -30,7 +30,9 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@id/pager_title" app:spi_dotColor="@color/dotNormal" - app:spi_dotSelectedColor="@color/dotHighlight" /> + app:spi_dotSelectedColor="@color/dotHighlight" + app:spi_lastDotDrawable="@drawable/baseline_free_breakfast_24" + app:spi_firstDotDrawable="@drawable/baseline_accessibility_new_24" /> + + 1) { scaleDotByOffset(0, 1 - offset); } - } - else { // Vertical orientation + } else { // Vertical orientation scaleDotByOffset(page - 1, offset); scaleDotByOffset(page, 1 - offset); } @@ -551,7 +560,31 @@ protected void onDraw(Canvas canvas) { } paint.setColor(calculateDotColor(scale)); - if (orientation == LinearLayoutManager.HORIZONTAL) { + final Drawable dotDrawable; + if (i == firstVisibleDotPos) { + dotDrawable = firstDotDrawable; + } else if (i == lastVisibleDotPos) { + dotDrawable = lastDotDrawable; + } else { + dotDrawable = null; + } + if (dotDrawable != null) { + if (orientation == LinearLayoutManager.HORIZONTAL) { + dotDrawable.setBounds((int) (dot - visibleFramePosition - dotSelectedSize / 2), + getMeasuredHeight() / 2 - dotSelectedSize / 2, + (int) (dot - visibleFramePosition + dotSelectedSize / 2), + getMeasuredHeight() / 2 + dotSelectedSize / 2); + } else { + dotDrawable.setBounds(getMeasuredWidth() / 2 - dotSelectedSize / 2, + (int) (dot - visibleFramePosition - dotSelectedSize / 2), + getMeasuredWidth() / 2 + dotSelectedSize / 2, + (int) (dot - visibleFramePosition + dotSelectedSize / 2)); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + dotDrawable.setTint(paint.getColor()); + } + dotDrawable.draw(canvas); + } else if (orientation == LinearLayoutManager.HORIZONTAL) { float cx = dot - visibleFramePosition; if (autoRtl && isRtl()) { cx = getWidth() - cx; diff --git a/scrollingpagerindicator/src/main/res/values/attrs.xml b/scrollingpagerindicator/src/main/res/values/attrs.xml index fe36b51..38e55cb 100644 --- a/scrollingpagerindicator/src/main/res/values/attrs.xml +++ b/scrollingpagerindicator/src/main/res/values/attrs.xml @@ -17,5 +17,7 @@ + +