├── .gradle
├── 2.10
│ └── taskArtifacts
│ │ ├── cache.properties
│ │ ├── cache.properties.lock
│ │ ├── fileHashes.bin
│ │ ├── fileSnapshots.bin
│ │ ├── outputFileStates.bin
│ │ └── taskArtifacts.bin
└── 2.8
│ └── taskArtifacts
│ ├── cache.properties
│ ├── cache.properties.lock
│ ├── fileHashes.bin
│ ├── fileSnapshots.bin
│ ├── outputFileStates.bin
│ └── taskArtifacts.bin
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── libraries
│ ├── appcompat_v7_23_1_1.xml
│ ├── cardview_v7_23_1_1.xml
│ ├── design_23_1_1.xml
│ ├── hamcrest_core_1_3.xml
│ ├── junit_4_12.xml
│ ├── picasso_2_5_2.xml
│ ├── recyclerview_v7_23_2_0.xml
│ ├── support_annotations_23_2_0.xml
│ ├── support_v4_23_2_0.xml
│ └── universal_image_loader_1_9_3.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── workspace.xml
├── LICENSE.txt
├── PowerfulRecyclerView.iml
├── README.md
├── bintray.gradle
├── build.gradle
├── build
├── generated
│ └── mockable-android-23.jar
└── intermediates
│ └── dex-cache
│ └── cache.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── local.properties
├── powerfulrecyclerviewlib
├── .gitignore
├── build.gradle
├── powerfulrecyclerviewlib.iml
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── kangzhe
│ │ └── powerfulrecyclerviewlib
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── zjutkz
│ │ │ └── powerfulrecyclerview
│ │ │ ├── adapter
│ │ │ └── PowerfulRecyclerAdapter.java
│ │ │ ├── animator
│ │ │ ├── base
│ │ │ │ └── BaseItemAnimator.java
│ │ │ └── impl
│ │ │ │ ├── FadeInAnimator.java
│ │ │ │ ├── SlideInAnimator.java
│ │ │ │ └── ZoomInAnimator.java
│ │ │ ├── listener
│ │ │ ├── IFooterView.java
│ │ │ ├── IHeaderView.java
│ │ │ ├── ItemTouchAdapter.java
│ │ │ ├── OnLoadMoreListener.java
│ │ │ ├── OnRefreshListener.java
│ │ │ └── OnViewClick.java
│ │ │ ├── ptr
│ │ │ ├── PowerfulRecyclerView.java
│ │ │ └── PowerfulSimpleRecyclerView.java
│ │ │ ├── simple
│ │ │ ├── SimpleFooterView.java
│ │ │ ├── SimpleHeaderContainer.java
│ │ │ ├── SimpleImageView.java
│ │ │ └── SimpleTextView.java
│ │ │ ├── touchHelper
│ │ │ ├── ItemTouchHelperCallback.java
│ │ │ ├── ItemTouchHelperFactory.java
│ │ │ ├── ItemTouchListenerAdapter.java
│ │ │ └── SimpleItemTouchHelperCallback.java
│ │ │ └── utils
│ │ │ ├── AnimateViewUtils.java
│ │ │ ├── FooterUtils.java
│ │ │ └── RecyclerViewUtils.java
│ └── res
│ │ ├── drawable-hdpi
│ │ └── ptr_down_arrow.png
│ │ ├── drawable-xhdpi
│ │ └── ptr_loading.png
│ │ ├── drawable
│ │ └── ptr_img_progress.xml
│ │ ├── layout
│ │ ├── def_no_data_view_layout.xml
│ │ ├── default_footer.xml
│ │ ├── recycler_view.xml
│ │ └── simple_header.xml
│ │ └── values
│ │ ├── attrs.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── example
│ └── kangzhe
│ └── powerfulrecyclerviewlib
│ └── ExampleUnitTest.java
├── sample
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── sample.iml
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── kangzhe
│ │ └── sample
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── kangzhe
│ │ │ └── sample
│ │ │ ├── MyApp.java
│ │ │ ├── activity
│ │ │ ├── HorizontalActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── RecyclerGridViewActivity.java
│ │ │ ├── RecyclerListViewActivity.java
│ │ │ ├── RecyclerStaggeredViewActivity.java
│ │ │ └── SimplePtrActivity.java
│ │ │ ├── divider
│ │ │ ├── DividerGridItemDecoration.java
│ │ │ └── DividerItemDecoration.java
│ │ │ ├── fragment
│ │ │ ├── MyFragment1.java
│ │ │ ├── MyFragment2.java
│ │ │ └── MyFragment3.java
│ │ │ └── view
│ │ │ ├── FooterContainer.java
│ │ │ ├── FooterTextView.java
│ │ │ ├── HeaderContainer.java
│ │ │ ├── HeaderImageView.java
│ │ │ ├── HeaderScaleImageView.java
│ │ │ ├── HeaderTextView.java
│ │ │ ├── HistoryThemeFooterView.java
│ │ │ └── HistoryThemeHeaderView.java
│ └── res
│ │ ├── drawable-xhdpi
│ │ ├── bj_ic_loading.png
│ │ └── bj_theme_top_shadow.9.png
│ │ ├── drawable
│ │ ├── bj_frame_red_white.xml
│ │ ├── bj_img_progress.xml
│ │ ├── down.png
│ │ ├── ic_toc_white_24dp.png
│ │ ├── img1.jpg
│ │ ├── img2.jpg
│ │ ├── img3.jpg
│ │ ├── img4.jpg
│ │ ├── img5.jpg
│ │ ├── img6.jpg
│ │ ├── img7.jpg
│ │ ├── img8.jpg
│ │ ├── img9.jpg
│ │ ├── load.jpeg
│ │ └── up.png
│ │ ├── layout
│ │ ├── activity_horizontal.xml
│ │ ├── activity_main.xml
│ │ ├── big_photo_item_layout.xml
│ │ ├── content_main.xml
│ │ ├── footer.xml
│ │ ├── fragment_layout.xml
│ │ ├── header.xml
│ │ ├── history_footer_theme.xml
│ │ ├── history_header_theme.xml
│ │ ├── list_header_viewpager.xml
│ │ ├── new_grid_layout.xml
│ │ ├── new_list_item.xml
│ │ ├── no_network_layout.xml
│ │ ├── recycler_activity.xml
│ │ ├── recycler_footer.xml
│ │ ├── recycler_item.xml
│ │ ├── server_error_layout.xml
│ │ ├── simple_ptr_activity.xml
│ │ ├── staggered_item.xml
│ │ └── swip_refresh_recycler_activity.xml
│ │ ├── menu
│ │ └── menu_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── example
│ └── kangzhe
│ └── sample
│ └── ExampleUnitTest.java
└── settings.gradle
/.gradle/2.10/taskArtifacts/cache.properties:
--------------------------------------------------------------------------------
1 | #Wed Aug 31 11:42:41 CST 2016
2 |
--------------------------------------------------------------------------------
/.gradle/2.10/taskArtifacts/cache.properties.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/.gradle/2.10/taskArtifacts/cache.properties.lock
--------------------------------------------------------------------------------
/.gradle/2.10/taskArtifacts/fileHashes.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/.gradle/2.10/taskArtifacts/fileHashes.bin
--------------------------------------------------------------------------------
/.gradle/2.10/taskArtifacts/fileSnapshots.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/.gradle/2.10/taskArtifacts/fileSnapshots.bin
--------------------------------------------------------------------------------
/.gradle/2.10/taskArtifacts/outputFileStates.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/.gradle/2.10/taskArtifacts/outputFileStates.bin
--------------------------------------------------------------------------------
/.gradle/2.10/taskArtifacts/taskArtifacts.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/.gradle/2.10/taskArtifacts/taskArtifacts.bin
--------------------------------------------------------------------------------
/.gradle/2.8/taskArtifacts/cache.properties:
--------------------------------------------------------------------------------
1 | #Thu Mar 24 21:39:28 CST 2016
2 |
--------------------------------------------------------------------------------
/.gradle/2.8/taskArtifacts/cache.properties.lock:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/.gradle/2.8/taskArtifacts/cache.properties.lock
--------------------------------------------------------------------------------
/.gradle/2.8/taskArtifacts/fileHashes.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/.gradle/2.8/taskArtifacts/fileHashes.bin
--------------------------------------------------------------------------------
/.gradle/2.8/taskArtifacts/fileSnapshots.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/.gradle/2.8/taskArtifacts/fileSnapshots.bin
--------------------------------------------------------------------------------
/.gradle/2.8/taskArtifacts/outputFileStates.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/.gradle/2.8/taskArtifacts/outputFileStates.bin
--------------------------------------------------------------------------------
/.gradle/2.8/taskArtifacts/taskArtifacts.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/.gradle/2.8/taskArtifacts/taskArtifacts.bin
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/libraries/appcompat_v7_23_1_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/libraries/cardview_v7_23_1_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/libraries/design_23_1_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/libraries/hamcrest_core_1_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/junit_4_12.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/picasso_2_5_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/recyclerview_v7_23_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/libraries/support_annotations_23_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/libraries/support_v4_23_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/libraries/universal_image_loader_1_9_3.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/PowerfulRecyclerView.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PowerfulRecyclerView
2 |
3 | ####A powerful RecyclerView which support:
4 |
5 | (1) Pull to refresh(can be customization)
6 | (2) Load more(can be customization)
7 | (3) Swipe to remove items & drag to change items
8 | (4) Animation
9 | (5) Custom header(like banner) & custom footer
10 | (6) Nested scrolling(Means you can use it with coordinatorLayout,AppbarLayout or any component in v7)
11 | (7) Using swipeRefreshLayout
12 |
13 |
14 |
15 | ###Download
16 |
17 | ```groovy
18 | compile 'com.zjutkz:PowerfulRecyclerView:1.0.0'
19 | ```
20 |
21 |
22 |
23 | ###Usage
24 |
25 | you can see the usage [on my blog](http://zjutkz.net/2016/03/29/重复造轮子也是有意义的!PowerfulRecyclerView使用指导和源码分析/).
26 |
27 |
28 |
29 | ###Notice
30 |
31 | ~~There are some bugs with 'com.android.support:recyclerview-v7:23.2.0' and higher,especially when you adding or removing items.So please use lower version of recycierview,I will try my best to fix bugs.~~
32 |
33 |
34 |
35 | #License
36 |
37 | ```
38 | Copyright 2015 zjutkz
39 |
40 | Licensed under the Apache License, Version 2.0 (the "License");
41 | you may not use this file except in compliance with the License.
42 | You may obtain a copy of the License at
43 |
44 | http://www.apache.org/licenses/LICENSE-2.0
45 |
46 | Unless required by applicable law or agreed to in writing, software
47 | distributed under the License is distributed on an "AS IS" BASIS,
48 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49 | See the License for the specific language governing permissions and
50 | limitations under the License.
51 | ```
52 |
53 |
--------------------------------------------------------------------------------
/bintray.gradle:
--------------------------------------------------------------------------------
1 | group = "com.zjutkz"
2 | version = "1.0.1"
3 | project.archivesBaseName = "PowerfulRecyclerView"
4 |
5 | apply plugin: 'com.jfrog.bintray'
6 | apply plugin: 'maven-publish'
7 |
8 | task sourcesJar(type: Jar) {
9 | from android.sourceSets.main.java.srcDirs
10 | classifier = 'sources'
11 | }
12 |
13 | task javadoc(type: Javadoc) {
14 | source = android.sourceSets.main.java.srcDirs
15 | classpath += configurations.compile
16 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
17 | }
18 |
19 | task javadocJar(type: Jar, dependsOn: javadoc) {
20 | classifier = 'javadoc'
21 | from javadoc.destinationDir
22 | }
23 |
24 | javadoc {
25 | options{
26 | encoding "UTF-8"
27 | charSet 'UTF-8'
28 | author true
29 | version true
30 | links "http://docs.oracle.com/javase/7/docs/api"
31 | title "PowerfulRecyclerView"
32 | }
33 | }
34 |
35 | artifacts {
36 | archives javadocJar
37 | archives sourcesJar
38 | }
39 |
40 | def pomConfig = {
41 | licenses {
42 | license {
43 | name "The Apache Software License, Version 2.0"
44 | url "http://www.apache.org/licenses/LICENSE-2.0.txt"
45 | distribution "repo"
46 | }
47 | }
48 | developers {
49 | developer {
50 | id "zjutkz"
51 | name "zjutkz"
52 | email "568255592@qq.com"
53 | }
54 | }
55 | //这里有引号,并且有个空格,否则生成不了依赖,主要是这里的dependencies并不是build.gradle里的dependencies,而gradle会把他当成自身的dependencies处理
56 | "dependencies " {
57 | dependency{
58 | groupId "com.android.support"
59 | artifactId "recyclerview-v7"
60 | "version " "23.2.0"
61 | //同dependencies
62 | }
63 | }
64 |
65 | }
66 |
67 | publishing {
68 | publications {
69 | mavenJava(MavenPublication) {
70 | artifactId "PowerfulRecyclerView"
71 |
72 | pom{
73 | packaging 'aar'
74 | }
75 | pom.withXml {
76 | def root = asNode()
77 | root.appendNode('description', "A powerful and useful RecyclerView")
78 | root.children().last() + pomConfig
79 | }
80 | }
81 | }
82 | }
83 |
84 | bintray {
85 | Properties properties = new Properties()
86 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
87 |
88 | user = properties.getProperty('BINTRAY_USER');
89 | key = properties.getProperty('BINTRAY_KEY');
90 |
91 |
92 |
93 | configurations = ['archives']
94 | publications = ['mavenJava']
95 | publish = true
96 |
97 | pkg {
98 | repo = 'maven'
99 | name = "PowerfulRecyclerView"
100 | desc = "A powerful and useful RecyclerView"
101 | websiteUrl = "https://github.com/zjutkz/PowerfulRecyclerView"
102 | issueTrackerUrl = "https://github.com/zjutkz/PowerfulRecyclerView/issues"
103 | vcsUrl = "https://github.com/zjutkz"
104 | licenses = ['Apache-2.0']
105 | publicDownloadNumbers = true
106 | }
107 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.5.0'
9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
10 | classpath 'com.github.dcendents:android-maven-plugin:1.2'
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/build/generated/mockable-android-23.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/build/generated/mockable-android-23.jar
--------------------------------------------------------------------------------
/build/intermediates/dex-cache/cache.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.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 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | ## This file is automatically generated by Android Studio.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 | #
7 | # Location of the SDK. This is only used by Gradle.
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | #Thu Mar 24 18:37:39 CST 2016
11 | sdk.dir=/Users/kangzhe/Library/Android/sdk
12 | BINTRAY_KEY=7e13a32514519b9a7410dd6fd00da81c900c0ec3
13 | BINTRAY_USER=zjutkz
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion '23.0.2'
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | testCompile 'junit:junit:4.12'
24 | compile 'com.android.support:recyclerview-v7:23.2.0'
25 | }
26 |
27 | apply from: '../bintray.gradle'
28 |
29 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/powerfulrecyclerviewlib.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | generateDebugSources
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/kangzhe/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/androidTest/java/com/example/kangzhe/powerfulrecyclerviewlib/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.powerfulrecyclerviewlib;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/adapter/PowerfulRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.adapter;
2 |
3 | import android.support.v7.widget.GridLayoutManager;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.support.v7.widget.StaggeredGridLayoutManager;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | import com.zjutkz.powerfulrecyclerview.listener.ItemTouchAdapter;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by kangZhe on 16/1/1.
16 | */
17 | public class PowerfulRecyclerAdapter extends RecyclerView.Adapter implements ItemTouchAdapter {
18 |
19 | private static final String TAG = "PowerfulRecyclerAdapter";
20 |
21 | private static final int TYPE_HEADER = -2;
22 | private static final int TYPE_FOOT = -1;
23 |
24 |
25 | private List mHeaderViews;
26 | private View mFootView;
27 | private RecyclerView.Adapter mPlugAdapter;
28 | private int spanCount;
29 | private int headerPosition = 0;
30 |
31 | public PowerfulRecyclerAdapter(final RecyclerView.Adapter mPlugAdapter){
32 | this.mPlugAdapter = mPlugAdapter;
33 |
34 | mHeaderViews = new ArrayList();
35 |
36 | mPlugAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
37 | @Override
38 | public void onChanged() {
39 | PowerfulRecyclerAdapter.this.notifyDataSetChanged();
40 | }
41 |
42 | @Override
43 | public void onItemRangeChanged(int positionStart, int itemCount) {
44 | PowerfulRecyclerAdapter.this.notifyItemRangeChanged(positionStart + getHeaderViewCount(), itemCount);
45 | }
46 |
47 | @Override
48 | public void onItemRangeInserted(int positionStart, int itemCount) {
49 | int truePositionStart = positionStart + getHeaderViewCount();
50 |
51 | PowerfulRecyclerAdapter.this.notifyItemRangeInserted(truePositionStart, itemCount);
52 | }
53 |
54 | @Override
55 | public void onItemRangeRemoved(int positionStart, int itemCount) {
56 | int truePositionStart = positionStart + getHeaderViewCount();
57 |
58 | PowerfulRecyclerAdapter.this.notifyItemRangeRemoved(truePositionStart, itemCount);
59 | }
60 |
61 | @Override
62 | public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
63 | int truePositionStart = fromPosition + getHeaderViewCount();
64 | int truePositionEnd = toPosition + getHeaderViewCount();
65 |
66 | PowerfulRecyclerAdapter.this.notifyItemMoved(truePositionStart, truePositionEnd);
67 | }
68 | });
69 | }
70 |
71 | @Override
72 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
73 | if(viewType == TYPE_HEADER){
74 | if(headerPosition >= mHeaderViews.size()){
75 | headerPosition = 0;
76 | }
77 | return new ViewHolder(mHeaderViews.get(headerPosition++));
78 | }else if(viewType == TYPE_FOOT){
79 | return new ViewHolder(mFootView);
80 | }else{
81 | return mPlugAdapter.onCreateViewHolder(parent,viewType);
82 | }
83 | }
84 |
85 | @Override
86 | public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
87 | if(hasFootView() && hasHeaderView()){
88 | if(position < getHeaderViewCount() || position == getItemCount() - 1){
89 | //do nothing
90 | }else{
91 |
92 | mPlugAdapter.onBindViewHolder(holder, position - getHeaderViewCount());
93 | }
94 | }else if(hasFootView() && !hasHeaderView()){
95 | if(position == getItemCount() - 1){
96 | //do nothing
97 | }else{
98 |
99 | mPlugAdapter.onBindViewHolder(holder,position);
100 | }
101 | }else if(!hasFootView() && hasHeaderView()){
102 | if(position < getHeaderViewCount()){
103 | //do nothing
104 | }else{
105 |
106 | mPlugAdapter.onBindViewHolder(holder,position - getHeaderViewCount());
107 | }
108 | }else{
109 |
110 | mPlugAdapter.onBindViewHolder(holder, position);
111 | }
112 | }
113 |
114 | @Override
115 | public int getItemCount() {
116 | return mPlugAdapter.getItemCount() + getHeaderViewCount() + getFootViewCount();
117 | }
118 |
119 | @Override
120 | public int getItemViewType(int position) {
121 | int realCount = mPlugAdapter.getItemCount();
122 |
123 | if(position < getHeaderViewCount()){
124 | return TYPE_HEADER;
125 | }else if(position >= getHeaderViewCount() && position < realCount + getHeaderViewCount()){
126 | return mPlugAdapter.getItemViewType(position - getHeaderViewCount());
127 | }else{
128 | return TYPE_FOOT;
129 | }
130 | }
131 |
132 | @Override
133 | public void onAttachedToRecyclerView(RecyclerView recyclerView) {
134 | super.onAttachedToRecyclerView(recyclerView);
135 | RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
136 | if(manager instanceof GridLayoutManager) {
137 | final GridLayoutManager gridManager = ((GridLayoutManager) manager);
138 | gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
139 | @Override
140 | public int getSpanSize(int position) {
141 | return (getItemViewType(position) == TYPE_FOOT) || (getItemViewType(position) == TYPE_HEADER) ? spanCount : 1;
142 | }
143 | });
144 | }
145 | }
146 |
147 | @Override
148 | public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
149 | super.onViewAttachedToWindow(holder);
150 | ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
151 | if (lp != null
152 | && lp instanceof StaggeredGridLayoutManager.LayoutParams
153 | && ((holder.getLayoutPosition() == this.getItemCount() - 1 && hasFootView())
154 | || (holder.getLayoutPosition() < getHeaderViewCount()) && hasHeaderView())) {
155 | StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
156 | p.setFullSpan(true);
157 | }
158 | }
159 |
160 | /**
161 | * 设置footrer
162 | * @param mFootView
163 | * @param spanCount
164 | */
165 | public void setFootView(View mFootView,int spanCount){
166 | if(mFootView == null){
167 | return;
168 | }
169 | this.mFootView = mFootView;
170 | this.spanCount = spanCount;
171 | this.notifyDataSetChanged();
172 | }
173 |
174 | /**
175 | * 设置header
176 | * @param mHeaderView
177 | * @param spanCount
178 | */
179 | public void setHeaderView(View mHeaderView,int spanCount){
180 | if(mHeaderView == null){
181 | return;
182 | }
183 |
184 | mHeaderViews.add(mHeaderView);
185 |
186 | this.spanCount = spanCount;
187 | this.notifyDataSetChanged();
188 | }
189 |
190 | /**
191 | * 去除footer
192 | * @param mFootView
193 | */
194 | public void removeFootView(View mFootView){
195 | if(mFootView == null){
196 | return;
197 | }
198 | this.mFootView = null;
199 | this.notifyDataSetChanged();
200 | }
201 |
202 | /**
203 | * 是否含有header
204 | */
205 | public boolean hasHeaderView(){
206 | return mHeaderViews != null && mHeaderViews.size() > 0;
207 | }
208 |
209 | /**
210 | * header个数
211 | */
212 | public int getHeaderViewCount(){
213 | return mHeaderViews.size();
214 | }
215 |
216 | /**
217 | * 是否含有footer
218 | */
219 | public boolean hasFootView(){
220 | return mFootView != null;
221 | }
222 |
223 | /**
224 | * footer个数
225 | */
226 | public int getFootViewCount(){
227 | return mFootView == null ? 0 : 1;
228 | }
229 |
230 | @Override
231 | public void onMove(int fromPosition, int toPosition) {
232 | if(mPlugAdapter instanceof ItemTouchAdapter){
233 | int realFromPos = fromPosition - getHeaderViewCount();
234 | int realToPos = toPosition - getHeaderViewCount();
235 |
236 | ((ItemTouchAdapter) mPlugAdapter).onMove(realFromPos, realToPos);
237 | }
238 | }
239 |
240 | @Override
241 | public void onDismiss(int position) {
242 | if(mPlugAdapter instanceof ItemTouchAdapter){
243 | int realPos = position - getHeaderViewCount();
244 |
245 | ((ItemTouchAdapter) mPlugAdapter).onDismiss(realPos);
246 | }
247 | }
248 |
249 | public RecyclerView.Adapter getPlugAdapter(){
250 | return mPlugAdapter;
251 | }
252 |
253 | public static class ViewHolder extends RecyclerView.ViewHolder {
254 | public ViewHolder(View itemView) {
255 | super(itemView);
256 | }
257 | }
258 | }
259 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/animator/impl/FadeInAnimator.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.animator.impl;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ObjectAnimator;
5 | import android.support.v4.view.ViewCompat;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.View;
8 |
9 | import com.zjutkz.powerfulrecyclerview.animator.base.BaseItemAnimator;
10 |
11 |
12 | /**
13 | * Created by kangzhe on 16/1/29.
14 | */
15 | public class FadeInAnimator extends BaseItemAnimator {
16 |
17 | @Override
18 | protected void onPreAnimateAdd(RecyclerView.ViewHolder holder) {
19 | ViewCompat.setAlpha(holder.itemView, 0);
20 | }
21 |
22 | @Override
23 | protected void onPreAnimateRemove(RecyclerView.ViewHolder holder) {
24 | }
25 |
26 | @Override
27 | protected AnimatorSet generateRemoveAnimator(RecyclerView.ViewHolder holder) {
28 | View target = holder.itemView;
29 |
30 | AnimatorSet animator = new AnimatorSet();
31 |
32 | animator.playTogether(
33 | ObjectAnimator.ofFloat(target, "alpha", 1.0f, 0.0f)
34 | );
35 |
36 | animator.setTarget(target);
37 | animator.setDuration(getRemoveDuration());
38 |
39 | return animator;
40 | }
41 |
42 | @Override
43 | protected AnimatorSet generateAddAnimator(RecyclerView.ViewHolder holder) {
44 | View target = holder.itemView;
45 |
46 | AnimatorSet animator = new AnimatorSet();
47 |
48 | animator.playTogether(
49 | ObjectAnimator.ofFloat(target, "alpha", 0.0f, 1.0f)
50 | );
51 |
52 | animator.setTarget(target);
53 | animator.setDuration(getAddDuration());
54 |
55 | return animator;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/animator/impl/SlideInAnimator.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.animator.impl;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ObjectAnimator;
5 | import android.support.v4.view.ViewCompat;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.View;
8 |
9 | import com.zjutkz.powerfulrecyclerview.animator.base.BaseItemAnimator;
10 |
11 |
12 | /**
13 | * Created by kangzhe on 16/1/29.
14 | */
15 | public class SlideInAnimator extends BaseItemAnimator {
16 | @Override
17 | protected void onPreAnimateAdd(RecyclerView.ViewHolder holder) {
18 | ViewCompat.setTranslationX(holder.itemView, -holder.itemView.getMeasuredWidth());
19 | }
20 |
21 | @Override
22 | protected void onPreAnimateRemove(RecyclerView.ViewHolder holder) {
23 |
24 | }
25 |
26 | @Override
27 | protected AnimatorSet generateRemoveAnimator(RecyclerView.ViewHolder holder) {
28 | View target = holder.itemView;
29 |
30 | AnimatorSet animator = new AnimatorSet();
31 |
32 | animator.playTogether(
33 | ObjectAnimator.ofFloat(target, "translationX", 0, -holder.itemView.getMeasuredWidth())
34 | );
35 |
36 | animator.setTarget(target);
37 | animator.setDuration(getRemoveDuration());
38 |
39 | return animator;
40 | }
41 |
42 | @Override
43 | protected AnimatorSet generateAddAnimator(RecyclerView.ViewHolder holder) {
44 | View target = holder.itemView;
45 |
46 | AnimatorSet animator = new AnimatorSet();
47 |
48 | animator.playTogether(
49 | ObjectAnimator.ofFloat(target, "translationX", -holder.itemView.getMeasuredWidth(),0)
50 | );
51 |
52 | animator.setTarget(target);
53 | animator.setDuration(getAddDuration());
54 |
55 | return animator;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/animator/impl/ZoomInAnimator.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.animator.impl;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ObjectAnimator;
5 | import android.support.v4.view.ViewCompat;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.View;
8 |
9 | import com.zjutkz.powerfulrecyclerview.animator.base.BaseItemAnimator;
10 |
11 |
12 | /**
13 | * Created by kangzhe on 16/1/29.
14 | */
15 | public class ZoomInAnimator extends BaseItemAnimator {
16 | private static final String TAG = "ZoomInAnimator";
17 |
18 | @Override
19 | protected void onPreAnimateAdd(RecyclerView.ViewHolder holder) {
20 | ViewCompat.setScaleX(holder.itemView, 0);
21 | ViewCompat.setScaleY(holder.itemView, 0);
22 | //setAddDuration(1000);
23 | }
24 |
25 | @Override
26 | protected void onPreAnimateRemove(RecyclerView.ViewHolder holder) {
27 | //setRemoveDuration(1000);
28 | }
29 |
30 | @Override
31 | protected AnimatorSet generateRemoveAnimator(RecyclerView.ViewHolder holder) {
32 | View target = holder.itemView;
33 |
34 | AnimatorSet animator = new AnimatorSet();
35 |
36 | animator.playTogether(
37 | ObjectAnimator.ofFloat(target, "scaleX", 1.0f, 0.0f),
38 | ObjectAnimator.ofFloat(target, "scaleY", 1.0f, 0.0f)
39 | );
40 |
41 | animator.setTarget(target);
42 | animator.setDuration(getRemoveDuration());
43 |
44 | return animator;
45 | }
46 |
47 | @Override
48 | protected AnimatorSet generateAddAnimator(RecyclerView.ViewHolder holder) {
49 | View target = holder.itemView;
50 |
51 | AnimatorSet animator = new AnimatorSet();
52 |
53 | animator.playTogether(
54 | ObjectAnimator.ofFloat(target, "scaleX", 0.0f, 1.0f),
55 | ObjectAnimator.ofFloat(target, "scaleY", 0.0f, 1.0f)
56 | );
57 |
58 | animator.setTarget(target);
59 | animator.setDuration(getAddDuration());
60 |
61 | return animator;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/listener/IFooterView.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.listener;
2 |
3 | /**
4 | * Created by kangzhe on 16/1/10.
5 | */
6 | public interface IFooterView {
7 |
8 | void onShow();
9 |
10 | void onLoadMore();
11 | }
12 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/listener/IHeaderView.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.listener;
2 |
3 | /**
4 | * Created by kangzhe on 16/1/2.
5 | */
6 | public interface IHeaderView {
7 |
8 | void pullToRefresh();
9 |
10 | void releaseToRefresh();
11 |
12 | void onRefresh();
13 |
14 | void onReset(float distance, float fraction);
15 |
16 | void onPull(float distance, float fraction);
17 | }
18 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/listener/ItemTouchAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.listener;
2 |
3 | /**
4 | * Created by kangzhe on 16/1/27.
5 | */
6 | public interface ItemTouchAdapter {
7 |
8 | void onMove(int fromPosition, int toPosition);
9 |
10 | void onDismiss(int position);
11 | }
12 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/listener/OnLoadMoreListener.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.listener;
2 |
3 | /**
4 | * Created by kangzhe on 16/1/5.
5 | */
6 | public interface OnLoadMoreListener {
7 |
8 | void onLoadMore();
9 | }
10 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/listener/OnRefreshListener.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.listener;
2 |
3 | /**
4 | * Created by kangzhe on 16/1/5.
5 | */
6 | public interface OnRefreshListener {
7 |
8 | void onRefresh();
9 | }
10 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/listener/OnViewClick.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.listener;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 |
5 | /**
6 | * Created by kangzhe on 16/1/20.
7 | */
8 | public interface OnViewClick {
9 |
10 | void onClick(RecyclerView.ViewHolder holder, int position);
11 |
12 | boolean onLongClick(RecyclerView.ViewHolder holder, int position);
13 | }
14 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/ptr/PowerfulSimpleRecyclerView.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.ptr;
2 |
3 | import android.content.Context;
4 | import android.support.v4.widget.SwipeRefreshLayout;
5 | import android.util.AttributeSet;
6 | import android.view.LayoutInflater;
7 | import android.view.MotionEvent;
8 |
9 | import com.example.kangzhe.powerfulrecyclerviewlib.R;
10 | import com.zjutkz.powerfulrecyclerview.listener.IHeaderView;
11 | import com.zjutkz.powerfulrecyclerview.listener.OnViewClick;
12 | import com.zjutkz.powerfulrecyclerview.simple.SimpleImageView;
13 | import com.zjutkz.powerfulrecyclerview.simple.SimpleTextView;
14 |
15 |
16 | /**
17 | * Created by kangzhe on 16/1/5.
18 | */
19 | public class PowerfulSimpleRecyclerView extends PowerfulRecyclerView implements OnViewClick,SwipeRefreshLayout.OnRefreshListener{
20 |
21 | private static final String TAG = "WdSimplePtrContainer";
22 |
23 | public PowerfulSimpleRecyclerView(Context context, AttributeSet attrs) {
24 | this(context, attrs, 0);
25 | }
26 |
27 | public PowerfulSimpleRecyclerView(Context context) {
28 | this(context, null);
29 | }
30 |
31 | public PowerfulSimpleRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) {
32 | super(context, attrs, defStyleAttr);
33 | }
34 |
35 | @Override
36 | protected void onAttachedToWindow() {
37 | super.onAttachedToWindow();
38 | if(!isSwipeToRefresh && mRefreshListener != null){
39 | setHeaderView(LayoutInflater.from(getContext()).inflate(R.layout.simple_header, PowerfulSimpleRecyclerView.this, false));
40 | }
41 | }
42 |
43 | public PowerfulSimpleRecyclerView setHeaderStrings(final String[] strArray){
44 | this.post(new Runnable() {
45 | @Override
46 | public void run() {
47 | for (IHeaderView headerView : mHeaderViews) {
48 | if (headerView instanceof SimpleTextView) {
49 | ((SimpleTextView) headerView).setPullToRefreshText(strArray[0]);
50 | ((SimpleTextView) headerView).setReleaseToRefreshText(strArray[1]);
51 | ((SimpleTextView) headerView).setOnRefreshText(strArray[2]);
52 | }
53 | }
54 | }
55 | });
56 |
57 | return this;
58 | }
59 |
60 | public PowerfulSimpleRecyclerView setHeaderDrawables(final int[] drawable){
61 | this.post(new Runnable() {
62 | @Override
63 | public void run() {
64 | for (IHeaderView headerView : mHeaderViews) {
65 | if (headerView instanceof SimpleImageView) {
66 | ((SimpleImageView) headerView).setPullToRefreshDrawable(getContext().getResources().getDrawable(drawable[0]));
67 | ((SimpleImageView) headerView).setReleaseToRefreshDrawable(getContext().getResources().getDrawable(drawable[1]));
68 | }
69 | }
70 | }
71 | });
72 |
73 | return this;
74 | }
75 |
76 | @Override
77 | public boolean onInterceptTouchEvent(MotionEvent ev) {
78 | return super.onInterceptTouchEvent(ev);
79 | }
80 |
81 | @Override
82 | public boolean onTouchEvent(MotionEvent event) {
83 | return super.onTouchEvent(event);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/simple/SimpleFooterView.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.simple;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.TextView;
6 |
7 | import com.zjutkz.powerfulrecyclerview.listener.IFooterView;
8 |
9 |
10 | /**
11 | * Created by kangzhe on 16/1/10.
12 | */
13 | public class SimpleFooterView extends TextView implements IFooterView {
14 |
15 | private String onShowText;
16 | private String onLoadMoreText;
17 |
18 | public SimpleFooterView(Context context) {
19 | this(context, null);
20 | }
21 |
22 | public SimpleFooterView(Context context, AttributeSet attrs) {
23 | this(context, attrs, 0);
24 | }
25 |
26 | public SimpleFooterView(Context context, AttributeSet attrs, int defStyleAttr) {
27 | super(context, attrs, defStyleAttr);
28 | }
29 |
30 | @Override
31 | public void onShow() {
32 | setText(onShowText);
33 | }
34 |
35 | @Override
36 | public void onLoadMore() {
37 | setText(onLoadMoreText);
38 | }
39 |
40 | public void setOnShowText(String onShowText){
41 | this.onShowText = onShowText;
42 | }
43 |
44 | public void setOnLoadMoreText(String onLoadMoreText){
45 | this.onLoadMoreText = onLoadMoreText;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/simple/SimpleHeaderContainer.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.simple;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.animation.Animation;
6 | import android.view.animation.RotateAnimation;
7 | import android.widget.FrameLayout;
8 | import android.widget.LinearLayout;
9 | import android.widget.ProgressBar;
10 |
11 | import com.example.kangzhe.powerfulrecyclerviewlib.R;
12 | import com.zjutkz.powerfulrecyclerview.listener.IHeaderView;
13 |
14 |
15 | /**
16 | * Created by kangzhe on 16/2/26.
17 | */
18 | public class SimpleHeaderContainer extends LinearLayout implements IHeaderView {
19 |
20 | private static final int ANIMATION_DURATION = 180;
21 |
22 | public static final int PULL_TO_REFRESH = 0;
23 |
24 | public static final int RELEASE_TO_REFRESH = 1;
25 |
26 | public static final int ON_REFRESH = 2;
27 |
28 | public static final int IDLE = 3;
29 |
30 | private int state = IDLE;
31 |
32 | private SimpleImageView iv;
33 |
34 | private SimpleTextView tv;
35 |
36 | private ProgressBar pb;
37 |
38 | private Animation mRotateUpAnim;
39 |
40 | private Animation mRotateDownAnim;
41 |
42 | public SimpleHeaderContainer(Context context) {
43 | this(context, null);
44 | }
45 |
46 | public SimpleHeaderContainer(Context context, AttributeSet attrs) {
47 | this(context, attrs, 0);
48 | }
49 |
50 | public SimpleHeaderContainer(Context context, AttributeSet attrs, int defStyleAttr) {
51 | super(context, attrs, defStyleAttr);
52 | this.post(new Runnable() {
53 | @Override
54 | public void run() {
55 | initView();
56 | }
57 | });
58 | initAnim();
59 | }
60 |
61 | private void initAnim() {
62 | mRotateUpAnim = new RotateAnimation(0.0f, -180.0f,
63 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
64 | 0.5f);
65 | mRotateUpAnim.setDuration(ANIMATION_DURATION);
66 | mRotateUpAnim.setFillAfter(true);
67 |
68 | mRotateDownAnim = new RotateAnimation(-180.0f, 0.0f,
69 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
70 | 0.5f);
71 | mRotateDownAnim.setDuration(ANIMATION_DURATION);
72 | mRotateDownAnim.setFillAfter(true);
73 | }
74 |
75 | private void initView() {
76 | FrameLayout container = (FrameLayout)getChildAt(0);
77 | iv = (SimpleImageView)container.getChildAt(0);
78 | pb = (ProgressBar)container.getChildAt(1);
79 |
80 | tv = (SimpleTextView)getChildAt(1);
81 |
82 | iv.setImageDrawable(getResources().getDrawable(R.drawable.ptr_down_arrow));
83 | }
84 |
85 |
86 | @Override
87 | public void pullToRefresh() {
88 | if(state == RELEASE_TO_REFRESH){
89 | iv.startAnimation(mRotateDownAnim);
90 | }
91 |
92 | state = PULL_TO_REFRESH;
93 |
94 | pb.setVisibility(INVISIBLE);
95 | iv.setVisibility(VISIBLE);
96 |
97 | tv.setText("下拉刷新");
98 | }
99 |
100 | @Override
101 | public void releaseToRefresh() {
102 | if(state == PULL_TO_REFRESH){
103 | iv.startAnimation(mRotateUpAnim);
104 | }
105 |
106 | state = RELEASE_TO_REFRESH;
107 |
108 | pb.setVisibility(INVISIBLE);
109 | iv.setVisibility(VISIBLE);
110 |
111 | tv.setText("松开刷新数据");
112 | }
113 |
114 | @Override
115 | public void onRefresh() {
116 | state = ON_REFRESH;
117 |
118 | iv.clearAnimation();
119 |
120 | pb.setVisibility(VISIBLE);
121 | iv.setVisibility(INVISIBLE);
122 |
123 | tv.setText("正在加载...");
124 | }
125 |
126 | @Override
127 | public void onReset(float distance, float fraction) {
128 |
129 | }
130 |
131 | @Override
132 | public void onPull(float distance, float fraction) {
133 |
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/simple/SimpleImageView.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.simple;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 | import android.util.AttributeSet;
6 | import android.widget.ImageView;
7 |
8 | import com.zjutkz.powerfulrecyclerview.listener.IHeaderView;
9 |
10 |
11 | /**
12 | * Created by kangzhe on 16/1/5.
13 | */
14 | public class SimpleImageView extends ImageView implements IHeaderView {
15 |
16 | private Drawable pullToRefreshDrawable;
17 | private Drawable releaseToRefreshDrawable;
18 | private Drawable onRefreshDrawable;
19 |
20 | public void setPullToRefreshDrawable(Drawable pullToRefreshDrawable) {
21 | this.pullToRefreshDrawable = pullToRefreshDrawable;
22 | }
23 |
24 | public void setReleaseToRefreshDrawable(Drawable releaseToRefreshDrawable) {
25 | this.releaseToRefreshDrawable = releaseToRefreshDrawable;
26 | }
27 |
28 | public void setOnRefreshDrawable(Drawable onRefreshDrawable) {
29 | this.onRefreshDrawable = onRefreshDrawable;
30 | }
31 |
32 | public SimpleImageView(Context context) {
33 | this(context, null);
34 | }
35 |
36 | public SimpleImageView(Context context, AttributeSet attrs) {
37 | this(context, attrs, 0);
38 | }
39 |
40 | public SimpleImageView(Context context, AttributeSet attrs, int defStyleAttr) {
41 | super(context, attrs, defStyleAttr);
42 | }
43 |
44 | @Override
45 | public void pullToRefresh() {
46 | if(pullToRefreshDrawable != null){
47 | setImageDrawable(pullToRefreshDrawable);
48 | }
49 | }
50 |
51 | @Override
52 | public void releaseToRefresh() {
53 | if(releaseToRefreshDrawable != null){
54 | setImageDrawable(releaseToRefreshDrawable);
55 | }
56 | }
57 |
58 | @Override
59 | public void onRefresh() {
60 | if(onRefreshDrawable != null){
61 | setImageDrawable(onRefreshDrawable);
62 | }
63 | }
64 |
65 | @Override
66 | public void onReset(float distance, float fraction) {
67 |
68 | }
69 |
70 | @Override
71 | public void onPull(float distance, float fraction) {
72 |
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/simple/SimpleTextView.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.simple;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 | import android.util.AttributeSet;
6 | import android.widget.TextView;
7 |
8 | import com.zjutkz.powerfulrecyclerview.listener.IHeaderView;
9 |
10 |
11 | /**
12 | * Created by kangzhe on 16/1/5.
13 | */
14 | public class SimpleTextView extends TextView implements IHeaderView {
15 |
16 | private String pullToRefreshText;
17 | private String releaseToRefreshText;
18 | private String onRefreshText;
19 |
20 | public void setPullToRefreshText(String pullToRefreshText) {
21 | this.pullToRefreshText = pullToRefreshText;
22 | }
23 |
24 | public void setReleaseToRefreshText(String releaseToRefreshText) {
25 | this.releaseToRefreshText = releaseToRefreshText;
26 | }
27 |
28 | public void setOnRefreshText(String onRefreshText) {
29 | this.onRefreshText = onRefreshText;
30 | }
31 |
32 | public SimpleTextView(Context context) {
33 | this(context, null);
34 | }
35 |
36 | public SimpleTextView(Context context, AttributeSet attrs) {
37 | this(context, attrs, 0);
38 | }
39 |
40 | public SimpleTextView(Context context, AttributeSet attrs, int defStyleAttr) {
41 | super(context, attrs, defStyleAttr);
42 | }
43 |
44 | @Override
45 | public void pullToRefresh() {
46 | if(!TextUtils.isEmpty(pullToRefreshText)){
47 | setText(pullToRefreshText);
48 | }
49 | }
50 |
51 | @Override
52 | public void releaseToRefresh() {
53 | if(!TextUtils.isEmpty(releaseToRefreshText)){
54 | setText(releaseToRefreshText);
55 | }
56 | }
57 |
58 | @Override
59 | public void onRefresh() {
60 | if(!TextUtils.isEmpty(onRefreshText)){
61 | setText(onRefreshText);
62 | }
63 | }
64 |
65 | @Override
66 | public void onReset(float distance, float fraction) {
67 |
68 | }
69 |
70 | @Override
71 | public void onPull(float distance, float fraction) {
72 |
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/touchHelper/ItemTouchHelperCallback.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.touchHelper;
2 |
3 | import android.graphics.Canvas;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.support.v7.widget.helper.ItemTouchHelper;
6 |
7 | import com.zjutkz.powerfulrecyclerview.adapter.PowerfulRecyclerAdapter;
8 | import com.zjutkz.powerfulrecyclerview.listener.ItemTouchAdapter;
9 | import com.zjutkz.powerfulrecyclerview.ptr.PowerfulRecyclerView;
10 |
11 |
12 | /**
13 | * Created by kangzhe on 16/1/27.
14 | */
15 | public class ItemTouchHelperCallback extends ItemTouchHelper.Callback {
16 |
17 | private final ItemTouchAdapter mAdapter;
18 |
19 | private boolean shouldDrag;
20 |
21 | private boolean shouldSwipe;
22 |
23 | public ItemTouchHelperCallback(ItemTouchAdapter adapter,boolean shouldDrag,boolean shouldSwipe) {
24 | mAdapter = adapter;
25 | this.shouldDrag = shouldDrag;
26 | this.shouldSwipe = shouldSwipe;
27 | }
28 |
29 | @Override
30 | public boolean isLongPressDragEnabled() {
31 | return shouldDrag;
32 | }
33 |
34 | @Override
35 | public boolean isItemViewSwipeEnabled() {
36 | return shouldSwipe;
37 | }
38 |
39 | @Override
40 | public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
41 | int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN |
42 | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
43 | int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
44 | return makeMovementFlags(dragFlags, swipeFlags);
45 | }
46 |
47 | @Override
48 | public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
49 | RecyclerView.ViewHolder target) {
50 | //存在头部或底部,并且点击头部或底部
51 | if((((PowerfulRecyclerAdapter) mAdapter).hasHeaderView() && viewHolder.getAdapterPosition() == 0) || (((PowerfulRecyclerAdapter) mAdapter).hasFootView() && viewHolder.getAdapterPosition() == ((PowerfulRecyclerAdapter)mAdapter).getItemCount() - 1)){
52 | return false;
53 | }
54 |
55 | //存在头部或底部,并且点击头部或底部
56 | if((((PowerfulRecyclerAdapter) mAdapter).hasHeaderView() && target.getAdapterPosition() == 0) || (((PowerfulRecyclerAdapter) mAdapter).hasFootView() && target.getAdapterPosition() == ((PowerfulRecyclerAdapter)mAdapter).getItemCount() - 1)){
57 | return false;
58 | }
59 |
60 | if(((PowerfulRecyclerAdapter) mAdapter).getPlugAdapter().getItemViewType(viewHolder.getAdapterPosition() - ((PowerfulRecyclerAdapter) mAdapter).getHeaderViewCount()) == PowerfulRecyclerView.TYPE_RECYCLER_FOOTER){
61 | return false;
62 | }
63 |
64 | mAdapter.onMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
65 | return true;
66 | }
67 |
68 | @Override
69 | public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
70 | if(!(mAdapter instanceof PowerfulRecyclerAdapter)){
71 | return;
72 | }
73 |
74 | //存在头部,并且点击头部
75 | if(((PowerfulRecyclerAdapter) mAdapter).hasHeaderView() && viewHolder.getAdapterPosition() == 0){
76 | return;
77 | }
78 |
79 | //存在底部,并且点击底部
80 | if(((PowerfulRecyclerAdapter) mAdapter).hasFootView() && viewHolder.getAdapterPosition() == ((PowerfulRecyclerAdapter)mAdapter).getItemCount() - 1){
81 | return;
82 | }
83 |
84 | if(((PowerfulRecyclerAdapter) mAdapter).getPlugAdapter().getItemViewType(viewHolder.getAdapterPosition() - ((PowerfulRecyclerAdapter) mAdapter).getHeaderViewCount()) == PowerfulRecyclerView.TYPE_RECYCLER_FOOTER){
85 | return;
86 | }
87 |
88 | mAdapter.onDismiss(viewHolder.getAdapterPosition());
89 | }
90 |
91 | @Override
92 | public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
93 | boolean clickHeader = ((PowerfulRecyclerAdapter) mAdapter).hasHeaderView() && viewHolder.getAdapterPosition() == 0;
94 | boolean clickFooter = ((PowerfulRecyclerAdapter) mAdapter).hasFootView() && viewHolder.getAdapterPosition() == ((PowerfulRecyclerAdapter)mAdapter).getItemCount() - 1;
95 | boolean clickRecyclerFooter = ((PowerfulRecyclerAdapter) mAdapter).getPlugAdapter().getItemViewType(viewHolder.getAdapterPosition() - ((PowerfulRecyclerAdapter) mAdapter).getHeaderViewCount()) == PowerfulRecyclerView.TYPE_RECYCLER_FOOTER;
96 | if(clickHeader || clickFooter || clickRecyclerFooter){
97 | return;
98 | }else{
99 | if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
100 | float width = (float) viewHolder.itemView.getWidth();
101 | float alpha = 1.0f - Math.abs(dX) / width;
102 | viewHolder.itemView.setAlpha(alpha);
103 | viewHolder.itemView.setTranslationX(dX);
104 | } else {
105 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY,
106 | actionState, isCurrentlyActive);
107 | }
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/touchHelper/ItemTouchHelperFactory.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.touchHelper;
2 |
3 | import android.support.v7.widget.GridLayoutManager;
4 | import android.support.v7.widget.LinearLayoutManager;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.support.v7.widget.StaggeredGridLayoutManager;
7 | import android.support.v7.widget.helper.ItemTouchHelper;
8 |
9 | import com.zjutkz.powerfulrecyclerview.listener.ItemTouchAdapter;
10 |
11 |
12 | /**
13 | * Created by kangzhe on 16/1/27.
14 | */
15 | public class ItemTouchHelperFactory {
16 |
17 | private static final String TAG = "ItemTouchHelperFactory";
18 |
19 | public static ItemTouchHelper.Callback createCallback(RecyclerView mRecycler,RecyclerView.LayoutManager manager,boolean shouldDrag,boolean shouldSwipe){
20 | if((manager instanceof GridLayoutManager || manager instanceof StaggeredGridLayoutManager) && mRecycler.getAdapter() instanceof ItemTouchAdapter){
21 | return new ItemTouchHelperCallback((ItemTouchAdapter)mRecycler.getAdapter(),shouldDrag,shouldSwipe);
22 | }else if(manager instanceof LinearLayoutManager && mRecycler.getAdapter() instanceof ItemTouchAdapter){
23 | return new SimpleItemTouchHelperCallback((ItemTouchAdapter)mRecycler.getAdapter(),shouldDrag,shouldSwipe);
24 | }
25 |
26 | throw new RuntimeException("invalid LayoutManager!it must be linear,grid or staggered");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/touchHelper/ItemTouchListenerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.touchHelper;
2 |
3 | import android.support.annotation.Nullable;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.util.Log;
6 | import android.view.GestureDetector;
7 | import android.view.MotionEvent;
8 | import android.view.View;
9 |
10 | import com.zjutkz.powerfulrecyclerview.adapter.PowerfulRecyclerAdapter;
11 | import com.zjutkz.powerfulrecyclerview.listener.OnViewClick;
12 |
13 |
14 | /**
15 | * Created by kangzhe on 16/3/9.
16 | */
17 | public class ItemTouchListenerAdapter extends GestureDetector.SimpleOnGestureListener implements RecyclerView.OnItemTouchListener {
18 |
19 | private OnViewClick listener;
20 | private RecyclerView recyclerView;
21 | private GestureDetector gestureDetector;
22 |
23 | public ItemTouchListenerAdapter(RecyclerView recyclerView, OnViewClick listener) {
24 | if (recyclerView == null || listener == null) {
25 | throw new IllegalArgumentException("RecyclerView and Listener arguments can not be null");
26 | }
27 | this.recyclerView = recyclerView;
28 | this.listener = listener;
29 | this.gestureDetector = new GestureDetector(recyclerView.getContext(), this);
30 | }
31 |
32 | @Override
33 | public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
34 | gestureDetector.onTouchEvent(motionEvent);
35 | return false;
36 | }
37 |
38 | @Override
39 | public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
40 | }
41 |
42 | @Override
43 | public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
44 |
45 | }
46 | @Override
47 | public void onShowPress(MotionEvent e) {
48 | View view = getChildViewUnder(e);
49 | if (view != null) {
50 | view.setPressed(true);
51 | }
52 | }
53 |
54 | @Override
55 | public boolean onSingleTapUp(MotionEvent e) {
56 | View view = getChildViewUnder(e);
57 | if (view == null) return false;
58 |
59 | view.setPressed(false);
60 |
61 | int position = recyclerView.getChildAdapterPosition(view);
62 |
63 | RecyclerView.ViewHolder holder = getViewHolderUnder(position);
64 |
65 | RecyclerView.Adapter mAdapter = recyclerView.getAdapter();
66 | if(mAdapter instanceof PowerfulRecyclerAdapter){
67 | position -= ((PowerfulRecyclerAdapter) mAdapter).getHeaderViewCount();
68 | }
69 |
70 | if(position < 0){
71 | return false;
72 | }
73 |
74 | listener.onClick(holder, position);
75 | return true;
76 | }
77 |
78 | public void onLongPress(MotionEvent e) {
79 | View view = getChildViewUnder(e);
80 | if (view == null) return;
81 |
82 | int position = recyclerView.getChildAdapterPosition(view);
83 |
84 | RecyclerView.Adapter mAdapter = recyclerView.getAdapter();
85 | if(mAdapter instanceof PowerfulRecyclerAdapter){
86 | position -= ((PowerfulRecyclerAdapter) mAdapter).getHeaderViewCount();
87 | }
88 |
89 | RecyclerView.ViewHolder holder = getViewHolderUnder(position);
90 |
91 | if(position < 0){
92 | return;
93 | }
94 |
95 | listener.onLongClick(holder, position);
96 | view.setPressed(false);
97 | }
98 |
99 | @Nullable
100 | private View getChildViewUnder(MotionEvent e) {
101 | return recyclerView.findChildViewUnder(e.getX(), e.getY());
102 | }
103 |
104 | private RecyclerView.ViewHolder getViewHolderUnder(int position){
105 | return recyclerView.findViewHolderForAdapterPosition(position);
106 | }
107 | }
108 |
109 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/touchHelper/SimpleItemTouchHelperCallback.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.touchHelper;
2 |
3 | import android.graphics.Canvas;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.support.v7.widget.helper.ItemTouchHelper;
6 |
7 | import com.zjutkz.powerfulrecyclerview.adapter.PowerfulRecyclerAdapter;
8 | import com.zjutkz.powerfulrecyclerview.listener.ItemTouchAdapter;
9 | import com.zjutkz.powerfulrecyclerview.ptr.PowerfulRecyclerView;
10 |
11 |
12 | /**
13 | * Created by kangzhe on 16/1/27.
14 | */
15 | public class SimpleItemTouchHelperCallback extends ItemTouchHelper.Callback {
16 |
17 | private static final String TAG = "Callback";
18 |
19 | private final ItemTouchAdapter mAdapter;
20 |
21 | private boolean shouldDrag = false;
22 |
23 | private boolean shouldSwipe = false;
24 |
25 | public SimpleItemTouchHelperCallback(ItemTouchAdapter adapter,boolean shouldDrag,boolean shouldSwipe) {
26 | mAdapter = adapter;
27 | this.shouldDrag = shouldDrag;
28 | this.shouldSwipe = shouldSwipe;
29 | }
30 |
31 | @Override
32 | public boolean isLongPressDragEnabled() {
33 | return shouldDrag;
34 | }
35 |
36 | @Override
37 | public boolean isItemViewSwipeEnabled() {
38 | return shouldSwipe;
39 | }
40 |
41 | @Override
42 | public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
43 | int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
44 | int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
45 | return makeMovementFlags(dragFlags, swipeFlags);
46 | }
47 |
48 | @Override
49 | public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
50 | RecyclerView.ViewHolder target) {
51 | //存在头部或底部,并且点击头部或底部
52 | if((((PowerfulRecyclerAdapter) mAdapter).hasHeaderView() && viewHolder.getAdapterPosition() == 0) || (((PowerfulRecyclerAdapter) mAdapter).hasFootView() && viewHolder.getAdapterPosition() == ((PowerfulRecyclerAdapter)mAdapter).getItemCount() - 1)){
53 | return false;
54 | }
55 |
56 | //存在头部或底部,并且点击头部或底部
57 | if((((PowerfulRecyclerAdapter) mAdapter).hasHeaderView() && target.getAdapterPosition() == 0) || (((PowerfulRecyclerAdapter) mAdapter).hasFootView() && target.getAdapterPosition() == ((PowerfulRecyclerAdapter)mAdapter).getItemCount() - 1)){
58 | return false;
59 | }
60 |
61 | if(((PowerfulRecyclerAdapter) mAdapter).getPlugAdapter().getItemViewType(viewHolder.getAdapterPosition() - ((PowerfulRecyclerAdapter) mAdapter).getHeaderViewCount()) == PowerfulRecyclerView.TYPE_RECYCLER_FOOTER){
62 | return false;
63 | }
64 |
65 | mAdapter.onMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
66 | return true;
67 | }
68 |
69 | @Override
70 | public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
71 | if(!(mAdapter instanceof PowerfulRecyclerAdapter)){
72 | return;
73 | }
74 |
75 | //存在头部,并且点击头部
76 | if(((PowerfulRecyclerAdapter) mAdapter).hasHeaderView() && viewHolder.getAdapterPosition() == 0){
77 | return;
78 | }
79 |
80 | //存在底部,并且点击底部
81 | if(((PowerfulRecyclerAdapter) mAdapter).hasFootView() && viewHolder.getAdapterPosition() == ((PowerfulRecyclerAdapter)mAdapter).getItemCount() - 1){
82 | return;
83 | }
84 |
85 | if(((PowerfulRecyclerAdapter) mAdapter).getPlugAdapter().getItemViewType(viewHolder.getAdapterPosition() - ((PowerfulRecyclerAdapter) mAdapter).getHeaderViewCount()) == PowerfulRecyclerView.TYPE_RECYCLER_FOOTER){
86 | return;
87 | }
88 |
89 | mAdapter.onDismiss(viewHolder.getAdapterPosition());
90 | }
91 |
92 | @Override
93 | public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
94 | if(viewHolder.getAdapterPosition() < 0){
95 | return;
96 | }
97 | boolean clickHeader = ((PowerfulRecyclerAdapter) mAdapter).hasHeaderView() && viewHolder.getAdapterPosition() == 0;
98 | boolean clickFooter = ((PowerfulRecyclerAdapter) mAdapter).hasFootView() && viewHolder.getAdapterPosition() == ((PowerfulRecyclerAdapter)mAdapter).getItemCount() - 1;
99 | boolean clickRecyclerFooter = ((PowerfulRecyclerAdapter) mAdapter).getPlugAdapter().getItemViewType(viewHolder.getAdapterPosition() - ((PowerfulRecyclerAdapter) mAdapter).getHeaderViewCount()) == PowerfulRecyclerView.TYPE_RECYCLER_FOOTER;
100 | if(clickHeader || clickFooter || clickRecyclerFooter){
101 | return;
102 | }else{
103 | if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
104 | float width = (float) viewHolder.itemView.getWidth();
105 | float alpha = 1.0f - Math.abs(dX) / width;
106 | viewHolder.itemView.setAlpha(alpha);
107 | viewHolder.itemView.setTranslationX(dX);
108 | } else {
109 | super.onChildDraw(c, recyclerView, viewHolder, dX, dY,
110 | actionState, isCurrentlyActive);
111 | }
112 | }
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/utils/AnimateViewUtils.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.utils;
2 |
3 | import android.support.v4.view.ViewCompat;
4 | import android.view.View;
5 |
6 | /**
7 | * Created by kangzhe on 16/1/29.
8 | */
9 | public class AnimateViewUtils {
10 |
11 | public static void clear(View v) {
12 | ViewCompat.setAlpha(v, 1);
13 | ViewCompat.setScaleY(v, 1);
14 | ViewCompat.setScaleX(v, 1);
15 | ViewCompat.setTranslationY(v, 0);
16 | ViewCompat.setTranslationX(v, 0);
17 | ViewCompat.setRotation(v, 0);
18 | ViewCompat.setRotationY(v, 0);
19 | ViewCompat.setRotationX(v, 0);
20 | v.setPivotY(v.getMeasuredHeight() / 2);
21 | ViewCompat.setPivotX(v, v.getMeasuredWidth() / 2);
22 | ViewCompat.animate(v).setInterpolator(null);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/java/com/zjutkz/powerfulrecyclerview/utils/FooterUtils.java:
--------------------------------------------------------------------------------
1 | package com.zjutkz.powerfulrecyclerview.utils;
2 |
3 | import android.support.v7.widget.LinearLayoutManager;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.support.v7.widget.StaggeredGridLayoutManager;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 |
10 | import com.zjutkz.powerfulrecyclerview.listener.IFooterView;
11 | import com.zjutkz.powerfulrecyclerview.listener.OnLoadMoreListener;
12 | import com.zjutkz.powerfulrecyclerview.ptr.PowerfulRecyclerView;
13 |
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | /**
18 | * Created by kangzhe on 16/1/5.
19 | */
20 | public class FooterUtils {
21 | private static final String TAG = "FooterUtils";
22 |
23 | private boolean isLoadMore = false;
24 |
25 | private List mFooterViews;
26 |
27 | /**
28 | * 防止重复load
29 | */
30 | private boolean isFirst = true;
31 |
32 | /**
33 | * 由于setListener后会调用一次onScroll方法,屏蔽掉。
34 | */
35 | private boolean isFirstScroll = true;
36 |
37 | private OnLoadMoreListener loadMoreListener;
38 |
39 | private PowerfulRecyclerView container;
40 |
41 | public FooterUtils(PowerfulRecyclerView container){
42 | this.container = container;
43 | }
44 |
45 | private RecyclerView.OnScrollListener onScrollListener = new RecyclerView.OnScrollListener() {
46 | @Override
47 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
48 | if (newState == RecyclerView.SCROLL_STATE_IDLE && isLoadMore && isFirst && container.isLoadMoreEnable()) {
49 | if (loadMoreListener != null) {
50 | isFirst = false;
51 |
52 | loadMoreListener.onLoadMore();
53 |
54 | for (IFooterView footerView : mFooterViews) {
55 | footerView.onLoadMore();
56 | }
57 | }
58 | }
59 | }
60 |
61 | @Override
62 | public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
63 | if (isFirstScroll) {
64 | isFirstScroll = false;
65 | } else {
66 | if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
67 | int lastVisibleItemPosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastCompletelyVisibleItemPosition();
68 | if (lastVisibleItemPosition + 1 == recyclerView.getAdapter().getItemCount() && !isLoadMore) {
69 |
70 | isLoadMore = true;
71 | } else {
72 | isLoadMore = false;
73 | }
74 | } else {
75 | int[] lastVisibleItemPosition = ((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findLastCompletelyVisibleItemPositions(null);
76 | if (lastVisibleItemPosition[lastVisibleItemPosition.length - 1] + 1 == recyclerView.getAdapter().getItemCount() && !isLoadMore) {
77 |
78 | isLoadMore = true;
79 | } else {
80 | isLoadMore = false;
81 | }
82 | }
83 | }
84 | }
85 | };
86 |
87 | /**
88 | * 添加footer
89 | * @param parent
90 | * @param footerView
91 | * @param loadMoreListener
92 | */
93 | public void addFooterView(RecyclerView parent,View footerView,final OnLoadMoreListener loadMoreListener){
94 | this.loadMoreListener = loadMoreListener;
95 |
96 | if(mFooterViews != null){
97 | mFooterViews.clear();
98 | }
99 |
100 | if(mFooterViews == null){
101 | mFooterViews = new ArrayList();
102 | }
103 |
104 | if(footerView instanceof IFooterView){
105 | mFooterViews.add((IFooterView)footerView);
106 | }
107 |
108 | if(footerView instanceof ViewGroup){
109 | for(int i = 0;i < ((ViewGroup) footerView).getChildCount();i++){
110 | View child = ((ViewGroup) footerView).getChildAt(i);
111 | if(child instanceof IFooterView){
112 | mFooterViews.add((IFooterView)child);
113 | }
114 | }
115 | }
116 |
117 | RecyclerViewUtils.getInstance().setFootView(parent, footerView);
118 |
119 | parent.removeOnScrollListener(onScrollListener);
120 | parent.addOnScrollListener(onScrollListener);
121 |
122 |
123 | footerView.setOnClickListener(new View.OnClickListener() {
124 | @Override
125 | public void onClick(View v) {
126 | if (loadMoreListener != null && isFirst) {
127 | isFirst = false;
128 |
129 | loadMoreListener.onLoadMore();
130 | for (IFooterView footerView : mFooterViews) {
131 | footerView.onLoadMore();
132 | }
133 | }
134 | }
135 | });
136 |
137 | for (IFooterView footerView2 : mFooterViews) {
138 | footerView2.onLoadMore();
139 | }
140 | }
141 |
142 | public void resetFooterView(RecyclerView parent,View footerView,final OnLoadMoreListener loadMoreListener){
143 | isLoadMore = false;
144 |
145 | isFirst = true;
146 |
147 | addFooterView(parent, footerView, loadMoreListener);
148 | }
149 |
150 | public void stopLoadMore(){
151 | if(mFooterViews != null && mFooterViews.size() > 0) {
152 | for (IFooterView footerView : mFooterViews) {
153 | footerView.onShow();
154 | }
155 | }
156 | isLoadMore = false;
157 |
158 | isFirst = true;
159 | }
160 |
161 | /**
162 | * 取消footer
163 | * @param parent
164 | * @param footerView
165 | */
166 | public void removeFooterView(View parent,View footerView){
167 | if(parent instanceof RecyclerView){
168 | removeRecyclerViewFooterView(((RecyclerView) parent), footerView);
169 | }
170 | }
171 |
172 | public static void removeRecyclerViewFooterView(RecyclerView parent, View footerView){
173 | RecyclerViewUtils.getInstance().removeFootView(parent, footerView);
174 |
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/res/drawable-hdpi/ptr_down_arrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/powerfulrecyclerviewlib/src/main/res/drawable-hdpi/ptr_down_arrow.png
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/res/drawable-xhdpi/ptr_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/powerfulrecyclerviewlib/src/main/res/drawable-xhdpi/ptr_loading.png
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/res/drawable/ptr_img_progress.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/res/layout/def_no_data_view_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/res/layout/default_footer.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
18 |
19 |
24 |
25 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/res/layout/recycler_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/res/layout/simple_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
18 |
19 |
26 |
27 |
28 |
32 |
33 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PowerfulRecyclerViewLib
3 |
4 |
--------------------------------------------------------------------------------
/powerfulrecyclerviewlib/src/test/java/com/example/kangzhe/powerfulrecyclerviewlib/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.powerfulrecyclerviewlib;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.kz.sample"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.1.1'
26 | compile 'com.android.support:design:23.1.1'
27 | compile 'com.android.support:cardview-v7:23.1.1'
28 | compile 'com.squareup.picasso:picasso:2.5.2'
29 | compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
30 | compile project(':powerfulrecyclerviewlib')
31 | }
32 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/kangzhe/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/sample.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | generateDebugSources
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/example/kangzhe/sample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/MyApp.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample;
2 |
3 | import android.app.Application;
4 |
5 | import com.nostra13.universalimageloader.core.ImageLoader;
6 | import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
7 |
8 | /**
9 | * Created by kangzhe on 16/3/24.
10 | */
11 | public class MyApp extends Application{
12 |
13 | @Override
14 | public void onCreate() {
15 | super.onCreate();
16 |
17 | ImageLoaderConfiguration configuration = ImageLoaderConfiguration
18 | .createDefault(this);
19 |
20 | ImageLoader.getInstance().init(configuration);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/activity/HorizontalActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.activity;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.os.Message;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.util.Log;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.ImageView;
15 |
16 | import com.zjutkz.powerfulrecyclerview.listener.ItemTouchAdapter;
17 | import com.zjutkz.powerfulrecyclerview.listener.OnLoadMoreListener;
18 | import com.zjutkz.powerfulrecyclerview.listener.OnRefreshListener;
19 | import com.zjutkz.powerfulrecyclerview.ptr.PowerfulRecyclerView;
20 | import com.zjutkz.powerfulrecyclerview.ptr.PowerfulSimpleRecyclerView;
21 | import com.example.kangzhe.sample.R;
22 | import com.squareup.picasso.Picasso;
23 |
24 | import java.util.ArrayList;
25 | import java.util.Collections;
26 | import java.util.List;
27 |
28 | /**
29 | * Created by kangzhe on 16/3/9.
30 | */
31 | public class HorizontalActivity extends AppCompatActivity implements OnRefreshListener,OnLoadMoreListener {
32 |
33 | private static final String TAG = "HorizontalActivity";
34 |
35 | private MyAdapter adapter;
36 |
37 | private List datas = new ArrayList();
38 |
39 | PowerfulSimpleRecyclerView horizontalList;
40 |
41 | int loadMoreCount = 0;
42 |
43 | private int positionToRestore = 0;
44 |
45 | private Handler mHandler = new Handler(){
46 |
47 | @Override
48 | public void handleMessage(Message msg) {
49 | super.handleMessage(msg);
50 | if(msg.what == 0){
51 |
52 | getDatas(0);
53 |
54 | adapter.notifyDataSetChanged();
55 | loadMoreCount = 0;
56 |
57 | horizontalList.stopRefresh();
58 |
59 | if(!horizontalList.isLoadMoreEnable()){
60 | horizontalList.setLoadMoreEnable(true);
61 | }
62 | }else if(msg.what == 1){
63 |
64 | getDatas(1);
65 |
66 | adapter.notifyItemRangeInserted(adapter.getItemCount(), 9);
67 |
68 | horizontalList.stopLoadMore();
69 | }else if(msg.what == 2){
70 | horizontalList.setLoadMoreEnable(false);
71 | }else if(msg.what == 3){
72 | horizontalList.hideSpecialInfoView();
73 | }
74 | }
75 | };
76 |
77 | @Override
78 | protected void onCreate(Bundle savedInstanceState) {
79 | super.onCreate(savedInstanceState);
80 | setContentView(R.layout.activity_horizontal);
81 |
82 | getDatas(0);
83 |
84 | horizontalList = (PowerfulSimpleRecyclerView)findViewById(R.id.horizontal_list);
85 |
86 | adapter = new MyAdapter(this,datas);
87 |
88 | horizontalList.setAdapter(adapter);
89 |
90 | horizontalList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
91 |
92 | horizontalList.setOnRefreshListener(this);
93 |
94 | horizontalList.setOnLoadMoreListener(this);
95 | }
96 |
97 | @Override
98 | protected void onStop() {
99 | super.onStop();
100 |
101 | positionToRestore = horizontalList.getFirstVisiblePosition();
102 | Log.d(TAG, "onStop: " + horizontalList.getFirstVisiblePosition() + " " + horizontalList.getLastVisiblePosition());
103 | }
104 |
105 | @Override
106 | protected void onResume() {
107 | super.onResume();
108 |
109 | horizontalList.setSelection(positionToRestore);
110 | }
111 |
112 | private void getDatas(int msg) {
113 |
114 |
115 | if(msg == 0){
116 | datas.clear();
117 | }
118 |
119 | datas.add(R.drawable.img1);
120 | datas.add(R.drawable.img2);
121 | datas.add(R.drawable.img3);
122 | datas.add(R.drawable.img4);
123 | datas.add(R.drawable.img5);
124 | datas.add(R.drawable.img6);
125 | datas.add(R.drawable.img7);
126 | datas.add(R.drawable.img8);
127 | datas.add(R.drawable.img9);
128 |
129 | }
130 |
131 | @Override
132 | public void onLoadMore() {
133 | if(++loadMoreCount <= 2){
134 | new Thread(new Runnable() {
135 | @Override
136 | public void run() {
137 | try {
138 | Thread.sleep(3000);
139 | mHandler.sendEmptyMessage(1);
140 | } catch (InterruptedException e) {
141 | e.printStackTrace();
142 | }
143 | }
144 | }).start();
145 | }else{
146 | new Thread(new Runnable() {
147 | @Override
148 | public void run() {
149 | try {
150 | Thread.sleep(3000);
151 | mHandler.sendEmptyMessage(2);
152 | } catch (InterruptedException e) {
153 | e.printStackTrace();
154 | }
155 | }
156 | }).start();
157 | }
158 | }
159 |
160 | @Override
161 | public void onRefresh() {
162 | new Thread(new Runnable() {
163 | @Override
164 | public void run() {
165 | try {
166 | Thread.sleep(2000);
167 | mHandler.sendEmptyMessage(0);
168 | } catch (InterruptedException e) {
169 | e.printStackTrace();
170 | }
171 | }
172 | }).start();
173 | }
174 |
175 | public class MyAdapter extends RecyclerView.Adapter implements ItemTouchAdapter {
176 |
177 | private Context mContext;
178 | private List datas;
179 |
180 | public MyAdapter(Context mContext,List datas){
181 | this.mContext = mContext;
182 | this.datas = datas;
183 | }
184 |
185 | @Override
186 | public int getItemViewType(int position) {
187 | if(position < datas.size()){
188 | return 1;
189 | }
190 | return PowerfulRecyclerView.TYPE_RECYCLER_FOOTER;
191 | }
192 |
193 | @Override
194 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
195 | RecyclerView.ViewHolder vh = null;
196 | if(viewType == 1){
197 | vh = new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.new_list_item,parent,false));
198 | }else {
199 | vh = new FooterViewHolder(LayoutInflater.from(mContext).inflate(R.layout.recycler_footer,parent,false));
200 | }
201 |
202 | return vh;
203 | }
204 |
205 | @Override
206 | public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
207 | if(holder instanceof MyViewHolder){
208 | ((MyViewHolder) holder).setImage(datas.get(position));
209 | }
210 | }
211 |
212 | @Override
213 | public int getItemCount() {
214 | return datas.size() + 1;
215 | }
216 |
217 | @Override
218 | public void onMove(int fromPosition, int toPosition) {
219 | if(fromPosition < 0 || toPosition >= datas.size()){
220 | return;
221 | }
222 | Collections.swap(datas, fromPosition, toPosition);
223 | notifyItemMoved(fromPosition, toPosition);
224 | }
225 |
226 | @Override
227 | public void onDismiss(int position) {
228 | if(position < 0 || position >= datas.size()){
229 | return;
230 | }
231 | datas.remove(position);
232 | notifyItemRemoved(position);
233 | }
234 |
235 | public class MyViewHolder extends RecyclerView.ViewHolder{
236 |
237 | public ImageView iv;
238 | public ImageView android;
239 |
240 | public MyViewHolder(View itemView) {
241 | super(itemView);
242 |
243 | iv = (ImageView)itemView.findViewById(R.id.item_iv);
244 | android = (ImageView)itemView.findViewById(R.id.android);
245 | }
246 |
247 | public void setImage(int idImage) {
248 | Picasso.with(iv.getContext()).
249 | load(idImage).
250 | centerCrop().
251 | resize(130,130).
252 | into(iv);
253 | }
254 | }
255 |
256 | public class FooterViewHolder extends RecyclerView.ViewHolder {
257 |
258 | public FooterViewHolder(View itemView) {
259 | super(itemView);
260 | }
261 | }
262 | }
263 | }
264 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.activity;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | import com.example.kangzhe.sample.R;
10 |
11 |
12 | public class MainActivity extends AppCompatActivity {
13 |
14 | private Button recyclerList;
15 |
16 | private Button recyclerGrid;
17 |
18 | private Button recyclerStaggered;
19 |
20 | private Button simplePtr;
21 |
22 | private Button brand5Ptr;
23 |
24 | private Button horizontal;
25 |
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main);
30 |
31 | recyclerList = (Button)findViewById(R.id.recycler_list);
32 | recyclerList.setOnClickListener(new View.OnClickListener() {
33 | @Override
34 | public void onClick(View v) {
35 | Intent intent = new Intent(MainActivity.this,RecyclerListViewActivity.class);
36 | startActivity(intent);
37 | }
38 | });
39 |
40 | recyclerGrid = (Button)findViewById(R.id.recycler_grid);
41 | recyclerGrid.setOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View v) {
44 | Intent intent = new Intent(MainActivity.this,RecyclerGridViewActivity.class);
45 | startActivity(intent);
46 | }
47 | });
48 |
49 | recyclerStaggered = (Button)findViewById(R.id.recycler_staggered);
50 | recyclerStaggered.setOnClickListener(new View.OnClickListener() {
51 | @Override
52 | public void onClick(View v) {
53 | Intent intent = new Intent(MainActivity.this,RecyclerStaggeredViewActivity.class);
54 | startActivity(intent);
55 | }
56 | });
57 |
58 | simplePtr = (Button)findViewById(R.id.simple_ptr);
59 | simplePtr.setOnClickListener(new View.OnClickListener() {
60 | @Override
61 | public void onClick(View v) {
62 | Intent intent = new Intent(MainActivity.this,SimplePtrActivity.class);
63 | startActivity(intent);
64 | }
65 | });
66 |
67 | horizontal = (Button)findViewById(R.id.horizontal_mode);
68 | horizontal.setOnClickListener(new View.OnClickListener() {
69 | @Override
70 | public void onClick(View v) {
71 | Intent intent = new Intent(MainActivity.this,HorizontalActivity.class);
72 | startActivity(intent);
73 | }
74 | });
75 | }
76 | }
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/divider/DividerGridItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.divider;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Rect;
7 | import android.graphics.drawable.Drawable;
8 | import android.support.v7.widget.GridLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.support.v7.widget.RecyclerView.LayoutManager;
11 | import android.support.v7.widget.RecyclerView.State;
12 | import android.support.v7.widget.StaggeredGridLayoutManager;
13 | import android.view.View;
14 |
15 | /**
16 | * Created by kangzhe on 16/1/5.
17 | */
18 | public class DividerGridItemDecoration extends RecyclerView.ItemDecoration
19 | {
20 |
21 | private static final int[] ATTRS = new int[] { android.R.attr.listDivider };
22 | private Drawable mDivider;
23 |
24 | public DividerGridItemDecoration(Context context)
25 | {
26 | final TypedArray a = context.obtainStyledAttributes(ATTRS);
27 | mDivider = a.getDrawable(0);
28 | a.recycle();
29 | }
30 |
31 | @Override
32 | public void onDraw(Canvas c, RecyclerView parent, State state)
33 | {
34 |
35 | drawHorizontal(c, parent);
36 | drawVertical(c, parent);
37 |
38 | }
39 |
40 | private int getSpanCount(RecyclerView parent)
41 | {
42 | // 列数
43 | int spanCount = -1;
44 | LayoutManager layoutManager = parent.getLayoutManager();
45 | if (layoutManager instanceof GridLayoutManager)
46 | {
47 |
48 | spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
49 | } else if (layoutManager instanceof StaggeredGridLayoutManager)
50 | {
51 | spanCount = ((StaggeredGridLayoutManager) layoutManager)
52 | .getSpanCount();
53 | }
54 | return spanCount;
55 | }
56 |
57 | public void drawHorizontal(Canvas c, RecyclerView parent)
58 | {
59 | int childCount = parent.getChildCount();
60 | for (int i = 0; i < childCount; i++)
61 | {
62 | final View child = parent.getChildAt(i);
63 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
64 | .getLayoutParams();
65 | final int left = child.getLeft() - params.leftMargin;
66 | final int right = child.getRight() + params.rightMargin
67 | + mDivider.getIntrinsicWidth();
68 | final int top = child.getBottom() + params.bottomMargin;
69 | final int bottom = top + mDivider.getIntrinsicHeight();
70 | mDivider.setBounds(left, top, right, bottom);
71 | mDivider.draw(c);
72 | }
73 | }
74 |
75 | public void drawVertical(Canvas c, RecyclerView parent)
76 | {
77 | final int childCount = parent.getChildCount();
78 | for (int i = 0; i < childCount; i++)
79 | {
80 | final View child = parent.getChildAt(i);
81 |
82 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
83 | .getLayoutParams();
84 | final int top = child.getTop() - params.topMargin;
85 | final int bottom = child.getBottom() + params.bottomMargin;
86 | final int left = child.getRight() + params.rightMargin;
87 | final int right = left + mDivider.getIntrinsicWidth();
88 |
89 | mDivider.setBounds(left, top, right, bottom);
90 | mDivider.draw(c);
91 | }
92 | }
93 |
94 | private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
95 | int childCount)
96 | {
97 | LayoutManager layoutManager = parent.getLayoutManager();
98 | if (layoutManager instanceof GridLayoutManager)
99 | {
100 | if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
101 | {
102 | return true;
103 | }
104 | } else if (layoutManager instanceof StaggeredGridLayoutManager)
105 | {
106 | int orientation = ((StaggeredGridLayoutManager) layoutManager)
107 | .getOrientation();
108 | if (orientation == StaggeredGridLayoutManager.VERTICAL)
109 | {
110 | if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
111 | {
112 | return true;
113 | }
114 | } else
115 | {
116 | childCount = childCount - childCount % spanCount;
117 | if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
118 | return true;
119 | }
120 | }
121 | return false;
122 | }
123 |
124 | private boolean isLastRaw(RecyclerView parent, int pos, int spanCount,
125 | int childCount)
126 | {
127 | LayoutManager layoutManager = parent.getLayoutManager();
128 | if (layoutManager instanceof GridLayoutManager)
129 | {
130 | childCount = childCount - childCount % spanCount;
131 | if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
132 | return true;
133 | } else if (layoutManager instanceof StaggeredGridLayoutManager)
134 | {
135 | int orientation = ((StaggeredGridLayoutManager) layoutManager)
136 | .getOrientation();
137 | // StaggeredGridLayoutManager 且纵向滚动
138 | if (orientation == StaggeredGridLayoutManager.VERTICAL)
139 | {
140 | childCount = childCount - childCount % spanCount;
141 | // 如果是最后一行,则不需要绘制底部
142 | if (pos >= childCount)
143 | return true;
144 | } else
145 | // StaggeredGridLayoutManager 且横向滚动
146 | {
147 | // 如果是最后一行,则不需要绘制底部
148 | if ((pos + 1) % spanCount == 0)
149 | {
150 | return true;
151 | }
152 | }
153 | }
154 | return false;
155 | }
156 |
157 | @Override
158 | public void getItemOffsets(Rect outRect, int itemPosition,
159 | RecyclerView parent)
160 | {
161 | int spanCount = getSpanCount(parent);
162 | int childCount = parent.getAdapter().getItemCount();
163 | if (isLastRaw(parent, itemPosition, spanCount, childCount))// 如果是最后一行,则不需要绘制底部
164 | {
165 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
166 | } else if (isLastColum(parent, itemPosition, spanCount, childCount))// 如果是最后一列,则不需要绘制右边
167 | {
168 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
169 | } else
170 | {
171 | outRect.set(0, 0, mDivider.getIntrinsicWidth(),
172 | mDivider.getIntrinsicHeight());
173 | }
174 | }
175 | }
176 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/divider/DividerItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.divider;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Rect;
7 | import android.graphics.drawable.Drawable;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.View;
11 |
12 | /**
13 | * Created by kangzhe on 16/1/5.
14 | */
15 | public class DividerItemDecoration extends RecyclerView.ItemDecoration {
16 |
17 | private static final int[] ATTRS = new int[]{
18 | android.R.attr.listDivider
19 | };
20 |
21 | public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
22 |
23 | public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
24 |
25 | private Drawable mDivider;
26 |
27 | private int mOrientation;
28 |
29 | public DividerItemDecoration(Context context, int orientation) {
30 | final TypedArray a = context.obtainStyledAttributes(ATTRS);
31 | mDivider = a.getDrawable(0);
32 | a.recycle();
33 | setOrientation(orientation);
34 | }
35 |
36 | public void setOrientation(int orientation) {
37 | if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) {
38 | throw new IllegalArgumentException("invalid orientation");
39 | }
40 | mOrientation = orientation;
41 | }
42 |
43 | @Override
44 | public void onDraw(Canvas c, RecyclerView parent) {
45 | if (mOrientation == VERTICAL_LIST) {
46 | drawVertical(c, parent);
47 | } else {
48 | drawHorizontal(c, parent);
49 | }
50 |
51 | }
52 |
53 |
54 | public void drawVertical(Canvas c, RecyclerView parent) {
55 | final int left = parent.getPaddingLeft();
56 | final int right = parent.getWidth() - parent.getPaddingRight();
57 |
58 | final int childCount = parent.getChildCount();
59 | for (int i = 0; i < childCount; i++) {
60 | final View child = parent.getChildAt(i);
61 | RecyclerView v = new RecyclerView(parent.getContext());
62 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
63 | .getLayoutParams();
64 | final int top = child.getBottom() + params.bottomMargin;
65 | final int bottom = top + mDivider.getIntrinsicHeight();
66 | mDivider.setBounds(left, top, right, bottom);
67 | mDivider.draw(c);
68 | }
69 | }
70 |
71 | public void drawHorizontal(Canvas c, RecyclerView parent) {
72 | final int top = parent.getPaddingTop();
73 | final int bottom = parent.getHeight() - parent.getPaddingBottom();
74 |
75 | final int childCount = parent.getChildCount();
76 | for (int i = 0; i < childCount; i++) {
77 | final View child = parent.getChildAt(i);
78 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
79 | .getLayoutParams();
80 | final int left = child.getRight() + params.rightMargin;
81 | final int right = left + mDivider.getIntrinsicHeight();
82 | mDivider.setBounds(left, top, right, bottom);
83 | mDivider.draw(c);
84 | }
85 | }
86 |
87 | @Override
88 | public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
89 | if (mOrientation == VERTICAL_LIST) {
90 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
91 | } else {
92 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/fragment/MyFragment1.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import com.example.kangzhe.sample.R;
14 |
15 |
16 | /**
17 | * Created by kangzhe on 16/1/17.
18 | */
19 | public class MyFragment1 extends Fragment {
20 |
21 | @Nullable
22 | @Override
23 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
24 | View view = inflater.inflate(R.layout.fragment_layout,container,false);
25 | TextView tv = (TextView)view.findViewById(R.id.fragment_tv);
26 | tv.setBackgroundColor(Color.CYAN);
27 | tv.setText("fragment1");
28 | tv.setOnClickListener(new View.OnClickListener() {
29 | @Override
30 | public void onClick(View v) {
31 | Toast.makeText(getActivity(),"header click!",Toast.LENGTH_SHORT).show();
32 | }
33 | });
34 | return view;
35 | }
36 |
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/fragment/MyFragment2.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.TextView;
11 |
12 | import com.example.kangzhe.sample.R;
13 |
14 |
15 | /**
16 | * Created by kangzhe on 16/1/17.
17 | */
18 | public class MyFragment2 extends Fragment {
19 |
20 | @Nullable
21 | @Override
22 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
23 | View view = inflater.inflate(R.layout.fragment_layout,container,false);
24 | TextView tv = (TextView)view.findViewById(R.id.fragment_tv);
25 | tv.setBackgroundColor(Color.GRAY);
26 | tv.setText("fragment2");
27 | return view;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/fragment/MyFragment3.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.fragment;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.TextView;
11 |
12 | import com.example.kangzhe.sample.R;
13 |
14 |
15 | /**
16 | * Created by kangzhe on 16/1/17.
17 | */
18 | public class MyFragment3 extends Fragment {
19 |
20 | @Nullable
21 | @Override
22 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
23 | View view = inflater.inflate(R.layout.fragment_layout,container,false);
24 | TextView tv = (TextView)view.findViewById(R.id.fragment_tv);
25 | tv.setBackgroundColor(Color.MAGENTA);
26 | tv.setText("fragment3");
27 | return view;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/view/FooterContainer.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.util.AttributeSet;
6 | import android.widget.FrameLayout;
7 |
8 | import com.zjutkz.powerfulrecyclerview.listener.IFooterView;
9 |
10 |
11 | /**
12 | * Created by kangzhe on 16/1/10.
13 | */
14 | public class FooterContainer extends FrameLayout implements IFooterView {
15 |
16 | public FooterContainer(Context context) {
17 | this(context, null);
18 | }
19 |
20 | public FooterContainer(Context context, AttributeSet attrs) {
21 | this(context, attrs, 0);
22 | }
23 |
24 | public FooterContainer(Context context, AttributeSet attrs, int defStyleAttr) {
25 | super(context, attrs, defStyleAttr);
26 | }
27 |
28 | @Override
29 | public void onShow() {
30 | setBackgroundColor(Color.RED);
31 | }
32 |
33 | @Override
34 | public void onLoadMore() {
35 | setBackgroundColor(Color.YELLOW);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/view/FooterTextView.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.TextView;
6 |
7 | import com.zjutkz.powerfulrecyclerview.listener.IFooterView;
8 |
9 |
10 | /**
11 | * Created by kangzhe on 16/1/10.
12 | */
13 | public class FooterTextView extends TextView implements IFooterView {
14 |
15 | public FooterTextView(Context context) {
16 | this(context, null);
17 | }
18 |
19 | public FooterTextView(Context context, AttributeSet attrs) {
20 | this(context, attrs, 0);
21 | }
22 |
23 | public FooterTextView(Context context, AttributeSet attrs, int defStyleAttr) {
24 | super(context, attrs, defStyleAttr);
25 | }
26 |
27 | @Override
28 | public void onShow() {
29 | setText("完全定制onShow");
30 | }
31 |
32 | @Override
33 | public void onLoadMore() {
34 | setText("完全定制onLoadMore");
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/view/HeaderContainer.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.util.AttributeSet;
6 | import android.widget.FrameLayout;
7 |
8 | import com.zjutkz.powerfulrecyclerview.listener.IHeaderView;
9 |
10 |
11 | /**
12 | * Created by kangzhe on 16/1/4.
13 | */
14 | public class HeaderContainer extends FrameLayout implements IHeaderView {
15 |
16 | public HeaderContainer(Context context) {
17 | this(context, null);
18 | }
19 |
20 | public HeaderContainer(Context context, AttributeSet attrs) {
21 | this(context, attrs, 0);
22 | }
23 |
24 | public HeaderContainer(Context context, AttributeSet attrs, int defStyleAttr) {
25 | super(context, attrs, defStyleAttr);
26 | }
27 |
28 | @Override
29 | public void pullToRefresh() {
30 | setBackgroundColor(Color.RED);
31 | }
32 |
33 | @Override
34 | public void releaseToRefresh() {
35 | setBackgroundColor(Color.BLUE);
36 | }
37 |
38 | @Override
39 | public void onRefresh() {
40 | setBackgroundColor(Color.YELLOW);
41 | }
42 |
43 | @Override
44 | public void onReset(float distance, float fraction) {
45 | }
46 |
47 | @Override
48 | public void onPull(float distance, float fraction) {
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/view/HeaderImageView.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.ImageView;
6 |
7 | import com.zjutkz.powerfulrecyclerview.listener.IHeaderView;
8 | import com.example.kangzhe.sample.R;
9 |
10 |
11 | /**
12 | * Created by kangzhe on 16/1/2.
13 | */
14 | public class HeaderImageView extends ImageView implements IHeaderView {
15 |
16 | public HeaderImageView(Context context) {
17 | this(context, null);
18 | }
19 |
20 | public HeaderImageView(Context context, AttributeSet attrs) {
21 | this(context, attrs, 0);
22 | }
23 |
24 | public HeaderImageView(Context context, AttributeSet attrs, int defStyleAttr) {
25 | super(context, attrs, defStyleAttr);
26 | }
27 |
28 | @Override
29 | public void pullToRefresh() {
30 | setImageDrawable(getContext().getResources().getDrawable(R.drawable.down));
31 | }
32 |
33 | @Override
34 | public void releaseToRefresh() {
35 | setImageDrawable(getContext().getResources().getDrawable(R.drawable.up));
36 | }
37 |
38 | @Override
39 | public void onRefresh() {
40 | setImageDrawable(getContext().getResources().getDrawable(R.mipmap.ic_launcher));
41 | }
42 |
43 | @Override
44 | public void onReset(float distance, float fraction) {
45 |
46 | }
47 |
48 | @Override
49 | public void onPull(float distance, float fraction) {
50 |
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/view/HeaderScaleImageView.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.view;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.ViewCompat;
5 | import android.util.AttributeSet;
6 | import android.widget.ImageView;
7 |
8 | import com.zjutkz.powerfulrecyclerview.listener.IHeaderView;
9 | import com.example.kangzhe.sample.R;
10 |
11 |
12 | /**
13 | * Created by kangzhe on 16/1/2.
14 | */
15 | public class HeaderScaleImageView extends ImageView implements IHeaderView {
16 |
17 | public HeaderScaleImageView(Context context) {
18 | this(context, null);
19 | }
20 |
21 | public HeaderScaleImageView(Context context, AttributeSet attrs) {
22 | this(context, attrs, 0);
23 | }
24 |
25 | public HeaderScaleImageView(Context context, AttributeSet attrs, int defStyleAttr) {
26 | super(context, attrs, defStyleAttr);
27 | setImageDrawable(getContext().getResources().getDrawable(R.mipmap.ic_launcher));
28 | }
29 |
30 | @Override
31 | public void pullToRefresh() {
32 |
33 | }
34 |
35 | @Override
36 | public void releaseToRefresh() {
37 |
38 | }
39 |
40 | @Override
41 | public void onRefresh() {
42 |
43 | }
44 |
45 | @Override
46 | public void onReset(float distance, float fraction) {
47 | ViewCompat.setScaleX(this, fraction);
48 | ViewCompat.setScaleY(this, fraction);
49 | }
50 |
51 | @Override
52 | public void onPull(float distance, float fraction) {
53 | ViewCompat.setScaleX(this, fraction);
54 | ViewCompat.setScaleY(this, fraction);
55 | }
56 | }
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/view/HeaderTextView.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.TextView;
6 |
7 | import com.zjutkz.powerfulrecyclerview.listener.IHeaderView;
8 |
9 |
10 | /**
11 | * Created by kangzhe on 16/1/2.
12 | */
13 | public class HeaderTextView extends TextView implements IHeaderView {
14 |
15 | public HeaderTextView(Context context, AttributeSet attrs, int defStyleAttr) {
16 | super(context, attrs, defStyleAttr);
17 | }
18 |
19 | public HeaderTextView(Context context, AttributeSet attrs) {
20 | this(context, attrs, 0);
21 | }
22 |
23 | public HeaderTextView(Context context) {
24 | this(context, null);
25 | }
26 |
27 | @Override
28 | public void pullToRefresh() {
29 | setText("pull to refresh");
30 | }
31 |
32 | @Override
33 | public void releaseToRefresh() {
34 | setText("release to refresh");
35 | }
36 |
37 | @Override
38 | public void onRefresh() {
39 | setText("on refresh");
40 | }
41 |
42 | @Override
43 | public void onReset(float distance, float fraction) {
44 |
45 | }
46 |
47 | @Override
48 | public void onPull(float distance, float fraction) {
49 |
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/view/HistoryThemeFooterView.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 | import android.view.animation.Animation;
7 | import android.view.animation.RotateAnimation;
8 | import android.widget.ImageView;
9 | import android.widget.LinearLayout;
10 | import android.widget.ProgressBar;
11 | import android.widget.TextView;
12 |
13 | import com.zjutkz.powerfulrecyclerview.listener.IFooterView;
14 | import com.example.kangzhe.sample.R;
15 |
16 |
17 | /**
18 | * Created by kangzhe on 16/2/29.
19 | */
20 | public class HistoryThemeFooterView extends LinearLayout implements IFooterView {
21 |
22 | private static final int ANIMATION_DURATION = 180;
23 |
24 | public static final int ON_SHOW = 1;
25 |
26 | public static final int ON_LOAD_MORE = 2;
27 |
28 | public static final int IDLE = 3;
29 |
30 | private int state = IDLE;
31 |
32 | private ImageView iv;
33 |
34 | private TextView tv;
35 |
36 | private ProgressBar pb;
37 |
38 | private ImageView mImageView;
39 |
40 | private Animation mRotateUpAnim;
41 |
42 | private Animation mRotateDownAnim;
43 |
44 | public HistoryThemeFooterView(Context context) {
45 | this(context, null);
46 | }
47 |
48 | public HistoryThemeFooterView(Context context, AttributeSet attrs) {
49 | this(context, attrs, 0);
50 | }
51 |
52 | public HistoryThemeFooterView(Context context, AttributeSet attrs, int defStyleAttr) {
53 | super(context, attrs, defStyleAttr);
54 |
55 | initAnim();
56 | }
57 |
58 | private void initAnim() {
59 | mRotateUpAnim = new RotateAnimation(0.0f, -180.0f,
60 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
61 | 0.5f);
62 | mRotateUpAnim.setDuration(ANIMATION_DURATION);
63 | mRotateUpAnim.setFillAfter(true);
64 |
65 | mRotateDownAnim = new RotateAnimation(-180.0f, 0.0f,
66 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
67 | 0.5f);
68 | mRotateDownAnim.setDuration(ANIMATION_DURATION);
69 | mRotateDownAnim.setFillAfter(true);
70 | }
71 |
72 | private void initView() {
73 | iv = (ImageView)findViewById(R.id.arrow);
74 |
75 | pb = (ProgressBar)findViewById(R.id.progress);
76 |
77 | tv = (TextView)findViewById(R.id.message);
78 |
79 | mImageView = (ImageView)findViewById(R.id.image);
80 | }
81 |
82 | public void clearImage() {
83 | mImageView.setImageDrawable(null);
84 | mImageView.setVisibility(View.GONE);
85 | }
86 |
87 |
88 | @Override
89 | public void onShow() {
90 | if(state == ON_LOAD_MORE){
91 | iv.startAnimation(mRotateUpAnim);
92 | }
93 |
94 | state = ON_SHOW;
95 |
96 | pb.setVisibility(INVISIBLE);
97 | iv.setVisibility(VISIBLE);
98 |
99 | //tv.setText(activity.hasOldTheme() ? "松开加载下个主题" : "没有下个主题了");
100 | tv.setText("松开加载下个主题");
101 | }
102 |
103 | @Override
104 | public void onLoadMore() {
105 | if(iv == null){
106 | initView();
107 | }
108 |
109 | if(state != IDLE){
110 | iv.clearAnimation();
111 | }
112 |
113 | state = ON_LOAD_MORE;
114 |
115 | pb.setVisibility(VISIBLE);
116 | iv.setVisibility(INVISIBLE);
117 |
118 | tv.setText("正在加载...");
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/example/kangzhe/sample/view/HistoryThemeHeaderView.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample.view;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.animation.Animation;
6 | import android.view.animation.RotateAnimation;
7 | import android.widget.ImageView;
8 | import android.widget.LinearLayout;
9 | import android.widget.ProgressBar;
10 | import android.widget.TextView;
11 |
12 | import com.zjutkz.powerfulrecyclerview.listener.IHeaderView;
13 | import com.example.kangzhe.sample.R;
14 |
15 | /**
16 | * Created by kangzhe on 16/2/29.
17 | */
18 | public class HistoryThemeHeaderView extends LinearLayout implements IHeaderView {
19 |
20 | private static final int ANIMATION_DURATION = 180;
21 |
22 | public static final int PULL_TO_REFRESH = 0;
23 |
24 | public static final int RELEASE_TO_REFRESH = 1;
25 |
26 | public static final int ON_REFRESH = 2;
27 |
28 | public static final int IDLE = 3;
29 |
30 | private int state = IDLE;
31 |
32 | private ImageView iv;
33 |
34 | private TextView tv;
35 |
36 | private ProgressBar pb;
37 |
38 | private ImageView mImageView;
39 |
40 | private Animation mRotateUpAnim;
41 |
42 | private Animation mRotateDownAnim;
43 |
44 | public HistoryThemeHeaderView(Context context) {
45 | this(context, null);
46 | }
47 |
48 | public HistoryThemeHeaderView(Context context, AttributeSet attrs) {
49 | this(context, attrs, 0);
50 | }
51 |
52 | public HistoryThemeHeaderView(Context context, AttributeSet attrs, int defStyleAttr) {
53 | super(context, attrs, defStyleAttr);
54 |
55 | this.post(new Runnable() {
56 | @Override
57 | public void run() {
58 | initView();
59 | }
60 | });
61 |
62 | initAnim();
63 | }
64 |
65 | private void initAnim() {
66 | mRotateUpAnim = new RotateAnimation(0.0f, -180.0f,
67 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
68 | 0.5f);
69 | mRotateUpAnim.setDuration(ANIMATION_DURATION);
70 | mRotateUpAnim.setFillAfter(true);
71 |
72 | mRotateDownAnim = new RotateAnimation(-180.0f, 0.0f,
73 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
74 | 0.5f);
75 | mRotateDownAnim.setDuration(ANIMATION_DURATION);
76 | mRotateDownAnim.setFillAfter(true);
77 | }
78 |
79 | private void initView() {
80 | iv = (ImageView)findViewById(R.id.arrow);
81 |
82 | pb = (ProgressBar)findViewById(R.id.progress);
83 |
84 | tv = (TextView)findViewById(R.id.message);
85 |
86 | mImageView = (ImageView)findViewById(R.id.image);
87 | iv.setImageDrawable(getResources().getDrawable(R.drawable.up));
88 | }
89 |
90 | @Override
91 | public void pullToRefresh() {
92 | if(state == RELEASE_TO_REFRESH){
93 | iv.startAnimation(mRotateDownAnim);
94 | }
95 |
96 | state = PULL_TO_REFRESH;
97 |
98 | pb.setVisibility(INVISIBLE);
99 | iv.setVisibility(VISIBLE);
100 |
101 | tv.setText("下拉查看上个主题");
102 | }
103 |
104 | @Override
105 | public void releaseToRefresh() {
106 | if(state == PULL_TO_REFRESH){
107 | iv.startAnimation(mRotateUpAnim);
108 | }
109 |
110 | state = RELEASE_TO_REFRESH;
111 |
112 | pb.setVisibility(INVISIBLE);
113 | iv.setVisibility(VISIBLE);
114 |
115 | tv.setText("松开加载上个主题");
116 | }
117 |
118 | @Override
119 | public void onRefresh() {
120 | state = ON_REFRESH;
121 |
122 | iv.clearAnimation();
123 |
124 | pb.setVisibility(VISIBLE);
125 | iv.setVisibility(INVISIBLE);
126 |
127 | tv.setText("正在加载...");
128 | }
129 |
130 | @Override
131 | public void onReset(float distance, float fraction) {
132 |
133 | }
134 |
135 | @Override
136 | public void onPull(float distance, float fraction) {
137 |
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/bj_ic_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable-xhdpi/bj_ic_loading.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/bj_theme_top_shadow.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable-xhdpi/bj_theme_top_shadow.9.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/bj_frame_red_white.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
10 |
11 |
13 |
14 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/bj_img_progress.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/down.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/down.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_toc_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/ic_toc_white_24dp.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/img1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/img1.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/img2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/img2.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/img3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/img3.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/img4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/img4.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/img5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/img5.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/img6.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/img6.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/img7.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/img7.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/img8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/img8.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/img9.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/img9.jpg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/load.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/load.jpeg
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/up.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/drawable/up.png
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_horizontal.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
19 |
20 |
25 |
26 |
29 |
30 |
34 |
35 |
40 |
41 |
44 |
45 |
49 |
50 |
55 |
56 |
59 |
60 |
64 |
65 |
70 |
71 |
74 |
75 |
79 |
80 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/big_photo_item_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
23 |
24 |
31 |
32 |
33 |
38 |
39 |
43 |
44 |
50 |
51 |
52 |
53 |
60 |
61 |
64 |
65 |
75 |
76 |
86 |
87 |
88 |
89 |
90 |
98 |
99 |
105 |
106 |
114 |
115 |
116 |
117 |
132 |
133 |
141 |
142 |
149 |
150 |
151 |
152 |
156 |
157 |
158 |
162 |
163 |
164 |
172 |
173 |
174 |
175 |
184 |
185 |
186 |
201 |
202 |
203 |
204 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
238 |
239 |
240 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
19 |
20 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/footer.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/fragment_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/header.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
24 |
25 |
32 |
33 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/history_footer_theme.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
18 |
23 |
27 |
34 |
35 |
38 |
39 |
45 |
46 |
52 |
53 |
54 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/history_header_theme.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
18 |
19 |
24 |
29 |
39 |
46 |
47 |
50 |
51 |
57 |
58 |
64 |
65 |
66 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/list_header_viewpager.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/new_grid_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/new_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
22 |
23 |
30 |
31 |
32 |
37 |
38 |
42 |
43 |
49 |
50 |
51 |
52 |
59 |
60 |
63 |
64 |
74 |
75 |
85 |
86 |
87 |
88 |
89 |
97 |
98 |
104 |
105 |
113 |
114 |
115 |
116 |
131 |
132 |
140 |
141 |
148 |
149 |
150 |
151 |
155 |
156 |
157 |
161 |
162 |
163 |
171 |
172 |
173 |
174 |
183 |
184 |
185 |
200 |
201 |
202 |
203 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
237 |
238 |
244 |
245 |
246 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/no_network_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/recycler_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
26 |
27 |
28 |
29 |
37 |
38 |
39 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/recycler_footer.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/recycler_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/server_error_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
20 |
21 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/simple_ptr_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
17 |
18 |
19 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/staggered_item.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
24 |
25 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/swip_refresh_recycler_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
20 |
21 |
22 |
34 |
35 |
36 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/zjutkz/PowerfulRecyclerView/429d07ba804379ae1e2bcd6bdafed00c70122ec9/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #D7CCC8
7 |
8 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | app
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
24 |
25 |
30 |
31 |
35 |
36 |
40 |
41 |
44 |
45 |
48 |
49 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/sample/src/test/java/com/example/kangzhe/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.kangzhe.sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':powerfulrecyclerviewlib', ':sample'
2 |
--------------------------------------------------------------------------------