├── .gitignore
├── .idea
└── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── .travis.yml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── chahinem
│ │ └── pageindicator
│ │ └── sample
│ │ ├── MainActivity.kt
│ │ ├── MyAdapter.kt
│ │ └── MyPagerAdapter.kt
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ └── ic_launcher_background.xml
│ ├── layout
│ ├── activity_main.xml
│ ├── item_card.xml
│ └── item_simple.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── art
├── pageindicator.gif
└── pageindicator.mp4
├── build.gradle
├── dependencies.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── pageindicator
├── .gitignore
├── build.gradle
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── chahinem
│ │ │ └── pageindicator
│ │ │ ├── DotManager.kt
│ │ │ ├── Dps.kt
│ │ │ ├── PageChangeListener.kt
│ │ │ ├── PageIndicator.kt
│ │ │ ├── SavedState.kt
│ │ │ └── ScrollListener.kt
│ └── res
│ │ ├── anim
│ │ └── pi_default_interpolator.xml
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── chahinem
│ └── pageindicator
│ └── DotManagerTest.kt
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # [Android] ========================
2 | # Built application files
3 | *.apk
4 | *.ap_
5 |
6 | # Files for the Dalvik VM
7 | *.dex
8 |
9 | # Java class files
10 | *.class
11 |
12 | # Generated files
13 | bin/
14 | gen/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 |
30 | ## Directory-based project format:
31 | .idea/
32 |
33 | ## File-based project format:
34 | *.ipr
35 | *.iws
36 |
37 | ## Plugin-specific files:
38 |
39 | # IntelliJ
40 | out/
41 |
42 | # mpeltonen/sbt-idea plugin
43 | .idea_modules/
44 |
45 | # JIRA plugin
46 | atlassian-ide-plugin.xml
47 |
48 | # Crashlytics plugin (for Android Studio and IntelliJ)
49 | com_crashlytics_export_strings.xml
50 |
51 |
52 | # [Maven] ========================
53 | target/
54 | pom.xml.tag
55 | pom.xml.releaseBackup
56 | pom.xml.versionsBackup
57 | pom.xml.next
58 | release.properties
59 |
60 |
61 | # [Gradle-Android] ========================
62 |
63 | # Ignore Gradle GUI config
64 | gradle-app.setting
65 |
66 | # Gradle Signing
67 | signing.properties
68 | trestle.keystore
69 |
70 | # Mobile Tools for Java (J2ME)
71 | .mtj.tmp/
72 |
73 | # Package Files #
74 | *.jar
75 | *.war
76 | *.ear
77 |
78 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
79 | hs_err_pid*
80 |
81 | # Misc
82 | /.idea/workspace.xml
83 | .DS_Store
84 | /captures
85 | **/*.iml
86 | *.classgradle.properties
87 |
88 |
89 | # keep code style
90 | !.idea/codeStyles/
91 | !.idea/codeStyles/**
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 | true
210 | true
211 | true
212 | true
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 | true
222 | true
223 | true
224 | true
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 | true
234 | true
235 | true
236 | true
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 | true
246 | true
247 | true
248 | true
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 | true
258 | true
259 | true
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 | true
269 | true
270 | true
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 | true
280 | true
281 | true
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 | true
291 | true
292 | true
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 | true
302 | true
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 |
311 | true
312 | true
313 | true
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 | true
323 | true
324 | true
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 | true
334 | true
335 | true
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 | true
345 | true
346 | true
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 | true
356 | true
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 | true
366 | true
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 | true
376 | true
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 | true
386 | true
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 | true
395 |
396 |
397 |
398 |
399 |
400 |
401 | true
402 |
403 |
404 |
405 |
406 |
407 |
408 | true
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 | true
417 | true
418 |
419 |
420 | BY_NAME
421 |
422 |
423 |
424 |
425 |
426 |
427 | getLayoutId
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 | initializeDependencyInjector
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 | onAttach
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 | onCreate
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 | onCreateView
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 | onViewCreated
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 | onActivityCreated
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 | onStart
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 | onActivityResult
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 | onPostCreate
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 | onResume
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 | onPostResume
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 | onNewIntent
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 | onCreateOptionsMenu
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 | onPrepareOptionsMenu
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 | onOptionsItemSelected
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 | onPause
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 | onSaveInstanceState
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 | onStop
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 | onDestroyView
618 |
619 |
620 |
621 |
622 |
623 |
624 |
625 |
626 |
627 | onDestroy
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 | onDetach
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 | getSystemService
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 | true
658 | setUpViews
659 | true
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 | true
669 | observeView
670 |
671 |
672 |
673 |
674 |
675 |
676 |
677 |
678 |
679 | true
680 | toBuilder
681 |
682 |
683 |
684 |
685 |
686 |
687 |
688 |
689 | true
690 |
691 |
692 |
693 | BY_NAME
694 |
695 |
696 |
697 |
698 |
699 |
700 | true
701 |
702 | true
703 | true
704 |
705 |
706 | BY_NAME
707 |
708 |
709 |
710 |
711 |
712 |
713 | true
714 | true
715 |
716 |
717 | BY_NAME
718 |
719 |
720 |
721 |
722 |
723 |
724 | true
725 | true
726 |
727 |
728 | BY_NAME
729 |
730 |
731 |
732 |
733 |
734 |
735 | true
736 | true
737 |
738 |
739 | BY_NAME
740 |
741 |
742 |
743 |
744 |
745 |
746 | true
747 | true
748 |
749 |
750 | BY_NAME
751 |
752 |
753 |
754 |
755 |
756 | true
757 |
758 | BY_NAME
759 |
760 |
761 |
762 |
763 |
764 | true
765 |
766 | BY_NAME
767 |
768 |
769 |
770 |
771 |
772 | true
773 |
774 | BY_NAME
775 |
776 |
777 |
778 |
779 |
780 |
781 | true
782 | true
783 |
784 |
785 | BY_NAME
786 |
787 |
788 |
789 |
790 |
791 | true
792 |
793 | BY_NAME
794 |
795 |
796 |
797 |
798 |
799 |
800 |
801 |
802 |
803 |
804 |
805 |
806 |
807 |
808 |
809 |
810 |
811 |
812 |
813 |
814 |
815 |
816 |
817 |
818 |
819 |
820 |
821 |
822 |
823 |
824 |
825 |
826 |
827 |
828 |
829 |
830 |
831 |
832 |
833 |
834 |
835 |
836 |
837 |
838 |
839 |
840 |
841 |
842 |
843 |
844 |
845 |
846 |
847 |
848 |
849 |
850 |
851 |
852 |
853 |
854 |
855 |
856 |
857 |
858 |
859 |
860 |
861 |
862 |
863 |
864 |
865 |
866 |
867 |
868 | class
869 |
870 |
871 |
872 |
873 |
874 |
875 | layout
876 |
877 |
878 |
879 |
880 |
881 |
882 | xmlns:android
883 |
884 |
885 |
886 |
887 |
888 |
889 | xmlns:.*
890 |
891 | BY_NAME
892 |
893 |
894 |
895 |
896 |
897 | type
898 |
899 |
900 |
901 |
902 |
903 |
904 |
905 | .*:id
906 | http://schemas.android.com/apk/res/android
907 |
908 |
909 |
910 |
911 |
912 |
913 |
914 |
915 | .*:name
916 | http://schemas.android.com/apk/res/android
917 |
918 |
919 |
920 |
921 |
922 |
923 |
924 |
925 | .*:layout_width
926 | http://schemas.android.com/apk/res/android
927 |
928 |
929 |
930 |
931 |
932 |
933 |
934 |
935 | .*:layout_height
936 | http://schemas.android.com/apk/res/android
937 |
938 |
939 |
940 |
941 |
942 |
943 |
944 |
945 | .*:layout_.*
946 | http://schemas.android.com/apk/res/android
947 |
948 |
949 | BY_NAME
950 |
951 |
952 |
953 |
954 |
955 | http://schemas.android.com/apk/res/android
956 |
957 | BY_NAME
958 |
959 |
960 |
961 |
962 |
963 | http://schemas.android.com/apk/res-auto
964 |
965 | BY_NAME
966 |
967 |
968 |
969 |
970 |
971 | http://schemas.android.com/tools
972 |
973 | BY_NAME
974 |
975 |
976 |
977 |
978 |
979 |
980 |
981 |
982 |
983 |
984 |
985 |
986 |
987 |
988 |
989 |
990 |
991 |
992 |
993 |
994 |
995 |
996 |
997 |
998 |
999 |
1000 |
1001 |
1002 |
1003 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 |
3 | language: android
4 | dist: trusty
5 |
6 | android:
7 | components:
8 | - tools
9 | - platform-tools
10 | - build-tools-28.0.3
11 | - android-28
12 | - extra-google-m2repository
13 | - extra-android-m2repository
14 | licenses:
15 | - 'android-sdk-license-.+'
16 | - 'google-gdk-license-.+'
17 |
18 | before_install:
19 | - echo yes | sdkmanager "platforms;android-28"
20 |
21 | script:
22 | - ./gradlew clean build -PdisablePreDex --stacktrace --console plain
23 |
24 | jdk:
25 | - oraclejdk8
26 |
27 | branches:
28 | only:
29 | - master
30 |
31 | before_cache:
32 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
33 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/
34 | cache:
35 | directories:
36 | - $HOME/.gradle/caches/
37 | - $HOME/.gradle/wrapper/
38 | - $HOME/.android/build-cache
39 |
40 | sudo: false
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Chahine Mouhamad
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/chahine/pageindicator)
2 | [](https://jitpack.io/#chahine/pageindicator)
3 |
4 | # Page Indicator
5 |
6 | An Instagram like page indicator compatible with [RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html) and [ViewPager](https://developer.android.com/reference/android/support/v4/view/ViewPager.html).
7 |
8 | 
9 |
10 | # Setup
11 |
12 | __Step 1.__ Add the JitPack repository to your build file
13 | ```groovy
14 | allprojects {
15 | repositories {
16 | maven { url 'https://jitpack.io' }
17 | }
18 | }
19 | ```
20 | __Step 2.__ Add the dependency
21 |
22 | ```groovy
23 | dependencies {
24 | compile 'com.github.chahine:pageindicator:'
25 | }
26 | ```
27 |
28 | # Usage
29 |
30 | Add the `PageIndicator` to your XML file:
31 |
32 | ```xml
33 |
38 | ```
39 |
40 | #### RecyclerView
41 |
42 | ```kotlin
43 | pageIndicator.attachTo(recyclerView)
44 | ```
45 |
46 | By default, attaching to a RecyclerView will end up updating the pageIndicator when the most visible item position changes and expect the RecyclerView items to have the same width.
47 | If you would like to customize this behavior, add a scroll listener to your RecyclerView and use `PageIndicator::swipeNext` and `PageIndicator::swipePrevious`; and set the pageIndicator's count
48 |
49 | #### View Pager
50 |
51 | ```kotlin
52 | pageIndicator.attachTo(viewPager)
53 | ```
54 |
55 | #### Manual
56 | ```kotlin
57 | pageIndicator.swipePrevious()
58 | pageIndicator.swipeNext()
59 | ```
60 |
61 | # Customization
62 |
63 | | Attribute | Note | Default |
64 | |---------------------|-------------------------------------------|-------------|
65 | | piDotSpacing | Spacing between dots | 3dp |
66 | | piDotBound | Range in which the selected dot remains | 40dp |
67 | | piSize[1-6] | Size from smallest to largest dot | .5dp - 6dp |
68 | | piAnimDuration | Duration of animation* in ms | 200 |
69 | | piAnimInterpolator | Animation interpolator* | decelerate |
70 | | piDefaultColor | Default unselected dot color | #B2B2B2 |
71 | | piSelectedColor | Selected dot color | #3897F0 |
72 |
73 |
74 | *Note: the animation duration and interpolator are shared between the scroll animation and dot scaling animation.
75 |
76 | ## License
77 |
78 | ```
79 | MIT License
80 |
81 | Copyright (c) 2018 Chahine Mouhamad
82 |
83 | Permission is hereby granted, free of charge, to any person obtaining a copy
84 | of this software and associated documentation files (the "Software"), to deal
85 | in the Software without restriction, including without limitation the rights
86 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
87 | copies of the Software, and to permit persons to whom the Software is
88 | furnished to do so, subject to the following conditions:
89 |
90 | The above copyright notice and this permission notice shall be included in all
91 | copies or substantial portions of the Software.
92 |
93 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
94 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
95 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
96 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
97 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
98 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
99 | SOFTWARE.
100 |
101 | ```
102 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion rootProject.compileSdkVersion
7 |
8 | defaultConfig {
9 | applicationId 'com.chahinem.pageindicator.sample'
10 |
11 | minSdkVersion rootProject.minSdkVersion
12 | targetSdkVersion rootProject.targetSdkVersion
13 |
14 | versionCode 1
15 | versionName '1.0'
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation project(':pageindicator')
23 |
24 | implementation rootProject.kotlinStdlib
25 | implementation rootProject.picasso
26 | implementation rootProject.supportLibs
27 | }
28 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/java/com/chahinem/pageindicator/sample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.chahinem.pageindicator.sample
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import androidx.recyclerview.widget.LinearSnapHelper
6 | import com.chahinem.pageindicator.sample.MyAdapter.MyItem
7 | import com.squareup.picasso.Picasso.Builder
8 | import kotlinx.android.synthetic.main.activity_main.*
9 |
10 | class MainActivity : AppCompatActivity() {
11 |
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | super.onCreate(savedInstanceState)
14 | setContentView(R.layout.activity_main)
15 |
16 | val picasso = Builder(this).build()
17 |
18 | // RecyclerView
19 | val adapter = MyAdapter(picasso)
20 | list.adapter = adapter
21 | LinearSnapHelper().attachToRecyclerView(list)
22 | adapter.swapData(LIST_ITEMS)
23 | pageIndicator attachTo list
24 | pageIndicator2 attachTo list
25 |
26 | // ViewPager
27 | val myPagerAdapter = MyPagerAdapter(picasso, LIST_ITEMS)
28 | pager.adapter = myPagerAdapter
29 | pagerPageIndicator attachTo pager
30 |
31 | // Manual
32 | manualPageIndicator.count = 50
33 | leftBtn.setOnClickListener { manualPageIndicator.swipePrevious() }
34 | rightBtn.setOnClickListener { manualPageIndicator.swipeNext() }
35 | }
36 |
37 | companion object {
38 | private val LIST_ITEMS = listOf(
39 | MyItem(
40 | "Cormorant fishing at sunset",
41 | "Patryk Wojciechowicz",
42 | "https://cdn.dribbble.com/users/3178178/screenshots/6287074/cormorant_fishing_1600x1200_final_04_05_2019_4x.jpg"),
43 | MyItem(
44 | "Mountain House",
45 | "Alex Pasquarella",
46 | "https://cdn.dribbble.com/users/989466/screenshots/6100954/cabin-2-dribbble-alex-pasquarella_4x.png"),
47 | MyItem(
48 | "journey",
49 | "Febin_Raj",
50 | "https://cdn.dribbble.com/users/1803663/screenshots/6163551/nature-4_4x.png"),
51 | MyItem(
52 | "Explorer",
53 | "Uran",
54 | "https://cdn.dribbble.com/users/1355613/screenshots/6441984/landscape_4x.jpg"),
55 | MyItem(
56 | "Fishers Peak Limited Edition Print",
57 | "Brian Edward Miller ",
58 | "https://cdn.dribbble.com/users/329207/screenshots/6128300/bemocs_fisherspeak_dribbble.jpg"),
59 | MyItem(
60 | "First Man",
61 | "Lana Marandina",
62 | "https://cdn.dribbble.com/users/1461762/screenshots/6280906/first_man_lana_marandina_4x.png"),
63 | MyItem(
64 | "On The Road Again",
65 | "Brian Edward Miller",
66 | "https://cdn.dribbble.com/users/329207/screenshots/6522800/2026_nationwide_02_train_landscape_v01.00.jpg")
67 | )
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/chahinem/pageindicator/sample/MyAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.chahinem.pageindicator.sample
2 |
3 | import android.view.LayoutInflater
4 | import android.view.View
5 | import android.view.ViewGroup
6 | import android.widget.ImageView
7 | import android.widget.TextView
8 | import androidx.recyclerview.widget.RecyclerView
9 | import com.chahinem.pageindicator.sample.MyAdapter.MyViewHolder
10 | import com.squareup.picasso.Picasso
11 |
12 | class MyAdapter(private val picasso: Picasso) : RecyclerView.Adapter() {
13 |
14 | private val items: MutableList = mutableListOf()
15 |
16 | override fun getItemCount() = items.size
17 |
18 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = MyViewHolder(
19 | LayoutInflater
20 | .from(parent.context)
21 | .inflate(R.layout.item_card, parent, false))
22 |
23 | override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
24 | holder.bind(picasso, items[holder.adapterPosition])
25 | }
26 |
27 | fun swapData(data: Iterable?) {
28 | items.clear()
29 | data?.let { items.addAll(data) }
30 | notifyDataSetChanged()
31 | }
32 |
33 | class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
34 |
35 | private val title: TextView = itemView.findViewById(R.id.title)
36 | private val caption: TextView = itemView.findViewById(R.id.caption)
37 | private val image: ImageView = itemView.findViewById(R.id.image)
38 |
39 | fun bind(picasso: Picasso, item: MyItem) {
40 | picasso
41 | .load(item.image)
42 | .placeholder(R.color.colorPrimaryDark)
43 | .fit()
44 | .centerCrop()
45 | .into(image)
46 | title.text = item.title
47 | caption.text = item.caption
48 | }
49 | }
50 |
51 | class MyItem(val title: String, val caption: String, val image: String)
52 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/chahinem/pageindicator/sample/MyPagerAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.chahinem.pageindicator.sample
2 |
3 | import android.view.LayoutInflater
4 | import android.view.View
5 | import android.view.ViewGroup
6 | import android.widget.ImageView
7 | import android.widget.TextView
8 | import androidx.viewpager.widget.PagerAdapter
9 | import com.chahinem.pageindicator.sample.MyAdapter.MyItem
10 | import com.squareup.picasso.Picasso
11 |
12 | class MyPagerAdapter(private val picasso: Picasso,
13 | private val items: List) : PagerAdapter() {
14 |
15 | override fun getCount() = items.size
16 |
17 | override fun isViewFromObject(view: View, `object`: Any): Boolean = view == `object`
18 |
19 | override fun instantiateItem(container: ViewGroup, position: Int): Any {
20 | val view = LayoutInflater
21 | .from(container.context)
22 | .inflate(R.layout.item_card, container, false)
23 |
24 | val item = items[position]
25 | val title: TextView = view.findViewById(R.id.title)
26 | val caption: TextView = view.findViewById(R.id.caption)
27 | val image: ImageView = view.findViewById(R.id.image)
28 |
29 | picasso
30 | .load(item.image)
31 | .placeholder(R.color.colorPrimaryDark)
32 | .fit()
33 | .centerCrop()
34 | .into(image)
35 | title.text = item.title
36 | caption.text = item.caption
37 |
38 | container.addView(view)
39 | return view
40 | }
41 |
42 | override fun destroyItem(container: ViewGroup, position: Int, view: Any) {
43 | container.removeView(view as View)
44 | }
45 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
8 |
14 |
15 |
22 |
26 |
30 |
31 |
32 |
33 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
13 |
19 |
25 |
31 |
37 |
43 |
49 |
55 |
61 |
67 |
73 |
79 |
85 |
91 |
97 |
103 |
109 |
115 |
121 |
127 |
133 |
139 |
145 |
151 |
157 |
163 |
169 |
175 |
181 |
187 |
193 |
199 |
205 |
206 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
14 |
15 |
22 |
23 |
31 |
32 |
39 |
40 |
55 |
56 |
64 |
65 |
70 |
71 |
78 |
79 |
87 |
88 |
94 |
95 |
102 |
109 |
116 |
117 |
118 |
125 |
126 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
15 |
21 |
33 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_simple.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Page Indicator
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/art/pageindicator.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/art/pageindicator.gif
--------------------------------------------------------------------------------
/art/pageindicator.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/art/pageindicator.mp4
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | apply from: rootProject.file('dependencies.gradle')
3 | repositories {
4 | google()
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath "com.android.tools.build:gradle:$gradleVersion"
9 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
11 | }
12 | }
13 |
14 | plugins {
15 | id 'com.github.ben-manes.versions' version '0.21.0'
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | maven { url 'https://jitpack.io' }
23 | maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
24 | }
25 | }
26 |
27 | task clean(type: Delete) {
28 | delete rootProject.buildDir
29 | }
--------------------------------------------------------------------------------
/dependencies.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | // Android Version
3 | minSdkVersion = 14
4 | compileSdkVersion = 28
5 | targetSdkVersion = 28
6 | gradleVersion = '3.5.0-beta04'
7 | kotlinVersion = '1.3.40'
8 |
9 | // Kotlin
10 | kotlinStdlib = 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:' + kotlinVersion
11 |
12 | animatedVectorDrawable = "androidx.vectordrawable:vectordrawable-animated:1.0.0"
13 | appcompatV7 = "androidx.appcompat:appcompat:1.0.0"
14 | cardView = "androidx.cardview:cardview:1.0.0"
15 | design = "com.google.android.material:material:1.0.0"
16 | exifinterface = "androidx.exifinterface:exifinterface:1.0.0"
17 | recyclerviewV7 = "androidx.recyclerview:recyclerview:1.0.0"
18 | supportAnnotations = "androidx.annotation:annotation:1.1.0"
19 | constraintLayout = "androidx.constraintlayout:constraintlayout:1.1.2"
20 |
21 | picasso = 'com.squareup.picasso:picasso:2.71828'
22 |
23 | supportLibs = [animatedVectorDrawable,
24 | appcompatV7,
25 | cardView,
26 | design,
27 | exifinterface,
28 | recyclerviewV7,
29 | supportAnnotations,
30 | constraintLayout]
31 |
32 | junit = 'junit:junit:4.12'
33 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | android.enableJetifier = true
2 | android.useAndroidX = true
3 | org.gradle.jvmargs = -Xmx1536m
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chahine/pageindicator/a3d3325b79852c44e2b48751764c3fb922e265ea/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase = GRADLE_USER_HOME
2 | distributionPath = wrapper/dists
3 | distributionUrl = https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
4 | zipStoreBase = GRADLE_USER_HOME
5 | zipStorePath = wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 | # Determine the Java command to use to start the JVM.
86 | if [ -n "$JAVA_HOME" ] ; then
87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
88 | # IBM's JDK on AIX uses strange locations for the executables
89 | JAVACMD="$JAVA_HOME/jre/sh/java"
90 | else
91 | JAVACMD="$JAVA_HOME/bin/java"
92 | fi
93 | if [ ! -x "$JAVACMD" ] ; then
94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
95 |
96 | Please set the JAVA_HOME variable in your environment to match the
97 | location of your Java installation."
98 | fi
99 | else
100 | JAVACMD="java"
101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
102 |
103 | Please set the JAVA_HOME variable in your environment to match the
104 | location of your Java installation."
105 | fi
106 |
107 | # Increase the maximum file descriptors if we can.
108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
109 | MAX_FD_LIMIT=`ulimit -H -n`
110 | if [ $? -eq 0 ] ; then
111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
112 | MAX_FD="$MAX_FD_LIMIT"
113 | fi
114 | ulimit -n $MAX_FD
115 | if [ $? -ne 0 ] ; then
116 | warn "Could not set maximum file descriptor limit: $MAX_FD"
117 | fi
118 | else
119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
120 | fi
121 | fi
122 |
123 | # For Darwin, add options to specify how the application appears in the dock
124 | if $darwin; then
125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126 | fi
127 |
128 | # For Cygwin, switch paths to Windows format before running java
129 | if $cygwin ; then
130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132 | JAVACMD=`cygpath --unix "$JAVACMD"`
133 |
134 | # We build the pattern for arguments to be converted via cygpath
135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
136 | SEP=""
137 | for dir in $ROOTDIRSRAW ; do
138 | ROOTDIRS="$ROOTDIRS$SEP$dir"
139 | SEP="|"
140 | done
141 | OURCYGPATTERN="(^($ROOTDIRS))"
142 | # Add a user-defined pattern to the cygpath arguments
143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
145 | fi
146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
147 | i=0
148 | for arg in "$@" ; do
149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
151 |
152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
154 | else
155 | eval `echo args$i`="\"$arg\""
156 | fi
157 | i=$((i+1))
158 | done
159 | case $i in
160 | (0) set -- ;;
161 | (1) set -- "$args0" ;;
162 | (2) set -- "$args0" "$args1" ;;
163 | (3) set -- "$args0" "$args1" "$args2" ;;
164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
170 | esac
171 | fi
172 |
173 | # Escape application args
174 | save () {
175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176 | echo " "
177 | }
178 | APP_ARGS=$(save "$@")
179 |
180 | # Collect all arguments for the java command, following the shell quoting and substitution rules
181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
182 |
183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
185 | cd "$(dirname "$0")"
186 | fi
187 |
188 | exec "$JAVACMD" "$@"
189 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem http://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
34 |
35 | @rem Find java.exe
36 | if defined JAVA_HOME goto findJavaFromJavaHome
37 |
38 | set JAVA_EXE=java.exe
39 | %JAVA_EXE% -version >NUL 2>&1
40 | if "%ERRORLEVEL%" == "0" goto init
41 |
42 | echo.
43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
44 | echo.
45 | echo Please set the JAVA_HOME variable in your environment to match the
46 | echo location of your Java installation.
47 |
48 | goto fail
49 |
50 | :findJavaFromJavaHome
51 | set JAVA_HOME=%JAVA_HOME:"=%
52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
53 |
54 | if exist "%JAVA_EXE%" goto init
55 |
56 | echo.
57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
58 | echo.
59 | echo Please set the JAVA_HOME variable in your environment to match the
60 | echo location of your Java installation.
61 |
62 | goto fail
63 |
64 | :init
65 | @rem Get command-line arguments, handling Windows variants
66 |
67 | if not "%OS%" == "Windows_NT" goto win9xME_args
68 |
69 | :win9xME_args
70 | @rem Slurp the command line arguments.
71 | set CMD_LINE_ARGS=
72 | set _SKIP=2
73 |
74 | :win9xME_args_slurp
75 | if "x%~1" == "x" goto execute
76 |
77 | set CMD_LINE_ARGS=%*
78 |
79 | :execute
80 | @rem Setup the command line
81 |
82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
83 |
84 | @rem Execute Gradle
85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
86 |
87 | :end
88 | @rem End local scope for the variables with windows NT shell
89 | if "%ERRORLEVEL%"=="0" goto mainEnd
90 |
91 | :fail
92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
93 | rem the _cmd.exe /c_ return code!
94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
95 | exit /b 1
96 |
97 | :mainEnd
98 | if "%OS%"=="Windows_NT" endlocal
99 |
100 | :omega
101 |
--------------------------------------------------------------------------------
/pageindicator/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/pageindicator/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'com.github.dcendents.android-maven'
5 |
6 | android {
7 | compileSdkVersion rootProject.compileSdkVersion
8 |
9 | defaultConfig {
10 | minSdkVersion rootProject.minSdkVersion
11 | targetSdkVersion rootProject.targetSdkVersion
12 |
13 | versionCode 1
14 | versionName '1.0'
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | testOptions.unitTests.all {
20 | testLogging {
21 | events "passed", "skipped", "failed", "standardOut", "standardError"
22 | outputs.upToDateWhen { false }
23 | showStandardStreams = true
24 | }
25 | }
26 | }
27 |
28 | dependencies {
29 | compileOnly rootProject.kotlinStdlib
30 | compileOnly rootProject.recyclerviewV7
31 | testImplementation rootProject.junit
32 | testImplementation rootProject.kotlinStdlib
33 | }
34 |
--------------------------------------------------------------------------------
/pageindicator/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/pageindicator/src/main/java/com/chahinem/pageindicator/DotManager.kt:
--------------------------------------------------------------------------------
1 | package com.chahinem.pageindicator
2 |
3 | internal class DotManager(
4 | count: Int,
5 | private val dotSize: Int,
6 | private val dotSpacing: Int,
7 | private val dotBound: Int,
8 | private val dotSizes: Map,
9 | private val targetScrollListener: TargetScrollListener? = null
10 | ) {
11 |
12 | internal var dots: ByteArray = ByteArray(count)
13 | internal var selectedIndex = 0
14 |
15 | private var scrollAmount = 0
16 |
17 | init {
18 |
19 | if (count > 0) {
20 | dots[0] = 6
21 | }
22 |
23 | if (count <= SIZE_THRESHOLD) {
24 | (1 until count).forEach { i -> dots[i] = 5 }
25 | } else {
26 | (1..3).forEach { i -> dots[i] = 5 }
27 | dots[4] = 4
28 | if (count > SIZE_THRESHOLD) {
29 | dots[5] = 2
30 | }
31 | (SIZE_THRESHOLD + 1 until count).forEach { i -> dots[i] = 0 }
32 | }
33 | }
34 |
35 | internal fun dots() = dots.joinToString("")
36 |
37 | fun dotSizeFor(size: Byte) = dotSizes[size] ?: 0
38 |
39 | fun goToNext() {
40 | if (selectedIndex >= dots.size - 1) {
41 | return
42 | }
43 |
44 | ++selectedIndex
45 |
46 | if (dots.size <= SIZE_THRESHOLD) {
47 | goToNextSmall()
48 | } else {
49 | goToNextLarge()
50 | }
51 | }
52 |
53 | fun goToPrevious() {
54 | if (selectedIndex == 0) {
55 | return
56 | }
57 |
58 | --selectedIndex
59 |
60 | if (dots.size <= SIZE_THRESHOLD) {
61 | goToPreviousSmall()
62 | } else {
63 | goToPreviousLarge()
64 | }
65 | }
66 |
67 | private fun goToNextSmall() {
68 | dots[selectedIndex] = 6
69 | dots[selectedIndex - 1] = 5
70 | }
71 |
72 | private fun goToNextLarge() {
73 | // swap 6 and 5
74 | dots[selectedIndex] = 6
75 | dots[selectedIndex - 1] = 5
76 |
77 | // no more than 3 5's in a row backward
78 | if (selectedIndex > 3
79 | && dots[selectedIndex - 1] == 5.toByte()
80 | && dots[selectedIndex - 2] == 5.toByte()
81 | && dots[selectedIndex - 3] == 5.toByte()
82 | && dots[selectedIndex - 4] == 5.toByte()) {
83 | dots[selectedIndex - 4] = 4
84 | if (selectedIndex - 5 >= 0) {
85 | dots[selectedIndex - 5] = 2
86 | (selectedIndex - 6 downTo 0)
87 | .takeWhile { dots[it] != 0.toByte() }
88 | .forEach { dots[it] = 0 }
89 | }
90 | }
91 |
92 | // 6 must be around 3 or higher
93 | if (selectedIndex + 1 < dots.size && dots[selectedIndex + 1] < 3) {
94 | dots[selectedIndex + 1] = 3
95 | // set the next one to 1 if any
96 | if (selectedIndex + 2 < dots.size && dots[selectedIndex + 2] < 1) {
97 | dots[selectedIndex + 2] = 1
98 | }
99 | }
100 |
101 | // Scroll to keep the selected dot within bound
102 | val endBound = selectedIndex * (dotSize + dotSpacing) + dotSize
103 | if (endBound > dotBound) {
104 | scrollAmount = endBound - dotBound
105 | targetScrollListener?.scrollToTarget(scrollAmount)
106 | }
107 | }
108 |
109 | private fun goToPreviousSmall() {
110 | dots[selectedIndex] = 6
111 | dots[selectedIndex + 1] = 5
112 | }
113 |
114 | private fun goToPreviousLarge() {
115 | // swap 6 and 5
116 | dots[selectedIndex] = 6
117 | dots[selectedIndex + 1] = 5
118 |
119 | // no more than 3 5's in a row backward
120 | if (selectedIndex < dots.size - 4
121 | && dots[selectedIndex + 1] == 5.toByte()
122 | && dots[selectedIndex + 2] == 5.toByte()
123 | && dots[selectedIndex + 3] == 5.toByte()
124 | && dots[selectedIndex + 4] == 5.toByte()) {
125 | dots[selectedIndex + 4] = 4
126 | if (selectedIndex + 5 < dots.size) {
127 | dots[selectedIndex + 5] = 2
128 | (selectedIndex + 6 until dots.size)
129 | .takeWhile { dots[it] != 0.toByte() }
130 | .forEach { i -> dots[i] = 0 }
131 | }
132 | }
133 |
134 | // 6 must be around 3 or higher
135 | if (selectedIndex - 1 >= 0 && dots[selectedIndex - 1] < 3) {
136 | dots[selectedIndex - 1] = 3
137 | // set the next one to 1 if any
138 | if (selectedIndex - 2 >= 0 && dots[selectedIndex - 2] < 1) {
139 | dots[selectedIndex - 2] = 1
140 | }
141 | }
142 |
143 | // Scroll to keep the selected dot within bound
144 | val startBound = selectedIndex * (dotSize + dotSpacing)
145 | if (startBound < scrollAmount) {
146 | scrollAmount = selectedIndex * (dotSize + dotSpacing)
147 | targetScrollListener?.scrollToTarget(scrollAmount)
148 | }
149 | }
150 |
151 | interface TargetScrollListener {
152 | fun scrollToTarget(target: Int)
153 | }
154 |
155 | companion object {
156 | private const val SIZE_THRESHOLD = 5
157 | }
158 | }
--------------------------------------------------------------------------------
/pageindicator/src/main/java/com/chahinem/pageindicator/Dps.kt:
--------------------------------------------------------------------------------
1 | package com.chahinem.pageindicator
2 |
3 | import android.content.res.Resources
4 |
5 | inline val Int.dp: Int
6 | get() = (this * Resources.getSystem().displayMetrics.density).toInt()
7 |
8 | inline val Float.dp: Int
9 | get() = (this * Resources.getSystem().displayMetrics.density).toInt()
--------------------------------------------------------------------------------
/pageindicator/src/main/java/com/chahinem/pageindicator/PageChangeListener.kt:
--------------------------------------------------------------------------------
1 | package com.chahinem.pageindicator
2 |
3 | import androidx.viewpager.widget.ViewPager
4 |
5 | internal class PageChangeListener(private val indicator: PageIndicator) : ViewPager.OnPageChangeListener {
6 | private var selectedPage = 0
7 |
8 | override fun onPageScrollStateChanged(state: Int) {}
9 |
10 | override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
11 |
12 | override fun onPageSelected(position: Int) {
13 | if (position != selectedPage) {
14 | when {
15 | this.selectedPage < position -> indicator.swipeNext()
16 | else -> indicator.swipePrevious()
17 | }
18 | }
19 | selectedPage = position
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/pageindicator/src/main/java/com/chahinem/pageindicator/PageIndicator.kt:
--------------------------------------------------------------------------------
1 | package com.chahinem.pageindicator
2 |
3 | import android.animation.ValueAnimator
4 | import android.content.Context
5 | import android.graphics.Canvas
6 | import android.graphics.Paint
7 | import android.os.Parcelable
8 | import android.util.AttributeSet
9 | import android.view.View
10 | import android.view.animation.AnimationUtils
11 | import android.view.animation.DecelerateInterpolator
12 | import android.view.animation.Interpolator
13 | import androidx.core.content.ContextCompat
14 | import androidx.recyclerview.widget.RecyclerView
15 | import androidx.viewpager.widget.PagerAdapter
16 | import androidx.viewpager.widget.ViewPager
17 | import com.chahinem.pageindicator.DotManager.TargetScrollListener
18 | import kotlin.math.max
19 | import kotlin.math.min
20 |
21 | open class PageIndicator @JvmOverloads constructor(
22 | context: Context,
23 | attrs: AttributeSet? = null,
24 | defStyleAttr: Int = 0
25 | ) : View(context, attrs, defStyleAttr), TargetScrollListener {
26 |
27 | private lateinit var dotSizes: IntArray
28 | private lateinit var dotAnimators: Array
29 |
30 | private val defaultPaint = Paint().apply { isAntiAlias = true }
31 | private val selectedPaint = Paint().apply { isAntiAlias = true }
32 |
33 | private val dotSize: Int
34 | private val dotSizeMap: Map
35 | private val dotBound: Int
36 | private val dotSpacing: Int
37 | private val animDuration: Long
38 | private val animInterpolator: Interpolator
39 | private var centered: Boolean = true
40 | private val customInitalPadding: Int
41 |
42 | private var dotManager: DotManager? = null
43 | private var scrollAmount: Int = 0
44 | private var scrollAnimator: ValueAnimator? = null
45 | private var initialPadding: Int = 0
46 |
47 | private lateinit var scrollListener: RecyclerView.OnScrollListener
48 | private lateinit var pageChangeListener: ViewPager.OnPageChangeListener
49 |
50 | var count: Int = 0
51 | set(value) {
52 | dotManager = DotManager(
53 | value,
54 | dotSize,
55 | dotSpacing,
56 | dotBound,
57 | dotSizeMap,
58 | this)
59 |
60 | dotSizes = IntArray(value)
61 | dotManager?.let { it.dots.forEachIndexed { index, dot -> dotSizes[index] = it.dotSizeFor(dot) } }
62 | dotAnimators = Array(value) { ValueAnimator() }
63 |
64 | initialPadding = when {
65 | !centered -> 0
66 | customInitalPadding != -1 -> customInitalPadding
67 | else -> when (value) {
68 | in 0..4 -> (dotBound + (4 - value) * (dotSize + dotSpacing) + dotSpacing) / 2
69 | else -> 2 * (dotSize + dotSpacing)
70 | }
71 | }
72 |
73 | field = value
74 | invalidate()
75 | }
76 |
77 | init {
78 | val ta = getContext().obtainStyledAttributes(attrs, R.styleable.PageIndicator)
79 | dotSizeMap = mapOf(
80 | BYTE_6 to ta.getDimensionPixelSize(R.styleable.PageIndicator_piSize1, 6.dp),
81 | BYTE_5 to ta.getDimensionPixelSize(R.styleable.PageIndicator_piSize2, 5f.dp),
82 | BYTE_4 to ta.getDimensionPixelSize(R.styleable.PageIndicator_piSize3, 4.5f.dp),
83 | BYTE_3 to ta.getDimensionPixelSize(R.styleable.PageIndicator_piSize4, 3f.dp),
84 | BYTE_2 to ta.getDimensionPixelSize(R.styleable.PageIndicator_piSize5, 2.5f.dp),
85 | BYTE_1 to ta.getDimensionPixelSize(R.styleable.PageIndicator_piSize6, .5f.dp)
86 | )
87 | dotSize = dotSizeMap.values.max() ?: 0
88 | dotSpacing = ta.getDimensionPixelSize(R.styleable.PageIndicator_piDotSpacing, 3.dp)
89 | centered = ta.getBoolean(R.styleable.PageIndicator_piCentered, true)
90 | dotBound = ta.getDimensionPixelSize(R.styleable.PageIndicator_piDotBound, 40.dp)
91 | customInitalPadding = ta.getDimensionPixelSize(R.styleable.PageIndicator_piInitialPadding, -1)
92 |
93 | animDuration = ta.getInteger(
94 | R.styleable.PageIndicator_piAnimDuration, DEFAULT_ANIM_DURATION).toLong()
95 | defaultPaint.color = ta.getColor(
96 | R.styleable.PageIndicator_piDefaultColor,
97 | ContextCompat.getColor(getContext(), R.color.pi_default_color))
98 | selectedPaint.color = ta.getColor(
99 | R.styleable.PageIndicator_piSelectedColor,
100 | ContextCompat.getColor(getContext(), R.color.pi_selected_color))
101 | animInterpolator = AnimationUtils.loadInterpolator(context, ta.getResourceId(
102 | R.styleable.PageIndicator_piAnimInterpolator,
103 | R.anim.pi_default_interpolator))
104 | ta.recycle()
105 | }
106 |
107 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
108 | super.onMeasure(widthMeasureSpec, heightMeasureSpec)
109 | // FIXME: add support for `match_parent`
110 | setMeasuredDimension(4 * (dotSize + dotSpacing) + dotBound + initialPadding, dotSize)
111 | }
112 |
113 | override fun onDraw(canvas: Canvas?) {
114 | super.onDraw(canvas)
115 |
116 | var paddingStart = initialPadding
117 | val (start, end) = getDrawingRange()
118 |
119 | paddingStart += (dotSize + dotSpacing) * start
120 | (start until end).forEach {
121 | canvas?.drawCircle(
122 | paddingStart + dotSize / 2f - scrollAmount,
123 | dotSize / 2f,
124 | dotSizes[it] / 2f,
125 | when (dotManager?.dots?.get(it)) {
126 | BYTE_6 -> selectedPaint
127 | else -> defaultPaint
128 | })
129 | paddingStart += dotSize + dotSpacing
130 | }
131 | }
132 |
133 | override fun onSaveInstanceState(): Parcelable? {
134 | val superState = super.onSaveInstanceState()
135 | if (superState == null) {
136 | return superState
137 | }
138 |
139 | val savedState = SavedState(superState)
140 | savedState.count = this.count
141 | savedState.selectedIndex = this.dotManager?.selectedIndex ?: 0
142 | return savedState
143 | }
144 |
145 | override fun onRestoreInstanceState(state: Parcelable?) {
146 | if (state !is SavedState) {
147 | super.onRestoreInstanceState(state)
148 | return
149 | }
150 |
151 | super.onRestoreInstanceState(state.superState)
152 |
153 | this.count = state.count
154 | for (i in 0 until state.selectedIndex) {
155 | swipeNext()
156 | }
157 | }
158 |
159 | override fun scrollToTarget(target: Int) {
160 | scrollAnimator?.cancel()
161 | scrollAnimator = ValueAnimator.ofInt(scrollAmount, target).apply {
162 | duration = animDuration
163 | interpolator = DEFAULT_INTERPOLATOR
164 | addUpdateListener { animation ->
165 | scrollAmount = animation.animatedValue as Int
166 | invalidate()
167 | }
168 | start()
169 | }
170 | }
171 |
172 | infix fun attachTo(recyclerView: RecyclerView) {
173 | if (::scrollListener.isInitialized) {
174 | recyclerView.removeOnScrollListener(scrollListener)
175 | }
176 | count = recyclerView.adapter?.itemCount ?: 0
177 | scrollListener = ScrollListener(this)
178 | recyclerView.addOnScrollListener(scrollListener)
179 | scrollToTarget(0)
180 | }
181 |
182 | infix fun attachTo(viewPager: ViewPager) {
183 | if (::pageChangeListener.isInitialized) {
184 | viewPager.removeOnPageChangeListener(pageChangeListener)
185 | }
186 | count = (viewPager.adapter as PagerAdapter).count
187 | pageChangeListener = PageChangeListener(this)
188 | viewPager.addOnPageChangeListener(pageChangeListener)
189 | scrollToTarget(0)
190 | }
191 |
192 | fun swipePrevious() {
193 | dotManager?.goToPrevious()
194 | animateDots()
195 | }
196 |
197 | fun swipeNext() {
198 | dotManager?.goToNext()
199 | animateDots()
200 | }
201 |
202 | private fun animateDots() {
203 | dotManager?.let {
204 | val (start, end) = getDrawingRange()
205 | (start until end).forEach { index ->
206 | dotAnimators[index].cancel()
207 | dotAnimators[index] = ValueAnimator.ofInt(dotSizes[index], it.dotSizeFor(it.dots[index]))
208 | .apply {
209 | duration = animDuration
210 | interpolator = DEFAULT_INTERPOLATOR
211 | addUpdateListener { animation ->
212 | dotSizes[index] = animation.animatedValue as Int
213 | invalidate()
214 | }
215 | }
216 | dotAnimators[index].start()
217 | }
218 | }
219 | }
220 |
221 | private fun getDrawingRange(): Pair {
222 | val start = max(0, (dotManager?.selectedIndex ?: 0) - MOST_VISIBLE_COUNT)
223 | val end = min(dotManager?.dots?.size ?: 0,
224 | (dotManager?.selectedIndex ?: 0) + MOST_VISIBLE_COUNT)
225 | return Pair(start, end)
226 | }
227 |
228 | companion object {
229 | private const val BYTE_6 = 6.toByte()
230 | private const val BYTE_5 = 5.toByte()
231 | private const val BYTE_4 = 4.toByte()
232 | private const val BYTE_3 = 3.toByte()
233 | private const val BYTE_2 = 2.toByte()
234 | private const val BYTE_1 = 1.toByte()
235 |
236 | private const val MOST_VISIBLE_COUNT = 10
237 | private const val DEFAULT_ANIM_DURATION = 200
238 |
239 | private val DEFAULT_INTERPOLATOR = DecelerateInterpolator()
240 | }
241 | }
--------------------------------------------------------------------------------
/pageindicator/src/main/java/com/chahinem/pageindicator/SavedState.kt:
--------------------------------------------------------------------------------
1 | package com.chahinem.pageindicator
2 |
3 | import android.os.Parcel
4 | import android.os.Parcelable
5 | import android.view.View.BaseSavedState
6 | import org.jetbrains.annotations.NotNull
7 |
8 | internal class SavedState : BaseSavedState {
9 | var count: Int = 0
10 | var selectedIndex = 0
11 |
12 | constructor(superState: Parcelable) : super(superState)
13 |
14 | private constructor(`in`: Parcel) : super(`in`) {
15 | this.count = `in`.readInt()
16 | this.selectedIndex = `in`.readInt()
17 | }
18 |
19 | override fun writeToParcel(out: Parcel, flags: Int) {
20 | super.writeToParcel(out, flags)
21 | out.writeInt(this.count)
22 | out.writeInt(this.selectedIndex)
23 | }
24 |
25 | companion object {
26 | @JvmField
27 | @NotNull
28 | val CREATOR: Parcelable.Creator = object : Parcelable.Creator {
29 | override fun createFromParcel(`in`: Parcel): SavedState {
30 | return SavedState(`in`)
31 | }
32 |
33 | override fun newArray(size: Int): Array {
34 | return arrayOfNulls(size)
35 | }
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/pageindicator/src/main/java/com/chahinem/pageindicator/ScrollListener.kt:
--------------------------------------------------------------------------------
1 | package com.chahinem.pageindicator
2 |
3 | import androidx.recyclerview.widget.RecyclerView
4 |
5 | internal class ScrollListener(private val indicator: PageIndicator) : RecyclerView.OnScrollListener() {
6 | private var midPos = 0
7 | private var scrollX = 0
8 |
9 | override fun onScrolled(recyclerView: RecyclerView,
10 | dx: Int,
11 | dy: Int) {
12 | super.onScrolled(recyclerView, dx, dy)
13 | scrollX += dx
14 | recyclerView.getChildAt(0)?.width?.let {
15 | val midPos = Math.floor(((scrollX + it / 2f) / it).toDouble()).toInt()
16 | if (this.midPos != midPos) {
17 | when {
18 | this.midPos < midPos -> indicator.swipeNext()
19 | else -> indicator.swipePrevious()
20 | }
21 | }
22 | this.midPos = midPos
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/pageindicator/src/main/res/anim/pi_default_interpolator.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/pageindicator/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/pageindicator/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3897F0
4 | #B2B2B2
5 |
--------------------------------------------------------------------------------
/pageindicator/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/pageindicator/src/test/java/com/chahinem/pageindicator/DotManagerTest.kt:
--------------------------------------------------------------------------------
1 | package com.chahinem.pageindicator
2 |
3 | import org.junit.Assert.assertEquals
4 | import org.junit.Test
5 |
6 | class DotManagerTest {
7 | companion object {
8 | private val dotSizes = mapOf(
9 | 6.toByte() to 12,
10 | 5.toByte() to 10,
11 | 4.toByte() to 9,
12 | 3.toByte() to 6,
13 | 2.toByte() to 5,
14 | 1.toByte() to 1
15 | )
16 | }
17 |
18 | @Test fun init_isCorrect() {
19 | assertEquals("6", DotManager(1, 0, 0, 0, dotSizes).dots())
20 | assertEquals("65", DotManager(2, 0, 0, 0, dotSizes).dots())
21 | assertEquals("655", DotManager(3, 0, 0, 0, dotSizes).dots())
22 | assertEquals("6555", DotManager(4, 0, 0, 0, dotSizes).dots())
23 | assertEquals("65555", DotManager(5, 0, 0, 0, dotSizes).dots())
24 | assertEquals("655542", DotManager(6, 0, 0, 0, dotSizes).dots())
25 | assertEquals("6555420", DotManager(7, 0, 0, 0, dotSizes).dots())
26 | assertEquals("65554200", DotManager(8, 0, 0, 0, dotSizes).dots())
27 | }
28 |
29 | @Test fun goToNext_small() {
30 | val dotManager = DotManager(5, 0, 0, 0, dotSizes)
31 | assertEquals("65555", dotManager.dots())
32 | dotManager.goToNext()
33 | assertEquals("56555", dotManager.dots())
34 | dotManager.goToNext()
35 | assertEquals("55655", dotManager.dots())
36 | dotManager.goToNext()
37 | assertEquals("55565", dotManager.dots())
38 | dotManager.goToNext()
39 | assertEquals("55556", dotManager.dots())
40 | }
41 |
42 | @Test fun goToNext_large6() {
43 | val dotManager = DotManager(6, 0, 0, 0, dotSizes)
44 | assertEquals("655542", dotManager.dots())
45 | dotManager.goToNext()
46 | assertEquals("565542", dotManager.dots())
47 | dotManager.goToNext()
48 | assertEquals("556542", dotManager.dots())
49 | dotManager.goToNext()
50 | assertEquals("555642", dotManager.dots())
51 | dotManager.goToNext()
52 | assertEquals("455563", dotManager.dots())
53 | dotManager.goToNext()
54 | assertEquals("245556", dotManager.dots())
55 | }
56 |
57 | @Test fun goToNext_large8() {
58 | val dotManager = DotManager(8, 0, 0, 0, dotSizes)
59 | assertEquals("65554200", dotManager.dots())
60 | dotManager.goToNext()
61 | assertEquals("56554200", dotManager.dots())
62 | dotManager.goToNext()
63 | assertEquals("55654200", dotManager.dots())
64 | dotManager.goToNext()
65 | assertEquals("55564200", dotManager.dots())
66 | dotManager.goToNext()
67 | assertEquals("45556310", dotManager.dots())
68 | dotManager.goToNext()
69 | assertEquals("24555631", dotManager.dots())
70 | dotManager.goToNext()
71 | assertEquals("02455563", dotManager.dots())
72 | dotManager.goToNext()
73 | assertEquals("00245556", dotManager.dots())
74 | }
75 |
76 | @Test fun goToPrevious_small() {
77 | val dotManager = DotManager(5, 0, 0, 0, dotSizes)
78 | assertEquals("65555", dotManager.dots())
79 | dotManager.goToNext()
80 | dotManager.goToNext()
81 | dotManager.goToNext()
82 | dotManager.goToNext()
83 | assertEquals("55556", dotManager.dots())
84 | dotManager.goToPrevious()
85 | assertEquals("55565", dotManager.dots())
86 | dotManager.goToPrevious()
87 | assertEquals("55655", dotManager.dots())
88 | dotManager.goToPrevious()
89 | assertEquals("56555", dotManager.dots())
90 | dotManager.goToPrevious()
91 | assertEquals("65555", dotManager.dots())
92 | }
93 |
94 | @Test fun goToPrevious_large6() {
95 | val dotManager = DotManager(6, 0, 0, 0, dotSizes)
96 | dotManager.goToNext()
97 | dotManager.goToNext()
98 | dotManager.goToNext()
99 | dotManager.goToNext()
100 | dotManager.goToNext()
101 | assertEquals("245556", dotManager.dots())
102 | dotManager.goToPrevious()
103 | assertEquals("245565", dotManager.dots())
104 | dotManager.goToPrevious()
105 | assertEquals("245655", dotManager.dots())
106 | dotManager.goToPrevious()
107 | assertEquals("246555", dotManager.dots())
108 | dotManager.goToPrevious()
109 | assertEquals("365554", dotManager.dots()) // double check
110 | dotManager.goToPrevious()
111 | assertEquals("655542", dotManager.dots())
112 | }
113 |
114 | @Test fun goToPrevious_large8() {
115 | val dotManager = DotManager(8, 0, 0, 0, dotSizes)
116 | assertEquals("65554200", dotManager.dots())
117 | dotManager.goToNext()
118 | dotManager.goToNext()
119 | dotManager.goToNext()
120 | dotManager.goToNext()
121 | dotManager.goToNext()
122 | dotManager.goToNext()
123 | dotManager.goToNext()
124 | assertEquals("00245556", dotManager.dots())
125 | dotManager.goToPrevious()
126 | assertEquals("00245565", dotManager.dots())
127 | dotManager.goToPrevious()
128 | assertEquals("00245655", dotManager.dots())
129 | dotManager.goToPrevious()
130 | assertEquals("00246555", dotManager.dots())
131 | dotManager.goToPrevious()
132 | assertEquals("01365554", dotManager.dots())
133 | dotManager.goToPrevious()
134 | assertEquals("13655542", dotManager.dots())
135 | dotManager.goToPrevious()
136 | assertEquals("36555420", dotManager.dots())
137 | dotManager.goToPrevious()
138 | assertEquals("65554200", dotManager.dots())
139 | }
140 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | include ':pageindicator'
3 | project(':pageindicator').name = 'pageindicator'
4 |
--------------------------------------------------------------------------------