├── lib ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── vpi__colors.xml │ │ │ │ ├── vpi__styles.xml │ │ │ │ ├── vpi__defaults.xml │ │ │ │ └── vpi__attrs.xml │ │ │ ├── drawable-hdpi │ │ │ │ ├── vpi__tab_selected_holo.9.png │ │ │ │ ├── vpi__tab_unselected_holo.9.png │ │ │ │ ├── vpi__tab_selected_focused_holo.9.png │ │ │ │ ├── vpi__tab_selected_pressed_holo.9.png │ │ │ │ ├── vpi__tab_unselected_focused_holo.9.png │ │ │ │ └── vpi__tab_unselected_pressed_holo.9.png │ │ │ ├── drawable-mdpi │ │ │ │ ├── vpi__tab_selected_holo.9.png │ │ │ │ ├── vpi__tab_unselected_holo.9.png │ │ │ │ ├── vpi__tab_selected_focused_holo.9.png │ │ │ │ ├── vpi__tab_selected_pressed_holo.9.png │ │ │ │ ├── vpi__tab_unselected_focused_holo.9.png │ │ │ │ └── vpi__tab_unselected_pressed_holo.9.png │ │ │ ├── drawable-xhdpi │ │ │ │ ├── vpi__tab_selected_holo.9.png │ │ │ │ ├── vpi__tab_unselected_holo.9.png │ │ │ │ ├── vpi__tab_selected_focused_holo.9.png │ │ │ │ ├── vpi__tab_selected_pressed_holo.9.png │ │ │ │ ├── vpi__tab_unselected_focused_holo.9.png │ │ │ │ └── vpi__tab_unselected_pressed_holo.9.png │ │ │ ├── color │ │ │ │ ├── vpi__dark_theme.xml │ │ │ │ └── vpi__light_theme.xml │ │ │ └── drawable │ │ │ │ └── vpi__tab_indicator.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── viewpagerindicator │ │ │ │ ├── IconPagerAdapter.java │ │ │ │ ├── PageIndicator.java │ │ │ │ ├── IconPageIndicator.java │ │ │ │ ├── IcsLinearLayout.java │ │ │ │ ├── TabPageIndicator.java │ │ │ │ ├── UnderlinePageIndicator.java │ │ │ │ └── LinePageIndicator.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── viewpagerindicator │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── viewpagerindicator │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── sample ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.xml │ │ │ ├── drawable-hdpi │ │ │ │ ├── icon.png │ │ │ │ ├── perm_group_camera_normal.png │ │ │ │ ├── perm_group_calendar_normal.png │ │ │ │ ├── perm_group_camera_selected.png │ │ │ │ ├── perm_group_location_normal.png │ │ │ │ ├── custom_tab_indicator_divider.9.png │ │ │ │ ├── custom_tab_indicator_focused.9.png │ │ │ │ ├── perm_group_calendar_selected.png │ │ │ │ ├── perm_group_location_selected.png │ │ │ │ ├── custom_tab_indicator_selected.9.png │ │ │ │ ├── perm_group_device_alarms_normal.png │ │ │ │ ├── custom_tab_indicator_unselected.9.png │ │ │ │ ├── perm_group_device_alarms_selected.png │ │ │ │ ├── custom_tab_indicator_selected_pressed.9.png │ │ │ │ ├── custom_tab_indicator_unselected_focused.9.png │ │ │ │ └── custom_tab_indicator_unselected_pressed.9.png │ │ │ ├── drawable-mdpi │ │ │ │ ├── icon.png │ │ │ │ ├── perm_group_camera_normal.png │ │ │ │ ├── perm_group_calendar_normal.png │ │ │ │ ├── perm_group_camera_selected.png │ │ │ │ ├── perm_group_location_normal.png │ │ │ │ ├── custom_tab_indicator_divider.9.png │ │ │ │ ├── perm_group_calendar_selected.png │ │ │ │ ├── perm_group_location_selected.png │ │ │ │ ├── custom_tab_indicator_selected.9.png │ │ │ │ ├── perm_group_device_alarms_normal.png │ │ │ │ ├── custom_tab_indicator_unselected.9.png │ │ │ │ ├── perm_group_device_alarms_selected.png │ │ │ │ ├── custom_tab_indicator_selected_focused.9.png │ │ │ │ ├── custom_tab_indicator_selected_pressed.9.png │ │ │ │ ├── custom_tab_indicator_unselected_focused.9.png │ │ │ │ └── custom_tab_indicator_unselected_pressed.9.png │ │ │ ├── drawable-xhdpi │ │ │ │ ├── icon.png │ │ │ │ ├── perm_group_camera_normal.png │ │ │ │ ├── perm_group_calendar_normal.png │ │ │ │ ├── perm_group_camera_selected.png │ │ │ │ ├── perm_group_location_normal.png │ │ │ │ ├── perm_group_calendar_selected.png │ │ │ │ ├── perm_group_location_selected.png │ │ │ │ ├── custom_tab_indicator_divider.9.png │ │ │ │ ├── custom_tab_indicator_selected.9.png │ │ │ │ ├── perm_group_device_alarms_normal.png │ │ │ │ ├── custom_tab_indicator_unselected.9.png │ │ │ │ ├── perm_group_device_alarms_selected.png │ │ │ │ ├── custom_tab_indicator_selected_focused.9.png │ │ │ │ ├── custom_tab_indicator_selected_pressed.9.png │ │ │ │ ├── custom_tab_indicator_unselected_focused.9.png │ │ │ │ └── custom_tab_indicator_unselected_pressed.9.png │ │ │ ├── drawable │ │ │ │ ├── perm_group_camera.xml │ │ │ │ ├── perm_group_calendar.xml │ │ │ │ ├── perm_group_location.xml │ │ │ │ ├── perm_group_device_alarms.xml │ │ │ │ └── custom_tab_indicator.xml │ │ │ ├── menu │ │ │ │ └── menu.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ ├── activity_main.xml │ │ │ │ ├── simple_underlines.xml │ │ │ │ ├── simple_icons.xml │ │ │ │ ├── simple_tabs.xml │ │ │ │ ├── simple_lines.xml │ │ │ │ ├── simple_circles.xml │ │ │ │ ├── simple_titles.xml │ │ │ │ ├── simple_circles_vertical.xml │ │ │ │ ├── simple_titles_bottom.xml │ │ │ │ ├── themed_underlines.xml │ │ │ │ ├── themed_lines.xml │ │ │ │ ├── themed_circles.xml │ │ │ │ └── themed_titles.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── viewpagerindicator │ │ │ │ └── sample │ │ │ │ ├── SampleLinesDefault.java │ │ │ │ ├── SampleIconsDefault.java │ │ │ │ ├── SampleCirclesDefault.java │ │ │ │ ├── SampleLinesStyledLayout.java │ │ │ │ ├── SampleTitlesBottom.java │ │ │ │ ├── SampleTitlesDefault.java │ │ │ │ ├── SampleCirclesStyledLayout.java │ │ │ │ ├── SampleTitlesStyledLayout.java │ │ │ │ ├── SampleUnderlinesDefault.java │ │ │ │ ├── SampleUnderlinesStyledLayout.java │ │ │ │ ├── SampleLinesStyledTheme.java │ │ │ │ ├── SampleCirclesSnap.java │ │ │ │ ├── SampleCirclesStyledTheme.java │ │ │ │ ├── SampleTitlesStyledTheme.java │ │ │ │ ├── SampleUnderlinesStyledTheme.java │ │ │ │ ├── SampleUnderlinesNoFade.java │ │ │ │ ├── SampleCirclesInitialPage.java │ │ │ │ ├── SampleTitlesInitialPage.java │ │ │ │ ├── SampleTitlesTriangle.java │ │ │ │ ├── SampleUnderlinesStyledMethods.java │ │ │ │ ├── SampleLinesStyledMethods.java │ │ │ │ ├── SampleCirclesStyledMethods.java │ │ │ │ ├── SampleTitlesCenterClickListener.java │ │ │ │ ├── SampleTitlesStyledMethods.java │ │ │ │ ├── SampleCirclesWithListener.java │ │ │ │ ├── SampleTitlesWithListener.java │ │ │ │ ├── TestFragmentAdapter.java │ │ │ │ ├── SampleTabsDefault.java │ │ │ │ ├── SampleTabsStyled.java │ │ │ │ ├── BaseSampleActivity.java │ │ │ │ ├── SampleTabsWithIcons.java │ │ │ │ ├── TestFragment.java │ │ │ │ └── ListSamples.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── viewpagerindicator │ │ │ └── sample │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── viewpagerindicator │ │ └── sample │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── .idea ├── copyright │ └── profiles_settings.xml ├── vcs.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── compiler.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /lib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':lib' 2 | -------------------------------------------------------------------------------- /lib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | lib 3 | 4 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ViewPagerIndicator 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /lib/src/main/res/drawable-hdpi/vpi__tab_selected_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-hdpi/vpi__tab_selected_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-mdpi/vpi__tab_selected_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-mdpi/vpi__tab_selected_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-xhdpi/vpi__tab_selected_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-xhdpi/vpi__tab_selected_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-hdpi/vpi__tab_unselected_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-hdpi/vpi__tab_unselected_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-mdpi/vpi__tab_unselected_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-mdpi/vpi__tab_unselected_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-xhdpi/vpi__tab_unselected_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-xhdpi/vpi__tab_unselected_holo.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/perm_group_camera_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/perm_group_camera_normal.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/perm_group_camera_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/perm_group_camera_normal.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/perm_group_camera_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/perm_group_camera_normal.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/perm_group_calendar_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/perm_group_calendar_normal.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/perm_group_camera_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/perm_group_camera_selected.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/perm_group_location_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/perm_group_location_normal.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/perm_group_calendar_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/perm_group_calendar_normal.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/perm_group_camera_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/perm_group_camera_selected.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/perm_group_location_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/perm_group_location_normal.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/perm_group_calendar_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/perm_group_calendar_normal.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/perm_group_camera_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/perm_group_camera_selected.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/perm_group_location_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/perm_group_location_normal.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-hdpi/vpi__tab_selected_focused_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-hdpi/vpi__tab_selected_focused_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-hdpi/vpi__tab_selected_pressed_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-hdpi/vpi__tab_selected_pressed_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-mdpi/vpi__tab_selected_focused_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-mdpi/vpi__tab_selected_focused_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-mdpi/vpi__tab_selected_pressed_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-mdpi/vpi__tab_selected_pressed_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-xhdpi/vpi__tab_selected_focused_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-xhdpi/vpi__tab_selected_focused_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-xhdpi/vpi__tab_selected_pressed_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-xhdpi/vpi__tab_selected_pressed_holo.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/custom_tab_indicator_divider.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/custom_tab_indicator_divider.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/custom_tab_indicator_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/custom_tab_indicator_focused.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/perm_group_calendar_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/perm_group_calendar_selected.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/perm_group_location_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/perm_group_location_selected.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/custom_tab_indicator_divider.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/custom_tab_indicator_divider.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/perm_group_calendar_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/perm_group_calendar_selected.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/perm_group_location_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/perm_group_location_selected.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/perm_group_calendar_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/perm_group_calendar_selected.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/perm_group_location_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/perm_group_location_selected.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-hdpi/vpi__tab_unselected_focused_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-hdpi/vpi__tab_unselected_focused_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-hdpi/vpi__tab_unselected_pressed_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-hdpi/vpi__tab_unselected_pressed_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-mdpi/vpi__tab_unselected_focused_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-mdpi/vpi__tab_unselected_focused_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-mdpi/vpi__tab_unselected_pressed_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-mdpi/vpi__tab_unselected_pressed_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-xhdpi/vpi__tab_unselected_focused_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-xhdpi/vpi__tab_unselected_focused_holo.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-xhdpi/vpi__tab_unselected_pressed_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/lib/src/main/res/drawable-xhdpi/vpi__tab_unselected_pressed_holo.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/custom_tab_indicator_selected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/custom_tab_indicator_selected.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/perm_group_device_alarms_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/perm_group_device_alarms_normal.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/custom_tab_indicator_selected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/custom_tab_indicator_selected.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/perm_group_device_alarms_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/perm_group_device_alarms_normal.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/custom_tab_indicator_divider.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/custom_tab_indicator_divider.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/custom_tab_indicator_selected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/custom_tab_indicator_selected.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/perm_group_device_alarms_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/perm_group_device_alarms_normal.png -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/custom_tab_indicator_unselected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/custom_tab_indicator_unselected.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/perm_group_device_alarms_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/perm_group_device_alarms_selected.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/custom_tab_indicator_unselected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/custom_tab_indicator_unselected.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/perm_group_device_alarms_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/perm_group_device_alarms_selected.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/custom_tab_indicator_unselected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/custom_tab_indicator_unselected.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/perm_group_device_alarms_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/perm_group_device_alarms_selected.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/custom_tab_indicator_selected_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/custom_tab_indicator_selected_pressed.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/custom_tab_indicator_selected_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/custom_tab_indicator_selected_focused.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/custom_tab_indicator_selected_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/custom_tab_indicator_selected_pressed.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/custom_tab_indicator_selected_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/custom_tab_indicator_selected_focused.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/custom_tab_indicator_selected_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/custom_tab_indicator_selected_pressed.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/custom_tab_indicator_unselected_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/custom_tab_indicator_unselected_focused.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-hdpi/custom_tab_indicator_unselected_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-hdpi/custom_tab_indicator_unselected_pressed.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/custom_tab_indicator_unselected_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/custom_tab_indicator_unselected_focused.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-mdpi/custom_tab_indicator_unselected_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-mdpi/custom_tab_indicator_unselected_pressed.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/custom_tab_indicator_unselected_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/custom_tab_indicator_unselected_focused.9.png -------------------------------------------------------------------------------- /sample/src/main/res/drawable-xhdpi/custom_tab_indicator_unselected_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/uncleleonfan/ViewPagerIndicator/HEAD/sample/src/main/res/drawable-xhdpi/custom_tab_indicator_unselected_pressed.9.png -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /lib/src/main/java/com/viewpagerindicator/IconPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator; 2 | 3 | public interface IconPagerAdapter { 4 | /** 5 | * Get icon representing the page at {@code index} in the adapter. 6 | */ 7 | int getIconResId(int index); 8 | 9 | // From PagerAdapter 10 | int getCount(); 11 | } 12 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/perm_group_camera.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/perm_group_calendar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/perm_group_location.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/menu/menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/perm_group_device_alarms.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 原项目 # 2 | 本项目是JakeWharton大神作品ViewPagerIndicator的Android Studio版,方便开发者在Android Studio中使用。 3 | 原项目地址[https://github.com/JakeWharton/ViewPagerIndicator](https://github.com/JakeWharton/ViewPagerIndicator) 4 | 5 | # 使用方式 # 6 | allprojects { 7 | repositories { 8 | ... 9 | maven { url 'https://jitpack.io' } 10 | } 11 | } 12 | 13 | dependencies { 14 | compile 'com.github.uncleleonfan:ViewPagerIndicator:1.0.0' 15 | } -------------------------------------------------------------------------------- /lib/src/test/java/com/viewpagerindicator/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/test/java/com/viewpagerindicator/sample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /lib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\software\AndroidStudio\android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\software\AndroidStudio\android-sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleLinesDefault.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.LinePageIndicator; 6 | 7 | public class SampleLinesDefault extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.simple_lines); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | mIndicator = (LinePageIndicator)findViewById(R.id.indicator); 19 | mIndicator.setViewPager(mPager); 20 | } 21 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleIconsDefault.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.IconPageIndicator; 6 | 7 | public class SampleIconsDefault extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.simple_icons); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | mIndicator = (IconPageIndicator)findViewById(R.id.indicator); 19 | mIndicator.setViewPager(mPager); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleCirclesDefault.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.CirclePageIndicator; 6 | 7 | public class SampleCirclesDefault extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.simple_circles); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | mIndicator = (CirclePageIndicator)findViewById(R.id.indicator); 19 | mIndicator.setViewPager(mPager); 20 | } 21 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleLinesStyledLayout.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.LinePageIndicator; 6 | 7 | public class SampleLinesStyledLayout extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.themed_lines); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | mIndicator = (LinePageIndicator)findViewById(R.id.indicator); 19 | mIndicator.setViewPager(mPager); 20 | } 21 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleTitlesBottom.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.TitlePageIndicator; 6 | 7 | public class SampleTitlesBottom extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.simple_titles_bottom); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); 19 | mIndicator.setViewPager(mPager); 20 | } 21 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleTitlesDefault.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | 6 | import com.viewpagerindicator.TitlePageIndicator; 7 | 8 | public class SampleTitlesDefault extends BaseSampleActivity { 9 | @Override 10 | protected void onCreate(Bundle savedInstanceState) { 11 | super.onCreate(savedInstanceState); 12 | setContentView(R.layout.simple_titles); 13 | 14 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 15 | 16 | mPager = (ViewPager)findViewById(R.id.pager); 17 | mPager.setAdapter(mAdapter); 18 | 19 | mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); 20 | mIndicator.setViewPager(mPager); 21 | } 22 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleCirclesStyledLayout.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.CirclePageIndicator; 6 | 7 | public class SampleCirclesStyledLayout extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.themed_circles); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | mIndicator = (CirclePageIndicator)findViewById(R.id.indicator); 19 | mIndicator.setViewPager(mPager); 20 | } 21 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleTitlesStyledLayout.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | 6 | import com.viewpagerindicator.TitlePageIndicator; 7 | 8 | public class SampleTitlesStyledLayout extends BaseSampleActivity { 9 | @Override 10 | protected void onCreate(Bundle savedInstanceState) { 11 | super.onCreate(savedInstanceState); 12 | setContentView(R.layout.themed_titles); 13 | 14 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 15 | 16 | mPager = (ViewPager)findViewById(R.id.pager); 17 | mPager.setAdapter(mAdapter); 18 | 19 | mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); 20 | mIndicator.setViewPager(mPager); 21 | } 22 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleUnderlinesDefault.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.UnderlinePageIndicator; 6 | 7 | public class SampleUnderlinesDefault extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.simple_underlines); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | mIndicator = (UnderlinePageIndicator)findViewById(R.id.indicator); 19 | mIndicator.setViewPager(mPager); 20 | } 21 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleUnderlinesStyledLayout.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.UnderlinePageIndicator; 6 | 7 | public class SampleUnderlinesStyledLayout extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.themed_underlines); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | mIndicator = (UnderlinePageIndicator)findViewById(R.id.indicator); 19 | mIndicator.setViewPager(mPager); 20 | } 21 | } -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 18 | 19 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleLinesStyledTheme.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.LinePageIndicator; 6 | 7 | public class SampleLinesStyledTheme extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | 12 | //The look of this sample is set via a style in the manifest 13 | setContentView(R.layout.simple_lines); 14 | 15 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 16 | 17 | mPager = (ViewPager)findViewById(R.id.pager); 18 | mPager.setAdapter(mAdapter); 19 | 20 | mIndicator = (LinePageIndicator)findViewById(R.id.indicator); 21 | mIndicator.setViewPager(mPager); 22 | } 23 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleCirclesSnap.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.CirclePageIndicator; 6 | 7 | public class SampleCirclesSnap extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.simple_circles); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | CirclePageIndicator indicator = (CirclePageIndicator)findViewById(R.id.indicator); 19 | mIndicator = indicator; 20 | indicator.setViewPager(mPager); 21 | indicator.setSnap(true); 22 | } 23 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleCirclesStyledTheme.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.CirclePageIndicator; 6 | 7 | public class SampleCirclesStyledTheme extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | 12 | //The look of this sample is set via a style in the manifest 13 | setContentView(R.layout.simple_circles); 14 | 15 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 16 | 17 | mPager = (ViewPager)findViewById(R.id.pager); 18 | mPager.setAdapter(mAdapter); 19 | 20 | mIndicator = (CirclePageIndicator)findViewById(R.id.indicator); 21 | mIndicator.setViewPager(mPager); 22 | } 23 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleTitlesStyledTheme.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | 6 | import com.viewpagerindicator.TitlePageIndicator; 7 | 8 | public class SampleTitlesStyledTheme extends BaseSampleActivity { 9 | @Override 10 | protected void onCreate(Bundle savedInstanceState) { 11 | super.onCreate(savedInstanceState); 12 | 13 | //The look of this sample is set via a style in the manifest 14 | setContentView(R.layout.simple_titles); 15 | 16 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 17 | 18 | mPager = (ViewPager)findViewById(R.id.pager); 19 | mPager.setAdapter(mAdapter); 20 | 21 | mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); 22 | mIndicator.setViewPager(mPager); 23 | } 24 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleUnderlinesStyledTheme.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.UnderlinePageIndicator; 6 | 7 | public class SampleUnderlinesStyledTheme extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | 12 | //The look of this sample is set via a style in the manifest 13 | setContentView(R.layout.simple_underlines); 14 | 15 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 16 | 17 | mPager = (ViewPager)findViewById(R.id.pager); 18 | mPager.setAdapter(mAdapter); 19 | 20 | mIndicator = (UnderlinePageIndicator)findViewById(R.id.indicator); 21 | mIndicator.setViewPager(mPager); 22 | } 23 | } -------------------------------------------------------------------------------- /lib/src/androidTest/java/com/viewpagerindicator/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.viewpagerindicator.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleUnderlinesNoFade.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.UnderlinePageIndicator; 6 | 7 | public class SampleUnderlinesNoFade extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.simple_underlines); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | UnderlinePageIndicator indicator = (UnderlinePageIndicator)findViewById(R.id.indicator); 19 | indicator.setViewPager(mPager); 20 | indicator.setFades(false); 21 | mIndicator = indicator; 22 | } 23 | } -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/viewpagerindicator/sample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.viewpagerindicator.sample", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleCirclesInitialPage.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.CirclePageIndicator; 6 | 7 | public class SampleCirclesInitialPage extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.simple_circles); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | mIndicator = (CirclePageIndicator)findViewById(R.id.indicator); 19 | mIndicator.setViewPager(mPager); 20 | mIndicator.setCurrentItem(mAdapter.getCount() - 1); 21 | 22 | //You can also do: indicator.setViewPager(pager, initialPage); 23 | } 24 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleTitlesInitialPage.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | 6 | import com.viewpagerindicator.TitlePageIndicator; 7 | 8 | public class SampleTitlesInitialPage extends BaseSampleActivity { 9 | @Override 10 | protected void onCreate(Bundle savedInstanceState) { 11 | super.onCreate(savedInstanceState); 12 | setContentView(R.layout.simple_titles); 13 | 14 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 15 | 16 | mPager = (ViewPager)findViewById(R.id.pager); 17 | mPager.setAdapter(mAdapter); 18 | 19 | mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); 20 | mIndicator.setViewPager(mPager); 21 | mIndicator.setCurrentItem(mAdapter.getCount() - 1); 22 | 23 | //You can also do: indicator.setViewPager(pager, initialPage); 24 | } 25 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleTitlesTriangle.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | 6 | import com.viewpagerindicator.TitlePageIndicator; 7 | import com.viewpagerindicator.TitlePageIndicator.IndicatorStyle; 8 | 9 | public class SampleTitlesTriangle extends BaseSampleActivity { 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.simple_titles); 14 | 15 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 16 | 17 | mPager = (ViewPager)findViewById(R.id.pager); 18 | mPager.setAdapter(mAdapter); 19 | 20 | TitlePageIndicator indicator = (TitlePageIndicator)findViewById(R.id.indicator); 21 | indicator.setViewPager(mPager); 22 | indicator.setFooterIndicatorStyle(IndicatorStyle.Triangle); 23 | mIndicator = indicator; 24 | } 25 | } -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | defaultConfig { 7 | applicationId "com.viewpagerindicator.sample" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 65 11 | versionName "2.4.1" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.1.1' 28 | testCompile 'junit:junit:4.12' 29 | compile project(':lib') 30 | } 31 | -------------------------------------------------------------------------------- /lib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | group='com.github.uncleleonfan' 4 | 5 | android { 6 | compileSdkVersion 25 7 | buildToolsVersion "25.0.2" 8 | 9 | defaultConfig { 10 | minSdkVersion 15 11 | targetSdkVersion 25 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 16 | 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(dir: 'libs', include: ['*.jar']) 28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 29 | exclude group: 'com.android.support', module: 'support-annotations' 30 | }) 31 | compile 'com.android.support:appcompat-v7:25.1.1' 32 | testCompile 'junit:junit:4.12' 33 | } 34 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleUnderlinesStyledMethods.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.UnderlinePageIndicator; 6 | 7 | public class SampleUnderlinesStyledMethods extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.simple_underlines); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | UnderlinePageIndicator indicator = (UnderlinePageIndicator)findViewById(R.id.indicator); 19 | mIndicator = indicator; 20 | indicator.setViewPager(mPager); 21 | indicator.setSelectedColor(0xFFCC0000); 22 | indicator.setBackgroundColor(0xFFCCCCCC); 23 | indicator.setFadeDelay(1000); 24 | indicator.setFadeLength(1000); 25 | } 26 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleLinesStyledMethods.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.LinePageIndicator; 6 | 7 | public class SampleLinesStyledMethods extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.simple_lines); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | LinePageIndicator indicator = (LinePageIndicator)findViewById(R.id.indicator); 19 | mIndicator = indicator; 20 | indicator.setViewPager(mPager); 21 | 22 | final float density = getResources().getDisplayMetrics().density; 23 | indicator.setSelectedColor(0x88FF0000); 24 | indicator.setUnselectedColor(0xFF888888); 25 | indicator.setStrokeWidth(4 * density); 26 | indicator.setLineWidth(30 * density); 27 | } 28 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleCirclesStyledMethods.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import com.viewpagerindicator.CirclePageIndicator; 6 | 7 | public class SampleCirclesStyledMethods extends BaseSampleActivity { 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.simple_circles); 12 | 13 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 14 | 15 | mPager = (ViewPager)findViewById(R.id.pager); 16 | mPager.setAdapter(mAdapter); 17 | 18 | CirclePageIndicator indicator = (CirclePageIndicator)findViewById(R.id.indicator); 19 | mIndicator = indicator; 20 | indicator.setViewPager(mPager); 21 | 22 | final float density = getResources().getDisplayMetrics().density; 23 | indicator.setBackgroundColor(0xFFCCCCCC); 24 | indicator.setRadius(10 * density); 25 | indicator.setPageColor(0x880000FF); 26 | indicator.setFillColor(0xFF888888); 27 | indicator.setStrokeColor(0xFF000000); 28 | indicator.setStrokeWidth(2 * density); 29 | } 30 | } -------------------------------------------------------------------------------- /sample/src/main/res/layout/simple_underlines.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 29 | 34 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/simple_icons.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 29 | 34 | 35 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/simple_tabs.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleTitlesCenterClickListener.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import android.widget.Toast; 6 | 7 | import com.viewpagerindicator.TitlePageIndicator; 8 | import com.viewpagerindicator.TitlePageIndicator.IndicatorStyle; 9 | import com.viewpagerindicator.TitlePageIndicator.OnCenterItemClickListener; 10 | 11 | public class SampleTitlesCenterClickListener extends BaseSampleActivity implements OnCenterItemClickListener { 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.simple_titles); 16 | 17 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 18 | 19 | mPager = (ViewPager)findViewById(R.id.pager); 20 | mPager.setAdapter(mAdapter); 21 | 22 | TitlePageIndicator indicator = (TitlePageIndicator)findViewById(R.id.indicator); 23 | indicator.setViewPager(mPager); 24 | indicator.setFooterIndicatorStyle(IndicatorStyle.Underline); 25 | indicator.setOnCenterItemClickListener(this); 26 | mIndicator = indicator; 27 | } 28 | 29 | @Override 30 | public void onCenterItemClick(int position) { 31 | Toast.makeText(this, "You clicked the center title!", Toast.LENGTH_SHORT).show(); 32 | } 33 | } -------------------------------------------------------------------------------- /sample/src/main/res/layout/simple_lines.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 29 | 35 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/simple_circles.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 29 | 35 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/simple_titles.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 29 | 35 | 36 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/simple_circles_vertical.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 29 | 35 | -------------------------------------------------------------------------------- /lib/src/main/res/color/vpi__dark_theme.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /lib/src/main/res/values/vpi__colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | #ff000000 19 | #fff3f3f3 20 | @color/vpi__background_holo_light 21 | @color/vpi__background_holo_dark 22 | #ff4c4c4c 23 | #ffb2b2b2 24 | @color/vpi__bright_foreground_holo_light 25 | @color/vpi__bright_foreground_holo_dark 26 | 27 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleTitlesStyledMethods.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | 6 | import com.viewpagerindicator.TitlePageIndicator; 7 | import com.viewpagerindicator.TitlePageIndicator.IndicatorStyle; 8 | 9 | public class SampleTitlesStyledMethods extends BaseSampleActivity { 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.simple_titles); 14 | 15 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 16 | 17 | mPager = (ViewPager)findViewById(R.id.pager); 18 | mPager.setAdapter(mAdapter); 19 | 20 | TitlePageIndicator indicator = (TitlePageIndicator)findViewById(R.id.indicator); 21 | mIndicator = indicator; 22 | indicator.setViewPager(mPager); 23 | 24 | final float density = getResources().getDisplayMetrics().density; 25 | indicator.setBackgroundColor(0x18FF0000); 26 | indicator.setFooterColor(0xFFAA2222); 27 | indicator.setFooterLineHeight(1 * density); //1dp 28 | indicator.setFooterIndicatorHeight(3 * density); //3dp 29 | indicator.setFooterIndicatorStyle(IndicatorStyle.Underline); 30 | indicator.setTextColor(0xAA000000); 31 | indicator.setSelectedColor(0xFF000000); 32 | indicator.setSelectedBold(true); 33 | } 34 | } -------------------------------------------------------------------------------- /lib/src/main/res/color/vpi__light_theme.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleCirclesWithListener.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import android.widget.Toast; 6 | import com.viewpagerindicator.CirclePageIndicator; 7 | 8 | public class SampleCirclesWithListener extends BaseSampleActivity { 9 | @Override 10 | protected void onCreate(Bundle savedInstanceState) { 11 | super.onCreate(savedInstanceState); 12 | setContentView(R.layout.simple_circles); 13 | 14 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 15 | 16 | mPager = (ViewPager)findViewById(R.id.pager); 17 | mPager.setAdapter(mAdapter); 18 | 19 | mIndicator = (CirclePageIndicator)findViewById(R.id.indicator); 20 | mIndicator.setViewPager(mPager); 21 | 22 | //We set this on the indicator, NOT the pager 23 | mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { 24 | @Override 25 | public void onPageSelected(int position) { 26 | Toast.makeText(SampleCirclesWithListener.this, "Changed to page " + position, Toast.LENGTH_SHORT).show(); 27 | } 28 | 29 | @Override 30 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 31 | } 32 | 33 | @Override 34 | public void onPageScrollStateChanged(int state) { 35 | } 36 | }); 37 | } 38 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleTitlesWithListener.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.view.ViewPager; 5 | import android.widget.Toast; 6 | 7 | import com.viewpagerindicator.TitlePageIndicator; 8 | 9 | public class SampleTitlesWithListener extends BaseSampleActivity { 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.simple_titles); 14 | 15 | mAdapter = new TestFragmentAdapter(getSupportFragmentManager()); 16 | 17 | mPager = (ViewPager)findViewById(R.id.pager); 18 | mPager.setAdapter(mAdapter); 19 | 20 | mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); 21 | mIndicator.setViewPager(mPager); 22 | 23 | //We set this on the indicator, NOT the pager 24 | mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { 25 | @Override 26 | public void onPageSelected(int position) { 27 | Toast.makeText(SampleTitlesWithListener.this, "Changed to page " + position, Toast.LENGTH_SHORT).show(); 28 | } 29 | 30 | @Override 31 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 32 | } 33 | 34 | @Override 35 | public void onPageScrollStateChanged(int state) { 36 | } 37 | }); 38 | } 39 | } -------------------------------------------------------------------------------- /sample/src/main/res/layout/simple_titles_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 23 | 24 | 30 | 37 | 38 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/themed_underlines.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 23 | 24 | 30 | 39 | 40 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/TestFragmentAdapter.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentPagerAdapter; 6 | import com.viewpagerindicator.IconPagerAdapter; 7 | 8 | class TestFragmentAdapter extends FragmentPagerAdapter implements IconPagerAdapter { 9 | protected static final String[] CONTENT = new String[] { "This", "Is", "A", "Test", }; 10 | protected static final int[] ICONS = new int[] { 11 | R.drawable.perm_group_calendar, 12 | R.drawable.perm_group_camera, 13 | R.drawable.perm_group_device_alarms, 14 | R.drawable.perm_group_location 15 | }; 16 | 17 | private int mCount = CONTENT.length; 18 | 19 | public TestFragmentAdapter(FragmentManager fm) { 20 | super(fm); 21 | } 22 | 23 | @Override 24 | public Fragment getItem(int position) { 25 | return TestFragment.newInstance(CONTENT[position % CONTENT.length]); 26 | } 27 | 28 | @Override 29 | public int getCount() { 30 | return mCount; 31 | } 32 | 33 | @Override 34 | public CharSequence getPageTitle(int position) { 35 | return TestFragmentAdapter.CONTENT[position % CONTENT.length]; 36 | } 37 | 38 | @Override 39 | public int getIconResId(int index) { 40 | return ICONS[index % ICONS.length]; 41 | } 42 | 43 | public void setCount(int count) { 44 | if (count > 0 && count <= 10) { 45 | mCount = count; 46 | notifyDataSetChanged(); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /sample/src/main/res/layout/themed_lines.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 23 | 24 | 30 | 40 | 41 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/themed_circles.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 23 | 24 | 30 | 42 | 43 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleTabsDefault.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentActivity; 6 | import android.support.v4.app.FragmentManager; 7 | import android.support.v4.app.FragmentPagerAdapter; 8 | import android.support.v4.view.ViewPager; 9 | import com.viewpagerindicator.TabPageIndicator; 10 | 11 | public class SampleTabsDefault extends FragmentActivity { 12 | private static final String[] CONTENT = new String[] { "Recent", "Artists", "Albums", "Songs", "Playlists", "Genres" }; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.simple_tabs); 18 | 19 | FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager()); 20 | 21 | ViewPager pager = (ViewPager)findViewById(R.id.pager); 22 | pager.setAdapter(adapter); 23 | 24 | TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator); 25 | indicator.setViewPager(pager); 26 | } 27 | 28 | class GoogleMusicAdapter extends FragmentPagerAdapter { 29 | public GoogleMusicAdapter(FragmentManager fm) { 30 | super(fm); 31 | } 32 | 33 | @Override 34 | public Fragment getItem(int position) { 35 | return TestFragment.newInstance(CONTENT[position % CONTENT.length]); 36 | } 37 | 38 | @Override 39 | public CharSequence getPageTitle(int position) { 40 | return CONTENT[position % CONTENT.length].toUpperCase(); 41 | } 42 | 43 | @Override 44 | public int getCount() { 45 | return CONTENT.length; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleTabsStyled.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentActivity; 6 | import android.support.v4.app.FragmentManager; 7 | import android.support.v4.app.FragmentPagerAdapter; 8 | import android.support.v4.view.ViewPager; 9 | import com.viewpagerindicator.TabPageIndicator; 10 | 11 | public class SampleTabsStyled extends FragmentActivity { 12 | private static final String[] CONTENT = new String[] { "Recent", "Artists", "Albums", "Songs", "Playlists", "Genres" }; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.simple_tabs); 18 | 19 | FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager()); 20 | 21 | ViewPager pager = (ViewPager)findViewById(R.id.pager); 22 | pager.setAdapter(adapter); 23 | 24 | TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator); 25 | indicator.setViewPager(pager); 26 | } 27 | 28 | class GoogleMusicAdapter extends FragmentPagerAdapter { 29 | public GoogleMusicAdapter(FragmentManager fm) { 30 | super(fm); 31 | } 32 | 33 | @Override 34 | public Fragment getItem(int position) { 35 | return TestFragment.newInstance(CONTENT[position % CONTENT.length]); 36 | } 37 | 38 | @Override 39 | public CharSequence getPageTitle(int position) { 40 | return CONTENT[position % CONTENT.length].toUpperCase(); 41 | } 42 | 43 | @Override 44 | public int getCount() { 45 | return CONTENT.length; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/themed_titles.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 23 | 24 | 38 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/BaseSampleActivity.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import java.util.Random; 4 | 5 | import com.viewpagerindicator.PageIndicator; 6 | 7 | import android.support.v4.app.FragmentActivity; 8 | import android.support.v4.view.ViewPager; 9 | import android.view.Menu; 10 | import android.view.MenuItem; 11 | import android.widget.Toast; 12 | 13 | public abstract class BaseSampleActivity extends FragmentActivity { 14 | private static final Random RANDOM = new Random(); 15 | 16 | TestFragmentAdapter mAdapter; 17 | ViewPager mPager; 18 | PageIndicator mIndicator; 19 | 20 | @Override 21 | public boolean onCreateOptionsMenu(Menu menu) { 22 | getMenuInflater().inflate(R.menu.menu, menu); 23 | return true; 24 | } 25 | 26 | @Override 27 | public boolean onOptionsItemSelected(MenuItem item) { 28 | switch (item.getItemId()) { 29 | case R.id.random: 30 | final int page = RANDOM.nextInt(mAdapter.getCount()); 31 | Toast.makeText(this, "Changing to page " + page, Toast.LENGTH_SHORT); 32 | mPager.setCurrentItem(page); 33 | return true; 34 | 35 | case R.id.add_page: 36 | if (mAdapter.getCount() < 10) { 37 | mAdapter.setCount(mAdapter.getCount() + 1); 38 | mIndicator.notifyDataSetChanged(); 39 | } 40 | return true; 41 | 42 | case R.id.remove_page: 43 | if (mAdapter.getCount() > 1) { 44 | mAdapter.setCount(mAdapter.getCount() - 1); 45 | mIndicator.notifyDataSetChanged(); 46 | } 47 | return true; 48 | } 49 | return super.onOptionsItemSelected(item); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lib/src/main/java/com/viewpagerindicator/PageIndicator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Patrik Akerfeldt 3 | * Copyright (C) 2011 Jake Wharton 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package com.viewpagerindicator; 19 | 20 | import android.support.v4.view.ViewPager; 21 | 22 | /** 23 | * A PageIndicator is responsible to show an visual indicator on the total views 24 | * number and the current visible view. 25 | */ 26 | public interface PageIndicator extends ViewPager.OnPageChangeListener { 27 | /** 28 | * Bind the indicator to a ViewPager. 29 | * 30 | * @param view 31 | */ 32 | void setViewPager(ViewPager view); 33 | 34 | /** 35 | * Bind the indicator to a ViewPager. 36 | * 37 | * @param view 38 | * @param initialPosition 39 | */ 40 | void setViewPager(ViewPager view, int initialPosition); 41 | 42 | /** 43 | *

Set the current page of both the ViewPager and indicator.

44 | * 45 | *

This must be used if you need to set the page before 46 | * the views are drawn on screen (e.g., default start page).

47 | * 48 | * @param item 49 | */ 50 | void setCurrentItem(int item); 51 | 52 | /** 53 | * Set a page change listener which will receive forwarded events. 54 | * 55 | * @param listener 56 | */ 57 | void setOnPageChangeListener(ViewPager.OnPageChangeListener listener); 58 | 59 | /** 60 | * Notify the indicator that the fragment list has changed. 61 | */ 62 | void notifyDataSetChanged(); 63 | } 64 | -------------------------------------------------------------------------------- /lib/src/main/res/values/vpi__styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 22 | 23 | 25 | 26 | 37 | 38 | 42 | 43 | 47 | 48 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/SampleTabsWithIcons.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.support.v4.app.FragmentActivity; 6 | import android.support.v4.app.FragmentManager; 7 | import android.support.v4.app.FragmentPagerAdapter; 8 | import android.support.v4.view.ViewPager; 9 | import com.viewpagerindicator.IconPagerAdapter; 10 | import com.viewpagerindicator.TabPageIndicator; 11 | 12 | public class SampleTabsWithIcons extends FragmentActivity { 13 | private static final String[] CONTENT = new String[] { "Calendar", "Camera", "Alarms", "Location" }; 14 | private static final int[] ICONS = new int[] { 15 | R.drawable.perm_group_calendar, 16 | R.drawable.perm_group_camera, 17 | R.drawable.perm_group_device_alarms, 18 | R.drawable.perm_group_location, 19 | }; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.simple_tabs); 25 | 26 | FragmentPagerAdapter adapter = new GoogleMusicAdapter(getSupportFragmentManager()); 27 | 28 | ViewPager pager = (ViewPager)findViewById(R.id.pager); 29 | pager.setAdapter(adapter); 30 | 31 | TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator); 32 | indicator.setViewPager(pager); 33 | } 34 | 35 | class GoogleMusicAdapter extends FragmentPagerAdapter implements IconPagerAdapter { 36 | public GoogleMusicAdapter(FragmentManager fm) { 37 | super(fm); 38 | } 39 | 40 | @Override 41 | public Fragment getItem(int position) { 42 | return TestFragment.newInstance(CONTENT[position % CONTENT.length]); 43 | } 44 | 45 | @Override 46 | public CharSequence getPageTitle(int position) { 47 | return CONTENT[position % CONTENT.length].toUpperCase(); 48 | } 49 | 50 | @Override public int getIconResId(int index) { 51 | return ICONS[index]; 52 | } 53 | 54 | @Override 55 | public int getCount() { 56 | return CONTENT.length; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/TestFragment.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.Gravity; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.LinearLayout; 10 | import android.widget.LinearLayout.LayoutParams; 11 | import android.widget.TextView; 12 | 13 | public final class TestFragment extends Fragment { 14 | private static final String KEY_CONTENT = "TestFragment:Content"; 15 | 16 | public static TestFragment newInstance(String content) { 17 | TestFragment fragment = new TestFragment(); 18 | 19 | StringBuilder builder = new StringBuilder(); 20 | for (int i = 0; i < 20; i++) { 21 | builder.append(content).append(" "); 22 | } 23 | builder.deleteCharAt(builder.length() - 1); 24 | fragment.mContent = builder.toString(); 25 | 26 | return fragment; 27 | } 28 | 29 | private String mContent = "???"; 30 | 31 | @Override 32 | public void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | 35 | if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)) { 36 | mContent = savedInstanceState.getString(KEY_CONTENT); 37 | } 38 | } 39 | 40 | @Override 41 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 42 | TextView text = new TextView(getActivity()); 43 | text.setGravity(Gravity.CENTER); 44 | text.setText(mContent); 45 | text.setTextSize(20 * getResources().getDisplayMetrics().density); 46 | text.setPadding(20, 20, 20, 20); 47 | 48 | LinearLayout layout = new LinearLayout(getActivity()); 49 | layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 50 | layout.setGravity(Gravity.CENTER); 51 | layout.addView(text); 52 | 53 | return layout; 54 | } 55 | 56 | @Override 57 | public void onSaveInstanceState(Bundle outState) { 58 | super.onSaveInstanceState(outState); 59 | outState.putString(KEY_CONTENT, mContent); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /lib/src/main/res/drawable/vpi__tab_indicator.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/custom_tab_indicator.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /lib/src/main/res/values/vpi__defaults.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | true 19 | #FFFFFFFF 20 | #00000000 21 | 0 22 | 3dp 23 | false 24 | #FFDDDDDD 25 | 1dp 26 | 27 | 12dp 28 | 4dp 29 | 1dp 30 | #FF33B5E5 31 | #FFBBBBBB 32 | true 33 | 34 | 4dp 35 | #FF33B5E5 36 | 2dp 37 | 2 38 | 4dp 39 | 20dp 40 | 7dp 41 | 0 42 | #FFFFFFFF 43 | true 44 | #BBFFFFFF 45 | 15dp 46 | 5dp 47 | 7dp 48 | 49 | true 50 | 300 51 | 400 52 | #FF33B5E5 53 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 25 | 26 | 36 | 37 | 43 | 44 | 51 | 52 | 65 | 66 | 69 | 70 | 76 | 77 | -------------------------------------------------------------------------------- /sample/src/main/java/com/viewpagerindicator/sample/ListSamples.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator.sample; 2 | 3 | import java.text.Collator; 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | import java.util.Comparator; 7 | import java.util.HashMap; 8 | import java.util.List; 9 | import java.util.Map; 10 | import android.app.ListActivity; 11 | import android.content.Intent; 12 | import android.content.pm.PackageManager; 13 | import android.content.pm.ResolveInfo; 14 | import android.os.Bundle; 15 | import android.view.View; 16 | import android.widget.ListView; 17 | import android.widget.SimpleAdapter; 18 | 19 | public class ListSamples extends ListActivity { 20 | 21 | @Override 22 | public void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | 25 | Intent intent = getIntent(); 26 | String path = intent.getStringExtra("com.jakewharton.android.viewpagerindicator.sample.Path"); 27 | 28 | if (path == null) { 29 | path = ""; 30 | } 31 | 32 | setListAdapter(new SimpleAdapter(this, getData(path), 33 | android.R.layout.simple_list_item_1, new String[] { "title" }, 34 | new int[] { android.R.id.text1 })); 35 | getListView().setTextFilterEnabled(true); 36 | } 37 | 38 | protected List> getData(String prefix) { 39 | List> myData = new ArrayList>(); 40 | 41 | Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 42 | mainIntent.addCategory("com.jakewharton.android.viewpagerindicator.sample.SAMPLE"); 43 | 44 | PackageManager pm = getPackageManager(); 45 | List list = pm.queryIntentActivities(mainIntent, 0); 46 | 47 | if (null == list) 48 | return myData; 49 | 50 | String[] prefixPath; 51 | String prefixWithSlash = prefix; 52 | 53 | if (prefix.equals("")) { 54 | prefixPath = null; 55 | } else { 56 | prefixPath = prefix.split("/"); 57 | prefixWithSlash = prefix + "/"; 58 | } 59 | 60 | int len = list.size(); 61 | 62 | Map entries = new HashMap(); 63 | 64 | for (int i = 0; i < len; i++) { 65 | ResolveInfo info = list.get(i); 66 | CharSequence labelSeq = info.loadLabel(pm); 67 | String label = labelSeq != null 68 | ? labelSeq.toString() 69 | : info.activityInfo.name; 70 | 71 | if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) { 72 | 73 | String[] labelPath = label.split("/"); 74 | 75 | String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length]; 76 | 77 | if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) { 78 | addItem(myData, nextLabel, activityIntent( 79 | info.activityInfo.applicationInfo.packageName, 80 | info.activityInfo.name)); 81 | } else { 82 | if (entries.get(nextLabel) == null) { 83 | addItem(myData, nextLabel, browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel)); 84 | entries.put(nextLabel, true); 85 | } 86 | } 87 | } 88 | } 89 | 90 | Collections.sort(myData, NAME_COMPARATOR); 91 | 92 | return myData; 93 | } 94 | 95 | private final static Comparator> NAME_COMPARATOR = 96 | new Comparator>() { 97 | private final Collator collator = Collator.getInstance(); 98 | 99 | public int compare(Map map1, Map map2) { 100 | return collator.compare(map1.get("title"), map2.get("title")); 101 | } 102 | }; 103 | 104 | protected Intent activityIntent(String pkg, String componentName) { 105 | Intent result = new Intent(); 106 | result.setClassName(pkg, componentName); 107 | return result; 108 | } 109 | 110 | protected Intent browseIntent(String path) { 111 | Intent result = new Intent(); 112 | result.setClass(this, ListSamples.class); 113 | result.putExtra("com.jakewharton.android.viewpagerindicator.sample.Path", path); 114 | return result; 115 | } 116 | 117 | protected void addItem(List> data, String name, Intent intent) { 118 | Map temp = new HashMap(); 119 | temp.put("title", name); 120 | temp.put("intent", intent); 121 | data.add(temp); 122 | } 123 | 124 | @Override 125 | @SuppressWarnings("unchecked") 126 | protected void onListItemClick(ListView l, View v, int position, long id) { 127 | Map map = (Map)l.getItemAtPosition(position); 128 | 129 | Intent intent = (Intent) map.get("intent"); 130 | startActivity(intent); 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /lib/src/main/java/com/viewpagerindicator/IconPageIndicator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * Copyright (C) 2012 Jake Wharton 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.viewpagerindicator; 18 | 19 | import android.content.Context; 20 | import android.support.v4.view.PagerAdapter; 21 | import android.support.v4.view.ViewPager; 22 | import android.support.v4.view.ViewPager.OnPageChangeListener; 23 | import android.util.AttributeSet; 24 | import android.view.Gravity; 25 | import android.view.View; 26 | import android.widget.HorizontalScrollView; 27 | import android.widget.ImageView; 28 | 29 | import static android.view.ViewGroup.LayoutParams.FILL_PARENT; 30 | import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; 31 | 32 | /** 33 | * This widget implements the dynamic action bar tab behavior that can change 34 | * across different configurations or circumstances. 35 | */ 36 | public class IconPageIndicator extends HorizontalScrollView implements PageIndicator { 37 | private final IcsLinearLayout mIconsLayout; 38 | 39 | private ViewPager mViewPager; 40 | private OnPageChangeListener mListener; 41 | private Runnable mIconSelector; 42 | private int mSelectedIndex; 43 | 44 | public IconPageIndicator(Context context) { 45 | this(context, null); 46 | } 47 | 48 | public IconPageIndicator(Context context, AttributeSet attrs) { 49 | super(context, attrs); 50 | setHorizontalScrollBarEnabled(false); 51 | 52 | mIconsLayout = new IcsLinearLayout(context, R.attr.vpiIconPageIndicatorStyle); 53 | addView(mIconsLayout, new LayoutParams(WRAP_CONTENT, FILL_PARENT, Gravity.CENTER)); 54 | } 55 | 56 | private void animateToIcon(final int position) { 57 | final View iconView = mIconsLayout.getChildAt(position); 58 | if (mIconSelector != null) { 59 | removeCallbacks(mIconSelector); 60 | } 61 | mIconSelector = new Runnable() { 62 | public void run() { 63 | final int scrollPos = iconView.getLeft() - (getWidth() - iconView.getWidth()) / 2; 64 | smoothScrollTo(scrollPos, 0); 65 | mIconSelector = null; 66 | } 67 | }; 68 | post(mIconSelector); 69 | } 70 | 71 | @Override 72 | public void onAttachedToWindow() { 73 | super.onAttachedToWindow(); 74 | if (mIconSelector != null) { 75 | // Re-post the selector we saved 76 | post(mIconSelector); 77 | } 78 | } 79 | 80 | @Override 81 | public void onDetachedFromWindow() { 82 | super.onDetachedFromWindow(); 83 | if (mIconSelector != null) { 84 | removeCallbacks(mIconSelector); 85 | } 86 | } 87 | 88 | @Override 89 | public void onPageScrollStateChanged(int arg0) { 90 | if (mListener != null) { 91 | mListener.onPageScrollStateChanged(arg0); 92 | } 93 | } 94 | 95 | @Override 96 | public void onPageScrolled(int arg0, float arg1, int arg2) { 97 | if (mListener != null) { 98 | mListener.onPageScrolled(arg0, arg1, arg2); 99 | } 100 | } 101 | 102 | @Override 103 | public void onPageSelected(int arg0) { 104 | setCurrentItem(arg0); 105 | if (mListener != null) { 106 | mListener.onPageSelected(arg0); 107 | } 108 | } 109 | 110 | @Override 111 | public void setViewPager(ViewPager view) { 112 | if (mViewPager == view) { 113 | return; 114 | } 115 | if (mViewPager != null) { 116 | mViewPager.setOnPageChangeListener(null); 117 | } 118 | PagerAdapter adapter = view.getAdapter(); 119 | if (adapter == null) { 120 | throw new IllegalStateException("ViewPager does not have adapter instance."); 121 | } 122 | mViewPager = view; 123 | view.setOnPageChangeListener(this); 124 | notifyDataSetChanged(); 125 | } 126 | 127 | public void notifyDataSetChanged() { 128 | mIconsLayout.removeAllViews(); 129 | IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter(); 130 | int count = iconAdapter.getCount(); 131 | for (int i = 0; i < count; i++) { 132 | ImageView view = new ImageView(getContext(), null, R.attr.vpiIconPageIndicatorStyle); 133 | view.setImageResource(iconAdapter.getIconResId(i)); 134 | mIconsLayout.addView(view); 135 | } 136 | if (mSelectedIndex > count) { 137 | mSelectedIndex = count - 1; 138 | } 139 | setCurrentItem(mSelectedIndex); 140 | requestLayout(); 141 | } 142 | 143 | @Override 144 | public void setViewPager(ViewPager view, int initialPosition) { 145 | setViewPager(view); 146 | setCurrentItem(initialPosition); 147 | } 148 | 149 | @Override 150 | public void setCurrentItem(int item) { 151 | if (mViewPager == null) { 152 | throw new IllegalStateException("ViewPager has not been bound."); 153 | } 154 | mSelectedIndex = item; 155 | mViewPager.setCurrentItem(item); 156 | 157 | int tabCount = mIconsLayout.getChildCount(); 158 | for (int i = 0; i < tabCount; i++) { 159 | View child = mIconsLayout.getChildAt(i); 160 | boolean isSelected = (i == item); 161 | child.setSelected(isSelected); 162 | if (isSelected) { 163 | animateToIcon(item); 164 | } 165 | } 166 | } 167 | 168 | @Override 169 | public void setOnPageChangeListener(OnPageChangeListener listener) { 170 | mListener = listener; 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /lib/src/main/res/values/vpi__attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 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 | -------------------------------------------------------------------------------- /lib/src/main/java/com/viewpagerindicator/IcsLinearLayout.java: -------------------------------------------------------------------------------- 1 | package com.viewpagerindicator; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.drawable.Drawable; 7 | import android.view.View; 8 | import android.widget.LinearLayout; 9 | 10 | /** 11 | * A simple extension of a regular linear layout that supports the divider API 12 | * of Android 4.0+. The dividers are added adjacent to the children by changing 13 | * their layout params. If you need to rely on the margins which fall in the 14 | * same orientation as the layout you should wrap the child in a simple 15 | * {@link android.widget.FrameLayout} so it can receive the margin. 16 | */ 17 | class IcsLinearLayout extends LinearLayout { 18 | private static final int[] LL = new int[] { 19 | /* 0 */ android.R.attr.divider, 20 | /* 1 */ android.R.attr.showDividers, 21 | /* 2 */ android.R.attr.dividerPadding, 22 | }; 23 | private static final int LL_DIVIDER = 0; 24 | private static final int LL_SHOW_DIVIDER = 1; 25 | private static final int LL_DIVIDER_PADDING = 2; 26 | 27 | private Drawable mDivider; 28 | private int mDividerWidth; 29 | private int mDividerHeight; 30 | private int mShowDividers; 31 | private int mDividerPadding; 32 | 33 | 34 | public IcsLinearLayout(Context context, int themeAttr) { 35 | super(context); 36 | 37 | TypedArray a = context.obtainStyledAttributes(null, LL, themeAttr, 0); 38 | setDividerDrawable(a.getDrawable(IcsLinearLayout.LL_DIVIDER)); 39 | mDividerPadding = a.getDimensionPixelSize(LL_DIVIDER_PADDING, 0); 40 | mShowDividers = a.getInteger(LL_SHOW_DIVIDER, SHOW_DIVIDER_NONE); 41 | a.recycle(); 42 | } 43 | 44 | public void setDividerDrawable(Drawable divider) { 45 | if (divider == mDivider) { 46 | return; 47 | } 48 | mDivider = divider; 49 | if (divider != null) { 50 | mDividerWidth = divider.getIntrinsicWidth(); 51 | mDividerHeight = divider.getIntrinsicHeight(); 52 | } else { 53 | mDividerWidth = 0; 54 | mDividerHeight = 0; 55 | } 56 | setWillNotDraw(divider == null); 57 | requestLayout(); 58 | } 59 | 60 | @Override 61 | protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) { 62 | final int index = indexOfChild(child); 63 | final int orientation = getOrientation(); 64 | final LayoutParams params = (LayoutParams) child.getLayoutParams(); 65 | if (hasDividerBeforeChildAt(index)) { 66 | if (orientation == VERTICAL) { 67 | //Account for the divider by pushing everything up 68 | params.topMargin = mDividerHeight; 69 | } else { 70 | //Account for the divider by pushing everything left 71 | params.leftMargin = mDividerWidth; 72 | } 73 | } 74 | 75 | final int count = getChildCount(); 76 | if (index == count - 1) { 77 | if (hasDividerBeforeChildAt(count)) { 78 | if (orientation == VERTICAL) { 79 | params.bottomMargin = mDividerHeight; 80 | } else { 81 | params.rightMargin = mDividerWidth; 82 | } 83 | } 84 | } 85 | super.measureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed); 86 | } 87 | 88 | @Override 89 | protected void onDraw(Canvas canvas) { 90 | if (mDivider != null) { 91 | if (getOrientation() == VERTICAL) { 92 | drawDividersVertical(canvas); 93 | } else { 94 | drawDividersHorizontal(canvas); 95 | } 96 | } 97 | super.onDraw(canvas); 98 | } 99 | 100 | private void drawDividersVertical(Canvas canvas) { 101 | final int count = getChildCount(); 102 | for (int i = 0; i < count; i++) { 103 | final View child = getChildAt(i); 104 | 105 | if (child != null && child.getVisibility() != GONE) { 106 | if (hasDividerBeforeChildAt(i)) { 107 | final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 108 | final int top = child.getTop() - lp.topMargin/* - mDividerHeight*/; 109 | drawHorizontalDivider(canvas, top); 110 | } 111 | } 112 | } 113 | 114 | if (hasDividerBeforeChildAt(count)) { 115 | final View child = getChildAt(count - 1); 116 | int bottom = 0; 117 | if (child == null) { 118 | bottom = getHeight() - getPaddingBottom() - mDividerHeight; 119 | } else { 120 | //final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 121 | bottom = child.getBottom()/* + lp.bottomMargin*/; 122 | } 123 | drawHorizontalDivider(canvas, bottom); 124 | } 125 | } 126 | 127 | private void drawDividersHorizontal(Canvas canvas) { 128 | final int count = getChildCount(); 129 | for (int i = 0; i < count; i++) { 130 | final View child = getChildAt(i); 131 | 132 | if (child != null && child.getVisibility() != GONE) { 133 | if (hasDividerBeforeChildAt(i)) { 134 | final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 135 | final int left = child.getLeft() - lp.leftMargin/* - mDividerWidth*/; 136 | drawVerticalDivider(canvas, left); 137 | } 138 | } 139 | } 140 | 141 | if (hasDividerBeforeChildAt(count)) { 142 | final View child = getChildAt(count - 1); 143 | int right = 0; 144 | if (child == null) { 145 | right = getWidth() - getPaddingRight() - mDividerWidth; 146 | } else { 147 | //final LayoutParams lp = (LayoutParams) child.getLayoutParams(); 148 | right = child.getRight()/* + lp.rightMargin*/; 149 | } 150 | drawVerticalDivider(canvas, right); 151 | } 152 | } 153 | 154 | private void drawHorizontalDivider(Canvas canvas, int top) { 155 | mDivider.setBounds(getPaddingLeft() + mDividerPadding, top, 156 | getWidth() - getPaddingRight() - mDividerPadding, top + mDividerHeight); 157 | mDivider.draw(canvas); 158 | } 159 | 160 | private void drawVerticalDivider(Canvas canvas, int left) { 161 | mDivider.setBounds(left, getPaddingTop() + mDividerPadding, 162 | left + mDividerWidth, getHeight() - getPaddingBottom() - mDividerPadding); 163 | mDivider.draw(canvas); 164 | } 165 | 166 | private boolean hasDividerBeforeChildAt(int childIndex) { 167 | if (childIndex == 0 || childIndex == getChildCount()) { 168 | return false; 169 | } 170 | if ((mShowDividers & SHOW_DIVIDER_MIDDLE) != 0) { 171 | boolean hasVisibleViewBefore = false; 172 | for (int i = childIndex - 1; i >= 0; i--) { 173 | if (getChildAt(i).getVisibility() != GONE) { 174 | hasVisibleViewBefore = true; 175 | break; 176 | } 177 | } 178 | return hasVisibleViewBefore; 179 | } 180 | return false; 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /lib/src/main/java/com/viewpagerindicator/TabPageIndicator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * Copyright (C) 2011 Jake Wharton 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package com.viewpagerindicator; 18 | 19 | import android.content.Context; 20 | import android.support.v4.view.PagerAdapter; 21 | import android.support.v4.view.ViewPager; 22 | import android.support.v4.view.ViewPager.OnPageChangeListener; 23 | import android.util.AttributeSet; 24 | import android.view.View; 25 | import android.view.ViewGroup; 26 | import android.widget.HorizontalScrollView; 27 | import android.widget.LinearLayout; 28 | import android.widget.TextView; 29 | 30 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; 31 | import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; 32 | 33 | /** 34 | * This widget implements the dynamic action bar tab behavior that can change 35 | * across different configurations or circumstances. 36 | */ 37 | public class TabPageIndicator extends HorizontalScrollView implements PageIndicator { 38 | /** Title text used when no title is provided by the adapter. */ 39 | private static final CharSequence EMPTY_TITLE = ""; 40 | 41 | /** 42 | * Interface for a callback when the selected tab has been reselected. 43 | */ 44 | public interface OnTabReselectedListener { 45 | /** 46 | * Callback when the selected tab has been reselected. 47 | * 48 | * @param position Position of the current center item. 49 | */ 50 | void onTabReselected(int position); 51 | } 52 | 53 | private Runnable mTabSelector; 54 | 55 | private final OnClickListener mTabClickListener = new OnClickListener() { 56 | public void onClick(View view) { 57 | TabView tabView = (TabView)view; 58 | final int oldSelected = mViewPager.getCurrentItem(); 59 | final int newSelected = tabView.getIndex(); 60 | mViewPager.setCurrentItem(newSelected); 61 | if (oldSelected == newSelected && mTabReselectedListener != null) { 62 | mTabReselectedListener.onTabReselected(newSelected); 63 | } 64 | } 65 | }; 66 | 67 | private final IcsLinearLayout mTabLayout; 68 | 69 | private ViewPager mViewPager; 70 | private OnPageChangeListener mListener; 71 | 72 | private int mMaxTabWidth; 73 | private int mSelectedTabIndex; 74 | 75 | private OnTabReselectedListener mTabReselectedListener; 76 | 77 | public TabPageIndicator(Context context) { 78 | this(context, null); 79 | } 80 | 81 | public TabPageIndicator(Context context, AttributeSet attrs) { 82 | super(context, attrs); 83 | setHorizontalScrollBarEnabled(false); 84 | 85 | mTabLayout = new IcsLinearLayout(context, R.attr.vpiTabPageIndicatorStyle); 86 | addView(mTabLayout, new ViewGroup.LayoutParams(WRAP_CONTENT, MATCH_PARENT)); 87 | } 88 | 89 | public void setOnTabReselectedListener(OnTabReselectedListener listener) { 90 | mTabReselectedListener = listener; 91 | } 92 | 93 | @Override 94 | public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 95 | final int widthMode = MeasureSpec.getMode(widthMeasureSpec); 96 | final boolean lockedExpanded = widthMode == MeasureSpec.EXACTLY; 97 | setFillViewport(lockedExpanded); 98 | 99 | final int childCount = mTabLayout.getChildCount(); 100 | if (childCount > 1 && (widthMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.AT_MOST)) { 101 | if (childCount > 2) { 102 | mMaxTabWidth = (int)(MeasureSpec.getSize(widthMeasureSpec) * 0.4f); 103 | } else { 104 | mMaxTabWidth = MeasureSpec.getSize(widthMeasureSpec) / 2; 105 | } 106 | } else { 107 | mMaxTabWidth = -1; 108 | } 109 | 110 | final int oldWidth = getMeasuredWidth(); 111 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 112 | final int newWidth = getMeasuredWidth(); 113 | 114 | if (lockedExpanded && oldWidth != newWidth) { 115 | // Recenter the tab display if we're at a new (scrollable) size. 116 | setCurrentItem(mSelectedTabIndex); 117 | } 118 | } 119 | 120 | private void animateToTab(final int position) { 121 | final View tabView = mTabLayout.getChildAt(position); 122 | if (mTabSelector != null) { 123 | removeCallbacks(mTabSelector); 124 | } 125 | mTabSelector = new Runnable() { 126 | public void run() { 127 | final int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2; 128 | smoothScrollTo(scrollPos, 0); 129 | mTabSelector = null; 130 | } 131 | }; 132 | post(mTabSelector); 133 | } 134 | 135 | @Override 136 | public void onAttachedToWindow() { 137 | super.onAttachedToWindow(); 138 | if (mTabSelector != null) { 139 | // Re-post the selector we saved 140 | post(mTabSelector); 141 | } 142 | } 143 | 144 | @Override 145 | public void onDetachedFromWindow() { 146 | super.onDetachedFromWindow(); 147 | if (mTabSelector != null) { 148 | removeCallbacks(mTabSelector); 149 | } 150 | } 151 | 152 | private void addTab(int index, CharSequence text, int iconResId) { 153 | final TabView tabView = new TabView(getContext()); 154 | tabView.mIndex = index; 155 | tabView.setFocusable(true); 156 | tabView.setOnClickListener(mTabClickListener); 157 | tabView.setText(text); 158 | 159 | if (iconResId != 0) { 160 | tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0); 161 | } 162 | 163 | mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1)); 164 | } 165 | 166 | @Override 167 | public void onPageScrollStateChanged(int arg0) { 168 | if (mListener != null) { 169 | mListener.onPageScrollStateChanged(arg0); 170 | } 171 | } 172 | 173 | @Override 174 | public void onPageScrolled(int arg0, float arg1, int arg2) { 175 | if (mListener != null) { 176 | mListener.onPageScrolled(arg0, arg1, arg2); 177 | } 178 | } 179 | 180 | @Override 181 | public void onPageSelected(int arg0) { 182 | setCurrentItem(arg0); 183 | if (mListener != null) { 184 | mListener.onPageSelected(arg0); 185 | } 186 | } 187 | 188 | @Override 189 | public void setViewPager(ViewPager view) { 190 | if (mViewPager == view) { 191 | return; 192 | } 193 | if (mViewPager != null) { 194 | mViewPager.setOnPageChangeListener(null); 195 | } 196 | final PagerAdapter adapter = view.getAdapter(); 197 | if (adapter == null) { 198 | throw new IllegalStateException("ViewPager does not have adapter instance."); 199 | } 200 | mViewPager = view; 201 | view.setOnPageChangeListener(this); 202 | notifyDataSetChanged(); 203 | } 204 | 205 | public void notifyDataSetChanged() { 206 | mTabLayout.removeAllViews(); 207 | PagerAdapter adapter = mViewPager.getAdapter(); 208 | IconPagerAdapter iconAdapter = null; 209 | if (adapter instanceof IconPagerAdapter) { 210 | iconAdapter = (IconPagerAdapter)adapter; 211 | } 212 | final int count = adapter.getCount(); 213 | for (int i = 0; i < count; i++) { 214 | CharSequence title = adapter.getPageTitle(i); 215 | if (title == null) { 216 | title = EMPTY_TITLE; 217 | } 218 | int iconResId = 0; 219 | if (iconAdapter != null) { 220 | iconResId = iconAdapter.getIconResId(i); 221 | } 222 | addTab(i, title, iconResId); 223 | } 224 | if (mSelectedTabIndex > count) { 225 | mSelectedTabIndex = count - 1; 226 | } 227 | setCurrentItem(mSelectedTabIndex); 228 | requestLayout(); 229 | } 230 | 231 | @Override 232 | public void setViewPager(ViewPager view, int initialPosition) { 233 | setViewPager(view); 234 | setCurrentItem(initialPosition); 235 | } 236 | 237 | @Override 238 | public void setCurrentItem(int item) { 239 | if (mViewPager == null) { 240 | throw new IllegalStateException("ViewPager has not been bound."); 241 | } 242 | mSelectedTabIndex = item; 243 | mViewPager.setCurrentItem(item); 244 | 245 | final int tabCount = mTabLayout.getChildCount(); 246 | for (int i = 0; i < tabCount; i++) { 247 | final View child = mTabLayout.getChildAt(i); 248 | final boolean isSelected = (i == item); 249 | child.setSelected(isSelected); 250 | if (isSelected) { 251 | animateToTab(item); 252 | } 253 | } 254 | } 255 | 256 | @Override 257 | public void setOnPageChangeListener(OnPageChangeListener listener) { 258 | mListener = listener; 259 | } 260 | 261 | private class TabView extends TextView { 262 | private int mIndex; 263 | 264 | public TabView(Context context) { 265 | super(context, null, R.attr.vpiTabPageIndicatorStyle); 266 | } 267 | 268 | @Override 269 | public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 270 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 271 | 272 | // Re-measure if we went beyond our maximum size. 273 | if (mMaxTabWidth > 0 && getMeasuredWidth() > mMaxTabWidth) { 274 | super.onMeasure(MeasureSpec.makeMeasureSpec(mMaxTabWidth, MeasureSpec.EXACTLY), 275 | heightMeasureSpec); 276 | } 277 | } 278 | 279 | public int getIndex() { 280 | return mIndex; 281 | } 282 | } 283 | } 284 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 | 27 | 28 | 29 | 30 | 33 | 34 | 35 | 36 | 37 | 38 | 41 | 42 | 43 | 44 | 45 | 46 | 50 | 51 | 52 | 53 | 54 | 55 | 59 | 60 | 61 | 62 | 63 | 64 | 68 | 69 | 70 | 71 | 72 | 73 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 101 | 102 | 103 | 104 | 105 | 106 | 110 | 111 | 112 | 113 | 114 | 115 | 119 | 120 | 121 | 122 | 123 | 124 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 140 | 141 | 142 | 143 | 144 | 145 | 148 | 149 | 150 | 151 | 152 | 153 | 156 | 157 | 158 | 159 | 160 | 161 | 164 | 165 | 166 | 167 | 168 | 169 | 173 | 174 | 175 | 176 | 177 | 178 | 182 | 183 | 184 | 185 | 186 | 187 | 191 | 192 | 193 | 194 | 195 | 196 | 199 | 200 | 201 | 202 | 203 | 204 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 220 | 221 | 222 | 223 | 224 | 225 | 229 | 230 | 231 | 232 | 233 | 234 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 250 | 251 | 252 | 253 | 254 | 255 | 258 | 259 | 260 | 261 | 262 | 263 | 267 | 268 | 269 | 270 | 271 | 272 | 276 | 277 | 278 | 279 | 280 | 281 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | -------------------------------------------------------------------------------- /lib/src/main/java/com/viewpagerindicator/UnderlinePageIndicator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Jake Wharton 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.viewpagerindicator; 17 | 18 | import android.content.Context; 19 | import android.content.res.Resources; 20 | import android.content.res.TypedArray; 21 | import android.graphics.Canvas; 22 | import android.graphics.Paint; 23 | import android.graphics.drawable.Drawable; 24 | import android.os.Parcel; 25 | import android.os.Parcelable; 26 | import android.support.v4.view.MotionEventCompat; 27 | import android.support.v4.view.ViewConfigurationCompat; 28 | import android.support.v4.view.ViewPager; 29 | import android.util.AttributeSet; 30 | import android.view.MotionEvent; 31 | import android.view.View; 32 | import android.view.ViewConfiguration; 33 | 34 | /** 35 | * Draws a line for each page. The current page line is colored differently 36 | * than the unselected page lines. 37 | */ 38 | public class UnderlinePageIndicator extends View implements PageIndicator { 39 | private static final int INVALID_POINTER = -1; 40 | private static final int FADE_FRAME_MS = 30; 41 | 42 | private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 43 | 44 | private boolean mFades; 45 | private int mFadeDelay; 46 | private int mFadeLength; 47 | private int mFadeBy; 48 | 49 | private ViewPager mViewPager; 50 | private ViewPager.OnPageChangeListener mListener; 51 | private int mScrollState; 52 | private int mCurrentPage; 53 | private float mPositionOffset; 54 | 55 | private int mTouchSlop; 56 | private float mLastMotionX = -1; 57 | private int mActivePointerId = INVALID_POINTER; 58 | private boolean mIsDragging; 59 | 60 | private final Runnable mFadeRunnable = new Runnable() { 61 | @Override public void run() { 62 | if (!mFades) return; 63 | 64 | final int alpha = Math.max(mPaint.getAlpha() - mFadeBy, 0); 65 | mPaint.setAlpha(alpha); 66 | invalidate(); 67 | if (alpha > 0) { 68 | postDelayed(this, FADE_FRAME_MS); 69 | } 70 | } 71 | }; 72 | 73 | public UnderlinePageIndicator(Context context) { 74 | this(context, null); 75 | } 76 | 77 | public UnderlinePageIndicator(Context context, AttributeSet attrs) { 78 | this(context, attrs, R.attr.vpiUnderlinePageIndicatorStyle); 79 | } 80 | 81 | public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) { 82 | super(context, attrs, defStyle); 83 | if (isInEditMode()) return; 84 | 85 | final Resources res = getResources(); 86 | 87 | //Load defaults from resources 88 | final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades); 89 | final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay); 90 | final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length); 91 | final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color); 92 | 93 | //Retrieve styles attributes 94 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0); 95 | 96 | setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades)); 97 | setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor)); 98 | setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay)); 99 | setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength)); 100 | 101 | Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background); 102 | if (background != null) { 103 | setBackgroundDrawable(background); 104 | } 105 | 106 | a.recycle(); 107 | 108 | final ViewConfiguration configuration = ViewConfiguration.get(context); 109 | mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); 110 | } 111 | 112 | public boolean getFades() { 113 | return mFades; 114 | } 115 | 116 | public void setFades(boolean fades) { 117 | if (fades != mFades) { 118 | mFades = fades; 119 | if (fades) { 120 | post(mFadeRunnable); 121 | } else { 122 | removeCallbacks(mFadeRunnable); 123 | mPaint.setAlpha(0xFF); 124 | invalidate(); 125 | } 126 | } 127 | } 128 | 129 | public int getFadeDelay() { 130 | return mFadeDelay; 131 | } 132 | 133 | public void setFadeDelay(int fadeDelay) { 134 | mFadeDelay = fadeDelay; 135 | } 136 | 137 | public int getFadeLength() { 138 | return mFadeLength; 139 | } 140 | 141 | public void setFadeLength(int fadeLength) { 142 | mFadeLength = fadeLength; 143 | mFadeBy = 0xFF / (mFadeLength / FADE_FRAME_MS); 144 | } 145 | 146 | public int getSelectedColor() { 147 | return mPaint.getColor(); 148 | } 149 | 150 | public void setSelectedColor(int selectedColor) { 151 | mPaint.setColor(selectedColor); 152 | invalidate(); 153 | } 154 | 155 | @Override 156 | protected void onDraw(Canvas canvas) { 157 | super.onDraw(canvas); 158 | 159 | if (mViewPager == null) { 160 | return; 161 | } 162 | final int count = mViewPager.getAdapter().getCount(); 163 | if (count == 0) { 164 | return; 165 | } 166 | 167 | if (mCurrentPage >= count) { 168 | setCurrentItem(count - 1); 169 | return; 170 | } 171 | 172 | final int paddingLeft = getPaddingLeft(); 173 | final float pageWidth = (getWidth() - paddingLeft - getPaddingRight()) / (1f * count); 174 | final float left = paddingLeft + pageWidth * (mCurrentPage + mPositionOffset); 175 | final float right = left + pageWidth; 176 | final float top = getPaddingTop(); 177 | final float bottom = getHeight() - getPaddingBottom(); 178 | canvas.drawRect(left, top, right, bottom, mPaint); 179 | } 180 | 181 | public boolean onTouchEvent(MotionEvent ev) { 182 | if (super.onTouchEvent(ev)) { 183 | return true; 184 | } 185 | if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { 186 | return false; 187 | } 188 | 189 | final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; 190 | switch (action) { 191 | case MotionEvent.ACTION_DOWN: 192 | mActivePointerId = MotionEventCompat.getPointerId(ev, 0); 193 | mLastMotionX = ev.getX(); 194 | break; 195 | 196 | case MotionEvent.ACTION_MOVE: { 197 | final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); 198 | final float x = MotionEventCompat.getX(ev, activePointerIndex); 199 | final float deltaX = x - mLastMotionX; 200 | 201 | if (!mIsDragging) { 202 | if (Math.abs(deltaX) > mTouchSlop) { 203 | mIsDragging = true; 204 | } 205 | } 206 | 207 | if (mIsDragging) { 208 | mLastMotionX = x; 209 | if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { 210 | mViewPager.fakeDragBy(deltaX); 211 | } 212 | } 213 | 214 | break; 215 | } 216 | 217 | case MotionEvent.ACTION_CANCEL: 218 | case MotionEvent.ACTION_UP: 219 | if (!mIsDragging) { 220 | final int count = mViewPager.getAdapter().getCount(); 221 | final int width = getWidth(); 222 | final float halfWidth = width / 2f; 223 | final float sixthWidth = width / 6f; 224 | 225 | if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { 226 | if (action != MotionEvent.ACTION_CANCEL) { 227 | mViewPager.setCurrentItem(mCurrentPage - 1); 228 | } 229 | return true; 230 | } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { 231 | if (action != MotionEvent.ACTION_CANCEL) { 232 | mViewPager.setCurrentItem(mCurrentPage + 1); 233 | } 234 | return true; 235 | } 236 | } 237 | 238 | mIsDragging = false; 239 | mActivePointerId = INVALID_POINTER; 240 | if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); 241 | break; 242 | 243 | case MotionEventCompat.ACTION_POINTER_DOWN: { 244 | final int index = MotionEventCompat.getActionIndex(ev); 245 | mLastMotionX = MotionEventCompat.getX(ev, index); 246 | mActivePointerId = MotionEventCompat.getPointerId(ev, index); 247 | break; 248 | } 249 | 250 | case MotionEventCompat.ACTION_POINTER_UP: 251 | final int pointerIndex = MotionEventCompat.getActionIndex(ev); 252 | final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); 253 | if (pointerId == mActivePointerId) { 254 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; 255 | mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); 256 | } 257 | mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); 258 | break; 259 | } 260 | 261 | return true; 262 | } 263 | 264 | @Override 265 | public void setViewPager(ViewPager viewPager) { 266 | if (mViewPager == viewPager) { 267 | return; 268 | } 269 | if (mViewPager != null) { 270 | //Clear us from the old pager. 271 | mViewPager.setOnPageChangeListener(null); 272 | } 273 | if (viewPager.getAdapter() == null) { 274 | throw new IllegalStateException("ViewPager does not have adapter instance."); 275 | } 276 | mViewPager = viewPager; 277 | mViewPager.setOnPageChangeListener(this); 278 | invalidate(); 279 | post(new Runnable() { 280 | @Override public void run() { 281 | if (mFades) { 282 | post(mFadeRunnable); 283 | } 284 | } 285 | }); 286 | } 287 | 288 | @Override 289 | public void setViewPager(ViewPager view, int initialPosition) { 290 | setViewPager(view); 291 | setCurrentItem(initialPosition); 292 | } 293 | 294 | @Override 295 | public void setCurrentItem(int item) { 296 | if (mViewPager == null) { 297 | throw new IllegalStateException("ViewPager has not been bound."); 298 | } 299 | mViewPager.setCurrentItem(item); 300 | mCurrentPage = item; 301 | invalidate(); 302 | } 303 | 304 | @Override 305 | public void notifyDataSetChanged() { 306 | invalidate(); 307 | } 308 | 309 | @Override 310 | public void onPageScrollStateChanged(int state) { 311 | mScrollState = state; 312 | 313 | if (mListener != null) { 314 | mListener.onPageScrollStateChanged(state); 315 | } 316 | } 317 | 318 | @Override 319 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 320 | mCurrentPage = position; 321 | mPositionOffset = positionOffset; 322 | if (mFades) { 323 | if (positionOffsetPixels > 0) { 324 | removeCallbacks(mFadeRunnable); 325 | mPaint.setAlpha(0xFF); 326 | } else if (mScrollState != ViewPager.SCROLL_STATE_DRAGGING) { 327 | postDelayed(mFadeRunnable, mFadeDelay); 328 | } 329 | } 330 | invalidate(); 331 | 332 | if (mListener != null) { 333 | mListener.onPageScrolled(position, positionOffset, positionOffsetPixels); 334 | } 335 | } 336 | 337 | @Override 338 | public void onPageSelected(int position) { 339 | if (mScrollState == ViewPager.SCROLL_STATE_IDLE) { 340 | mCurrentPage = position; 341 | mPositionOffset = 0; 342 | invalidate(); 343 | mFadeRunnable.run(); 344 | } 345 | if (mListener != null) { 346 | mListener.onPageSelected(position); 347 | } 348 | } 349 | 350 | @Override 351 | public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) { 352 | mListener = listener; 353 | } 354 | 355 | @Override 356 | public void onRestoreInstanceState(Parcelable state) { 357 | SavedState savedState = (SavedState)state; 358 | super.onRestoreInstanceState(savedState.getSuperState()); 359 | mCurrentPage = savedState.currentPage; 360 | requestLayout(); 361 | } 362 | 363 | @Override 364 | public Parcelable onSaveInstanceState() { 365 | Parcelable superState = super.onSaveInstanceState(); 366 | SavedState savedState = new SavedState(superState); 367 | savedState.currentPage = mCurrentPage; 368 | return savedState; 369 | } 370 | 371 | static class SavedState extends BaseSavedState { 372 | int currentPage; 373 | 374 | public SavedState(Parcelable superState) { 375 | super(superState); 376 | } 377 | 378 | private SavedState(Parcel in) { 379 | super(in); 380 | currentPage = in.readInt(); 381 | } 382 | 383 | @Override 384 | public void writeToParcel(Parcel dest, int flags) { 385 | super.writeToParcel(dest, flags); 386 | dest.writeInt(currentPage); 387 | } 388 | 389 | @SuppressWarnings("UnusedDeclaration") 390 | public static final Creator CREATOR = new Creator() { 391 | @Override 392 | public SavedState createFromParcel(Parcel in) { 393 | return new SavedState(in); 394 | } 395 | 396 | @Override 397 | public SavedState[] newArray(int size) { 398 | return new SavedState[size]; 399 | } 400 | }; 401 | } 402 | } -------------------------------------------------------------------------------- /lib/src/main/java/com/viewpagerindicator/LinePageIndicator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Jake Wharton 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.viewpagerindicator; 17 | 18 | import android.content.Context; 19 | import android.content.res.Resources; 20 | import android.content.res.TypedArray; 21 | import android.graphics.Canvas; 22 | import android.graphics.Paint; 23 | import android.graphics.drawable.Drawable; 24 | import android.os.Parcel; 25 | import android.os.Parcelable; 26 | import android.support.v4.view.MotionEventCompat; 27 | import android.support.v4.view.ViewConfigurationCompat; 28 | import android.support.v4.view.ViewPager; 29 | import android.util.AttributeSet; 30 | import android.view.MotionEvent; 31 | import android.view.View; 32 | import android.view.ViewConfiguration; 33 | 34 | /** 35 | * Draws a line for each page. The current page line is colored differently 36 | * than the unselected page lines. 37 | */ 38 | public class LinePageIndicator extends View implements PageIndicator { 39 | private static final int INVALID_POINTER = -1; 40 | 41 | private final Paint mPaintUnselected = new Paint(Paint.ANTI_ALIAS_FLAG); 42 | private final Paint mPaintSelected = new Paint(Paint.ANTI_ALIAS_FLAG); 43 | private ViewPager mViewPager; 44 | private ViewPager.OnPageChangeListener mListener; 45 | private int mCurrentPage; 46 | private boolean mCentered; 47 | private float mLineWidth; 48 | private float mGapWidth; 49 | 50 | private int mTouchSlop; 51 | private float mLastMotionX = -1; 52 | private int mActivePointerId = INVALID_POINTER; 53 | private boolean mIsDragging; 54 | 55 | 56 | public LinePageIndicator(Context context) { 57 | this(context, null); 58 | } 59 | 60 | public LinePageIndicator(Context context, AttributeSet attrs) { 61 | this(context, attrs, R.attr.vpiLinePageIndicatorStyle); 62 | } 63 | 64 | public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) { 65 | super(context, attrs, defStyle); 66 | if (isInEditMode()) return; 67 | 68 | final Resources res = getResources(); 69 | 70 | //Load defaults from resources 71 | final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color); 72 | final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color); 73 | final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width); 74 | final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width); 75 | final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width); 76 | final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered); 77 | 78 | //Retrieve styles attributes 79 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0); 80 | 81 | mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered); 82 | mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth); 83 | mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth); 84 | setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth)); 85 | mPaintUnselected.setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor)); 86 | mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor)); 87 | 88 | Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background); 89 | if (background != null) { 90 | setBackgroundDrawable(background); 91 | } 92 | 93 | a.recycle(); 94 | 95 | final ViewConfiguration configuration = ViewConfiguration.get(context); 96 | mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); 97 | } 98 | 99 | 100 | public void setCentered(boolean centered) { 101 | mCentered = centered; 102 | invalidate(); 103 | } 104 | 105 | public boolean isCentered() { 106 | return mCentered; 107 | } 108 | 109 | public void setUnselectedColor(int unselectedColor) { 110 | mPaintUnselected.setColor(unselectedColor); 111 | invalidate(); 112 | } 113 | 114 | public int getUnselectedColor() { 115 | return mPaintUnselected.getColor(); 116 | } 117 | 118 | public void setSelectedColor(int selectedColor) { 119 | mPaintSelected.setColor(selectedColor); 120 | invalidate(); 121 | } 122 | 123 | public int getSelectedColor() { 124 | return mPaintSelected.getColor(); 125 | } 126 | 127 | public void setLineWidth(float lineWidth) { 128 | mLineWidth = lineWidth; 129 | invalidate(); 130 | } 131 | 132 | public float getLineWidth() { 133 | return mLineWidth; 134 | } 135 | 136 | public void setStrokeWidth(float lineHeight) { 137 | mPaintSelected.setStrokeWidth(lineHeight); 138 | mPaintUnselected.setStrokeWidth(lineHeight); 139 | invalidate(); 140 | } 141 | 142 | public float getStrokeWidth() { 143 | return mPaintSelected.getStrokeWidth(); 144 | } 145 | 146 | public void setGapWidth(float gapWidth) { 147 | mGapWidth = gapWidth; 148 | invalidate(); 149 | } 150 | 151 | public float getGapWidth() { 152 | return mGapWidth; 153 | } 154 | 155 | @Override 156 | protected void onDraw(Canvas canvas) { 157 | super.onDraw(canvas); 158 | 159 | if (mViewPager == null) { 160 | return; 161 | } 162 | final int count = mViewPager.getAdapter().getCount(); 163 | if (count == 0) { 164 | return; 165 | } 166 | 167 | if (mCurrentPage >= count) { 168 | setCurrentItem(count - 1); 169 | return; 170 | } 171 | 172 | final float lineWidthAndGap = mLineWidth + mGapWidth; 173 | final float indicatorWidth = (count * lineWidthAndGap) - mGapWidth; 174 | final float paddingTop = getPaddingTop(); 175 | final float paddingLeft = getPaddingLeft(); 176 | final float paddingRight = getPaddingRight(); 177 | 178 | float verticalOffset = paddingTop + ((getHeight() - paddingTop - getPaddingBottom()) / 2.0f); 179 | float horizontalOffset = paddingLeft; 180 | if (mCentered) { 181 | horizontalOffset += ((getWidth() - paddingLeft - paddingRight) / 2.0f) - (indicatorWidth / 2.0f); 182 | } 183 | 184 | //Draw stroked circles 185 | for (int i = 0; i < count; i++) { 186 | float dx1 = horizontalOffset + (i * lineWidthAndGap); 187 | float dx2 = dx1 + mLineWidth; 188 | canvas.drawLine(dx1, verticalOffset, dx2, verticalOffset, (i == mCurrentPage) ? mPaintSelected : mPaintUnselected); 189 | } 190 | } 191 | 192 | public boolean onTouchEvent(MotionEvent ev) { 193 | if (super.onTouchEvent(ev)) { 194 | return true; 195 | } 196 | if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { 197 | return false; 198 | } 199 | 200 | final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; 201 | switch (action) { 202 | case MotionEvent.ACTION_DOWN: 203 | mActivePointerId = MotionEventCompat.getPointerId(ev, 0); 204 | mLastMotionX = ev.getX(); 205 | break; 206 | 207 | case MotionEvent.ACTION_MOVE: { 208 | final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); 209 | final float x = MotionEventCompat.getX(ev, activePointerIndex); 210 | final float deltaX = x - mLastMotionX; 211 | 212 | if (!mIsDragging) { 213 | if (Math.abs(deltaX) > mTouchSlop) { 214 | mIsDragging = true; 215 | } 216 | } 217 | 218 | if (mIsDragging) { 219 | mLastMotionX = x; 220 | if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { 221 | mViewPager.fakeDragBy(deltaX); 222 | } 223 | } 224 | 225 | break; 226 | } 227 | 228 | case MotionEvent.ACTION_CANCEL: 229 | case MotionEvent.ACTION_UP: 230 | if (!mIsDragging) { 231 | final int count = mViewPager.getAdapter().getCount(); 232 | final int width = getWidth(); 233 | final float halfWidth = width / 2f; 234 | final float sixthWidth = width / 6f; 235 | 236 | if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { 237 | if (action != MotionEvent.ACTION_CANCEL) { 238 | mViewPager.setCurrentItem(mCurrentPage - 1); 239 | } 240 | return true; 241 | } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { 242 | if (action != MotionEvent.ACTION_CANCEL) { 243 | mViewPager.setCurrentItem(mCurrentPage + 1); 244 | } 245 | return true; 246 | } 247 | } 248 | 249 | mIsDragging = false; 250 | mActivePointerId = INVALID_POINTER; 251 | if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); 252 | break; 253 | 254 | case MotionEventCompat.ACTION_POINTER_DOWN: { 255 | final int index = MotionEventCompat.getActionIndex(ev); 256 | mLastMotionX = MotionEventCompat.getX(ev, index); 257 | mActivePointerId = MotionEventCompat.getPointerId(ev, index); 258 | break; 259 | } 260 | 261 | case MotionEventCompat.ACTION_POINTER_UP: 262 | final int pointerIndex = MotionEventCompat.getActionIndex(ev); 263 | final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); 264 | if (pointerId == mActivePointerId) { 265 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; 266 | mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); 267 | } 268 | mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); 269 | break; 270 | } 271 | 272 | return true; 273 | } 274 | 275 | @Override 276 | public void setViewPager(ViewPager viewPager) { 277 | if (mViewPager == viewPager) { 278 | return; 279 | } 280 | if (mViewPager != null) { 281 | //Clear us from the old pager. 282 | mViewPager.setOnPageChangeListener(null); 283 | } 284 | if (viewPager.getAdapter() == null) { 285 | throw new IllegalStateException("ViewPager does not have adapter instance."); 286 | } 287 | mViewPager = viewPager; 288 | mViewPager.setOnPageChangeListener(this); 289 | invalidate(); 290 | } 291 | 292 | @Override 293 | public void setViewPager(ViewPager view, int initialPosition) { 294 | setViewPager(view); 295 | setCurrentItem(initialPosition); 296 | } 297 | 298 | @Override 299 | public void setCurrentItem(int item) { 300 | if (mViewPager == null) { 301 | throw new IllegalStateException("ViewPager has not been bound."); 302 | } 303 | mViewPager.setCurrentItem(item); 304 | mCurrentPage = item; 305 | invalidate(); 306 | } 307 | 308 | @Override 309 | public void notifyDataSetChanged() { 310 | invalidate(); 311 | } 312 | 313 | @Override 314 | public void onPageScrollStateChanged(int state) { 315 | if (mListener != null) { 316 | mListener.onPageScrollStateChanged(state); 317 | } 318 | } 319 | 320 | @Override 321 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 322 | if (mListener != null) { 323 | mListener.onPageScrolled(position, positionOffset, positionOffsetPixels); 324 | } 325 | } 326 | 327 | @Override 328 | public void onPageSelected(int position) { 329 | mCurrentPage = position; 330 | invalidate(); 331 | 332 | if (mListener != null) { 333 | mListener.onPageSelected(position); 334 | } 335 | } 336 | 337 | @Override 338 | public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) { 339 | mListener = listener; 340 | } 341 | 342 | @Override 343 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 344 | setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec)); 345 | } 346 | 347 | /** 348 | * Determines the width of this view 349 | * 350 | * @param measureSpec 351 | * A measureSpec packed into an int 352 | * @return The width of the view, honoring constraints from measureSpec 353 | */ 354 | private int measureWidth(int measureSpec) { 355 | float result; 356 | int specMode = MeasureSpec.getMode(measureSpec); 357 | int specSize = MeasureSpec.getSize(measureSpec); 358 | 359 | if ((specMode == MeasureSpec.EXACTLY) || (mViewPager == null)) { 360 | //We were told how big to be 361 | result = specSize; 362 | } else { 363 | //Calculate the width according the views count 364 | final int count = mViewPager.getAdapter().getCount(); 365 | result = getPaddingLeft() + getPaddingRight() + (count * mLineWidth) + ((count - 1) * mGapWidth); 366 | //Respect AT_MOST value if that was what is called for by measureSpec 367 | if (specMode == MeasureSpec.AT_MOST) { 368 | result = Math.min(result, specSize); 369 | } 370 | } 371 | return (int)Math.ceil(result); 372 | } 373 | 374 | /** 375 | * Determines the height of this view 376 | * 377 | * @param measureSpec 378 | * A measureSpec packed into an int 379 | * @return The height of the view, honoring constraints from measureSpec 380 | */ 381 | private int measureHeight(int measureSpec) { 382 | float result; 383 | int specMode = MeasureSpec.getMode(measureSpec); 384 | int specSize = MeasureSpec.getSize(measureSpec); 385 | 386 | if (specMode == MeasureSpec.EXACTLY) { 387 | //We were told how big to be 388 | result = specSize; 389 | } else { 390 | //Measure the height 391 | result = mPaintSelected.getStrokeWidth() + getPaddingTop() + getPaddingBottom(); 392 | //Respect AT_MOST value if that was what is called for by measureSpec 393 | if (specMode == MeasureSpec.AT_MOST) { 394 | result = Math.min(result, specSize); 395 | } 396 | } 397 | return (int)Math.ceil(result); 398 | } 399 | 400 | @Override 401 | public void onRestoreInstanceState(Parcelable state) { 402 | SavedState savedState = (SavedState)state; 403 | super.onRestoreInstanceState(savedState.getSuperState()); 404 | mCurrentPage = savedState.currentPage; 405 | requestLayout(); 406 | } 407 | 408 | @Override 409 | public Parcelable onSaveInstanceState() { 410 | Parcelable superState = super.onSaveInstanceState(); 411 | SavedState savedState = new SavedState(superState); 412 | savedState.currentPage = mCurrentPage; 413 | return savedState; 414 | } 415 | 416 | static class SavedState extends BaseSavedState { 417 | int currentPage; 418 | 419 | public SavedState(Parcelable superState) { 420 | super(superState); 421 | } 422 | 423 | private SavedState(Parcel in) { 424 | super(in); 425 | currentPage = in.readInt(); 426 | } 427 | 428 | @Override 429 | public void writeToParcel(Parcel dest, int flags) { 430 | super.writeToParcel(dest, flags); 431 | dest.writeInt(currentPage); 432 | } 433 | 434 | @SuppressWarnings("UnusedDeclaration") 435 | public static final Creator CREATOR = new Creator() { 436 | @Override 437 | public SavedState createFromParcel(Parcel in) { 438 | return new SavedState(in); 439 | } 440 | 441 | @Override 442 | public SavedState[] newArray(int size) { 443 | return new SavedState[size]; 444 | } 445 | }; 446 | } 447 | } --------------------------------------------------------------------------------