├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── ic_loading.png
│ │ │ │ ├── ic_loading_empty.png
│ │ │ │ ├── ic_loading_error.png
│ │ │ │ ├── ic_loading_login.png
│ │ │ │ └── ic_loading_no_net.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-xxhdpi
│ │ │ │ ├── game_ic_loading_1.webp
│ │ │ │ ├── game_ic_loading_10.webp
│ │ │ │ ├── game_ic_loading_11.webp
│ │ │ │ ├── game_ic_loading_12.webp
│ │ │ │ ├── game_ic_loading_13.webp
│ │ │ │ ├── game_ic_loading_14.webp
│ │ │ │ ├── game_ic_loading_15.webp
│ │ │ │ ├── game_ic_loading_16.webp
│ │ │ │ ├── game_ic_loading_17.webp
│ │ │ │ ├── game_ic_loading_18.webp
│ │ │ │ ├── game_ic_loading_19.webp
│ │ │ │ ├── game_ic_loading_2.webp
│ │ │ │ ├── game_ic_loading_20.webp
│ │ │ │ ├── game_ic_loading_21.webp
│ │ │ │ ├── game_ic_loading_22.webp
│ │ │ │ ├── game_ic_loading_23.webp
│ │ │ │ ├── game_ic_loading_24.webp
│ │ │ │ ├── game_ic_loading_25.webp
│ │ │ │ ├── game_ic_loading_26.webp
│ │ │ │ ├── game_ic_loading_27.webp
│ │ │ │ ├── game_ic_loading_28.webp
│ │ │ │ ├── game_ic_loading_3.webp
│ │ │ │ ├── game_ic_loading_30.webp
│ │ │ │ ├── game_ic_loading_31.webp
│ │ │ │ ├── game_ic_loading_32.webp
│ │ │ │ ├── game_ic_loading_33.webp
│ │ │ │ ├── game_ic_loading_34.webp
│ │ │ │ ├── game_ic_loading_35.webp
│ │ │ │ ├── game_ic_loading_36.webp
│ │ │ │ ├── game_ic_loading_37.webp
│ │ │ │ ├── game_ic_loading_38.webp
│ │ │ │ ├── game_ic_loading_4.webp
│ │ │ │ ├── game_ic_loading_5.webp
│ │ │ │ ├── game_ic_loading_6.webp
│ │ │ │ ├── game_ic_loading_7.webp
│ │ │ │ ├── game_ic_loading_8.webp
│ │ │ │ ├── game_ic_loading_9.webp
│ │ │ │ └── page_status_demo_loading.gif
│ │ │ ├── layout
│ │ │ │ ├── view_custom_loading.xml
│ │ │ │ ├── activity_single_page_more_state.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── view_custom_error.xml
│ │ │ │ ├── activity_simple.xml
│ │ │ │ └── activity_coordinatorlayout.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ ├── game_anim_loading.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── smartcity
│ │ │ └── commonbase
│ │ │ └── widget
│ │ │ └── pagestatus
│ │ │ └── test
│ │ │ ├── FaceLoadingView.java
│ │ │ ├── CoordinatorLayoutActivity.java
│ │ │ ├── LoadingGifView.java
│ │ │ ├── MainActivity.java
│ │ │ ├── SinglePageMoreStateActivity.java
│ │ │ ├── SimpleActivity.java
│ │ │ └── Custom1Activity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── smartcity
│ │ │ └── commonbase
│ │ │ └── widget
│ │ │ └── pagestatus
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── smartcity
│ │ └── commonbase
│ │ └── widget
│ │ └── pagestatus
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── pagestatushelper
├── .gitignore
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── smartcity
│ │ │ └── commonbase
│ │ │ └── widget
│ │ │ └── pagestatus
│ │ │ ├── OnEmptyClickListener.java
│ │ │ ├── OnErrorClickListener.java
│ │ │ ├── OnNoLoginClickListener.java
│ │ │ ├── imp
│ │ │ ├── FrameLayoutViewStatusImp.java
│ │ │ ├── ViewStatusInterface.java
│ │ │ ├── RelativeLayoutViewStatusImp.java
│ │ │ ├── LinearLayoutViewStatusImp.java
│ │ │ ├── ViewGroupViewStatusImp.java
│ │ │ └── ConstraintLayoutViewStatusImp.java
│ │ │ ├── LayoutParams.java
│ │ │ ├── ViewStatusController.java
│ │ │ ├── ColorUtils.java
│ │ │ ├── ViewUtils.java
│ │ │ ├── PageStatusHelper.java
│ │ │ └── Builder.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── smartcity
│ │ │ └── commonbase
│ │ │ └── widget
│ │ │ └── pagestatus
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── smartcity
│ │ └── commonbase
│ │ └── widget
│ │ └── pagestatus
│ │ └── ExampleInstrumentedTest.java
├── push.gradle
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gif
├── simple1.gif
├── simple2.gif
├── simple3.gif
└── simple4.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/pagestatushelper/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':pagestatushelper'
--------------------------------------------------------------------------------
/gif/simple1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/gif/simple1.gif
--------------------------------------------------------------------------------
/gif/simple2.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/gif/simple2.gif
--------------------------------------------------------------------------------
/gif/simple3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/gif/simple3.gif
--------------------------------------------------------------------------------
/gif/simple4.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/gif/simple4.gif
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PageStatusHelper
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xhdpi/ic_loading.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_loading_empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xhdpi/ic_loading_empty.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_loading_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xhdpi/ic_loading_error.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_loading_login.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xhdpi/ic_loading_login.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_loading_no_net.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xhdpi/ic_loading_no_net.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_1.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_1.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_10.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_10.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_11.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_11.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_12.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_12.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_13.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_13.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_14.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_14.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_15.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_15.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_16.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_16.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_17.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_17.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_18.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_18.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_19.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_19.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_2.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_2.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_20.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_20.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_21.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_21.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_22.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_22.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_23.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_23.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_24.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_24.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_25.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_25.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_26.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_26.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_27.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_27.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_28.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_28.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_3.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_3.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_30.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_30.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_31.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_31.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_32.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_32.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_33.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_33.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_34.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_34.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_35.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_35.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_36.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_36.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_37.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_37.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_38.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_38.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_4.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_4.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_5.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_5.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_6.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_6.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_7.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_7.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_8.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_8.webp
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/game_ic_loading_9.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/game_ic_loading_9.webp
--------------------------------------------------------------------------------
/pagestatushelper/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/page_status_demo_loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/YuJunKui1995/PageStatusHelper/HEAD/app/src/main/res/drawable-xxhdpi/page_status_demo_loading.gif
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 30dp
5 | 10dp
6 | 10dp
7 |
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jul 04 14:15:51 CST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_custom_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/OnEmptyClickListener.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Created by ychen on 2018/8/13.
7 | */
8 | public interface OnEmptyClickListener {
9 | void onEmptyClick(View v);
10 | }
11 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/OnErrorClickListener.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Author: YuJunKui
7 | * Time:2017/12/8 16:03
8 | * Tips:
9 | */
10 |
11 | public interface OnErrorClickListener {
12 |
13 | void onErrorClick(View v);
14 | }
15 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/OnNoLoginClickListener.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Author: YuJunKui
7 | * Time:2017/12/15 15:28
8 | * Tips:
9 | */
10 |
11 | public interface OnNoLoginClickListener {
12 |
13 | void OnNoLoginClick(View v);
14 | }
15 |
--------------------------------------------------------------------------------
/pagestatushelper/src/test/java/com/smartcity/commonbase/widget/pagestatus/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
2 |
3 |
4 |
5 | /**
6 | * Example local unit test, which will execute on the development machine (host).
7 | *
8 | * @see Testing documentation
9 | */
10 | public class ExampleUnitTest {
11 | }
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/imp/FrameLayoutViewStatusImp.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.imp;
2 |
3 | import android.view.ViewGroup;
4 |
5 | /**
6 | * Author: YuJunKui
7 | * Time:2017/12/8 10:57
8 | * Tips:
9 | */
10 |
11 | public class FrameLayoutViewStatusImp extends ViewGroupViewStatusImp {
12 |
13 | @Override
14 | protected void initLayoutParams(ViewGroup.LayoutParams layoutParams) {
15 | //nothing 基类的处理已经足够了
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/test/java/com/smartcity/commonbase/widget/pagestatus/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/imp/ViewStatusInterface.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.imp;
2 |
3 | import android.view.View;
4 |
5 | import com.smartcity.commonbase.widget.pagestatus.LayoutParams;
6 |
7 | /**
8 | * Author: YuJunKui
9 | * Time:2017/12/8 10:55
10 | * Tips:
11 | */
12 |
13 | public interface ViewStatusInterface {
14 |
15 | String ADD_View_TAG="add_view_tag";
16 |
17 | void addStatusView(View bindView, View addView, LayoutParams params);
18 |
19 | void showContentView();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/pagestatushelper/push.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.novoda.bintray-release'
2 |
3 | def siteUrl = 'https://github.com/YuJunKui1995/PageStatusHelper'
4 |
5 | publish{
6 | repoName = 'HouShanRen'
7 | userOrg = "yujkyujk"
8 | groupId = 'firemonkey'
9 | artifactId = 'pagestatushelper'
10 | publishVersion = '1.0.0'
11 | desc = 'Simple and elegant management of page status .'
12 | website = siteUrl
13 | }
14 | tasks.withType(Javadoc) {//防止编码问题
15 | options.addStringOption('Xdoclint:none', '-quiet')
16 | options.addStringOption('encoding', 'UTF-8')
17 | options.addStringOption('charSet', 'UTF-8')
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/pagestatushelper/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_single_page_more_state.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
16 |
17 |
18 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/smartcity/commonbase/widget/pagestatus/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
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 | * Instrumented 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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.smartcity.commonbase.widget.pagestatus", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/pagestatushelper/src/androidTest/java/com/smartcity/commonbase/widget/pagestatus/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
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 | * Instrumented 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() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.smartcity.commonbase.widget.pagestatus.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/imp/RelativeLayoutViewStatusImp.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.imp;
2 |
3 | import android.view.ViewGroup;
4 | import android.widget.RelativeLayout;
5 |
6 | /**
7 | * Author: YuJunKui
8 | * Time:2017/12/8 10:57
9 | * Tips:
10 | */
11 |
12 | public class RelativeLayoutViewStatusImp extends ViewGroupViewStatusImp {
13 |
14 | @Override
15 | protected void initLayoutParams(ViewGroup.LayoutParams layoutParams) {
16 |
17 | //状态view的params
18 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) layoutParams;
19 | //bindView的
20 | RelativeLayout.LayoutParams bindViewParams = (RelativeLayout.LayoutParams) bindView.getLayoutParams();
21 |
22 | //bindView的对齐关系
23 | int[] rules = bindViewParams.getRules();
24 | for (int i = 0; i < rules.length; i++) {
25 | params.addRule(i, rules[i]);
26 | }
27 | // ok
28 |
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/pagestatushelper/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply from: 'push.gradle'
3 | //apply from: 'push2.gradle'
4 | android {
5 | compileSdkVersion 27
6 |
7 |
8 |
9 | defaultConfig {
10 | minSdkVersion 19
11 | targetSdkVersion 27
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | lintOptions {
18 | abortOnError false
19 | }
20 | }
21 |
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 |
29 | }
30 |
31 | dependencies {
32 | implementation fileTree(include: ['*.jar'], dir: 'libs')
33 | implementation 'com.android.support:appcompat-v7:27.1.1'
34 |
35 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
36 |
37 | implementation 'com.android.support:design:27.1.1'
38 | }
39 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/imp/LinearLayoutViewStatusImp.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.imp;
2 |
3 | import android.util.Log;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.view.ViewTreeObserver;
7 | import android.widget.LinearLayout;
8 |
9 | import com.smartcity.commonbase.widget.pagestatus.LayoutParams;
10 | import com.smartcity.commonbase.widget.pagestatus.ViewUtils;
11 |
12 | /**
13 | * Author: YuJunKui
14 | * Time:2017/12/8 10:57
15 | * Tips: LinearLayoutView和ViewGroupView 存在两点差异
16 | * 1、LinearLayoutView的bindView不能INVISIBLE
17 | */
18 |
19 | public class LinearLayoutViewStatusImp extends ViewGroupViewStatusImp {
20 |
21 | private static final String TAG = "LinearLayoutViewStatusI";
22 |
23 | @Override
24 | protected void initLayoutParams(ViewGroup.LayoutParams layoutParams) {
25 | //nothing 基类的处理已经足够了
26 | }
27 |
28 | @Override
29 | public void hideContent(View bindView) {
30 | bindView.setVisibility(View.GONE);
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smartcity/commonbase/widget/pagestatus/test/FaceLoadingView.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.test;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.graphics.drawable.AnimationDrawable;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.widget.AppCompatImageView;
8 | import android.util.AttributeSet;
9 |
10 | /**
11 | * Author: YuJunKui
12 | * Time:2018/5/26 11:42
13 | * Tips:
14 | */
15 | public class FaceLoadingView extends AppCompatImageView {
16 |
17 | public FaceLoadingView(Context context) {
18 | this(context, null);
19 | }
20 |
21 | public FaceLoadingView(Context context, @Nullable AttributeSet attrs) {
22 | this(context, attrs, -1);
23 | }
24 |
25 | public FaceLoadingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
26 | super(context, attrs, defStyleAttr);
27 | setBackgroundColor(Color.WHITE);
28 | setImageResource(R.drawable.game_anim_loading);
29 | ((AnimationDrawable) this.getDrawable()).start();
30 | }
31 |
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
18 |
19 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/.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/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/dictionaries
41 | .idea/libraries
42 |
43 | # Keystore files
44 | # Uncomment the following line if you do not want to check your keystore files in.
45 | #*.jks
46 |
47 | # External native build folder generated in Android Studio 2.2 and later
48 | .externalNativeBuild
49 |
50 | # Google Services (e.g. APIs or Firebase)
51 | google-services.json
52 |
53 | # Freeline
54 | freeline.py
55 | freeline/
56 | freeline_project_description.json
57 | *.ser
58 | .idea/codeStyles/Project.xml
59 | .idea/encodings.xml
60 | .idea/misc.xml
61 | .idea/modules.xml
62 | .idea/runConfigurations.xml
63 | .idea/vcs.xml
64 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.smartcity.commonbase.widget.pagestatus.test"
7 | minSdkVersion 19
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | compileOptions {
20 | sourceCompatibility JavaVersion.VERSION_1_8
21 | targetCompatibility JavaVersion.VERSION_1_8
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(include: ['*.jar'], dir: 'libs')
27 | implementation 'com.android.support:appcompat-v7:27.1.1'
28 | implementation 'com.android.support:design:27.1.1'
29 | implementation 'com.android.support.constraint:constraint-layout:1.1.0'
30 | testImplementation 'junit:junit:4.12'
31 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
33 | implementation project(':pagestatushelper')
34 | // api 'common:pagestatushelper:0.7.3'
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
25 |
26 |
31 |
32 |
37 |
38 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smartcity/commonbase/widget/pagestatus/test/CoordinatorLayoutActivity.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.test;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import com.smartcity.commonbase.widget.pagestatus.PageStatusHelper;
9 |
10 | /**
11 | * Author: YuJunKui
12 | * Time:2019/2/1 17:08
13 | * Tips:
14 | */
15 | public class CoordinatorLayoutActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(@Nullable Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 |
21 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
22 | getSupportActionBar().setDisplayShowHomeEnabled(true);
23 | getSupportActionBar().setDisplayShowTitleEnabled(true);
24 | getSupportActionBar().setDisplayUseLogoEnabled(false);
25 | getSupportActionBar().setTitle("CoordinatorLayout效果");
26 | setContentView(R.layout.activity_coordinatorlayout);
27 |
28 | View bindView=findViewById(R.id.rv_content);
29 | PageStatusHelper pageStatusHelper=new PageStatusHelper(this);
30 | pageStatusHelper.bindView(bindView);
31 |
32 | bindView.postDelayed(() -> pageStatusHelper.refreshPageStatus(PageStatusHelper.LOADING),200);
33 |
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smartcity/commonbase/widget/pagestatus/test/LoadingGifView.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.test;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.content.Context;
5 | import android.support.v7.widget.AppCompatImageView;
6 | import android.util.AttributeSet;
7 | import android.view.animation.Animation;
8 |
9 | import com.smartcity.commonbase.widget.pagestatus.ViewUtils;
10 |
11 | /**
12 | * Author: YuJunKui
13 | * Time:2018/10/7 16:25
14 | * Tips:
15 | */
16 | public class LoadingGifView extends AppCompatImageView {
17 |
18 | public LoadingGifView(Context context) {
19 | this(context, null);
20 | }
21 |
22 | public LoadingGifView(Context context, AttributeSet attrs) {
23 | this(context, attrs, -1);
24 | }
25 |
26 | public LoadingGifView(Context context, AttributeSet attrs, int defStyleAttr) {
27 | super(context, attrs, defStyleAttr);
28 | setImageResource(R.drawable.ic_loading);
29 | ObjectAnimator animator = ObjectAnimator.ofFloat(this, "rotation", 0, 360);
30 | animator.setDuration(1000);
31 | animator.setRepeatCount(Animation.INFINITE);
32 | animator.start();
33 | }
34 |
35 | @Override
36 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
37 | int width = ViewUtils.dip2px(getContext(), 80);
38 | setMeasuredDimension(width + getPaddingLeft() + getPaddingRight(), width + getPaddingTop() + getPaddingBottom());
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_custom_error.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
19 |
20 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smartcity/commonbase/widget/pagestatus/test/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.test;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | public class MainActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
14 | getSupportActionBar().setDisplayShowHomeEnabled(true);
15 | getSupportActionBar().setDisplayShowTitleEnabled(true);
16 | getSupportActionBar().setDisplayUseLogoEnabled(false);
17 | getSupportActionBar().setTitle("PageStatusHelper");
18 | setContentView(R.layout.activity_main);
19 | }
20 |
21 |
22 | public void onClick(View v) {
23 |
24 | switch (v.getId()) {
25 |
26 | case R.id.btn_simple1:
27 |
28 | startActivity(new Intent(this, SimpleActivity.class));
29 | break;
30 | case R.id.btn_simple2:
31 |
32 | startActivity(new Intent(this, SinglePageMoreStateActivity.class));
33 | break;
34 | case R.id.btn_simple3:
35 |
36 | startActivity(new Intent(this, Custom1Activity.class));
37 | break;
38 |
39 | case R.id.btn_simple6:
40 |
41 | startActivity(new Intent(this, CoordinatorLayoutActivity.class));
42 | break;
43 | }
44 |
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/LayoutParams.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
2 |
3 | import android.view.View;
4 | import android.view.ViewGroup;
5 |
6 | /**
7 | * Author: YuJunKui
8 | * Time:2018/1/16 15:30
9 | * Tips:
10 | */
11 |
12 | public class LayoutParams {
13 |
14 |
15 | public int paddingLeft;
16 | public int paddingTop;
17 | public int paddingRight;
18 | public int paddingBottom;
19 |
20 | public int leftMargin;
21 | public int topMargin;
22 | public int rightMargin;
23 | public int bottomMargin;
24 |
25 | public int imageWidth = ViewGroup.LayoutParams.WRAP_CONTENT;
26 | public int imageHeight = ViewGroup.LayoutParams.WRAP_CONTENT;
27 |
28 | public boolean centerInParent;
29 |
30 | public void setPadding(int left, int top, int right, int bottom) {
31 | paddingLeft = left;
32 | paddingTop = top;
33 | paddingRight = right;
34 | paddingBottom = bottom;
35 | }
36 |
37 | /**
38 | * 只有在图片模式下才有用
39 | *
40 | * @param imageWidth
41 | * @param imageHeight
42 | */
43 | public LayoutParams(int imageWidth, int imageHeight) {
44 | this();
45 | this.imageWidth = imageWidth;
46 | this.imageHeight = imageHeight;
47 | }
48 |
49 | public void setWidth(int imageWidth) {
50 | this.imageWidth = imageWidth;
51 | }
52 |
53 | public void setHeight(int imageHeight) {
54 | this.imageHeight = imageHeight;
55 | }
56 |
57 | public LayoutParams() {
58 | centerInParent=true;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smartcity/commonbase/widget/pagestatus/test/SinglePageMoreStateActivity.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.test;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.widget.TextView;
7 |
8 | import com.smartcity.commonbase.widget.pagestatus.PageStatusHelper;
9 |
10 | /**
11 | * Author: YuJunKui
12 | * Time:2018/10/7 15:41
13 | * Tips: 一个页面存在多个接口 需要多个加载状态
14 | *
15 | * 这个页面会有一个有意思的玩意
16 | * 状态的文字会自动设置颜色,是根据取bindView的颜色做颜色反转, 来实现颜色不用主动设置
17 | * 如果需要主动设置 可以通过Helper.getBuilder().setTextColor()
18 | */
19 | public class SinglePageMoreStateActivity extends AppCompatActivity {
20 |
21 |
22 | @Override
23 | protected void onCreate(@Nullable Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
26 | getSupportActionBar().setDisplayShowHomeEnabled(true);
27 | getSupportActionBar().setDisplayShowTitleEnabled(true);
28 | getSupportActionBar().setDisplayUseLogoEnabled(false);
29 | getSupportActionBar().setTitle("一个页面存在多个接口");
30 | setContentView(R.layout.activity_single_page_more_state);
31 |
32 | //模拟的第一个列表
33 | TextView tvList1 = findViewById(R.id.tv_list1);
34 |
35 | PageStatusHelper list1StatusHelper = new PageStatusHelper(this);
36 | list1StatusHelper.bindView(tvList1);
37 | //加载中
38 | list1StatusHelper.refreshPageStatus(PageStatusHelper.LOADING);
39 |
40 | //第二个列表也需要加载状态维护
41 | TextView tvList2 = findViewById(R.id.tv_list2);
42 |
43 | PageStatusHelper list2StatusHelper = new PageStatusHelper(this);
44 | list2StatusHelper.bindView(tvList2);
45 | list2StatusHelper.setOnErrorClickListener(v -> {
46 | //you load again
47 | loadList2(tvList2, list2StatusHelper);
48 | });
49 |
50 | //加载中
51 | list2StatusHelper.refreshPageStatus(PageStatusHelper.LOADING);
52 | loadList2(tvList2, list2StatusHelper);
53 |
54 |
55 | }
56 |
57 | private void loadList2(TextView tvList2, PageStatusHelper list2StatusHelper) {
58 | //模拟第二个列表加载失败
59 | tvList2.postDelayed(new Runnable() {
60 | @Override
61 | public void run() {
62 | list2StatusHelper.refreshPageStatus(PageStatusHelper.ERROR);
63 | }
64 | }, 2500);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/ViewStatusController.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
2 |
3 | import android.support.constraint.ConstraintLayout;
4 | import android.support.v4.view.ViewPager;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.FrameLayout;
8 | import android.widget.LinearLayout;
9 | import android.widget.RelativeLayout;
10 | import android.widget.ScrollView;
11 |
12 | import com.smartcity.commonbase.widget.pagestatus.imp.ConstraintLayoutViewStatusImp;
13 | import com.smartcity.commonbase.widget.pagestatus.imp.FrameLayoutViewStatusImp;
14 | import com.smartcity.commonbase.widget.pagestatus.imp.LinearLayoutViewStatusImp;
15 | import com.smartcity.commonbase.widget.pagestatus.imp.RelativeLayoutViewStatusImp;
16 | import com.smartcity.commonbase.widget.pagestatus.imp.ViewGroupViewStatusImp;
17 | import com.smartcity.commonbase.widget.pagestatus.imp.ViewStatusInterface;
18 |
19 | /**
20 | * Author: YuJunKui
21 | * Time:2017/12/8 10:38
22 | * Tips:
23 | */
24 |
25 | public class ViewStatusController {
26 |
27 | private ViewStatusInterface viewStatusInterface;
28 |
29 | public void showViewStatus(View bindView, View addView, LayoutParams params) {
30 |
31 | //理论上只有有一次成立
32 |
33 | if (viewStatusInterface==null) {
34 |
35 | ViewGroup parent = (ViewGroup) bindView.getParent();
36 |
37 | if (parent instanceof RelativeLayout) {
38 |
39 | viewStatusInterface = new RelativeLayoutViewStatusImp();
40 | } else if (parent instanceof LinearLayout) {
41 |
42 | viewStatusInterface = new LinearLayoutViewStatusImp();
43 | } else if (parent instanceof FrameLayout) {
44 |
45 | viewStatusInterface = new FrameLayoutViewStatusImp();
46 | } else if (parent instanceof ConstraintLayout) {
47 |
48 | viewStatusInterface = new ConstraintLayoutViewStatusImp();
49 | } else if (parent instanceof ViewPager || parent instanceof ScrollView) {
50 |
51 | throw new RuntimeException("不支持直属父布局为" + parent.getClass().getSimpleName() + "使用PageStatusHelper,解决方案暂为在 binview外套一层布局");
52 | } else {
53 | // throw new RuntimeException("不支持" + bindView.getParent().getClass().getSimpleName() + "布局使用PageStatusHelper,联系维护者");
54 | viewStatusInterface = new FrameLayoutViewStatusImp();
55 | }
56 | }
57 | viewStatusInterface.addStatusView(bindView, addView, params);
58 |
59 | }
60 |
61 | public void showContent() {
62 |
63 | if (viewStatusInterface == null) return;
64 | viewStatusInterface.showContentView();
65 |
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/ColorUtils.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
2 |
3 | import android.graphics.Color;
4 | import android.graphics.drawable.ColorDrawable;
5 | import android.graphics.drawable.Drawable;
6 | import android.view.View;
7 |
8 | /**
9 | * Author: YuJunKui
10 | * Time:2018/5/14 15:31
11 | * Tips:
12 | */
13 | public class ColorUtils {
14 |
15 | /**
16 | * 颜色反转
17 | * 比如输入白色 返回黑色
18 | * 颜色转16进制后 15减去即可
19 | *
20 | * @param originalColor 原来的颜色 #******格式或者 #******** 带透明值
21 | * @return 返回反转后的颜色
22 | */
23 | public static String reserveColor(String originalColor) {
24 | StringBuilder sb = new StringBuilder().append("#");
25 |
26 | if (!originalColor.startsWith("#")) {
27 | originalColor = "#" + originalColor;
28 | }
29 | //==9则 带了透明值 消除透明值
30 | int start = originalColor.length() == 9 ? 3 : 1;
31 |
32 | for (int i = start; i < originalColor.length(); i++) {
33 | String st = originalColor.charAt(i) + "";
34 | int temp = Integer.parseInt(st, 16);
35 | sb.append("" + Integer.toHexString(15 - temp).toUpperCase());
36 | }
37 | return sb.toString();
38 | }
39 |
40 |
41 | /**
42 | * @param v 需要获取的控件
43 | * @return 返回值
44 | */
45 | public static String obtainBgColor(View v) {
46 |
47 | try {
48 | Drawable background = v.getBackground();
49 | if (background == null) {
50 | return obtainBgColor((View) v.getParent());
51 | } else if (background instanceof ColorDrawable){
52 | ColorDrawable colorDrawable = (ColorDrawable) background;
53 | int color = colorDrawable.getColor();
54 | return intColorConvert16Color(color);
55 | }
56 | } catch (Exception e) {
57 | }
58 | return null;
59 | }
60 |
61 |
62 | /**
63 | * int 颜色值转化为16进制颜色值
64 | *
65 | * @param color
66 | * @return
67 | */
68 | public static String intColorConvert16Color(int color) {
69 | String R, G, B;
70 | StringBuffer sb = new StringBuffer();
71 | R = Integer.toHexString(Color.red(color));
72 | G = Integer.toHexString(Color.green(color));
73 | B = Integer.toHexString(Color.blue(color));
74 | //判断获取到的R,G,B值的长度 如果长度等于1 给R,G,B值的前边添0
75 | R = R.length() == 1 ? "0" + R : R;
76 | G = G.length() == 1 ? "0" + G : G;
77 | B = B.length() == 1 ? "0" + B : B;
78 | sb.append("0x");
79 | sb.append(R);
80 | sb.append(G);
81 | sb.append(B);
82 | return sb.toString();
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smartcity/commonbase/widget/pagestatus/test/SimpleActivity.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.test;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import com.smartcity.commonbase.widget.pagestatus.PageStatusHelper;
9 |
10 | /**
11 | * Author: YuJunKui
12 | * Time:2018/9/11 17:31
13 | * Tips:
14 | */
15 | public class SimpleActivity extends AppCompatActivity {
16 |
17 | private PageStatusHelper statusHelper;
18 |
19 | //可以是list 也可以是任何view
20 | private View contentView;
21 |
22 | @Override
23 | protected void onCreate(@Nullable Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 |
26 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
27 | getSupportActionBar().setDisplayShowHomeEnabled(true);
28 | getSupportActionBar().setDisplayShowTitleEnabled(true);
29 | getSupportActionBar().setDisplayUseLogoEnabled(false);
30 | getSupportActionBar().setTitle("简单使用");
31 | setContentView(R.layout.activity_simple);
32 |
33 | contentView = findViewById(R.id.rv_content);
34 |
35 | statusHelper = new PageStatusHelper(this);
36 | statusHelper.bindView(contentView);
37 |
38 | statusHelper.setOnErrorClickListener(v -> {
39 | // 重新开始你的请求
40 | });
41 |
42 | statusHelper.setOnNoLoginClickListener(v -> {
43 | //打开登录页面
44 | //建议写个静态方法 构造一系列通用视图 以及 打开登录页面
45 | });
46 |
47 |
48 | statusHelper.refreshPageStatus(PageStatusHelper.LOADING);
49 | //模拟接口速度很快,LoadingView还没有绘制完成就调用了Content的情况
50 | statusHelper.refreshPageStatus(PageStatusHelper.CONTENT);
51 |
52 | }
53 |
54 | public void onClick(View view) {
55 |
56 | switch (view.getId()) {
57 |
58 | case R.id.btn_content:
59 | //数据加载完成调用这个方法
60 | statusHelper.refreshPageStatus(PageStatusHelper.CONTENT);
61 | break;
62 |
63 | case R.id.btn_empty:
64 | //空视图
65 | statusHelper.refreshPageStatus(PageStatusHelper.EMPTY);
66 | break;
67 |
68 | case R.id.btn_loading:
69 | //加载中
70 | statusHelper.refreshPageStatus(PageStatusHelper.LOADING);
71 | break;
72 |
73 | case R.id.btn_loading_error:
74 | //加载失败
75 | statusHelper.refreshPageStatus(PageStatusHelper.ERROR);
76 | break;
77 |
78 | case R.id.btn_no_login:
79 | //未登录
80 | statusHelper.refreshPageStatus(PageStatusHelper.NO_LOGIN);
81 | break;
82 |
83 | case R.id.btn_no_network:
84 | //没有网络
85 | statusHelper.refreshPageStatus(PageStatusHelper.NET_WORK);
86 | break;
87 | }
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/smartcity/commonbase/widget/pagestatus/test/Custom1Activity.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.test;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 |
8 | import com.smartcity.commonbase.widget.pagestatus.Builder;
9 | import com.smartcity.commonbase.widget.pagestatus.PageStatusHelper;
10 |
11 | /**
12 | * Author: YuJunKui
13 | * Time:2018/10/7 15:59
14 | * Tips:
15 | */
16 | public class Custom1Activity extends AppCompatActivity {
17 |
18 | private PageStatusHelper statusHelper;
19 |
20 | //可以是list 也可以是任何view
21 | private View contentView;
22 |
23 | @Override
24 | protected void onCreate(@Nullable Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 |
27 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
28 | getSupportActionBar().setDisplayShowHomeEnabled(true);
29 | getSupportActionBar().setDisplayShowTitleEnabled(true);
30 | getSupportActionBar().setDisplayUseLogoEnabled(false);
31 | getSupportActionBar().setTitle("定制一");
32 | setContentView(R.layout.activity_simple);
33 |
34 | contentView = findViewById(R.id.rv_content);
35 |
36 | statusHelper = new Builder(this)
37 | .setErrorLayout(R.layout.view_custom_error)
38 | .setEmptyImage(R.drawable.ic_loading_empty)
39 | .setNetworkImage(R.drawable.ic_loading_no_net)
40 | .setLoadingLayout(R.layout.view_custom_loading)
41 | .build();
42 | statusHelper.bindView(contentView);
43 |
44 |
45 | statusHelper.refreshPageStatus(PageStatusHelper.LOADING);
46 | statusHelper.refreshPageStatus(PageStatusHelper.ERROR);
47 | statusHelper.refreshPageStatus(PageStatusHelper.EMPTY);
48 |
49 | }
50 |
51 | public void onClick(View view) {
52 |
53 | switch (view.getId()) {
54 |
55 | case R.id.btn_content:
56 | //数据加载完成调用这个方法
57 | statusHelper.refreshPageStatus(PageStatusHelper.CONTENT);
58 | break;
59 |
60 | case R.id.btn_empty:
61 | //空视图
62 | statusHelper.refreshPageStatus(PageStatusHelper.EMPTY);
63 | break;
64 |
65 | case R.id.btn_loading:
66 | //加载中
67 | statusHelper.refreshPageStatus(PageStatusHelper.LOADING);
68 | break;
69 |
70 | case R.id.btn_loading_error:
71 | //加载失败
72 | statusHelper.refreshPageStatus(PageStatusHelper.ERROR);
73 | break;
74 |
75 | case R.id.btn_no_login:
76 | //未登录
77 | statusHelper.refreshPageStatus(PageStatusHelper.NO_LOGIN);
78 | break;
79 |
80 | case R.id.btn_no_network:
81 | //没有网络
82 | statusHelper.refreshPageStatus(PageStatusHelper.NET_WORK);
83 | break;
84 | }
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_simple.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
17 |
18 |
23 |
24 |
29 |
30 |
35 |
36 |
42 |
43 |
49 |
50 |
56 |
57 |
63 |
64 |
65 |
66 |
67 |
68 |
77 |
78 |
79 |
84 |
85 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | ### 1、什么是PageStatusHelper
3 | 一款**简单的、方便**,解决页面各种状态的框架。
4 |
5 | ### 与其他方案的区别、优点
6 | -几乎每个页面都需要加载中、加载失败、没有数据、没有网络。( 而普遍套一层的方案麻烦这里提出一种贴的方案
7 | “贴”? 哪个View上要出现加载状态哪里贴,比如现在在ListView没有数据的时候加载一个提示数据为空的view,这时候我们就往ListView上贴,而不再套一层,而且使用方便 )
8 |
9 | -单页面存在多个加载状态的时候,极其便利,因为他针对的是view
10 |
11 | -杜绝数据未加载出来,出现点击错误显示异常
12 |
13 | ### 少废话先看效果
14 |
15 | **单页面多个接口**
16 |
17 | 
18 | 
19 |
20 | **绑定部分区域加载**
21 |
22 | 
23 |
24 |
25 | **防止页面数据未加载出来点击错误 或者数据不雅**
26 |
27 | 
28 |
29 |
30 | ### 2、版本依赖
31 | ```Groovy
32 | //添加jitpack仓库
33 | allprojects {
34 | repositories {
35 | ...
36 | maven { url 'https://jitpack.io' }
37 | }
38 | }
39 | //添加库
40 | dependencies {
41 | implementation 'com.github.YuJunKui1995:PageStatusHelper:v1.1.0'
42 | }
43 | ```
44 |
45 | ### 3、使用
46 |
47 | **1、简单使用 三行代码(简单模式下所有的状态view皆为TextView)**
48 | ```java
49 | statusHelper = new PageStatusHelper(Context context)
50 | //需要把加载状态绑定到那个view
51 | statusHelper.bindView(View contentView);
52 | statusHelper.refreshPageStatus(@PageStatusValue int pageStatusValue)
53 |
54 | refreshPageStatus方法有如下类型
55 | ERROR、 NO_LOGIN =、 LOADING、 NET_WORK(网络异常)、 EMPTY 、 CONTENT(正常内容)
56 | ```
57 |
58 | **2、定制使用使用**
59 | ```java
60 | //可通过Builder对象对各个状态进行定制,text image layout view 等等都可以
61 | statusHelper = new PageStatusHelper(Context context
62 | , new Builder(Context context)
63 | .setErrorImage(int imageId)
64 | .setLoadingView(View view)
65 | .setEmptyImage(int imageId)
66 | .setNetworkLayout(int layoutId)
67 | .setNoLoginText(String text)
68 | );
69 | ```
70 |
71 | ### 4、目前已知的问题
72 |
73 | 1、bindView的父布局为ViewPage下异常
74 |
75 | 2、在Fragment使用时bindView是根布局,而这个Fragment使用的地方需要show hide Fragment(常见为主页tab)
76 | 以上两个问题都可以通过在bindView包裹一层父布局解决
77 |
78 | ### 5、版本优化
79 | 1.0.0 版本
80 | 重构view的绘制流程用来支持对根布局的属性支持
81 |
82 | 约束布局使用不在需要每个view都设置id
83 |
84 | 约束布局中属性不全的优化支持,约束布局自定义view或layout的优化支持
85 |
86 | 相对布局的完成支持
87 |
88 | 瞬间多次调用(断网状态)的绘制优化
89 |
90 | ## License MIT
91 |
92 | Copyright (c) 2017-2020 YuJunKui
93 |
94 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
95 |
96 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
97 |
98 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
99 |
100 | [1]: https://user-images.githubusercontent.com/2038071/31045150-a077cc8a-a5a2-11e7-8dc2-7a0e3a9f3e62.jpg
101 | [2]: https://user-images.githubusercontent.com/2038071/29978804-45c321ba-8f75-11e7-9040-776d3b6dca1f.jpg
102 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/ViewUtils.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
2 |
3 | import android.content.Context;
4 | import android.support.design.widget.AppBarLayout;
5 | import android.support.design.widget.CoordinatorLayout;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.view.ViewParent;
9 |
10 | /**
11 | * Author: YuJunKui
12 | * Time:2017/12/9 9:41
13 | * Tips:
14 | */
15 |
16 | public class ViewUtils {
17 |
18 | private static final String TAG = "ViewUtils";
19 |
20 | /**
21 | * 测量view方法
22 | *
23 | * @param view
24 | * @return int[0] width int[1] height
25 | */
26 | public static int[] getViewMetrics(View view) {
27 |
28 | int[] ints = new int[2];
29 |
30 | ints[0] = view.getWidth();
31 | ints[1] = view.getHeight();
32 |
33 | if (ints[0] == 0 || ints[1] == 0) {
34 | try {
35 | view.measure(0, 0);
36 | } catch (Exception e) {
37 | }
38 | ints[0] = view.getMeasuredWidth();
39 | ints[1] = view.getMeasuredHeight();
40 | }
41 |
42 | return ints;
43 | }
44 |
45 | /**
46 | * 简单处理下有些情况下异常的问题
47 | *
48 | * @param view
49 | * @return int[0] width int[1] height
50 | */
51 | public static int[] getNormalBindViewMetric(View view) {
52 |
53 | int[] ints = getViewMetrics(view);
54 |
55 | //目前这种测量方法不好 兼容下获取父类的
56 | if (ints[0] == 0 && ints[1] == 0) {
57 | View parent = (View) view.getParent();
58 | if (parent != null) {
59 | return getViewMetrics(parent);
60 | }
61 | }
62 | return ints;
63 | }
64 |
65 |
66 | /**
67 | * 这里会处理如果bindView的某个父类是CoordinatorLayout的话
68 | * 将正确高度 CoordinatorLayout-AppBarLayout 返回
69 | * @param bindView
70 | * @return
71 | */
72 | public static int[] getBindViewMetrics(View bindView) {
73 |
74 | CoordinatorLayout parent = findCoordinatorLayoutParent(bindView);
75 | if (parent != null) {
76 | int[] ints;
77 |
78 | //寻找AppBarLayout
79 | AppBarLayout appBarLayout = null;
80 | for (int i = 0; i < parent.getChildCount(); i++) {
81 | View childAt = parent.getChildAt(i);
82 | if (childAt instanceof AppBarLayout) {
83 | appBarLayout = (AppBarLayout) childAt;
84 | break;
85 | }
86 | }
87 |
88 | if (appBarLayout == null) {
89 | return getNormalBindViewMetric(bindView);
90 | }
91 |
92 | ints=new int[]{parent.getWidth(),parent.getHeight()-appBarLayout.getHeight()};
93 | return ints;
94 | } else {
95 | return getNormalBindViewMetric(bindView);
96 | }
97 | }
98 |
99 |
100 | /**
101 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
102 | */
103 | public static int dip2px(Context context, float dpValue) {
104 | final float scale = context.getResources().getDisplayMetrics().density;
105 | return (int) (dpValue * scale + 0.5f);
106 | }
107 |
108 | /**
109 | * @param v
110 | * @return
111 | */
112 | public static CoordinatorLayout findCoordinatorLayoutParent(View v) {
113 |
114 | View parent;
115 |
116 | if (v == null || v.getParent()==null|| ! (v.getParent() instanceof View)) {
117 | return null;
118 | }
119 |
120 | parent= (View) v.getParent();
121 |
122 | if (parent instanceof CoordinatorLayout) {
123 | return (CoordinatorLayout) parent;
124 | } else {
125 | return findCoordinatorLayoutParent(parent);
126 | }
127 | }
128 |
129 |
130 | /**
131 | * 父view是否是CoordinatorLayout(会递归至null)
132 | *
133 | * @param v
134 | * @return
135 | */
136 | public static boolean parentCoordinatorLayout(View v) {
137 |
138 | return findCoordinatorLayoutParent(v) != null;
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/game_anim_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
10 |
13 |
16 |
19 |
22 |
25 |
28 |
31 |
34 |
37 |
40 |
43 |
46 |
49 |
52 |
55 |
58 |
61 |
64 |
67 |
70 |
73 |
76 |
79 |
82 |
85 |
88 |
91 |
94 |
97 |
100 |
103 |
106 |
109 |
112 |
115 |
118 |
121 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/imp/ViewGroupViewStatusImp.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.imp;
2 |
3 | import android.view.View;
4 | import android.view.ViewGroup;
5 |
6 | import com.smartcity.commonbase.widget.pagestatus.LayoutParams;
7 | import com.smartcity.commonbase.widget.pagestatus.ViewUtils;
8 |
9 | /**
10 | * Author: YuJunKui
11 | * Time:2017/12/8 10:57
12 | * Tips:
13 | */
14 |
15 | public abstract class ViewGroupViewStatusImp implements ViewStatusInterface {
16 |
17 | private static final String TAG = "ViewGroupViewStatusImp";
18 |
19 | protected View addView;
20 | protected View bindView;
21 |
22 | protected View lastAddView;
23 |
24 |
25 | //线性布局插入view后会对bindView的的宽高会变化,导致的问题
26 | //比如当前在加载中,在线性布局下 ????
27 | private int bindViewWidth = -1, bindViewHeight = -1;
28 |
29 | private Runnable mRunnable = null;
30 |
31 | @Override
32 | public void addStatusView(final View bindView, final View addView, LayoutParams params) {
33 |
34 | this.addView = addView;
35 | this.bindView = bindView;
36 |
37 | ViewGroup parent = (ViewGroup) bindView.getParent();
38 |
39 | if (lastAddView != null) {
40 | lastAddView.setVisibility(View.GONE);
41 | }
42 | lastAddView = addView;
43 |
44 | if (addView.getTag() == null) {
45 |
46 | if (params.centerInParent) {
47 | mRunnable = new Runnable() {
48 | @Override
49 | public void run() {
50 | //说明在一瞬间调用了两次状态 有可能前一次绘制计算位置还没完成就 调用了第二次
51 | //一般出现在没有网络的情况下,
52 | // gone后没有绘制完成的会没有宽高
53 | //如果用INVISIBLE会导致线性布局出现问题
54 | //所以在下次调用的时候直接gone,
55 | // 当第一次的状态下次再调用的时候就会当做第一次显示,再次走这里
56 | if (ViewGroupViewStatusImp.this.addView != addView) {
57 | //没有摆放成功就调用了其他的状态直接返回
58 | return;
59 | }
60 |
61 | //获取bindview宽高
62 | if (bindViewWidth == -1) {
63 | int[] bindViewMetrics = ViewUtils.getBindViewMetrics(bindView);
64 | bindViewWidth = bindViewMetrics[0];
65 | bindViewHeight = bindViewMetrics[1];
66 | }
67 |
68 | int width = addView.getWidth();
69 | int height = addView.getHeight();
70 |
71 | int left = (bindViewWidth - width) / 2;
72 | int top = (bindViewHeight - height) / 2;
73 |
74 | ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) addView.getLayoutParams();
75 | layoutParams.setMargins(left, top, 0, 0);
76 |
77 | initLayoutParams(layoutParams);
78 |
79 | addView.setTag(ADD_View_TAG);
80 | addView.setLayoutParams(addView.getLayoutParams());
81 | addView.setVisibility(View.VISIBLE);
82 | }
83 | };
84 | addView.post(mRunnable);
85 |
86 | } else {
87 |
88 | addView.setPadding(params.paddingLeft, params.paddingTop, params.paddingRight, params.paddingBottom);
89 | }
90 |
91 | if (addView.getId() == View.NO_ID) {
92 | addView.setId(View.generateViewId());
93 | }
94 | if (addView.getParent() == null) parent.addView(addView);
95 | hideContent(bindView);
96 | } else {
97 | lastAddView = addView;
98 | addView.setVisibility(View.VISIBLE);
99 | hideContent(bindView);
100 | }
101 | }
102 |
103 | /**
104 | * 注意 init 你不需要在这个方法中调用setLayoutParams
105 | *
106 | * @param layoutParams
107 | */
108 | protected abstract void initLayoutParams(ViewGroup.LayoutParams layoutParams);
109 |
110 | /**
111 | * 隐藏content view 默认INVISIBLE隐藏
112 | *
113 | * @param bindView
114 | */
115 | public void hideContent(View bindView) {
116 | bindView.setVisibility(View.INVISIBLE);
117 | }
118 |
119 |
120 | @Override
121 | public void showContentView() {
122 |
123 | bindView.setVisibility(View.VISIBLE);
124 | //有可能addView还没有绘制完成就调用了showContent
125 | addView.removeCallbacks(mRunnable);
126 | addView.setVisibility(View.GONE);
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/imp/ConstraintLayoutViewStatusImp.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus.imp;
2 |
3 | import android.support.constraint.ConstraintLayout;
4 | import android.support.constraint.ConstraintSet;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import com.smartcity.commonbase.widget.pagestatus.LayoutParams;
9 | import com.smartcity.commonbase.widget.pagestatus.ViewUtils;
10 |
11 | /**
12 | * Author: YuJunKui
13 | * Time:2018/5/14 15:21
14 | * Tips:
15 | */
16 | public class ConstraintLayoutViewStatusImp extends ViewGroupViewStatusImp {
17 |
18 |
19 | @Override
20 | public void addStatusView(View bindView, View addView, LayoutParams params) {
21 |
22 | //((ConstraintLayout) bindView.getParent()).addView(addView, bindView.getLayoutParams());
23 | //这个是不行的 ConstraintLayout并没有处理 addView
24 |
25 | super.addStatusView(bindView, addView, params);
26 | }
27 |
28 |
29 | @Override
30 | protected void initLayoutParams(ViewGroup.LayoutParams addLayoutParams) {
31 |
32 | ((ViewGroup.MarginLayoutParams) addLayoutParams).setMargins(0, 0, 0, 0);
33 | int rulesCount = 0;
34 |
35 | ConstraintLayout layout = (ConstraintLayout) bindView.getParent();
36 | //因为约束布局使用ConstraintSet新增view的时候 必须要其他view要有id
37 | for (int i = 0; i < layout.getChildCount(); i++) {
38 | View v=layout.getChildAt(i);
39 | if (v.getId() == View.NO_ID) {
40 | v.setId(View.generateViewId());
41 | }
42 | }
43 |
44 | ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) bindView.getLayoutParams();
45 |
46 | ConstraintSet set = new ConstraintSet();
47 | set.clone(layout);
48 |
49 | //获取对应关系和间隔
50 | //设置对应关系
51 |
52 | //左右只是设置了Margin但是没有设置以什么为标准
53 | //比如设置了leftMargin和rightMargin 没有设置leftToRight或者leftToLeft rightToRight或者rightToLeft
54 | //目前只支持leftMargin==rightToRight的显示
55 | //这里的方案还要更换
56 | if (layoutParams.leftMargin == layoutParams.rightMargin &&
57 | layoutParams.leftToLeft == -1 && layoutParams.leftToRight == -1 &&
58 | layoutParams.rightToRight == -1 && layoutParams.rightToLeft == -1
59 | ) {
60 | layoutParams.leftToLeft = ConstraintLayout.LayoutParams.PARENT_ID;
61 | layoutParams.rightToRight = ConstraintLayout.LayoutParams.PARENT_ID;
62 | layoutParams.leftMargin = 0;
63 | layoutParams.rightToRight = 0;
64 | }
65 | if (layoutParams.topMargin == layoutParams.bottomMargin &&
66 | layoutParams.topToTop == -1 && layoutParams.topToBottom == -1 &&
67 | layoutParams.bottomToBottom == -1 && layoutParams.bottomToTop == -1
68 | ) {
69 | layoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
70 | layoutParams.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID;
71 | layoutParams.topMargin = 0;
72 | layoutParams.bottomMargin = 0;
73 | }
74 |
75 | //left to left start to start
76 | if (layoutParams.leftToLeft != -1 || layoutParams.startToStart != -1) {
77 | int leftToLeft = layoutParams.leftToLeft != -1 ? layoutParams.leftToLeft : layoutParams.startToStart;
78 | set.connect(addView.getId(), ConstraintSet.START, leftToLeft, ConstraintSet.START, layoutParams.leftMargin);
79 | rulesCount++;
80 | }
81 |
82 | //right to right end to end
83 | if (layoutParams.rightToRight != -1 || layoutParams.endToEnd != -1) {
84 | int rightToRight = layoutParams.rightToRight != -1 ? layoutParams.rightToRight : layoutParams.endToEnd;
85 | set.connect(addView.getId(), ConstraintSet.END, rightToRight, ConstraintSet.END, layoutParams.rightMargin);
86 | rulesCount++;
87 | }
88 |
89 | //top to top
90 | if (layoutParams.topToTop != -1) {
91 | set.connect(addView.getId(), ConstraintSet.TOP, layoutParams.topToTop, ConstraintSet.TOP, layoutParams.topMargin);
92 | rulesCount++;
93 | }
94 |
95 | //bottom to bottom
96 | if (layoutParams.bottomToBottom != -1) {
97 | set.connect(addView.getId(), ConstraintSet.BOTTOM, layoutParams.bottomToBottom, ConstraintSet.BOTTOM, layoutParams.bottomMargin);
98 | rulesCount++;
99 | }
100 |
101 | //left to right start to end
102 | if (layoutParams.leftToRight != -1 || layoutParams.startToEnd != -1) {
103 | int leftToRight = layoutParams.rightToRight != -1 ? layoutParams.rightToRight : layoutParams.startToEnd;
104 | set.connect(addView.getId(), ConstraintSet.LEFT, leftToRight, ConstraintSet.RIGHT, layoutParams.leftMargin);
105 | rulesCount++;
106 | }
107 |
108 | //right to left end to start
109 | if (layoutParams.rightToLeft != -1 && layoutParams.endToStart != -1) {
110 | int rightToLeft = layoutParams.rightToLeft != -1 ? layoutParams.rightToLeft : layoutParams.endToStart;
111 | set.connect(addView.getId(), ConstraintSet.RIGHT, rightToLeft, ConstraintSet.LEFT, layoutParams.rightMargin);
112 | rulesCount++;
113 | }
114 |
115 | //top to bottom
116 | if (layoutParams.topToBottom != -1) {
117 | set.connect(addView.getId(), ConstraintSet.TOP, layoutParams.topToBottom, ConstraintSet.BOTTOM, layoutParams.topMargin);
118 | rulesCount++;
119 | }
120 |
121 | //bottom to top
122 | if (layoutParams.bottomToTop != -1) {
123 | set.connect(addView.getId(), ConstraintSet.BOTTOM, layoutParams.bottomToTop, ConstraintSet.TOP, layoutParams.bottomMargin);
124 | rulesCount++;
125 | }
126 |
127 | //检查约束布局的参数 理论应该是4个
128 | if (rulesCount < 3) {
129 | set.connect(addView.getId(), ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP, 0);
130 | set.connect(addView.getId(), ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, 0);
131 | set.connect(addView.getId(), ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START, 0);
132 | set.connect(addView.getId(), ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END, 0);
133 | }
134 |
135 | if (addLayoutParams.width == ViewGroup.LayoutParams.MATCH_PARENT
136 | && addLayoutParams.height == ViewGroup.LayoutParams.MATCH_PARENT
137 | && rulesCount >= 4
138 | ) {
139 | set.constrainWidth(addView.getId(), 0);
140 | set.constrainHeight(addView.getId(), 0);
141 | }
142 |
143 | set.applyTo(layout);
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/PageStatusHelper.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.os.Build;
6 | import android.support.annotation.IntDef;
7 | import android.support.annotation.RequiresApi;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.view.ViewTreeObserver;
11 |
12 | import java.lang.annotation.Retention;
13 | import java.lang.annotation.RetentionPolicy;
14 |
15 | /**
16 | * Author: YuJunKui
17 | * Time:2017/12/8 9:24
18 | * Tips: 页面状态类
19 | */
20 |
21 | public class PageStatusHelper {
22 |
23 | private View bindView;
24 | private Builder builder;
25 |
26 | private ViewStatusController controller;
27 | private OnErrorClickListener onErrorClickListener;
28 | private OnNoLoginClickListener onNoLoginClickListener;
29 | private OnEmptyClickListener onEmptyClickListener;
30 |
31 | public static final int ERROR = 0, NO_LOGIN = 1, LOADING = 2, NET_WORK = 3, EMPTY = 4, CONTENT = 5;
32 |
33 | private static final String TAG = "PageStatusHelper";
34 |
35 | @PageStatusValue
36 | private int currentPageStatusValue = CONTENT;
37 |
38 | private String bindViewBgColor;
39 |
40 | /**
41 | * @param context 用于构建view
42 | */
43 | public PageStatusHelper(Context context) {
44 | this(context, new Builder(context));
45 |
46 | }
47 |
48 | /**
49 | * @param context 用于构建view
50 | */
51 | public PageStatusHelper(Context context, Builder builder) {
52 | setBuilder(builder);
53 | controller = new ViewStatusController();
54 | }
55 |
56 | @Deprecated
57 | public PageStatusHelper setLayoutParams(LayoutParams params) {
58 | builder.setLayoutParams(params);
59 | return this;
60 | }
61 |
62 |
63 | public PageStatusHelper bindView(View bindView) {
64 |
65 | checkBindView();
66 | if (this.bindView != null) {
67 | return this;// song 没抛运行时异常
68 | }
69 |
70 | builder.setBindView(bindView);
71 |
72 | this.bindView = bindView;
73 | this.bindViewBgColor = ColorUtils.obtainBgColor(bindView);
74 |
75 | return this;
76 |
77 | }
78 |
79 | //检测
80 | private void checkBindView() {
81 |
82 |
83 | }
84 |
85 | @Deprecated
86 | public void bindActivity(Activity bindActivity) {
87 | this.bindView = bindActivity.getWindow().getDecorView();
88 | }
89 |
90 | public PageStatusHelper setBuilder(Builder builder) {
91 | this.builder = builder;
92 | return this;
93 | }
94 |
95 | public Builder getBuilder() {
96 | return builder;
97 | }
98 |
99 | /**
100 | * 此方法会将在GONE状态下的bindView改为INVISIBLE
101 | *
102 | * @param pageStatusValue
103 | */
104 | public PageStatusHelper refreshPageStatus(@PageStatusValue final int pageStatusValue) {
105 |
106 | //状态一样不做处理
107 | if (currentPageStatusValue == pageStatusValue) {
108 | return this;
109 | }
110 |
111 | Log.i(TAG,"call refreshPageStatus currentPageStatusValue="+pageStatusValue);
112 |
113 | currentPageStatusValue = pageStatusValue;
114 |
115 | if (bindView.getVisibility() == View.GONE) {
116 | bindView.setVisibility(View.INVISIBLE);
117 | }
118 |
119 | //没有绘制完成的
120 | if (bindView.getWidth() == 0) {
121 |
122 | bindView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
123 | @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
124 | @Override
125 | public void onGlobalLayout() {
126 | refreshStatus(pageStatusValue);
127 | bindView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
128 | }
129 | });
130 |
131 | } else {
132 | refreshStatus(pageStatusValue);
133 | }
134 |
135 | return this;
136 | }
137 |
138 | private void refreshStatus(@PageStatusValue final int pageStatusValue) {
139 |
140 | builder.setBindViewBgColor(bindViewBgColor);
141 |
142 | if (pageStatusValue == CONTENT) {
143 |
144 | controller.showContent();
145 | return;
146 | }
147 |
148 | View statusView;
149 | if (pageStatusValue == ERROR) {
150 |
151 | statusView = builder.buildErrorView(onErrorClickListener != null);
152 | } else if (pageStatusValue == EMPTY) {
153 |
154 | statusView = builder.buildEmptyView();
155 | } else if (pageStatusValue == LOADING) {
156 |
157 | statusView = builder.buildLoadingView();
158 | } else if (pageStatusValue == NET_WORK) {
159 |
160 | statusView = builder.buildNetWorkView(onErrorClickListener != null);
161 | } else if (pageStatusValue == NO_LOGIN) {
162 |
163 | statusView = builder.buildNoLoginView();
164 | } else {
165 | return;
166 | }
167 |
168 | //绑定事件
169 | statusView.setOnClickListener(new View.OnClickListener() {
170 | @Override
171 | public void onClick(View v) {
172 |
173 |
174 | if ((pageStatusValue == ERROR || pageStatusValue == NET_WORK) && onErrorClickListener != null) {
175 |
176 | //改变状态
177 | refreshPageStatus(LOADING);
178 | onErrorClickListener.onErrorClick(v);
179 | } else if (pageStatusValue == NO_LOGIN && onNoLoginClickListener != null) {
180 | onNoLoginClickListener.OnNoLoginClick(v);
181 | } else if (pageStatusValue == EMPTY && onEmptyClickListener != null) {
182 | onEmptyClickListener.onEmptyClick(v);
183 | }
184 |
185 | }
186 | });
187 |
188 | controller.showViewStatus(bindView, statusView, builder.getLayoutParams());
189 | }
190 |
191 |
192 | public PageStatusHelper setOnNoLoginClickListener(OnNoLoginClickListener onNoLoginClickListener) {
193 | this.onNoLoginClickListener = onNoLoginClickListener;
194 | return this;
195 | }
196 |
197 | @Deprecated
198 | public void showContent() {
199 | refreshPageStatus(CONTENT);
200 | }
201 |
202 | @IntDef({ERROR, NO_LOGIN, LOADING, NET_WORK, EMPTY, CONTENT})
203 | @Retention(RetentionPolicy.SOURCE)
204 | public @interface PageStatusValue {
205 | }
206 |
207 | public void setOnErrorClickListener(OnErrorClickListener onErrorClickListener) {
208 | this.onErrorClickListener = onErrorClickListener;
209 | }
210 |
211 | public void setOnEmptyClickListener(OnEmptyClickListener onEmptyClickListener) {
212 | this.onEmptyClickListener = onEmptyClickListener;
213 | }
214 |
215 | public int getCurrentPageStatusValue() {
216 | return currentPageStatusValue;
217 | }
218 | }
219 |
--------------------------------------------------------------------------------
/pagestatushelper/src/main/java/com/smartcity/commonbase/widget/pagestatus/Builder.java:
--------------------------------------------------------------------------------
1 | package com.smartcity.commonbase.widget.pagestatus;
2 |
3 | import android.content.Context;
4 | import android.graphics.Color;
5 | import android.support.annotation.ColorInt;
6 | import android.support.annotation.DimenRes;
7 | import android.support.annotation.DrawableRes;
8 | import android.support.annotation.LayoutRes;
9 | import android.view.Gravity;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 |
16 | /**
17 | * Author: YuJunKui
18 | * Time:2017/12/8 15:03
19 | * Tips:用来构建占位
20 | */
21 | public class Builder {
22 |
23 | @ColorInt
24 | private int bgColor = Color.TRANSPARENT;
25 |
26 | @ColorInt
27 | private Integer textColor = null;
28 | @DimenRes
29 | private int textSize = 16;
30 | private CharSequence errorText = "加载失败~点击重试", errorText2 = "加载失败~", loadingText = "努力加载中~", emptyText = "空空如也~", networkText = "网络断线啦~点击重试", networkText2 = "网络断线啦~", noLoginText = "没有登录~";
31 |
32 | @DrawableRes
33 | private int errorImage, loadingImage, emptyImage, networkImage, noLoginImage;
34 |
35 | @LayoutRes
36 | private int errorLayout, loadingLayout, emptyLayout, networkLayout, noLoginLayout;
37 |
38 | private View errorView, loadingView, emptyView, networkView, noLoginView;
39 |
40 | private Context context;
41 |
42 | private String bindViewBgColor = null;
43 |
44 | private View bindView;
45 |
46 | private LayoutParams params;
47 |
48 | /**
49 | * 此方法仅供PageStatusHelper类调用
50 | * 外部不可调用
51 | *
52 | * @param bindViewBgColor
53 | */
54 | public void setBindViewBgColor(String bindViewBgColor) {
55 | if (this.bindViewBgColor == null) {
56 | this.bindViewBgColor = bindViewBgColor;
57 | }
58 | }
59 |
60 | public void setBindView(View bindView) {
61 | this.bindView = bindView;
62 | }
63 |
64 | public Builder(Context context) {
65 | this.context = context;
66 | params = new LayoutParams();
67 | }
68 |
69 | public Builder setErrorText(CharSequence errorText) {
70 | this.errorText = errorText;
71 | return this;
72 | }
73 |
74 | public Builder setTextColor(@ColorInt int textColor) {
75 | this.textColor = textColor;
76 | return this;
77 | }
78 |
79 |
80 | /**
81 | * 不支持透明色
82 | *
83 | * @param bgColor
84 | * @return
85 | */
86 | public Builder setBgColor(@ColorInt int bgColor) {
87 | this.bgColor = bgColor;
88 | return this;
89 | }
90 |
91 | public Builder setBgColor(String bgColor) {
92 | return setBgColor(Color.parseColor(bgColor));
93 | }
94 |
95 |
96 | public Builder setLoadingText(CharSequence loadingText) {
97 | this.loadingText = loadingText;
98 | return this;
99 | }
100 |
101 | public Builder setEmptyText(CharSequence emptyText) {
102 | this.emptyText = emptyText;
103 | return this;
104 | }
105 |
106 | public Builder setNetworkText(CharSequence networkText) {
107 | this.networkText = networkText;
108 | return this;
109 | }
110 |
111 | public Builder setNoLoginText(CharSequence noLoginText) {
112 | this.noLoginText = noLoginText;
113 | return this;
114 | }
115 |
116 | public Builder setErrorImage(@DrawableRes int errorImage) {
117 | this.errorImage = errorImage;
118 | return this;
119 | }
120 |
121 | public Builder setLoadingImage(@DrawableRes int loadingImage) {
122 | this.loadingImage = loadingImage;
123 | return this;
124 | }
125 |
126 | public Builder setEmptyImage(@DrawableRes int emptyImage) {
127 | this.emptyImage = emptyImage;
128 | return this;
129 | }
130 |
131 | public Builder setNetworkImage(@DrawableRes int networkImage) {
132 | this.networkImage = networkImage;
133 | return this;
134 | }
135 |
136 | public Builder setNoLoginImage(@DrawableRes int noLoginImage) {
137 | this.noLoginImage = noLoginImage;
138 | return this;
139 | }
140 |
141 | public Builder setErrorLayout(@LayoutRes int errorLayout) {
142 | this.errorLayout = errorLayout;
143 | return this;
144 | }
145 |
146 | public Builder setLoadingLayout(@LayoutRes int loadingLayout) {
147 | this.loadingLayout = loadingLayout;
148 | return this;
149 | }
150 |
151 | public Builder setEmptyLayout(@LayoutRes int emptyLayout) {
152 | this.emptyLayout = emptyLayout;
153 | return this;
154 | }
155 |
156 | public Builder setNetworkLayout(@LayoutRes int networkLayout) {
157 | this.networkLayout = networkLayout;
158 | return this;
159 | }
160 |
161 | public Builder setNoLoginLayout(@LayoutRes int noLoginLayout) {
162 | this.noLoginLayout = noLoginLayout;
163 | return this;
164 | }
165 |
166 |
167 | public Builder setNetworkView(View networkView) {
168 | this.networkView = networkView;
169 | return this;
170 | }
171 |
172 | public Builder setNoLoginView(View noLoginView) {
173 | this.noLoginView = noLoginView;
174 | return this;
175 | }
176 |
177 | public Builder setErrorView(View errorView) {
178 | this.errorView = errorView;
179 | return this;
180 | }
181 |
182 | public Builder setLoadingView(View loadingView) {
183 | this.loadingView = loadingView;
184 | return this;
185 | }
186 |
187 | public Builder setEmptyView(View emptyView) {
188 | this.emptyView = emptyView;
189 | return this;
190 | }
191 |
192 |
193 | public Builder setLayoutParams(LayoutParams params) {
194 | this.params = params;
195 | return this;
196 | }
197 |
198 | public PageStatusHelper build(){
199 | return new PageStatusHelper(context,this);
200 | }
201 |
202 | public LayoutParams getLayoutParams() {
203 | return params;
204 | }
205 |
206 | public View buildErrorView(boolean isRetry) {
207 |
208 | errorView = getView(errorView, errorLayout, errorImage, errorText);
209 |
210 | if (errorView instanceof TextView && !isRetry) {
211 | ((TextView) errorView).setText(errorText2);
212 | }
213 |
214 | return errorView;
215 | }
216 |
217 | public View buildNoLoginView() {
218 |
219 | return noLoginView = getView(noLoginView, noLoginLayout, noLoginImage, noLoginText);
220 | }
221 |
222 | public View buildEmptyView() {
223 |
224 | return emptyView = getView(emptyView, emptyLayout, emptyImage, emptyText);
225 | }
226 |
227 | public View buildNetWorkView(boolean isRetry) {
228 | networkView = getView(networkView, networkLayout, networkImage, networkText);
229 | if (networkView instanceof TextView && !isRetry) {
230 | ((TextView) networkView).setText(networkText2);
231 | }
232 |
233 | return networkView;
234 | }
235 |
236 |
237 | public View buildLoadingView() {
238 |
239 | return loadingView = getView(loadingView, loadingLayout, loadingImage, loadingText);
240 | }
241 |
242 | private View getView(View view, int layout, int image, CharSequence text) {
243 | if (view == null) {
244 | //没有实例化
245 |
246 | //优先级 layout->image->text
247 | if (layout != 0) {
248 |
249 | view = LayoutInflater.from(context).inflate(layout, (ViewGroup) bindView.getParent(), false);
250 |
251 | } else if (image != 0) {
252 |
253 | ImageView imageView = new ImageView(context);
254 | imageView.setImageResource(image);
255 | imageView.setLayoutParams(new ViewGroup.LayoutParams(params.imageWidth, params.imageHeight));
256 | view = imageView;
257 | } else {
258 |
259 | //字体颜色的获取
260 | //如果没有配置 取bindview的反转色
261 | if (textColor == null) {
262 | //调用者没有配置颜色
263 | //尝试使用bindview的反转色
264 | if (bindViewBgColor != null) {
265 |
266 | try {
267 | textColor = Color.parseColor(ColorUtils.reserveColor(bindViewBgColor));
268 | } catch (Exception e) {
269 | textColor = Color.WHITE;
270 | }
271 | } else {
272 | // bindview的反射色没取到
273 | // 设置默认白色
274 | textColor = Color.WHITE;
275 | }
276 | }
277 |
278 | TextView textView = new TextView(context);
279 | textView.setText(text);
280 | textView.setTextColor(textColor);
281 | textView.setTextSize(textSize);
282 | textView.setGravity(Gravity.CENTER);
283 | if (bindView.getWidth() > 0 && bindView.getHeight() > 0) {
284 | textView.setLayoutParams(new ViewGroup.LayoutParams(bindView.getWidth(), bindView.getHeight()));
285 | } else {
286 | textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
287 | int dp10 = ViewUtils.dip2px(bindView.getContext(), 10);
288 | textView.setPadding(dp10 * 2, dp10, dp10 * 2, dp10);
289 | }
290 | view = textView;
291 |
292 | }
293 |
294 | if (bgColor != Color.TRANSPARENT) {
295 | view.setBackgroundColor(bgColor);
296 | }
297 | } else if (view instanceof TextView) {
298 |
299 | ((TextView) view).setText(text);
300 | }
301 | //这个是必须的 因为让布局根布局的属性生效 必须使用这样的,但是刚加上如
302 | view.setVisibility(View.INVISIBLE);
303 | return view;
304 | }
305 |
306 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_coordinatorlayout.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
22 |
23 |
29 |
30 |
44 |
45 |
46 |
55 |
56 |
66 |
67 |
76 |
77 |
93 |
94 |
109 |
110 |
124 |
125 |
130 |
131 |
138 |
139 |
140 |
141 |
142 |
148 |
149 |
155 |
156 |
159 |
160 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
189 |
190 |
191 |
192 |
193 |
194 |
199 |
200 |
204 |
205 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
--------------------------------------------------------------------------------