├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── sad_face.png
│ │ │ │ └── broken_link.png
│ │ │ ├── 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
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── layout
│ │ │ │ ├── ad_slot_view.xml
│ │ │ │ ├── content_main.xml
│ │ │ │ ├── state_view.xml
│ │ │ │ ├── item_view.xml
│ │ │ │ └── activity_main.xml
│ │ │ └── menu
│ │ │ │ └── menu_main.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── jc
│ │ │ │ └── myrecyclerview
│ │ │ │ ├── GlideImageLoader.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── jc
│ │ │ └── myrecyclerview
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── jc
│ │ └── myrecyclerview
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── jcRecyclerView
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ └── strings.xml
│ │ │ └── layout
│ │ │ │ └── bottom_view.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── jc
│ │ │ └── JCRecyclerView.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── jc
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── jc
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── demo.apk
├── lifx.apk
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
├── gradlew
└── host.gradle
/.idea/.name:
--------------------------------------------------------------------------------
1 | MyRecyclerView
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/jcRecyclerView/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':jcRecyclerView'
2 |
--------------------------------------------------------------------------------
/demo.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/JCRecyclerView/HEAD/demo.apk
--------------------------------------------------------------------------------
/lifx.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/JCRecyclerView/HEAD/lifx.apk
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/JCRecyclerView/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/jcRecyclerView/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | JCRecyclerView
3 |
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/sad_face.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/JCRecyclerView/HEAD/app/src/main/res/drawable/sad_face.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/broken_link.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/JCRecyclerView/HEAD/app/src/main/res/drawable/broken_link.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/JCRecyclerView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/JCRecyclerView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/JCRecyclerView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/JCRecyclerView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/githubhaohao/JCRecyclerView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #8BC34A
4 | #689F38
5 | #CDDC39
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 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.8-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/jcRecyclerView/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/jcRecyclerView/src/main/res/layout/bottom_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
--------------------------------------------------------------------------------
/jcRecyclerView/src/test/java/com/jc/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.jc;
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 | }
--------------------------------------------------------------------------------
/app/src/test/java/com/jc/myrecyclerview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.jc.myrecyclerview;
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 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/ad_slot_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
--------------------------------------------------------------------------------
/jcRecyclerView/src/androidTest/java/com/jc/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.jc;
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 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/jc/myrecyclerview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.jc.myrecyclerview;
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 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MyRecyclerView
3 | Settings
4 | What if, instead of having to declare an anonymous class every time we need to
5 | implement a click listener, we could just define what we want to do?
6 | We can add new functions to any class. It’s a much more readable substitute to the usual utility classes we all have in our projects.
7 |
8 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jc/myrecyclerview/GlideImageLoader.java:
--------------------------------------------------------------------------------
1 | package com.jc.myrecyclerview;
2 |
3 | import android.content.Context;
4 | import android.widget.ImageView;
5 |
6 | import com.bumptech.glide.Glide;
7 | import com.youth.banner.loader.ImageLoader;
8 |
9 | /**
10 | * Created by HaohaoChang on 2017/4/10.
11 | */
12 | public class GlideImageLoader extends ImageLoader {
13 | @Override
14 | public void displayImage(Context context, Object path, ImageView imageView) {
15 | Glide.with(context).load(path).into(imageView);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/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 K:\AndroidSDK/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 |
--------------------------------------------------------------------------------
/jcRecyclerView/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 K:\AndroidSDK/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 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # JCRecyclerView
2 | [APK](https://github.com/githubhaohao/JCRecyclerView/blob/master/demo.apk)
3 |
4 | 一个针对 RecyclerView 的极简的加载刷新库。
5 |
6 | 极简主要体现在对 RecyclerView 进行简单的封装,与 SwipeRefreshLayout 组合使用可以无缝显示加载、刷新的(异常和失败)状态,具有很强的灵活性和实用性,并且不改变 RecyclerView 原有的特性。
7 |
8 | JCRecyclerView 具备 RecyclerView 的所有特性。
9 |
10 | ## 效果展示
11 |
12 | 
13 | 
14 |
15 | ## 用法
16 |
17 | 基本用法与 RecyclerView 相同。
18 | [sample](https://github.com/githubhaohao/JCRecyclerView/blob/master/app/src/main/java/com/jc/myrecyclerview/MainActivity.java)
19 |
20 | ## TBD
21 | - [x] 可自定义 Load View
22 | - [ ] 可自定义 Refresh View
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/jcRecyclerView/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 19
9 | targetSdkVersion 25
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:appcompat-v7:25.3.1'
25 | compile 'com.android.support:recyclerview-v7:25.3.1'
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.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 |
23 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/state_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.jc.myrecyclerview"
9 | minSdkVersion 19
10 | targetSdkVersion 25
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(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:25.3.1'
26 | compile 'com.android.support:design:25.3.1'
27 | compile 'com.android.support:cardview-v7:25.3.1'
28 |
29 | // state layout
30 | compile 'com.github.fingdo:stateLayout:1.0.2'
31 | // banner
32 | compile 'com.youth.banner:banner:1.4.9'
33 | // glide
34 | compile "com.github.bumptech.glide:glide:3.7.0"
35 | compile project(':jcRecyclerView')
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
15 |
24 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/jc/myrecyclerview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.jc.myrecyclerview;
2 |
3 | import android.os.Bundle;
4 | import android.os.Handler;
5 | import android.support.design.widget.FloatingActionButton;
6 | import android.support.design.widget.Snackbar;
7 | import android.support.v4.widget.SwipeRefreshLayout;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.DefaultItemAnimator;
10 | import android.support.v7.widget.GridLayoutManager;
11 | import android.support.v7.widget.LinearLayoutManager;
12 | import android.support.v7.widget.RecyclerView;
13 | import android.support.v7.widget.StaggeredGridLayoutManager;
14 | import android.support.v7.widget.Toolbar;
15 | import android.util.Log;
16 | import android.view.LayoutInflater;
17 | import android.view.View;
18 | import android.view.Menu;
19 | import android.view.MenuItem;
20 | import android.view.ViewGroup;
21 | import android.widget.TextView;
22 |
23 | import com.fingdo.statelayout.StateLayout;
24 | import com.jc.JCRecyclerView;
25 | import com.youth.banner.Banner;
26 |
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 | public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener{
31 |
32 | private JCRecyclerView jcRecyclerView;
33 | private MyAdapter adapter;
34 | private ViewGroup adslotView,stateView, bottomView;
35 | private SwipeRefreshLayout refreshLayout;
36 | private Handler handler;
37 | private StateLayout stateLayout;
38 | private String[] images = {
39 | "https://github.com/githubhaohao/ImageRoom/blob/master/Images/img1.jpg?raw=true",
40 | "https://github.com/githubhaohao/ImageRoom/blob/master/Images/img2.jpg?raw=true",
41 | "https://github.com/githubhaohao/ImageRoom/blob/master/Images/img3.jpg?raw=true",
42 | "https://github.com/githubhaohao/ImageRoom/blob/master/Images/img4.jpg?raw=true",
43 | "https://github.com/githubhaohao/ImageRoom/blob/master/Images/img5.jpg?raw=true",
44 | "https://github.com/githubhaohao/ImageRoom/blob/master/Images/img6.jpg?raw=true",
45 | "https://github.com/githubhaohao/ImageRoom/blob/master/Images/img7.jpg?raw=true"
46 | };
47 | private Banner banner;
48 |
49 | @Override
50 | protected void onCreate(Bundle savedInstanceState) {
51 | super.onCreate(savedInstanceState);
52 | setContentView(R.layout.activity_main);
53 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
54 | setSupportActionBar(toolbar);
55 |
56 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
57 | fab.setOnClickListener(new View.OnClickListener() {
58 | @Override
59 | public void onClick(View view) {
60 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
61 | .setAction("Action", null).show();
62 | }
63 | });
64 |
65 | jcRecyclerView = (JCRecyclerView) findViewById(R.id.jc_recycler_view);
66 | refreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
67 |
68 | refreshLayout.setColorSchemeResources(android.R.color.holo_orange_dark,android.R.color.holo_purple);
69 |
70 | GridLayoutManager layoutManager = new GridLayoutManager(this,2);
71 | StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(4,StaggeredGridLayoutManager.VERTICAL);
72 | jcRecyclerView.setLayoutManager(layoutManager);
73 |
74 | adslotView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.ad_slot_view, (ViewGroup) findViewById(android.R.id.content), false);
75 | stateView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.state_view, (ViewGroup) findViewById(android.R.id.content), false);
76 | bottomView = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.bottom_view, (ViewGroup) findViewById(android.R.id.content), false);
77 |
78 | stateLayout = (StateLayout) stateView.findViewById(R.id.state_layout);
79 | stateLayout.setUseAnimation(true);
80 |
81 | //广告位
82 | initBanner();
83 |
84 | jcRecyclerView.setAdSlotView(adslotView);
85 | jcRecyclerView.setBottomView(bottomView);
86 |
87 | adapter = new MyAdapter(getData());
88 |
89 | jcRecyclerView.setItemAnimator(new DefaultItemAnimator());
90 | jcRecyclerView.setAdapter(adapter);
91 | refreshLayout.setOnRefreshListener(this);
92 |
93 | handler = new Handler();
94 |
95 | jcRecyclerView.addOnLoadMoreListener(new JCRecyclerView.OnLoadMoreListener() {
96 | @Override
97 | public void onLoadMore() {
98 | handler.postDelayed(new Runnable() {
99 | @Override
100 | public void run() {
101 | jcRecyclerView.setLoading(false);
102 | adapter.addItem(getString(R.string.new_item));
103 | }
104 | },2000);
105 |
106 | }
107 | });
108 |
109 |
110 | }
111 |
112 | private void initBanner() {
113 | banner = (Banner) adslotView.findViewById(R.id.banner);
114 | banner.setImageLoader(new GlideImageLoader());
115 | List imageArr = new ArrayList<>();
116 | for (String uri : images) {
117 | imageArr.add(uri);
118 | }
119 | banner.setImages(imageArr);
120 | banner.start();
121 | }
122 |
123 | private List getData() {
124 | List data = new ArrayList<>();
125 | for (int i = 0; i < 20; i++) {
126 | data.add(getString(R.string.item_string));
127 | }
128 |
129 | return data;
130 | }
131 |
132 | @Override
133 | public boolean onCreateOptionsMenu(Menu menu) {
134 | // Inflate the menu; this adds items to the action bar if it is present.
135 | getMenuInflater().inflate(R.menu.menu_main, menu);
136 | return true;
137 | }
138 |
139 | @Override
140 | public boolean onOptionsItemSelected(MenuItem item) {
141 | // Handle action bar item clicks here. The action bar will
142 | // automatically handle clicks on the Home/Up button, so long
143 | // as you specify a parent activity in AndroidManifest.xml.
144 | int id = item.getItemId();
145 |
146 | //noinspection SimplifiableIfStatement
147 | if (id == R.id.add_adslot_view) {
148 | jcRecyclerView.setAdSlotView(adslotView);
149 | } else if (id == R.id.add_state_view) {
150 | adapter.clear();
151 | jcRecyclerView.setStateView(stateView);
152 | stateLayout.showErrorView("数据加载异常");
153 |
154 | } else if (id == R.id.remove_adslot_view) {
155 | jcRecyclerView.removeAdSlotView();
156 |
157 | } else if (id == R.id.remove_state_view) {
158 | jcRecyclerView.removeStateView();
159 | adapter.updateData(getData());
160 | } else if (id == R.id.change_state_view) {
161 | stateLayout.showNoNetworkView("网络发生异常");
162 |
163 | }
164 |
165 | return super.onOptionsItemSelected(item);
166 | }
167 |
168 | @Override
169 | public void onRefresh() {
170 | new Handler().postDelayed(new Runnable() {
171 | @Override
172 | public void run() {
173 | adapter.clear();
174 | adapter.updateData(getData());
175 | refreshLayout.setRefreshing(false);
176 | }
177 | },2000);
178 | }
179 |
180 | private class MyAdapter extends RecyclerView.Adapter {
181 |
182 | private List data;
183 |
184 | public MyAdapter(List data) {
185 | this.data = data;
186 | }
187 |
188 | @Override
189 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
190 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_view,parent,false);
191 | return new MyViewHolder(view);
192 | }
193 |
194 | @Override
195 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
196 | ((MyViewHolder) holder).textView.setText(data.get(position));
197 | }
198 |
199 | @Override
200 | public int getItemCount() {
201 | return data.size();
202 | }
203 |
204 | public void clear() {
205 | this.data.clear();
206 | notifyDataSetChanged();
207 | }
208 |
209 | public void updateData(List data) {
210 | this.data = data;
211 | notifyDataSetChanged();
212 |
213 | }
214 |
215 | public void addItem(String item) {
216 | data.add(item);
217 | notifyItemInserted(getItemCount() - 1);
218 | }
219 |
220 | class MyViewHolder extends RecyclerView.ViewHolder {
221 | TextView textView;
222 |
223 | public MyViewHolder(View itemView) {
224 | super(itemView);
225 | textView = (TextView) itemView.findViewById(R.id.text);
226 | }
227 | }
228 | }
229 | }
230 |
--------------------------------------------------------------------------------
/jcRecyclerView/src/main/java/com/jc/JCRecyclerView.java:
--------------------------------------------------------------------------------
1 | package com.jc;
2 |
3 | import android.content.Context;
4 | import android.graphics.Rect;
5 | import android.support.v7.widget.GridLayoutManager;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.StaggeredGridLayoutManager;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.LinearLayout;
13 | import android.widget.Toast;
14 |
15 | /**
16 | * Created by HaohaoChang on 2017/4/10.
17 | */
18 | public class JCRecyclerView extends RecyclerView {
19 |
20 | private static final String TAG = JCRecyclerView.class.getSimpleName();
21 | private LayoutManager layoutManager;
22 | private ViewGroup adSlotView;
23 | private ViewGroup stateView;
24 | private ViewGroup bottomView;
25 | private boolean isLoading = false;
26 | private JCAdapter jcAdapter;
27 | private OnLoadMoreListener onLoadMoreListener;
28 |
29 | public void addOnLoadMoreListener(OnLoadMoreListener listener) {
30 | this.onLoadMoreListener = listener;
31 | this.addOnScrollListener(new OnScrollListener() {
32 | @Override
33 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
34 | if (recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
35 | StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) recyclerView.getLayoutManager();
36 | int totalItemCount = recyclerView.getAdapter().getItemCount();
37 | int[] lastVisibleItemPositions = new int[layoutManager.getSpanCount()];
38 | layoutManager.findLastVisibleItemPositions(lastVisibleItemPositions);
39 | int visibleItemCount = recyclerView.getChildCount();
40 | int lastVisibleItemPosition = findMaxPosition(lastVisibleItemPositions);
41 |
42 | if (newState == RecyclerView.SCROLL_STATE_IDLE
43 | && lastVisibleItemPosition == totalItemCount - 1
44 | && visibleItemCount > 0) {
45 | if (bottomView == null || isLoading || stateView != null) return;
46 |
47 | isLoading = true;
48 | jcAdapter.notifyDataSetChanged();
49 | onLoadMoreListener.onLoadMore();
50 | scrollToPosition(jcAdapter.getItemCount() - 1);
51 | }
52 | } else {
53 | LinearLayoutManager lm = (LinearLayoutManager) recyclerView.getLayoutManager();
54 | int totalItemCount = recyclerView.getAdapter().getItemCount();
55 | int lastVisibleItemPosition = lm.findLastVisibleItemPosition();
56 | int visibleItemCount = recyclerView.getChildCount();
57 |
58 | if (newState == RecyclerView.SCROLL_STATE_IDLE
59 | && lastVisibleItemPosition == totalItemCount - 1
60 | && visibleItemCount > 0) {
61 | if (bottomView == null || isLoading || stateView != null) return;
62 |
63 | isLoading = true;
64 | jcAdapter.notifyDataSetChanged();
65 | onLoadMoreListener.onLoadMore();
66 | scrollToPosition(jcAdapter.getItemCount() - 1);
67 | }
68 |
69 | }
70 |
71 | }
72 | });
73 |
74 | }
75 |
76 | private int findMaxPosition(int[] positions) {
77 | int max = positions[0];
78 | for (int index = 1; index < positions.length; index++) {
79 | if (positions[index] > max) {
80 | max = positions[index];
81 | }
82 | }
83 | return max;
84 | }
85 |
86 | public void setBottomView(ViewGroup view) {
87 | if (bottomView == null) {
88 | this.bottomView = view;
89 | }
90 |
91 | }
92 |
93 | public void setLoading(boolean flag) {
94 | if (!flag) {
95 | isLoading = false;
96 | jcAdapter.notifyDataSetChanged();
97 | scrollToPosition(jcAdapter.getItemCount() - 1);
98 | }
99 |
100 | }
101 |
102 | public void setAdSlotView(ViewGroup view) {
103 | if (adSlotView == null) {
104 | adSlotView = view;
105 | if (jcAdapter != null) {
106 | jcAdapter.notifyItemInserted(0);
107 | scrollToPosition(0);
108 | }
109 | }
110 | }
111 |
112 | public void setStateView(ViewGroup view) {
113 | if (stateView != null) return;
114 | if (view == null) return;
115 | if (adSlotView != null) {
116 | scrollToPosition(0);
117 | stateView = view;
118 | Rect rect = new Rect();
119 | getGlobalVisibleRect(rect);
120 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, rect.bottom - rect.top - adSlotView.getHeight());
121 | adSlotView.addView(stateView, layoutParams);
122 | } else {
123 | showToast("You should set the ad-slot view at first.");
124 | }
125 | }
126 |
127 | public void removeAdSlotView() {
128 | if (adSlotView != null && jcAdapter != null) {
129 | adSlotView = null;
130 | jcAdapter.notifyItemRemoved(0);
131 | }
132 | }
133 |
134 | public void removeStateView() {
135 | if (adSlotView != null && stateView != null && jcAdapter != null) {
136 | adSlotView.removeView(stateView);
137 | stateView = null;
138 | }
139 | }
140 |
141 | @Override
142 | public void setAdapter(Adapter adapter) {
143 | this.jcAdapter = new JCAdapter(adapter);
144 | super.setAdapter(this.jcAdapter);
145 | }
146 |
147 | public JCRecyclerView(Context context, AttributeSet attrs) {
148 | super(context, attrs);
149 | }
150 |
151 | @Override
152 | public void setLayoutManager(LayoutManager layoutManager) {
153 | this.layoutManager = layoutManager;
154 | super.setLayoutManager(layoutManager);
155 | }
156 |
157 | private class JCAdapter extends RecyclerView.Adapter {
158 |
159 | private RecyclerView.Adapter adapter;
160 |
161 | private static final int TYPE_ADSLOT = 0x10;
162 | private static final int TYPE_NORMAL = 0x11;
163 | private static final int TYPE_BOTTOM = 0x12;
164 |
165 | public JCAdapter(RecyclerView.Adapter adapter) {
166 | this.adapter = adapter;
167 | }
168 |
169 | @Override
170 | public void onViewAttachedToWindow(ViewHolder holder) {
171 | super.onViewAttachedToWindow(holder);
172 | ViewGroup.LayoutParams layoutParams = holder.itemView.getLayoutParams();
173 | if(layoutParams != null){
174 | if(adSlotView != null) {
175 | if(layoutParams instanceof StaggeredGridLayoutManager.LayoutParams && holder.getLayoutPosition() == 0){
176 | StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) layoutParams;
177 | p.setFullSpan(true);
178 | }
179 | }
180 | if (bottomView != null && isLoading) {
181 | if(layoutParams instanceof StaggeredGridLayoutManager.LayoutParams && holder.getLayoutPosition() == getItemCount() - 1){
182 | StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) layoutParams;
183 | p.setFullSpan(true);
184 | }
185 | }
186 |
187 | }
188 |
189 | if (layoutManager instanceof GridLayoutManager) {
190 | final GridLayoutManager gridManager = ((GridLayoutManager)
191 | layoutManager);
192 | gridManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
193 | @Override
194 | public int getSpanSize(int position) {
195 | boolean spanResult = false;
196 | if(adSlotView != null && bottomView != null) {
197 | if (isLoading) {
198 | spanResult = (position == 0 || position == getItemCount() - 1);
199 | } else {
200 | spanResult = (position == 0);
201 | }
202 | } else if (adSlotView != null) {
203 | spanResult = (position==0);
204 | } else if (bottomView != null && isLoading) {
205 | spanResult = (position == getItemCount() - 1);
206 | }
207 |
208 | return spanResult
209 | ? gridManager.getSpanCount():1;
210 | }
211 | });
212 | }
213 | }
214 |
215 | @Override
216 |
217 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
218 | if (viewType == TYPE_ADSLOT) {
219 | return new JCViewHolder(adSlotView);
220 | } else if (viewType == TYPE_BOTTOM) {
221 | return new JCViewHolder(bottomView);
222 | }
223 |
224 | return adapter.onCreateViewHolder(parent,viewType);
225 | }
226 |
227 | @Override
228 | public void onBindViewHolder(ViewHolder holder, int position) {
229 | if (getItemViewType(0) == TYPE_ADSLOT) {
230 | if (position == 0) return;
231 | int newPosition = --position;
232 | if (adapter != null) {
233 | if (newPosition < adapter.getItemCount()) {
234 | adapter.onBindViewHolder(holder, newPosition);
235 | }
236 | }
237 | return;
238 | } else if (getItemViewType(position) == TYPE_BOTTOM) {
239 | return;
240 | }
241 | adapter.onBindViewHolder(holder, position);
242 |
243 | }
244 |
245 | @Override
246 | public int getItemCount() {
247 | int count = adapter.getItemCount();
248 | if (adSlotView != null) {
249 | count ++;
250 | }
251 |
252 | if (bottomView != null && isLoading) {
253 | count ++;
254 | }
255 | return count;
256 | }
257 |
258 | @Override
259 | public int getItemViewType(int position) {
260 | if (position == 0) {
261 | return adSlotView == null ? TYPE_NORMAL : TYPE_ADSLOT;
262 | } else if (position == getItemCount() - 1 && isLoading) {
263 | return bottomView == null ? TYPE_NORMAL : TYPE_BOTTOM;
264 | } else {
265 | return TYPE_NORMAL;
266 | }
267 | }
268 | }
269 |
270 | private class JCViewHolder extends RecyclerView.ViewHolder {
271 |
272 | public JCViewHolder(View itemView) {
273 | super(itemView);
274 | }
275 | }
276 |
277 | private void showToast(String msg) {
278 | Toast.makeText(getContext(),msg,Toast.LENGTH_SHORT).show();
279 |
280 | }
281 |
282 | public interface OnLoadMoreListener {
283 | void onLoadMore();
284 | }
285 | }
286 |
--------------------------------------------------------------------------------
/host.gradle:
--------------------------------------------------------------------------------
1 | import org.xml.sax.Attributes
2 | import org.xml.sax.SAXException
3 | import org.xml.sax.helpers.DefaultHandler
4 |
5 | import javax.xml.parsers.ParserConfigurationException
6 | import javax.xml.parsers.SAXParser
7 | import javax.xml.parsers.SAXParserFactory
8 | import java.util.jar.JarEntry
9 | import java.util.jar.JarOutputStream
10 | import java.util.regex.Pattern
11 | import java.util.zip.ZipEntry
12 | import java.util.zip.ZipInputStream
13 | ////////////////////////////////////////////////////////////////
14 | ////////////////////////////////////////////////////////////////
15 | ////////////////////////////////////////////////////////////////
16 | //在宿主脚本中apply此脚本, 此脚本一共做了6件事
17 | //1、编译完成后导出所有资源id,即aaptOptions.additionalParameters这个配置干的事情, 下面第4步需要此文件
18 | //2、编译宿主资源时插入public.xml,用来控制宿主资源id分组
19 | //3、编译宿主资源编译完成后导出后缀为.ap_的资源包,此资源包在编译非独立插件时需要此包
20 | //4、编译完成后根据资源中间文件以及导出的资源id表生成一份主题patch包,编译非独立插件时需要此包
21 | //5、编译完成后导出宿主的jar,包括宿主的src和其依赖的所有class, 编译非独立插件时需要此包
22 | //6、编译完成后导出宿主混淆后的jar,包括宿主的src和其依赖的所有class, 编译非独立插件时若插件需要混淆则需要此包
23 | ////////////////////////////////////////////////////////////////
24 | ////////////////////////////////////////////////////////////////
25 | ////////////////////////////////////////////////////////////////
26 |
27 | //getProperties()会从ext {} 配置下取值
28 | def hasExtPluginProcessName = getProperties().containsKey("pluginProcess")
29 | def pluginProcessName = getProperties().get("pluginProcess")
30 |
31 | //第1件事
32 | android.aaptOptions.additionalParameters("-P", project.buildDir.absolutePath + "/outputs/generated_exported_all_resouces.xml")
33 |
34 | afterEvaluate {
35 |
36 | for (variant in android.applicationVariants) {
37 | def scope = variant.getVariantData().getScope()
38 | String mergeTaskName = scope.getMergeResourcesTask().name
39 | def mergeTask = tasks.getByName(mergeTaskName)
40 | //第2件事
41 | mergeTask.doLast {
42 | String destPath = mergeTask.outputDir.absolutePath + '/values/';
43 | if (buildscript.sourceFile != null) {
44 | println '编译宿主资源时插入' + buildscript.sourceFile.getParentFile().absolutePath + '/public.xml 到' + destPath + ', 用来控制宿主资源id分组'
45 | copy {
46 | from(buildscript.sourceFile.getParentFile()) {
47 | include 'public.xml'
48 | }
49 | into(destPath)
50 | }
51 | } else {
52 | String url = buildscript.sourceURI.toString().replaceFirst("[a-zA-Z\\.]*\$", "public.xml")
53 | println '编译宿主资源时插入' + url + ' 到' + destPath + ', 用来控制宿主资源id分组'
54 | HttpURLConnection httpConn =(HttpURLConnection)(new URL(url).openConnection())
55 | InputStream inputStream = httpConn.getInputStream()
56 | OutputStream ouput =new FileOutputStream(new File(destPath, "public.xml"))
57 | byte[] buffer = new byte[8*1024]
58 | int size = -1
59 | while((size = inputStream.read(buffer)) != -1) {
60 | ouput.write(buffer, 0, size)
61 | }
62 | ouput.close()
63 | httpConn.disconnect()
64 | }
65 | }
66 |
67 | //def buildTypeName = variant.buildType.name
68 | def varDirName = variant.dirName
69 |
70 | //第3件事
71 | for (baseVariant in variant.outputs) {
72 |
73 | def manifestFilePath = baseVariant.processResources.manifestFile.absolutePath;
74 | def tastName = baseVariant.processResources.name
75 |
76 | baseVariant.processManifest.doLast {
77 |
78 | File manifestFile = new File(manifestFilePath)
79 |
80 | println '正在检查Manifest中的插件配置是否正确' + manifestFilePath
81 |
82 | def originManifestContent = manifestFile.getText('UTF-8')
83 | if (originManifestContent.contains("{applicationId}")) {
84 | throw new Exception("宿主build.gradle未配置android.defaultConfig.applicationId")
85 | }
86 |
87 | def pattern = Pattern.compile("versionName\\s*=\\s*\"(.+?)\"");
88 | def matcher = pattern.matcher(originManifestContent);
89 | if (matcher.find()) {
90 | def versionName = matcher.group(1)
91 | //File hostInfo = new File("${project.buildDir}/outputs/HostInfo-" + tastName.replace("process","").replace("Resources", "") + ".prop")
92 | //没有单独命名,有多个favor时文件会覆盖
93 | File hostInfo = new File("${project.buildDir}/outputs/HostInfo.prop")
94 | if (hostInfo.exists()) {
95 | hostInfo.delete()
96 | }
97 | println '正在生成文件' + hostInfo.absolutePath
98 | hostInfo.write("#Manifest CREATED AT " + new Date().format("yyyy-MM-dd HH:mm::ss"))
99 | hostInfo.append("\nhost.versoinCode=" + android.defaultConfig.versionCode)
100 | //versionName可能有后缀,所以以Manifest中为准
101 | hostInfo.append("\nhost.versionName=" + versionName)
102 | }
103 |
104 | //指定插件进程名,设置为空串或者null即是和宿主同进程
105 | //不设置即使用默认进程(:plugin)
106 | if (hasExtPluginProcessName) {
107 | def customPluginProcessName = "";
108 | if (pluginProcessName != null) {
109 | customPluginProcessName = "android:process=\"" + pluginProcessName + "\""
110 | }
111 | def modifyedManifestContent = originManifestContent.replaceAll("android:process=\":plugin\"", customPluginProcessName)
112 | manifestFile.write(modifyedManifestContent, 'UTF-8')
113 | baseVariant.processResources.manifestFile = manifestFile
114 | }
115 | }
116 |
117 | def processResourcesTask = baseVariant.getProcessResources();
118 | processResourcesTask.doLast {
119 | println '编译宿主资源编译完成后导出后缀为.ap_的资源包,此资源包在编译非独立插件时需要此包'
120 | copy {
121 | from processResourcesTask.packageOutputFile
122 | into("${project.buildDir}/outputs/")
123 | rename('resources', project.name + "-resources")
124 | }
125 | }
126 | }
127 |
128 | //第5件事
129 | def org.gradle.api.tasks.compile.JavaCompile javaCompile = variant.javaCompile;
130 | def String buildType = variant.buildType.name
131 |
132 | javaCompile.doLast {
133 |
134 | def flavorBuildType = javaCompile.name.replace("compile", "").replace("JavaWithJavac", "");
135 | def flavor = flavorBuildType.toLowerCase().replace(buildType, "")
136 | println "Merge Jar After Task " + javaCompile.name + " buildType is " + buildType
137 |
138 | File jarFile = new File(project.buildDir, "outputs/" + project.name + "-" + flavorBuildType + ".jar")
139 | if (jarFile.exists()) {
140 | jarFile.delete()
141 | }
142 |
143 | JarMerger jarMerger = new JarMerger(jarFile)
144 | try {
145 | jarMerger.setFilter(new JarFilter() {
146 | public boolean checkEntry(String archivePath) throws JarFilter.ZipAbortException {
147 | if (archivePath.endsWith(".class")) {
148 | return true
149 | }
150 | return false
151 | }
152 | });
153 |
154 | javaCompile.classpath.each { jarPath ->
155 | jarMerger.addJar(jarPath);
156 | //jarMerger.addFolder(directoryInput.getFile());
157 | }
158 | File classes = new File(buildDir, 'intermediates/packaged/' + (flavor.equals("")?"":(flavor + "/")) + buildType + "/classes.jar");
159 |
160 | println "classes path is " + classes.absolutePath
161 |
162 | if (!classes.exists()) {
163 | try {
164 | tasks.getByName("jar" + flavorBuildType + "Classes").execute()
165 | } catch(Exception e) {
166 | println "fail to create jar for task " + javaCompile.name
167 | }
168 | } else {
169 | println "classes path not exist " + classes.absolutePath
170 | }
171 | if (classes.exists()) {
172 | jarMerger.addJar(classes)
173 | }
174 | } catch (Exception e) {
175 | e.printStackTrace()
176 | } finally {
177 | jarMerger.close()
178 | }
179 |
180 | println "Merge Jar Finished, Jar is at " + jarFile.absolutePath
181 | }
182 |
183 | //处理混淆,这里保存混淆以后dex之前的jar包作为基线包备用
184 | def proguardTask = project.tasks.findByName("transformClassesAndResourcesWithProguardFor${variant.name.capitalize()}")
185 | def variantName = variant.name
186 | if (proguardTask) {
187 | proguardTask.doFirst {
188 | println "开始混淆任务" + variantName.capitalize()
189 | }
190 | proguardTask.doLast {
191 | println "混淆完成" + variantName.capitalize()
192 | boolean isFind = false;
193 | proguardTask.outputs.files.files.each { File file->
194 | //http://blog.csdn.net/sbsujjbcy/article/details/50839263
195 | //build/intermediates/transforms/proguard/anzhi/release/jars/3/1f/main.jar
196 | project.logger.error "file outputs=>${file.absolutePath}"
197 | String keyword = File.separator + "transforms" + File.separator + "proguard" + File.separator;
198 | println String.valueOf(file.absolutePath.contains(keyword)) + ", " + String.valueOf(file.absolutePath.endsWith(buildType))
199 | if (file.absolutePath.contains(keyword) && file.absolutePath.endsWith(buildType)) {
200 |
201 | isFind = true;
202 | println "导出混淆后的宿主jar包" + "${project.buildDir}/outputs/" + "host_" + variantName + "_obfuscated" + ".jar"
203 |
204 | copy {
205 | from file.absolutePath + "/jars/3/1f/main.jar"
206 | into("${project.buildDir}/outputs/")
207 | rename('main', "host_" + variantName + "_obfuscated")
208 | }
209 | }
210 | }
211 | if (!isFind) {
212 | throw "obfuscated jar file not found, please check."
213 | }
214 | }
215 | }
216 |
217 | }
218 |
219 | tasks.each { task ->
220 | if (task.name.startsWith("generate") && task.name.endsWith("Sources") && !task.name.contains("AndroidTest")) {
221 | task.doFirst {
222 | def buildFavType = task.name.replace("generate", "").replace("Sources", "")
223 | println '编译宿主ap完成后根据资源中间文件以及导出的资源id表生成一份主题patch包,编译非独立插件时需要此包 buildFavType = ' + buildFavType
224 |
225 | //脚本不熟,将就用吧。。。
226 | if (buildFavType.endsWith("Debug")) {
227 | createThemePatch(buildFavType.replace("Debug", "").toLowerCase(), "debug");
228 | } else if (buildFavType.endsWith("Release")) {
229 | createThemePatch(buildFavType.replace("Release", "").toLowerCase(), "release");
230 | }
231 | }
232 | }
233 | }
234 |
235 | if (gradle.startParameter.taskNames.find {
236 | println ">>>>>>执行命令: " + it
237 | it.startsWith("assemble") || it.startsWith("build")
238 | } != null) {
239 | //nothing
240 | }
241 | }
242 |
243 | //导出主题patch
244 | def createThemePatch(String flavor, String buildType) {
245 |
246 | File patchDir = new File(project.buildDir.absolutePath + "/outputs/theme_patch/" + buildType);
247 | patchDir.mkdirs();
248 |
249 | File generatedRes = new File(project.buildDir.absolutePath + "/outputs/generated_exported_all_resouces.xml");
250 | File dest = new File(patchDir, "patch_theme.xml")
251 |
252 | println "export from " + generatedRes + " to " + dest
253 |
254 | if (!generatedRes.exists()) {
255 | throw new FileNotFoundException("File Not Found : " + generatedRes.absolutePath)
256 | }
257 |
258 | def packageName = android.defaultConfig.applicationId
259 | if (android.buildTypes[buildType].applicationIdSuffix != null) {
260 | packageName = packageName + android.buildTypes[buildType].applicationIdSuffix;
261 | }
262 |
263 | ThemeProcessor.exportThemeStyle(generatedRes, dest, packageName)
264 |
265 | String mergedResDir = "${project.buildDir}/intermediates/res/merged/" + (flavor.equals("")?"":(flavor + "/")) + buildType + "/";
266 | FileTree allxmlFiles = fileTree(dir: mergedResDir)
267 | allxmlFiles.include 'values/values*.xml', 'values-v1*/values-v1*.xml', 'values-v2*/values-v2*.xml', 'values-*-v1*/values-*-v1*.xml', 'values-*-v4/values-*-v4.xml', 'values-land/values-land.xml', 'values-*-v2*/values-*-v2*.xml', 'values-*-v8/values-*-v8.xml'
268 |
269 | allxmlFiles.each { File itemFile ->
270 | dest = new File(patchDir, 'patch_' + itemFile.name)
271 |
272 | println "export from " + itemFile + " to " + dest
273 |
274 | ThemeProcessor.exportThemeStyle(itemFile, dest, packageName)
275 | }
276 | }
277 |
278 | public class ThemeProcessor extends DefaultHandler {
279 |
280 | public static void exportThemeStyle(File srcFile, File destFile, String packageName) {
281 | try {
282 | SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
283 | saxParser.parse(new FileInputStream(srcFile), new ThemeProcessor(destFile, packageName));
284 | } catch (ParserConfigurationException e) {
285 | System.out.println(e.getMessage());
286 | } catch (SAXException e) {
287 | System.out.println(e.getMessage());
288 | } catch (FileNotFoundException e) {
289 | System.out.println(e.getMessage());
290 | } catch (IOException e) {
291 | System.out.println(e.getMessage());
292 | }
293 |
294 | }
295 |
296 | ////////////////
297 | ////////////////
298 | ////////////////
299 |
300 | File destFile;
301 | String packageName;
302 | Stack stack = new Stack();
303 | BufferedWriter outXmlStream = null;
304 |
305 | HashSet attrSets = new HashSet<>();
306 |
307 | HashSet dupcate = new HashSet<>();
308 |
309 | public ThemeProcessor(File destFile, String packageName) {
310 | this.destFile = destFile;
311 | this.packageName = packageName;
312 | }
313 |
314 | public void startDocument() throws SAXException {
315 | try {
316 | outXmlStream = new BufferedWriter(new FileWriter(destFile));
317 | outXmlStream.write("");
318 | outXmlStream.write("\n");
319 | } catch (FileNotFoundException e) {
320 | e.printStackTrace();
321 | } catch (IOException e) {
322 | e.printStackTrace();
323 | }
324 | }
325 |
326 | public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
327 |
328 | if (qName.equals("bool") || qName.equals("color") || qName.equals("dimen") || qName.equals("eat-comment")
329 | || qName.equals("integer") || qName.equals("string") || qName.equals("ns2:g")) {
330 | stack.add(new Node(attributes.getValue("name"), false, true));
331 | return;
332 | }
333 |
334 | boolean skip = false;
335 | if (!qName.equals("declare-styleable")) {
336 | String space = "\n";
337 | for (int i = 0; i < stack.size(); i++) {
338 | space = space + " ";
339 | }
340 | String tag = space + "<" + qName;
341 | for (int i = 0; i < attributes.getLength(); i++) {
342 | tag = tag + " " + attributes.getQName(i) + "=\""+ attributes.getValue(i) + "\"";
343 | }
344 | tag = tag + ">";
345 | try {
346 | if (qName.equals("attr") && (attributes.getValue("name").startsWith("android:") || (attrSets.add(attributes.getValue("name"))?false:(dupcate.add(attributes.getValue("name"))?true:true)))
347 | || (qName.equals("public") && (!attributes.getValue("type").equals("attr") || attributes.getValue("name").startsWith("public_static_final_")))) {
348 | //skip
349 | skip = true;
350 | } else {
351 | if (qName.equals("enum")) {
352 | if (!stack.empty()) {
353 | Node top = stack.peek();
354 | if (!dupcate.contains(top.name)) {
355 | outXmlStream.write(tag);
356 | }
357 | } else {
358 | outXmlStream.write(tag);
359 | }
360 | } else {
361 | outXmlStream.write(tag);
362 | }
363 | }
364 | } catch (IOException e) {
365 | e.printStackTrace();
366 | }
367 | }
368 |
369 | if (!stack.empty()) {
370 | Node top = stack.peek();
371 | top.hasChild = true;
372 | }
373 | stack.add(new Node(attributes.getValue("name"), false, skip));
374 | }
375 |
376 | public void endElement(String uri, String localName, String qName) throws SAXException {
377 |
378 | Node node = stack.pop();
379 | if (node.skip) {
380 | return;
381 | }
382 |
383 | if (!qName.equals("declare-styleable")) {
384 | String space = "";
385 | if (node.hasChild) {
386 | space = "\n";
387 | for (int i = 0; i < stack.size(); i++) {
388 | space = space + " ";
389 | }
390 | }
391 | try {
392 | if (!stack.empty()) {
393 | Node parent = stack.peek();
394 | if (qName.equals("enum") && dupcate.contains(parent.name)) {
395 | //nothing
396 | } else {
397 | outXmlStream.write(space + "" + qName + ">");
398 | }
399 | } else {
400 | outXmlStream.write(space + "" + qName + ">");
401 | }
402 | } catch (IOException e) {
403 | e.printStackTrace();
404 | }
405 | }
406 |
407 | }
408 |
409 | public void characters(char[] ch, int start, int length) throws SAXException {
410 | Node node = stack.peek();
411 | if (node.skip) {
412 | return;
413 | }
414 |
415 | String text = new String(ch, start, length);
416 | text = text.replaceAll("[\n ]", "");
417 | if (text.length() > 0) {
418 | try {
419 | if (text.startsWith("@color")) {
420 | text = text.replace("@color", "@*" + packageName +":color");
421 |
422 | } else if (text.startsWith("@dimen")) {
423 | text = text.replace("@dimen", "@*" + packageName +":dimen");
424 |
425 | } else if (text.startsWith("@string")) {
426 | text = text.replace("@string", "@*" + packageName +":string");
427 |
428 | } else if (text.startsWith("@bool")) {
429 | text = text.replace("@bool", "@*" + packageName +":bool");
430 |
431 | } else if (text.startsWith("@integer")) {
432 | text = text.replace("@integer", "@*" + packageName +":integer");
433 |
434 | } else if (text.startsWith("@layout")) {
435 | text = text.replace("@layout", "@*" + packageName +":layout");
436 |
437 | } else if (text.startsWith("@anim")) {
438 | text = text.replace("@anim", "@*" + packageName +":anim");
439 |
440 | } else if (text.startsWith("@id")) {
441 | text = text.replace("@id", "@*" + packageName +":id");
442 |
443 | } else if (text.startsWith("@drawable")) {
444 | text = text.replace("@drawable", "@*" + packageName +":drawable");
445 |
446 | //} else if (text.startsWith("?attr")) {
447 | // text = text.replace("?attr", "?*" + packageName +":attr");
448 | }
449 |
450 | outXmlStream.write(text);
451 | } catch (IOException e) {
452 | e.printStackTrace();
453 | }
454 | }
455 | }
456 |
457 | public void endDocument() throws SAXException {
458 | try {
459 | outXmlStream.flush();
460 | outXmlStream.close();
461 | } catch (IOException e) {
462 | e.printStackTrace();
463 | }
464 | }
465 |
466 | public static class Node {
467 | String name = null;
468 | boolean hasChild = false;
469 | boolean skip = false;
470 |
471 | public Node(String name, boolean hasChild, boolean skip) {
472 | this.name = name;
473 | this.hasChild = hasChild;
474 | this.skip = skip;
475 | }
476 | }
477 |
478 | }
479 |
480 |
481 | public class JarMerger {
482 | private final byte[] buffer = new byte[8192];
483 | private final File jarFile;
484 | private FileOutputStream fos;
485 | private JarOutputStream jarOutputStream;
486 |
487 | private JarFilter filter;
488 |
489 | public JarMerger(File jarFile) throws IOException {
490 | this.jarFile = jarFile;
491 | }
492 |
493 | private void init() throws IOException {
494 | if(this.fos == null && this.jarOutputStream == null) {
495 | if(!this.jarFile.getParentFile().mkdirs() && !this.jarFile.getParentFile().exists()) {
496 | throw new RuntimeException("Cannot create directory " + this.jarFile.getParentFile());
497 | }
498 | this.fos = new FileOutputStream(this.jarFile);
499 | this.jarOutputStream = new JarOutputStream(fos);
500 | }
501 | }
502 |
503 | public void setFilter(JarFilter filter) {
504 | this.filter = filter;
505 | }
506 |
507 | public void addFolder(File folder) throws IOException {
508 | this.init();
509 |
510 | try {
511 | this.addFolderInternal(folder, "");
512 | } catch (JarFilter.ZipAbortException var3) {
513 | throw new IOException(var3);
514 | }
515 | }
516 |
517 | private void addFolderInternal(File folder, String path) throws IOException, JarFilter.ZipAbortException {
518 | File[] files = folder.listFiles();
519 | if(files != null) {
520 | File[] arr$ = files;
521 | int len$ = files.length;
522 |
523 | for(int i$ = 0; i$ < len$; ++i$) {
524 | File file = arr$[i$];
525 | if(!file.isFile()) {
526 | if(file.isDirectory()) {
527 | this.addFolderInternal(file, path + file.getName() + "/");
528 | }
529 | } else {
530 | String entryPath = path + file.getName();
531 | if(this.filter == null || this.filter.checkEntry(entryPath)) {
532 | this.jarOutputStream.putNextEntry(new JarEntry(entryPath));
533 | FileInputStream fis = null;
534 | try {
535 | fis = new FileInputStream(file);
536 |
537 | int count;
538 | while((count = fis.read(this.buffer)) != -1) {
539 | this.jarOutputStream.write(this.buffer, 0, count);
540 | }
541 | } finally {
542 | if (fis != null) {
543 | fis.close();
544 | fis = null;
545 | }
546 | }
547 |
548 | this.jarOutputStream.closeEntry();
549 | }
550 | }
551 | }
552 | }
553 |
554 | }
555 |
556 | public void addJar(File file) throws IOException {
557 | this.addJar(file, false);
558 | }
559 |
560 | public void addJar(File file, boolean removeEntryTimestamp) throws IOException {
561 | this.init();
562 |
563 | FileInputStream e = null;
564 | ZipInputStream zis = null;
565 | try {
566 | e = new FileInputStream(file);
567 | zis = new ZipInputStream(e);
568 |
569 | ZipEntry entry;
570 | while((entry = zis.getNextEntry()) != null) {
571 | if(!entry.isDirectory()) {
572 | String name = entry.getName();
573 | if(this.filter == null || this.filter.checkEntry(name)) {
574 | JarEntry newEntry;
575 | if(entry.getMethod() == ZipEntry.STORED) {
576 | newEntry = new JarEntry(entry);
577 | } else {
578 | newEntry = new JarEntry(name);
579 | }
580 |
581 | if(removeEntryTimestamp) {
582 | newEntry.setTime(0L);
583 | }
584 |
585 | this.jarOutputStream.putNextEntry(newEntry);
586 |
587 | int count;
588 | while((count = zis.read(this.buffer)) != -1) {
589 | this.jarOutputStream.write(this.buffer, 0, count);
590 | }
591 |
592 | this.jarOutputStream.closeEntry();
593 | zis.closeEntry();
594 | }
595 | }
596 | }
597 | } catch (JarFilter.ZipAbortException var13) {
598 | throw new IOException(var13);
599 | } finally {
600 | if (zis != null) {
601 | zis.close();
602 | }
603 | if (e != null) {
604 | e.close();
605 | }
606 | }
607 |
608 | }
609 |
610 | public void addEntry(String path, byte[] bytes) throws IOException {
611 | this.init();
612 | this.jarOutputStream.putNextEntry(new JarEntry(path));
613 | this.jarOutputStream.write(bytes);
614 | this.jarOutputStream.closeEntry();
615 | }
616 |
617 | public void close() throws IOException {
618 | if (this.jarOutputStream != null) {
619 | jarOutputStream.close();
620 | jarOutputStream = null;
621 | }
622 | if (this.fos != null) {
623 | fos.close();
624 | fos = null;
625 | }
626 |
627 | }
628 | }
629 |
630 | public interface JarFilter {
631 | boolean checkEntry(String var1) throws ZipAbortException;
632 |
633 | public static class ZipAbortException extends Exception {
634 | private static final long serialVersionUID = 1L;
635 |
636 | public ZipAbortException() {
637 | }
638 |
639 | public ZipAbortException(String format, Object... args) {
640 | super(String.format(format, args));
641 | }
642 |
643 | public ZipAbortException(Throwable cause, String format, Object... args) {
644 | super(String.format(format, args), cause);
645 | }
646 |
647 | public ZipAbortException(Throwable cause) {
648 | super(cause);
649 | }
650 | }
651 | }
--------------------------------------------------------------------------------