├── .gitignore ├── CHANGELOG.md ├── README.md ├── checkstyle.xml ├── library ├── AndroidManifest.xml ├── libs │ └── android-support-v4.jar ├── pom.xml ├── project.properties ├── res │ ├── color │ │ ├── vpi__dark_theme.xml │ │ └── vpi__light_theme.xml │ ├── drawable-hdpi │ │ ├── vpi__tab_selected_focused_holo.9.png │ │ ├── vpi__tab_selected_holo.9.png │ │ ├── vpi__tab_selected_pressed_holo.9.png │ │ ├── vpi__tab_unselected_focused_holo.9.png │ │ ├── vpi__tab_unselected_holo.9.png │ │ └── vpi__tab_unselected_pressed_holo.9.png │ ├── drawable-mdpi │ │ ├── vpi__tab_selected_focused_holo.9.png │ │ ├── vpi__tab_selected_holo.9.png │ │ ├── vpi__tab_selected_pressed_holo.9.png │ │ ├── vpi__tab_unselected_focused_holo.9.png │ │ ├── vpi__tab_unselected_holo.9.png │ │ └── vpi__tab_unselected_pressed_holo.9.png │ ├── drawable-xhdpi │ │ ├── vpi__tab_selected_focused_holo.9.png │ │ ├── vpi__tab_selected_holo.9.png │ │ ├── vpi__tab_selected_pressed_holo.9.png │ │ ├── vpi__tab_unselected_focused_holo.9.png │ │ ├── vpi__tab_unselected_holo.9.png │ │ └── vpi__tab_unselected_pressed_holo.9.png │ ├── drawable │ │ └── vpi__tab_indicator.xml │ └── values │ │ ├── vpi__attrs.xml │ │ ├── vpi__colors.xml │ │ ├── vpi__defaults.xml │ │ └── vpi__styles.xml └── src │ └── com │ └── viewpagerindicator │ ├── CirclePageIndicator.java │ ├── IconPageIndicator.java │ ├── IconPagerAdapter.java │ ├── IcsLinearLayout.java │ ├── LinePageIndicator.java │ ├── PageIndicator.java │ ├── TabPageIndicator.java │ ├── TitlePageIndicator.java │ └── UnderlinePageIndicator.java ├── pom.xml └── sample ├── AndroidManifest.xml ├── libs └── android-support-v4.jar ├── logo.png ├── pom.xml ├── project.properties ├── psd ├── icon_hdpi.psd ├── icon_mdpi.psd ├── icon_xhdpi.psd ├── logo.psd └── web.psd ├── res ├── drawable-hdpi │ ├── custom_tab_indicator_divider.9.png │ ├── custom_tab_indicator_focused.9.png │ ├── custom_tab_indicator_selected.9.png │ ├── custom_tab_indicator_selected_pressed.9.png │ ├── custom_tab_indicator_unselected.9.png │ ├── custom_tab_indicator_unselected_focused.9.png │ ├── custom_tab_indicator_unselected_pressed.9.png │ ├── icon.png │ ├── perm_group_calendar_normal.png │ ├── perm_group_calendar_selected.png │ ├── perm_group_camera_normal.png │ ├── perm_group_camera_selected.png │ ├── perm_group_device_alarms_normal.png │ ├── perm_group_device_alarms_selected.png │ ├── perm_group_location_normal.png │ └── perm_group_location_selected.png ├── drawable-mdpi │ ├── custom_tab_indicator_divider.9.png │ ├── custom_tab_indicator_selected.9.png │ ├── custom_tab_indicator_selected_focused.9.png │ ├── custom_tab_indicator_selected_pressed.9.png │ ├── custom_tab_indicator_unselected.9.png │ ├── custom_tab_indicator_unselected_focused.9.png │ ├── custom_tab_indicator_unselected_pressed.9.png │ ├── icon.png │ ├── perm_group_calendar_normal.png │ ├── perm_group_calendar_selected.png │ ├── perm_group_camera_normal.png │ ├── perm_group_camera_selected.png │ ├── perm_group_device_alarms_normal.png │ ├── perm_group_device_alarms_selected.png │ ├── perm_group_location_normal.png │ └── perm_group_location_selected.png ├── drawable-xhdpi │ ├── custom_tab_indicator_divider.9.png │ ├── custom_tab_indicator_selected.9.png │ ├── custom_tab_indicator_selected_focused.9.png │ ├── custom_tab_indicator_selected_pressed.9.png │ ├── custom_tab_indicator_unselected.9.png │ ├── custom_tab_indicator_unselected_focused.9.png │ ├── custom_tab_indicator_unselected_pressed.9.png │ ├── icon.png │ ├── perm_group_calendar_normal.png │ ├── perm_group_calendar_selected.png │ ├── perm_group_camera_normal.png │ ├── perm_group_camera_selected.png │ ├── perm_group_device_alarms_normal.png │ ├── perm_group_device_alarms_selected.png │ ├── perm_group_location_normal.png │ └── perm_group_location_selected.png ├── drawable │ ├── custom_tab_indicator.xml │ ├── perm_group_calendar.xml │ ├── perm_group_camera.xml │ ├── perm_group_device_alarms.xml │ └── perm_group_location.xml ├── layout │ ├── simple_circles.xml │ ├── simple_circles_vertical.xml │ ├── simple_icons.xml │ ├── simple_lines.xml │ ├── simple_tabs.xml │ ├── simple_titles.xml │ ├── simple_titles_bottom.xml │ ├── simple_underlines.xml │ ├── themed_circles.xml │ ├── themed_lines.xml │ ├── themed_titles.xml │ └── themed_underlines.xml ├── menu │ └── menu.xml └── values │ └── styles.xml ├── screens.png ├── src └── com │ └── viewpagerindicator │ └── sample │ ├── BaseSampleActivity.java │ ├── ListSamples.java │ ├── SampleCirclesDefault.java │ ├── SampleCirclesInitialPage.java │ ├── SampleCirclesSnap.java │ ├── SampleCirclesStyledLayout.java │ ├── SampleCirclesStyledMethods.java │ ├── SampleCirclesStyledTheme.java │ ├── SampleCirclesWithListener.java │ ├── SampleIconsDefault.java │ ├── SampleLinesDefault.java │ ├── SampleLinesStyledLayout.java │ ├── SampleLinesStyledMethods.java │ ├── SampleLinesStyledTheme.java │ ├── SampleTabsDefault.java │ ├── SampleTabsStyled.java │ ├── SampleTabsWithIcons.java │ ├── SampleTitlesBottom.java │ ├── SampleTitlesCenterClickListener.java │ ├── SampleTitlesDefault.java │ ├── SampleTitlesInitialPage.java │ ├── SampleTitlesStyledLayout.java │ ├── SampleTitlesStyledMethods.java │ ├── SampleTitlesStyledTheme.java │ ├── SampleTitlesTriangle.java │ ├── SampleTitlesWithListener.java │ ├── SampleUnderlinesDefault.java │ ├── SampleUnderlinesNoFade.java │ ├── SampleUnderlinesStyledLayout.java │ ├── SampleUnderlinesStyledMethods.java │ ├── SampleUnderlinesStyledTheme.java │ ├── TestFragment.java │ └── TestFragmentAdapter.java └── web.png /.gitignore: -------------------------------------------------------------------------------- 1 | #Android generated 2 | bin 3 | gen 4 | 5 | #Eclipse 6 | .project 7 | .classpath 8 | .settings 9 | 10 | #IntelliJ IDEA 11 | .idea 12 | *.iml 13 | classes 14 | 15 | #Maven 16 | target 17 | release.properties 18 | pom.xml.* 19 | 20 | #Command line 21 | local.properties 22 | build.xml 23 | proguard-project.txt 24 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | 4 | Version 2.4.1 *(2012-09-11)* 5 | ---------------------------- 6 | 7 | * Fix: `TitlePageIndicator`, `LinePageIndicator`, and `UnderlinePageIndicator` 8 | support of `android:background`. 9 | 10 | 11 | Version 2.4.0 *(2012-09-06)* 12 | ---------------------------- 13 | 14 | * New `IconPageIndicator`! Uses state-list images to represent pages. 15 | * `TabPageIndicator` now supports icons via `IconPagerAdapter` interface. 16 | * Support `android:background` attribute on `Canvas`-based views. 17 | * Title indicator allows for drawing its line, underline, and/or triangle on 18 | top of the titles for placement underneath a `ViewPager`. 19 | * Tab indicator now supports ICS-style dividers (see styled sample). 20 | * Fix: Do not attempt to change the `ViewPager` page when a motion is 21 | cancelled. 22 | * Fix: Long titles no longer overlap when swiping to the right. 23 | 24 | 25 | Version 2.3.1 *(2012-05-19)* 26 | ---------------------------- 27 | 28 | * Fix: Corrected filename with erroneous lowercase letter. 29 | 30 | 31 | Version 2.3.0 *(2012-05-19)* 32 | ---------------------------- 33 | 34 | * New `LinePageIndicator`! Draws small indicators lines much like the circle 35 | indicator but much more subtle. 36 | * New `UnderlinePageIndicator`! Acts like the indicator on the Ice Cream 37 | Sandwich application launcher. 38 | * Circle indicator now uses `android:orientation` rather than custom attribute. 39 | * Title indicator adapter callback now uses the standard `getPageTitle(int)` 40 | method introduced in the r6 version of the support library. 41 | * Title indicator now uses `android:textSize` and `android:textColor` in its 42 | styles. 43 | * Fix: Do not create objects in drawing, layout, or measurement steps of each 44 | indicator. 45 | * Fix: Improve offset detection when page margins are in use on the pager. 46 | * Maven: The dependency on the support library is now using an artifact from 47 | central rather than requiring you to deploy your own locally 48 | 49 | 50 | Version 2.2.3 *(2012-01-26)* 51 | ---------------------------- 52 | 53 | * Correctly handle removing the last page when it is selected. 54 | * Use antialiased text for the title indicators. 55 | * New circle fill color for circle indicators. 56 | 57 | 58 | Version 2.2.2 *(2011-12-31)* 59 | ---------------------------- 60 | 61 | * Fix incorrect `R.java` imports in all of the sample activities. 62 | 63 | 64 | Version 2.2.1 *(2011-12-31)* 65 | ---------------------------- 66 | 67 | * New `setTypeface(Typeface)` and `getTypeface()` methods for title indicator. 68 | (Thanks Dimitri Fedorov) 69 | * Added styled tab indicator sample. 70 | * Support for widths other than those that could be measured exactly. 71 | 72 | 73 | Version 2.2.0 *(2011-12-13)* 74 | ---------------------------- 75 | 76 | * Default title indicator style is now 'underline'. 77 | * Title indicator now allows specifying an `OnCenterItemClickListener` which 78 | will give you callbacks when the current item title has been clicked. 79 | (Thanks Chris Banes) 80 | 81 | 82 | Version 2.1.0 *(2011-11-30)* 83 | ---------------------------- 84 | 85 | * Indicators now have a `notifyDataSetChanged` method which should be called 86 | when changes are made to the adapter. 87 | * Fix: Avoid `NullPointerException`s when the `ViewPager` is not immediately 88 | bound to the indicator. 89 | 90 | 91 | Version 2.0.0 *(2011-11-20)* 92 | ---------------------------- 93 | 94 | * New `TabPageIndicator`! Uses the Ice Cream Sandwich-style action bar tabs 95 | which fill the width of the view when there are only a few tabs or provide 96 | horizontal animated scrolling when there are many. 97 | * Update to link against ACLv4r4. This will now be required in all implementing 98 | applications. 99 | * Allow dragging the title and circle indicators to drag the pager. 100 | * Remove orientation example as the DirectionalViewPager library has not been 101 | updated to ACLv4r4. 102 | 103 | 104 | Version 1.2.1 *(2011-10-20)* 105 | ---------------------------- 106 | 107 | Maven 3 is now required when building from the command line. 108 | 109 | * Update to support ADT 14. 110 | 111 | 112 | Version 1.2.0 *(2011-10-04)* 113 | ---------------------------- 114 | 115 | * Move to `com.viewpagerindicator` package. 116 | * Move maven group and artifact to `com.viewpagerindicator:library`. 117 | 118 | 119 | Version 1.1.0 *(2011-10-02)* 120 | ---------------------------- 121 | 122 | * Package changed from `com.jakewharton.android.viewpagerindicator` to 123 | `com.jakewharton.android.view`. 124 | * Add vertical orientation support to the circle indicator. 125 | * Fix: Corrected drawing bug where a single frame would be drawn as if the 126 | pager had completed its scroll when in fact it was still scrolling. 127 | (Thanks SimonVT!) 128 | 129 | 130 | Version 1.0.1 *(2011-09-15)* 131 | ---------------------------- 132 | 133 | * Fade selected title color to normal text color during the swipe to and from 134 | the center position. 135 | * Fix: Ensure both the indicator and footer line are updated when changing the 136 | footer color via the `setFooterColor` method. 137 | 138 | 139 | Version 1.0.0 *(2011-08-07)* 140 | ---------------------------- 141 | 142 | Initial release. 143 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Android ViewPagerIndicator 2 | ========================== 3 | 4 | Paging indicator widgets that are compatible with the `ViewPager` from the 5 | [Android Support Library][2] to improve discoverability of content. 6 | 7 | Try out the sample application [on the Android Market][10]. 8 | 9 | ![ViewPagerIndicator Sample Screenshots][9] 10 | 11 | These widgets can also be used in conjunction with [ActionBarSherlock][3]! 12 | 13 | 14 | 15 | Usage 16 | ===== 17 | 18 | *For a working implementation of this project see the `sample/` folder.* 19 | 20 | 1. Include one of the widgets in your view. This should usually be placed 21 | adjacent to the `ViewPager` it represents. 22 | 23 | 27 | 28 | 2. In your `onCreate` method (or `onCreateView` for a fragment), bind the 29 | indicator to the `ViewPager`. 30 | 31 | //Set the pager with an adapter 32 | ViewPager pager = (ViewPager)findViewById(R.id.pager); 33 | pager.setAdapter(new TestAdapter(getSupportFragmentManager())); 34 | 35 | //Bind the title indicator to the adapter 36 | TitlePageIndicator titleIndicator = (TitlePageIndicator)findViewById(R.id.titles); 37 | titleIndicator.setViewPager(pager); 38 | 39 | 3. *(Optional)* If you use an `OnPageChangeListener` with your view pager 40 | you should set it in the indicator rather than on the pager directly. 41 | 42 | //continued from above 43 | titleIndicator.setOnPageChangeListener(mPageChangeListener); 44 | 45 | 46 | Theming 47 | ------- 48 | 49 | There are three ways to style the look of the indicators. 50 | 51 | 1. **Theme XML**. An attribute for each type of indicator is provided in which 52 | you can specify a custom style. 53 | 2. **Layout XML**. Through the use of a custom namespace you can include any 54 | desired styles. 55 | 3. **Object methods**. Both styles have getters and setters for each style 56 | attribute which can be changed at any point. 57 | 58 | Each indicator has a demo which creates the same look using each of these 59 | methods. 60 | 61 | 62 | Including In Your Project 63 | ------------------------- 64 | 65 | Android-ViewPagerIndicator is presented as an [Android library project][7]. A 66 | standalone JAR is not possible due to the theming capabilities offered by the 67 | indicator widgets. 68 | 69 | You can include this project by [referencing it as a library project][8] in 70 | Eclipse or ant. 71 | 72 | If you are a Maven user you can easily include the library by specifying it as 73 | a dependency: 74 | 75 | 76 | com.viewpagerindicator 77 | library 78 | 2.4.1 79 | apklib 80 | 81 | 82 | This project depends on the `ViewPager` class which is available in the 83 | [Android Support Library][2] or [ActionBarSherlock][3]. Details for 84 | including one of those libraries is available on their respecitve web sites. 85 | 86 | 87 | 88 | 89 | Developed By 90 | ============ 91 | 92 | * Jake Wharton - 93 | 94 | 95 | Credits 96 | ------- 97 | 98 | * [Patrik Åkerfeldt][1] - Author of [ViewFlow][4], a precursor to the ViewPager, 99 | which supports paged views and is the original source of both the title 100 | and circle indicators. 101 | * [Francisco Figueiredo Jr.][5] - Idea and [first implementation][6] for 102 | fragment support via ViewPager. 103 | 104 | 105 | 106 | 107 | License 108 | ======= 109 | 110 | Copyright 2012 Jake Wharton 111 | Copyright 2011 Patrik Åkerfeldt 112 | Copyright 2011 Francisco Figueiredo Jr. 113 | 114 | Licensed under the Apache License, Version 2.0 (the "License"); 115 | you may not use this file except in compliance with the License. 116 | You may obtain a copy of the License at 117 | 118 | http://www.apache.org/licenses/LICENSE-2.0 119 | 120 | Unless required by applicable law or agreed to in writing, software 121 | distributed under the License is distributed on an "AS IS" BASIS, 122 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123 | See the License for the specific language governing permissions and 124 | limitations under the License. 125 | 126 | 127 | 128 | 129 | 130 | 131 | [1]: https://github.com/pakerfeldt 132 | [2]: http://developer.android.com/sdk/compatibility-library.html 133 | [3]: http://actionbarsherlock.com 134 | [4]: https://github.com/pakerfeldt/android-viewflow 135 | [5]: https://github.com/franciscojunior 136 | [6]: https://gist.github.com/1122947 137 | [7]: http://developer.android.com/guide/developing/projects/projects-eclipse.html 138 | [8]: http://developer.android.com/guide/developing/projects/projects-eclipse.html#ReferencingLibraryProject 139 | [9]: https://raw.github.com/JakeWharton/Android-ViewPagerIndicator/master/sample/screens.png 140 | [10]: https://play.google.com/store/apps/details?id=com.viewpagerindicator.sample 141 | -------------------------------------------------------------------------------- /checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /library/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /library/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/libs/android-support-v4.jar -------------------------------------------------------------------------------- /library/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | library 7 | Android-ViewPagerIndicator 8 | apklib 9 | 10 | 11 | com.viewpagerindicator 12 | parent 13 | 2.4.1 14 | ../pom.xml 15 | 16 | 17 | 18 | 19 | com.google.android 20 | android 21 | provided 22 | 23 | 24 | 25 | com.google.android 26 | support-v4 27 | 28 | 29 | 30 | 31 | src 32 | 33 | 34 | 35 | com.jayway.maven.plugins.android.generation2 36 | android-maven-plugin 37 | true 38 | 39 | 40 | 41 | org.apache.maven.plugins 42 | maven-checkstyle-plugin 43 | 44 | ../checkstyle.xml 45 | 46 | 47 | 48 | verify 49 | 50 | checkstyle 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /library/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | android.library=true 11 | # Project target. 12 | target=android-16 13 | -------------------------------------------------------------------------------- /library/res/color/vpi__dark_theme.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /library/res/color/vpi__light_theme.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /library/res/drawable-hdpi/vpi__tab_selected_focused_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-hdpi/vpi__tab_selected_focused_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-hdpi/vpi__tab_selected_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-hdpi/vpi__tab_selected_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-hdpi/vpi__tab_selected_pressed_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-hdpi/vpi__tab_selected_pressed_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-hdpi/vpi__tab_unselected_focused_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-hdpi/vpi__tab_unselected_focused_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-hdpi/vpi__tab_unselected_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-hdpi/vpi__tab_unselected_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-hdpi/vpi__tab_unselected_pressed_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-hdpi/vpi__tab_unselected_pressed_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-mdpi/vpi__tab_selected_focused_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-mdpi/vpi__tab_selected_focused_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-mdpi/vpi__tab_selected_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-mdpi/vpi__tab_selected_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-mdpi/vpi__tab_selected_pressed_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-mdpi/vpi__tab_selected_pressed_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-mdpi/vpi__tab_unselected_focused_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-mdpi/vpi__tab_unselected_focused_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-mdpi/vpi__tab_unselected_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-mdpi/vpi__tab_unselected_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-mdpi/vpi__tab_unselected_pressed_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-mdpi/vpi__tab_unselected_pressed_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-xhdpi/vpi__tab_selected_focused_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-xhdpi/vpi__tab_selected_focused_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-xhdpi/vpi__tab_selected_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-xhdpi/vpi__tab_selected_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-xhdpi/vpi__tab_selected_pressed_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-xhdpi/vpi__tab_selected_pressed_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-xhdpi/vpi__tab_unselected_focused_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-xhdpi/vpi__tab_unselected_focused_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-xhdpi/vpi__tab_unselected_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-xhdpi/vpi__tab_unselected_holo.9.png -------------------------------------------------------------------------------- /library/res/drawable-xhdpi/vpi__tab_unselected_pressed_holo.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/library/res/drawable-xhdpi/vpi__tab_unselected_pressed_holo.9.png -------------------------------------------------------------------------------- /library/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 | -------------------------------------------------------------------------------- /library/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 | -------------------------------------------------------------------------------- /library/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 | -------------------------------------------------------------------------------- /library/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 | -------------------------------------------------------------------------------- /library/res/values/vpi__styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 22 | 23 | 25 | 26 | 37 | 38 | 42 | 43 | 47 | 48 | -------------------------------------------------------------------------------- /library/src/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 | -------------------------------------------------------------------------------- /library/src/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 | -------------------------------------------------------------------------------- /library/src/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 android.widget.LinearLayout.LayoutParams lp = (android.widget.LinearLayout.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 android.widget.LinearLayout.LayoutParams lp = (android.widget.LinearLayout.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 | -------------------------------------------------------------------------------- /library/src/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.util.FloatMath; 31 | import android.view.MotionEvent; 32 | import android.view.View; 33 | import android.view.ViewConfiguration; 34 | 35 | /** 36 | * Draws a line for each page. The current page line is colored differently 37 | * than the unselected page lines. 38 | */ 39 | public class LinePageIndicator extends View implements PageIndicator { 40 | private static final int INVALID_POINTER = -1; 41 | 42 | private final Paint mPaintUnselected = new Paint(Paint.ANTI_ALIAS_FLAG); 43 | private final Paint mPaintSelected = new Paint(Paint.ANTI_ALIAS_FLAG); 44 | private ViewPager mViewPager; 45 | private ViewPager.OnPageChangeListener mListener; 46 | private int mCurrentPage; 47 | private boolean mCentered; 48 | private float mLineWidth; 49 | private float mGapWidth; 50 | 51 | private int mTouchSlop; 52 | private float mLastMotionX = -1; 53 | private int mActivePointerId = INVALID_POINTER; 54 | private boolean mIsDragging; 55 | 56 | 57 | public LinePageIndicator(Context context) { 58 | this(context, null); 59 | } 60 | 61 | public LinePageIndicator(Context context, AttributeSet attrs) { 62 | this(context, attrs, R.attr.vpiLinePageIndicatorStyle); 63 | } 64 | 65 | public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) { 66 | super(context, attrs, defStyle); 67 | if (isInEditMode()) return; 68 | 69 | final Resources res = getResources(); 70 | 71 | //Load defaults from resources 72 | final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color); 73 | final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color); 74 | final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width); 75 | final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width); 76 | final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width); 77 | final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered); 78 | 79 | //Retrieve styles attributes 80 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0); 81 | 82 | mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered); 83 | mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth); 84 | mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth); 85 | setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth)); 86 | mPaintUnselected.setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor)); 87 | mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor)); 88 | 89 | Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background); 90 | if (background != null) { 91 | setBackgroundDrawable(background); 92 | } 93 | 94 | a.recycle(); 95 | 96 | final ViewConfiguration configuration = ViewConfiguration.get(context); 97 | mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); 98 | } 99 | 100 | 101 | public void setCentered(boolean centered) { 102 | mCentered = centered; 103 | invalidate(); 104 | } 105 | 106 | public boolean isCentered() { 107 | return mCentered; 108 | } 109 | 110 | public void setUnselectedColor(int unselectedColor) { 111 | mPaintUnselected.setColor(unselectedColor); 112 | invalidate(); 113 | } 114 | 115 | public int getUnselectedColor() { 116 | return mPaintUnselected.getColor(); 117 | } 118 | 119 | public void setSelectedColor(int selectedColor) { 120 | mPaintSelected.setColor(selectedColor); 121 | invalidate(); 122 | } 123 | 124 | public int getSelectedColor() { 125 | return mPaintSelected.getColor(); 126 | } 127 | 128 | public void setLineWidth(float lineWidth) { 129 | mLineWidth = lineWidth; 130 | invalidate(); 131 | } 132 | 133 | public float getLineWidth() { 134 | return mLineWidth; 135 | } 136 | 137 | public void setStrokeWidth(float lineHeight) { 138 | mPaintSelected.setStrokeWidth(lineHeight); 139 | mPaintUnselected.setStrokeWidth(lineHeight); 140 | invalidate(); 141 | } 142 | 143 | public float getStrokeWidth() { 144 | return mPaintSelected.getStrokeWidth(); 145 | } 146 | 147 | public void setGapWidth(float gapWidth) { 148 | mGapWidth = gapWidth; 149 | invalidate(); 150 | } 151 | 152 | public float getGapWidth() { 153 | return mGapWidth; 154 | } 155 | 156 | @Override 157 | protected void onDraw(Canvas canvas) { 158 | super.onDraw(canvas); 159 | 160 | if (mViewPager == null) { 161 | return; 162 | } 163 | final int count = mViewPager.getAdapter().getCount(); 164 | if (count == 0) { 165 | return; 166 | } 167 | 168 | if (mCurrentPage >= count) { 169 | setCurrentItem(count - 1); 170 | return; 171 | } 172 | 173 | final float lineWidthAndGap = mLineWidth + mGapWidth; 174 | final float indicatorWidth = (count * lineWidthAndGap) - mGapWidth; 175 | final float paddingTop = getPaddingTop(); 176 | final float paddingLeft = getPaddingLeft(); 177 | final float paddingRight = getPaddingRight(); 178 | 179 | float verticalOffset = paddingTop + ((getHeight() - paddingTop - getPaddingBottom()) / 2.0f); 180 | float horizontalOffset = paddingLeft; 181 | if (mCentered) { 182 | horizontalOffset += ((getWidth() - paddingLeft - paddingRight) / 2.0f) - (indicatorWidth / 2.0f); 183 | } 184 | 185 | //Draw stroked circles 186 | for (int i = 0; i < count; i++) { 187 | float dx1 = horizontalOffset + (i * lineWidthAndGap); 188 | float dx2 = dx1 + mLineWidth; 189 | canvas.drawLine(dx1, verticalOffset, dx2, verticalOffset, (i == mCurrentPage) ? mPaintSelected : mPaintUnselected); 190 | } 191 | } 192 | 193 | public boolean onTouchEvent(android.view.MotionEvent ev) { 194 | if (super.onTouchEvent(ev)) { 195 | return true; 196 | } 197 | if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { 198 | return false; 199 | } 200 | 201 | final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; 202 | switch (action) { 203 | case MotionEvent.ACTION_DOWN: 204 | mActivePointerId = MotionEventCompat.getPointerId(ev, 0); 205 | mLastMotionX = ev.getX(); 206 | break; 207 | 208 | case MotionEvent.ACTION_MOVE: { 209 | final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); 210 | final float x = MotionEventCompat.getX(ev, activePointerIndex); 211 | final float deltaX = x - mLastMotionX; 212 | 213 | if (!mIsDragging) { 214 | if (Math.abs(deltaX) > mTouchSlop) { 215 | mIsDragging = true; 216 | } 217 | } 218 | 219 | if (mIsDragging) { 220 | mLastMotionX = x; 221 | if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) { 222 | mViewPager.fakeDragBy(deltaX); 223 | } 224 | } 225 | 226 | break; 227 | } 228 | 229 | case MotionEvent.ACTION_CANCEL: 230 | case MotionEvent.ACTION_UP: 231 | if (!mIsDragging) { 232 | final int count = mViewPager.getAdapter().getCount(); 233 | final int width = getWidth(); 234 | final float halfWidth = width / 2f; 235 | final float sixthWidth = width / 6f; 236 | 237 | if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) { 238 | if (action != MotionEvent.ACTION_CANCEL) { 239 | mViewPager.setCurrentItem(mCurrentPage - 1); 240 | } 241 | return true; 242 | } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) { 243 | if (action != MotionEvent.ACTION_CANCEL) { 244 | mViewPager.setCurrentItem(mCurrentPage + 1); 245 | } 246 | return true; 247 | } 248 | } 249 | 250 | mIsDragging = false; 251 | mActivePointerId = INVALID_POINTER; 252 | if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); 253 | break; 254 | 255 | case MotionEventCompat.ACTION_POINTER_DOWN: { 256 | final int index = MotionEventCompat.getActionIndex(ev); 257 | mLastMotionX = MotionEventCompat.getX(ev, index); 258 | mActivePointerId = MotionEventCompat.getPointerId(ev, index); 259 | break; 260 | } 261 | 262 | case MotionEventCompat.ACTION_POINTER_UP: 263 | final int pointerIndex = MotionEventCompat.getActionIndex(ev); 264 | final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); 265 | if (pointerId == mActivePointerId) { 266 | final int newPointerIndex = pointerIndex == 0 ? 1 : 0; 267 | mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); 268 | } 269 | mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); 270 | break; 271 | } 272 | 273 | return true; 274 | } 275 | 276 | @Override 277 | public void setViewPager(ViewPager viewPager) { 278 | if (mViewPager == viewPager) { 279 | return; 280 | } 281 | if (mViewPager != null) { 282 | //Clear us from the old pager. 283 | mViewPager.setOnPageChangeListener(null); 284 | } 285 | if (viewPager.getAdapter() == null) { 286 | throw new IllegalStateException("ViewPager does not have adapter instance."); 287 | } 288 | mViewPager = viewPager; 289 | mViewPager.setOnPageChangeListener(this); 290 | invalidate(); 291 | } 292 | 293 | @Override 294 | public void setViewPager(ViewPager view, int initialPosition) { 295 | setViewPager(view); 296 | setCurrentItem(initialPosition); 297 | } 298 | 299 | @Override 300 | public void setCurrentItem(int item) { 301 | if (mViewPager == null) { 302 | throw new IllegalStateException("ViewPager has not been bound."); 303 | } 304 | mViewPager.setCurrentItem(item); 305 | mCurrentPage = item; 306 | invalidate(); 307 | } 308 | 309 | @Override 310 | public void notifyDataSetChanged() { 311 | invalidate(); 312 | } 313 | 314 | @Override 315 | public void onPageScrollStateChanged(int state) { 316 | if (mListener != null) { 317 | mListener.onPageScrollStateChanged(state); 318 | } 319 | } 320 | 321 | @Override 322 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 323 | if (mListener != null) { 324 | mListener.onPageScrolled(position, positionOffset, positionOffsetPixels); 325 | } 326 | } 327 | 328 | @Override 329 | public void onPageSelected(int position) { 330 | mCurrentPage = position; 331 | invalidate(); 332 | 333 | if (mListener != null) { 334 | mListener.onPageSelected(position); 335 | } 336 | } 337 | 338 | @Override 339 | public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) { 340 | mListener = listener; 341 | } 342 | 343 | @Override 344 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 345 | setMeasuredDimension(measureWidth(widthMeasureSpec), measureHeight(heightMeasureSpec)); 346 | } 347 | 348 | /** 349 | * Determines the width of this view 350 | * 351 | * @param measureSpec 352 | * A measureSpec packed into an int 353 | * @return The width of the view, honoring constraints from measureSpec 354 | */ 355 | private int measureWidth(int measureSpec) { 356 | float result; 357 | int specMode = MeasureSpec.getMode(measureSpec); 358 | int specSize = MeasureSpec.getSize(measureSpec); 359 | 360 | if ((specMode == MeasureSpec.EXACTLY) || (mViewPager == null)) { 361 | //We were told how big to be 362 | result = specSize; 363 | } else { 364 | //Calculate the width according the views count 365 | final int count = mViewPager.getAdapter().getCount(); 366 | result = getPaddingLeft() + getPaddingRight() + (count * mLineWidth) + ((count - 1) * mGapWidth); 367 | //Respect AT_MOST value if that was what is called for by measureSpec 368 | if (specMode == MeasureSpec.AT_MOST) { 369 | result = Math.min(result, specSize); 370 | } 371 | } 372 | return (int)FloatMath.ceil(result); 373 | } 374 | 375 | /** 376 | * Determines the height of this view 377 | * 378 | * @param measureSpec 379 | * A measureSpec packed into an int 380 | * @return The height of the view, honoring constraints from measureSpec 381 | */ 382 | private int measureHeight(int measureSpec) { 383 | float result; 384 | int specMode = MeasureSpec.getMode(measureSpec); 385 | int specSize = MeasureSpec.getSize(measureSpec); 386 | 387 | if (specMode == MeasureSpec.EXACTLY) { 388 | //We were told how big to be 389 | result = specSize; 390 | } else { 391 | //Measure the height 392 | result = mPaintSelected.getStrokeWidth() + getPaddingTop() + getPaddingBottom(); 393 | //Respect AT_MOST value if that was what is called for by measureSpec 394 | if (specMode == MeasureSpec.AT_MOST) { 395 | result = Math.min(result, specSize); 396 | } 397 | } 398 | return (int)FloatMath.ceil(result); 399 | } 400 | 401 | @Override 402 | public void onRestoreInstanceState(Parcelable state) { 403 | SavedState savedState = (SavedState)state; 404 | super.onRestoreInstanceState(savedState.getSuperState()); 405 | mCurrentPage = savedState.currentPage; 406 | requestLayout(); 407 | } 408 | 409 | @Override 410 | public Parcelable onSaveInstanceState() { 411 | Parcelable superState = super.onSaveInstanceState(); 412 | SavedState savedState = new SavedState(superState); 413 | savedState.currentPage = mCurrentPage; 414 | return savedState; 415 | } 416 | 417 | static class SavedState extends BaseSavedState { 418 | int currentPage; 419 | 420 | public SavedState(Parcelable superState) { 421 | super(superState); 422 | } 423 | 424 | private SavedState(Parcel in) { 425 | super(in); 426 | currentPage = in.readInt(); 427 | } 428 | 429 | @Override 430 | public void writeToParcel(Parcel dest, int flags) { 431 | super.writeToParcel(dest, flags); 432 | dest.writeInt(currentPage); 433 | } 434 | 435 | @SuppressWarnings("UnusedDeclaration") 436 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 437 | @Override 438 | public SavedState createFromParcel(Parcel in) { 439 | return new SavedState(in); 440 | } 441 | 442 | @Override 443 | public SavedState[] newArray(int size) { 444 | return new SavedState[size]; 445 | } 446 | }; 447 | } 448 | } -------------------------------------------------------------------------------- /library/src/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 | -------------------------------------------------------------------------------- /library/src/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 ViewPager.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 | -------------------------------------------------------------------------------- /library/src/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 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 7 | org.sonatype.oss 8 | oss-parent 9 | 7 10 | 11 | 12 | com.viewpagerindicator 13 | parent 14 | pom 15 | 2.4.1 16 | 17 | Android-ViewPagerIndicator (Parent) 18 | Android library for. 19 | https://github.com/JakeWharton/Android-ViewPagerIndicator 20 | 2011 21 | 22 | 23 | library 24 | sample 25 | 26 | 27 | 28 | http://github.com/JakeWharton/Android-ViewPagerIndicator/ 29 | scm:git:git://github.com/JakeWharton/Android-ViewPagerIndicator.git 30 | scm:git:git@github.com:JakeWharton/Android-ViewPagerIndicator.git 31 | 32 | 33 | 34 | 35 | Jake Wharton 36 | jakewharton@gmail.com 37 | jakewharton 38 | http://jakewharton.com 39 | -5 40 | 41 | developer 42 | 43 | 44 | 45 | 46 | 47 | 48 | Apache License Version 2.0 49 | http://www.apache.org/licenses/LICENSE-2.0.txt 50 | repo 51 | 52 | 53 | 54 | 55 | Jake Wharton 56 | http://jakewharton.com 57 | 58 | 59 | 60 | GitHub Issues 61 | https://github.com/JakeWharton/Android-ViewPagerIndicator/issues 62 | 63 | 64 | 65 | UTF-8 66 | UTF-8 67 | 68 | 1.6 69 | 4.1.1.4 70 | 16 71 | r7 72 | 73 | 3.3.0 74 | 75 | 76 | 77 | 78 | 79 | com.google.android 80 | android 81 | ${android.version} 82 | 83 | 84 | 85 | com.google.android 86 | support-v4 87 | ${android.support.version} 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-compiler-plugin 98 | 2.3.2 99 | 100 | ${java.version} 101 | ${java.version} 102 | 103 | 104 | 105 | 106 | com.jayway.maven.plugins.android.generation2 107 | android-maven-plugin 108 | ${android-maven.version} 109 | 110 | 111 | ${android.platform} 112 | 113 | true 114 | 115 | true 116 | 117 | 118 | 119 | org.apache.maven.plugins 120 | maven-checkstyle-plugin 121 | 2.6 122 | 123 | true 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | org.apache.maven.plugins 132 | maven-release-plugin 133 | 2.1 134 | 135 | true 136 | 137 | 138 | 139 | 140 | org.apache.maven.plugins 141 | maven-eclipse-plugin 142 | 2.9 143 | 144 | 145 | android:android 146 | com.google.android.maps:maps 147 | 148 | bin 149 | 150 | com.android.ide.eclipse.adt.ANDROID_FRAMEWORK 151 | 152 | 153 | com.android.ide.eclipse.adt.AndroidNature 154 | org.eclipse.ajdt.ui.ajnature 155 | 156 | 157 | com.android.ide.eclipse.adt.ResourceManagerBuilder 158 | com.android.ide.eclipse.adt.PreCompilerBuilder 159 | org.eclipse.jdt.core.javabuilder 160 | com.android.ide.eclipse.adt.ApkBuilder 161 | 162 | false 163 | 164 | 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /sample/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 14 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 39 | 40 | 41 | 42 | 43 | 44 | 47 | 48 | 49 | 50 | 51 | 52 | 56 | 57 | 58 | 59 | 60 | 61 | 65 | 66 | 67 | 68 | 69 | 70 | 74 | 75 | 76 | 77 | 78 | 79 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 107 | 108 | 109 | 110 | 111 | 112 | 116 | 117 | 118 | 119 | 120 | 121 | 125 | 126 | 127 | 128 | 129 | 130 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 146 | 147 | 148 | 149 | 150 | 151 | 154 | 155 | 156 | 157 | 158 | 159 | 162 | 163 | 164 | 165 | 166 | 167 | 170 | 171 | 172 | 173 | 174 | 175 | 179 | 180 | 181 | 182 | 183 | 184 | 188 | 189 | 190 | 191 | 192 | 193 | 197 | 198 | 199 | 200 | 201 | 202 | 205 | 206 | 207 | 208 | 209 | 210 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 226 | 227 | 228 | 229 | 230 | 231 | 235 | 236 | 237 | 238 | 239 | 240 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 256 | 257 | 258 | 259 | 260 | 261 | 264 | 265 | 266 | 267 | 268 | 269 | 273 | 274 | 275 | 276 | 277 | 278 | 282 | 283 | 284 | 285 | 286 | 287 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | -------------------------------------------------------------------------------- /sample/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/libs/android-support-v4.jar -------------------------------------------------------------------------------- /sample/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/logo.png -------------------------------------------------------------------------------- /sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | sample 7 | Android-ViewPagerIndicator Sample 8 | apk 9 | 10 | 11 | com.viewpagerindicator 12 | parent 13 | 2.4.1 14 | ../pom.xml 15 | 16 | 17 | 18 | 19 | com.google.android 20 | android 21 | provided 22 | 23 | 24 | 25 | com.google.android 26 | support-v4 27 | 28 | 29 | 30 | com.viewpagerindicator 31 | library 32 | ${project.version} 33 | apklib 34 | 35 | 36 | 37 | 38 | src 39 | ${project.artifactId}-unaligned 40 | 41 | 42 | 43 | com.jayway.maven.plugins.android.generation2 44 | android-maven-plugin 45 | true 46 | 47 | 48 | 49 | org.apache.maven.plugins 50 | maven-checkstyle-plugin 51 | 52 | ../checkstyle.xml 53 | 54 | 55 | 56 | verify 57 | 58 | checkstyle 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | release 69 | 70 | 71 | performRelease 72 | true 73 | 74 | 75 | 76 | 77 | 78 | com.jayway.maven.plugins.android.generation2 79 | android-maven-plugin 80 | ${android-maven.version} 81 | true 82 | 83 | 84 | ${project.build.directory}/${project.build.finalName}.apk 85 | ${project.build.directory}/${project.artifactId}.apk 86 | 87 | 88 | 89 | 90 | alignApk 91 | package 92 | 93 | zipalign 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /sample/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-16 12 | android.library.reference.1=../library 13 | -------------------------------------------------------------------------------- /sample/psd/icon_hdpi.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/psd/icon_hdpi.psd -------------------------------------------------------------------------------- /sample/psd/icon_mdpi.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/psd/icon_mdpi.psd -------------------------------------------------------------------------------- /sample/psd/icon_xhdpi.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/psd/icon_xhdpi.psd -------------------------------------------------------------------------------- /sample/psd/logo.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/psd/logo.psd -------------------------------------------------------------------------------- /sample/psd/web.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/psd/web.psd -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/custom_tab_indicator_divider.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/custom_tab_indicator_divider.9.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/custom_tab_indicator_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/custom_tab_indicator_focused.9.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/custom_tab_indicator_selected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/custom_tab_indicator_selected.9.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/custom_tab_indicator_selected_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/custom_tab_indicator_selected_pressed.9.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/custom_tab_indicator_unselected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/custom_tab_indicator_unselected.9.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/custom_tab_indicator_unselected_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/custom_tab_indicator_unselected_focused.9.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/custom_tab_indicator_unselected_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/custom_tab_indicator_unselected_pressed.9.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/perm_group_calendar_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/perm_group_calendar_normal.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/perm_group_calendar_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/perm_group_calendar_selected.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/perm_group_camera_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/perm_group_camera_normal.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/perm_group_camera_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/perm_group_camera_selected.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/perm_group_device_alarms_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/perm_group_device_alarms_normal.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/perm_group_device_alarms_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/perm_group_device_alarms_selected.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/perm_group_location_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/perm_group_location_normal.png -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/perm_group_location_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-hdpi/perm_group_location_selected.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/custom_tab_indicator_divider.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/custom_tab_indicator_divider.9.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/custom_tab_indicator_selected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/custom_tab_indicator_selected.9.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/custom_tab_indicator_selected_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/custom_tab_indicator_selected_focused.9.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/custom_tab_indicator_selected_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/custom_tab_indicator_selected_pressed.9.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/custom_tab_indicator_unselected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/custom_tab_indicator_unselected.9.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/custom_tab_indicator_unselected_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/custom_tab_indicator_unselected_focused.9.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/custom_tab_indicator_unselected_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/custom_tab_indicator_unselected_pressed.9.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/icon.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/perm_group_calendar_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/perm_group_calendar_normal.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/perm_group_calendar_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/perm_group_calendar_selected.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/perm_group_camera_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/perm_group_camera_normal.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/perm_group_camera_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/perm_group_camera_selected.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/perm_group_device_alarms_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/perm_group_device_alarms_normal.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/perm_group_device_alarms_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/perm_group_device_alarms_selected.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/perm_group_location_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/perm_group_location_normal.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/perm_group_location_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-mdpi/perm_group_location_selected.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/custom_tab_indicator_divider.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/custom_tab_indicator_divider.9.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/custom_tab_indicator_selected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/custom_tab_indicator_selected.9.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/custom_tab_indicator_selected_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/custom_tab_indicator_selected_focused.9.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/custom_tab_indicator_selected_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/custom_tab_indicator_selected_pressed.9.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/custom_tab_indicator_unselected.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/custom_tab_indicator_unselected.9.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/custom_tab_indicator_unselected_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/custom_tab_indicator_unselected_focused.9.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/custom_tab_indicator_unselected_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/custom_tab_indicator_unselected_pressed.9.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/perm_group_calendar_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/perm_group_calendar_normal.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/perm_group_calendar_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/perm_group_calendar_selected.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/perm_group_camera_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/perm_group_camera_normal.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/perm_group_camera_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/perm_group_camera_selected.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/perm_group_device_alarms_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/perm_group_device_alarms_normal.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/perm_group_device_alarms_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/perm_group_device_alarms_selected.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/perm_group_location_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/perm_group_location_normal.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/perm_group_location_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/res/drawable-xhdpi/perm_group_location_selected.png -------------------------------------------------------------------------------- /sample/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 | -------------------------------------------------------------------------------- /sample/res/drawable/perm_group_calendar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/res/drawable/perm_group_camera.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/res/drawable/perm_group_device_alarms.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/res/drawable/perm_group_location.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /sample/res/layout/simple_circles.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 29 | 35 | -------------------------------------------------------------------------------- /sample/res/layout/simple_circles_vertical.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 29 | 35 | -------------------------------------------------------------------------------- /sample/res/layout/simple_icons.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 29 | 34 | 35 | -------------------------------------------------------------------------------- /sample/res/layout/simple_lines.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 29 | 35 | -------------------------------------------------------------------------------- /sample/res/layout/simple_tabs.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /sample/res/layout/simple_titles.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 29 | 35 | 36 | -------------------------------------------------------------------------------- /sample/res/layout/simple_titles_bottom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 23 | 24 | 30 | 37 | 38 | -------------------------------------------------------------------------------- /sample/res/layout/simple_underlines.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 22 | 23 | 29 | 34 | -------------------------------------------------------------------------------- /sample/res/layout/themed_circles.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 23 | 24 | 30 | 42 | 43 | -------------------------------------------------------------------------------- /sample/res/layout/themed_lines.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 23 | 24 | 30 | 40 | 41 | -------------------------------------------------------------------------------- /sample/res/layout/themed_titles.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 23 | 24 | 38 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /sample/res/layout/themed_underlines.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 23 | 24 | 30 | 39 | 40 | -------------------------------------------------------------------------------- /sample/res/menu/menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /sample/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 25 | 26 | 36 | 37 | 43 | 44 | 51 | 52 | 65 | 66 | 69 | 70 | 76 | 77 | -------------------------------------------------------------------------------- /sample/screens.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/screens.png -------------------------------------------------------------------------------- /sample/src/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 | -------------------------------------------------------------------------------- /sample/src/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 | -------------------------------------------------------------------------------- /sample/src/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 | } -------------------------------------------------------------------------------- /sample/src/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/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/src/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/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/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/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/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/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 | } -------------------------------------------------------------------------------- /sample/src/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 | -------------------------------------------------------------------------------- /sample/src/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/web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ViewPagerIndicator/8cd549f23f3d20ff920e19a2345c54983f65e26b/sample/web.png --------------------------------------------------------------------------------