├── .classpath
├── .github
└── FUNDING.yml
├── .gitignore
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── LICENSE
├── README.md
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── libs
└── android-support-v4.jar
├── lint.xml
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ ├── ic_header_logo.png
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── drawable
│ ├── background_tab.xml
│ ├── pic0.jpg
│ └── pic1.jpg
├── layout-xhdpi
│ ├── activity_main.xml
│ ├── fragment_list.xml
│ ├── list_item.xml
│ ├── view_header_placeholder.xml
│ └── view_kenburns.xml
└── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── dimens.xml
│ └── strings.xml
├── screen.png
└── src
└── com
├── astuetz
└── PagerSlidingTabStrip.java
└── kmshack
└── newsstand
├── MainActivity.java
├── SampleListFragment.java
├── ScrollTabHolder.java
└── ScrollTabHolderFragment.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: paypal.me/kmshack
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | gen/
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | ParallaxHeaderViewPager
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ParallaxHeaderViewPager Example
2 | ===================
3 |
4 | HeaderView to secure the top left and right swipe at ViewPager even when a sample code for implementing HeaderView UI that can be maintained. Through the sample code, you can configure a better UI.
5 |
6 |
7 | 
8 |
9 |
10 | Sample Application Download
11 | ----
12 | https://play.google.com/store/apps/details?id=com.kmshack.newsstand
13 |
14 |
15 | License
16 | ----
17 | Apache License, Version 2.0
18 |
19 |
20 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:1.1.1'
7 | }
8 | }
9 | apply plugin: 'android'
10 |
11 | dependencies {
12 | compile fileTree(dir: 'libs', include: '*.jar')
13 | }
14 |
15 | android {
16 | compileSdkVersion 22
17 | buildToolsVersion "22.0.1"
18 |
19 | sourceSets {
20 | main {
21 | manifest.srcFile 'AndroidManifest.xml'
22 | java.srcDirs = ['src']
23 | resources.srcDirs = ['src']
24 | aidl.srcDirs = ['src']
25 | renderscript.srcDirs = ['src']
26 | res.srcDirs = ['res']
27 | assets.srcDirs = ['assets']
28 | }
29 |
30 | // Move the tests to tests/java, tests/res, etc...
31 | instrumentTest.setRoot('tests')
32 |
33 | // Move the build types to build-types/
34 | // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
35 | // This moves them out of them default location under src//... which would
36 | // conflict with src/ being used by the main source set.
37 | // Adding new build types or product flavors should be accompanied
38 | // by a similar customization.
39 | debug.setRoot('build-types/debug')
40 | release.setRoot('build-types/release')
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmshack/Android-ParallaxHeaderViewPager/66700fd25b6968cc3789f8c8d721f880eba430ab/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=http\://services.gradle.org/distributions/gradle-1.10-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 |
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmshack/Android-ParallaxHeaderViewPager/66700fd25b6968cc3789f8c8d721f880eba430ab/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmshack/Android-ParallaxHeaderViewPager/66700fd25b6968cc3789f8c8d721f880eba430ab/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmshack/Android-ParallaxHeaderViewPager/66700fd25b6968cc3789f8c8d721f880eba430ab/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_header_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmshack/Android-ParallaxHeaderViewPager/66700fd25b6968cc3789f8c8d721f880eba430ab/res/drawable-xhdpi/ic_header_logo.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmshack/Android-ParallaxHeaderViewPager/66700fd25b6968cc3789f8c8d721f880eba430ab/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmshack/Android-ParallaxHeaderViewPager/66700fd25b6968cc3789f8c8d721f880eba430ab/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/background_tab.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/drawable/pic0.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmshack/Android-ParallaxHeaderViewPager/66700fd25b6968cc3789f8c8d721f880eba430ab/res/drawable/pic0.jpg
--------------------------------------------------------------------------------
/res/drawable/pic1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmshack/Android-ParallaxHeaderViewPager/66700fd25b6968cc3789f8c8d721f880eba430ab/res/drawable/pic1.jpg
--------------------------------------------------------------------------------
/res/layout-xhdpi/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
18 |
25 |
26 |
32 |
33 |
41 |
--------------------------------------------------------------------------------
/res/layout-xhdpi/fragment_list.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/res/layout-xhdpi/list_item.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/res/layout-xhdpi/view_header_placeholder.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/res/layout-xhdpi/view_kenburns.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
12 |
13 |
18 |
--------------------------------------------------------------------------------
/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6633B5E5
4 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 | 298dp
7 | 250dp
8 | 100dp
9 |
10 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ParallaxHeaderViewPager
5 | ParallaxHeaderViewPager
6 |
7 |
8 |
--------------------------------------------------------------------------------
/screen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmshack/Android-ParallaxHeaderViewPager/66700fd25b6968cc3789f8c8d721f880eba430ab/screen.png
--------------------------------------------------------------------------------
/src/com/astuetz/PagerSlidingTabStrip.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Andreas Stuetz
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 |
17 | package com.astuetz;
18 |
19 | import java.util.Locale;
20 |
21 | import android.annotation.SuppressLint;
22 | import android.content.Context;
23 | import android.content.res.TypedArray;
24 | import android.graphics.Canvas;
25 | import android.graphics.Paint;
26 | import android.graphics.Paint.Style;
27 | import android.graphics.Typeface;
28 | import android.os.Build;
29 | import android.os.Parcel;
30 | import android.os.Parcelable;
31 | import android.support.v4.view.ViewPager;
32 | import android.support.v4.view.ViewPager.OnPageChangeListener;
33 | import android.util.AttributeSet;
34 | import android.util.DisplayMetrics;
35 | import android.util.TypedValue;
36 | import android.view.Gravity;
37 | import android.view.View;
38 | import android.view.ViewTreeObserver.OnGlobalLayoutListener;
39 | import android.widget.HorizontalScrollView;
40 | import android.widget.ImageButton;
41 | import android.widget.LinearLayout;
42 | import android.widget.TextView;
43 |
44 | import com.kmshack.newsstand.R;
45 |
46 | public class PagerSlidingTabStrip extends HorizontalScrollView {
47 |
48 | public interface IconTabProvider {
49 | public int getPageIconResId(int position);
50 | }
51 |
52 | // @formatter:off
53 | private static final int[] ATTRS = new int[] {
54 | android.R.attr.textSize,
55 | android.R.attr.textColor
56 | };
57 | // @formatter:on
58 |
59 | private LinearLayout.LayoutParams defaultTabLayoutParams;
60 | private LinearLayout.LayoutParams expandedTabLayoutParams;
61 |
62 | private final PageListener pageListener = new PageListener();
63 | public OnPageChangeListener delegatePageListener;
64 |
65 | private LinearLayout tabsContainer;
66 | private ViewPager pager;
67 |
68 | private int tabCount;
69 |
70 | private int currentPosition = 0;
71 | private float currentPositionOffset = 0f;
72 |
73 | private Paint rectPaint;
74 | private Paint dividerPaint;
75 |
76 | private int indicatorColor = 0xEEFFFFFF;
77 | private int underlineColor = 0x33FFFFFF;
78 | private int dividerColor = 0xAAFFFFFF;
79 |
80 | private boolean shouldExpand = false;
81 | private boolean textAllCaps = true;
82 |
83 | private int scrollOffset = 52;
84 | private int indicatorHeight = 4;
85 | private int underlineHeight = 2;
86 | private int dividerPadding = 12;
87 | private int tabPadding = 24;
88 | private int dividerWidth = 1;
89 |
90 | private int tabTextSize = 12;
91 | private int tabTextColor = 0xFFFFFFFF;
92 | private Typeface tabTypeface = null;
93 | private int tabTypefaceStyle = Typeface.BOLD;
94 |
95 | private int lastScrollX = 0;
96 |
97 | private int tabBackgroundResId = R.drawable.background_tab;
98 |
99 | private Locale locale;
100 |
101 | public PagerSlidingTabStrip(Context context) {
102 | this(context, null);
103 | }
104 |
105 | public PagerSlidingTabStrip(Context context, AttributeSet attrs) {
106 | this(context, attrs, 0);
107 | }
108 |
109 | public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
110 | super(context, attrs, defStyle);
111 |
112 | setFillViewport(true);
113 | setWillNotDraw(false);
114 |
115 | tabsContainer = new LinearLayout(context);
116 | tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
117 | tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
118 | addView(tabsContainer);
119 |
120 | DisplayMetrics dm = getResources().getDisplayMetrics();
121 |
122 | scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
123 | indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
124 | underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
125 | dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
126 | tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
127 | dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
128 | tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);
129 |
130 | // get system attrs (android:textSize and android:textColor)
131 |
132 | TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
133 |
134 | tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
135 | tabTextColor = a.getColor(1, tabTextColor);
136 |
137 | a.recycle();
138 |
139 | // get custom attrs
140 |
141 | a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
142 |
143 | indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
144 | underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
145 | dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
146 | indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight);
147 | underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight);
148 | dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding);
149 | tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
150 | tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId);
151 | shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
152 | scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
153 | textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
154 |
155 | a.recycle();
156 |
157 | rectPaint = new Paint();
158 | rectPaint.setAntiAlias(true);
159 | rectPaint.setStyle(Style.FILL);
160 |
161 | dividerPaint = new Paint();
162 | dividerPaint.setAntiAlias(true);
163 | dividerPaint.setStrokeWidth(dividerWidth);
164 |
165 | defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
166 | expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);
167 |
168 | if (locale == null) {
169 | locale = getResources().getConfiguration().locale;
170 | }
171 | }
172 |
173 | public void setViewPager(ViewPager pager) {
174 | this.pager = pager;
175 |
176 | if (pager.getAdapter() == null) {
177 | throw new IllegalStateException("ViewPager does not have adapter instance.");
178 | }
179 |
180 | pager.setOnPageChangeListener(pageListener);
181 |
182 | notifyDataSetChanged();
183 | }
184 |
185 | public void setOnPageChangeListener(OnPageChangeListener listener) {
186 | this.delegatePageListener = listener;
187 | }
188 |
189 | public void notifyDataSetChanged() {
190 |
191 | tabsContainer.removeAllViews();
192 |
193 | tabCount = pager.getAdapter().getCount();
194 |
195 | for (int i = 0; i < tabCount; i++) {
196 |
197 | if (pager.getAdapter() instanceof IconTabProvider) {
198 | addIconTab(i, ((IconTabProvider) pager.getAdapter()).getPageIconResId(i));
199 | } else {
200 | addTextTab(i, pager.getAdapter().getPageTitle(i).toString());
201 | }
202 |
203 | }
204 |
205 | updateTabStyles();
206 |
207 | getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
208 |
209 | @SuppressWarnings("deprecation")
210 | @SuppressLint("NewApi")
211 | @Override
212 | public void onGlobalLayout() {
213 |
214 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
215 | getViewTreeObserver().removeGlobalOnLayoutListener(this);
216 | } else {
217 | getViewTreeObserver().removeOnGlobalLayoutListener(this);
218 | }
219 |
220 | currentPosition = pager.getCurrentItem();
221 | scrollToChild(currentPosition, 0);
222 | }
223 | });
224 |
225 | }
226 |
227 | private void addTextTab(final int position, String title) {
228 |
229 | TextView tab = new TextView(getContext());
230 | tab.setText(title);
231 | tab.setGravity(Gravity.CENTER);
232 | tab.setSingleLine();
233 |
234 | addTab(position, tab);
235 | }
236 |
237 | private void addIconTab(final int position, int resId) {
238 |
239 | ImageButton tab = new ImageButton(getContext());
240 | tab.setImageResource(resId);
241 |
242 | addTab(position, tab);
243 |
244 | }
245 |
246 | private void addTab(final int position, View tab) {
247 | tab.setFocusable(true);
248 | tab.setOnClickListener(new OnClickListener() {
249 | @Override
250 | public void onClick(View v) {
251 | pager.setCurrentItem(position);
252 | }
253 | });
254 |
255 | tab.setPadding(tabPadding, 0, tabPadding, 0);
256 | tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
257 | }
258 |
259 | private void updateTabStyles() {
260 |
261 | for (int i = 0; i < tabCount; i++) {
262 |
263 | View v = tabsContainer.getChildAt(i);
264 |
265 | v.setBackgroundResource(tabBackgroundResId);
266 |
267 | if (v instanceof TextView) {
268 |
269 | TextView tab = (TextView) v;
270 | tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
271 | tab.setTypeface(tabTypeface, tabTypefaceStyle);
272 | tab.setTextColor(tabTextColor);
273 |
274 | // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
275 | // pre-ICS-build
276 | if (textAllCaps) {
277 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
278 | tab.setAllCaps(true);
279 | } else {
280 | tab.setText(tab.getText().toString().toUpperCase(locale));
281 | }
282 | }
283 | }
284 | }
285 |
286 | }
287 |
288 | private void scrollToChild(int position, int offset) {
289 |
290 | if (tabCount == 0) {
291 | return;
292 | }
293 |
294 | int newScrollX = tabsContainer.getChildAt(position).getLeft() + offset;
295 |
296 | if (position > 0 || offset > 0) {
297 | newScrollX -= scrollOffset;
298 | }
299 |
300 | if (newScrollX != lastScrollX) {
301 | lastScrollX = newScrollX;
302 | scrollTo(newScrollX, 0);
303 | }
304 |
305 | }
306 |
307 | @Override
308 | protected void onDraw(Canvas canvas) {
309 | super.onDraw(canvas);
310 |
311 | if (isInEditMode() || tabCount == 0) {
312 | return;
313 | }
314 |
315 | final int height = getHeight();
316 |
317 | // draw indicator line
318 |
319 | rectPaint.setColor(indicatorColor);
320 |
321 | // default: line below current tab
322 | View currentTab = tabsContainer.getChildAt(currentPosition);
323 | float lineLeft = currentTab.getLeft();
324 | float lineRight = currentTab.getRight();
325 |
326 | // if there is an offset, start interpolating left and right coordinates between current and next tab
327 | if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {
328 |
329 | View nextTab = tabsContainer.getChildAt(currentPosition + 1);
330 | final float nextTabLeft = nextTab.getLeft();
331 | final float nextTabRight = nextTab.getRight();
332 |
333 | lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
334 | lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
335 | }
336 |
337 | canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
338 |
339 | // draw underline
340 |
341 | rectPaint.setColor(underlineColor);
342 | canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);
343 |
344 | // draw divider
345 |
346 | dividerPaint.setColor(dividerColor);
347 | for (int i = 0; i < tabCount - 1; i++) {
348 | View tab = tabsContainer.getChildAt(i);
349 | canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding, dividerPaint);
350 | }
351 | }
352 |
353 | private class PageListener implements OnPageChangeListener {
354 |
355 | @Override
356 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
357 |
358 | currentPosition = position;
359 | currentPositionOffset = positionOffset;
360 |
361 | scrollToChild(position, (int) (positionOffset * tabsContainer.getChildAt(position).getWidth()));
362 |
363 | invalidate();
364 |
365 | if (delegatePageListener != null) {
366 | delegatePageListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
367 | }
368 | }
369 |
370 | @Override
371 | public void onPageScrollStateChanged(int state) {
372 | if (state == ViewPager.SCROLL_STATE_IDLE) {
373 | scrollToChild(pager.getCurrentItem(), 0);
374 | }
375 |
376 | if (delegatePageListener != null) {
377 | delegatePageListener.onPageScrollStateChanged(state);
378 | }
379 | }
380 |
381 | @Override
382 | public void onPageSelected(int position) {
383 | if (delegatePageListener != null) {
384 | delegatePageListener.onPageSelected(position);
385 | }
386 | }
387 |
388 | }
389 |
390 | public void setIndicatorColor(int indicatorColor) {
391 | this.indicatorColor = indicatorColor;
392 | invalidate();
393 | }
394 |
395 | public void setIndicatorColorResource(int resId) {
396 | this.indicatorColor = getResources().getColor(resId);
397 | invalidate();
398 | }
399 |
400 | public int getIndicatorColor() {
401 | return this.indicatorColor;
402 | }
403 |
404 | public void setIndicatorHeight(int indicatorLineHeightPx) {
405 | this.indicatorHeight = indicatorLineHeightPx;
406 | invalidate();
407 | }
408 |
409 | public int getIndicatorHeight() {
410 | return indicatorHeight;
411 | }
412 |
413 | public void setUnderlineColor(int underlineColor) {
414 | this.underlineColor = underlineColor;
415 | invalidate();
416 | }
417 |
418 | public void setUnderlineColorResource(int resId) {
419 | this.underlineColor = getResources().getColor(resId);
420 | invalidate();
421 | }
422 |
423 | public int getUnderlineColor() {
424 | return underlineColor;
425 | }
426 |
427 | public void setDividerColor(int dividerColor) {
428 | this.dividerColor = dividerColor;
429 | invalidate();
430 | }
431 |
432 | public void setDividerColorResource(int resId) {
433 | this.dividerColor = getResources().getColor(resId);
434 | invalidate();
435 | }
436 |
437 | public int getDividerColor() {
438 | return dividerColor;
439 | }
440 |
441 | public void setUnderlineHeight(int underlineHeightPx) {
442 | this.underlineHeight = underlineHeightPx;
443 | invalidate();
444 | }
445 |
446 | public int getUnderlineHeight() {
447 | return underlineHeight;
448 | }
449 |
450 | public void setDividerPadding(int dividerPaddingPx) {
451 | this.dividerPadding = dividerPaddingPx;
452 | invalidate();
453 | }
454 |
455 | public int getDividerPadding() {
456 | return dividerPadding;
457 | }
458 |
459 | public void setScrollOffset(int scrollOffsetPx) {
460 | this.scrollOffset = scrollOffsetPx;
461 | invalidate();
462 | }
463 |
464 | public int getScrollOffset() {
465 | return scrollOffset;
466 | }
467 |
468 | public void setShouldExpand(boolean shouldExpand) {
469 | this.shouldExpand = shouldExpand;
470 | requestLayout();
471 | }
472 |
473 | public boolean getShouldExpand() {
474 | return shouldExpand;
475 | }
476 |
477 | public boolean isTextAllCaps() {
478 | return textAllCaps;
479 | }
480 |
481 | public void setAllCaps(boolean textAllCaps) {
482 | this.textAllCaps = textAllCaps;
483 | }
484 |
485 | public void setTextSize(int textSizePx) {
486 | this.tabTextSize = textSizePx;
487 | updateTabStyles();
488 | }
489 |
490 | public int getTextSize() {
491 | return tabTextSize;
492 | }
493 |
494 | public void setTextColor(int textColor) {
495 | this.tabTextColor = textColor;
496 | updateTabStyles();
497 | }
498 |
499 | public void setTextColorResource(int resId) {
500 | this.tabTextColor = getResources().getColor(resId);
501 | updateTabStyles();
502 | }
503 |
504 | public int getTextColor() {
505 | return tabTextColor;
506 | }
507 |
508 | public void setTypeface(Typeface typeface, int style) {
509 | this.tabTypeface = typeface;
510 | this.tabTypefaceStyle = style;
511 | updateTabStyles();
512 | }
513 |
514 | public void setTabBackground(int resId) {
515 | this.tabBackgroundResId = resId;
516 | }
517 |
518 | public int getTabBackground() {
519 | return tabBackgroundResId;
520 | }
521 |
522 | public void setTabPaddingLeftRight(int paddingPx) {
523 | this.tabPadding = paddingPx;
524 | updateTabStyles();
525 | }
526 |
527 | public int getTabPaddingLeftRight() {
528 | return tabPadding;
529 | }
530 |
531 | @Override
532 | public void onRestoreInstanceState(Parcelable state) {
533 | SavedState savedState = (SavedState) state;
534 | super.onRestoreInstanceState(savedState.getSuperState());
535 | currentPosition = savedState.currentPosition;
536 | requestLayout();
537 | }
538 |
539 | @Override
540 | public Parcelable onSaveInstanceState() {
541 | Parcelable superState = super.onSaveInstanceState();
542 | SavedState savedState = new SavedState(superState);
543 | savedState.currentPosition = currentPosition;
544 | return savedState;
545 | }
546 |
547 | static class SavedState extends BaseSavedState {
548 | int currentPosition;
549 |
550 | public SavedState(Parcelable superState) {
551 | super(superState);
552 | }
553 |
554 | private SavedState(Parcel in) {
555 | super(in);
556 | currentPosition = in.readInt();
557 | }
558 |
559 | @Override
560 | public void writeToParcel(Parcel dest, int flags) {
561 | super.writeToParcel(dest, flags);
562 | dest.writeInt(currentPosition);
563 | }
564 |
565 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
566 | @Override
567 | public SavedState createFromParcel(Parcel in) {
568 | return new SavedState(in);
569 | }
570 |
571 | @Override
572 | public SavedState[] newArray(int size) {
573 | return new SavedState[size];
574 | }
575 | };
576 | }
577 |
578 | }
579 |
--------------------------------------------------------------------------------
/src/com/kmshack/newsstand/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.kmshack.newsstand;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.os.Build;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v4.app.FragmentActivity;
8 | import android.support.v4.app.FragmentManager;
9 | import android.support.v4.app.FragmentPagerAdapter;
10 | import android.support.v4.util.SparseArrayCompat;
11 | import android.support.v4.view.ViewPager;
12 | import android.view.View;
13 | import android.widget.AbsListView;
14 | import android.widget.TextView;
15 |
16 | import com.astuetz.PagerSlidingTabStrip;
17 |
18 | @SuppressLint("NewApi")
19 | public class MainActivity extends FragmentActivity implements ScrollTabHolder, ViewPager.OnPageChangeListener {
20 |
21 | public static final boolean NEEDS_PROXY = Integer.valueOf(Build.VERSION.SDK_INT).intValue() < 11;
22 |
23 | private View mHeader;
24 |
25 | private PagerSlidingTabStrip mPagerSlidingTabStrip;
26 | private ViewPager mViewPager;
27 | private PagerAdapter mPagerAdapter;
28 |
29 | private int mMinHeaderHeight;
30 | private int mHeaderHeight;
31 | private int mMinHeaderTranslation;
32 |
33 | private TextView info;
34 | private int mLastY;
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 |
40 | mMinHeaderHeight = getResources().getDimensionPixelSize(R.dimen.min_header_height);
41 | mHeaderHeight = getResources().getDimensionPixelSize(R.dimen.header_height);
42 | mMinHeaderTranslation = -mMinHeaderHeight;
43 |
44 | setContentView(R.layout.activity_main);
45 |
46 | mHeader = findViewById(R.id.header);
47 | info = (TextView) findViewById(R.id.info);
48 |
49 | mPagerSlidingTabStrip = (PagerSlidingTabStrip) findViewById(R.id.tabs);
50 | mViewPager = (ViewPager) findViewById(R.id.pager);
51 | mViewPager.setOffscreenPageLimit(4);
52 |
53 | mPagerAdapter = new PagerAdapter(getSupportFragmentManager());
54 | mPagerAdapter.setTabHolderScrollingContent(this);
55 |
56 | mViewPager.setAdapter(mPagerAdapter);
57 |
58 | mPagerSlidingTabStrip.setViewPager(mViewPager);
59 | mPagerSlidingTabStrip.setOnPageChangeListener(this);
60 | mLastY=0;
61 | }
62 |
63 | @Override
64 | public void onPageScrollStateChanged(int arg0) {
65 | // nothing
66 | }
67 |
68 | @Override
69 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
70 |
71 | if (positionOffsetPixels > 0) {
72 | int currentItem = mViewPager.getCurrentItem();
73 |
74 | SparseArrayCompat scrollTabHolders = mPagerAdapter.getScrollTabHolders();
75 | ScrollTabHolder currentHolder;
76 |
77 | if (position < currentItem) {
78 | currentHolder = scrollTabHolders.valueAt(position);
79 | } else {
80 | currentHolder = scrollTabHolders.valueAt(position + 1);
81 | }
82 |
83 | if (NEEDS_PROXY) {
84 | // TODO is not good
85 | currentHolder.adjustScroll(mHeader.getHeight() - mLastY);
86 | mHeader.postInvalidate();
87 | } else {
88 | currentHolder.adjustScroll((int) (mHeader.getHeight() + mHeader.getTranslationY()));
89 | }
90 | }
91 | }
92 |
93 | @Override
94 | public void onPageSelected(int position) {
95 | SparseArrayCompat scrollTabHolders = mPagerAdapter.getScrollTabHolders();
96 | ScrollTabHolder currentHolder = scrollTabHolders.valueAt(position);
97 | if(NEEDS_PROXY){
98 | //TODO is not good
99 | currentHolder.adjustScroll(mHeader.getHeight()-mLastY);
100 | mHeader.postInvalidate();
101 | }else{
102 | currentHolder.adjustScroll((int) (mHeader.getHeight() +mHeader.getTranslationY()));
103 | }
104 | }
105 |
106 | @Override
107 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount, int pagePosition) {
108 | if (mViewPager.getCurrentItem() == pagePosition) {
109 | int scrollY = getScrollY(view);
110 | if(NEEDS_PROXY){
111 | //TODO is not good
112 | mLastY=-Math.max(-scrollY, mMinHeaderTranslation);
113 | info.setText(String.valueOf(scrollY));
114 | mHeader.scrollTo(0, mLastY);
115 | mHeader.postInvalidate();
116 | }else{
117 | mHeader.setTranslationY(Math.max(-scrollY, mMinHeaderTranslation));
118 | }
119 | }
120 | }
121 |
122 | @Override
123 | public void adjustScroll(int scrollHeight) {
124 | // nothing
125 | }
126 |
127 | public int getScrollY(AbsListView view) {
128 | View c = view.getChildAt(0);
129 | if (c == null) {
130 | return 0;
131 | }
132 |
133 | int firstVisiblePosition = view.getFirstVisiblePosition();
134 | int top = c.getTop();
135 |
136 | int headerHeight = 0;
137 | if (firstVisiblePosition >= 1) {
138 | headerHeight = mHeaderHeight;
139 | }
140 |
141 | return -top + firstVisiblePosition * c.getHeight() + headerHeight;
142 | }
143 |
144 | public static float clamp(float value, float max, float min) {
145 | return Math.max(Math.min(value, min), max);
146 | }
147 |
148 | public class PagerAdapter extends FragmentPagerAdapter {
149 |
150 | private SparseArrayCompat mScrollTabHolders;
151 | private final String[] TITLES = { "Page 1", "Page 2", "Page 3", "Page 4"};
152 | private ScrollTabHolder mListener;
153 |
154 | public PagerAdapter(FragmentManager fm) {
155 | super(fm);
156 | mScrollTabHolders = new SparseArrayCompat();
157 | }
158 |
159 | public void setTabHolderScrollingContent(ScrollTabHolder listener) {
160 | mListener = listener;
161 | }
162 |
163 | @Override
164 | public CharSequence getPageTitle(int position) {
165 | return TITLES[position];
166 | }
167 |
168 | @Override
169 | public int getCount() {
170 | return TITLES.length;
171 | }
172 |
173 | @Override
174 | public Fragment getItem(int position) {
175 | ScrollTabHolderFragment fragment = (ScrollTabHolderFragment) SampleListFragment.newInstance(position);
176 |
177 | mScrollTabHolders.put(position, fragment);
178 | if (mListener != null) {
179 | fragment.setScrollTabHolder(mListener);
180 | }
181 |
182 | return fragment;
183 | }
184 |
185 | public SparseArrayCompat getScrollTabHolders() {
186 | return mScrollTabHolders;
187 | }
188 |
189 | }
190 | }
191 |
--------------------------------------------------------------------------------
/src/com/kmshack/newsstand/SampleListFragment.java:
--------------------------------------------------------------------------------
1 | package com.kmshack.newsstand;
2 |
3 | import java.util.ArrayList;
4 |
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.MotionEvent;
9 | import android.view.View;
10 | import android.view.View.OnTouchListener;
11 | import android.view.ViewGroup;
12 | import android.widget.AbsListView;
13 | import android.widget.AbsListView.OnScrollListener;
14 | import android.widget.ArrayAdapter;
15 | import android.widget.ListView;
16 |
17 | public class SampleListFragment extends ScrollTabHolderFragment{
18 |
19 | private static final String ARG_POSITION = "position";
20 |
21 | private ListView mListView;
22 | private ArrayList mListItems;
23 |
24 | private int mPosition;
25 |
26 | public static Fragment newInstance(int position) {
27 | SampleListFragment f = new SampleListFragment();
28 | Bundle b = new Bundle();
29 | b.putInt(ARG_POSITION, position);
30 | f.setArguments(b);
31 | return f;
32 | }
33 |
34 | @Override
35 | public void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | mPosition = getArguments().getInt(ARG_POSITION);
38 |
39 | mListItems = new ArrayList();
40 |
41 | for (int i = 1; i <= 100; i++) {
42 | mListItems.add(i + ". item - currnet page: " + (mPosition + 1));
43 | }
44 | }
45 |
46 | @Override
47 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
48 | View v = inflater.inflate(R.layout.fragment_list, null);
49 |
50 | mListView = (ListView) v.findViewById(R.id.listView);
51 |
52 | View placeHolderView = inflater.inflate(R.layout.view_header_placeholder, mListView, false);
53 | placeHolderView.setBackgroundColor(0xFFFFFFFF);
54 | mListView.addHeaderView(placeHolderView);
55 |
56 | return v;
57 | }
58 |
59 | @Override
60 | public void onActivityCreated(Bundle savedInstanceState) {
61 | super.onActivityCreated(savedInstanceState);
62 |
63 | mListView.setOnScrollListener(new OnScroll());
64 | mListView.setAdapter(new ArrayAdapter(getActivity(), R.layout.list_item, android.R.id.text1, mListItems));
65 |
66 | if(MainActivity.NEEDS_PROXY){//in my moto phone(android 2.1),setOnScrollListener do not work well
67 | mListView.setOnTouchListener(new OnTouchListener() {
68 | @Override
69 | public boolean onTouch(View v, MotionEvent event) {
70 | if (mScrollTabHolder != null)
71 | mScrollTabHolder.onScroll(mListView, 0, 0, 0, mPosition);
72 | return false;
73 | }
74 | });
75 | }
76 | }
77 |
78 | @Override
79 | public void adjustScroll(int scrollHeight) {
80 | if (scrollHeight == 0 && mListView.getFirstVisiblePosition() >= 1) {
81 | return;
82 | }
83 |
84 | mListView.setSelectionFromTop(1, scrollHeight);
85 |
86 | }
87 |
88 | public class OnScroll implements OnScrollListener{
89 |
90 | @Override
91 | public void onScrollStateChanged(AbsListView view, int scrollState) {
92 |
93 | }
94 |
95 | @Override
96 | public void onScroll(AbsListView view, int firstVisibleItem,
97 | int visibleItemCount, int totalItemCount) {
98 | if (mScrollTabHolder != null)
99 | mScrollTabHolder.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount, mPosition);
100 | }
101 |
102 | }
103 |
104 |
105 | @Override
106 | public void onScroll(AbsListView view, int firstVisibleItem,
107 | int visibleItemCount, int totalItemCount, int pagePosition) {
108 | }
109 |
110 | }
--------------------------------------------------------------------------------
/src/com/kmshack/newsstand/ScrollTabHolder.java:
--------------------------------------------------------------------------------
1 | package com.kmshack.newsstand;
2 |
3 | import android.widget.AbsListView;
4 |
5 | public interface ScrollTabHolder {
6 |
7 | void adjustScroll(int scrollHeight);
8 |
9 | void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount, int pagePosition);
10 | }
11 |
--------------------------------------------------------------------------------
/src/com/kmshack/newsstand/ScrollTabHolderFragment.java:
--------------------------------------------------------------------------------
1 | package com.kmshack.newsstand;
2 |
3 | import android.support.v4.app.Fragment;
4 |
5 | public abstract class ScrollTabHolderFragment extends Fragment implements ScrollTabHolder {
6 |
7 | protected ScrollTabHolder mScrollTabHolder;
8 |
9 | public void setScrollTabHolder(ScrollTabHolder scrollTabHolder) {
10 | mScrollTabHolder = scrollTabHolder;
11 | }
12 | }
--------------------------------------------------------------------------------