├── .gitignore ├── CHANGELOG.md ├── LICENSE.txt ├── README.md ├── art ├── google-plus.png ├── linkedin.png ├── readme_pic.png ├── snapshot-0.png ├── snapshot-1.png ├── snapshot-2.png ├── snapshot-framed-0.png ├── snapshot-framed-1.png ├── snapshot-gplay-0.png ├── snapshot-gplay-1.png ├── snapshot-gplay-2.png ├── twitter.png └── web_hi_res_512.png ├── library ├── AndroidManifest.xml ├── libs │ └── android-support-v4.jar ├── pom.xml ├── proguard-project.txt ├── project.properties ├── res │ └── values │ │ ├── npi__attrs.xml │ │ └── npi__defaults.xml └── src │ └── com │ └── manuelpeinado │ └── numericpageindicator │ └── NumericPageIndicator.java ├── pom.xml └── sample ├── AndroidManifest.xml ├── libs └── android-support-v4.jar ├── pom.xml ├── proguard-project.txt ├── project.properties ├── res ├── anim │ ├── scale_fade_in.xml │ └── scale_fade_out.xml ├── drawable-hdpi │ └── ic_launcher.png ├── drawable-mdpi │ └── ic_launcher.png ├── drawable-xhdpi │ └── ic_launcher.png ├── drawable-xxhdpi │ └── ic_launcher.png ├── layout │ ├── activity_home.xml │ ├── activity_main.xml │ └── activity_styling_in_layout.xml ├── values-land │ └── bools.xml └── values │ ├── bools.xml │ ├── colors.xml │ ├── strings.xml │ ├── styles.xml │ └── themes.xml └── src └── com └── manuelpeinado └── numericpageindicator └── demo ├── ActivityInfo.java ├── BasicUsageActivity.java ├── ButtonsInLandscapeActivity.java ├── HomeActivity.java ├── MyPagerAdapter.java ├── StylingInLayoutActivity.java ├── StylingInThemeActivity.java └── StylingProgrammaticallyActivity.java /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Eclipse project files 19 | .classpath 20 | .project 21 | 22 | #Maven 23 | target 24 | release.properties 25 | pom.xml.* 26 | 27 | # Folder containing all the Google Play APKs 28 | apks 29 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | 4 | Version 1.1.0 *(2013-06-6)* 5 | --------------------------- 6 | * Don't change button background when pressed if the button is not visible in first or last page. 7 | 8 | Version 1.1.0 *(2013-04-16)* 9 | ---------------------------- 10 | * Added "start" and "end" buttons 11 | * Added new demo "Buttons in landscape mode only" 12 | 13 | 14 | Version 1.0.0 *(2013-04-09)* 15 | ---------------------------- 16 | * Initial release. 17 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NumericPageIndicator 2 | ==================== 3 | 4 | A ViewPager page indicator that displays the current page number and (optionally) the page count. It can also display buttons to go to adjacent pages, and to move to the start and end pages. 5 | 6 | Integrates seamlessly with Jake Wharton's [ViewPagerIndicator][1] library. 7 | 8 | ![Example Image][2] 9 | 10 | Try out the sample application: 11 | 12 | 13 | Android app on Google Play 15 | 16 | 17 | Or browse the [source code of the sample application][3] for a complete example of use. 18 | 19 | 20 | Including in your project 21 | ------------------------- 22 | 23 | If you’re using the Eclipse ADT plugin you can include NumericPageIndicator as a library project. Create a new Android project using the library/ folder as the existing source. Then, open the properties of this new project and, in the 'Android' category, add a reference to the ViewPagerIndicator library project. Finally, in your application project properties, add a reference to the created library project. 24 | 25 | If you use maven to build your Android project you can simply add a dependency for this library. 26 | 27 | ```xml 28 | 29 | com.github.manuelpeinado.numericpageindicator 30 | library 31 | 1.1.1 32 | apklib 33 | 34 | ``` 35 | 36 | Usage 37 | ----- 38 | 39 | Add a element to your XML layout and attach it to your ViewPager in your Java code just like you would with any of the built-in ViewPagerIndicator classes. 40 | 41 | See the accompanying sample application for a complete example. 42 | 43 | Customization 44 | ------------- 45 | 46 | You can customize the look of the indicators in any of the following ways: 47 | 48 | 1. **Theme XML**. Define a numericPageIndicatorStyle attribute in your theme and make it reference a custom style where you can customize any of the multiple attributes supported by the library. 49 | 2. **Layout XML**. Include any of the attributes supported by the library directly in your NumericPageIndicator element. 50 | 3. **Object methods**. Use the getters and setters methods provided by the library from your Java code. 51 | 52 | The sample application includes one activity to illustrate each of these methods. 53 | 54 | Who's using it 55 | -------------- 56 | 57 | *Does your app use NumericPageIndicator? If you want to be featured on this list drop me a line.* 58 | 59 | Developed By 60 | -------------------- 61 | 62 | Manuel Peinado Gallego - 63 | 64 | 65 | Follow me on Twitter 67 | 68 | 69 | Follow me on Twitter 71 | 72 | 73 | Follow me on Twitter 75 | 76 | 77 | License 78 | ------- 79 | 80 | Copyright 2013 Manuel Peinado 81 | 82 | Licensed under the Apache License, Version 2.0 (the "License"); 83 | you may not use this file except in compliance with the License. 84 | You may obtain a copy of the License at 85 | 86 | http://www.apache.org/licenses/LICENSE-2.0 87 | 88 | Unless required by applicable law or agreed to in writing, software 89 | distributed under the License is distributed on an "AS IS" BASIS, 90 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 91 | See the License for the specific language governing permissions and 92 | limitations under the License. 93 | 94 | [1]: http://viewpagerindicator.com 95 | [2]: https://raw.github.com/ManuelPeinado/NumericPageIndicator/master/art/readme_pic.png 96 | [3]: https://github.com/ManuelPeinado/NumericPageIndicator/tree/master/sample 97 | -------------------------------------------------------------------------------- /art/google-plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/google-plus.png -------------------------------------------------------------------------------- /art/linkedin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/linkedin.png -------------------------------------------------------------------------------- /art/readme_pic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/readme_pic.png -------------------------------------------------------------------------------- /art/snapshot-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/snapshot-0.png -------------------------------------------------------------------------------- /art/snapshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/snapshot-1.png -------------------------------------------------------------------------------- /art/snapshot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/snapshot-2.png -------------------------------------------------------------------------------- /art/snapshot-framed-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/snapshot-framed-0.png -------------------------------------------------------------------------------- /art/snapshot-framed-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/snapshot-framed-1.png -------------------------------------------------------------------------------- /art/snapshot-gplay-0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/snapshot-gplay-0.png -------------------------------------------------------------------------------- /art/snapshot-gplay-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/snapshot-gplay-1.png -------------------------------------------------------------------------------- /art/snapshot-gplay-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/snapshot-gplay-2.png -------------------------------------------------------------------------------- /art/twitter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/twitter.png -------------------------------------------------------------------------------- /art/web_hi_res_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/art/web_hi_res_512.png -------------------------------------------------------------------------------- /library/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /library/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/library/libs/android-support-v4.jar -------------------------------------------------------------------------------- /library/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | library 7 | NumericPageIndicator 8 | apklib 9 | 10 | 11 | com.github.manuelpeinado.numericpageindicator 12 | parent 13 | 1.1.2-SNAPSHOT 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 | 2.4.1 33 | apklib 34 | 35 | 36 | 37 | 38 | src 39 | 40 | 41 | 42 | com.jayway.maven.plugins.android.generation2 43 | android-maven-plugin 44 | true 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /library/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /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 edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-17 15 | android.library.reference.1=../../ViewPagerIndicator 16 | android.library=true 17 | -------------------------------------------------------------------------------- /library/res/values/npi__attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 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 | -------------------------------------------------------------------------------- /library/res/values/npi__defaults.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Page #i of #N 4 | Start 5 | End 6 | Previous 7 | Next 8 | #AFFF 9 | #FFFF 10 | true 11 | #3FFF 12 | 15dp 13 | 15dp 14 | 15dp 15 | true 16 | true 17 | -------------------------------------------------------------------------------- /library/src/com/manuelpeinado/numericpageindicator/NumericPageIndicator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Manuel Peinado 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.manuelpeinado.numericpageindicator; 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.Color; 23 | import android.graphics.Paint; 24 | import android.graphics.Rect; 25 | import android.graphics.Typeface; 26 | import android.graphics.drawable.Drawable; 27 | import android.os.Parcel; 28 | import android.os.Parcelable; 29 | import android.support.v4.view.MotionEventCompat; 30 | import android.support.v4.view.ViewPager; 31 | import android.util.AttributeSet; 32 | import android.util.Log; 33 | import android.view.MotionEvent; 34 | import android.view.View; 35 | 36 | import com.viewpagerindicator.PageIndicator; 37 | 38 | /** 39 | * Class that implements a ViewPager indicator fully compatible with with Jake Wharton's 40 | * ViewPagerIndicator library. 41 | *

42 | * It displays the number of the current page, and (optionally) the total number of pages. 43 | * This information is formatted using a customizable template. 44 | *

45 | * It can also display buttons to go to the previous page and to the next page. 46 | */ 47 | public class NumericPageIndicator extends View implements PageIndicator { 48 | protected static final String TAG = NumericPageIndicator.class.getSimpleName(); 49 | private ViewPager mViewPager; 50 | private ViewPager.OnPageChangeListener mListener; 51 | private int mCurrentPage = -1; 52 | private float mPageOffset; 53 | private int mScrollState; 54 | private final Paint mPaintText = new Paint(); 55 | private final Paint mPaintPageNumberText = new Paint(); 56 | private final Paint mPaintButtonBackground = new Paint(); 57 | private int mColorText; 58 | private float mPaddingTop; 59 | private float mPaddingBottom; 60 | private float mTextBottom; 61 | private int mTextHeight; 62 | private final Rect mRectPreviousText = new Rect(); 63 | private final Rect mRectNextText = new Rect(); 64 | private final Rect mRectPrevious = new Rect(); 65 | private final Rect mRectNext = new Rect(); 66 | private final Rect mRectStartText = new Rect(); 67 | private final Rect mRectEndText = new Rect(); 68 | private final Rect mRectStart = new Rect(); 69 | private final Rect mRectEnd = new Rect(); 70 | private boolean mPreviousDown; 71 | private boolean mNextDown; 72 | private boolean mStartDown; 73 | private boolean mEndDown; 74 | private float mWidthNextText; 75 | private float mWidthPreviousText; 76 | private float mWidthStartText; 77 | private float mWidthEndText; 78 | private int mColorPressedButton; 79 | private boolean mShowChangePageButtons; 80 | private boolean mShowStartEndButtons; 81 | private int mColorPageNumberText; 82 | private boolean mPageNumberTextBold; 83 | private String mTextTemplate; 84 | private String mTextTemplateFirstPart; 85 | private String mTextTemplateSecondPart; 86 | private String mTextFirstPart; 87 | private String mTextLastPart; 88 | private String mTextPreviousButton; 89 | private String mTextNextButton; 90 | private String mTextStartButton; 91 | private String mTextEndButton; 92 | private static final String TEMPLATE_PAGE_NUMBER_PLACEHOLDER = "#i"; 93 | private static final String TEMPLATE_PAGE_COUNT_PLACEHOLDER = "#N"; 94 | 95 | public NumericPageIndicator(Context context) { 96 | this(context, null); 97 | } 98 | 99 | public NumericPageIndicator(Context context, AttributeSet attrs) { 100 | this(context, attrs, R.attr.numericPageIndicatorStyle); 101 | } 102 | 103 | @SuppressWarnings("deprecation") 104 | public NumericPageIndicator(Context context, AttributeSet attrs, int defStyle) { 105 | super(context, attrs, defStyle); 106 | if (isInEditMode()) { 107 | return; 108 | } 109 | 110 | // Load defaults from resources 111 | final Resources res = getResources(); 112 | final int defaultTextColor = res.getColor(R.color.default_page_number_indicator_text_color); 113 | final int defaultPageNumberTextColor = res.getColor(R.color.default_page_number_indicator_page_number_text_color); 114 | final boolean defaultPageNumberTextBold = res.getBoolean(R.bool.default_page_number_indicator_page_number_text_bold); 115 | final int defaultButtonPressedColor = res.getColor(R.color.default_page_number_indicator_pressed_button_color); 116 | final float defaultTopPadding = res.getDimension(R.dimen.default_page_number_indicator_top_padding); 117 | final float defaultBottomPadding = res.getDimension(R.dimen.default_page_number_indicator_bottom_padding); 118 | final float defaultTextSize = res.getDimension(R.dimen.default_page_number_indicator_text_size); 119 | final boolean defaultShowChangePageButtons = res.getBoolean(R.bool.default_page_number_indicator_show_change_page_buttons); 120 | final boolean defaultShowStartEndButtons = res.getBoolean(R.bool.default_page_number_indicator_show_start_end_buttons); 121 | 122 | // Retrieve styles attributes 123 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumericPageIndicator, defStyle, 0); 124 | 125 | mTextTemplate = a.getString(R.styleable.NumericPageIndicator_textTemplate); 126 | if (mTextTemplate == null) { 127 | mTextTemplate = res.getString(R.string.default_page_number_indicator_text_template); 128 | ; 129 | } 130 | parseTextTemplate(); 131 | 132 | mTextStartButton = a.getString(R.styleable.NumericPageIndicator_startButtonText); 133 | if (mTextStartButton == null) { 134 | mTextStartButton = res.getString(R.string.default_page_number_indicator_start_button_text); 135 | } 136 | mTextEndButton = a.getString(R.styleable.NumericPageIndicator_endButtonText); 137 | if (mTextEndButton == null) { 138 | mTextEndButton = res.getString(R.string.default_page_number_indicator_end_button_text); 139 | } 140 | mTextPreviousButton = a.getString(R.styleable.NumericPageIndicator_previousButtonText); 141 | if (mTextPreviousButton == null) { 142 | mTextPreviousButton = res.getString(R.string.default_page_number_indicator_previous_button_text); 143 | } 144 | mTextNextButton = a.getString(R.styleable.NumericPageIndicator_nextButtonText); 145 | if (mTextNextButton == null) { 146 | mTextNextButton = res.getString(R.string.default_page_number_indicator_next_button_text); 147 | } 148 | 149 | mColorText = a.getColor(R.styleable.NumericPageIndicator_android_textColor, defaultTextColor); 150 | mColorPageNumberText = a.getColor(R.styleable.NumericPageIndicator_pageNumberTextColor, defaultPageNumberTextColor); 151 | mPageNumberTextBold = a.getBoolean(R.styleable.NumericPageIndicator_pageNumberTextBold, defaultPageNumberTextBold); 152 | mColorPressedButton = a.getColor(R.styleable.NumericPageIndicator_pressedButtonColor, defaultButtonPressedColor); 153 | mPaddingTop = a.getDimension(R.styleable.NumericPageIndicator_android_paddingTop, defaultTopPadding); 154 | mPaddingBottom = a.getDimension(R.styleable.NumericPageIndicator_android_paddingBottom, defaultBottomPadding); 155 | mPaintText.setColor(mColorText); 156 | mShowChangePageButtons = a.getBoolean(R.styleable.NumericPageIndicator_showChangePageButtons, defaultShowChangePageButtons); 157 | mShowStartEndButtons = a.getBoolean(R.styleable.NumericPageIndicator_showStartEndButtons, defaultShowStartEndButtons); 158 | 159 | mPaintButtonBackground.setColor(mColorPressedButton); 160 | final float textSize = a.getDimension(R.styleable.NumericPageIndicator_android_textSize, defaultTextSize); 161 | mPaintText.setTextSize(textSize); 162 | mPaintText.setAntiAlias(true); 163 | 164 | mPaintPageNumberText.setColor(mColorPageNumberText); 165 | mPaintPageNumberText.setTextSize(textSize); 166 | mPaintPageNumberText.setAntiAlias(true); 167 | if (mPageNumberTextBold) { 168 | mPaintPageNumberText.setTypeface(Typeface.DEFAULT_BOLD); 169 | } 170 | 171 | final Drawable background = a.getDrawable(R.styleable.NumericPageIndicator_android_background); 172 | if (background != null) { 173 | setBackgroundDrawable(background); 174 | } 175 | 176 | a.recycle(); 177 | } 178 | 179 | /** 180 | * @return The template used to generate the text used by the indicator to show the page 181 | * number and (optionally) the page count 182 | */ 183 | public String getTextTemplate() { 184 | return mTextTemplate; 185 | } 186 | 187 | /** 188 | * Sets the template used to generate the text used by the indicator to show the page 189 | * number and (optionally) the page count.

The provided template must contain the text 190 | * #i, which will be replaced by the page number. If can also contain the optional 191 | * text #N, which will be replaced by the number of pages.

For example: "Page #i of #N" 192 | * @param textTemplate The desired text template 193 | */ 194 | public void setTextTemplate(String textTemplate) { 195 | mTextTemplate = textTemplate; 196 | parseTextTemplate(); 197 | updateText(); 198 | invalidate(); 199 | } 200 | 201 | /** 202 | * Returns the text of the "start page" button 203 | */ 204 | public String getStartButtonText() { 205 | return mTextStartButton; 206 | } 207 | 208 | /** 209 | * Sets the text of the "start page" button 210 | * @param textStartButton The desired text 211 | */ 212 | public void setStartButtonText(String textStartButton) { 213 | this.mTextStartButton = textStartButton; 214 | invalidate(); 215 | } 216 | 217 | /** 218 | * Returns the text of the "next page" button 219 | */ 220 | public String getNextButtonText() { 221 | return mTextNextButton; 222 | } 223 | 224 | /** 225 | * Sets the text of the "next page" button 226 | * @param textPreviousButton The desired text 227 | */ 228 | public void setNextButtonText(String textNextButton) { 229 | this.mTextNextButton = textNextButton; 230 | invalidate(); 231 | } 232 | 233 | /** 234 | * Returns the text of the "previous page" button 235 | */ 236 | public String getPreviousButtonText() { 237 | return mTextPreviousButton; 238 | } 239 | 240 | /** 241 | * Sets the text of the "previous page" button 242 | * @param textPreviousButton The desired text 243 | */ 244 | public void setPreviousButtonText(String textPreviousButton) { 245 | this.mTextPreviousButton = textPreviousButton; 246 | invalidate(); 247 | } 248 | 249 | /** 250 | * Returns the text of the "end page" button 251 | */ 252 | public String getEndButtonText() { 253 | return mTextEndButton; 254 | } 255 | 256 | /** 257 | * Sets the text of the "end page" button 258 | * @param textStartButton The desired text 259 | */ 260 | public void setEndButtonText(String textEndButton) { 261 | this.mTextEndButton = textEndButton; 262 | invalidate(); 263 | } 264 | 265 | public int getTextColor() { 266 | return mColorText; 267 | } 268 | 269 | public void setTextColor(int textColor) { 270 | mPaintText.setColor(textColor); 271 | mColorText = textColor; 272 | invalidate(); 273 | } 274 | 275 | public int getPageNumberTextColor() { 276 | return mColorText; 277 | } 278 | 279 | public void setPageNumberTextColor(int pageNumberTextColor) { 280 | mPaintPageNumberText.setColor(pageNumberTextColor); 281 | mColorPageNumberText = pageNumberTextColor; 282 | invalidate(); 283 | } 284 | 285 | public boolean isPageNumberTextBold() { 286 | return mPageNumberTextBold; 287 | } 288 | 289 | public void setPageNumberTextBold(boolean pageNumberTextBold) { 290 | mPageNumberTextBold = pageNumberTextBold; 291 | final Typeface typeface = mPageNumberTextBold ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT; 292 | mPaintPageNumberText.setTypeface(typeface); 293 | invalidate(); 294 | } 295 | 296 | public int getPressedButtonColor() { 297 | return mColorPressedButton; 298 | } 299 | 300 | public void setPressedButtonColor(int color) { 301 | mPaintButtonBackground.setColor(color); 302 | mColorPressedButton = color; 303 | invalidate(); 304 | } 305 | 306 | public float getTextSize() { 307 | return mPaintText.getTextSize(); 308 | } 309 | 310 | /** 311 | * Set the default text size to the given value, interpreted as "pixels" 312 | * pixel" units. 313 | * 314 | * @param textSize 315 | * The text size in pixels 316 | */ 317 | public void setTextSize(float textSize) { 318 | mPaintText.setTextSize(textSize); 319 | mPaintPageNumberText.setTextSize(textSize); 320 | invalidate(); 321 | } 322 | 323 | public float getTopPadding() { 324 | return this.mPaddingTop; 325 | } 326 | 327 | public void setTopPadding(float topPadding) { 328 | mPaddingTop = topPadding; 329 | invalidate(); 330 | } 331 | 332 | public float getBottomPadding() { 333 | return this.mPaddingBottom; 334 | } 335 | 336 | public void setBottomPadding(float bottomPadding) { 337 | mPaddingBottom = bottomPadding; 338 | invalidate(); 339 | } 340 | 341 | public void setTypeface(Typeface typeface) { 342 | mPaintText.setTypeface(typeface); 343 | invalidate(); 344 | } 345 | 346 | public Typeface getTypeface() { 347 | return mPaintText.getTypeface(); 348 | } 349 | 350 | public boolean isShowChangePageButtons() { 351 | return mShowChangePageButtons; 352 | } 353 | 354 | public void setShowChangePageButtons(boolean showChangePageButtons) { 355 | this.mShowChangePageButtons = showChangePageButtons; 356 | invalidate(); 357 | } 358 | 359 | public boolean isShowStartEndButtons() { 360 | return mShowStartEndButtons; 361 | } 362 | 363 | public void setShowStartEndButtons(boolean showStartEndButtons) { 364 | this.mShowStartEndButtons = showStartEndButtons; 365 | invalidate(); 366 | } 367 | 368 | /** 369 | * Parses a template (e.g. "Page #i of #N) splitting it in two parts: the 370 | * one before the page number "Page " and the one after (" of #N"). This is 371 | * necessary because when we draw the text we'll draw the page number 372 | * independently, as it has to fade out when the uses swipes to a new page 373 | * 374 | * @param template The text template to be parsed (e.g. "Page #i of #N) 375 | */ 376 | private void parseTextTemplate() { 377 | final String placeholder = TEMPLATE_PAGE_NUMBER_PLACEHOLDER; 378 | final int indexOfPageNumber = mTextTemplate.indexOf(placeholder); 379 | if (indexOfPageNumber == -1) { 380 | throw new RuntimeException("The template must contain the page number placeholder \"" + placeholder + "\""); 381 | } 382 | mTextTemplateFirstPart = mTextTemplate.substring(0, indexOfPageNumber); 383 | mTextTemplateSecondPart = mTextTemplate.substring(indexOfPageNumber + placeholder.length()); 384 | } 385 | 386 | /** 387 | * Updates the two "fixed" parts of the indicator text. The first part is 388 | * the one before the page number (e.g. "Page ") and the second part is the 389 | * one after (" of #N"). Updating consists simply on replacing the #N part 390 | * by the actual page count. So in the example above the outcome would be: 391 | *

  • First part: "Page " (unmodified)
  • Second part: " of 20" ("#N" 392 | * replaced by "20") 393 | */ 394 | private void updateText() { 395 | final int pageCount = mViewPager.getAdapter().getCount(); 396 | final String textPageCount = Integer.toString(pageCount); 397 | final String placeholder = TEMPLATE_PAGE_COUNT_PLACEHOLDER; 398 | mTextFirstPart = mTextTemplateFirstPart.replace(placeholder, textPageCount); 399 | mTextLastPart = mTextTemplateSecondPart.replace(placeholder, textPageCount); 400 | } 401 | 402 | /* 403 | * (non-Javadoc) 404 | * 405 | * @see android.view.View#onDraw(android.graphics.Canvas) 406 | */ 407 | @Override 408 | protected void onDraw(Canvas canvas) { 409 | super.onDraw(canvas); 410 | 411 | if (mViewPager == null) { 412 | return; 413 | } 414 | final int count = mViewPager.getAdapter().getCount(); 415 | if (count == 0) { 416 | return; 417 | } 418 | 419 | // mCurrentPage is -1 on first start and after orientation changed. If 420 | // so, retrieve the correct index from viewpager. 421 | if (mCurrentPage == -1 && mViewPager != null) { 422 | mCurrentPage = mViewPager.getCurrentItem(); 423 | } 424 | 425 | // Handle the first time we draw the view, when onMeasure has not been 426 | // called yet 427 | if (mTextFirstPart == null) { 428 | updateText(); 429 | } 430 | 431 | // Draw the main text (e.g. "Page 1 of 20"). The hardest part is drawing 432 | // the page 433 | // number itself, because of the animated effect in which the current 434 | // page fades 435 | // out and the next one fades in. In order to implement this effect we 436 | // are forced to 437 | // draw the text in four "chunks": the first part ("Page "), the current 438 | // page 439 | // number ("1"), the next page number ("2"), and the last part 440 | // (" of 20"). 441 | // To implement the fade in and fade out animations we simply change the 442 | // alpha 443 | // of the page number text, relative to the view pager scroll 444 | 445 | final float currentPageWeight = 1 - mPageOffset; 446 | final float nextPageWeight = mPageOffset; 447 | final float firstPartWidth = mPaintText.measureText(mTextFirstPart); 448 | final String currentPageNumber = Integer.toString(mCurrentPage + 1); 449 | final String nextPageNumber = Integer.toString(mCurrentPage + 2); 450 | final float currentPageNumberWidth = mPaintText.measureText(currentPageNumber); 451 | final float nextPageNumberWidth = mPaintText.measureText(nextPageNumber); 452 | final float pageNumberWidth = currentPageWeight * currentPageNumberWidth + nextPageWeight * nextPageNumberWidth; 453 | final float lastPartWidth = mPaintText.measureText(mTextLastPart); 454 | final float totalWidth = firstPartWidth + pageNumberWidth + lastPartWidth; 455 | float currentX = (getWidth() - totalWidth) / 2; 456 | canvas.drawText(mTextFirstPart, currentX, mTextBottom, mPaintText); 457 | currentX += firstPartWidth; 458 | final float pageNumberCenterX = currentX + pageNumberWidth / 2; 459 | 460 | final int startAlpha = Color.alpha(mColorPageNumberText); 461 | final int endAlpha = 0; 462 | final float currentPageNumberAlpha = currentPageWeight * startAlpha + nextPageWeight * endAlpha; 463 | 464 | mPaintPageNumberText.setAlpha((int) currentPageNumberAlpha); 465 | canvas.drawText(currentPageNumber, pageNumberCenterX - currentPageNumberWidth / 2, mTextBottom, mPaintPageNumberText); 466 | 467 | final float nextPageNumberAlpha = nextPageWeight * startAlpha + currentPageWeight * endAlpha; 468 | mPaintPageNumberText.setAlpha((int) nextPageNumberAlpha); 469 | canvas.drawText(nextPageNumber, pageNumberCenterX - nextPageNumberWidth / 2, mTextBottom, mPaintPageNumberText); 470 | 471 | currentX += pageNumberWidth; 472 | canvas.drawText(mTextLastPart, currentX, mTextBottom, mPaintText); 473 | 474 | // Draw the "start" and "end" buttons 475 | if (mShowStartEndButtons) { 476 | final int textStartAlpha = Color.alpha(mColorText); 477 | final int textEndAlpha = 0; 478 | if (mCurrentPage != 0 && mStartDown) { 479 | canvas.drawRect(mRectStart, mPaintButtonBackground); 480 | } 481 | if (mCurrentPage != count - 1 && mEndDown) { 482 | canvas.drawRect(mRectEnd, mPaintButtonBackground); 483 | } 484 | if (mCurrentPage == 0) { 485 | mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha)); 486 | } 487 | canvas.drawText(mTextStartButton, mRectStart.centerX() - mWidthStartText / 2, mRectStartText.bottom, mPaintText); 488 | mPaintText.setAlpha(Color.alpha(mColorText)); 489 | if (mCurrentPage < count - 1) { 490 | if (mCurrentPage == count - 2) { 491 | mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha)); 492 | } 493 | canvas.drawText(mTextEndButton, mRectEnd.centerX() - mWidthEndText / 2, mRectEndText.bottom, mPaintText); 494 | mPaintText.setAlpha(Color.alpha(mColorText)); 495 | } 496 | } 497 | 498 | 499 | // Draw the "next" and "previous" buttons 500 | if (mShowChangePageButtons) { 501 | final int textStartAlpha = Color.alpha(mColorText); 502 | final int textEndAlpha = 0; 503 | if (mCurrentPage != 0 && mPreviousDown) { 504 | canvas.drawRect(mRectPrevious, mPaintButtonBackground); 505 | } 506 | if (mCurrentPage != count - 1 && mNextDown) { 507 | canvas.drawRect(mRectNext, mPaintButtonBackground); 508 | } 509 | if (mCurrentPage == 0) { 510 | mPaintText.setAlpha((int) (nextPageWeight * textStartAlpha + currentPageWeight * textEndAlpha)); 511 | } 512 | canvas.drawText(mTextPreviousButton, mRectPrevious.centerX() - mWidthPreviousText / 2, mRectPreviousText.bottom, mPaintText); 513 | mPaintText.setAlpha(Color.alpha(mColorText)); 514 | if (mCurrentPage < count - 1) { 515 | if (mCurrentPage == count - 2) { 516 | mPaintText.setAlpha((int) (currentPageWeight * textStartAlpha + nextPageWeight * textEndAlpha)); 517 | } 518 | canvas.drawText(mTextNextButton, mRectNext.centerX() - mWidthNextText / 2, mRectNextText.bottom, mPaintText); 519 | mPaintText.setAlpha(Color.alpha(mColorText)); 520 | } 521 | } 522 | } 523 | 524 | @Override 525 | public void setViewPager(ViewPager view) { 526 | if (mViewPager == view) { 527 | return; 528 | } 529 | if (mViewPager != null) { 530 | mViewPager.setOnPageChangeListener(null); 531 | } 532 | if (view.getAdapter() == null) { 533 | throw new IllegalStateException("ViewPager does not have adapter instance."); 534 | } 535 | mViewPager = view; 536 | mViewPager.setOnPageChangeListener(this); 537 | invalidate(); 538 | } 539 | 540 | @Override 541 | public void setViewPager(ViewPager view, int initialPosition) { 542 | setViewPager(view); 543 | setCurrentItem(initialPosition); 544 | } 545 | 546 | @Override 547 | public void notifyDataSetChanged() { 548 | invalidate(); 549 | } 550 | 551 | @Override 552 | public void setCurrentItem(int item) { 553 | if (mViewPager == null) { 554 | throw new IllegalStateException("ViewPager has not been bound."); 555 | } 556 | mViewPager.setCurrentItem(item); 557 | mCurrentPage = item; 558 | updateText(); 559 | invalidate(); 560 | } 561 | 562 | @Override 563 | public void onPageScrollStateChanged(int state) { 564 | mScrollState = state; 565 | 566 | if (mListener != null) { 567 | mListener.onPageScrollStateChanged(state); 568 | } 569 | } 570 | 571 | @Override 572 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 573 | mCurrentPage = position; 574 | mPageOffset = positionOffset; 575 | invalidate(); 576 | 577 | if (mListener != null) { 578 | mListener.onPageScrolled(position, positionOffset, positionOffsetPixels); 579 | } 580 | } 581 | 582 | @Override 583 | public void onPageSelected(int position) { 584 | if (mScrollState == ViewPager.SCROLL_STATE_IDLE) { 585 | mCurrentPage = position; 586 | invalidate(); 587 | } 588 | 589 | if (mListener != null) { 590 | mListener.onPageSelected(position); 591 | } 592 | } 593 | 594 | @Override 595 | public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) { 596 | mListener = listener; 597 | } 598 | 599 | @Override 600 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 601 | final int measuredWidth = MeasureSpec.getSize(widthMeasureSpec); 602 | float height; 603 | final int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec); 604 | if (heightSpecMode == MeasureSpec.EXACTLY) { 605 | height = MeasureSpec.getSize(heightMeasureSpec); 606 | } else { 607 | mTextHeight = (int) (mPaintText.descent() - mPaintText.ascent()); 608 | height = mTextHeight + mPaddingTop + mPaddingBottom; 609 | } 610 | final int measuredHeight = (int) height; 611 | setMeasuredDimension(measuredWidth, measuredHeight); 612 | } 613 | 614 | @Override 615 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 616 | final float horizontalPadding = -mPaintText.ascent(); 617 | mTextBottom = h - mPaddingBottom - mPaintText.descent(); 618 | 619 | float leftOffset = 0; 620 | float rightOffset = 0; 621 | if (mShowStartEndButtons) { 622 | mWidthStartText = mPaintText.measureText(mTextStartButton); 623 | final float startButtonWidth = mWidthStartText + 2 * horizontalPadding; 624 | mWidthEndText = mPaintText.measureText(mTextEndButton); 625 | final float endButtonWidth = mWidthEndText + 2 * horizontalPadding; 626 | mRectStartText.set((int) horizontalPadding, (int) mPaddingTop, (int) startButtonWidth, (int) mTextBottom); 627 | mRectEndText.set((int) (w - endButtonWidth), (int) mPaddingTop, (int) (w - horizontalPadding), (int) mTextBottom); 628 | mRectStart.set(0, 0, (int) startButtonWidth, h); 629 | mRectEnd.set((int) (w - startButtonWidth), 0, w, h); 630 | leftOffset = startButtonWidth; 631 | rightOffset = endButtonWidth; 632 | } 633 | 634 | if (mShowChangePageButtons) { 635 | mWidthPreviousText = mPaintText.measureText(mTextPreviousButton); 636 | final float previousButtonWidth = mWidthPreviousText + 2 * horizontalPadding; 637 | mWidthNextText = mPaintText.measureText(mTextNextButton); 638 | final float nextButtonWidth = mWidthNextText + 2 * horizontalPadding; 639 | mRectPreviousText.set((int) (horizontalPadding + leftOffset), (int) mPaddingTop, (int) (previousButtonWidth + leftOffset), (int) mTextBottom); 640 | mRectNextText.set((int) (w - nextButtonWidth - rightOffset), (int) mPaddingTop, (int) (w - horizontalPadding - rightOffset), (int) mTextBottom); 641 | mRectPrevious.set((int)leftOffset, 0, (int) (leftOffset + previousButtonWidth), h); 642 | mRectNext.set((int) (w - nextButtonWidth - rightOffset), 0, (int)(w - rightOffset), h); 643 | } 644 | } 645 | 646 | @Override 647 | public boolean onTouchEvent(MotionEvent event) { 648 | if (!mShowChangePageButtons) { 649 | return false; 650 | } 651 | if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { 652 | return false; 653 | } 654 | final int action = event.getAction() & MotionEventCompat.ACTION_MASK; 655 | switch (action) { 656 | case MotionEvent.ACTION_DOWN: 657 | // See if the pointer is within the bounds one of the buttons 658 | // In that case, change the state of the button to pressed and 659 | // repaint 660 | if (isEventOnRect(event, mRectPrevious)) { 661 | mPreviousDown = true; 662 | invalidate(); 663 | } 664 | else if (isEventOnRect(event, mRectNext)) { 665 | mNextDown = true; 666 | invalidate(); 667 | } 668 | else if (isEventOnRect(event, mRectStart)) { 669 | mStartDown = true; 670 | invalidate(); 671 | } 672 | else if (isEventOnRect(event, mRectEnd)) { 673 | mEndDown = true; 674 | invalidate(); 675 | } 676 | break; 677 | case MotionEvent.ACTION_MOVE: 678 | // See if we've exited the bounds of a pressed button before the 679 | // pointer was released 680 | // In that case, change the state of the button to normal and 681 | // repaint 682 | if (mPreviousDown) { 683 | if (!isEventOnRect(event, mRectPrevious)) { 684 | mPreviousDown = false; 685 | invalidate(); 686 | } 687 | } else if (mNextDown) { 688 | if (!isEventOnRect(event, mRectNext)) { 689 | mNextDown = false; 690 | invalidate(); 691 | } 692 | } 693 | else if (mStartDown) { 694 | if (!isEventOnRect(event, mRectStart)) { 695 | mStartDown = false; 696 | invalidate(); 697 | } 698 | } else if (mEndDown) { 699 | if (!isEventOnRect(event, mRectEnd)) { 700 | mEndDown = false; 701 | invalidate(); 702 | } 703 | } 704 | break; 705 | case MotionEvent.ACTION_UP: 706 | // See if we've released the pointer while still inside the pressed 707 | // button 708 | // In that case, perform the action associated to the button 709 | if (mPreviousDown) { 710 | openPreviousPage(); 711 | } else if (mNextDown) { 712 | openNextPage(); 713 | } else if (mStartDown) { 714 | openStartPage(); 715 | } else if (mEndDown) { 716 | openEndPage(); 717 | } 718 | // Deliberate fall-through 719 | case MotionEvent.ACTION_CANCEL: 720 | // After an UP or CANCEL action we change the state of the buttons 721 | // to normal and repaint 722 | if (mPreviousDown || mNextDown || mStartDown || mEndDown) { 723 | mStartDown = mEndDown = mNextDown = mPreviousDown = false; 724 | invalidate(); 725 | } 726 | break; 727 | } 728 | return true; 729 | } 730 | 731 | private void openStartPage() { 732 | int count = mViewPager.getAdapter().getCount(); 733 | if (count == 0) { 734 | Log.w(TAG, "Trying to open start page when page count is 0"); 735 | return; 736 | } 737 | mViewPager.setCurrentItem(0, true); 738 | } 739 | 740 | private void openPreviousPage() { 741 | int currentPage = mViewPager.getCurrentItem(); 742 | if (currentPage == 0) { 743 | Log.w(TAG, "Trying to open previous page when current page is 0"); 744 | return; 745 | } 746 | mViewPager.setCurrentItem(currentPage - 1, true); 747 | } 748 | 749 | private void openNextPage() { 750 | int currentPage = mViewPager.getCurrentItem(); 751 | if (currentPage == mViewPager.getAdapter().getCount() - 1) { 752 | Log.w(TAG, "Trying to open next page when current page is already the last one"); 753 | return; 754 | } 755 | mViewPager.setCurrentItem(currentPage + 1, true); 756 | } 757 | 758 | private void openEndPage() { 759 | int count = mViewPager.getAdapter().getCount(); 760 | if (count == 0) { 761 | Log.w(TAG, "Trying to open end page when page count is 0"); 762 | return; 763 | } 764 | mViewPager.setCurrentItem(count - 1, true); 765 | } 766 | 767 | 768 | private boolean isEventOnRect(MotionEvent event, Rect rect) { 769 | return rect.contains((int) event.getX(), (int) event.getY()); 770 | } 771 | 772 | @Override 773 | public void onRestoreInstanceState(Parcelable state) { 774 | SavedState savedState = (SavedState) state; 775 | super.onRestoreInstanceState(savedState.getSuperState()); 776 | mCurrentPage = savedState.currentPage; 777 | requestLayout(); 778 | } 779 | 780 | @Override 781 | public Parcelable onSaveInstanceState() { 782 | Parcelable superState = super.onSaveInstanceState(); 783 | SavedState savedState = new SavedState(superState); 784 | savedState.currentPage = mCurrentPage; 785 | return savedState; 786 | } 787 | 788 | static class SavedState extends BaseSavedState { 789 | int currentPage; 790 | 791 | public SavedState(Parcelable superState) { 792 | super(superState); 793 | } 794 | 795 | private SavedState(Parcel in) { 796 | super(in); 797 | currentPage = in.readInt(); 798 | } 799 | 800 | @Override 801 | public void writeToParcel(Parcel dest, int flags) { 802 | super.writeToParcel(dest, flags); 803 | dest.writeInt(currentPage); 804 | } 805 | 806 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 807 | @Override 808 | public SavedState createFromParcel(Parcel in) { 809 | return new SavedState(in); 810 | } 811 | 812 | @Override 813 | public SavedState[] newArray(int size) { 814 | return new SavedState[size]; 815 | } 816 | }; 817 | } 818 | } 819 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | 7 | org.sonatype.oss 8 | oss-parent 9 | 7 10 | 11 | 12 | com.github.manuelpeinado.numericpageindicator 13 | parent 14 | pom 15 | 1.1.2-SNAPSHOT 16 | 17 | Android-NumericPageIndicator (Parent) 18 | ViewPager indicator showing page numbers 19 | https://github.com/ManuelPeinado/NumericPageIndicator 20 | 2013 21 | 22 | 23 | library 24 | sample 25 | 26 | 27 | 28 | http://github.com/ManuelPeinado/NumericPageIndicator/ 29 | scm:git:git://github.com/ManuelPeinado/NumericPageIndicator.git 30 | scm:git:git@github.com:ManuelPeinado/NumericPageIndicator.git 31 | 32 | 33 | 34 | 35 | Manuel Peinado 36 | manuelpeinado@gmail.com 37 | manuelpeinado 38 | http://github.com/ManuelPeinado 39 | 0 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 | Manuel Peinado G. 56 | http://github.com/ManuelPeinado 57 | 58 | 59 | 60 | GitHub Issues 61 | https://github.com/ManuelPeinado/NumericPageIndicator/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 | com.actionbarsherlock 92 | actionbarsherlock 93 | 4.2.0 94 | apklib 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | org.apache.maven.plugins 105 | maven-compiler-plugin 106 | 2.3.2 107 | 108 | ${java.version} 109 | ${java.version} 110 | 111 | 112 | 113 | 114 | com.jayway.maven.plugins.android.generation2 115 | android-maven-plugin 116 | ${android-maven.version} 117 | 118 | 119 | ${android.platform} 120 | 121 | true 122 | 123 | true 124 | 125 | 126 | 127 | org.apache.maven.plugins 128 | maven-checkstyle-plugin 129 | 2.6 130 | 131 | true 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | org.apache.maven.plugins 140 | maven-release-plugin 141 | 2.1 142 | 143 | true 144 | 145 | 146 | 147 | 148 | org.apache.maven.plugins 149 | maven-eclipse-plugin 150 | 2.9 151 | 152 | 153 | android:android 154 | com.google.android.maps:maps 155 | 156 | bin 157 | 158 | com.android.ide.eclipse.adt.ANDROID_FRAMEWORK 159 | 160 | 161 | com.android.ide.eclipse.adt.AndroidNature 162 | org.eclipse.ajdt.ui.ajnature 163 | 164 | 165 | com.android.ide.eclipse.adt.ResourceManagerBuilder 166 | com.android.ide.eclipse.adt.PreCompilerBuilder 167 | org.eclipse.jdt.core.javabuilder 168 | com.android.ide.eclipse.adt.ApkBuilder 169 | 170 | false 171 | 172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /sample/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 32 | 35 | 38 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /sample/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/sample/libs/android-support-v4.jar -------------------------------------------------------------------------------- /sample/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | sample 7 | NumericPageIndicator Sample 8 | apk 9 | 10 | 11 | com.github.manuelpeinado.numericpageindicator 12 | parent 13 | 1.1.2-SNAPSHOT 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.github.manuelpeinado.numericpageindicator 31 | library 32 | ${project.version} 33 | apklib 34 | 35 | 36 | 37 | com.actionbarsherlock 38 | actionbarsherlock 39 | 4.2.0 40 | apklib 41 | 42 | 43 | 44 | 45 | 46 | src 47 | ${project.artifactId}-unaligned 48 | 49 | 50 | 51 | com.jayway.maven.plugins.android.generation2 52 | android-maven-plugin 53 | true 54 | 55 | 56 | 57 | 58 | 59 | 60 | release 61 | 62 | 63 | performRelease 64 | true 65 | 66 | 67 | 68 | 69 | 70 | com.jayway.maven.plugins.android.generation2 71 | android-maven-plugin 72 | ${android-maven.version} 73 | true 74 | 75 | 76 | ${project.build.directory}/${project.build.finalName}.apk 77 | ${project.build.directory}/${project.artifactId}.apk 78 | 79 | 80 | 81 | 82 | alignApk 83 | package 84 | 85 | zipalign 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /sample/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /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 edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-17 15 | android.library.reference.1=../../ActionBarSherlock 16 | android.library.reference.2=../library 17 | -------------------------------------------------------------------------------- /sample/res/anim/scale_fade_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 13 | 14 | 17 | 18 | -------------------------------------------------------------------------------- /sample/res/anim/scale_fade_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 13 | 14 | 17 | 18 | -------------------------------------------------------------------------------- /sample/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/sample/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/sample/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/sample/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ManuelPeinado/NumericPageIndicator/c3d08d8c5c649e00abc4e67a6f3b6c4a92010135/sample/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/res/layout/activity_home.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | -------------------------------------------------------------------------------- /sample/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | 14 | 18 | 19 | -------------------------------------------------------------------------------- /sample/res/layout/activity_styling_in_layout.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 14 | 15 | 33 | 34 | -------------------------------------------------------------------------------- /sample/res/values-land/bools.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | true 4 | -------------------------------------------------------------------------------- /sample/res/values/bools.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | false 4 | -------------------------------------------------------------------------------- /sample/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #222 4 | 5 | -------------------------------------------------------------------------------- /sample/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | NumericPageIndicator sample 5 | Basic usage 6 | Styling in theme 7 | Styling in XML layout 8 | Styling programmatically 9 | Buttons in landscape mode only 10 | #i/#N" 11 | #i of #N" 12 | Prev. 13 | Next 14 | First 15 | Last 16 | More 17 | Less 18 | 1st 19 | Nth 20 | 21 | -------------------------------------------------------------------------------- /sample/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 25 | 26 | 30 | 31 | -------------------------------------------------------------------------------- /sample/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /sample/src/com/manuelpeinado/numericpageindicator/demo/ActivityInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Manuel Peinado 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.manuelpeinado.numericpageindicator.demo; 17 | 18 | import android.app.Activity; 19 | 20 | public class ActivityInfo { 21 | public Class activityClass; 22 | public int titleResourceId; 23 | 24 | public ActivityInfo(Class activityClass, int titleResourceId) { 25 | this.activityClass = activityClass; 26 | this.titleResourceId = titleResourceId; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sample/src/com/manuelpeinado/numericpageindicator/demo/BasicUsageActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Manuel Peinado 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.manuelpeinado.numericpageindicator.demo; 17 | 18 | import android.content.Intent; 19 | import android.os.Bundle; 20 | import android.support.v4.view.ViewPager; 21 | 22 | import com.actionbarsherlock.app.SherlockActivity; 23 | import com.actionbarsherlock.view.MenuItem; 24 | import com.viewpagerindicator.PageIndicator; 25 | 26 | public class BasicUsageActivity extends SherlockActivity { 27 | private ViewPager viewPager; 28 | private PageIndicator pageIndicator; 29 | 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.activity_main); 34 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 35 | 36 | viewPager = (ViewPager) findViewById(R.id.pager); 37 | viewPager.setAdapter(new MyPagerAdapter()); 38 | pageIndicator = (PageIndicator) findViewById(R.id.pageIndicator); 39 | pageIndicator.setViewPager(viewPager); 40 | } 41 | 42 | @Override 43 | public boolean onOptionsItemSelected(MenuItem item) { 44 | if (item.getItemId() == android.R.id.home) { 45 | Intent parentActivityIntent = new Intent(this, HomeActivity.class); 46 | parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 47 | startActivity(parentActivityIntent); 48 | finish(); 49 | return true; 50 | } 51 | return false; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sample/src/com/manuelpeinado/numericpageindicator/demo/ButtonsInLandscapeActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Manuel Peinado 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.manuelpeinado.numericpageindicator.demo; 17 | 18 | import android.content.Intent; 19 | import android.os.Bundle; 20 | import android.support.v4.view.ViewPager; 21 | 22 | import com.actionbarsherlock.app.SherlockActivity; 23 | import com.actionbarsherlock.view.MenuItem; 24 | import com.manuelpeinado.numericpageindicator.demo.R; 25 | import com.viewpagerindicator.PageIndicator; 26 | 27 | public class ButtonsInLandscapeActivity extends SherlockActivity { 28 | private ViewPager viewPager; 29 | private PageIndicator pageIndicator; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_main); 35 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 36 | 37 | viewPager = (ViewPager) findViewById(R.id.pager); 38 | viewPager.setAdapter(new MyPagerAdapter()); 39 | pageIndicator = (PageIndicator) findViewById(R.id.pageIndicator); 40 | pageIndicator.setViewPager(viewPager); 41 | } 42 | 43 | @Override 44 | public boolean onOptionsItemSelected(MenuItem item) { 45 | if (item.getItemId() == android.R.id.home) { 46 | Intent parentActivityIntent = new Intent(this, HomeActivity.class); 47 | parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 48 | startActivity(parentActivityIntent); 49 | finish(); 50 | return true; 51 | } 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sample/src/com/manuelpeinado/numericpageindicator/demo/HomeActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Manuel Peinado 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.manuelpeinado.numericpageindicator.demo; 17 | 18 | import java.util.Arrays; 19 | import java.util.List; 20 | 21 | import android.app.Activity; 22 | import android.content.Intent; 23 | import android.os.Bundle; 24 | import android.view.View; 25 | import android.widget.ArrayAdapter; 26 | import android.widget.ListView; 27 | 28 | import com.actionbarsherlock.app.SherlockListActivity; 29 | 30 | public class HomeActivity extends SherlockListActivity { 31 | private List activitiesInfo = Arrays.asList( 32 | new ActivityInfo(BasicUsageActivity.class, R.string.activity_title_basic_usage), 33 | new ActivityInfo(StylingInThemeActivity.class, R.string.activity_title_styling_in_theme), 34 | new ActivityInfo(StylingInLayoutActivity.class, R.string.activity_title_styling_in_layout), 35 | new ActivityInfo(StylingProgrammaticallyActivity.class, R.string.activity_title_styling_programmatically), 36 | new ActivityInfo(ButtonsInLandscapeActivity.class, R.string.activity_title_buttons_in_landscape)); 37 | 38 | @Override 39 | protected void onCreate(Bundle savedInstanceState) { 40 | super.onCreate(savedInstanceState); 41 | setContentView(R.layout.activity_home); 42 | String[] titles = getActivityTitles(); 43 | setListAdapter(new ArrayAdapter( 44 | this, android.R.layout.simple_list_item_1, android.R.id.text1, titles)); 45 | } 46 | 47 | @Override 48 | protected void onListItemClick(ListView l, View v, int position, long id) { 49 | Class class_ = activitiesInfo.get(position).activityClass; 50 | Intent intent = new Intent(this, class_); 51 | startActivity(intent); 52 | } 53 | 54 | private String[] getActivityTitles() { 55 | String[] result = new String[activitiesInfo.size()]; 56 | int i = 0; 57 | for (ActivityInfo info : activitiesInfo) { 58 | result[i++] = getString(info.titleResourceId); 59 | } 60 | return result; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sample/src/com/manuelpeinado/numericpageindicator/demo/MyPagerAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Manuel Peinado 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.manuelpeinado.numericpageindicator.demo; 17 | 18 | import android.graphics.Color; 19 | import android.support.v4.view.PagerAdapter; 20 | import android.util.TypedValue; 21 | import android.view.Gravity; 22 | import android.view.View; 23 | import android.view.ViewGroup; 24 | import android.widget.TextView; 25 | 26 | public class MyPagerAdapter extends PagerAdapter { 27 | 28 | private static final int[] COLORS = { 29 | Color.rgb(192, 128, 128), 30 | Color.rgb(128, 192, 128), 31 | Color.rgb(128, 128, 192), 32 | }; 33 | 34 | @Override 35 | public int getCount() { 36 | return 20; 37 | } 38 | 39 | @Override 40 | public boolean isViewFromObject(View view, Object object) { 41 | return view == object; 42 | } 43 | 44 | @Override 45 | public Object instantiateItem(ViewGroup container, int position) { 46 | TextView item = new TextView(container.getContext()); 47 | item.setText(Integer.toString(position + 1)); 48 | item.setTextColor(Color.argb(192, 255, 255, 255)); 49 | item.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 50); 50 | item.setGravity(Gravity.CENTER); 51 | item.setBackgroundColor(COLORS[position % COLORS.length]); 52 | ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 53 | container.addView(item, layoutParams); 54 | return item; 55 | } 56 | 57 | @Override 58 | public void destroyItem(ViewGroup container, int position, Object object) { 59 | container.removeView((View)object); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /sample/src/com/manuelpeinado/numericpageindicator/demo/StylingInLayoutActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Manuel Peinado 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.manuelpeinado.numericpageindicator.demo; 17 | 18 | import android.content.Intent; 19 | import android.os.Bundle; 20 | import android.support.v4.view.ViewPager; 21 | 22 | import com.actionbarsherlock.app.SherlockActivity; 23 | import com.actionbarsherlock.view.MenuItem; 24 | import com.manuelpeinado.numericpageindicator.demo.R; 25 | import com.viewpagerindicator.PageIndicator; 26 | 27 | public class StylingInLayoutActivity extends SherlockActivity { 28 | private ViewPager viewPager; 29 | private PageIndicator pageIndicator; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_styling_in_layout); 35 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 36 | 37 | viewPager = (ViewPager) findViewById(R.id.pager); 38 | viewPager.setAdapter(new MyPagerAdapter()); 39 | pageIndicator = (PageIndicator) findViewById(R.id.pageIndicator); 40 | pageIndicator.setViewPager(viewPager); 41 | } 42 | 43 | @Override 44 | public boolean onOptionsItemSelected(MenuItem item) { 45 | if (item.getItemId() == android.R.id.home) { 46 | Intent parentActivityIntent = new Intent(this, HomeActivity.class); 47 | parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 48 | startActivity(parentActivityIntent); 49 | finish(); 50 | return true; 51 | } 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sample/src/com/manuelpeinado/numericpageindicator/demo/StylingInThemeActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Manuel Peinado 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.manuelpeinado.numericpageindicator.demo; 17 | 18 | import android.content.Intent; 19 | import android.os.Bundle; 20 | import android.support.v4.view.ViewPager; 21 | 22 | import com.actionbarsherlock.app.SherlockActivity; 23 | import com.actionbarsherlock.view.MenuItem; 24 | import com.manuelpeinado.numericpageindicator.demo.R; 25 | import com.viewpagerindicator.PageIndicator; 26 | 27 | public class StylingInThemeActivity extends SherlockActivity { 28 | private ViewPager viewPager; 29 | private PageIndicator pageIndicator; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_main); 35 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 36 | 37 | viewPager = (ViewPager) findViewById(R.id.pager); 38 | viewPager.setAdapter(new MyPagerAdapter()); 39 | pageIndicator = (PageIndicator) findViewById(R.id.pageIndicator); 40 | pageIndicator.setViewPager(viewPager); 41 | } 42 | 43 | @Override 44 | public boolean onOptionsItemSelected(MenuItem item) { 45 | if (item.getItemId() == android.R.id.home) { 46 | Intent parentActivityIntent = new Intent(this, HomeActivity.class); 47 | parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 48 | startActivity(parentActivityIntent); 49 | finish(); 50 | return true; 51 | } 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sample/src/com/manuelpeinado/numericpageindicator/demo/StylingProgrammaticallyActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Manuel Peinado 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.manuelpeinado.numericpageindicator.demo; 17 | 18 | import android.content.Intent; 19 | import android.graphics.Color; 20 | import android.os.Bundle; 21 | import android.support.v4.view.ViewPager; 22 | 23 | import com.actionbarsherlock.app.SherlockActivity; 24 | import com.actionbarsherlock.view.MenuItem; 25 | import com.manuelpeinado.numericpageindicator.NumericPageIndicator; 26 | 27 | public class StylingProgrammaticallyActivity extends SherlockActivity { 28 | private ViewPager viewPager; 29 | private NumericPageIndicator pageIndicator; 30 | 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_main); 35 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 36 | 37 | viewPager = (ViewPager) findViewById(R.id.pager); 38 | viewPager.setAdapter(new MyPagerAdapter()); 39 | pageIndicator = (NumericPageIndicator) findViewById(R.id.pageIndicator); 40 | pageIndicator.setViewPager(viewPager); 41 | 42 | pageIndicator.setTextTemplate("Page: #i"); 43 | pageIndicator.setStartButtonText("|<"); 44 | pageIndicator.setPreviousButtonText("<"); 45 | pageIndicator.setNextButtonText(">"); 46 | pageIndicator.setEndButtonText(">|"); 47 | pageIndicator.setTextColor(Color.argb(128, 255, 255, 255)); 48 | pageIndicator.setPageNumberTextColor(Color.argb(192, 255, 255, 255)); 49 | pageIndicator.setPageNumberTextBold(false); 50 | final float scale = getResources().getDisplayMetrics().density; 51 | pageIndicator.setTextSize((int)(12 * scale + 0.5f)); 52 | pageIndicator.setTopPadding((int)(7 * scale + 0.5f)); 53 | pageIndicator.setBottomPadding((int)(7 * scale + 0.5f)); 54 | pageIndicator.setBackgroundColor(Color.rgb(64, 96, 64)); 55 | pageIndicator.setPressedButtonColor(Color.argb(128, 255, 255, 255)); 56 | pageIndicator.setShowChangePageButtons(true); 57 | } 58 | 59 | @Override 60 | public boolean onOptionsItemSelected(MenuItem item) { 61 | if (item.getItemId() == android.R.id.home) { 62 | Intent parentActivityIntent = new Intent(this, HomeActivity.class); 63 | parentActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); 64 | startActivity(parentActivityIntent); 65 | finish(); 66 | return true; 67 | } 68 | return false; 69 | } 70 | } 71 | --------------------------------------------------------------------------------