├── .gitignore
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE.txt
├── README.md
├── art
├── demo1.gif
├── demo2.gif
├── demo3.gif
├── demo4.gif
├── demo5.gif
├── demo6.gif
├── demo7.gif
└── icon.png
├── build.gradle
├── demo
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── ogaclejapan
│ │ └── smarttablayout
│ │ └── demo
│ │ ├── Demo.java
│ │ ├── DemoActivity.java
│ │ ├── DemoFragment.java
│ │ ├── DemoLikeMediumActivity.java
│ │ ├── DemoRtlActivity.java
│ │ ├── DemoTabWithNotificationMarkActivity.java
│ │ ├── MainActivity.java
│ │ └── TintableImageView.java
│ └── res
│ ├── color
│ ├── custom_tab.xml
│ ├── custom_tab_icon.xml
│ └── custom_tab_like_a_medium.xml
│ ├── drawable-hdpi
│ ├── ic_flash_on_white_24dp.png
│ ├── ic_home_white_24dp.png
│ ├── ic_launcher.png
│ ├── ic_person_white_24dp.png
│ └── ic_search_white_24dp.png
│ ├── drawable-mdpi
│ ├── ic_flash_on_white_24dp.png
│ ├── ic_home_white_24dp.png
│ ├── ic_launcher.png
│ ├── ic_person_white_24dp.png
│ └── ic_search_white_24dp.png
│ ├── drawable-xhdpi
│ ├── ic_flash_on_white_24dp.png
│ ├── ic_home_white_24dp.png
│ ├── ic_launcher.png
│ ├── ic_person_white_24dp.png
│ └── ic_search_white_24dp.png
│ ├── drawable-xxhdpi
│ ├── ic_flash_on_white_24dp.png
│ ├── ic_home_white_24dp.png
│ ├── ic_launcher.png
│ ├── ic_person_white_24dp.png
│ └── ic_search_white_24dp.png
│ ├── drawable-xxxhdpi
│ ├── ic_flash_on_white_24dp.png
│ ├── ic_home_white_24dp.png
│ ├── ic_launcher.png
│ ├── ic_person_white_24dp.png
│ └── ic_search_white_24dp.png
│ ├── drawable
│ ├── custom_circle.xml
│ ├── custom_icon.xml
│ ├── custom_tab.xml
│ └── shape_notification_mark.xml
│ ├── layout
│ ├── activity_demo.xml
│ ├── activity_demo_tab_with_notification_mark.xml
│ ├── activity_like_a_medium.xml
│ ├── activity_main.xml
│ ├── activity_rtl.xml
│ ├── custom_tab.xml
│ ├── custom_tab_circle.xml
│ ├── custom_tab_icon1.xml
│ ├── custom_tab_icon2.xml
│ ├── custom_tab_icon_and_notification_mark.xml
│ ├── custom_tab_icon_and_text.xml
│ ├── custom_tab_like_a_medium.xml
│ ├── custom_tab_margin.xml
│ ├── demo_always_in_center.xml
│ ├── demo_basic.xml
│ ├── demo_basic_title_offset_auto_center.xml
│ ├── demo_custom_tab_colors.xml
│ ├── demo_custom_tab_icon_and_notification_mark.xml
│ ├── demo_custom_tab_icon_and_text.xml
│ ├── demo_custom_tab_icons1.xml
│ ├── demo_custom_tab_icons2.xml
│ ├── demo_custom_tab_margin.xml
│ ├── demo_custom_tab_text.xml
│ ├── demo_distribute_evenly.xml
│ ├── demo_indicator_trick1.xml
│ ├── demo_indicator_trick2.xml
│ ├── demo_like_a_medium_tag.xml
│ ├── demo_rtl.xml
│ ├── demo_smart_indicator.xml
│ └── fragment_demo.xml
│ ├── menu
│ ├── menu_demo.xml
│ └── menu_main.xml
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── dimens.xml
│ ├── ids.xml
│ ├── strings.xml
│ └── styles.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── LICENSE
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── ogaclejapan
│ │ └── smarttablayout
│ │ ├── SmartTabIndicationInterpolator.java
│ │ ├── SmartTabLayout.java
│ │ ├── SmartTabStrip.java
│ │ └── Utils.java
│ └── res
│ └── values
│ └── attrs.xml
├── publish.gradle
├── settings.gradle
└── utils-v4
├── .gitignore
├── LICENSE
├── build.gradle
├── proguard-rules.pro
└── src
└── main
├── AndroidManifest.xml
└── java
└── com
└── ogaclejapan
└── smarttablayout
└── utils
├── PagerItem.java
├── PagerItems.java
├── ViewPagerItem.java
├── ViewPagerItemAdapter.java
├── ViewPagerItems.java
└── v4
├── Bundler.java
├── FragmentPagerItem.java
├── FragmentPagerItemAdapter.java
├── FragmentPagerItems.java
└── FragmentStatePagerItemAdapter.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # https://github.com/github/gitignore
2 | # https://github.com/hsz/idea-gitignore
3 |
4 |
5 | ### JetBrains template
6 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
7 |
8 | *.iml
9 |
10 | ## Directory-based project format:
11 | .idea/
12 | # if you remove the above rule, at least ignore the following:
13 |
14 | # User-specific stuff:
15 | # .idea/workspace.xml
16 | # .idea/tasks.xml
17 | # .idea/dictionaries
18 |
19 | # Sensitive or high-churn files:
20 | # .idea/dataSources.ids
21 | # .idea/dataSources.xml
22 | # .idea/sqlDataSources.xml
23 | # .idea/dynamic.xml
24 | # .idea/uiDesigner.xml
25 |
26 | # Gradle:
27 | # .idea/gradle.xml
28 | # .idea/libraries
29 |
30 | # Mongo Explorer plugin:
31 | # .idea/mongoSettings.xml
32 |
33 | ## File-based project format:
34 | *.ipr
35 | *.iws
36 |
37 | ## Plugin-specific files:
38 |
39 | # IntelliJ
40 | /out/
41 |
42 | # mpeltonen/sbt-idea plugin
43 | .idea_modules/
44 |
45 | # JIRA plugin
46 | atlassian-ide-plugin.xml
47 |
48 | # Crashlytics plugin (for Android Studio and IntelliJ)
49 | com_crashlytics_export_strings.xml
50 | crashlytics.properties
51 | crashlytics-build.properties
52 |
53 |
54 | ### Android template
55 | # Built application files
56 | *.apk
57 | *.ap_
58 |
59 | # Files for the Dalvik VM
60 | *.dex
61 |
62 | # Java class files
63 | *.class
64 |
65 | # Generated files
66 | bin/
67 | gen/
68 |
69 | # Gradle files
70 | .gradle/
71 | build/
72 | /*/build/
73 |
74 | # Local configuration file (sdk path, etc)
75 | local.properties
76 |
77 | # Proguard folder generated by Eclipse
78 | proguard/
79 |
80 | # Log Files
81 | *.log
82 |
83 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Version 2.0.0
2 |
3 | * Migrate to androidx 1.0.0
4 | * Remove util-v13 library
5 |
6 | # Version 1.7.0
7 |
8 | * Update support library version to 28.0.0
9 | * Change target sdk version to 28
10 | * Change min sdk version to 14
11 | * Deprecated util-v13 library
12 |
13 | # Version 1.6.1
14 |
15 | * Fixed issue with center last item in always in center tablayout #160
16 |
17 | # Version 1.6.0
18 |
19 | * Add `stl_indicatorWidth` to custom indicator's width #106
20 |
21 | # Version 1.5.1
22 |
23 | * Fixed indicator position of auto_center #100
24 |
25 | # Version 1.5.0
26 |
27 | * Add `stl_drawDecorationAfterTab` attribute for change the drawing order #58
28 | * Add `stl_titleOffset` attribute for adjust the slide position #89
29 | * Fixed a condition code of onSizeChanged for always in center
30 |
31 | # Version 1.4.2
32 |
33 | * Change the call order of OnTabClickListener when press the tab #74
34 |
35 | # Version 1.4.1
36 |
37 | * Update android support library version to 22.2.1
38 |
39 | # Version 1.4.0
40 |
41 | * Add TabClickListener interface #68
42 |
43 | # Version 1.3.0
44 |
45 | * RTL support #48
46 | * Add `stl_clickable` attribute.
47 |
48 | # Version 1.2.3
49 |
50 | * Modify to ensure the first scroll #54
51 |
52 | # Version 1.2.2
53 |
54 | * Fix bug when indicatorAlwaysInCenter is true and tabHost has only two tabs #50
55 |
56 | # Version 1.2.1
57 |
58 | * Add custom ScrollListener interface #46
59 |
60 | # Version 1.2.0
61 |
62 | * Support the margin of each tab.
63 | * Add `stl_indicatorWithoutPadding` and `stl_indicatorGravity` attributes.
64 | * Add `stl_overlineColor` and `stl_overlineThickness` attributes.
65 |
66 | # Version 1.1.3
67 |
68 | * Allow to set the background on default tab #13
69 |
70 | # Version 1.1.2
71 |
72 | * Added setter for tab text colors #10
73 | * Allow to set a String title dynamically on PagerItems. #7
74 |
75 | # Version 1.1.1
76 |
77 | * Enable the format of ‘reference’ for defaultTextColor to support ColorStateList #3
78 |
79 | # Version 1.1.0
80 |
81 | * Supported Icon Tab. #1
82 |
83 |
84 | # Version 1.0.0
85 |
86 | * Initial release.
87 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | If you would like to contribute code to SmartTabLayout you can do so through GitHub by
4 | forking the repository and sending a pull request.
5 |
6 | When submitting code, please make every effort to follow existing conventions
7 | and style in order to keep the code as readable as possible.
8 |
9 | ## Coding Style
10 |
11 | * Use the AndroidModernStyle of [Android Code Styles](https://github.com/ogaclejapan/android-code-styles) repository
12 |
--------------------------------------------------------------------------------
/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 (C) 2015 ogaclejapan
191 | Copyright (C) 2013 The Android Open Source Project
192 |
193 | Licensed under the Apache License, Version 2.0 (the "License");
194 | you may not use this file except in compliance with the License.
195 | You may obtain a copy of the License at
196 |
197 | http://www.apache.org/licenses/LICENSE-2.0
198 |
199 | Unless required by applicable law or agreed to in writing, software
200 | distributed under the License is distributed on an "AS IS" BASIS,
201 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202 | See the License for the specific language governing permissions and
203 | limitations under the License.
204 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SmartTabLayout
2 | [![Maven Central][maven_central_badge_svg]][maven_central_badge_app] [![Android Arsenal][android_arsenal_badge_svg]][android_arsenal_badge_link] [![Android Weekly][android_weekly_badge_svg]][android_weekly_badge_link]
3 |
4 | ![icon][demo_icon]
5 |
6 | A custom ViewPager title strip which gives continuous feedback to the user when scrolling.
7 |
8 | This library has been added some features and utilities based on [android-SlidingTabBasic][google_slidingtabbasic] project of Google Samples.
9 |
10 |
11 | ![SmartTabLayout Demo1][demo1_gif] ![SmartTabLayout Demo2][demo2_gif]
12 | ![SmartTabLayout Demo3][demo3_gif] ![SmartTabLayout Demo4][demo4_gif]
13 | ![SmartTabLayout Demo5][demo5_gif] ![SmartTabLayout Demo6][demo6_gif]
14 | ![SmartTabLayout Demo7][demo7_gif]
15 |
16 |
17 | Try out the sample application on the Play Store.
18 |
19 | [![Get it on Google Play][googleplay_store_badge]][demo_app]
20 |
21 |
22 | # Usage
23 |
24 | _(For a working implementation of this project see the demo/ folder.)_
25 |
26 | Add the dependency to your build.gradle.
27 |
28 | ```
29 | // For androidx (1.0.0)
30 | dependencies {
31 | compile 'com.ogaclejapan.smarttablayout:library:2.0.0@aar'
32 |
33 | //Optional: see how to use the utility.
34 | compile 'com.ogaclejapan.smarttablayout:utils-v4:2.0.0@aar'
35 | }
36 |
37 | // For legacy android support library (28.0.0)
38 | dependencies {
39 | compile 'com.ogaclejapan.smarttablayout:library:1.7.0@aar'
40 |
41 | //Optional: see how to use the utility.
42 | compile 'com.ogaclejapan.smarttablayout:utils-v4:1.7.0@aar'
43 |
44 | //Deprecated since 1.7.0
45 | compile 'com.ogaclejapan.smarttablayout:utils-v13:1.7.0@aar'
46 | }
47 | ```
48 |
49 | Include the SmartTabLayout widget in your layout.
50 | This should usually be placed above the ViewPager it represents.
51 |
52 | ```xml
53 |
54 |
84 |
85 |
91 |
92 | ```
93 |
94 | In your onCreate method (or onCreateView for a fragment), bind the widget to the ViewPager.
95 | (If you use a utility together, you can easily add items to PagerAdapter)
96 |
97 | e.g. ViewPager of v4.Fragment
98 |
99 | ```java
100 |
101 | FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
102 | getSupportFragmentManager(), FragmentPagerItems.with(this)
103 | .add(R.string.titleA, PageFragment.class)
104 | .add(R.string.titleB, PageFragment.class)
105 | .create());
106 |
107 | ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
108 | viewPager.setAdapter(adapter);
109 |
110 | SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
111 | viewPagerTab.setViewPager(viewPager);
112 |
113 | ```
114 |
115 | (Optional) If you use an OnPageChangeListener with your view pager you should set it in the widget rather than on the pager directly.
116 |
117 |
118 | ```java
119 |
120 | viewPagerTab.setOnPageChangeListener(mPageChangeListener);
121 |
122 | ```
123 |
124 | (Optional) Using the FragmentPagerItemAdapter of utility, you will be able to get a position in the Fragment side.
125 |
126 | ```java
127 |
128 | int position = FragmentPagerItem.getPosition(getArguments());
129 |
130 | ```
131 |
132 | This position will help to implement the parallax scrolling header that contains the ViewPager :P
133 |
134 | # Attributes
135 |
136 | There are several attributes you can set:
137 |
138 | | attr | description |
139 | |:---|:---|
140 | | stl_indicatorAlwaysInCenter | If set to true, active tab is always displayed in center (Like Newsstand google app), default false |
141 | | stl_indicatorWithoutPadding | If set to true, draw the indicator without padding of tab, default false |
142 | | stl_indicatorInFront | Draw the indicator in front of the underline, default false |
143 | | stl_indicatorInterpolation | Behavior of the indicator: 'linear' or 'smart' |
144 | | stl_indicatorGravity | Drawing position of the indicator: 'bottom' or 'top' or 'center', default 'bottom' |
145 | | stl_indicatorColor | Color of the indicator |
146 | | stl_indicatorColors | Multiple colors of the indicator, can set the color for each tab |
147 | | stl_indicatorThickness | Thickness of the indicator |
148 | | stl_indicatorWidth | Width of the indicator, default 'auto' |
149 | | stl_indicatorCornerRadius | Radius of rounded corner the indicator |
150 | | stl_overlineColor | Color of the top line |
151 | | stl_overlineThickness | Thickness of the top line |
152 | | stl_underlineColor | Color of the bottom line |
153 | | stl_underlineThickness | Thickness of the bottom line |
154 | | stl_dividerColor | Color of the dividers between tabs |
155 | | stl_dividerColors | Multiple colors of the dividers between tabs, can set the color for each tab |
156 | | stl_dividerThickness | Thickness of the divider |
157 | | stl_defaultTabBackground | Background drawable of each tab. In general it set the StateListDrawable |
158 | | stl_defaultTabTextAllCaps | If set to true, all tab titles will be upper case, default true |
159 | | stl_defaultTabTextColor | Text color of the tab that was included by default |
160 | | stl_defaultTabTextSize | Text size of the tab that was included by default |
161 | | stl_defaultTabTextHorizontalPadding | Text layout padding of the tab that was included by default |
162 | | stl_defaultTabTextMinWidth | Minimum width of tab |
163 | | stl_customTabTextLayoutId | Layout ID defined custom tab. If you do not specify a layout, use the default tab |
164 | | stl_customTabTextViewId | Text view ID in a custom tab layout. If you do not define with customTabTextLayoutId, does not work |
165 | | stl_distributeEvenly | If set to true, each tab is given the same weight, default false |
166 | | stl_clickable | If set to false, disable the selection of a tab click, default true |
167 | | stl_titleOffset | If set to 'auto_center', the slide position of the tab in the middle it will keep to the center. If specify a dimension it will be offset from the left edge, default 24dp |
168 | | stl_drawDecorationAfterTab | Draw the decoration(indicator and lines) after drawing of tab, default false |
169 |
170 | *__Notes:__ Both 'stl_indicatorAlwaysInCenter' and 'stl_distributeEvenly' if it is set to true, it will throw UnsupportedOperationException.*
171 |
172 | # How to customize the tab
173 |
174 | The customization of tab There are three ways.
175 |
176 | * Customize the attribute
177 | * SmartTabLayout#setCustomTabView(int layoutResId, int textViewId)
178 | * SmartTabLayout#setCustomTabView(TabProvider provider)
179 |
180 | If set the TabProvider, can build a view for each tab.
181 |
182 | ```java
183 |
184 | public class SmartTabLayout extends HorizontalScrollView {
185 |
186 | //...
187 |
188 | /**
189 | * Create the custom tabs in the tab layout. Set with
190 | * {@link #setCustomTabView(com.ogaclejapan.smarttablayout.SmartTabLayout.TabProvider)}
191 | */
192 | public interface TabProvider {
193 |
194 | /**
195 | * @return Return the View of {@code position} for the Tabs
196 | */
197 | View createTabView(ViewGroup container, int position, PagerAdapter adapter);
198 |
199 | }
200 |
201 | //...
202 | }
203 |
204 | ```
205 |
206 | # How to use the utility
207 |
208 | Utility has two types available to suit the Android support library.
209 |
210 | * utils-v4 library contains the PagerAdapter implementation class for _androidx.fragment.app.Fragment_
211 | * (Deprecated) utils-v13 library contains the PagerAdapter implementation class for _android.app.Fragment_
212 |
213 | The two libraries have different Android support libraries that depend,
214 | but implemented functionality is the same.
215 |
216 | ## PagerAdapter for View-based Page
217 |
218 | ```java
219 |
220 | ViewPagerItemAdapter adapter = new ViewPagerItemAdapter(ViewPagerItems.with(this)
221 | .add(R.string.title, R.layout.page)
222 | .add("title", R.layout.page)
223 | .create());
224 |
225 | viewPager.setAdapter(adapter);
226 |
227 | //...
228 |
229 | public void onPageSelected(int position) {
230 |
231 | //.instantiateItem() from until .destroyItem() is called it will be able to get the View of page.
232 | View page = adapter.getPage(position);
233 |
234 | }
235 |
236 |
237 | ```
238 |
239 | ## PagerAdapter for Fragment-based Page
240 |
241 | Fragment-based PagerAdapter There are two implementations.
242 | Please differences refer to the library documentation for Android.
243 |
244 | * FragmentPagerItemAdapter extends FragmentPagerAdapter
245 | * FragmentStatePagerItemAdapter extends FragmentStatePagerAdapter
246 |
247 | ```java
248 |
249 | FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
250 | getSupportFragmentManager(), FragmentPagerItems.with(this)
251 | .add(R.string.title, PageFragment.class),
252 | .add(R.string.title, WithArgumentsPageFragment.class, new Bundler().putString("key", "value").get()),
253 | .add("title", PageFragment.class)
254 | .create());
255 |
256 | viewPager.setAdapter(adapter);
257 |
258 | //...
259 |
260 | public void onPageSelected(int position) {
261 |
262 | //.instantiateItem() from until .destoryItem() is called it will be able to get the Fragment of page.
263 | Fragment page = adapter.getPage(position);
264 |
265 | }
266 |
267 | ```
268 |
269 | *__Notes:__ If using fragment inside a ViewPager, Must be use [Fragment#getChildFragmentManager()](https://developer.android.com/reference/androidx/fragment/app/Fragment.html#getChildFragmentManager).*
270 |
271 |
272 | # Looking for iOS ?
273 | Check [WormTabStrip](https://github.com/EzimetYusup/WormTabStrip) out.
274 |
275 | # LICENSE
276 |
277 | ```
278 | Copyright (C) 2015 ogaclejapan
279 | Copyright (C) 2013 The Android Open Source Project
280 |
281 | Licensed under the Apache License, Version 2.0 (the "License");
282 | you may not use this file except in compliance with the License.
283 | You may obtain a copy of the License at
284 |
285 | http://www.apache.org/licenses/LICENSE-2.0
286 |
287 | Unless required by applicable law or agreed to in writing, software
288 | distributed under the License is distributed on an "AS IS" BASIS,
289 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
290 | See the License for the specific language governing permissions and
291 | limitations under the License.
292 | ```
293 |
294 | [demo1_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo1.gif
295 | [demo2_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo2.gif
296 | [demo3_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo3.gif
297 | [demo4_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo4.gif
298 | [demo5_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo5.gif
299 | [demo6_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo6.gif
300 | [demo7_gif]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/demo7.gif
301 | [demo_app]: https://play.google.com/store/apps/details?id=com.ogaclejapan.smarttablayout.demo&referrer=utm_source%3Dgithub
302 | [demo_icon]: https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/master/art/icon.png
303 | [googleplay_store_badge]: http://www.android.com/images/brand/get_it_on_play_logo_large.png
304 | [maven_central_badge_svg]: https://maven-badges.herokuapp.com/maven-central/com.ogaclejapan.smarttablayout/library/badge.svg?style=flat
305 | [maven_central_badge_app]: https://maven-badges.herokuapp.com/maven-central/com.ogaclejapan.smarttablayout/library
306 | [android_arsenal_badge_svg]: https://img.shields.io/badge/Android%20Arsenal-SmartTabLayout-brightgreen.svg?style=flat
307 | [android_arsenal_badge_link]: http://android-arsenal.com/details/1/1683
308 | [android_weekly_badge_svg]: https://img.shields.io/badge/AndroidWeekly-%23148-blue.svg
309 | [android_weekly_badge_link]: http://androidweekly.net/issues/issue-148
310 | [qiitanium]: https://github.com/ogaclejapan/Qiitanium
311 | [google_slidingtabbasic]: https://github.com/googlesamples/android-SlidingTabsBasic
312 |
--------------------------------------------------------------------------------
/art/demo1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/art/demo1.gif
--------------------------------------------------------------------------------
/art/demo2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/art/demo2.gif
--------------------------------------------------------------------------------
/art/demo3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/art/demo3.gif
--------------------------------------------------------------------------------
/art/demo4.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/art/demo4.gif
--------------------------------------------------------------------------------
/art/demo5.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/art/demo5.gif
--------------------------------------------------------------------------------
/art/demo6.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/art/demo6.gif
--------------------------------------------------------------------------------
/art/demo7.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/art/demo7.gif
--------------------------------------------------------------------------------
/art/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/art/icon.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | ext {
3 | // Package information for bintray
4 | pkginfo = [name : ARTIFACT_NAME,
5 | description: ARTIFACT_DESCRIPTION,
6 | site : SITE_URL,
7 | issue : ISSUE_URL,
8 | vcs : SCM_URL]
9 | }
10 |
11 | buildscript {
12 | repositories {
13 | google()
14 | mavenCentral()
15 | maven {
16 | url "https://plugins.gradle.org/m2/"
17 | }
18 | jcenter()
19 | }
20 | dependencies {
21 | classpath 'com.android.tools.build:gradle:3.3.1'
22 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
23 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
24 | classpath 'com.github.ben-manes:gradle-versions-plugin:0.21.0'
25 | classpath 'gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.15.0'
26 |
27 | // NOTE: Do not place your application dependencies here; they belong
28 | // in the individual module build.gradle files
29 | }
30 | }
31 |
32 | allprojects {
33 |
34 | version = VERSION_NAME
35 | group = GROUP
36 |
37 | repositories {
38 | google()
39 | mavenCentral()
40 | jcenter()
41 | }
42 | }
43 |
44 | task clean(type: Delete) {
45 | delete rootProject.buildDir
46 | }
47 |
--------------------------------------------------------------------------------
/demo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/demo/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion COMPILE_SDK_VERSION as int
5 |
6 | defaultConfig {
7 | minSdkVersion 14
8 | targetSdkVersion COMPILE_SDK_VERSION as int
9 | versionCode VERSION_CODE as int
10 | versionName VERSION_NAME
11 | }
12 |
13 | def secretFile = file("${rootDir}/secret.gradle")
14 | if (secretFile.exists()) {
15 | apply from: secretFile.absolutePath
16 | signingConfigs {
17 | release {
18 | storeFile project.ext.storeFile
19 | storePassword project.ext.storePassword
20 | keyAlias project.ext.keyAlias
21 | keyPassword project.ext.keyPassword
22 | }
23 | }
24 | }
25 |
26 | buildTypes {
27 | release {
28 | if (secretFile.exists()) {
29 | signingConfig signingConfigs.release
30 | }
31 | minifyEnabled false
32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33 | }
34 | }
35 | }
36 |
37 | dependencies {
38 | implementation project(':library')
39 | implementation project(':utils-v4')
40 | implementation "androidx.appcompat:appcompat:${ANDROIDX_APPCOMPAT_VERSION}"
41 | }
42 |
--------------------------------------------------------------------------------
/demo/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/msk/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/demo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
31 |
32 |
38 |
39 |
45 |
46 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/ogaclejapan/smarttablayout/demo/Demo.java:
--------------------------------------------------------------------------------
1 | package com.ogaclejapan.smarttablayout.demo;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ImageView;
9 |
10 | import com.ogaclejapan.smarttablayout.SmartTabLayout;
11 |
12 | import androidx.viewpager.widget.PagerAdapter;
13 |
14 | public enum Demo {
15 |
16 | BASIC(R.string.demo_title_basic, R.layout.demo_basic),
17 |
18 | BASIC2(R.string.demo_title_basic2, R.layout.demo_basic_title_offset_auto_center),
19 |
20 | SMART_INDICATOR(R.string.demo_title_smart_indicator, R.layout.demo_smart_indicator),
21 |
22 | DISTRIBUTE_EVENLY(R.string.demo_title_distribute_evenly, R.layout.demo_distribute_evenly) {
23 | @Override
24 | public int[] tabs() {
25 | return tab3();
26 | }
27 | },
28 |
29 | ALWAYS_IN_CENTER(R.string.demo_title_always_in_center, R.layout.demo_always_in_center),
30 |
31 | CUSTOM_TAB(R.string.demo_title_custom_tab_text, R.layout.demo_custom_tab_text),
32 |
33 | CUSTOM_TAB_COLORS(R.string.demo_title_custom_tab_colors, R.layout.demo_custom_tab_colors),
34 |
35 | CUSTOM_TAB_ICONS1(R.string.demo_title_custom_tab_icons1, R.layout.demo_custom_tab_icons1) {
36 | @Override
37 | public int[] tabs() {
38 | return new int[] {
39 | R.string.demo_tab_no_title,
40 | R.string.demo_tab_no_title,
41 | R.string.demo_tab_no_title,
42 | R.string.demo_tab_no_title
43 | };
44 | }
45 |
46 | @Override
47 | public void setup(SmartTabLayout layout) {
48 | super.setup(layout);
49 |
50 | final LayoutInflater inflater = LayoutInflater.from(layout.getContext());
51 | final Resources res = layout.getContext().getResources();
52 |
53 | layout.setCustomTabView(new SmartTabLayout.TabProvider() {
54 | @Override
55 | public View createTabView(ViewGroup container, int position, PagerAdapter adapter) {
56 | ImageView icon = (ImageView) inflater.inflate(R.layout.custom_tab_icon1, container,
57 | false);
58 | switch (position) {
59 | case 0:
60 | icon.setImageDrawable(res.getDrawable(R.drawable.ic_home_white_24dp));
61 | break;
62 | case 1:
63 | icon.setImageDrawable(res.getDrawable(R.drawable.ic_search_white_24dp));
64 | break;
65 | case 2:
66 | icon.setImageDrawable(res.getDrawable(R.drawable.ic_person_white_24dp));
67 | break;
68 | case 3:
69 | icon.setImageDrawable(res.getDrawable(R.drawable.ic_flash_on_white_24dp));
70 | break;
71 | default:
72 | throw new IllegalStateException("Invalid position: " + position);
73 | }
74 | return icon;
75 | }
76 | });
77 | }
78 | },
79 |
80 | CUSTOM_TAB_ICONS2(R.string.demo_title_custom_tab_icons2, R.layout.demo_custom_tab_icons2) {
81 | @Override
82 | public int[] tabs() {
83 | return new int[] {
84 | R.string.demo_tab_no_title,
85 | R.string.demo_tab_no_title,
86 | R.string.demo_tab_no_title,
87 | R.string.demo_tab_no_title
88 | };
89 | }
90 |
91 | @Override
92 | public void setup(SmartTabLayout layout) {
93 | super.setup(layout);
94 |
95 | final LayoutInflater inflater = LayoutInflater.from(layout.getContext());
96 | final Resources res = layout.getContext().getResources();
97 |
98 | layout.setCustomTabView(new SmartTabLayout.TabProvider() {
99 | @Override
100 | public View createTabView(ViewGroup container, int position, PagerAdapter adapter) {
101 | ImageView icon = (ImageView) inflater.inflate(R.layout.custom_tab_icon2, container,
102 | false);
103 | switch (position) {
104 | case 0:
105 | icon.setImageDrawable(res.getDrawable(R.drawable.ic_home_white_24dp));
106 | break;
107 | case 1:
108 | icon.setImageDrawable(res.getDrawable(R.drawable.ic_search_white_24dp));
109 | break;
110 | case 2:
111 | icon.setImageDrawable(res.getDrawable(R.drawable.ic_person_white_24dp));
112 | break;
113 | case 3:
114 | icon.setImageDrawable(res.getDrawable(R.drawable.ic_flash_on_white_24dp));
115 | break;
116 | default:
117 | throw new IllegalStateException("Invalid position: " + position);
118 | }
119 | return icon;
120 | }
121 | });
122 | }
123 | },
124 |
125 | CUSTOM_TAB_ICON_AND_TEXT(R.string.demo_title_custom_tab_icon_and_text,
126 | R.layout.demo_custom_tab_icon_and_text) {
127 | @Override
128 | public int[] tabs() {
129 | return tab3();
130 | }
131 | },
132 |
133 | CUSTOM_TAB_ICON_AND_NOTIFICATION_MARK(R.string.demo_title_custom_tab_icon_and_notification_mark,
134 | R.layout.demo_custom_tab_icon_and_notification_mark) {
135 | @Override
136 | public int[] tabs() {
137 | return tab3();
138 | }
139 |
140 | @Override
141 | public void startActivity(Context context) {
142 | DemoTabWithNotificationMarkActivity.startActivity(context, this);
143 | }
144 | },
145 |
146 | CUSTOM_TAB_MARGIN(R.string.demo_title_custom_tab_margin, R.layout.demo_custom_tab_margin),
147 |
148 | INDICATOR_TRICK1(R.string.demo_title_indicator_trick1, R.layout.demo_indicator_trick1),
149 |
150 | INDICATOR_TRICK2(R.string.demo_title_indicator_trick2, R.layout.demo_indicator_trick2),
151 |
152 | RIGHT_TO_LEFT(R.string.demo_title_right_to_left, R.layout.demo_rtl) {
153 | @Override
154 | public void startActivity(Context context) {
155 | DemoRtlActivity.startActivity(context, this);
156 | }
157 | },
158 |
159 | LIKE_MEDIUM_TAG(R.string.demo_title_advanced_medium, R.layout.demo_like_a_medium_tag) {
160 | @Override
161 | public int[] tabs() {
162 | return new int[] {
163 | R.string.demo_tab_like_a_medium_top,
164 | R.string.demo_tab_like_a_medium_latest
165 | };
166 | }
167 |
168 | @Override
169 | public void startActivity(Context context) {
170 | DemoLikeMediumActivity.startActivity(context, this);
171 | }
172 | };
173 |
174 | public final int titleResId;
175 | public final int layoutResId;
176 |
177 | Demo(int titleResId, int layoutResId) {
178 | this.titleResId = titleResId;
179 | this.layoutResId = layoutResId;
180 | }
181 |
182 | public static int[] tab10() {
183 | return new int[] {
184 | R.string.demo_tab_1,
185 | R.string.demo_tab_2,
186 | R.string.demo_tab_3,
187 | R.string.demo_tab_4,
188 | R.string.demo_tab_5,
189 | R.string.demo_tab_6,
190 | R.string.demo_tab_7,
191 | R.string.demo_tab_8,
192 | R.string.demo_tab_9,
193 | R.string.demo_tab_10
194 | };
195 | }
196 |
197 | public static int[] tab3() {
198 | return new int[] {
199 | R.string.demo_tab_8,
200 | R.string.demo_tab_9,
201 | R.string.demo_tab_10
202 | };
203 | }
204 |
205 | public void startActivity(Context context) {
206 | DemoActivity.startActivity(context, this);
207 | }
208 |
209 | public void setup(final SmartTabLayout layout) {
210 | //Do nothing.
211 | }
212 |
213 | public int[] tabs() {
214 | return tab10();
215 | }
216 |
217 | }
218 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/ogaclejapan/smarttablayout/demo/DemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.ogaclejapan.smarttablayout.demo;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.ViewGroup;
8 |
9 | import com.ogaclejapan.smarttablayout.SmartTabLayout;
10 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItem;
11 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
12 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;
13 |
14 | import androidx.appcompat.app.AppCompatActivity;
15 | import androidx.appcompat.widget.Toolbar;
16 | import androidx.viewpager.widget.ViewPager;
17 |
18 | public class DemoActivity extends AppCompatActivity {
19 |
20 | private static final String KEY_DEMO = "demo";
21 |
22 | public static void startActivity(Context context, Demo demo) {
23 | Intent intent = new Intent(context, DemoActivity.class);
24 | intent.putExtra(KEY_DEMO, demo.name());
25 | context.startActivity(intent);
26 | }
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_demo);
32 |
33 | Demo demo = getDemo();
34 |
35 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
36 | toolbar.setTitle(demo.titleResId);
37 | setSupportActionBar(toolbar);
38 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
39 |
40 | ViewGroup tab = (ViewGroup) findViewById(R.id.tab);
41 | tab.addView(LayoutInflater.from(this).inflate(demo.layoutResId, tab, false));
42 |
43 | ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
44 | SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
45 | demo.setup(viewPagerTab);
46 |
47 | FragmentPagerItems pages = new FragmentPagerItems(this);
48 | for (int titleResId : demo.tabs()) {
49 | pages.add(FragmentPagerItem.of(getString(titleResId), DemoFragment.class));
50 | }
51 |
52 | FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
53 | getSupportFragmentManager(), pages);
54 |
55 | viewPager.setAdapter(adapter);
56 | viewPagerTab.setViewPager(viewPager);
57 |
58 | }
59 |
60 | private Demo getDemo() {
61 | return Demo.valueOf(getIntent().getStringExtra(KEY_DEMO));
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/ogaclejapan/smarttablayout/demo/DemoFragment.java:
--------------------------------------------------------------------------------
1 | package com.ogaclejapan.smarttablayout.demo;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItem;
10 |
11 | import androidx.annotation.Nullable;
12 | import androidx.fragment.app.Fragment;
13 |
14 | public class DemoFragment extends Fragment {
15 |
16 | @Override
17 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
18 | @Nullable Bundle savedInstanceState) {
19 | return inflater.inflate(R.layout.fragment_demo, container, false);
20 | }
21 |
22 | @Override
23 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
24 | super.onViewCreated(view, savedInstanceState);
25 | int position = FragmentPagerItem.getPosition(getArguments());
26 | TextView title = (TextView) view.findViewById(R.id.item_title);
27 | title.setText(String.valueOf(position));
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/ogaclejapan/smarttablayout/demo/DemoLikeMediumActivity.java:
--------------------------------------------------------------------------------
1 | package com.ogaclejapan.smarttablayout.demo;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.ViewGroup;
8 |
9 | import com.ogaclejapan.smarttablayout.SmartTabLayout;
10 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItem;
11 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
12 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;
13 |
14 | import androidx.appcompat.app.AppCompatActivity;
15 | import androidx.appcompat.widget.Toolbar;
16 | import androidx.viewpager.widget.ViewPager;
17 |
18 | public class DemoLikeMediumActivity extends AppCompatActivity {
19 |
20 | private static final String KEY_DEMO = "demo";
21 |
22 | public static void startActivity(Context context, Demo demo) {
23 | Intent intent = new Intent(context, DemoLikeMediumActivity.class);
24 | intent.putExtra(KEY_DEMO, demo.name());
25 | context.startActivity(intent);
26 | }
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_like_a_medium);
32 |
33 | Demo demo = getDemo();
34 |
35 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
36 | toolbar.setTitle(demo.titleResId);
37 | setSupportActionBar(toolbar);
38 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
39 |
40 | ViewGroup tab = (ViewGroup) findViewById(R.id.tab);
41 | tab.addView(LayoutInflater.from(this).inflate(demo.layoutResId, tab, false));
42 |
43 | ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
44 | SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
45 | demo.setup(viewPagerTab);
46 |
47 | FragmentPagerItems pages = new FragmentPagerItems(this);
48 | for (int titleResId : demo.tabs()) {
49 | pages.add(FragmentPagerItem.of(getString(titleResId), DemoFragment.class));
50 | }
51 |
52 | FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
53 | getSupportFragmentManager(), pages);
54 |
55 | viewPager.setAdapter(adapter);
56 | viewPagerTab.setViewPager(viewPager);
57 |
58 | }
59 |
60 | private Demo getDemo() {
61 | return Demo.valueOf(getIntent().getStringExtra(KEY_DEMO));
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/ogaclejapan/smarttablayout/demo/DemoRtlActivity.java:
--------------------------------------------------------------------------------
1 | package com.ogaclejapan.smarttablayout.demo;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.ViewGroup;
8 |
9 | import com.ogaclejapan.smarttablayout.SmartTabLayout;
10 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItem;
11 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
12 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;
13 |
14 | import androidx.appcompat.app.AppCompatActivity;
15 | import androidx.appcompat.widget.Toolbar;
16 | import androidx.viewpager.widget.ViewPager;
17 |
18 | public class DemoRtlActivity extends AppCompatActivity {
19 |
20 | private static final String KEY_DEMO = "demo";
21 |
22 | public static void startActivity(Context context, Demo demo) {
23 | Intent intent = new Intent(context, DemoRtlActivity.class);
24 | intent.putExtra(KEY_DEMO, demo.name());
25 | context.startActivity(intent);
26 | }
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_rtl);
32 |
33 | Demo demo = getDemo();
34 |
35 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
36 | toolbar.setTitle(demo.titleResId);
37 | setSupportActionBar(toolbar);
38 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
39 |
40 | ViewGroup tab = (ViewGroup) findViewById(R.id.tab);
41 | tab.addView(LayoutInflater.from(this).inflate(demo.layoutResId, tab, false));
42 |
43 | ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
44 | final SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
45 | demo.setup(viewPagerTab);
46 |
47 | FragmentPagerItems pages = new FragmentPagerItems(this);
48 | for (int titleResId : demo.tabs()) {
49 | pages.add(FragmentPagerItem.of(getString(titleResId), DemoFragment.class));
50 | }
51 |
52 | FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
53 | getSupportFragmentManager(), pages);
54 |
55 | viewPager.setAdapter(adapter);
56 | viewPagerTab.setViewPager(viewPager);
57 |
58 | }
59 |
60 | private Demo getDemo() {
61 | return Demo.valueOf(getIntent().getStringExtra(KEY_DEMO));
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/ogaclejapan/smarttablayout/demo/DemoTabWithNotificationMarkActivity.java:
--------------------------------------------------------------------------------
1 | package com.ogaclejapan.smarttablayout.demo;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.res.Resources;
6 | import android.os.Bundle;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.ImageView;
11 |
12 | import com.ogaclejapan.smarttablayout.SmartTabLayout;
13 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItem;
14 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
15 | import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;
16 |
17 | import java.util.Random;
18 |
19 | import androidx.appcompat.app.AppCompatActivity;
20 | import androidx.appcompat.widget.Toolbar;
21 | import androidx.viewpager.widget.PagerAdapter;
22 | import androidx.viewpager.widget.ViewPager;
23 |
24 | public class DemoTabWithNotificationMarkActivity extends AppCompatActivity implements
25 | SmartTabLayout.TabProvider {
26 |
27 | private static final String KEY_DEMO = "demo";
28 |
29 | public static void startActivity(Context context, Demo demo) {
30 | Intent intent = new Intent(context, DemoTabWithNotificationMarkActivity.class);
31 | intent.putExtra(KEY_DEMO, demo.name());
32 | context.startActivity(intent);
33 | }
34 |
35 | private Random random = new Random(System.currentTimeMillis());
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_demo_tab_with_notification_mark);
41 |
42 | final Demo demo = getDemo();
43 |
44 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
45 | toolbar.setTitle(demo.titleResId);
46 | setSupportActionBar(toolbar);
47 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
48 |
49 | ViewGroup tab = (ViewGroup) findViewById(R.id.tab);
50 | tab.addView(LayoutInflater.from(this).inflate(demo.layoutResId, tab, false));
51 |
52 | ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
53 | final SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
54 | viewPagerTab.setCustomTabView(this);
55 |
56 | FragmentPagerItems pages = new FragmentPagerItems(this);
57 | for (int titleResId : demo.tabs()) {
58 | pages.add(FragmentPagerItem.of(getString(titleResId), DemoFragment.class));
59 | }
60 |
61 | FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
62 | getSupportFragmentManager(), pages);
63 |
64 | viewPager.setAdapter(adapter);
65 | viewPagerTab.setViewPager(viewPager);
66 |
67 | viewPagerTab.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
68 | @Override
69 | public void onPageSelected(int position) {
70 | super.onPageSelected(position);
71 | View tab = viewPagerTab.getTabAt(position);
72 | View mark = tab.findViewById(R.id.custom_tab_notification_mark);
73 | mark.setVisibility(View.GONE);
74 | }
75 | });
76 |
77 | findViewById(R.id.test).setOnClickListener(new View.OnClickListener() {
78 | @Override
79 | public void onClick(View v) {
80 | int position = Math.abs(random.nextInt()) % demo.tabs().length;
81 | View tab = viewPagerTab.getTabAt(position);
82 | View mark = tab.findViewById(R.id.custom_tab_notification_mark);
83 | mark.setVisibility(View.VISIBLE);
84 | }
85 | });
86 |
87 | }
88 |
89 | @Override
90 | public View createTabView(ViewGroup container, int position, PagerAdapter adapter) {
91 | LayoutInflater inflater = LayoutInflater.from(container.getContext());
92 | Resources res = container.getContext().getResources();
93 | View tab = inflater.inflate(R.layout.custom_tab_icon_and_notification_mark, container, false);
94 | View mark = tab.findViewById(R.id.custom_tab_notification_mark);
95 | mark.setVisibility(View.GONE);
96 | ImageView icon = (ImageView) tab.findViewById(R.id.custom_tab_icon);
97 | switch (position) {
98 | case 0:
99 | icon.setImageDrawable(res.getDrawable(R.drawable.ic_home_white_24dp));
100 | break;
101 | case 1:
102 | icon.setImageDrawable(res.getDrawable(R.drawable.ic_search_white_24dp));
103 | break;
104 | case 2:
105 | icon.setImageDrawable(res.getDrawable(R.drawable.ic_person_white_24dp));
106 | break;
107 | default:
108 | throw new IllegalStateException("Invalid position: " + position);
109 | }
110 | return tab;
111 | }
112 |
113 | private Demo getDemo() {
114 | return Demo.valueOf(getIntent().getStringExtra(KEY_DEMO));
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/ogaclejapan/smarttablayout/demo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.ogaclejapan.smarttablayout.demo;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.view.View;
9 | import android.widget.AbsListView;
10 | import android.widget.AdapterView;
11 | import android.widget.ArrayAdapter;
12 | import android.widget.ListView;
13 |
14 | import androidx.appcompat.app.AppCompatActivity;
15 |
16 | public class MainActivity extends AppCompatActivity implements AbsListView.OnItemClickListener {
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 | ListView listView = (ListView) findViewById(R.id.list);
23 | listView.setOnItemClickListener(this);
24 |
25 | ArrayAdapter demoAdapter = new ArrayAdapter(this,
26 | android.R.layout.simple_list_item_1);
27 |
28 | for (Demo demo : Demo.values()) {
29 | demoAdapter.add(getString(demo.titleResId));
30 | }
31 |
32 | listView.setAdapter(demoAdapter);
33 | }
34 |
35 | @Override
36 | public boolean onCreateOptionsMenu(Menu menu) {
37 | getMenuInflater().inflate(R.menu.menu_main, menu);
38 | return super.onCreateOptionsMenu(menu);
39 | }
40 |
41 | @Override
42 | public boolean onOptionsItemSelected(MenuItem item) {
43 | switch (item.getItemId()) {
44 | case R.id.menu_github:
45 | openGitHub();
46 | return true;
47 | default:
48 | return super.onOptionsItemSelected(item);
49 | }
50 | }
51 |
52 | @Override
53 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
54 | Demo demo = Demo.values()[position];
55 | demo.startActivity(this);
56 | }
57 |
58 | private void openGitHub() {
59 | Uri uri = Uri.parse(getString(R.string.app_github_url));
60 | Intent intent = new Intent(Intent.ACTION_VIEW, uri);
61 | startActivity(intent);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/demo/src/main/java/com/ogaclejapan/smarttablayout/demo/TintableImageView.java:
--------------------------------------------------------------------------------
1 | package com.ogaclejapan.smarttablayout.demo;
2 |
3 | import android.content.Context;
4 | import android.content.res.ColorStateList;
5 | import android.content.res.TypedArray;
6 | import android.util.AttributeSet;
7 |
8 | import androidx.appcompat.widget.AppCompatImageView;
9 |
10 | /**
11 | * https://gist.github.com/tylerchesley/5d15d859be4f3ce31213
12 | */
13 | public class TintableImageView extends AppCompatImageView {
14 |
15 | private ColorStateList tint;
16 |
17 | public TintableImageView(Context context) {
18 | super(context);
19 | }
20 |
21 | public TintableImageView(Context context, AttributeSet attrs) {
22 | super(context, attrs);
23 | init(context, attrs, 0);
24 | }
25 |
26 | public TintableImageView(Context context, AttributeSet attrs, int defStyle) {
27 | super(context, attrs, defStyle);
28 | init(context, attrs, defStyle);
29 | }
30 |
31 | private void init(Context context, AttributeSet attrs, int defStyle) {
32 | TypedArray a = context.obtainStyledAttributes(
33 | attrs, R.styleable.TintableImageView, defStyle, 0);
34 | tint = a.getColorStateList(
35 | R.styleable.TintableImageView_tint);
36 | a.recycle();
37 | }
38 |
39 | @Override
40 | protected void drawableStateChanged() {
41 | super.drawableStateChanged();
42 | if (tint != null && tint.isStateful()) {
43 | updateTintColor();
44 | }
45 | }
46 |
47 | public void setColorFilter(ColorStateList tint) {
48 | this.tint = tint;
49 | super.setColorFilter(tint.getColorForState(getDrawableState(), 0));
50 | }
51 |
52 | private void updateTintColor() {
53 | int color = tint.getColorForState(getDrawableState(), 0);
54 | setColorFilter(color);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/demo/src/main/res/color/custom_tab.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/demo/src/main/res/color/custom_tab_icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/demo/src/main/res/color/custom_tab_like_a_medium.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-hdpi/ic_flash_on_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-hdpi/ic_flash_on_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-hdpi/ic_home_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-hdpi/ic_home_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-hdpi/ic_person_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-hdpi/ic_person_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-hdpi/ic_search_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-hdpi/ic_search_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-mdpi/ic_flash_on_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-mdpi/ic_flash_on_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-mdpi/ic_home_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-mdpi/ic_home_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-mdpi/ic_person_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-mdpi/ic_person_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-mdpi/ic_search_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-mdpi/ic_search_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xhdpi/ic_flash_on_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xhdpi/ic_flash_on_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xhdpi/ic_home_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xhdpi/ic_home_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xhdpi/ic_person_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xhdpi/ic_person_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xhdpi/ic_search_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xhdpi/ic_search_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xxhdpi/ic_flash_on_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xxhdpi/ic_flash_on_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xxhdpi/ic_home_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xxhdpi/ic_home_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xxhdpi/ic_person_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xxhdpi/ic_person_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xxhdpi/ic_search_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xxhdpi/ic_search_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xxxhdpi/ic_flash_on_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xxxhdpi/ic_flash_on_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xxxhdpi/ic_home_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xxxhdpi/ic_home_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xxxhdpi/ic_person_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xxxhdpi/ic_person_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable-xxxhdpi/ic_search_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/demo/src/main/res/drawable-xxxhdpi/ic_search_white_24dp.png
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/custom_circle.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/custom_icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/custom_tab.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/demo/src/main/res/drawable/shape_notification_mark.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_demo.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
15 |
16 |
24 |
25 |
26 |
27 |
32 |
33 |
34 |
35 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_demo_tab_with_notification_mark.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
15 |
16 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_like_a_medium.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
15 |
16 |
25 |
26 |
31 |
32 |
33 |
34 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/activity_rtl.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
16 |
17 |
25 |
26 |
31 |
32 |
33 |
34 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/custom_tab.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/custom_tab_circle.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/custom_tab_icon1.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/custom_tab_icon2.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/custom_tab_icon_and_notification_mark.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/custom_tab_icon_and_text.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
27 |
28 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/custom_tab_like_a_medium.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/custom_tab_margin.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_always_in_center.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_basic.xml:
--------------------------------------------------------------------------------
1 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_basic_title_offset_auto_center.xml:
--------------------------------------------------------------------------------
1 |
15 |
16 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_custom_tab_colors.xml:
--------------------------------------------------------------------------------
1 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_custom_tab_icon_and_notification_mark.xml:
--------------------------------------------------------------------------------
1 |
13 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_custom_tab_icon_and_text.xml:
--------------------------------------------------------------------------------
1 |
15 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_custom_tab_icons1.xml:
--------------------------------------------------------------------------------
1 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_custom_tab_icons2.xml:
--------------------------------------------------------------------------------
1 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_custom_tab_margin.xml:
--------------------------------------------------------------------------------
1 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_custom_tab_text.xml:
--------------------------------------------------------------------------------
1 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_distribute_evenly.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_indicator_trick1.xml:
--------------------------------------------------------------------------------
1 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_indicator_trick2.xml:
--------------------------------------------------------------------------------
1 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_like_a_medium_tag.xml:
--------------------------------------------------------------------------------
1 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_rtl.xml:
--------------------------------------------------------------------------------
1 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/demo_smart_indicator.xml:
--------------------------------------------------------------------------------
1 |
16 |
--------------------------------------------------------------------------------
/demo/src/main/res/layout/fragment_demo.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
16 |
17 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/demo/src/main/res/menu/menu_demo.xml:
--------------------------------------------------------------------------------
1 |
14 |
--------------------------------------------------------------------------------
/demo/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3C515C
4 | #142E3C
5 | #40C4FF
6 | #FFFFFFFF
7 | #FF000000
8 | #33000000
9 | #33FFFFFF
10 | #00000000
11 |
12 | #FFFFFFFF
13 | #4DFFFFFF
14 |
15 | #FFFFFFFF
16 | #FF63727B
17 |
18 | #FF000000
19 | #4D000000
20 |
21 | #03A9F4
22 | #00BCD4
23 | #009688
24 | #4CAF50
25 | #8BC34A
26 |
27 |
28 | @color/light_blue_500
29 | @color/cyan_500
30 | @color/teal_500
31 | @color/green_500
32 | @color/light_green_500
33 |
34 |
35 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 48dp
3 | 72dp
4 |
5 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SmartTabLayout
5 | GitHub
6 |
7 | Settings
8 |
9 | Basic
10 | Basic(Title Offset Auto Center)
11 | Smart Indicator
12 | Distribute Evenly
13 | Always In Center
14 | Custom Tab Text
15 | Custom Tab Margin (since 1.2~)
16 | Custom Tab Colors
17 | Custom Tab Icons 1
18 | Custom Tab Icons 2 (since 1.2~)
19 | Custom Tab Icon and Text
20 | Custom Tab Icon and Notification Mark
21 | Indicator Thickness Trick 1
22 | Indicator Thickness Trick 2
23 | RTL support
24 | Advanced: Like a Medium Tag (since 1.2~)
25 |
26 | Cupcake
27 | Donut
28 | Eclair
29 | Froyo
30 | Gingerbread
31 | Honeycomb
32 | Ice Cream Sandwich
33 | Jelly Bean
34 | KitKat
35 | Lollipop
36 |
37 | No Title
38 | Top
39 | Latest
40 |
41 |
42 |
--------------------------------------------------------------------------------
/demo/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | android.useAndroidX=true
2 |
3 | VERSION_NAME=2.0.0
4 | VERSION_CODE=18
5 | COMPILE_SDK_VERSION=28
6 | ANDROIDX_APPCOMPAT_VERSION=1.0.2
7 | ANDROIDX_BASE_VERSION=1.0.0
8 |
9 | GROUP=com.ogaclejapan.smarttablayout
10 | ARTIFACT_NAME=SmartTabLayout
11 | ARTIFACT_DESCRIPTION=A custom ViewPager title strip which gives continuous feedback to the user when scrolling
12 | SITE_URL=https://github.com/ogaclejapan/SmartTabLayout
13 | ISSUE_SYSTEM=github
14 | ISSUE_URL=https://github.com/ogaclejapan/SmartTabLayout/issues
15 | SCM_URL=https://github.com/ogaclejapan/SmartTabLayout
16 | SCM_CONNECTION=scm:git@github.com:ogaclejapan/SmartTabLayout.git
17 | SCM_DEV_CONNECTION=scm:git@github.com:ogaclejapan/SmartTabLayout.git
18 | LICENCE_NAME=The Apache Software License, Version 2.0
19 | LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
20 | LICENCE_DIST=repo
21 | DEVELOPER_ID=ogaclejapan
22 | DEVELOPER_NAME=Masaki Ogata
23 | DEVELOPER_EMAIL=ogaclejapan@gmail.com
24 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ogaclejapan/SmartTabLayout/712e81a92f1e12a3c33dcbda03d813e0162e8589/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Nov 27 17:23:04 JST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2015 ogaclejapan
2 | Copyright (C) 2013 The Android Open Source Project
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 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.ben-manes.versions'
3 | apply plugin: 'com.github.hierynomus.license'
4 |
5 | android {
6 | compileSdkVersion COMPILE_SDK_VERSION as int
7 | resourcePrefix 'stl_'
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion COMPILE_SDK_VERSION as int
12 | versionCode VERSION_CODE as int
13 | versionName VERSION_NAME
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation "androidx.viewpager:viewpager:${ANDROIDX_BASE_VERSION}"
26 | implementation "androidx.fragment:fragment:${ANDROIDX_BASE_VERSION}"
27 | }
28 |
29 | license {
30 |
31 | sourceSets {
32 | main.java.srcDirs = android.sourceSets.main.java.srcDirs
33 | main.resources.srcDirs = android.sourceSets.main.resources.srcDirs
34 | }
35 |
36 | excludes(["**/*.xml"])
37 |
38 | }
39 |
40 | pkginfo.name = ARTIFACT_NAME
41 | apply from: "${project.rootDir}/publish.gradle"
42 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/msk/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ogaclejapan/smarttablayout/SmartTabIndicationInterpolator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
3 | * Copyright (C) 2013 The Android Open Source Project
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.ogaclejapan.smarttablayout;
18 |
19 | import android.view.animation.AccelerateInterpolator;
20 | import android.view.animation.DecelerateInterpolator;
21 | import android.view.animation.Interpolator;
22 |
23 | public abstract class SmartTabIndicationInterpolator {
24 |
25 | public static final SmartTabIndicationInterpolator SMART = new SmartIndicationInterpolator();
26 | public static final SmartTabIndicationInterpolator LINEAR = new LinearIndicationInterpolator();
27 |
28 | static final int ID_SMART = 0;
29 | static final int ID_LINEAR = 1;
30 |
31 | public static SmartTabIndicationInterpolator of(int id) {
32 | switch (id) {
33 | case ID_SMART:
34 | return SMART;
35 | case ID_LINEAR:
36 | return LINEAR;
37 | default:
38 | throw new IllegalArgumentException("Unknown id: " + id);
39 | }
40 | }
41 |
42 | public abstract float getLeftEdge(float offset);
43 |
44 | public abstract float getRightEdge(float offset);
45 |
46 | public float getThickness(float offset) {
47 | return 1f; //Always the same thickness by default
48 | }
49 |
50 | public static class SmartIndicationInterpolator extends SmartTabIndicationInterpolator {
51 |
52 | private static final float DEFAULT_INDICATOR_INTERPOLATION_FACTOR = 3.0f;
53 |
54 | private final Interpolator leftEdgeInterpolator;
55 | private final Interpolator rightEdgeInterpolator;
56 |
57 | public SmartIndicationInterpolator() {
58 | this(DEFAULT_INDICATOR_INTERPOLATION_FACTOR);
59 | }
60 |
61 | public SmartIndicationInterpolator(float factor) {
62 | leftEdgeInterpolator = new AccelerateInterpolator(factor);
63 | rightEdgeInterpolator = new DecelerateInterpolator(factor);
64 | }
65 |
66 | @Override
67 | public float getLeftEdge(float offset) {
68 | return leftEdgeInterpolator.getInterpolation(offset);
69 | }
70 |
71 | @Override
72 | public float getRightEdge(float offset) {
73 | return rightEdgeInterpolator.getInterpolation(offset);
74 | }
75 |
76 | @Override
77 | public float getThickness(float offset) {
78 | return 1f / (1.0f - getLeftEdge(offset) + getRightEdge(offset));
79 | }
80 |
81 | }
82 |
83 | public static class LinearIndicationInterpolator extends SmartTabIndicationInterpolator {
84 |
85 | @Override
86 | public float getLeftEdge(float offset) {
87 | return offset;
88 | }
89 |
90 | @Override
91 | public float getRightEdge(float offset) {
92 | return offset;
93 | }
94 |
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ogaclejapan/smarttablayout/SmartTabLayout.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
3 | * Copyright (C) 2013 The Android Open Source Project
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.ogaclejapan.smarttablayout;
18 |
19 | import android.content.Context;
20 | import android.content.res.ColorStateList;
21 | import android.content.res.TypedArray;
22 | import android.graphics.Typeface;
23 | import android.os.Build;
24 | import android.util.AttributeSet;
25 | import android.util.DisplayMetrics;
26 | import android.util.TypedValue;
27 | import android.view.Gravity;
28 | import android.view.LayoutInflater;
29 | import android.view.View;
30 | import android.view.ViewGroup;
31 | import android.widget.HorizontalScrollView;
32 | import android.widget.LinearLayout;
33 | import android.widget.TextView;
34 |
35 | import androidx.core.view.ViewCompat;
36 | import androidx.viewpager.widget.PagerAdapter;
37 | import androidx.viewpager.widget.ViewPager;
38 |
39 | /**
40 | * To be used with ViewPager to provide a tab indicator component which give constant feedback as
41 | * to
42 | * the user's scroll progress.
43 | *
44 | * To use the component, simply add it to your view hierarchy. Then in your
45 | * {@link android.app.Activity} or {@link androidx.fragment.app.Fragment} call
46 | * {@link #setViewPager(ViewPager)} providing it the ViewPager this
47 | * layout
48 | * is being used for.
49 | *
50 | * The colors can be customized in two ways. The first and simplest is to provide an array of
51 | * colors
52 | * via {@link #setSelectedIndicatorColors(int...)} and {@link #setDividerColors(int...)}. The
53 | * alternative is via the {@link TabColorizer} interface which provides you complete control over
54 | * which color is used for any individual position.
55 | *
56 | * The views used as tabs can be customized by calling {@link #setCustomTabView(int, int)},
57 | * providing the layout ID of your custom layout.
58 | *
59 | * Forked from Google Samples > SlidingTabsBasic >
60 | * SlidingTabLayout
61 | */
62 | public class SmartTabLayout extends HorizontalScrollView {
63 |
64 | private static final boolean DEFAULT_DISTRIBUTE_EVENLY = false;
65 | private static final int TITLE_OFFSET_DIPS = 24;
66 | private static final int TITLE_OFFSET_AUTO_CENTER = -1;
67 | private static final int TAB_VIEW_PADDING_DIPS = 16;
68 | private static final boolean TAB_VIEW_TEXT_ALL_CAPS = true;
69 | private static final int TAB_VIEW_TEXT_SIZE_SP = 12;
70 | private static final int TAB_VIEW_TEXT_COLOR = 0xFC000000;
71 | private static final int TAB_VIEW_TEXT_MIN_WIDTH = 0;
72 | private static final boolean TAB_CLICKABLE = true;
73 |
74 | protected final SmartTabStrip tabStrip;
75 | private int titleOffset;
76 | private int tabViewBackgroundResId;
77 | private boolean tabViewTextAllCaps;
78 | private ColorStateList tabViewTextColors;
79 | private float tabViewTextSize;
80 | private int tabViewTextHorizontalPadding;
81 | private int tabViewTextMinWidth;
82 | private ViewPager viewPager;
83 | private ViewPager.OnPageChangeListener viewPagerPageChangeListener;
84 | private OnScrollChangeListener onScrollChangeListener;
85 | private TabProvider tabProvider;
86 | private InternalTabClickListener internalTabClickListener;
87 | private OnTabClickListener onTabClickListener;
88 | private boolean distributeEvenly;
89 |
90 | public SmartTabLayout(Context context) {
91 | this(context, null);
92 | }
93 |
94 | public SmartTabLayout(Context context, AttributeSet attrs) {
95 | this(context, attrs, 0);
96 | }
97 |
98 | public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) {
99 | super(context, attrs, defStyle);
100 |
101 | // Disable the Scroll Bar
102 | setHorizontalScrollBarEnabled(false);
103 |
104 | final DisplayMetrics dm = getResources().getDisplayMetrics();
105 | final float density = dm.density;
106 |
107 | int tabBackgroundResId = NO_ID;
108 | boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS;
109 | ColorStateList textColors;
110 | float textSize = TypedValue.applyDimension(
111 | TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP, dm);
112 | int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density);
113 | int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density);
114 | boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY;
115 | int customTabLayoutId = NO_ID;
116 | int customTabTextViewId = NO_ID;
117 | boolean clickable = TAB_CLICKABLE;
118 | int titleOffset = (int) (TITLE_OFFSET_DIPS * density);
119 |
120 | TypedArray a = context.obtainStyledAttributes(
121 | attrs, R.styleable.stl_SmartTabLayout, defStyle, 0);
122 | tabBackgroundResId = a.getResourceId(
123 | R.styleable.stl_SmartTabLayout_stl_defaultTabBackground, tabBackgroundResId);
124 | textAllCaps = a.getBoolean(
125 | R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps);
126 | textColors = a.getColorStateList(
127 | R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor);
128 | textSize = a.getDimension(
129 | R.styleable.stl_SmartTabLayout_stl_defaultTabTextSize, textSize);
130 | textHorizontalPadding = a.getDimensionPixelSize(
131 | R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding);
132 | textMinWidth = a.getDimensionPixelSize(
133 | R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth, textMinWidth);
134 | customTabLayoutId = a.getResourceId(
135 | R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId, customTabLayoutId);
136 | customTabTextViewId = a.getResourceId(
137 | R.styleable.stl_SmartTabLayout_stl_customTabTextViewId, customTabTextViewId);
138 | distributeEvenly = a.getBoolean(
139 | R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly);
140 | clickable = a.getBoolean(
141 | R.styleable.stl_SmartTabLayout_stl_clickable, clickable);
142 | titleOffset = a.getLayoutDimension(
143 | R.styleable.stl_SmartTabLayout_stl_titleOffset, titleOffset);
144 | a.recycle();
145 |
146 | this.titleOffset = titleOffset;
147 | this.tabViewBackgroundResId = tabBackgroundResId;
148 | this.tabViewTextAllCaps = textAllCaps;
149 | this.tabViewTextColors = (textColors != null)
150 | ? textColors
151 | : ColorStateList.valueOf(TAB_VIEW_TEXT_COLOR);
152 | this.tabViewTextSize = textSize;
153 | this.tabViewTextHorizontalPadding = textHorizontalPadding;
154 | this.tabViewTextMinWidth = textMinWidth;
155 | this.internalTabClickListener = clickable ? new InternalTabClickListener() : null;
156 | this.distributeEvenly = distributeEvenly;
157 |
158 | if (customTabLayoutId != NO_ID) {
159 | setCustomTabView(customTabLayoutId, customTabTextViewId);
160 | }
161 |
162 | this.tabStrip = new SmartTabStrip(context, attrs);
163 |
164 | if (distributeEvenly && tabStrip.isIndicatorAlwaysInCenter()) {
165 | throw new UnsupportedOperationException(
166 | "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support");
167 | }
168 |
169 | // Make sure that the Tab Strips fills this View
170 | setFillViewport(!tabStrip.isIndicatorAlwaysInCenter());
171 |
172 | addView(tabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
173 |
174 | }
175 |
176 | @Override
177 | protected void onScrollChanged(int l, int t, int oldl, int oldt) {
178 | super.onScrollChanged(l, t, oldl, oldt);
179 | if (onScrollChangeListener != null) {
180 | onScrollChangeListener.onScrollChanged(l, oldl);
181 | }
182 | }
183 |
184 | @Override
185 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
186 | super.onSizeChanged(w, h, oldw, oldh);
187 | if (tabStrip.isIndicatorAlwaysInCenter() && tabStrip.getChildCount() > 0) {
188 | View firstTab = tabStrip.getChildAt(0);
189 | View lastTab = tabStrip.getChildAt(tabStrip.getChildCount() - 1);
190 | int start = (w - Utils.getMeasuredWidth(firstTab)) / 2 - Utils.getMarginStart(firstTab);
191 | int end = (w - Utils.getMeasuredWidth(lastTab)) / 2 - Utils.getMarginEnd(lastTab);
192 | tabStrip.setMinimumWidth(tabStrip.getMeasuredWidth());
193 | ViewCompat.setPaddingRelative(this, start, getPaddingTop(), end, getPaddingBottom());
194 | setClipToPadding(false);
195 | }
196 | }
197 |
198 | @Override
199 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
200 | super.onLayout(changed, l, t, r, b);
201 | // Ensure first scroll
202 | if (changed && viewPager != null) {
203 | scrollToTab(viewPager.getCurrentItem(), 0);
204 | }
205 | }
206 |
207 | /**
208 | * Set the behavior of the Indicator scrolling feedback.
209 | *
210 | * @param interpolator {@link com.ogaclejapan.smarttablayout.SmartTabIndicationInterpolator}
211 | */
212 | public void setIndicationInterpolator(SmartTabIndicationInterpolator interpolator) {
213 | tabStrip.setIndicationInterpolator(interpolator);
214 | }
215 |
216 | /**
217 | * Set the custom {@link TabColorizer} to be used.
218 | *
219 | * If you only require simple customisation then you can use
220 | * {@link #setSelectedIndicatorColors(int...)} and {@link #setDividerColors(int...)} to achieve
221 | * similar effects.
222 | */
223 | public void setCustomTabColorizer(TabColorizer tabColorizer) {
224 | tabStrip.setCustomTabColorizer(tabColorizer);
225 | }
226 |
227 | /**
228 | * Set the color used for styling the tab text. This will need to be called prior to calling
229 | * {@link #setViewPager(ViewPager)} otherwise it will not get set
230 | *
231 | * @param color to use for tab text
232 | */
233 | public void setDefaultTabTextColor(int color) {
234 | tabViewTextColors = ColorStateList.valueOf(color);
235 | }
236 |
237 | /**
238 | * Sets the colors used for styling the tab text. This will need to be called prior to calling
239 | * {@link #setViewPager(ViewPager)} otherwise it will not get set
240 | *
241 | * @param colors ColorStateList to use for tab text
242 | */
243 | public void setDefaultTabTextColor(ColorStateList colors) {
244 | tabViewTextColors = colors;
245 | }
246 |
247 | /**
248 | * Set the same weight for tab
249 | */
250 | public void setDistributeEvenly(boolean distributeEvenly) {
251 | this.distributeEvenly = distributeEvenly;
252 | }
253 |
254 | /**
255 | * Sets the colors to be used for indicating the selected tab. These colors are treated as a
256 | * circular array. Providing one color will mean that all tabs are indicated with the same color.
257 | */
258 | public void setSelectedIndicatorColors(int... colors) {
259 | tabStrip.setSelectedIndicatorColors(colors);
260 | }
261 |
262 | /**
263 | * Sets the colors to be used for tab dividers. These colors are treated as a circular array.
264 | * Providing one color will mean that all tabs are indicated with the same color.
265 | */
266 | public void setDividerColors(int... colors) {
267 | tabStrip.setDividerColors(colors);
268 | }
269 |
270 | /**
271 | * Set the {@link ViewPager.OnPageChangeListener}. When using {@link SmartTabLayout} you are
272 | * required to set any {@link ViewPager.OnPageChangeListener} through this method. This is so
273 | * that the layout can update it's scroll position correctly.
274 | *
275 | * @see ViewPager#setOnPageChangeListener(ViewPager.OnPageChangeListener)
276 | */
277 | public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
278 | viewPagerPageChangeListener = listener;
279 | }
280 |
281 | /**
282 | * Set {@link OnScrollChangeListener} for obtaining values of scrolling.
283 | *
284 | * @param listener the {@link OnScrollChangeListener} to set
285 | */
286 | public void setOnScrollChangeListener(OnScrollChangeListener listener) {
287 | onScrollChangeListener = listener;
288 | }
289 |
290 | /**
291 | * Set {@link OnTabClickListener} for obtaining click event.
292 | *
293 | * @param listener the {@link OnTabClickListener} to set
294 | */
295 | public void setOnTabClickListener(OnTabClickListener listener) {
296 | onTabClickListener = listener;
297 | }
298 |
299 | /**
300 | * Set the custom layout to be inflated for the tab views.
301 | *
302 | * @param layoutResId Layout id to be inflated
303 | * @param textViewId id of the {@link android.widget.TextView} in the inflated view
304 | */
305 | public void setCustomTabView(int layoutResId, int textViewId) {
306 | tabProvider = new SimpleTabProvider(getContext(), layoutResId, textViewId);
307 | }
308 |
309 | /**
310 | * Set the custom layout to be inflated for the tab views.
311 | *
312 | * @param provider {@link TabProvider}
313 | */
314 | public void setCustomTabView(TabProvider provider) {
315 | tabProvider = provider;
316 | }
317 |
318 | /**
319 | * Sets the associated view pager. Note that the assumption here is that the pager content
320 | * (number of tabs and tab titles) does not change after this call has been made.
321 | */
322 | public void setViewPager(ViewPager viewPager) {
323 | tabStrip.removeAllViews();
324 |
325 | this.viewPager = viewPager;
326 | if (viewPager != null && viewPager.getAdapter() != null) {
327 | viewPager.addOnPageChangeListener(new InternalViewPagerListener());
328 | populateTabStrip();
329 | }
330 | }
331 |
332 | /**
333 | * Returns the view at the specified position in the tabs.
334 | *
335 | * @param position the position at which to get the view from
336 | * @return the view at the specified position or null if the position does not exist within the
337 | * tabs
338 | */
339 | public View getTabAt(int position) {
340 | return tabStrip.getChildAt(position);
341 | }
342 |
343 | /**
344 | * Create a default view to be used for tabs. This is called if a custom tab view is not set via
345 | * {@link #setCustomTabView(int, int)}.
346 | */
347 | protected TextView createDefaultTabView(CharSequence title) {
348 | TextView textView = new TextView(getContext());
349 | textView.setGravity(Gravity.CENTER);
350 | textView.setText(title);
351 | textView.setTextColor(tabViewTextColors);
352 | textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabViewTextSize);
353 | textView.setTypeface(Typeface.DEFAULT_BOLD);
354 | textView.setLayoutParams(new LinearLayout.LayoutParams(
355 | LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));
356 |
357 | if (tabViewBackgroundResId != NO_ID) {
358 | textView.setBackgroundResource(tabViewBackgroundResId);
359 | } else {
360 | // If we're running on Honeycomb or newer, then we can use the Theme's
361 | // selectableItemBackground to ensure that the View has a pressed state
362 | TypedValue outValue = new TypedValue();
363 | getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
364 | outValue, true);
365 | textView.setBackgroundResource(outValue.resourceId);
366 | }
367 |
368 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
369 | // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
370 | textView.setAllCaps(tabViewTextAllCaps);
371 | }
372 |
373 | textView.setPadding(
374 | tabViewTextHorizontalPadding, 0,
375 | tabViewTextHorizontalPadding, 0);
376 |
377 | if (tabViewTextMinWidth > 0) {
378 | textView.setMinWidth(tabViewTextMinWidth);
379 | }
380 |
381 | return textView;
382 | }
383 |
384 | private void populateTabStrip() {
385 | final PagerAdapter adapter = viewPager.getAdapter();
386 |
387 | for (int i = 0; i < adapter.getCount(); i++) {
388 |
389 | final View tabView = (tabProvider == null)
390 | ? createDefaultTabView(adapter.getPageTitle(i))
391 | : tabProvider.createTabView(tabStrip, i, adapter);
392 |
393 | if (tabView == null) {
394 | throw new IllegalStateException("tabView is null.");
395 | }
396 |
397 | if (distributeEvenly) {
398 | LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
399 | lp.width = 0;
400 | lp.weight = 1;
401 | }
402 |
403 | if (internalTabClickListener != null) {
404 | tabView.setOnClickListener(internalTabClickListener);
405 | }
406 |
407 | tabStrip.addView(tabView);
408 |
409 | if (i == viewPager.getCurrentItem()) {
410 | tabView.setSelected(true);
411 | }
412 |
413 | }
414 | }
415 |
416 | private void scrollToTab(int tabIndex, float positionOffset) {
417 | final int tabStripChildCount = tabStrip.getChildCount();
418 | if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
419 | return;
420 | }
421 |
422 | final boolean isLayoutRtl = Utils.isLayoutRtl(this);
423 | View selectedTab = tabStrip.getChildAt(tabIndex);
424 | int widthPlusMargin = Utils.getWidth(selectedTab) + Utils.getMarginHorizontally(selectedTab);
425 | int extraOffset = (int) (positionOffset * widthPlusMargin);
426 |
427 | if (tabStrip.isIndicatorAlwaysInCenter()) {
428 |
429 | if (0f < positionOffset && positionOffset < 1f) {
430 | View nextTab = tabStrip.getChildAt(tabIndex + 1);
431 | int selectHalfWidth = Utils.getWidth(selectedTab) / 2 + Utils.getMarginEnd(selectedTab);
432 | int nextHalfWidth = Utils.getWidth(nextTab) / 2 + Utils.getMarginStart(nextTab);
433 | extraOffset = Math.round(positionOffset * (selectHalfWidth + nextHalfWidth));
434 | }
435 |
436 | View firstTab = tabStrip.getChildAt(0);
437 | int x;
438 | if (isLayoutRtl) {
439 | int first = Utils.getWidth(firstTab) + Utils.getMarginEnd(firstTab);
440 | int selected = Utils.getWidth(selectedTab) + Utils.getMarginEnd(selectedTab);
441 | x = Utils.getEnd(selectedTab) - Utils.getMarginEnd(selectedTab) - extraOffset;
442 | x -= (first - selected) / 2;
443 | } else {
444 | int first = Utils.getWidth(firstTab) + Utils.getMarginStart(firstTab);
445 | int selected = Utils.getWidth(selectedTab) + Utils.getMarginStart(selectedTab);
446 | x = Utils.getStart(selectedTab) - Utils.getMarginStart(selectedTab) + extraOffset;
447 | x -= (first - selected) / 2;
448 | }
449 |
450 | scrollTo(x, 0);
451 | return;
452 |
453 | }
454 |
455 | int x;
456 | if (titleOffset == TITLE_OFFSET_AUTO_CENTER) {
457 |
458 | if (0f < positionOffset && positionOffset < 1f) {
459 | View nextTab = tabStrip.getChildAt(tabIndex + 1);
460 | int selectHalfWidth = Utils.getWidth(selectedTab) / 2 + Utils.getMarginEnd(selectedTab);
461 | int nextHalfWidth = Utils.getWidth(nextTab) / 2 + Utils.getMarginStart(nextTab);
462 | extraOffset = Math.round(positionOffset * (selectHalfWidth + nextHalfWidth));
463 | }
464 |
465 | if (isLayoutRtl) {
466 | x = -Utils.getWidthWithMargin(selectedTab) / 2 + getWidth() / 2;
467 | x -= Utils.getPaddingStart(this);
468 | } else {
469 | x = Utils.getWidthWithMargin(selectedTab) / 2 - getWidth() / 2;
470 | x += Utils.getPaddingStart(this);
471 | }
472 |
473 | } else {
474 |
475 | if (isLayoutRtl) {
476 | x = (tabIndex > 0 || positionOffset > 0) ? titleOffset : 0;
477 | } else {
478 | x = (tabIndex > 0 || positionOffset > 0) ? -titleOffset : 0;
479 | }
480 |
481 | }
482 |
483 | int start = Utils.getStart(selectedTab);
484 | int startMargin = Utils.getMarginStart(selectedTab);
485 | if (isLayoutRtl) {
486 | x += start + startMargin - extraOffset - getWidth() + Utils.getPaddingHorizontally(this);
487 | } else {
488 | x += start - startMargin + extraOffset;
489 | }
490 |
491 | scrollTo(x, 0);
492 |
493 | }
494 |
495 | /**
496 | * Allows complete control over the colors drawn in the tab layout. Set with
497 | * {@link #setCustomTabColorizer(TabColorizer)}.
498 | */
499 | public interface TabColorizer {
500 |
501 | /**
502 | * @return return the color of the indicator used when {@code position} is selected.
503 | */
504 | int getIndicatorColor(int position);
505 |
506 | /**
507 | * @return return the color of the divider drawn to the right of {@code position}.
508 | */
509 | int getDividerColor(int position);
510 |
511 | }
512 |
513 | /**
514 | * Interface definition for a callback to be invoked when the scroll position of a view changes.
515 | */
516 | public interface OnScrollChangeListener {
517 |
518 | /**
519 | * Called when the scroll position of a view changes.
520 | *
521 | * @param scrollX Current horizontal scroll origin.
522 | * @param oldScrollX Previous horizontal scroll origin.
523 | */
524 | void onScrollChanged(int scrollX, int oldScrollX);
525 | }
526 |
527 | /**
528 | * Interface definition for a callback to be invoked when a tab is clicked.
529 | */
530 | public interface OnTabClickListener {
531 |
532 | /**
533 | * Called when a tab is clicked.
534 | *
535 | * @param position tab's position
536 | */
537 | void onTabClicked(int position);
538 | }
539 |
540 | /**
541 | * Create the custom tabs in the tab layout. Set with
542 | * {@link #setCustomTabView(com.ogaclejapan.smarttablayout.SmartTabLayout.TabProvider)}
543 | */
544 | public interface TabProvider {
545 |
546 | /**
547 | * @return Return the View of {@code position} for the Tabs
548 | */
549 | View createTabView(ViewGroup container, int position, PagerAdapter adapter);
550 |
551 | }
552 |
553 | private static class SimpleTabProvider implements TabProvider {
554 |
555 | private final LayoutInflater inflater;
556 | private final int tabViewLayoutId;
557 | private final int tabViewTextViewId;
558 |
559 | private SimpleTabProvider(Context context, int layoutResId, int textViewId) {
560 | inflater = LayoutInflater.from(context);
561 | tabViewLayoutId = layoutResId;
562 | tabViewTextViewId = textViewId;
563 | }
564 |
565 | @Override
566 | public View createTabView(ViewGroup container, int position, PagerAdapter adapter) {
567 | View tabView = null;
568 | TextView tabTitleView = null;
569 |
570 | if (tabViewLayoutId != NO_ID) {
571 | tabView = inflater.inflate(tabViewLayoutId, container, false);
572 | }
573 |
574 | if (tabViewTextViewId != NO_ID && tabView != null) {
575 | tabTitleView = (TextView) tabView.findViewById(tabViewTextViewId);
576 | }
577 |
578 | if (tabTitleView == null && TextView.class.isInstance(tabView)) {
579 | tabTitleView = (TextView) tabView;
580 | }
581 |
582 | if (tabTitleView != null) {
583 | tabTitleView.setText(adapter.getPageTitle(position));
584 | }
585 |
586 | return tabView;
587 | }
588 |
589 | }
590 |
591 | private class InternalViewPagerListener implements ViewPager.OnPageChangeListener {
592 |
593 | private int scrollState;
594 |
595 | @Override
596 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
597 | int tabStripChildCount = tabStrip.getChildCount();
598 | if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) {
599 | return;
600 | }
601 |
602 | tabStrip.onViewPagerPageChanged(position, positionOffset);
603 |
604 | scrollToTab(position, positionOffset);
605 |
606 | if (viewPagerPageChangeListener != null) {
607 | viewPagerPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
608 | }
609 | }
610 |
611 | @Override
612 | public void onPageScrollStateChanged(int state) {
613 | scrollState = state;
614 |
615 | if (viewPagerPageChangeListener != null) {
616 | viewPagerPageChangeListener.onPageScrollStateChanged(state);
617 | }
618 | }
619 |
620 | @Override
621 | public void onPageSelected(int position) {
622 | if (scrollState == ViewPager.SCROLL_STATE_IDLE) {
623 | tabStrip.onViewPagerPageChanged(position, 0f);
624 | scrollToTab(position, 0);
625 | }
626 |
627 | for (int i = 0, size = tabStrip.getChildCount(); i < size; i++) {
628 | tabStrip.getChildAt(i).setSelected(position == i);
629 | }
630 |
631 | if (viewPagerPageChangeListener != null) {
632 | viewPagerPageChangeListener.onPageSelected(position);
633 | }
634 | }
635 |
636 | }
637 |
638 | private class InternalTabClickListener implements OnClickListener {
639 | @Override
640 | public void onClick(View v) {
641 | for (int i = 0; i < tabStrip.getChildCount(); i++) {
642 | if (v == tabStrip.getChildAt(i)) {
643 | if (onTabClickListener != null) {
644 | onTabClickListener.onTabClicked(i);
645 | }
646 | viewPager.setCurrentItem(i);
647 | return;
648 | }
649 | }
650 | }
651 | }
652 |
653 | }
654 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ogaclejapan/smarttablayout/SmartTabStrip.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
3 | * Copyright (C) 2013 The Android Open Source Project
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.ogaclejapan.smarttablayout;
18 |
19 | import android.content.Context;
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.RectF;
25 | import android.util.AttributeSet;
26 | import android.util.TypedValue;
27 | import android.view.View;
28 | import android.widget.LinearLayout;
29 |
30 | /**
31 | *
32 | * Forked from Google Samples > SlidingTabsBasic >
33 | * SlidingTabStrip
34 | */
35 | class SmartTabStrip extends LinearLayout {
36 |
37 | private static final int GRAVITY_BOTTOM = 0;
38 | private static final int GRAVITY_TOP = 1;
39 | private static final int GRAVITY_CENTER = 2;
40 |
41 | private static final int AUTO_WIDTH = -1;
42 |
43 | private static final int DEFAULT_TOP_BORDER_THICKNESS_DIPS = 0;
44 | private static final byte DEFAULT_TOP_BORDER_COLOR_ALPHA = 0x26;
45 | private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 2;
46 | private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26;
47 | private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 8;
48 | private static final int DEFAULT_SELECTED_INDICATOR_COLOR = 0xFF33B5E5;
49 | private static final float DEFAULT_INDICATOR_CORNER_RADIUS = 0f;
50 | private static final int DEFAULT_DIVIDER_THICKNESS_DIPS = 1;
51 | private static final byte DEFAULT_DIVIDER_COLOR_ALPHA = 0x20;
52 | private static final float DEFAULT_DIVIDER_HEIGHT = 0.5f;
53 | private static final boolean DEFAULT_INDICATOR_IN_CENTER = false;
54 | private static final boolean DEFAULT_INDICATOR_IN_FRONT = false;
55 | private static final boolean DEFAULT_INDICATOR_WITHOUT_PADDING = false;
56 | private static final int DEFAULT_INDICATOR_GRAVITY = GRAVITY_BOTTOM;
57 | private static final boolean DEFAULT_DRAW_DECORATION_AFTER_TAB = false;
58 |
59 | private final int topBorderThickness;
60 | private final int topBorderColor;
61 | private final int bottomBorderThickness;
62 | private final int bottomBorderColor;
63 | private final Paint borderPaint;
64 | private final RectF indicatorRectF = new RectF();
65 | private final boolean indicatorWithoutPadding;
66 | private final boolean indicatorAlwaysInCenter;
67 | private final boolean indicatorInFront;
68 | private final int indicatorThickness;
69 | private final int indicatorWidth;
70 | private final int indicatorGravity;
71 | private final float indicatorCornerRadius;
72 | private final Paint indicatorPaint;
73 | private final int dividerThickness;
74 | private final Paint dividerPaint;
75 | private final float dividerHeight;
76 | private final SimpleTabColorizer defaultTabColorizer;
77 | private final boolean drawDecorationAfterTab;
78 |
79 | private int lastPosition;
80 | private int selectedPosition;
81 | private float selectionOffset;
82 | private SmartTabIndicationInterpolator indicationInterpolator;
83 | private SmartTabLayout.TabColorizer customTabColorizer;
84 |
85 | SmartTabStrip(Context context, AttributeSet attrs) {
86 | super(context);
87 | setWillNotDraw(false);
88 |
89 | final float density = getResources().getDisplayMetrics().density;
90 |
91 | TypedValue outValue = new TypedValue();
92 | context.getTheme().resolveAttribute(android.R.attr.colorForeground, outValue, true);
93 | final int themeForegroundColor = outValue.data;
94 |
95 | boolean indicatorWithoutPadding = DEFAULT_INDICATOR_WITHOUT_PADDING;
96 | boolean indicatorInFront = DEFAULT_INDICATOR_IN_FRONT;
97 | boolean indicatorAlwaysInCenter = DEFAULT_INDICATOR_IN_CENTER;
98 | int indicationInterpolatorId = SmartTabIndicationInterpolator.ID_SMART;
99 | int indicatorGravity = DEFAULT_INDICATOR_GRAVITY;
100 | int indicatorColor = DEFAULT_SELECTED_INDICATOR_COLOR;
101 | int indicatorColorsId = NO_ID;
102 | int indicatorThickness = (int) (SELECTED_INDICATOR_THICKNESS_DIPS * density);
103 | int indicatorWidth = AUTO_WIDTH;
104 | float indicatorCornerRadius = DEFAULT_INDICATOR_CORNER_RADIUS * density;
105 | int overlineColor = setColorAlpha(themeForegroundColor, DEFAULT_TOP_BORDER_COLOR_ALPHA);
106 | int overlineThickness = (int) (DEFAULT_TOP_BORDER_THICKNESS_DIPS * density);
107 | int underlineColor = setColorAlpha(themeForegroundColor, DEFAULT_BOTTOM_BORDER_COLOR_ALPHA);
108 | int underlineThickness = (int) (DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density);
109 | int dividerColor = setColorAlpha(themeForegroundColor, DEFAULT_DIVIDER_COLOR_ALPHA);
110 | int dividerColorsId = NO_ID;
111 | int dividerThickness = (int) (DEFAULT_DIVIDER_THICKNESS_DIPS * density);
112 | boolean drawDecorationAfterTab = DEFAULT_DRAW_DECORATION_AFTER_TAB;
113 |
114 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout);
115 | indicatorAlwaysInCenter = a.getBoolean(
116 | R.styleable.stl_SmartTabLayout_stl_indicatorAlwaysInCenter, indicatorAlwaysInCenter);
117 | indicatorWithoutPadding = a.getBoolean(
118 | R.styleable.stl_SmartTabLayout_stl_indicatorWithoutPadding, indicatorWithoutPadding);
119 | indicatorInFront = a.getBoolean(
120 | R.styleable.stl_SmartTabLayout_stl_indicatorInFront, indicatorInFront);
121 | indicationInterpolatorId = a.getInt(
122 | R.styleable.stl_SmartTabLayout_stl_indicatorInterpolation, indicationInterpolatorId);
123 | indicatorGravity = a.getInt(
124 | R.styleable.stl_SmartTabLayout_stl_indicatorGravity, indicatorGravity);
125 | indicatorColor = a.getColor(
126 | R.styleable.stl_SmartTabLayout_stl_indicatorColor, indicatorColor);
127 | indicatorColorsId = a.getResourceId(
128 | R.styleable.stl_SmartTabLayout_stl_indicatorColors, indicatorColorsId);
129 | indicatorThickness = a.getDimensionPixelSize(
130 | R.styleable.stl_SmartTabLayout_stl_indicatorThickness, indicatorThickness);
131 | indicatorWidth = a.getLayoutDimension(
132 | R.styleable.stl_SmartTabLayout_stl_indicatorWidth, indicatorWidth);
133 | indicatorCornerRadius = a.getDimension(
134 | R.styleable.stl_SmartTabLayout_stl_indicatorCornerRadius, indicatorCornerRadius);
135 | overlineColor = a.getColor(
136 | R.styleable.stl_SmartTabLayout_stl_overlineColor, overlineColor);
137 | overlineThickness = a.getDimensionPixelSize(
138 | R.styleable.stl_SmartTabLayout_stl_overlineThickness, overlineThickness);
139 | underlineColor = a.getColor(
140 | R.styleable.stl_SmartTabLayout_stl_underlineColor, underlineColor);
141 | underlineThickness = a.getDimensionPixelSize(
142 | R.styleable.stl_SmartTabLayout_stl_underlineThickness, underlineThickness);
143 | dividerColor = a.getColor(
144 | R.styleable.stl_SmartTabLayout_stl_dividerColor, dividerColor);
145 | dividerColorsId = a.getResourceId(
146 | R.styleable.stl_SmartTabLayout_stl_dividerColors, dividerColorsId);
147 | dividerThickness = a.getDimensionPixelSize(
148 | R.styleable.stl_SmartTabLayout_stl_dividerThickness, dividerThickness);
149 | drawDecorationAfterTab = a.getBoolean(
150 | R.styleable.stl_SmartTabLayout_stl_drawDecorationAfterTab, drawDecorationAfterTab);
151 | a.recycle();
152 |
153 | final int[] indicatorColors = (indicatorColorsId == NO_ID)
154 | ? new int[] { indicatorColor }
155 | : getResources().getIntArray(indicatorColorsId);
156 |
157 | final int[] dividerColors = (dividerColorsId == NO_ID)
158 | ? new int[] { dividerColor }
159 | : getResources().getIntArray(dividerColorsId);
160 |
161 | this.defaultTabColorizer = new SimpleTabColorizer();
162 | this.defaultTabColorizer.setIndicatorColors(indicatorColors);
163 | this.defaultTabColorizer.setDividerColors(dividerColors);
164 |
165 | this.topBorderThickness = overlineThickness;
166 | this.topBorderColor = overlineColor;
167 | this.bottomBorderThickness = underlineThickness;
168 | this.bottomBorderColor = underlineColor;
169 | this.borderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
170 |
171 | this.indicatorAlwaysInCenter = indicatorAlwaysInCenter;
172 | this.indicatorWithoutPadding = indicatorWithoutPadding;
173 | this.indicatorInFront = indicatorInFront;
174 | this.indicatorThickness = indicatorThickness;
175 | this.indicatorWidth = indicatorWidth;
176 | this.indicatorPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
177 | this.indicatorCornerRadius = indicatorCornerRadius;
178 | this.indicatorGravity = indicatorGravity;
179 |
180 | this.dividerHeight = DEFAULT_DIVIDER_HEIGHT;
181 | this.dividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
182 | this.dividerPaint.setStrokeWidth(dividerThickness);
183 | this.dividerThickness = dividerThickness;
184 |
185 | this.drawDecorationAfterTab = drawDecorationAfterTab;
186 |
187 | this.indicationInterpolator = SmartTabIndicationInterpolator.of(indicationInterpolatorId);
188 | }
189 |
190 | /**
191 | * Set the alpha value of the {@code color} to be the given {@code alpha} value.
192 | */
193 | private static int setColorAlpha(int color, byte alpha) {
194 | return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));
195 | }
196 |
197 | /**
198 | * Blend {@code color1} and {@code color2} using the given ratio.
199 | *
200 | * @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
201 | * 0.0 will return {@code color2}.
202 | */
203 | private static int blendColors(int color1, int color2, float ratio) {
204 | final float inverseRation = 1f - ratio;
205 | float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
206 | float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
207 | float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
208 | return Color.rgb((int) r, (int) g, (int) b);
209 | }
210 |
211 | void setIndicationInterpolator(SmartTabIndicationInterpolator interpolator) {
212 | indicationInterpolator = interpolator;
213 | invalidate();
214 | }
215 |
216 | void setCustomTabColorizer(SmartTabLayout.TabColorizer customTabColorizer) {
217 | this.customTabColorizer = customTabColorizer;
218 | invalidate();
219 | }
220 |
221 | void setSelectedIndicatorColors(int... colors) {
222 | // Make sure that the custom colorizer is removed
223 | customTabColorizer = null;
224 | defaultTabColorizer.setIndicatorColors(colors);
225 | invalidate();
226 | }
227 |
228 | void setDividerColors(int... colors) {
229 | // Make sure that the custom colorizer is removed
230 | customTabColorizer = null;
231 | defaultTabColorizer.setDividerColors(colors);
232 | invalidate();
233 | }
234 |
235 | void onViewPagerPageChanged(int position, float positionOffset) {
236 | selectedPosition = position;
237 | selectionOffset = positionOffset;
238 | if (positionOffset == 0f && lastPosition != selectedPosition) {
239 | lastPosition = selectedPosition;
240 | }
241 | invalidate();
242 | }
243 |
244 | boolean isIndicatorAlwaysInCenter() {
245 | return indicatorAlwaysInCenter;
246 | }
247 |
248 | SmartTabLayout.TabColorizer getTabColorizer() {
249 | return (customTabColorizer != null) ? customTabColorizer : defaultTabColorizer;
250 | }
251 |
252 | @Override
253 | protected void onDraw(Canvas canvas) {
254 | if (!drawDecorationAfterTab) {
255 | drawDecoration(canvas);
256 | }
257 | }
258 |
259 | @Override
260 | protected void dispatchDraw(Canvas canvas) {
261 | super.dispatchDraw(canvas);
262 | if (drawDecorationAfterTab) {
263 | drawDecoration(canvas);
264 | }
265 | }
266 |
267 | private void drawDecoration(Canvas canvas) {
268 | final int height = getHeight();
269 | final int width = getWidth();
270 | final int tabCount = getChildCount();
271 | final SmartTabLayout.TabColorizer tabColorizer = getTabColorizer();
272 | final boolean isLayoutRtl = Utils.isLayoutRtl(this);
273 |
274 | if (indicatorInFront) {
275 | drawOverline(canvas, 0, width);
276 | drawUnderline(canvas, 0, width, height);
277 | }
278 |
279 | // Thick colored underline below the current selection
280 | if (tabCount > 0) {
281 | View selectedTab = getChildAt(selectedPosition);
282 | int selectedStart = Utils.getStart(selectedTab, indicatorWithoutPadding);
283 | int selectedEnd = Utils.getEnd(selectedTab, indicatorWithoutPadding);
284 | int left;
285 | int right;
286 | if (isLayoutRtl) {
287 | left = selectedEnd;
288 | right = selectedStart;
289 | } else {
290 | left = selectedStart;
291 | right = selectedEnd;
292 | }
293 |
294 | int color = tabColorizer.getIndicatorColor(selectedPosition);
295 | float thickness = indicatorThickness;
296 |
297 | if (selectionOffset > 0f && selectedPosition < (getChildCount() - 1)) {
298 | int nextColor = tabColorizer.getIndicatorColor(selectedPosition + 1);
299 | if (color != nextColor) {
300 | color = blendColors(nextColor, color, selectionOffset);
301 | }
302 |
303 | // Draw the selection partway between the tabs
304 | float startOffset = indicationInterpolator.getLeftEdge(selectionOffset);
305 | float endOffset = indicationInterpolator.getRightEdge(selectionOffset);
306 | float thicknessOffset = indicationInterpolator.getThickness(selectionOffset);
307 |
308 | View nextTab = getChildAt(selectedPosition + 1);
309 | int nextStart = Utils.getStart(nextTab, indicatorWithoutPadding);
310 | int nextEnd = Utils.getEnd(nextTab, indicatorWithoutPadding);
311 | if (isLayoutRtl) {
312 | left = (int) (endOffset * nextEnd + (1.0f - endOffset) * left);
313 | right = (int) (startOffset * nextStart + (1.0f - startOffset) * right);
314 | } else {
315 | left = (int) (startOffset * nextStart + (1.0f - startOffset) * left);
316 | right = (int) (endOffset * nextEnd + (1.0f - endOffset) * right);
317 | }
318 | thickness = thickness * thicknessOffset;
319 | }
320 |
321 | drawIndicator(canvas, left, right, height, thickness, color);
322 |
323 | }
324 |
325 | if (!indicatorInFront) {
326 | drawOverline(canvas, 0, width);
327 | drawUnderline(canvas, 0, getWidth(), height);
328 | }
329 |
330 | // Vertical separators between the titles
331 | drawSeparator(canvas, height, tabCount);
332 |
333 | }
334 |
335 | private void drawSeparator(Canvas canvas, int height, int tabCount) {
336 | if (dividerThickness <= 0) {
337 | return;
338 | }
339 |
340 | final int dividerHeightPx = (int) (Math.min(Math.max(0f, dividerHeight), 1f) * height);
341 | final SmartTabLayout.TabColorizer tabColorizer = getTabColorizer();
342 |
343 | // Vertical separators between the titles
344 | final int separatorTop = (height - dividerHeightPx) / 2;
345 | final int separatorBottom = separatorTop + dividerHeightPx;
346 |
347 | final boolean isLayoutRtl = Utils.isLayoutRtl(this);
348 | for (int i = 0; i < tabCount - 1; i++) {
349 | View child = getChildAt(i);
350 | int end = Utils.getEnd(child);
351 | int endMargin = Utils.getMarginEnd(child);
352 | int separatorX = isLayoutRtl ? end - endMargin : end + endMargin;
353 | dividerPaint.setColor(tabColorizer.getDividerColor(i));
354 | canvas.drawLine(separatorX, separatorTop, separatorX, separatorBottom, dividerPaint);
355 | }
356 | }
357 |
358 | private void drawIndicator(Canvas canvas, int left, int right, int height, float thickness,
359 | int color) {
360 | if (indicatorThickness <= 0 || indicatorWidth == 0) {
361 | return;
362 | }
363 |
364 | float center;
365 | float top;
366 | float bottom;
367 |
368 | switch (indicatorGravity) {
369 | case GRAVITY_TOP:
370 | center = indicatorThickness / 2f;
371 | top = center - (thickness / 2f);
372 | bottom = center + (thickness / 2f);
373 | break;
374 | case GRAVITY_CENTER:
375 | center = height / 2f;
376 | top = center - (thickness / 2f);
377 | bottom = center + (thickness / 2f);
378 | break;
379 | case GRAVITY_BOTTOM:
380 | default:
381 | center = height - (indicatorThickness / 2f);
382 | top = center - (thickness / 2f);
383 | bottom = center + (thickness / 2f);
384 | }
385 |
386 | indicatorPaint.setColor(color);
387 | if (indicatorWidth == AUTO_WIDTH) {
388 | indicatorRectF.set(left, top, right, bottom);
389 | } else {
390 | float padding = (Math.abs(left - right) - indicatorWidth) / 2f;
391 | indicatorRectF.set(left + padding, top, right - padding, bottom);
392 | }
393 |
394 | if (indicatorCornerRadius > 0f) {
395 | canvas.drawRoundRect(
396 | indicatorRectF, indicatorCornerRadius,
397 | indicatorCornerRadius, indicatorPaint);
398 | } else {
399 | canvas.drawRect(indicatorRectF, indicatorPaint);
400 | }
401 | }
402 |
403 | private void drawOverline(Canvas canvas, int left, int right) {
404 | if (topBorderThickness <= 0) {
405 | return;
406 | }
407 | // Thin overline along the entire top edge
408 | borderPaint.setColor(topBorderColor);
409 | canvas.drawRect(left, 0, right, topBorderThickness, borderPaint);
410 | }
411 |
412 | private void drawUnderline(Canvas canvas, int left, int right, int height) {
413 | if (bottomBorderThickness <= 0) {
414 | return;
415 | }
416 | // Thin underline along the entire bottom edge
417 | borderPaint.setColor(bottomBorderColor);
418 | canvas.drawRect(left, height - bottomBorderThickness, right, height, borderPaint);
419 | }
420 |
421 | private static class SimpleTabColorizer implements SmartTabLayout.TabColorizer {
422 |
423 | private int[] indicatorColors;
424 | private int[] dividerColors;
425 |
426 | @Override
427 | public final int getIndicatorColor(int position) {
428 | return indicatorColors[position % indicatorColors.length];
429 | }
430 |
431 | @Override
432 | public final int getDividerColor(int position) {
433 | return dividerColors[position % dividerColors.length];
434 | }
435 |
436 | void setIndicatorColors(int... colors) {
437 | indicatorColors = colors;
438 | }
439 |
440 | void setDividerColors(int... colors) {
441 | dividerColors = colors;
442 | }
443 | }
444 | }
445 |
--------------------------------------------------------------------------------
/library/src/main/java/com/ogaclejapan/smarttablayout/Utils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
3 | * Copyright (C) 2013 The Android Open Source Project
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.ogaclejapan.smarttablayout;
18 |
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 |
22 | import androidx.core.view.MarginLayoutParamsCompat;
23 | import androidx.core.view.ViewCompat;
24 |
25 | final class Utils {
26 |
27 | static int getMeasuredWidth(View v) {
28 | return (v == null) ? 0 : v.getMeasuredWidth();
29 | }
30 |
31 | static int getWidth(View v) {
32 | return (v == null) ? 0 : v.getWidth();
33 | }
34 |
35 | static int getWidthWithMargin(View v) {
36 | return getWidth(v) + getMarginHorizontally(v);
37 | }
38 |
39 | static int getStart(View v) {
40 | return getStart(v, false);
41 | }
42 |
43 | static int getStart(View v, boolean withoutPadding) {
44 | if (v == null) {
45 | return 0;
46 | }
47 | if (isLayoutRtl(v)) {
48 | return (withoutPadding) ? v.getRight() - getPaddingStart(v) : v.getRight();
49 | } else {
50 | return (withoutPadding) ? v.getLeft() + getPaddingStart(v) : v.getLeft();
51 | }
52 | }
53 |
54 | static int getEnd(View v) {
55 | return getEnd(v, false);
56 | }
57 |
58 | static int getEnd(View v, boolean withoutPadding) {
59 | if (v == null) {
60 | return 0;
61 | }
62 | if (isLayoutRtl(v)) {
63 | return (withoutPadding) ? v.getLeft() + getPaddingEnd(v) : v.getLeft();
64 | } else {
65 | return (withoutPadding) ? v.getRight() - getPaddingEnd(v) : v.getRight();
66 | }
67 | }
68 |
69 | static int getPaddingStart(View v) {
70 | if (v == null) {
71 | return 0;
72 | }
73 | return ViewCompat.getPaddingStart(v);
74 | }
75 |
76 | static int getPaddingEnd(View v) {
77 | if (v == null) {
78 | return 0;
79 | }
80 | return ViewCompat.getPaddingEnd(v);
81 | }
82 |
83 | static int getPaddingHorizontally(View v) {
84 | if (v == null) {
85 | return 0;
86 | }
87 | return v.getPaddingLeft() + v.getPaddingRight();
88 | }
89 |
90 | static int getMarginStart(View v) {
91 | if (v == null) {
92 | return 0;
93 | }
94 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
95 | return MarginLayoutParamsCompat.getMarginStart(lp);
96 | }
97 |
98 | static int getMarginEnd(View v) {
99 | if (v == null) {
100 | return 0;
101 | }
102 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
103 | return MarginLayoutParamsCompat.getMarginEnd(lp);
104 | }
105 |
106 | static int getMarginHorizontally(View v) {
107 | if (v == null) {
108 | return 0;
109 | }
110 | ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
111 | return MarginLayoutParamsCompat.getMarginStart(lp) + MarginLayoutParamsCompat.getMarginEnd(lp);
112 | }
113 |
114 | static boolean isLayoutRtl(View v) {
115 | return ViewCompat.getLayoutDirection(v) == ViewCompat.LAYOUT_DIRECTION_RTL;
116 | }
117 |
118 | private Utils() { }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/publish.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.jfrog.bintray'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 |
4 |
5 | // build a jar with source files
6 | task sourcesJar(type: Jar) {
7 | from android.sourceSets.main.java.srcDirs
8 | classifier = 'sources'
9 | }
10 |
11 | task javadoc(type: Javadoc) {
12 | failOnError false
13 | source = android.sourceSets.main.java.sourceFiles
14 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
15 | classpath += configurations.compile
16 | }
17 |
18 | // build a jar with javadoc
19 | task javadocJar(type: Jar, dependsOn: javadoc) {
20 | classifier = 'javadoc'
21 | from javadoc.destinationDir
22 | }
23 |
24 | artifacts {
25 | archives sourcesJar
26 | archives javadocJar
27 | }
28 |
29 | install {
30 | repositories.mavenInstaller {
31 | // This generates POM.xml with proper parameters
32 | pom {
33 | project {
34 | packaging 'aar'
35 |
36 | name ARTIFACT_NAME
37 | description ARTIFACT_DESCRIPTION
38 | url SITE_URL
39 |
40 | licenses {
41 | license {
42 | name LICENCE_NAME
43 | url LICENCE_URL
44 | distribution LICENCE_DIST
45 | }
46 | }
47 |
48 | developers {
49 | developer {
50 | id DEVELOPER_ID
51 | name DEVELOPER_NAME
52 | email DEVELOPER_EMAIL
53 | }
54 | }
55 | issueManagement {
56 | system ISSUE_SYSTEM
57 | url ISSUE_URL
58 | }
59 |
60 | scm {
61 | connection SCM_CONNECTION
62 | developerConnection SCM_DEV_CONNECTION
63 | url SCM_URL
64 |
65 | }
66 | }
67 | }
68 | }
69 | }
70 |
71 | bintray {
72 |
73 | user = findProperty('BINTRAY_USER')
74 | key = findProperty('BINTRAY_APIKEY')
75 |
76 | configurations = ['archives']
77 |
78 | dryRun = false
79 | publish = true
80 |
81 | pkg {
82 | repo = "maven"
83 | name = pkginfo.name
84 | desc = pkginfo.description
85 | websiteUrl = pkginfo.site
86 | issueTrackerUrl = pkginfo.issue
87 | vcsUrl = pkginfo.vcs
88 | licenses = ["Apache-2.0"]
89 | labels = ['android']
90 | publicDownloadNumbers = true
91 |
92 | version {
93 | gpg {
94 | sign = true
95 | passphrase = findProperty('BINTRAY_GPG_PASSPHRASE')
96 | }
97 |
98 | mavenCentralSync {
99 | sync = true
100 | user = findProperty('NEXUS_USER')
101 | password = findProperty('NEXUS_PASSWORD')
102 | close = '1'
103 | }
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':demo', ':library', ':utils-v4'
2 |
--------------------------------------------------------------------------------
/utils-v4/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/utils-v4/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2015 ogaclejapan
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
--------------------------------------------------------------------------------
/utils-v4/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.ben-manes.versions'
3 | apply plugin: 'com.github.hierynomus.license'
4 |
5 | android {
6 | compileSdkVersion COMPILE_SDK_VERSION as int
7 |
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion COMPILE_SDK_VERSION as int
11 | versionCode VERSION_CODE as int
12 | versionName VERSION_NAME
13 |
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | implementation "androidx.fragment:fragment:${ANDROIDX_BASE_VERSION}"
25 | }
26 |
27 | license {
28 |
29 | sourceSets {
30 | main.java.srcDirs = android.sourceSets.main.java.srcDirs
31 | main.resources.srcDirs = android.sourceSets.main.resources.srcDirs
32 | }
33 |
34 | ext.year = Calendar.getInstance().get(Calendar.YEAR)
35 | ext.name = DEVELOPER_ID
36 |
37 | }
38 |
39 | pkginfo.name = ARTIFACT_NAME + '-V4Utils'
40 | apply from: "${project.rootDir}/publish.gradle"
41 |
--------------------------------------------------------------------------------
/utils-v4/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/msk/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/utils-v4/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/utils-v4/src/main/java/com/ogaclejapan/smarttablayout/utils/PagerItem.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
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.ogaclejapan.smarttablayout.utils;
17 |
18 | public abstract class PagerItem {
19 |
20 | protected static final float DEFAULT_WIDTH = 1.f;
21 |
22 | private final CharSequence title;
23 | private final float width;
24 |
25 | protected PagerItem(CharSequence title, float width) {
26 | this.title = title;
27 | this.width = width;
28 | }
29 |
30 | public CharSequence getTitle() {
31 | return title;
32 | }
33 |
34 | public float getWidth() {
35 | return width;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/utils-v4/src/main/java/com/ogaclejapan/smarttablayout/utils/PagerItems.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
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.ogaclejapan.smarttablayout.utils;
17 |
18 | import android.content.Context;
19 |
20 | import java.util.ArrayList;
21 |
22 | public abstract class PagerItems extends ArrayList {
23 |
24 | private final Context context;
25 |
26 | protected PagerItems(Context context) {
27 | this.context = context;
28 | }
29 |
30 | public Context getContext() {
31 | return context;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/utils-v4/src/main/java/com/ogaclejapan/smarttablayout/utils/ViewPagerItem.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
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.ogaclejapan.smarttablayout.utils;
17 |
18 | import android.view.LayoutInflater;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 |
22 | import androidx.annotation.LayoutRes;
23 |
24 | public class ViewPagerItem extends PagerItem {
25 |
26 | private final int resource;
27 |
28 | protected ViewPagerItem(CharSequence title, float width, @LayoutRes int resource) {
29 | super(title, width);
30 | this.resource = resource;
31 | }
32 |
33 | public static ViewPagerItem of(CharSequence title, @LayoutRes int resource) {
34 | return of(title, DEFAULT_WIDTH, resource);
35 | }
36 |
37 | public static ViewPagerItem of(CharSequence title, float width, @LayoutRes int resource) {
38 | return new ViewPagerItem(title, width, resource);
39 | }
40 |
41 | public View initiate(LayoutInflater inflater, ViewGroup container) {
42 | return inflater.inflate(resource, container, false);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/utils-v4/src/main/java/com/ogaclejapan/smarttablayout/utils/ViewPagerItemAdapter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
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.ogaclejapan.smarttablayout.utils;
17 |
18 | import android.view.LayoutInflater;
19 | import android.view.View;
20 | import android.view.ViewGroup;
21 |
22 | import java.lang.ref.WeakReference;
23 |
24 | import androidx.annotation.NonNull;
25 | import androidx.collection.SparseArrayCompat;
26 | import androidx.viewpager.widget.PagerAdapter;
27 |
28 | public class ViewPagerItemAdapter extends PagerAdapter {
29 |
30 | private final ViewPagerItems pages;
31 | private final SparseArrayCompat> holder;
32 | private final LayoutInflater inflater;
33 |
34 | public ViewPagerItemAdapter(ViewPagerItems pages) {
35 | this.pages = pages;
36 | this.holder = new SparseArrayCompat<>(pages.size());
37 | this.inflater = LayoutInflater.from(pages.getContext());
38 | }
39 |
40 | @Override
41 | public int getCount() {
42 | return pages.size();
43 | }
44 |
45 | @NonNull
46 | @Override
47 | public Object instantiateItem(@NonNull ViewGroup container, int position) {
48 | View view = getPagerItem(position).initiate(inflater, container);
49 | container.addView(view);
50 | holder.put(position, new WeakReference(view));
51 | return view;
52 | }
53 |
54 | @Override
55 | public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
56 | holder.remove(position);
57 | container.removeView((View) object);
58 | }
59 |
60 | @Override
61 | public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
62 | return object == view;
63 | }
64 |
65 | @Override
66 | public CharSequence getPageTitle(int position) {
67 | return getPagerItem(position).getTitle();
68 | }
69 |
70 | @Override
71 | public float getPageWidth(int position) {
72 | return getPagerItem(position).getWidth();
73 | }
74 |
75 | public View getPage(int position) {
76 | final WeakReference weakRefItem = holder.get(position);
77 | return (weakRefItem != null) ? weakRefItem.get() : null;
78 | }
79 |
80 | protected ViewPagerItem getPagerItem(int position) {
81 | return pages.get(position);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/utils-v4/src/main/java/com/ogaclejapan/smarttablayout/utils/ViewPagerItems.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
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.ogaclejapan.smarttablayout.utils;
17 |
18 | import android.content.Context;
19 |
20 | import androidx.annotation.LayoutRes;
21 | import androidx.annotation.StringRes;
22 |
23 | public class ViewPagerItems extends PagerItems {
24 |
25 | public ViewPagerItems(Context context) {
26 | super(context);
27 | }
28 |
29 | public static Creator with(Context context) {
30 | return new Creator(context);
31 | }
32 |
33 | public static class Creator {
34 |
35 | private final ViewPagerItems items;
36 |
37 | public Creator(Context context) {
38 | items = new ViewPagerItems(context);
39 | }
40 |
41 | public Creator add(@StringRes int title, @LayoutRes int resource) {
42 | return add(ViewPagerItem.of(items.getContext().getString(title), resource));
43 | }
44 |
45 | public Creator add(@StringRes int title, float width, @LayoutRes int resource) {
46 | return add(ViewPagerItem.of(items.getContext().getString(title), width, resource));
47 | }
48 |
49 | public Creator add(CharSequence title, @LayoutRes int resource) {
50 | return add(ViewPagerItem.of(title, resource));
51 | }
52 |
53 | public Creator add(ViewPagerItem item) {
54 | items.add(item);
55 | return this;
56 | }
57 |
58 | public ViewPagerItems create() {
59 | return items;
60 | }
61 |
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/utils-v4/src/main/java/com/ogaclejapan/smarttablayout/utils/v4/Bundler.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
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.ogaclejapan.smarttablayout.utils.v4;
17 |
18 | import android.annotation.TargetApi;
19 | import android.os.Bundle;
20 | import android.os.IBinder;
21 | import android.os.Parcelable;
22 | import android.util.Size;
23 | import android.util.SizeF;
24 | import android.util.SparseArray;
25 |
26 | import java.io.Serializable;
27 | import java.util.ArrayList;
28 |
29 | import androidx.fragment.app.Fragment;
30 |
31 | public class Bundler {
32 |
33 | private final Bundle bundle;
34 |
35 | /**
36 | * Constructs a new, empty Bundle.
37 | */
38 | public Bundler() {
39 | this(null);
40 | }
41 |
42 | private Bundler(Bundle b) {
43 | bundle = (b == null) ? new Bundle() : new Bundle(b);
44 | }
45 |
46 | /**
47 | * Constructs a Bundle containing a copy of the mappings from the given
48 | * Bundle.
49 | *
50 | * @param b a Bundle to be copied.
51 | */
52 | public static Bundler of(Bundle b) {
53 | return new Bundler(b);
54 | }
55 |
56 | /**
57 | * Inserts all mappings from the given Bundle into this Bundle.
58 | *
59 | * @param bundle a Bundle
60 | * @return this
61 | */
62 | public Bundler putAll(Bundle bundle) {
63 | this.bundle.putAll(bundle);
64 | return this;
65 | }
66 |
67 | /**
68 | * Inserts a byte value into the mapping of this Bundle, replacing
69 | * any existing value for the given key.
70 | *
71 | * @param key a String, or null
72 | * @param value a byte
73 | * @return this
74 | */
75 | public Bundler putByte(String key, byte value) {
76 | bundle.putByte(key, value);
77 | return this;
78 | }
79 |
80 | /**
81 | * Inserts a char value into the mapping of this Bundle, replacing
82 | * any existing value for the given key.
83 | *
84 | * @param key a String, or null
85 | * @param value a char, or null
86 | * @return this
87 | */
88 | public Bundler putChar(String key, char value) {
89 | bundle.putChar(key, value);
90 | return this;
91 | }
92 |
93 | /**
94 | * Inserts a short value into the mapping of this Bundle, replacing
95 | * any existing value for the given key.
96 | *
97 | * @param key a String, or null
98 | * @param value a short
99 | * @return this
100 | */
101 | public Bundler putShort(String key, short value) {
102 | bundle.putShort(key, value);
103 | return this;
104 | }
105 |
106 | /**
107 | * Inserts a float value into the mapping of this Bundle, replacing
108 | * any existing value for the given key.
109 | *
110 | * @param key a String, or null
111 | * @param value a float
112 | * @return this
113 | */
114 | public Bundler putFloat(String key, float value) {
115 | bundle.putFloat(key, value);
116 | return this;
117 | }
118 |
119 | /**
120 | * Inserts a CharSequence value into the mapping of this Bundle, replacing
121 | * any existing value for the given key. Either key or value may be null.
122 | *
123 | * @param key a String, or null
124 | * @param value a CharSequence, or null
125 | * @return this
126 | */
127 | public Bundler putCharSequence(String key, CharSequence value) {
128 | bundle.putCharSequence(key, value);
129 | return this;
130 | }
131 |
132 | /**
133 | * Inserts a Parcelable value into the mapping of this Bundle, replacing
134 | * any existing value for the given key. Either key or value may be null.
135 | *
136 | * @param key a String, or null
137 | * @param value a Parcelable object, or null
138 | * @return this
139 | */
140 | public Bundler putParcelable(String key, Parcelable value) {
141 | bundle.putParcelable(key, value);
142 | return this;
143 | }
144 |
145 | /**
146 | * Inserts a Size value into the mapping of this Bundle, replacing
147 | * any existing value for the given key. Either key or value may be null.
148 | *
149 | * @param key a String, or null
150 | * @param value a Size object, or null
151 | * @return this
152 | */
153 | @TargetApi(21)
154 | public Bundler putSize(String key, Size value) {
155 | bundle.putSize(key, value);
156 | return this;
157 | }
158 |
159 | /**
160 | * Inserts a SizeF value into the mapping of this Bundle, replacing
161 | * any existing value for the given key. Either key or value may be null.
162 | *
163 | * @param key a String, or null
164 | * @param value a SizeF object, or null
165 | * @return this
166 | */
167 | @TargetApi(21)
168 | public Bundler putSizeF(String key, SizeF value) {
169 | bundle.putSizeF(key, value);
170 | return this;
171 | }
172 |
173 | /**
174 | * Inserts an array of Parcelable values into the mapping of this Bundle,
175 | * replacing any existing value for the given key. Either key or value may
176 | * be null.
177 | *
178 | * @param key a String, or null
179 | * @param value an array of Parcelable objects, or null
180 | * @return this
181 | */
182 | public Bundler putParcelableArray(String key, Parcelable[] value) {
183 | bundle.putParcelableArray(key, value);
184 | return this;
185 | }
186 |
187 | /**
188 | * Inserts a List of Parcelable values into the mapping of this Bundle,
189 | * replacing any existing value for the given key. Either key or value may
190 | * be null.
191 | *
192 | * @param key a String, or null
193 | * @param value an ArrayList of Parcelable objects, or null
194 | * @return this
195 | */
196 | public Bundler putParcelableArrayList(String key,
197 | ArrayList extends Parcelable> value) {
198 | bundle.putParcelableArrayList(key, value);
199 | return this;
200 | }
201 |
202 | /**
203 | * Inserts a SparceArray of Parcelable values into the mapping of this
204 | * Bundle, replacing any existing value for the given key. Either key
205 | * or value may be null.
206 | *
207 | * @param key a String, or null
208 | * @param value a SparseArray of Parcelable objects, or null
209 | * @return this
210 | */
211 | public Bundler putSparseParcelableArray(String key,
212 | SparseArray extends Parcelable> value) {
213 | bundle.putSparseParcelableArray(key, value);
214 | return this;
215 | }
216 |
217 | /**
218 | * Inserts an ArrayList value into the mapping of this Bundle, replacing
219 | * any existing value for the given key. Either key or value may be null.
220 | *
221 | * @param key a String, or null
222 | * @param value an ArrayList object, or null
223 | * @return this
224 | */
225 | public Bundler putIntegerArrayList(String key, ArrayList value) {
226 | bundle.putIntegerArrayList(key, value);
227 | return this;
228 | }
229 |
230 | /**
231 | * Inserts an ArrayList value into the mapping of this Bundle, replacing
232 | * any existing value for the given key. Either key or value may be null.
233 | *
234 | * @param key a String, or null
235 | * @param value an ArrayList object, or null
236 | * @return this
237 | */
238 | public Bundler putStringArrayList(String key, ArrayList value) {
239 | bundle.putStringArrayList(key, value);
240 | return this;
241 | }
242 |
243 | /**
244 | * Inserts an ArrayList value into the mapping of this Bundle, replacing
245 | * any existing value for the given key. Either key or value may be null.
246 | *
247 | * @param key a String, or null
248 | * @param value an ArrayList object, or null
249 | * @return this
250 | */
251 | @TargetApi(8)
252 | public Bundler putCharSequenceArrayList(String key, ArrayList value) {
253 | bundle.putCharSequenceArrayList(key, value);
254 | return this;
255 | }
256 |
257 | /**
258 | * Inserts a Serializable value into the mapping of this Bundle, replacing
259 | * any existing value for the given key. Either key or value may be null.
260 | *
261 | * @param key a String, or null
262 | * @param value a Serializable object, or null
263 | * @return this
264 | */
265 | public Bundler putSerializable(String key, Serializable value) {
266 | bundle.putSerializable(key, value);
267 | return this;
268 | }
269 |
270 | /**
271 | * Inserts a byte array value into the mapping of this Bundle, replacing
272 | * any existing value for the given key. Either key or value may be null.
273 | *
274 | * @param key a String, or null
275 | * @param value a byte array object, or null
276 | * @return this
277 | */
278 | public Bundler putByteArray(String key, byte[] value) {
279 | bundle.putByteArray(key, value);
280 | return this;
281 | }
282 |
283 | /**
284 | * Inserts a short array value into the mapping of this Bundle, replacing
285 | * any existing value for the given key. Either key or value may be null.
286 | *
287 | * @param key a String, or null
288 | * @param value a short array object, or null
289 | * @return this
290 | */
291 | public Bundler putShortArray(String key, short[] value) {
292 | bundle.putShortArray(key, value);
293 | return this;
294 | }
295 |
296 | /**
297 | * Inserts a char array value into the mapping of this Bundle, replacing
298 | * any existing value for the given key. Either key or value may be null.
299 | *
300 | * @param key a String, or null
301 | * @param value a char array object, or null
302 | * @return this
303 | */
304 | public Bundler putCharArray(String key, char[] value) {
305 | bundle.putCharArray(key, value);
306 | return this;
307 | }
308 |
309 | /**
310 | * Inserts a float array value into the mapping of this Bundle, replacing
311 | * any existing value for the given key. Either key or value may be null.
312 | *
313 | * @param key a String, or null
314 | * @param value a float array object, or null
315 | * @return this
316 | */
317 | public Bundler putFloatArray(String key, float[] value) {
318 | bundle.putFloatArray(key, value);
319 | return this;
320 | }
321 |
322 | /**
323 | * Inserts a CharSequence array value into the mapping of this Bundle, replacing
324 | * any existing value for the given key. Either key or value may be null.
325 | *
326 | * @param key a String, or null
327 | * @param value a CharSequence array object, or null
328 | * @return this
329 | */
330 | @TargetApi(8)
331 | public Bundler putCharSequenceArray(String key, CharSequence[] value) {
332 | bundle.putCharSequenceArray(key, value);
333 | return this;
334 | }
335 |
336 | /**
337 | * Inserts a Bundle value into the mapping of this Bundle, replacing
338 | * any existing value for the given key. Either key or value may be null.
339 | *
340 | * @param key a String, or null
341 | * @param value a Bundle object, or null
342 | * @return this
343 | */
344 | public Bundler putBundle(String key, Bundle value) {
345 | bundle.putBundle(key, value);
346 | return this;
347 | }
348 |
349 | /**
350 | * Inserts an {@link android.os.IBinder} value into the mapping of this Bundle, replacing
351 | * any existing value for the given key. Either key or value may be null.
352 | *
353 | *
You should be very careful when using this function. In many
354 | * places where Bundles are used (such as inside of Intent objects), the Bundle
355 | * can live longer inside of another process than the process that had originally
356 | * created it. In that case, the IBinder you supply here will become invalid
357 | * when your process goes away, and no longer usable, even if a new process is
358 | * created for you later on.
359 | *
360 | * @param key a String, or null
361 | * @param value an IBinder object, or null
362 | * @return this
363 | */
364 | @TargetApi(18)
365 | public Bundler putBinder(String key, IBinder value) {
366 | bundle.putBinder(key, value);
367 | return this;
368 | }
369 |
370 | /**
371 | * Inserts a Boolean value into the mapping of this Bundle, replacing
372 | * any existing value for the given key. Either key or value may be null.
373 | *
374 | * @param key a String, or null
375 | * @param value a Boolean, or null
376 | * @return this
377 | */
378 | public Bundler putBoolean(String key, boolean value) {
379 | bundle.putBoolean(key, value);
380 | return this;
381 | }
382 |
383 | /**
384 | * Inserts an int value into the mapping of this Bundle, replacing
385 | * any existing value for the given key.
386 | *
387 | * @param key a String, or null
388 | * @param value an int, or null
389 | * @return this
390 | */
391 | public Bundler putInt(String key, int value) {
392 | bundle.putInt(key, value);
393 | return this;
394 | }
395 |
396 | /**
397 | * Inserts a long value into the mapping of this Bundle, replacing
398 | * any existing value for the given key.
399 | *
400 | * @param key a String, or null
401 | * @param value a long
402 | * @return this
403 | */
404 | public Bundler putLong(String key, long value) {
405 | bundle.putLong(key, value);
406 | return this;
407 | }
408 |
409 | /**
410 | * Inserts a double value into the mapping of this Bundle, replacing
411 | * any existing value for the given key.
412 | *
413 | * @param key a String, or null
414 | * @param value a double
415 | * @return this
416 | */
417 | public Bundler putDouble(String key, double value) {
418 | bundle.putDouble(key, value);
419 | return this;
420 | }
421 |
422 | /**
423 | * Inserts a String value into the mapping of this Bundle, replacing
424 | * any existing value for the given key. Either key or value may be null.
425 | *
426 | * @param key a String, or null
427 | * @param value a String, or null
428 | * @return this
429 | */
430 | public Bundler putString(String key, String value) {
431 | bundle.putString(key, value);
432 | return this;
433 | }
434 |
435 | /**
436 | * Inserts a boolean array value into the mapping of this Bundle, replacing
437 | * any existing value for the given key. Either key or value may be null.
438 | *
439 | * @param key a String, or null
440 | * @param value a boolean array object, or null
441 | * @return this
442 | */
443 | public Bundler putBooleanArray(String key, boolean[] value) {
444 | bundle.putBooleanArray(key, value);
445 | return this;
446 | }
447 |
448 | /**
449 | * Inserts an int array value into the mapping of this Bundle, replacing
450 | * any existing value for the given key. Either key or value may be null.
451 | *
452 | * @param key a String, or null
453 | * @param value an int array object, or null
454 | * @return this
455 | */
456 | public Bundler putIntArray(String key, int[] value) {
457 | bundle.putIntArray(key, value);
458 | return this;
459 | }
460 |
461 | /**
462 | * Inserts a long array value into the mapping of this Bundle, replacing
463 | * any existing value for the given key. Either key or value may be null.
464 | *
465 | * @param key a String, or null
466 | * @param value a long array object, or null
467 | * @return this
468 | */
469 | public Bundler putLongArray(String key, long[] value) {
470 | bundle.putLongArray(key, value);
471 | return this;
472 | }
473 |
474 | /**
475 | * Inserts a double array value into the mapping of this Bundle, replacing
476 | * any existing value for the given key. Either key or value may be null.
477 | *
478 | * @param key a String, or null
479 | * @param value a double array object, or null
480 | * @return this
481 | */
482 | public Bundler putDoubleArray(String key, double[] value) {
483 | bundle.putDoubleArray(key, value);
484 | return this;
485 | }
486 |
487 | /**
488 | * Inserts a String array value into the mapping of this Bundle, replacing
489 | * any existing value for the given key. Either key or value may be null.
490 | *
491 | * @param key a String, or null
492 | * @param value a String array object, or null
493 | * @return this
494 | */
495 | public Bundler putStringArray(String key, String[] value) {
496 | bundle.putStringArray(key, value);
497 | return this;
498 | }
499 |
500 | /**
501 | * Get the bundle.
502 | *
503 | * @return a bundle
504 | */
505 | public Bundle get() {
506 | return bundle;
507 | }
508 |
509 | /**
510 | * Set the argument of Fragment.
511 | *
512 | * @param fragment a fragment
513 | * @return a fragment
514 | */
515 | public T into(T fragment) {
516 | fragment.setArguments(get());
517 | return fragment;
518 | }
519 |
520 | }
521 |
--------------------------------------------------------------------------------
/utils-v4/src/main/java/com/ogaclejapan/smarttablayout/utils/v4/FragmentPagerItem.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
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.ogaclejapan.smarttablayout.utils.v4;
17 |
18 | import android.content.Context;
19 | import android.os.Bundle;
20 |
21 | import com.ogaclejapan.smarttablayout.utils.PagerItem;
22 |
23 | import androidx.fragment.app.Fragment;
24 |
25 | public class FragmentPagerItem extends PagerItem {
26 |
27 | private static final String TAG = "FragmentPagerItem";
28 | private static final String KEY_POSITION = TAG + ":Position";
29 |
30 | private final String className;
31 | private final Bundle args;
32 |
33 | protected FragmentPagerItem(CharSequence title, float width, String className, Bundle args) {
34 | super(title, width);
35 | this.className = className;
36 | this.args = args;
37 | }
38 |
39 | public static FragmentPagerItem of(CharSequence title, Class extends Fragment> clazz) {
40 | return of(title, DEFAULT_WIDTH, clazz);
41 | }
42 |
43 | public static FragmentPagerItem of(CharSequence title, Class extends Fragment> clazz,
44 | Bundle args) {
45 | return of(title, DEFAULT_WIDTH, clazz, args);
46 | }
47 |
48 | public static FragmentPagerItem of(CharSequence title, float width,
49 | Class extends Fragment> clazz) {
50 | return of(title, width, clazz, new Bundle());
51 | }
52 |
53 | public static FragmentPagerItem of(CharSequence title, float width,
54 | Class extends Fragment> clazz, Bundle args) {
55 | return new FragmentPagerItem(title, width, clazz.getName(), args);
56 | }
57 |
58 | public static boolean hasPosition(Bundle args) {
59 | return args != null && args.containsKey(KEY_POSITION);
60 | }
61 |
62 | public static int getPosition(Bundle args) {
63 | return (hasPosition(args)) ? args.getInt(KEY_POSITION) : 0;
64 | }
65 |
66 | static void setPosition(Bundle args, int position) {
67 | args.putInt(KEY_POSITION, position);
68 | }
69 |
70 | public Fragment instantiate(Context context, int position) {
71 | setPosition(args, position);
72 | return Fragment.instantiate(context, className, args);
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/utils-v4/src/main/java/com/ogaclejapan/smarttablayout/utils/v4/FragmentPagerItemAdapter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
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.ogaclejapan.smarttablayout.utils.v4;
17 |
18 | import android.view.ViewGroup;
19 |
20 | import java.lang.ref.WeakReference;
21 |
22 | import androidx.annotation.NonNull;
23 | import androidx.collection.SparseArrayCompat;
24 | import androidx.fragment.app.Fragment;
25 | import androidx.fragment.app.FragmentManager;
26 | import androidx.fragment.app.FragmentPagerAdapter;
27 |
28 | public class FragmentPagerItemAdapter extends FragmentPagerAdapter {
29 |
30 | private final FragmentPagerItems pages;
31 | private final SparseArrayCompat> holder;
32 |
33 | public FragmentPagerItemAdapter(FragmentManager fm, FragmentPagerItems pages) {
34 | super(fm);
35 | this.pages = pages;
36 | this.holder = new SparseArrayCompat<>(pages.size());
37 | }
38 |
39 | @Override
40 | public int getCount() {
41 | return pages.size();
42 | }
43 |
44 | @Override
45 | public Fragment getItem(int position) {
46 | return getPagerItem(position).instantiate(pages.getContext(), position);
47 | }
48 |
49 | @NonNull
50 | @Override
51 | public Object instantiateItem(@NonNull ViewGroup container, int position) {
52 | Object item = super.instantiateItem(container, position);
53 | if (item instanceof Fragment) {
54 | holder.put(position, new WeakReference((Fragment) item));
55 | }
56 | return item;
57 | }
58 |
59 | @Override
60 | public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
61 | holder.remove(position);
62 | super.destroyItem(container, position, object);
63 | }
64 |
65 | @Override
66 | public CharSequence getPageTitle(int position) {
67 | return getPagerItem(position).getTitle();
68 | }
69 |
70 | @Override
71 | public float getPageWidth(int position) {
72 | return super.getPageWidth(position);
73 | }
74 |
75 | public Fragment getPage(int position) {
76 | final WeakReference weakRefItem = holder.get(position);
77 | return (weakRefItem != null) ? weakRefItem.get() : null;
78 | }
79 |
80 | protected FragmentPagerItem getPagerItem(int position) {
81 | return pages.get(position);
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/utils-v4/src/main/java/com/ogaclejapan/smarttablayout/utils/v4/FragmentPagerItems.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
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.ogaclejapan.smarttablayout.utils.v4;
17 |
18 | import android.content.Context;
19 | import android.os.Bundle;
20 |
21 | import com.ogaclejapan.smarttablayout.utils.PagerItems;
22 |
23 | import androidx.annotation.StringRes;
24 | import androidx.fragment.app.Fragment;
25 |
26 | public class FragmentPagerItems extends PagerItems {
27 |
28 | public FragmentPagerItems(Context context) {
29 | super(context);
30 | }
31 |
32 | public static Creator with(Context context) {
33 | return new Creator(context);
34 | }
35 |
36 | public static class Creator {
37 |
38 | private final FragmentPagerItems items;
39 |
40 | public Creator(Context context) {
41 | items = new FragmentPagerItems(context);
42 | }
43 |
44 | public Creator add(@StringRes int title, Class extends Fragment> clazz) {
45 | return add(FragmentPagerItem.of(items.getContext().getString(title), clazz));
46 | }
47 |
48 | public Creator add(@StringRes int title, Class extends Fragment> clazz, Bundle args) {
49 | return add(FragmentPagerItem.of(items.getContext().getString(title), clazz, args));
50 | }
51 |
52 | public Creator add(@StringRes int title, float width, Class extends Fragment> clazz) {
53 | return add(FragmentPagerItem.of(items.getContext().getString(title), width, clazz));
54 | }
55 |
56 | public Creator add(@StringRes int title, float width, Class extends Fragment> clazz,
57 | Bundle args) {
58 | return add(FragmentPagerItem.of(items.getContext().getString(title), width, clazz, args));
59 | }
60 |
61 | public Creator add(CharSequence title, Class extends Fragment> clazz) {
62 | return add(FragmentPagerItem.of(title, clazz));
63 | }
64 |
65 | public Creator add(CharSequence title, Class extends Fragment> clazz, Bundle args) {
66 | return add(FragmentPagerItem.of(title, clazz, args));
67 | }
68 |
69 | public Creator add(FragmentPagerItem item) {
70 | items.add(item);
71 | return this;
72 | }
73 |
74 | public FragmentPagerItems create() {
75 | return items;
76 | }
77 |
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/utils-v4/src/main/java/com/ogaclejapan/smarttablayout/utils/v4/FragmentStatePagerItemAdapter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 ogaclejapan
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.ogaclejapan.smarttablayout.utils.v4;
17 |
18 | import android.view.ViewGroup;
19 |
20 | import java.lang.ref.WeakReference;
21 |
22 | import androidx.annotation.NonNull;
23 | import androidx.collection.SparseArrayCompat;
24 | import androidx.fragment.app.Fragment;
25 | import androidx.fragment.app.FragmentManager;
26 | import androidx.fragment.app.FragmentStatePagerAdapter;
27 |
28 | public class FragmentStatePagerItemAdapter extends FragmentStatePagerAdapter {
29 |
30 | private final FragmentPagerItems pages;
31 | private final SparseArrayCompat> holder;
32 |
33 | public FragmentStatePagerItemAdapter(FragmentManager fm, FragmentPagerItems pages) {
34 | super(fm);
35 | this.pages = pages;
36 | this.holder = new SparseArrayCompat<>(pages.size());
37 | }
38 |
39 | @Override
40 | public int getCount() {
41 | return pages.size();
42 | }
43 |
44 | @Override
45 | public Fragment getItem(int position) {
46 | return getPagerItem(position).instantiate(pages.getContext(), position);
47 | }
48 |
49 | @NonNull
50 | @Override
51 | public Object instantiateItem(@NonNull ViewGroup container, int position) {
52 | Object item = super.instantiateItem(container, position);
53 | if (item instanceof Fragment) {
54 | holder.put(position, new WeakReference((Fragment) item));
55 | }
56 | return item;
57 | }
58 |
59 | @Override
60 | public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
61 | holder.remove(position);
62 | super.destroyItem(container, position, object);
63 | }
64 |
65 | @Override
66 | public CharSequence getPageTitle(int position) {
67 | return getPagerItem(position).getTitle();
68 | }
69 |
70 | @Override
71 | public float getPageWidth(int position) {
72 | return getPagerItem(position).getWidth();
73 | }
74 |
75 | public Fragment getPage(int position) {
76 | final WeakReference weakRefItem = holder.get(position);
77 | return (weakRefItem != null) ? weakRefItem.get() : null;
78 | }
79 |
80 | protected FragmentPagerItem getPagerItem(int position) {
81 | return pages.get(position);
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------