├── .gitignore
├── AndroidManifest.xml
├── LICENSE
├── README.md
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── libs
└── android-support-v4.jar
├── project.properties
└── src
└── com
└── imbryk
└── viewPager
├── LoopPagerAdapterWrapper.java
└── LoopViewPager.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.apk
2 | *.ap_
3 |
4 | # files for the dex VM
5 | *.dex
6 |
7 | # Java class files
8 | *.class
9 | # generated files
10 | bin/
11 | gen/
12 | build/
13 |
14 | # Local configuration file (sdk path, etc)
15 | local.properties
16 |
17 | # Eclipse project files
18 | .classpath
19 | .project
20 | proguard-project.txt
21 |
22 | # IntelliJ project files
23 | *.iws
24 | */.idea/workspace.xml
25 | */.idea/tasks.xml
26 |
27 | # Gradle files
28 | /.gradle
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/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, and
10 | distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright
13 | owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all other entities
16 | that control, are controlled by, or are under common control with that entity.
17 | For the purposes of this definition, "control" means (i) the power, direct or
18 | indirect, to cause the direction or management of such entity, whether by
19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20 | outstanding shares, or (iii) beneficial ownership of such entity.
21 |
22 | "You" (or "Your") shall mean an individual or Legal Entity exercising
23 | permissions granted by this License.
24 |
25 | "Source" form shall mean the preferred form for making modifications, including
26 | but not limited to software source code, documentation source, and configuration
27 | files.
28 |
29 | "Object" form shall mean any form resulting from mechanical transformation or
30 | translation of a Source form, including but not limited to compiled object code,
31 | generated documentation, and conversions to other media types.
32 |
33 | "Work" shall mean the work of authorship, whether in Source or Object form, made
34 | available under the License, as indicated by a copyright notice that is included
35 | in or attached to the work (an example is provided in the Appendix below).
36 |
37 | "Derivative Works" shall mean any work, whether in Source or Object form, that
38 | is based on (or derived from) the Work and for which the editorial revisions,
39 | annotations, elaborations, or other modifications represent, as a whole, an
40 | original work of authorship. For the purposes of this License, Derivative Works
41 | shall not include works that remain separable from, or merely link (or bind by
42 | name) to the interfaces of, the Work and Derivative Works thereof.
43 |
44 | "Contribution" shall mean any work of authorship, including the original version
45 | of the Work and any modifications or additions to that Work or Derivative Works
46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work
47 | by the copyright owner or by an individual or Legal Entity authorized to submit
48 | on behalf of the copyright owner. For the purposes of this definition,
49 | "submitted" means any form of electronic, verbal, or written communication sent
50 | to the Licensor or its representatives, including but not limited to
51 | communication on electronic mailing lists, source code control systems, and
52 | issue tracking systems that are managed by, or on behalf of, the Licensor for
53 | the purpose of discussing and improving the Work, but excluding communication
54 | that is conspicuously marked or otherwise designated in writing by the copyright
55 | owner as "Not a Contribution."
56 |
57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58 | of whom a Contribution has been received by Licensor and subsequently
59 | incorporated within the Work.
60 |
61 | 2. Grant of Copyright License.
62 |
63 | Subject to the terms and conditions of this License, each Contributor hereby
64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65 | irrevocable copyright license to reproduce, prepare Derivative Works of,
66 | publicly display, publicly perform, sublicense, and distribute the Work and such
67 | Derivative Works in Source or Object form.
68 |
69 | 3. Grant of Patent License.
70 |
71 | Subject to the terms and conditions of this License, each Contributor hereby
72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73 | irrevocable (except as stated in this section) patent license to make, have
74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75 | such license applies only to those patent claims licensable by such Contributor
76 | that are necessarily infringed by their Contribution(s) alone or by combination
77 | of their Contribution(s) with the Work to which such Contribution(s) was
78 | submitted. If You institute patent litigation against any entity (including a
79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80 | Contribution incorporated within the Work constitutes direct or contributory
81 | patent infringement, then any patent licenses granted to You under this License
82 | for that Work shall terminate as of the date such litigation is filed.
83 |
84 | 4. Redistribution.
85 |
86 | You may reproduce and distribute copies of the Work or Derivative Works thereof
87 | in any medium, with or without modifications, and in Source or Object form,
88 | provided that You meet the following conditions:
89 |
90 | You must give any other recipients of the Work or Derivative Works a copy of
91 | this License; and
92 | You must cause any modified files to carry prominent notices stating that You
93 | changed the files; and
94 | You must retain, in the Source form of any Derivative Works that You distribute,
95 | all copyright, patent, trademark, and attribution notices from the Source form
96 | of the Work, excluding those notices that do not pertain to any part of the
97 | Derivative Works; and
98 | If the Work includes a "NOTICE" text file as part of its distribution, then any
99 | Derivative Works that You distribute must include a readable copy of the
100 | attribution notices contained within such NOTICE file, excluding those notices
101 | that do not pertain to any part of the Derivative Works, in at least one of the
102 | following places: within a NOTICE text file distributed as part of the
103 | Derivative Works; within the Source form or documentation, if provided along
104 | with the Derivative Works; or, within a display generated by the Derivative
105 | Works, if and wherever such third-party notices normally appear. The contents of
106 | the NOTICE file are for informational purposes only and do not modify the
107 | License. You may add Your own attribution notices within Derivative Works that
108 | You distribute, alongside or as an addendum to the NOTICE text from the Work,
109 | provided that such additional attribution notices cannot be construed as
110 | modifying the License.
111 | You may add Your own copyright statement to Your modifications and may provide
112 | additional or different license terms and conditions for use, reproduction, or
113 | distribution of Your modifications, or for any such Derivative Works as a whole,
114 | provided Your use, reproduction, and distribution of the Work otherwise complies
115 | with the conditions stated in this License.
116 |
117 | 5. Submission of Contributions.
118 |
119 | Unless You explicitly state otherwise, any Contribution intentionally submitted
120 | for inclusion in the Work by You to the Licensor shall be under the terms and
121 | conditions of this License, without any additional terms or conditions.
122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of
123 | any separate license agreement you may have executed with Licensor regarding
124 | such Contributions.
125 |
126 | 6. Trademarks.
127 |
128 | This License does not grant permission to use the trade names, trademarks,
129 | service marks, or product names of the Licensor, except as required for
130 | reasonable and customary use in describing the origin of the Work and
131 | reproducing the content of the NOTICE file.
132 |
133 | 7. Disclaimer of Warranty.
134 |
135 | Unless required by applicable law or agreed to in writing, Licensor provides the
136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138 | including, without limitation, any warranties or conditions of TITLE,
139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140 | solely responsible for determining the appropriateness of using or
141 | redistributing the Work and assume any risks associated with Your exercise of
142 | permissions under this License.
143 |
144 | 8. Limitation of Liability.
145 |
146 | In no event and under no legal theory, whether in tort (including negligence),
147 | contract, or otherwise, unless required by applicable law (such as deliberate
148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be
149 | liable to You for damages, including any direct, indirect, special, incidental,
150 | or consequential damages of any character arising as a result of this License or
151 | out of the use or inability to use the Work (including but not limited to
152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153 | any and all other commercial damages or losses), even if such Contributor has
154 | been advised of the possibility of such damages.
155 |
156 | 9. Accepting Warranty or Additional Liability.
157 |
158 | While redistributing the Work or Derivative Works thereof, You may choose to
159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160 | other liability obligations and/or rights consistent with this License. However,
161 | in accepting such obligations, You may act only on Your own behalf and on Your
162 | sole responsibility, not on behalf of any other Contributor, and only if You
163 | agree to indemnify, defend, and hold each Contributor harmless for any liability
164 | incurred by, or claims asserted against, such Contributor by reason of your
165 | accepting any such warranty or additional liability.
166 |
167 | END OF TERMS AND CONDITIONS
168 |
169 | APPENDIX: How to apply the Apache License to your work
170 |
171 | To apply the Apache License to your work, attach the following boilerplate
172 | notice, with the fields enclosed by brackets "[]" replaced with your own
173 | identifying information. (Don't include the brackets!) The text should be
174 | enclosed in the appropriate comment syntax for the file format. We also
175 | recommend that a file or class name and description of purpose be included on
176 | the same "printed page" as the copyright notice for easier identification within
177 | third-party archives.
178 |
179 | Copyright [yyyy] [name of copyright owner]
180 |
181 | Licensed under the Apache License, Version 2.0 (the "License");
182 | you may not use this file except in compliance with the License.
183 | You may obtain a copy of the License at
184 |
185 | http://www.apache.org/licenses/LICENSE-2.0
186 |
187 | Unless required by applicable law or agreed to in writing, software
188 | distributed under the License is distributed on an "AS IS" BASIS,
189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190 | See the License for the specific language governing permissions and
191 | limitations under the License.
192 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | NO LONGER MAINTAINED
2 | ====================
3 |
4 | LoopingViewPager
5 | ================
6 |
7 | An android ViewPager extension allowing infinite scrolling.
8 |
9 |
10 | You can use it with "standart" `PagerAdapter` (inflating the pager with `Views`),
11 | but you can also use `FragmentPagerAdapter` which allows you to fill the pager with `Fragments`!
12 |
13 | The ViewPager will actually create 2 additional Views/Fragments to fake the infinite loop.
14 |
15 | This ViewPager is fully compatible with [ViewPagerIndicator][1], and [PagerSlidingTabStrip][2]!
16 |
17 |
18 |
19 | Usage
20 | -----
21 |
22 | To use it simply change `` to ``
23 |
24 | If your `PagerAdapter` is used only to create `Views` (i.e. you don't use `FragmentPagerAdapter` or `FragmentStatePagerAdapter`),
25 | then no more code changes are needed!
26 |
27 |
28 | If you want to use `LoopViewPager` with `FragmentPagerAdapter` or `FragmentStatePagerAdapter`
29 | additional changes in the adapter must be done.
30 | The adapter must be prepared to create 2 extra items e.g.:
31 | * The original adapter creates 4 items: `[0,1,2,3]`
32 | * The modified adapter will have to create 6 items `[0,1,2,3,4,5]`
33 | * with mapping `realPosition=(position-1)%count`
34 | * `[0->3, 1->0, 2->1, 3->2, 4->3, 5->0]`
35 |
36 |
37 | Sometimes "blinking" can be seen when paginating to first or last view (e.g. when you have a `NetworkImageView` in your layout).
38 | To remove this effect, simply call setBoundaryCaching( true ) on your `LoopViewPager`,
39 | or change `DEFAULT_BOUNDARY_CASHING` to true, if you want to set boundary caching
40 | on all `LoopViewPager` instances. This will prevent the first and last element from being destroyed,
41 | and every time they need to be displayed the existing instances will be used.
42 |
43 |
44 | Sample
45 | ------
46 | You can see a sample usage on [ViewPagerIndicator fork][3] (by [Jake Wharton][5])
47 | or on [PagerSlidingTabStrip fork][4] (by [Andreas Stütz][6])
48 |
49 | License
50 | =======
51 |
52 | Copyright 2013 Leszek Mzyk
53 |
54 | Licensed under the Apache License, Version 2.0 (the "License");
55 | you may not use this file except in compliance with the License.
56 | You may obtain a copy of the License at
57 |
58 | http://www.apache.org/licenses/LICENSE-2.0
59 |
60 | Unless required by applicable law or agreed to in writing, software
61 | distributed under the License is distributed on an "AS IS" BASIS,
62 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
63 | See the License for the specific language governing permissions and
64 | limitations under the License.
65 |
66 |
67 |
68 | [1]: https://github.com/JakeWharton/Android-ViewPagerIndicator
69 | [2]: https://github.com/astuetz/PagerSlidingTabStrip
70 | [3]: https://github.com/imbryk/Android-ViewPagerIndicator/compare/master...loopingViewPager-demo
71 | [4]: https://github.com/imbryk/PagerSlidingTabStrip/compare/master...loopingViewPager-demo
72 | [5]: https://github.com/JakeWharton
73 | [6]: https://github.com/astuetz
74 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:0.6.+'
7 | }
8 | }
9 |
10 | apply plugin: 'android-library'
11 |
12 | dependencies {
13 | compile files('libs/android-support-v4.jar')
14 | }
15 |
16 | android {
17 | compileSdkVersion 17
18 | buildToolsVersion '17.0.0'
19 |
20 | sourceSets {
21 | main {
22 | manifest.srcFile 'AndroidManifest.xml'
23 | java.srcDirs = ['src']
24 | }
25 |
26 | defaultConfig {
27 | minSdkVersion 4
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/imbryk/LoopingViewPager/67051d55e8b42107eb4a22335568f239fc1111ab/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.8-bin.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 | GRADLE_OPTS="$GRADLE_OPTS -Xmx512m -XX:MaxPermSize=256m"
12 |
13 | APP_NAME="Gradle"
14 | APP_BASE_NAME=`basename "$0"`
15 |
16 | # Use the maximum available, or set MAX_FD != -1 to use that value.
17 | MAX_FD="maximum"
18 |
19 | warn ( ) {
20 | echo "$*"
21 | }
22 |
23 | die ( ) {
24 | echo
25 | echo "$*"
26 | echo
27 | exit 1
28 | }
29 |
30 | # OS specific support (must be 'true' or 'false').
31 | cygwin=false
32 | msys=false
33 | darwin=false
34 | case "`uname`" in
35 | CYGWIN* )
36 | cygwin=true
37 | ;;
38 | Darwin* )
39 | darwin=true
40 | ;;
41 | MINGW* )
42 | msys=true
43 | ;;
44 | esac
45 |
46 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
47 | if $cygwin ; then
48 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
49 | fi
50 |
51 | # Attempt to set APP_HOME
52 | # Resolve links: $0 may be a link
53 | PRG="$0"
54 | # Need this for relative symlinks.
55 | while [ -h "$PRG" ] ; do
56 | ls=`ls -ld "$PRG"`
57 | link=`expr "$ls" : '.*-> \(.*\)$'`
58 | if expr "$link" : '/.*' > /dev/null; then
59 | PRG="$link"
60 | else
61 | PRG=`dirname "$PRG"`"/$link"
62 | fi
63 | done
64 | SAVED="`pwd`"
65 | cd "`dirname \"$PRG\"`/" >&-
66 | APP_HOME="`pwd -P`"
67 | cd "$SAVED" >&-
68 |
69 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
70 |
71 | # Determine the Java command to use to start the JVM.
72 | if [ -n "$JAVA_HOME" ] ; then
73 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
74 | # IBM's JDK on AIX uses strange locations for the executables
75 | JAVACMD="$JAVA_HOME/jre/sh/java"
76 | else
77 | JAVACMD="$JAVA_HOME/bin/java"
78 | fi
79 | if [ ! -x "$JAVACMD" ] ; then
80 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
81 |
82 | Please set the JAVA_HOME variable in your environment to match the
83 | location of your Java installation."
84 | fi
85 | else
86 | JAVACMD="java"
87 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
88 |
89 | Please set the JAVA_HOME variable in your environment to match the
90 | location of your Java installation."
91 | fi
92 |
93 | # Increase the maximum file descriptors if we can.
94 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
95 | MAX_FD_LIMIT=`ulimit -H -n`
96 | if [ $? -eq 0 ] ; then
97 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
98 | MAX_FD="$MAX_FD_LIMIT"
99 | fi
100 | ulimit -n $MAX_FD
101 | if [ $? -ne 0 ] ; then
102 | warn "Could not set maximum file descriptor limit: $MAX_FD"
103 | fi
104 | else
105 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
106 | fi
107 | fi
108 |
109 | # For Darwin, add options to specify how the application appears in the dock
110 | if $darwin; then
111 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
112 | fi
113 |
114 | # For Cygwin, switch paths to Windows format before running java
115 | if $cygwin ; then
116 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
117 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
118 |
119 | # We build the pattern for arguments to be converted via cygpath
120 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
121 | SEP=""
122 | for dir in $ROOTDIRSRAW ; do
123 | ROOTDIRS="$ROOTDIRS$SEP$dir"
124 | SEP="|"
125 | done
126 | OURCYGPATTERN="(^($ROOTDIRS))"
127 | # Add a user-defined pattern to the cygpath arguments
128 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
129 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
130 | fi
131 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
132 | i=0
133 | for arg in "$@" ; do
134 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
135 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
136 |
137 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
138 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
139 | else
140 | eval `echo args$i`="\"$arg\""
141 | fi
142 | i=$((i+1))
143 | done
144 | case $i in
145 | (0) set -- ;;
146 | (1) set -- "$args0" ;;
147 | (2) set -- "$args0" "$args1" ;;
148 | (3) set -- "$args0" "$args1" "$args2" ;;
149 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
150 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
151 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
152 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
153 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
154 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
155 | esac
156 | fi
157 |
158 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
159 | function splitJvmOpts() {
160 | JVM_OPTS=("$@")
161 | }
162 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
163 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
164 |
165 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
166 |
--------------------------------------------------------------------------------
/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/imbryk/LoopingViewPager/67051d55e8b42107eb4a22335568f239fc1111ab/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/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 | android.library=true
14 | # Project target.
15 | target=android-17
16 |
--------------------------------------------------------------------------------
/src/com/imbryk/viewPager/LoopPagerAdapterWrapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Leszek Mzyk
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.imbryk.viewPager;
18 |
19 | import android.os.Parcelable;
20 | import android.support.v4.app.FragmentPagerAdapter;
21 | import android.support.v4.app.FragmentStatePagerAdapter;
22 | import android.support.v4.view.PagerAdapter;
23 | import android.util.SparseArray;
24 | import android.view.View;
25 | import android.view.ViewGroup;
26 |
27 | /**
28 | * A PagerAdapter wrapper responsible for providing a proper page to
29 | * LoopViewPager
30 | *
31 | * This class shouldn't be used directly
32 | */
33 | public class LoopPagerAdapterWrapper extends PagerAdapter {
34 |
35 | private PagerAdapter mAdapter;
36 |
37 | private SparseArray mToDestroy = new SparseArray();
38 |
39 | private boolean mBoundaryCaching;
40 |
41 | void setBoundaryCaching(boolean flag) {
42 | mBoundaryCaching = flag;
43 | }
44 |
45 | LoopPagerAdapterWrapper(PagerAdapter adapter) {
46 | this.mAdapter = adapter;
47 | }
48 |
49 | @Override
50 | public void notifyDataSetChanged() {
51 | mToDestroy = new SparseArray();
52 | super.notifyDataSetChanged();
53 | }
54 |
55 | int toRealPosition(int position) {
56 | int realCount = getRealCount();
57 | if (realCount == 0)
58 | return 0;
59 | int realPosition = (position-1) % realCount;
60 | if (realPosition < 0)
61 | realPosition += realCount;
62 |
63 | return realPosition;
64 | }
65 |
66 | public int toInnerPosition(int realPosition) {
67 | int position = (realPosition + 1);
68 | return position;
69 | }
70 |
71 | private int getRealFirstPosition() {
72 | return 1;
73 | }
74 |
75 | private int getRealLastPosition() {
76 | return getRealFirstPosition() + getRealCount() - 1;
77 | }
78 |
79 | @Override
80 | public int getCount() {
81 | return mAdapter.getCount() + 2;
82 | }
83 |
84 | public int getRealCount() {
85 | return mAdapter.getCount();
86 | }
87 |
88 | public PagerAdapter getRealAdapter() {
89 | return mAdapter;
90 | }
91 |
92 | @Override
93 | public Object instantiateItem(ViewGroup container, int position) {
94 | int realPosition = (mAdapter instanceof FragmentPagerAdapter || mAdapter instanceof FragmentStatePagerAdapter)
95 | ? position
96 | : toRealPosition(position);
97 |
98 | if (mBoundaryCaching) {
99 | ToDestroy toDestroy = mToDestroy.get(position);
100 | if (toDestroy != null) {
101 | mToDestroy.remove(position);
102 | return toDestroy.object;
103 | }
104 | }
105 | return mAdapter.instantiateItem(container, realPosition);
106 | }
107 |
108 | @Override
109 | public void destroyItem(ViewGroup container, int position, Object object) {
110 | int realFirst = getRealFirstPosition();
111 | int realLast = getRealLastPosition();
112 | int realPosition = (mAdapter instanceof FragmentPagerAdapter || mAdapter instanceof FragmentStatePagerAdapter)
113 | ? position
114 | : toRealPosition(position);
115 |
116 | if (mBoundaryCaching && (position == realFirst || position == realLast)) {
117 | mToDestroy.put(position, new ToDestroy(container, realPosition,
118 | object));
119 | } else {
120 | mAdapter.destroyItem(container, realPosition, object);
121 | }
122 | }
123 |
124 | /*
125 | * Delegate rest of methods directly to the inner adapter.
126 | */
127 |
128 | @Override
129 | public void finishUpdate(ViewGroup container) {
130 | mAdapter.finishUpdate(container);
131 | }
132 |
133 | @Override
134 | public boolean isViewFromObject(View view, Object object) {
135 | return mAdapter.isViewFromObject(view, object);
136 | }
137 |
138 | @Override
139 | public void restoreState(Parcelable bundle, ClassLoader classLoader) {
140 | mAdapter.restoreState(bundle, classLoader);
141 | }
142 |
143 | @Override
144 | public Parcelable saveState() {
145 | return mAdapter.saveState();
146 | }
147 |
148 | @Override
149 | public void startUpdate(ViewGroup container) {
150 | mAdapter.startUpdate(container);
151 | }
152 |
153 | @Override
154 | public void setPrimaryItem(ViewGroup container, int position, Object object) {
155 | mAdapter.setPrimaryItem(container, position, object);
156 | }
157 |
158 | /*
159 | * End delegation
160 | */
161 |
162 | /**
163 | * Container class for caching the boundary views
164 | */
165 | static class ToDestroy {
166 | ViewGroup container;
167 | int position;
168 | Object object;
169 |
170 | public ToDestroy(ViewGroup container, int position, Object object) {
171 | this.container = container;
172 | this.position = position;
173 | this.object = object;
174 | }
175 | }
176 |
177 | }
--------------------------------------------------------------------------------
/src/com/imbryk/viewPager/LoopViewPager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2013 Leszek Mzyk
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.imbryk.viewPager;
18 |
19 | import android.content.Context;
20 | import android.support.v4.view.PagerAdapter;
21 | import android.support.v4.view.ViewPager;
22 | import android.util.AttributeSet;
23 |
24 | /**
25 | * A ViewPager subclass enabling infinte scrolling of the viewPager elements
26 | *
27 | * When used for paginating views (in opposite to fragments), no code changes
28 | * should be needed only change xml's from
29 | * to
30 | *
31 | * If "blinking" can be seen when paginating to first or last view, simply call
32 | * seBoundaryCaching( true ), or change DEFAULT_BOUNDARY_CASHING to true
33 | *
34 | * When using a FragmentPagerAdapter or FragmentStatePagerAdapter,
35 | * additional changes in the adapter must be done.
36 | * The adapter must be prepared to create 2 extra items e.g.:
37 | *
38 | * The original adapter creates 4 items: [0,1,2,3]
39 | * The modified adapter will have to create 6 items [0,1,2,3,4,5]
40 | * with mapping realPosition=(position-1)%count
41 | * [0->3, 1->0, 2->1, 3->2, 4->3, 5->0]
42 | */
43 | public class LoopViewPager extends ViewPager {
44 |
45 | private static final boolean DEFAULT_BOUNDARY_CASHING = false;
46 |
47 | OnPageChangeListener mOuterPageChangeListener;
48 | private LoopPagerAdapterWrapper mAdapter;
49 | private boolean mBoundaryCaching = DEFAULT_BOUNDARY_CASHING;
50 |
51 |
52 | /**
53 | * helper function which may be used when implementing FragmentPagerAdapter
54 | *
55 | * @param position
56 | * @param count
57 | * @return (position-1)%count
58 | */
59 | public static int toRealPosition( int position, int count ){
60 | position = position-1;
61 | if( position < 0 ){
62 | position += count;
63 | }else{
64 | position = position%count;
65 | }
66 | return position;
67 | }
68 |
69 | /**
70 | * If set to true, the boundary views (i.e. first and last) will never be destroyed
71 | * This may help to prevent "blinking" of some views
72 | *
73 | * @param flag
74 | */
75 | public void setBoundaryCaching(boolean flag) {
76 | mBoundaryCaching = flag;
77 | if (mAdapter != null) {
78 | mAdapter.setBoundaryCaching(flag);
79 | }
80 | }
81 |
82 | @Override
83 | public void setAdapter(PagerAdapter adapter) {
84 | mAdapter = new LoopPagerAdapterWrapper(adapter);
85 | mAdapter.setBoundaryCaching(mBoundaryCaching);
86 | super.setAdapter(mAdapter);
87 | setCurrentItem(0, false);
88 | }
89 |
90 | @Override
91 | public PagerAdapter getAdapter() {
92 | return mAdapter != null ? mAdapter.getRealAdapter() : mAdapter;
93 | }
94 |
95 | @Override
96 | public int getCurrentItem() {
97 | return mAdapter != null ? mAdapter.toRealPosition(super.getCurrentItem()) : 0;
98 | }
99 |
100 | public void setCurrentItem(int item, boolean smoothScroll) {
101 | int realItem = mAdapter.toInnerPosition(item);
102 | super.setCurrentItem(realItem, smoothScroll);
103 | }
104 |
105 | @Override
106 | public void setCurrentItem(int item) {
107 | if (getCurrentItem() != item) {
108 | setCurrentItem(item, true);
109 | }
110 | }
111 |
112 | @Override
113 | public void setOnPageChangeListener(OnPageChangeListener listener) {
114 | mOuterPageChangeListener = listener;
115 | };
116 |
117 | public LoopViewPager(Context context) {
118 | super(context);
119 | init();
120 | }
121 |
122 | public LoopViewPager(Context context, AttributeSet attrs) {
123 | super(context, attrs);
124 | init();
125 | }
126 |
127 | private void init() {
128 | super.setOnPageChangeListener(onPageChangeListener);
129 | }
130 |
131 | private OnPageChangeListener onPageChangeListener = new OnPageChangeListener() {
132 | private float mPreviousOffset = -1;
133 | private float mPreviousPosition = -1;
134 |
135 | @Override
136 | public void onPageSelected(int position) {
137 |
138 | int realPosition = mAdapter.toRealPosition(position);
139 | if (mPreviousPosition != realPosition) {
140 | mPreviousPosition = realPosition;
141 | if (mOuterPageChangeListener != null) {
142 | mOuterPageChangeListener.onPageSelected(realPosition);
143 | }
144 | }
145 | }
146 |
147 | @Override
148 | public void onPageScrolled(int position, float positionOffset,
149 | int positionOffsetPixels) {
150 | int realPosition = position;
151 | if (mAdapter != null) {
152 | realPosition = mAdapter.toRealPosition(position);
153 |
154 | if (positionOffset == 0
155 | && mPreviousOffset == 0
156 | && (position == 0 || position == mAdapter.getCount() - 1)) {
157 | setCurrentItem(realPosition, false);
158 | }
159 | }
160 |
161 | mPreviousOffset = positionOffset;
162 | if (mOuterPageChangeListener != null) {
163 | if (realPosition != mAdapter.getRealCount() - 1) {
164 | mOuterPageChangeListener.onPageScrolled(realPosition,
165 | positionOffset, positionOffsetPixels);
166 | } else {
167 | if (positionOffset > .5) {
168 | mOuterPageChangeListener.onPageScrolled(0, 0, 0);
169 | } else {
170 | mOuterPageChangeListener.onPageScrolled(realPosition,
171 | 0, 0);
172 | }
173 | }
174 | }
175 | }
176 |
177 | @Override
178 | public void onPageScrollStateChanged(int state) {
179 | if (mAdapter != null) {
180 | int position = LoopViewPager.super.getCurrentItem();
181 | int realPosition = mAdapter.toRealPosition(position);
182 | if (state == ViewPager.SCROLL_STATE_IDLE
183 | && (position == 0 || position == mAdapter.getCount() - 1)) {
184 | setCurrentItem(realPosition, false);
185 | }
186 | }
187 | if (mOuterPageChangeListener != null) {
188 | mOuterPageChangeListener.onPageScrollStateChanged(state);
189 | }
190 | }
191 | };
192 |
193 | }
194 |
--------------------------------------------------------------------------------