├── loading
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── load1.png
│ │ │ │ ├── load2.png
│ │ │ │ ├── load3.png
│ │ │ │ ├── load4.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── banner_demo_img.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_single_loading.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── activity_multi_loading.xml
│ │ │ │ ├── error.xml
│ │ │ │ └── loading.xml
│ │ │ └── drawable
│ │ │ │ ├── loading_frame_anim.xml
│ │ │ │ ├── error.xml
│ │ │ │ └── network_error.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── wpq
│ │ │ │ └── sample
│ │ │ │ └── loading
│ │ │ │ ├── loading
│ │ │ │ ├── LoadingInterface.java
│ │ │ │ └── LoadingController.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── SingleLoadingActivity.java
│ │ │ │ └── MultiLoadingActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── wpq
│ │ │ └── sample
│ │ │ └── loading
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── wpq
│ │ └── sample
│ │ └── loading
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── progress-dialog
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable
│ │ │ │ └── custom_progress_dialog_bg.xml
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ └── layout
│ │ │ │ ├── activity_custom_progress_dialog.xml
│ │ │ │ ├── activity_normal_progress_dialog.xml
│ │ │ │ ├── dialog_custom_progress.xml
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── wpq
│ │ │ └── sample
│ │ │ └── progress_dialog
│ │ │ ├── MyHttpClient.java
│ │ │ ├── CustomProgressDialogActivity.java
│ │ │ ├── NormalProgressDialogActivity.java
│ │ │ ├── widget
│ │ │ ├── NormalProgressDialog.java
│ │ │ └── CustomProgressDialog.java
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── wpq
│ │ │ └── sample
│ │ │ └── progress_dialog
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── wpq
│ │ └── sample
│ │ └── progress_dialog
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── images
├── multi.gif
├── single.gif
├── 自定义ProgressDialog.gif
├── 封装系统自带的ProgressDialog.gif
└── 系统自带的ProgressDialog.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── eventbus
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ └── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── activity_test.xml
│ │ │ │ └── fragment_home.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── wpq
│ │ │ │ └── sample
│ │ │ │ └── eventbus
│ │ │ │ ├── annotation
│ │ │ │ └── BindEventBus.java
│ │ │ │ ├── eventbus
│ │ │ │ └── MessageEvent.java
│ │ │ │ ├── base
│ │ │ │ ├── BaseFragment.java
│ │ │ │ └── BaseAppCompatActivity.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── TestActivity.java
│ │ │ │ └── HomeFragment.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── wpq
│ │ │ └── sample
│ │ │ └── eventbus
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── wpq
│ │ └── sample
│ │ └── eventbus
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── gradle.properties
├── .gitignore
├── README.md
├── gradlew.bat
└── gradlew
/loading/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/progress-dialog/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':eventbus', ':loading', ':progress-dialog'
2 |
--------------------------------------------------------------------------------
/images/multi.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/images/multi.gif
--------------------------------------------------------------------------------
/images/single.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/images/single.gif
--------------------------------------------------------------------------------
/images/自定义ProgressDialog.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/images/自定义ProgressDialog.gif
--------------------------------------------------------------------------------
/images/封装系统自带的ProgressDialog.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/images/封装系统自带的ProgressDialog.gif
--------------------------------------------------------------------------------
/images/系统自带的ProgressDialog.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/images/系统自带的ProgressDialog.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-xhdpi/load1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-xhdpi/load1.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-xhdpi/load2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-xhdpi/load2.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-xhdpi/load3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-xhdpi/load3.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-xhdpi/load4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-xhdpi/load4.png
--------------------------------------------------------------------------------
/eventbus/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/eventbus/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/eventbus/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/eventbus/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/eventbus/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/eventbus/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/eventbus/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/eventbus/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/eventbus/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/eventbus/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-xxhdpi/banner_demo_img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-xxhdpi/banner_demo_img.png
--------------------------------------------------------------------------------
/eventbus/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/eventbus/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/eventbus/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/eventbus/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/eventbus/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/eventbus/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/eventbus/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/eventbus/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/loading/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/loading/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/progress-dialog/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/progress-dialog/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/progress-dialog/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/eventbus/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/eventbus/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/progress-dialog/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/progress-dialog/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/progress-dialog/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/progress-dialog/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/progress-dialog/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/progress-dialog/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wpq2014/android-blog-samples/HEAD/progress-dialog/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/eventbus/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | eventbus
3 |
4 | MainActivity
5 | TestActivity
6 |
7 |
--------------------------------------------------------------------------------
/eventbus/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/loading/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri May 26 10:49:27 CST 2017
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-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/drawable/custom_progress_dialog_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | progress-dialog
3 | 系统自带的ProgressDialog
4 | 封装系统自带的ProgressDialog
5 | 自定义ProgressDialog
6 |
7 |
--------------------------------------------------------------------------------
/eventbus/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/loading/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/eventbus/src/main/java/com/wpq/sample/eventbus/annotation/BindEventBus.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.eventbus.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * @author wpq
10 | * @version 1.0
11 | */
12 | @Target(ElementType.TYPE)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface BindEventBus {
15 | }
16 |
--------------------------------------------------------------------------------
/loading/src/main/java/com/wpq/sample/loading/loading/LoadingInterface.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.loading.loading;
2 |
3 | /**
4 | * @author wpq
5 | * @version 1.0
6 | */
7 | public interface LoadingInterface {
8 |
9 | void showLoading();
10 |
11 | void showNetworkError();
12 |
13 | void showError();
14 |
15 | void showEmpty();
16 |
17 | void dismissLoading();
18 |
19 | interface OnClickListener {
20 | void onClick();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/loading/src/main/res/layout/activity_single_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/loading/src/test/java/com/wpq/sample/loading/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.loading;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/eventbus/src/test/java/com/wpq/sample/eventbus/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.eventbus;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/eventbus/src/main/java/com/wpq/sample/eventbus/eventbus/MessageEvent.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.eventbus.eventbus;
2 |
3 | /**
4 | * @author wpq
5 | * @version 1.0
6 | */
7 | public class MessageEvent {
8 |
9 | private String message;
10 |
11 | public MessageEvent(String message) {
12 | this.message = message;
13 | }
14 |
15 | public String getMessage() {
16 | return message;
17 | }
18 |
19 | public void setMessage(String message) {
20 | this.message = message;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/progress-dialog/src/test/java/com/wpq/sample/progress_dialog/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.progress_dialog;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/loading/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | loading
3 |
4 | 加载中
5 | 加载失败,请检查网络连接~
6 | 加载失败,点击重试~
7 | 重新加载
8 |
9 |
10 | 一个Loading
11 | 多个Loading
12 |
13 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/layout/activity_custom_progress_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/layout/activity_normal_progress_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/eventbus/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/loading/src/main/res/drawable/loading_frame_anim.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
11 |
14 |
17 |
18 |
--------------------------------------------------------------------------------
/loading/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
14 |
15 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx1024m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | #Fri Jun 02 09:53:34 CST 2017
16 | org.gradle.jvmargs=-Xmx1536m
17 |
18 |
--------------------------------------------------------------------------------
/loading/src/main/res/drawable/error.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/eventbus/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/
38 |
39 | # Keystore files
40 | *.jks
41 |
42 | # External native build folder generated in Android Studio 2.2 and later
43 | .externalNativeBuild
44 |
45 | # Google Services (e.g. APIs or Firebase)
46 | google-services.json
47 |
48 | # Freeline
49 | freeline.py
50 | freeline/
51 | freeline_project_description.json
52 |
--------------------------------------------------------------------------------
/eventbus/src/androidTest/java/com/wpq/sample/eventbus/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.eventbus;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.wpq.sample.eventbus", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/loading/src/androidTest/java/com/wpq/sample/loading/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.loading;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.wpq.sample.loading", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/eventbus/src/main/res/layout/activity_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/progress-dialog/src/androidTest/java/com/wpq/sample/progress_dialog/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.progress_dialog;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.wpq.sample.progress_dialog", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/loading/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/eventbus/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/wpq/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/loading/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/wpq/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/progress-dialog/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/wpq/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/loading/src/main/res/layout/activity_multi_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
21 |
22 |
27 |
28 |
--------------------------------------------------------------------------------
/eventbus/src/main/java/com/wpq/sample/eventbus/base/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.eventbus.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v4.app.Fragment;
6 |
7 | import com.wpq.sample.eventbus.annotation.BindEventBus;
8 |
9 | import org.greenrobot.eventbus.EventBus;
10 |
11 | /**
12 | * @author wpq
13 | * @version 1.0
14 | */
15 | public class BaseFragment extends Fragment {
16 |
17 | protected String TAG;
18 |
19 | @Override
20 | public void onCreate(@Nullable Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 |
23 | TAG = this.getClass().getSimpleName();
24 |
25 | if (this.getClass().isAnnotationPresent(BindEventBus.class)) {
26 | EventBus.getDefault().register(this);
27 | }
28 | }
29 |
30 | @Override
31 | public void onDestroy() {
32 | super.onDestroy();
33 | if (this.getClass().isAnnotationPresent(BindEventBus.class)) {
34 | EventBus.getDefault().unregister(this);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/eventbus/src/main/java/com/wpq/sample/eventbus/base/BaseAppCompatActivity.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.eventbus.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | import com.wpq.sample.eventbus.annotation.BindEventBus;
8 |
9 | import org.greenrobot.eventbus.EventBus;
10 |
11 | /**
12 | * @author wpq
13 | * @version 1.0
14 | */
15 | public abstract class BaseAppCompatActivity extends AppCompatActivity{
16 |
17 | protected String TAG;
18 |
19 | @Override
20 | protected void onCreate(@Nullable Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 |
23 | TAG = this.getClass().getSimpleName();
24 |
25 | if (this.getClass().isAnnotationPresent(BindEventBus.class)) {
26 | EventBus.getDefault().register(this);
27 | }
28 | }
29 |
30 | @Override
31 | protected void onDestroy() {
32 | super.onDestroy();
33 | if (this.getClass().isAnnotationPresent(BindEventBus.class)) {
34 | EventBus.getDefault().unregister(this);
35 | }
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/loading/src/main/java/com/wpq/sample/loading/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.loading;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 | import android.widget.Button;
7 |
8 | import butterknife.BindView;
9 | import butterknife.ButterKnife;
10 | import butterknife.OnClick;
11 |
12 | public class MainActivity extends AppCompatActivity {
13 |
14 | @BindView(R.id.btn1)
15 | Button btn1;
16 | @BindView(R.id.btn2)
17 | Button btn2;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 | ButterKnife.bind(this);
24 |
25 | }
26 |
27 | @OnClick({R.id.btn1, R.id.btn2})
28 | public void onViewClicked(View view) {
29 | switch (view.getId()) {
30 | case R.id.btn1:
31 | startActivity(SingleLoadingActivity.newIntent(this));
32 | break;
33 | case R.id.btn2:
34 | startActivity(MultiLoadingActivity.newIntent(this));
35 | break;
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/eventbus/src/main/java/com/wpq/sample/eventbus/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.eventbus;
2 |
3 | import android.os.Bundle;
4 | import android.util.Log;
5 |
6 | import com.wpq.sample.eventbus.annotation.BindEventBus;
7 | import com.wpq.sample.eventbus.base.BaseAppCompatActivity;
8 | import com.wpq.sample.eventbus.eventbus.MessageEvent;
9 |
10 | import org.greenrobot.eventbus.Subscribe;
11 | import org.greenrobot.eventbus.ThreadMode;
12 |
13 | import butterknife.ButterKnife;
14 |
15 | @BindEventBus
16 | public class MainActivity extends BaseAppCompatActivity {
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 | ButterKnife.bind(this);
23 |
24 | getSupportFragmentManager().beginTransaction().add(R.id.container, HomeFragment.newInstance()).commit();
25 | }
26 |
27 | /** 方法名可自定义 */
28 | @Subscribe(threadMode = ThreadMode.MAIN)
29 | public void onMessage(MessageEvent event) {
30 | if (event != null) {
31 | Log.e(TAG, "收到消息:【" + event.getMessage() +"】");
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/loading/src/main/res/layout/error.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
22 |
23 |
29 |
30 |
--------------------------------------------------------------------------------
/loading/src/main/res/layout/loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
17 |
18 |
22 |
23 |
24 |
25 |
33 |
34 |
--------------------------------------------------------------------------------
/eventbus/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'android-apt'
3 | apply plugin: 'com.jakewharton.butterknife'
4 |
5 | android {
6 | compileSdkVersion 25
7 | buildToolsVersion "25.0.2"
8 |
9 | defaultConfig {
10 | applicationId "com.wpq.sample.eventbus"
11 | minSdkVersion 15
12 | targetSdkVersion 25
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 |
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
30 | exclude group: 'com.android.support', module: 'support-annotations'
31 | })
32 | compile 'com.android.support:appcompat-v7:25.3.1'
33 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
34 | testCompile 'junit:junit:4.12'
35 |
36 | compile 'org.greenrobot:eventbus:3.0.0'
37 |
38 | compile 'com.jakewharton:butterknife:8.6.0'
39 | apt 'com.jakewharton:butterknife-compiler:8.6.0' // 修改的地方 把annotationProcessor改为apt
40 | }
41 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
8 | #0D000000
9 | #1A000000
10 | #26000000
11 | #33000000
12 | #40000000
13 | #4D000000
14 | #59000000
15 | #66000000
16 | #73000000
17 | #80000000
18 | #8C000000
19 | #99000000
20 | #A6000000
21 | #B3000000
22 | #BF000000
23 | #CC000000
24 | #D9000000
25 | #E6000000
26 | #F2000000
27 | #FF000000
28 |
29 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/eventbus/src/main/java/com/wpq/sample/eventbus/TestActivity.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.eventbus;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.widget.Button;
8 |
9 | import com.wpq.sample.eventbus.base.BaseAppCompatActivity;
10 | import com.wpq.sample.eventbus.eventbus.MessageEvent;
11 |
12 | import org.greenrobot.eventbus.EventBus;
13 |
14 | import butterknife.BindView;
15 | import butterknife.ButterKnife;
16 | import butterknife.OnClick;
17 |
18 | /**
19 | * @author wpq
20 | * @version 1.0
21 | */
22 | public class TestActivity extends BaseAppCompatActivity {
23 |
24 | @BindView(R.id.btn_post)
25 | Button mBtnPost;
26 |
27 | public static Intent newIntent(Context context) {
28 | Intent intent = new Intent(context, TestActivity.class);
29 | Bundle bundle = new Bundle();
30 | intent.putExtras(bundle);
31 | return intent;
32 | }
33 |
34 | @Override
35 | protected void onCreate(@Nullable Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_test);
38 | ButterKnife.bind(this);
39 | }
40 |
41 | @OnClick(R.id.btn_post)
42 | public void onViewClicked() {
43 | EventBus.getDefault().post(new MessageEvent("嘿嘿嘿~"));
44 | finish();
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/loading/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'android-apt'
3 | apply plugin: 'com.jakewharton.butterknife'
4 |
5 | android {
6 | compileSdkVersion 25
7 | buildToolsVersion "25.0.2"
8 |
9 | defaultConfig {
10 | applicationId "com.wpq.sample.loading"
11 | minSdkVersion 15
12 | targetSdkVersion 25
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 |
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
30 | exclude group: 'com.android.support', module: 'support-annotations'
31 | })
32 | compile 'com.android.support:appcompat-v7:25.3.1'
33 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
34 | testCompile 'junit:junit:4.12'
35 |
36 | compile 'com.android.support:design:25.3.1'
37 |
38 | compile 'com.github.bumptech.glide:glide:3.7.0'
39 |
40 | compile 'com.jakewharton:butterknife:8.6.0'
41 | apt 'com.jakewharton:butterknife-compiler:8.6.0' // 修改的地方 把annotationProcessor改为apt
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/eventbus/src/main/res/layout/fragment_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/progress-dialog/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'android-apt'
3 | apply plugin: 'com.jakewharton.butterknife'
4 |
5 | android {
6 | compileSdkVersion 25
7 | buildToolsVersion "25.0.2"
8 |
9 | defaultConfig {
10 | applicationId "com.wpq.sample.progress_dialog"
11 | minSdkVersion 15
12 | targetSdkVersion 25
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
17 |
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
30 | exclude group: 'com.android.support', module: 'support-annotations'
31 | })
32 | compile 'com.android.support:appcompat-v7:25.3.1'
33 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
34 | testCompile 'junit:junit:4.12'
35 |
36 | compile 'com.jakewharton:butterknife:8.6.0'
37 | apt 'com.jakewharton:butterknife-compiler:8.6.0' // 修改的地方 把annotationProcessor改为apt
38 |
39 | // compile 'com.loopj.android:android-async-http:1.4.9'
40 | compile 'com.loopj.android:android-async-http:latest.release'
41 | }
42 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/layout/dialog_custom_progress.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
25 |
26 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/java/com/wpq/sample/progress_dialog/MyHttpClient.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.progress_dialog;
2 |
3 | import android.content.Context;
4 |
5 | import com.loopj.android.http.*;
6 | import com.loopj.android.http.BuildConfig;
7 |
8 | import org.apache.http.conn.ssl.SSLSocketFactory;
9 |
10 | /**
11 | * @author wpq
12 | * @version 1.0
13 | */
14 | public class MyHttpClient {
15 |
16 | private static final AsyncHttpClient mClient = new AsyncHttpClient();
17 |
18 | static {
19 | try {
20 | mClient.setTimeout(20000); // 默认10秒超时
21 | if(BuildConfig.DEBUG){
22 | mClient.setSSLSocketFactory(MySSLSocketFactory.getFixedSocketFactory()); //不验证书
23 | }else{
24 | mClient.setSSLSocketFactory(SSLSocketFactory.getSocketFactory()); //验证书
25 | }
26 | mClient.addHeader("x-app-platform", "Android");
27 | mClient.addHeader("Content-Type", "application/json");
28 | } catch (Exception e) {
29 | e.printStackTrace();
30 | }
31 | }
32 |
33 | public static AsyncHttpClient getHttptClient(){
34 | return mClient;
35 | }
36 |
37 | /**
38 | * 取消与当前context关联的所有请求
39 | * @param context 当前context
40 | */
41 | public static void cancelRequests(Context context){
42 | mClient.cancelRequests(context, true);
43 | }
44 |
45 | /**
46 | * 取消所有请求
47 | */
48 | public static void cancelAllRequests(){
49 | mClient.cancelAllRequests(true);
50 | }
51 |
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
19 |
20 |
30 |
31 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/loading/src/main/res/drawable/network_error.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/java/com/wpq/sample/progress_dialog/CustomProgressDialogActivity.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.progress_dialog;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.Handler;
7 | import android.support.annotation.Nullable;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.widget.Button;
10 |
11 | import com.wpq.sample.progress_dialog.widget.CustomProgressDialog;
12 |
13 | import butterknife.BindView;
14 | import butterknife.ButterKnife;
15 | import butterknife.OnClick;
16 |
17 | /**
18 | * @author wpq
19 | * @version 1.0
20 | */
21 | public class CustomProgressDialogActivity extends AppCompatActivity {
22 |
23 | @BindView(R.id.btn_show)
24 | Button mBtnShow;
25 |
26 | public static Intent newIntent(Context context) {
27 | Intent intent = new Intent(context, CustomProgressDialogActivity.class);
28 | return intent;
29 | }
30 |
31 | @Override
32 | protected void onCreate(@Nullable Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_custom_progress_dialog);
35 | ButterKnife.bind(this);
36 | }
37 |
38 | @OnClick(R.id.btn_show)
39 | public void onViewClicked() {
40 | CustomProgressDialog.show(this, "加载中...", false);
41 | // 4s后dismiss
42 | new Handler().postDelayed(new Runnable() {
43 | @Override
44 | public void run() {
45 | CustomProgressDialog.stop();
46 | }
47 | }, 4000);
48 |
49 | // 在1.5s的时候再次调用show
50 | new Handler().postDelayed(new Runnable() {
51 | @Override
52 | public void run() {
53 | CustomProgressDialog.show(CustomProgressDialogActivity.this, "loading...");
54 | }
55 | }, 1500);
56 | // 3s时调一下
57 | new Handler().postDelayed(new Runnable() {
58 | @Override
59 | public void run() {
60 | CustomProgressDialog.stop();
61 | }
62 | }, 3000);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/java/com/wpq/sample/progress_dialog/NormalProgressDialogActivity.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.progress_dialog;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.Handler;
7 | import android.support.annotation.Nullable;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.widget.Button;
10 |
11 | import com.wpq.sample.progress_dialog.widget.NormalProgressDialog;
12 |
13 | import butterknife.BindView;
14 | import butterknife.ButterKnife;
15 | import butterknife.OnClick;
16 |
17 | /**
18 | * @author wpq
19 | * @version 1.0
20 | */
21 | public class NormalProgressDialogActivity extends AppCompatActivity {
22 |
23 | @BindView(R.id.btn_show)
24 | Button mBtnShow;
25 |
26 | public static Intent newIntent(Context context) {
27 | Intent intent = new Intent(context, NormalProgressDialogActivity.class);
28 | return intent;
29 | }
30 |
31 | @Override
32 | protected void onCreate(@Nullable Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_normal_progress_dialog);
35 | ButterKnife.bind(this);
36 | }
37 |
38 | @OnClick(R.id.btn_show)
39 | public void onViewClicked() {
40 | NormalProgressDialog.show(this, "加载中...", false);
41 | // 4s后dismiss
42 | new Handler().postDelayed(new Runnable() {
43 | @Override
44 | public void run() {
45 | NormalProgressDialog.stop();
46 | }
47 | }, 4000);
48 |
49 | // 在1.5s的时候再次调用show
50 | new Handler().postDelayed(new Runnable() {
51 | @Override
52 | public void run() {
53 | NormalProgressDialog.show(NormalProgressDialogActivity.this, "loading...");
54 | }
55 | }, 1500);
56 | // 3s时调一下
57 | new Handler().postDelayed(new Runnable() {
58 | @Override
59 | public void run() {
60 | NormalProgressDialog.stop();
61 | }
62 | }, 3000);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/eventbus/src/main/java/com/wpq/sample/eventbus/HomeFragment.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.eventbus;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.util.Log;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Button;
10 | import android.widget.TextView;
11 |
12 | import com.wpq.sample.eventbus.annotation.BindEventBus;
13 | import com.wpq.sample.eventbus.base.BaseFragment;
14 | import com.wpq.sample.eventbus.eventbus.MessageEvent;
15 |
16 | import org.greenrobot.eventbus.Subscribe;
17 | import org.greenrobot.eventbus.ThreadMode;
18 |
19 | import butterknife.BindView;
20 | import butterknife.ButterKnife;
21 | import butterknife.OnClick;
22 | import butterknife.Unbinder;
23 |
24 | /**
25 | * @author wpq
26 | * @version 1.0
27 | */
28 | @BindEventBus
29 | public class HomeFragment extends BaseFragment {
30 |
31 | @BindView(R.id.tv_msg)
32 | TextView mTvMsg;
33 | @BindView(R.id.btn_intent)
34 | Button mBtnIntent;
35 | Unbinder unbinder;
36 |
37 | public static HomeFragment newInstance() {
38 | Bundle bundle = new Bundle();
39 | HomeFragment homeFragment = new HomeFragment();
40 | homeFragment.setArguments(bundle);
41 | return homeFragment;
42 | }
43 |
44 | @Nullable
45 | @Override
46 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
47 | View v = inflater.inflate(R.layout.fragment_home, container, false);
48 | unbinder = ButterKnife.bind(this, v);
49 | return v;
50 | }
51 |
52 | @Override
53 | public void onDestroyView() {
54 | super.onDestroyView();
55 | unbinder.unbind();
56 | }
57 |
58 | @OnClick(R.id.btn_intent)
59 | public void onViewClicked() {
60 | startActivity(TestActivity.newIntent(getActivity()));
61 | }
62 |
63 | /** 方法名可自定义 */
64 | @Subscribe(threadMode = ThreadMode.MAIN)
65 | public void onMessage(MessageEvent event) {
66 | if (event != null) {
67 | Log.e(TAG, "收到消息:【" + event.getMessage() +"】");
68 | mTvMsg.setText("收到消息:【" + event.getMessage() +"】");
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # android-blog-samples
2 | #### [简书](http://www.jianshu.com/u/fca46862a3b2)博客文章的源码
3 | ## 文章列表
4 | * [Android项目实战 加载数据时页面状态切换封装过程](http://www.jianshu.com/p/739237652803)
5 | * [Android项目实战 ProgressDialog自定义和封装过程](http://www.jianshu.com/p/3fd52a212c6d)
6 | * [Android项目实战 EventBus的封装](http://www.jianshu.com/p/bf5c431872bf)
7 | ## 相关截图
8 | * [Android项目实战 加载数据时页面状态切换封装过程](http://www.jianshu.com/p/739237652803)
9 |
10 |
11 |
12 |
13 | * [Android项目实战 ProgressDialog自定义和封装过程](http://www.jianshu.com/p/3fd52a212c6d)
14 |
15 |
16 |
17 |
18 |
19 | * [Android项目实战 RecyclerView加载更多及添加Header和Footer](https://github.com/wpq2014/LoadMoreRecyclerView)
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/java/com/wpq/sample/progress_dialog/widget/NormalProgressDialog.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.progress_dialog.widget;
2 |
3 | import android.app.Activity;
4 | import android.app.ProgressDialog;
5 | import android.content.Context;
6 | import android.content.DialogInterface;
7 | import android.widget.Toast;
8 |
9 | import com.wpq.sample.progress_dialog.MyHttpClient;
10 |
11 | import java.lang.ref.WeakReference;
12 |
13 | /**
14 | * @author wpq
15 | * @version 1.0
16 | */
17 | public class NormalProgressDialog extends ProgressDialog implements DialogInterface.OnCancelListener {
18 |
19 | private WeakReference mContextRef = new WeakReference<>(null);
20 | private volatile static NormalProgressDialog sDialog;
21 |
22 | private NormalProgressDialog(Context context) {
23 | this(context, -1);
24 | }
25 |
26 | private NormalProgressDialog(Context context, int theme) {
27 | super(context, theme);
28 |
29 | mContextRef = new WeakReference<>(context);
30 | setOnCancelListener(this);
31 | }
32 |
33 | @Override
34 | public void onCancel(DialogInterface dialog) {
35 | // 点手机返回键等触发Dialog消失,应该取消正在进行的网络请求等
36 | Context context = mContextRef.get();
37 | if (context != null) {
38 | Toast.makeText(context, "cancel", Toast.LENGTH_SHORT).show();
39 | MyHttpClient.cancelRequests(context);
40 | }
41 | }
42 |
43 | public static void show(Context context) {
44 | show(context, "loading...");
45 | }
46 |
47 | public static void show(Context context, CharSequence message) {
48 | show(context, message, true);
49 | }
50 |
51 | public static void show(Context context, CharSequence message, boolean cancelable) {
52 | if (sDialog != null && sDialog.isShowing()) {
53 | sDialog.dismiss();
54 | }
55 |
56 | if (context == null || !(context instanceof Activity)) {
57 | return;
58 | }
59 | sDialog = new NormalProgressDialog(context);
60 | sDialog.setMessage(message);
61 | sDialog.setCancelable(cancelable);
62 |
63 | if (sDialog != null && !sDialog.isShowing() && !((Activity) context).isFinishing()) {
64 | sDialog.show();
65 | }
66 | }
67 |
68 | public static void stop() {
69 | if (sDialog != null && sDialog.isShowing()) {
70 | sDialog.dismiss();
71 | }
72 | sDialog = null;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/java/com/wpq/sample/progress_dialog/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.progress_dialog;
2 |
3 | import android.app.ProgressDialog;
4 | import android.os.Bundle;
5 | import android.os.Handler;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.Button;
9 |
10 | import butterknife.BindView;
11 | import butterknife.ButterKnife;
12 | import butterknife.OnClick;
13 |
14 | public class MainActivity extends AppCompatActivity {
15 |
16 | @BindView(R.id.btn_normalProgressDialog)
17 | Button mBtnNormalProgressDialog;
18 | @BindView(R.id.btn_customProgressDialog)
19 | Button mBtnCustomProgressDialog;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_main);
25 | ButterKnife.bind(this);
26 |
27 | }
28 |
29 | @OnClick({R.id.btn_show, R.id.btn_normalProgressDialog, R.id.btn_customProgressDialog})
30 | public void onViewClicked(View view) {
31 | switch (view.getId()) {
32 | case R.id.btn_show:
33 | test();
34 | break;
35 | case R.id.btn_normalProgressDialog:
36 | startActivity(NormalProgressDialogActivity.newIntent(this));
37 | break;
38 | case R.id.btn_customProgressDialog:
39 | startActivity(CustomProgressDialogActivity.newIntent(this));
40 | break;
41 | }
42 | }
43 |
44 | private void test() {
45 | final ProgressDialog pd1 = ProgressDialog.show(this, "网络请求", "加载中...");
46 | // 4s后dismiss
47 | new Handler().postDelayed(new Runnable() {
48 | @Override
49 | public void run() {
50 | pd1.dismiss();
51 | }
52 | }, 4000);
53 |
54 | // 在1.5s的时候再次调用show
55 | final ProgressDialog pd2 = new ProgressDialog(this);
56 | pd2.setMessage("loading...");
57 | // pd2.setView(LayoutInflater.from(this).inflate(R.layout.dialog_custom_progress, null));
58 | new Handler().postDelayed(new Runnable() {
59 | @Override
60 | public void run() {
61 | pd2.show();
62 | }
63 | }, 1500);
64 | // 3s时pd2 dismiss
65 | new Handler().postDelayed(new Runnable() {
66 | @Override
67 | public void run() {
68 | pd2.dismiss();
69 | }
70 | }, 3000);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/progress-dialog/src/main/java/com/wpq/sample/progress_dialog/widget/CustomProgressDialog.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.progress_dialog.widget;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.app.Dialog;
6 | import android.content.Context;
7 | import android.content.DialogInterface;
8 | import android.text.TextUtils;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.TextView;
13 | import android.widget.Toast;
14 |
15 | import com.wpq.sample.progress_dialog.MyHttpClient;
16 | import com.wpq.sample.progress_dialog.R;
17 |
18 | import java.lang.ref.WeakReference;
19 |
20 | /**
21 | * @author wpq
22 | * @version 1.0
23 | */
24 | public class CustomProgressDialog extends Dialog implements DialogInterface.OnCancelListener {
25 |
26 | private WeakReference mContextRef = new WeakReference<>(null);
27 | private volatile static CustomProgressDialog sDialog;
28 |
29 | private CustomProgressDialog(Context context, CharSequence message) {
30 | super(context, R.style.CustomProgressDialog);
31 |
32 | mContextRef = new WeakReference<>(context);
33 |
34 | @SuppressLint("InflateParams")
35 | View view = LayoutInflater.from(context).inflate(R.layout.dialog_custom_progress, null);
36 | TextView tvMessage = (TextView) view.findViewById(R.id.tv_message);
37 | if (!TextUtils.isEmpty(message)) {
38 | tvMessage.setText(message);
39 | }
40 | ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
41 | addContentView(view, lp);
42 |
43 | setOnCancelListener(this);
44 | }
45 |
46 | @Override
47 | public void onCancel(DialogInterface dialog) {
48 | // 点手机返回键等触发Dialog消失,应该取消正在进行的网络请求等
49 | Context context = mContextRef.get();
50 | if (context != null) {
51 | Toast.makeText(context, "cancel", Toast.LENGTH_SHORT).show();
52 | MyHttpClient.cancelRequests(context);
53 | }
54 | }
55 |
56 | public static void show(Context context) {
57 | show(context, "loading...");
58 | }
59 |
60 | public static void show(Context context, CharSequence message) {
61 | show(context, message, true);
62 | }
63 |
64 | public static void show(Context context, CharSequence message, boolean cancelable) {
65 | if (sDialog != null && sDialog.isShowing()) {
66 | sDialog.dismiss();
67 | }
68 |
69 | if (context == null || !(context instanceof Activity)) {
70 | return;
71 | }
72 |
73 | sDialog = new CustomProgressDialog(context, message);
74 | sDialog.setCancelable(cancelable);
75 |
76 | if (sDialog != null && !sDialog.isShowing() && !((Activity) context).isFinishing()) {
77 | sDialog.show();
78 | }
79 | }
80 |
81 | public static void stop() {
82 | if (sDialog != null && sDialog.isShowing()) {
83 | sDialog.dismiss();
84 | }
85 | sDialog = null;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/loading/src/main/java/com/wpq/sample/loading/SingleLoadingActivity.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.loading;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.Handler;
7 | import android.support.annotation.Nullable;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.RecyclerView;
10 |
11 | import com.wpq.sample.loading.loading.LoadingController;
12 | import com.wpq.sample.loading.loading.LoadingInterface;
13 |
14 | import butterknife.BindView;
15 | import butterknife.ButterKnife;
16 |
17 | /**
18 | * Created by WuPuquan on 2017/6/2.
19 | */
20 |
21 | public class SingleLoadingActivity extends AppCompatActivity {
22 |
23 | public static final int NETWORK_ERROR = 0;
24 | public static final int ERROR = 1;
25 | public static final int EMPTY = 2;
26 |
27 | @BindView(R.id.recyclerView)
28 | RecyclerView recyclerView;
29 |
30 | private LoadingController loadingController;
31 |
32 | public static Intent newIntent(Context context) {
33 | Intent intent = new Intent(context, SingleLoadingActivity.class);
34 | return intent;
35 | }
36 |
37 | @Override
38 | protected void onCreate(@Nullable Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_single_loading);
41 | ButterKnife.bind(this);
42 |
43 | request();
44 | }
45 |
46 | private void request() {
47 | loadingController = new LoadingController.Builder(this, recyclerView)
48 | .setLoadingImageResource(R.drawable.loading_frame_anim)
49 | .setLoadingMessage("加载中...")
50 | .setErrorMessage("加载失败,请稍后重试~")
51 | .setErrorImageResoruce(R.drawable.error)
52 | .setEmptyMessage("暂无数据~")
53 | .setOnNetworkErrorRetryClickListener(new LoadingInterface.OnClickListener() {
54 | @Override
55 | public void onClick() {
56 | refresh(ERROR);
57 | }
58 | })
59 | .setOnErrorRetryClickListener("点我重试", new LoadingInterface.OnClickListener() {
60 | @Override
61 | public void onClick() {
62 | refresh(EMPTY);
63 | }
64 | })
65 | .build();
66 |
67 | refresh(NETWORK_ERROR);
68 | }
69 |
70 | private void refresh(final int showTarget) {
71 | loadingController.showLoading();
72 | new Handler().postDelayed(new Runnable() {
73 | @Override
74 | public void run() {
75 | switch (showTarget) {
76 | case NETWORK_ERROR:
77 | loadingController.showNetworkError();
78 | break;
79 | case ERROR:
80 | loadingController.showError();
81 | break;
82 | case EMPTY:
83 | loadingController.showEmpty();
84 | break;
85 | }
86 | }
87 | }, 1000);
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/loading/src/main/java/com/wpq/sample/loading/MultiLoadingActivity.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.loading;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.Handler;
7 | import android.support.annotation.Nullable;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.widget.ImageView;
11 |
12 | import com.wpq.sample.loading.loading.LoadingController;
13 | import com.wpq.sample.loading.loading.LoadingInterface;
14 |
15 | import butterknife.BindView;
16 | import butterknife.ButterKnife;
17 |
18 | /**
19 | * Created by WuPuquan on 2017/6/2.
20 | */
21 |
22 | public class MultiLoadingActivity extends AppCompatActivity {
23 |
24 | public static final int NETWORK_ERROR = 0;
25 | public static final int ERROR = 1;
26 | public static final int EMPTY = 2;
27 | public static final int CONTENT = 3;
28 |
29 | @BindView(R.id.imageView)
30 | ImageView imageView;
31 | @BindView(R.id.recyclerView)
32 | RecyclerView recyclerView;
33 |
34 | private LoadingController videoLoadingController;
35 | private LoadingController listLoadingController;
36 |
37 | public static Intent newIntent(Context context) {
38 | Intent intent = new Intent(context, MultiLoadingActivity.class);
39 | return intent;
40 | }
41 |
42 | @Override
43 | protected void onCreate(@Nullable Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.activity_multi_loading);
46 | ButterKnife.bind(this);
47 |
48 | requestVideo();
49 | requestList();
50 | }
51 |
52 | private void requestVideo() {
53 | videoLoadingController = new LoadingController.Builder(this, imageView)
54 | .setOnErrorRetryClickListener(new LoadingInterface.OnClickListener() {
55 | @Override
56 | public void onClick() {
57 | refreshVideo(CONTENT);
58 | }
59 | })
60 | .build();
61 | refreshVideo(NETWORK_ERROR);
62 | }
63 |
64 | private void refreshVideo(final int target) {
65 | videoLoadingController.showLoading();
66 | new Handler().postDelayed(new Runnable() {
67 | @Override
68 | public void run() {
69 | switch (target) {
70 | case NETWORK_ERROR:
71 | videoLoadingController.showError();
72 | break;
73 | case CONTENT:
74 | videoLoadingController.dismissLoading();
75 | // videoView.
76 | break;
77 | }
78 | }
79 | }, 1500);
80 | }
81 |
82 | private void requestList() {
83 | listLoadingController = new LoadingController.Builder(this, recyclerView)
84 | .setErrorImageResoruce(R.drawable.error)
85 | .setOnNetworkErrorRetryClickListener(new LoadingInterface.OnClickListener() {
86 | @Override
87 | public void onClick() {
88 | refreshList(EMPTY);
89 | }
90 | })
91 | .setEmptyMessage("暂无数据~")
92 | .setOnEmptyTodoClickListener("刷新", new LoadingInterface.OnClickListener() {
93 | @Override
94 | public void onClick() {
95 | refreshList(EMPTY);
96 | }
97 | })
98 | .build();
99 | refreshList(ERROR);
100 | }
101 |
102 | private void refreshList(final int target) {
103 | listLoadingController.showLoading();
104 | new Handler().postDelayed(new Runnable() {
105 | @Override
106 | public void run() {
107 | switch (target) {
108 | case ERROR:
109 | listLoadingController.showNetworkError();
110 | break;
111 | case EMPTY:
112 | listLoadingController.showEmpty();
113 | break;
114 | }
115 | }
116 | }, 1500);
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/loading/src/main/java/com/wpq/sample/loading/loading/LoadingController.java:
--------------------------------------------------------------------------------
1 | package com.wpq.sample.loading.loading;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.graphics.drawable.AnimationDrawable;
6 | import android.graphics.drawable.Drawable;
7 | import android.support.annotation.NonNull;
8 | import android.text.TextUtils;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.Button;
13 | import android.widget.ImageView;
14 | import android.widget.ProgressBar;
15 | import android.widget.TextView;
16 |
17 | import com.wpq.sample.loading.R;
18 |
19 | /**
20 | * @author wpq
21 | * @version 1.0
22 | */
23 | public class LoadingController implements LoadingInterface {
24 |
25 | private Context context;
26 | private View loadingTargetView;
27 | // loading
28 | private int loadingImageResource;
29 | private Drawable loadingImageDrawable;
30 | private String loadingMessage;
31 | // network error
32 |
33 | // other error
34 | private int errorImageResoruce;
35 | private Drawable errorImageDrawable;
36 | private String errorMessage;
37 | // empty
38 | private int emptyViewImageResource;
39 | private Drawable emptyViewImageDrawable;
40 | private String emptyMessage;
41 |
42 | // listener
43 | private String networkErrorRetryText;
44 | private LoadingInterface.OnClickListener onNetworkErrorRetryClickListener;
45 | private String errorRetryText;
46 | private LoadingInterface.OnClickListener onErrorRetryClickListener;
47 | private String emptyTodoText;
48 | private LoadingInterface.OnClickListener onEmptyTodoClickListener;
49 |
50 | private LayoutInflater inflater;
51 | /** {@link #loadingTargetView} 的父布局 */
52 | private ViewGroup parentView;
53 | /** {@link #loadingTargetView} 在父布局中的位置 */
54 | private int currentViewIndex;
55 | /** {@link #loadingTargetView} 的LayoutParams */
56 | private ViewGroup.LayoutParams params;
57 |
58 | private View loadingView;
59 | private AnimationDrawable loadingAnimationDrawable;
60 | private View networkErrorView;
61 | private View errorView;
62 | private View emptyView;
63 |
64 | private LoadingController(Builder builder) {
65 | context = builder.context;
66 | loadingTargetView = builder.loadingTargetView;
67 | loadingImageResource = builder.loadingImageResource;
68 | loadingImageDrawable = builder.loadingImageDrawable;
69 | loadingMessage = builder.loadingMessage;
70 | errorImageResoruce = builder.errorImageResoruce;
71 | errorImageDrawable = builder.errorImageDrawable;
72 | errorMessage = builder.errorMessage;
73 | emptyViewImageResource = builder.emptyViewImageResource;
74 | emptyViewImageDrawable = builder.emptyViewImageDrawable;
75 | emptyMessage = builder.emptyMessage;
76 | networkErrorRetryText = builder.networkErrorRetryText;
77 | onNetworkErrorRetryClickListener = builder.onNetworkErrorRetryClickListener;
78 | errorRetryText = builder.errorRetryText;
79 | onErrorRetryClickListener = builder.onErrorRetryClickListener;
80 | emptyTodoText = builder.emptyTodoText;
81 | onEmptyTodoClickListener = builder.onEmptyTodoClickListener;
82 |
83 | if (builder.customLoadingView != null) {
84 | loadingView = builder.customLoadingView;
85 | }
86 | if (builder.customNetworkErrorView != null) {
87 | networkErrorView = builder.customNetworkErrorView;
88 | }
89 | if (builder.customErrorView != null) {
90 | errorView = builder.customErrorView;
91 | }
92 | if (builder.customEmptyView != null) {
93 | emptyView = builder.customEmptyView;
94 | }
95 |
96 | init();
97 | }
98 |
99 | private void init() {
100 | inflater = LayoutInflater.from(context);
101 | params = loadingTargetView.getLayoutParams();
102 | if (loadingTargetView.getParent() != null) {
103 | parentView = (ViewGroup) loadingTargetView.getParent();
104 | } else {
105 | parentView = (ViewGroup) loadingTargetView.getRootView().findViewById(android.R.id.content);
106 | }
107 | int count = parentView.getChildCount();
108 | for (int i = 0; i < count; i++) {
109 | if (loadingTargetView == parentView.getChildAt(i)) {
110 | currentViewIndex = i;
111 | break;
112 | }
113 | }
114 | }
115 |
116 | /**
117 | * 切换状态
118 | * @param view 目标View
119 | */
120 | private void showView(View view) {
121 | // 如果当前状态和要切换的状态相同,则不做处理,反之切换
122 | if (parentView.getChildAt(currentViewIndex) != view) {
123 | // 先把view从父布局移除
124 | ViewGroup viewParent = (ViewGroup) view.getParent();
125 | if (viewParent != null) {
126 | viewParent.removeView(view);
127 | }
128 | parentView.removeViewAt(currentViewIndex);
129 | parentView.addView(view, currentViewIndex, params);
130 | if (loadingAnimationDrawable != null) {
131 | if (view == loadingView) {
132 | loadingAnimationDrawable.start();
133 | } else {
134 | loadingAnimationDrawable.stop();
135 | }
136 | }
137 | }
138 | }
139 |
140 | @SuppressLint("InflateParams")
141 | @Override
142 | public void showLoading() {
143 | if (loadingView != null) {
144 | showView(loadingView);
145 | return;
146 | }
147 | loadingView = inflater.inflate(R.layout.loading, null);
148 | ProgressBar pbLoading = (ProgressBar) loadingView.findViewById(R.id.pb_loading);
149 | ImageView ivLoading = (ImageView) loadingView.findViewById(R.id.iv_loading);
150 | TextView tvLoadingMessage = (TextView) loadingView.findViewById(R.id.tv_loadingMessage);
151 | pbLoading.setVisibility(View.GONE);
152 | ivLoading.setVisibility(View.GONE);
153 | tvLoadingMessage.setVisibility(View.GONE);
154 |
155 | if (loadingImageResource != 0) {
156 | ivLoading.setVisibility(View.VISIBLE);
157 | ivLoading.setImageResource(loadingImageResource);
158 | Drawable imageDrawable = ivLoading.getDrawable();
159 | if (imageDrawable instanceof AnimationDrawable) {
160 | loadingAnimationDrawable = (AnimationDrawable) imageDrawable;
161 | }
162 | } else if (loadingImageDrawable != null) {
163 | ivLoading.setVisibility(View.VISIBLE);
164 | ivLoading.setImageDrawable(loadingImageDrawable);
165 | Drawable imageDrawable = ivLoading.getDrawable();
166 | if (imageDrawable instanceof AnimationDrawable) {
167 | loadingAnimationDrawable = (AnimationDrawable) imageDrawable;
168 | }
169 | } else {
170 | pbLoading.setVisibility(View.VISIBLE);
171 | }
172 |
173 | if (!TextUtils.isEmpty(loadingMessage)) {
174 | tvLoadingMessage.setVisibility(View.VISIBLE);
175 | tvLoadingMessage.setText(loadingMessage);
176 | }
177 |
178 | showView(loadingView);
179 | }
180 |
181 | @SuppressLint("InflateParams")
182 | @Override
183 | public void showNetworkError() {
184 | if (networkErrorView != null) {
185 | showView(networkErrorView);
186 | return;
187 | }
188 | networkErrorView = inflater.inflate(R.layout.error, null);
189 | TextView tvNetworkErrorMessage = (TextView) networkErrorView.findViewById(R.id.tv_errorMessage);
190 | Button btnRetry = (Button) networkErrorView.findViewById(R.id.btn_retry);
191 |
192 | tvNetworkErrorMessage.setText(context.getResources().getString(R.string.LoadingController_network_error_message));
193 |
194 | if (!TextUtils.isEmpty(networkErrorRetryText)) {
195 | btnRetry.setText(networkErrorRetryText);
196 | }
197 | if (onNetworkErrorRetryClickListener != null) {
198 | btnRetry.setOnClickListener(new View.OnClickListener() {
199 | @Override
200 | public void onClick(View v) {
201 | onNetworkErrorRetryClickListener.onClick();
202 | }
203 | });
204 | }
205 |
206 | showView(networkErrorView);
207 | }
208 |
209 | @SuppressLint("InflateParams")
210 | @Override
211 | public void showError() {
212 | if (errorView != null) {
213 | showView(errorView);
214 | return;
215 | }
216 | errorView = inflater.inflate(R.layout.error, null);
217 | ImageView ivError = (ImageView) errorView.findViewById(R.id.iv_error);
218 | TextView tvErrorMessage = (TextView) errorView.findViewById(R.id.tv_errorMessage);
219 | Button btnRetry = (Button) errorView.findViewById(R.id.btn_retry);
220 |
221 | ivError.setImageResource(R.drawable.error);
222 | if (errorImageResoruce != 0){
223 | ivError.setImageResource(errorImageResoruce);
224 | } else if (errorImageDrawable != null) {
225 | ivError.setImageDrawable(errorImageDrawable);
226 | }
227 |
228 | if (!TextUtils.isEmpty(errorMessage)) {
229 | tvErrorMessage.setText(errorMessage);
230 | } else {
231 | tvErrorMessage.setText(context.getResources().getString(R.string.LoadingController_error_message));
232 | }
233 |
234 | if (!TextUtils.isEmpty(errorRetryText)) {
235 | btnRetry.setText(errorRetryText);
236 | }
237 | if (onErrorRetryClickListener != null) {
238 | btnRetry.setOnClickListener(new View.OnClickListener() {
239 | @Override
240 | public void onClick(View v) {
241 | onErrorRetryClickListener.onClick();
242 | }
243 | });
244 | }
245 |
246 | showView(errorView);
247 | }
248 |
249 | @SuppressLint("InflateParams")
250 | @Override
251 | public void showEmpty() {
252 | if (emptyView != null) {
253 | showView(emptyView);
254 | return;
255 | }
256 | emptyView = inflater.inflate(R.layout.error, null);
257 | ImageView ivEmpty = (ImageView) emptyView.findViewById(R.id.iv_error);
258 | TextView tvEmptyMessage = (TextView) emptyView.findViewById(R.id.tv_errorMessage);
259 | Button btnTodo = (Button) emptyView.findViewById(R.id.btn_retry);
260 | ivEmpty.setVisibility(View.GONE);
261 | tvEmptyMessage.setVisibility(View.GONE);
262 | btnTodo.setVisibility(View.GONE);
263 |
264 | if (emptyViewImageResource != 0){
265 | ivEmpty.setVisibility(View.VISIBLE);
266 | ivEmpty.setImageResource(emptyViewImageResource);
267 | } else if (emptyViewImageDrawable != null) {
268 | ivEmpty.setVisibility(View.VISIBLE);
269 | ivEmpty.setImageDrawable(emptyViewImageDrawable);
270 | }
271 |
272 | if (!TextUtils.isEmpty(emptyMessage)) {
273 | tvEmptyMessage.setVisibility(View.VISIBLE);
274 | tvEmptyMessage.setText(emptyMessage);
275 | }
276 |
277 | if (!TextUtils.isEmpty(emptyTodoText)) {
278 | btnTodo.setVisibility(View.VISIBLE);
279 | btnTodo.setText(emptyTodoText);
280 | }
281 | if (onEmptyTodoClickListener != null) {
282 | btnTodo.setOnClickListener(new View.OnClickListener() {
283 | @Override
284 | public void onClick(View v) {
285 | onEmptyTodoClickListener.onClick();
286 | }
287 | });
288 | }
289 |
290 | showView(emptyView);
291 | }
292 |
293 | @Override
294 | public void dismissLoading() {
295 | showView(loadingTargetView);
296 | }
297 |
298 | public static class Builder{
299 |
300 | private Context context;
301 | private View loadingTargetView;
302 | // qlk_loading
303 | private int loadingImageResource;
304 | private Drawable loadingImageDrawable;
305 | private String loadingMessage;
306 | private View customLoadingView;
307 | // network qlk_loading_result
308 | private View customNetworkErrorView;
309 |
310 | // normal qlk_loading_result
311 | private int errorImageResoruce;
312 | private Drawable errorImageDrawable;
313 | private String errorMessage;
314 | private View customErrorView;
315 | // empty
316 | private int emptyViewImageResource;
317 | private Drawable emptyViewImageDrawable;
318 | private String emptyMessage;
319 | private View customEmptyView;
320 |
321 | // listener
322 | private String networkErrorRetryText;
323 | private LoadingInterface.OnClickListener onNetworkErrorRetryClickListener;
324 | private String errorRetryText;
325 | private LoadingInterface.OnClickListener onErrorRetryClickListener;
326 | private String emptyTodoText;
327 | private LoadingInterface.OnClickListener onEmptyTodoClickListener;
328 |
329 | public Builder(@NonNull Context context, @NonNull View loadingTargetView) {
330 | this.context = context;
331 | this.loadingTargetView = loadingTargetView;
332 | }
333 |
334 | public Builder setLoadingImageResource(int loadingImageResource) {
335 | this.loadingImageResource = loadingImageResource;
336 | return this;
337 | }
338 |
339 | public Builder setLoadingImageDrawable(Drawable loadingImageDrawable) {
340 | this.loadingImageDrawable = loadingImageDrawable;
341 | return this;
342 | }
343 |
344 | public Builder setLoadingMessage(String loadingMessage) {
345 | this.loadingMessage = loadingMessage;
346 | return this;
347 | }
348 |
349 | /**
350 | * 自定义loadingView
351 | * @param loadingView view for loading
352 | * @return this Builder
353 | */
354 | public Builder setLoadingView(View loadingView) {
355 | this.customLoadingView = loadingView;
356 | return this;
357 | }
358 |
359 | /**
360 | * 自定义networkErrorView
361 | * @param networkErrorView view for networkError
362 | * @return this Builder
363 | */
364 | public Builder setNetworkErrorView(View networkErrorView) {
365 | this.customNetworkErrorView = networkErrorView;
366 | return this;
367 | }
368 |
369 | public Builder setErrorImageResoruce(int errorImageResoruce) {
370 | this.errorImageResoruce = errorImageResoruce;
371 | return this;
372 | }
373 |
374 | public Builder setErrorImageDrawable(Drawable errorImageDrawable) {
375 | this.errorImageDrawable = errorImageDrawable;
376 | return this;
377 | }
378 |
379 | public Builder setErrorMessage(String errorMessage) {
380 | this.errorMessage = errorMessage;
381 | return this;
382 | }
383 |
384 | /**
385 | * 自定义errorView
386 | * @param errorView view for error
387 | * @return this Builder
388 | */
389 | public Builder setErrorView(View errorView) {
390 | this.customErrorView = errorView;
391 | return this;
392 | }
393 |
394 | public Builder setEmptyViewImageResource(int emptyViewImageResource) {
395 | this.emptyViewImageResource = emptyViewImageResource;
396 | return this;
397 | }
398 |
399 | public Builder setEmptyViewImageDrawable(Drawable emptyViewImageDrawable) {
400 | this.emptyViewImageDrawable = emptyViewImageDrawable;
401 | return this;
402 | }
403 |
404 | public Builder setEmptyMessage(String emptyMessage) {
405 | this.emptyMessage = emptyMessage;
406 | return this;
407 | }
408 |
409 | /**
410 | * 自定义emptyView
411 | * @param emptyView view for empty
412 | * @return this Builder
413 | */
414 | public Builder setEmptyView(View emptyView) {
415 | this.customEmptyView = emptyView;
416 | return this;
417 | }
418 |
419 | public Builder setOnNetworkErrorRetryClickListener(LoadingInterface.OnClickListener listener) {
420 | this.onNetworkErrorRetryClickListener = listener;
421 | return this;
422 | }
423 |
424 | public Builder setOnNetworkErrorRetryClickListener(String networkErrorRetryText, LoadingInterface.OnClickListener listener) {
425 | this.networkErrorRetryText = networkErrorRetryText;
426 | this.onNetworkErrorRetryClickListener = listener;
427 | return this;
428 | }
429 |
430 | public Builder setOnErrorRetryClickListener(LoadingInterface.OnClickListener listener) {
431 | this.onErrorRetryClickListener = listener;
432 | return this;
433 | }
434 |
435 | public Builder setOnErrorRetryClickListener(String errorRetryText, LoadingInterface.OnClickListener listener) {
436 | this.errorRetryText = errorRetryText;
437 | this.onErrorRetryClickListener = listener;
438 | return this;
439 | }
440 |
441 | public Builder setOnEmptyTodoClickListener(LoadingInterface.OnClickListener listener) {
442 | this.onEmptyTodoClickListener = listener;
443 | return this;
444 | }
445 |
446 | public Builder setOnEmptyTodoClickListener(String emptyTodoText, LoadingInterface.OnClickListener listener) {
447 | this.emptyTodoText = emptyTodoText;
448 | this.onEmptyTodoClickListener = listener;
449 | return this;
450 | }
451 |
452 | public LoadingController build() {
453 | return new LoadingController(this);
454 | }
455 |
456 | }
457 | }
458 |
--------------------------------------------------------------------------------