├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── drawable
│ │ │ └── rounded_corners.xml
│ │ ├── values-en
│ │ │ └── strings.xml
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ └── layout
│ │ │ ├── layout_custom_view.xml
│ │ │ └── activity_sample.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── fingdo
│ │ └── statelayoutdemo
│ │ └── SampleActivity.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gif
└── stateLayout.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── library
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable-hdpi
│ │ │ ├── ic_state_empty.png
│ │ │ ├── ic_state_error.png
│ │ │ ├── ic_state_login.png
│ │ │ ├── ic_state_loading.png
│ │ │ ├── ic_state_time_out.png
│ │ │ └── ic_state_no_network.png
│ │ ├── drawable-mdpi
│ │ │ ├── ic_state_empty.png
│ │ │ ├── ic_state_error.png
│ │ │ ├── ic_state_login.png
│ │ │ ├── ic_state_loading.png
│ │ │ ├── ic_state_time_out.png
│ │ │ └── ic_state_no_network.png
│ │ ├── drawable-xhdpi
│ │ │ ├── ic_state_empty.png
│ │ │ ├── ic_state_error.png
│ │ │ ├── ic_state_login.png
│ │ │ ├── ic_state_loading.png
│ │ │ ├── ic_state_time_out.png
│ │ │ └── ic_state_no_network.png
│ │ ├── drawable-xxhdpi
│ │ │ ├── ic_state_empty.png
│ │ │ ├── ic_state_error.png
│ │ │ ├── ic_state_loading.png
│ │ │ ├── ic_state_login.png
│ │ │ ├── ic_state_time_out.png
│ │ │ └── ic_state_no_network.png
│ │ ├── drawable-xxxhdpi
│ │ │ ├── ic_state_empty.png
│ │ │ ├── ic_state_error.png
│ │ │ ├── ic_state_login.png
│ │ │ ├── ic_state_loading.png
│ │ │ ├── ic_state_time_out.png
│ │ │ └── ic_state_no_network.png
│ │ ├── drawable
│ │ │ └── bg_loading.xml
│ │ ├── values
│ │ │ ├── dimen.xml
│ │ │ ├── color.xml
│ │ │ ├── strings.xml
│ │ │ └── attr.xml
│ │ ├── values-en
│ │ │ └── strings.xml
│ │ └── layout
│ │ │ ├── layout_loading.xml
│ │ │ ├── layout_empty.xml
│ │ │ ├── layout_login.xml
│ │ │ ├── layout_error.xml
│ │ │ ├── layout_time_out.xml
│ │ │ └── layout_no_network.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── fingdo
│ │ └── statelayout
│ │ ├── holder
│ │ ├── BaseHolder.java
│ │ ├── ErrorViewHolder.java
│ │ ├── LoginViewHolder.java
│ │ ├── TimeOutViewHolder.java
│ │ ├── NoNetworkViewHolder.java
│ │ ├── EmptyViewHolder.java
│ │ └── LoadingViewHolder.java
│ │ ├── bean
│ │ ├── LoadingItem.java
│ │ ├── EmptyItem.java
│ │ ├── ErrorItem.java
│ │ ├── LoginItem.java
│ │ ├── TimeOutItem.java
│ │ ├── NoNetworkItem.java
│ │ └── BaseItem.java
│ │ ├── anim
│ │ ├── ViewAnimProvider.java
│ │ ├── FadeViewAnimProvider.java
│ │ └── FadeScaleViewAnimProvider.java
│ │ ├── helper
│ │ ├── ViewHelper.java
│ │ ├── AnimationHelper.java
│ │ └── LayoutHelper.java
│ │ └── StateLayout.java
├── .gitignore
├── build.gradle
└── proguard-rules.pro
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README-zh.md
├── gradlew
├── README.md
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------
/gif/stateLayout.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/gif/stateLayout.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_state_empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-hdpi/ic_state_empty.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_state_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-hdpi/ic_state_error.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_state_login.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-hdpi/ic_state_login.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_state_empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-mdpi/ic_state_empty.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_state_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-mdpi/ic_state_error.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_state_login.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-mdpi/ic_state_login.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_state_empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xhdpi/ic_state_empty.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_state_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xhdpi/ic_state_error.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_state_login.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xhdpi/ic_state_login.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_state_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-hdpi/ic_state_loading.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_state_time_out.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-hdpi/ic_state_time_out.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_state_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-mdpi/ic_state_loading.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_state_time_out.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-mdpi/ic_state_time_out.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_state_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xhdpi/ic_state_loading.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_state_time_out.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xhdpi/ic_state_time_out.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_state_empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xxhdpi/ic_state_empty.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_state_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xxhdpi/ic_state_error.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_state_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xxhdpi/ic_state_loading.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_state_login.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xxhdpi/ic_state_login.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_state_empty.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xxxhdpi/ic_state_empty.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_state_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xxxhdpi/ic_state_error.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_state_login.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xxxhdpi/ic_state_login.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_state_no_network.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-hdpi/ic_state_no_network.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_state_no_network.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-mdpi/ic_state_no_network.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_state_no_network.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xhdpi/ic_state_no_network.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_state_time_out.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xxhdpi/ic_state_time_out.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_state_loading.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xxxhdpi/ic_state_loading.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_state_time_out.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xxxhdpi/ic_state_time_out.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_state_no_network.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xxhdpi/ic_state_no_network.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxxhdpi/ic_state_no_network.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fingdo/stateLayout/HEAD/library/src/main/res/drawable-xxxhdpi/ic_state_no_network.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 | * author : fingdo 8 | * e-mail : fingdo@qq.com 9 | * time : 2017/03/13 10 | * desc : 基类ViewHolder 11 | * version: 1.0 12 | *13 | */ 14 | 15 | public class BaseHolder { 16 | 17 | public TextView tvTip; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 |
5 | * author : fingdo 6 | * e-mail : fingdo@qq.com 7 | * time : 2017/03/10 8 | * desc : 加载数据对象 9 | * version: 1.0 10 | *11 | */ 12 | 13 | public class LoadingItem extends BaseItem { 14 | 15 | public LoadingItem(String tip) { 16 | setTip(tip); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /library/src/main/java/com/fingdo/statelayout/bean/EmptyItem.java: -------------------------------------------------------------------------------- 1 | package com.fingdo.statelayout.bean; 2 | 3 | /** 4 | *
5 | * author : fingdo 6 | * e-mail : fingdo@qq.com 7 | * time : 2017/03/10 8 | * desc : 空数据对象 9 | * version: 1.0 10 | *11 | */ 12 | 13 | public class EmptyItem extends BaseItem { 14 | 15 | public EmptyItem(int resId, String tip) { 16 | setResId(resId); 17 | setTip(tip); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /library/src/main/java/com/fingdo/statelayout/bean/ErrorItem.java: -------------------------------------------------------------------------------- 1 | package com.fingdo.statelayout.bean; 2 | 3 | /** 4 | *
5 | * author : fingdo 6 | * e-mail : fingdo@qq.com 7 | * time : 2017/03/10 8 | * desc : 错误数据对象 9 | * version: 1.0 10 | *11 | */ 12 | 13 | public class ErrorItem extends BaseItem { 14 | 15 | public ErrorItem(int resId, String tip) { 16 | setResId(resId); 17 | setTip(tip); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /library/src/main/java/com/fingdo/statelayout/bean/LoginItem.java: -------------------------------------------------------------------------------- 1 | package com.fingdo.statelayout.bean; 2 | 3 | /** 4 | *
5 | * author : fingdo 6 | * e-mail : fingdo@qq.com 7 | * time : 2017/03/10 8 | * desc : 登录对象 9 | * version: 1.0 10 | *11 | */ 12 | 13 | public class LoginItem extends BaseItem { 14 | 15 | public LoginItem(int resId, String tip) { 16 | setResId(resId); 17 | setTip(tip); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 |
5 | * author : fingdo 6 | * e-mail : fingdo@qq.com 7 | * time : 2017/03/10 8 | * desc : 超时数据对象 9 | * version: 1.0 10 | *11 | */ 12 | 13 | public class TimeOutItem extends BaseItem { 14 | 15 | public TimeOutItem(int resId, String tip) { 16 | setResId(resId); 17 | setTip(tip); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /library/src/main/java/com/fingdo/statelayout/bean/NoNetworkItem.java: -------------------------------------------------------------------------------- 1 | package com.fingdo.statelayout.bean; 2 | 3 | /** 4 | *
5 | * author : fingdo 6 | * e-mail : fingdo@qq.com 7 | * time : 2017/03/10 8 | * desc : 没有网络数据对象 9 | * version: 1.0 10 | *11 | */ 12 | 13 | public class NoNetworkItem extends BaseItem { 14 | 15 | public NoNetworkItem(int resId, String tip) { 16 | setResId(resId); 17 | setTip(tip); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /library/src/main/java/com/fingdo/statelayout/anim/ViewAnimProvider.java: -------------------------------------------------------------------------------- 1 | package com.fingdo.statelayout.anim; 2 | 3 | import android.view.animation.Animation; 4 | 5 | /** 6 | *
7 | * author : fingdo 8 | * e-mail : fingdo@qq.com 9 | * time : 2017/03/13 10 | * desc : 基类ViewAnimProvider 11 | * version: 1.0 12 | *13 | */ 14 | 15 | public interface ViewAnimProvider { 16 | 17 | Animation showAnimation(); 18 | 19 | Animation hideAnimation(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_custom_view.xml: -------------------------------------------------------------------------------- 1 | 2 |
5 | * author : fingdo 6 | * e-mail : fingdo@qq.com 7 | * time : 2017/03/10 8 | * desc : 基类对象 9 | * version: 1.0 10 | *11 | */ 12 | 13 | public class BaseItem { 14 | 15 | private int resId; 16 | private String tip; 17 | 18 | public int getResId() { 19 | return resId; 20 | } 21 | 22 | public void setResId(int resId) { 23 | this.resId = resId; 24 | } 25 | 26 | public String getTip() { 27 | return tip; 28 | } 29 | 30 | public void setTip(String tip) { 31 | this.tip = tip; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/fingdo/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/fingdo/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 |
10 | * author : fingdo 11 | * e-mail : fingdo@qq.com 12 | * time : 2017/03/13 13 | * desc : 渐隐动画 14 | * version: 1.0 15 | *16 | */ 17 | 18 | public class FadeViewAnimProvider implements ViewAnimProvider { 19 | 20 | @Override 21 | public Animation showAnimation() { 22 | Animation animation = new AlphaAnimation(0.0f,1.0f); 23 | animation.setDuration(200); 24 | animation.setInterpolator(new DecelerateInterpolator()); 25 | return animation; 26 | } 27 | 28 | @Override 29 | public Animation hideAnimation() { 30 | Animation animation = new AlphaAnimation(1.0f,0.0f); 31 | animation.setDuration(200); 32 | animation.setInterpolator(new AccelerateDecelerateInterpolator()); 33 | return animation; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /library/src/main/res/layout/layout_empty.xml: -------------------------------------------------------------------------------- 1 | 2 |
11 | * author : fingdo 12 | * e-mail : fingdo@qq.com 13 | * time : 2017/03/13 14 | * desc : 渐隐缩放动画 15 | * version: 1.0 16 | *17 | */ 18 | 19 | public class FadeScaleViewAnimProvider implements ViewAnimProvider { 20 | 21 | public Animation showAnimation() { 22 | AnimationSet set = new AnimationSet(true); 23 | Animation alphaAnimation = new AlphaAnimation(0.0f, 1.0f); 24 | Animation scaleAnimation = new ScaleAnimation(0.1f, 1f, 0.1f, 1f, Animation.RELATIVE_TO_SELF, 25 | 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 26 | 27 | set.setDuration(200); 28 | set.setInterpolator(new DecelerateInterpolator()); 29 | set.addAnimation(alphaAnimation); 30 | set.addAnimation(scaleAnimation); 31 | return set; 32 | } 33 | 34 | @Override 35 | public Animation hideAnimation() { 36 | AnimationSet set = new AnimationSet(true); 37 | Animation alphaAnimation = new AlphaAnimation(1.0f, 0.0f); 38 | Animation scaleAnimation = new ScaleAnimation(1.0f, 0.1f, 1.0f, 0.1f, Animation.RELATIVE_TO_SELF, 0.5f, 39 | Animation.RELATIVE_TO_SELF, 0.5f); 40 | 41 | set.setDuration(200); 42 | set.setInterpolator(new DecelerateInterpolator()); 43 | set.addAnimation(alphaAnimation); 44 | set.addAnimation(scaleAnimation); 45 | return set; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /library/src/main/java/com/fingdo/statelayout/helper/ViewHelper.java: -------------------------------------------------------------------------------- 1 | package com.fingdo.statelayout.helper; 2 | 3 | import android.view.View; 4 | import android.widget.ImageView; 5 | import android.widget.TextView; 6 | 7 | import com.fingdo.statelayout.holder.EmptyViewHolder; 8 | import com.fingdo.statelayout.holder.ErrorViewHolder; 9 | import com.fingdo.statelayout.holder.LoadingViewHolder; 10 | import com.fingdo.statelayout.holder.NoNetworkViewHolder; 11 | import com.fingdo.statelayout.holder.TimeOutViewHolder; 12 | 13 | /** 14 | *
15 | * author : fingdo 16 | * e-mail : fingdo@qq.com 17 | * time : 2017/03/13 18 | * desc : View设置帮助类 19 | * version: 1.0 20 | *21 | */ 22 | 23 | public class ViewHelper { 24 | 25 | public static final int ERROR = 1; 26 | public static final int EMPTY = 2; 27 | public static final int TIMEOUT = 3; 28 | public static final int NOT_NETWORK = 4; 29 | public static final int LOADING = 5; 30 | 31 | 32 | public TextView getTvTip(int type, View view) { 33 | switch (type) { 34 | case ERROR: 35 | return ((ErrorViewHolder) view.getTag()).tvTip; 36 | case EMPTY: 37 | return ((EmptyViewHolder) view.getTag()).tvTip; 38 | case TIMEOUT: 39 | return ((TimeOutViewHolder) view.getTag()).tvTip; 40 | case NOT_NETWORK: 41 | return ((NoNetworkViewHolder) view.getTag()).tvTip; 42 | case LOADING: 43 | return ((LoadingViewHolder) view.getTag()).tvTip; 44 | default: 45 | return null; 46 | } 47 | } 48 | 49 | public ImageView getImg(int type, View view) { 50 | switch (type) { 51 | case ERROR: 52 | return ((ErrorViewHolder) view.getTag()).ivImg; 53 | case EMPTY: 54 | return ((EmptyViewHolder) view.getTag()).ivImg; 55 | case TIMEOUT: 56 | return ((TimeOutViewHolder) view.getTag()).ivImg; 57 | case NOT_NETWORK: 58 | return ((NoNetworkViewHolder) view.getTag()).ivImg; 59 | default: 60 | return null; 61 | } 62 | } 63 | 64 | 65 | } 66 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /library/src/main/java/com/fingdo/statelayout/helper/AnimationHelper.java: -------------------------------------------------------------------------------- 1 | package com.fingdo.statelayout.helper; 2 | 3 | import android.view.View; 4 | import android.view.animation.Animation; 5 | 6 | import com.fingdo.statelayout.anim.FadeScaleViewAnimProvider; 7 | import com.fingdo.statelayout.anim.ViewAnimProvider; 8 | 9 | /** 10 | *
11 | * author : fingdo 12 | * e-mail : fingdo@qq.com 13 | * time : 2017/03/14 14 | * desc : 动画帮助类 15 | * version: 1.0 16 | *17 | */ 18 | 19 | public class AnimationHelper { 20 | 21 | 22 | /** 23 | * 切换布局 24 | * @param useAnimation 是否使用动画 25 | * @param viewAnimProvider 动画持有类 26 | * @param fromView 开始View 27 | * @param toView 结束View 28 | */ 29 | public static void switchViewByAnim(boolean useAnimation, ViewAnimProvider viewAnimProvider, 30 | final View fromView, View toView) { 31 | if (fromView == toView) 32 | return; 33 | if (useAnimation) { 34 | if (viewAnimProvider == null) { 35 | //使用默认动画 36 | viewAnimProvider = new FadeScaleViewAnimProvider(); 37 | } 38 | Animation hideAnimation = viewAnimProvider.hideAnimation(); 39 | Animation showAnimation = viewAnimProvider.showAnimation(); 40 | 41 | if (fromView != null) { 42 | if (hideAnimation != null) { 43 | hideAnimation.setAnimationListener(new Animation.AnimationListener() { 44 | @Override 45 | public void onAnimationStart(Animation animation) { 46 | 47 | } 48 | 49 | @Override 50 | public void onAnimationEnd(Animation animation) { 51 | fromView.setVisibility(View.GONE); 52 | } 53 | 54 | @Override 55 | public void onAnimationRepeat(Animation animation) { 56 | 57 | } 58 | }); 59 | hideAnimation.setFillAfter(false); 60 | fromView.startAnimation(hideAnimation); 61 | } else { 62 | fromView.setVisibility(View.GONE); 63 | } 64 | } 65 | if (toView != null) { 66 | if (toView.getVisibility() != View.VISIBLE) { 67 | toView.setVisibility(View.VISIBLE); 68 | } 69 | if (showAnimation != null) { 70 | showAnimation.setFillAfter(false); 71 | toView.startAnimation(showAnimation); 72 | } 73 | } 74 | } else { 75 | if (fromView != null) { 76 | fromView.setVisibility(View.GONE); 77 | } 78 | if (toView != null) { 79 | toView.setVisibility(View.VISIBLE); 80 | } 81 | } 82 | 83 | 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_sample.xml: -------------------------------------------------------------------------------- 1 | 2 |
18 | * author : fingdo 19 | * e-mail : fingdo@qq.com 20 | * time : 2017/03/10 21 | * desc : 测试StateLayout 22 | * version: 1.0 23 | *24 | */ 25 | 26 | public class SampleActivity extends AppCompatActivity implements View.OnClickListener { 27 | 28 | 29 | private StateLayout stateLayout; 30 | private RelativeLayout rlCustom; 31 | 32 | @Override 33 | protected void onCreate(@Nullable Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_sample); 36 | 37 | stateLayout = (StateLayout) findViewById(R.id.state_layout); 38 | rlCustom = (RelativeLayout) findViewById(R.id.rl_custom); 39 | 40 | 41 | //提前设置 42 | //设置空数据提示文字 43 | //stateLayout.setTipText(StateLayout.EMPTY, "empty tip text"); 44 | //stateLayout.setTipText(StateLayout.EMPTY, R.string.empty_tip); 45 | //空数据提示图标 46 | //stateLayout.setTipImg(StateLayout.EMPTY, R.drawable.ic_state_empty); 47 | //stateLayout.setTipImg(StateLayout.EMPTY, getResources().getDrawable(R.drawable.ic_state_empty)); 48 | 49 | 50 | //展示内容的界面 51 | // stateLayout.showContentView(); 52 | //展示加载中的界面 53 | // stateLayout.showLoadingView(); 54 | 55 | //展示没有网络的界面 56 | // stateLayout.showNoNetworkView(); 57 | //展示超时的界面 58 | // stateLayout.showTimeoutView(); 59 | //展示空数据的界面 60 | // stateLayout.showEmptyView(); 61 | //展示错误的界面 62 | // stateLayout.showErrorView(); 63 | //展示登录的界面 64 | // stateLayout.showLoginView(); 65 | 66 | 67 | //显示加载界面 68 | // stateLayout.showLoadingView(); 69 | 70 | //显示自定义界面 71 | // stateLayout.showCustomView(); 72 | 73 | 74 | stateLayout.setUseAnimation(true); 75 | // stateLayout.setViewSwitchAnimProvider(new FadeScaleViewAnimProvider()); 76 | stateLayout.setRefreshListener(new StateLayout.OnViewRefreshListener() { 77 | @Override 78 | public void refreshClick() { 79 | Toast.makeText(SampleActivity.this, R.string.toast_refresh, Toast.LENGTH_SHORT).show(); 80 | } 81 | 82 | @Override 83 | public void loginClick() { 84 | Toast.makeText(SampleActivity.this, R.string.toast_sign_in, Toast.LENGTH_SHORT).show(); 85 | } 86 | }); 87 | 88 | findViewById(R.id.btn_content).setOnClickListener(this); 89 | findViewById(R.id.btn_empty).setOnClickListener(this); 90 | findViewById(R.id.btn_error).setOnClickListener(this); 91 | findViewById(R.id.btn_loading).setOnClickListener(this); 92 | findViewById(R.id.btn_loading_no_tip).setOnClickListener(this); 93 | findViewById(R.id.btn_time_out).setOnClickListener(this); 94 | findViewById(R.id.btn_not_network).setOnClickListener(this); 95 | findViewById(R.id.btn_login).setOnClickListener(this); 96 | findViewById(R.id.btn_custom).setOnClickListener(this); 97 | } 98 | 99 | @Override 100 | public void onClick(View v) { 101 | switch (v.getId()) { 102 | case R.id.btn_content: 103 | stateLayout.showContentView(); 104 | // stateLayout.setTipText(StateLayout.EMPTY, "12345"); 105 | // stateLayout.setTipImg(StateLayout.EMPTY, R.mipmap.ic_launcher); 106 | break; 107 | case R.id.btn_empty: 108 | stateLayout.showEmptyView(); 109 | // stateLayout.setTipText(StateLayout.ERROR, "12345"); 110 | // stateLayout.setTipImg(StateLayout.ERROR, R.mipmap.ic_launcher); 111 | break; 112 | case R.id.btn_error: 113 | stateLayout.showErrorView(); 114 | // stateLayout.setTipText(StateLayout.LOADING, "12345"); 115 | break; 116 | case R.id.btn_loading: 117 | stateLayout.showLoadingView(); 118 | // stateLayout.setTipText(StateLayout.TIMEOUT, "12345"); 119 | // stateLayout.setTipImg(StateLayout.TIMEOUT, R.mipmap.ic_launcher); 120 | break; 121 | case R.id.btn_loading_no_tip: 122 | ImageView imageView = new ImageView(this); 123 | imageView.setBackgroundResource(R.color.colorPrimary); 124 | ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(300, 300); 125 | imageView.setLayoutParams(layoutParams); 126 | stateLayout.showLoadingView(imageView, false); 127 | // stateLayout.setTipText(StateLayout.TIMEOUT, "12345"); 128 | // stateLayout.setTipImg(StateLayout.TIMEOUT, R.mipmap.ic_launcher); 129 | break; 130 | case R.id.btn_time_out: 131 | stateLayout.showTimeoutView(); 132 | // stateLayout.setTipText(StateLayout.NOT_NETWORK, "12345"); 133 | // stateLayout.setTipImg(StateLayout.NOT_NETWORK, R.mipmap.ic_launcher); 134 | break; 135 | case R.id.btn_not_network: 136 | stateLayout.showNoNetworkView(); 137 | break; 138 | case R.id.btn_login: 139 | stateLayout.showLoginView(); 140 | break; 141 | case R.id.btn_custom: 142 | // View customView = LayoutInflater.from(this).inflate(R.layout.layout_custom_view, null); 143 | stateLayout.showCustomView(rlCustom); 144 | break; 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # StateLayout usage 2 | 3 | ## Demo 4 | 5 |  6 | 7 | 8 | ## Dependently 9 | - one step 10 | add to your project `build.gradle` 11 | 12 | ``` basic 13 | allprojects { 14 | repositories { 15 | maven { url 'https://jitpack.io' } 16 | } 17 | } 18 | ``` 19 | - second step 20 | 21 | ``` basic 22 | compile 'com.github.fingdo:stateLayout:1.0.4' 23 | ``` 24 | 25 | [中文文档点这里](README-zh.md) 26 | 27 | ### add in your xml 28 | 29 | Usage is consistent with `ScrollView`, allowing only one root layout 30 | 31 | ``` xml 32 |
31 | * author : fingdo 32 | * e-mail : fingdo@qq.com 33 | * time : 2017/03/10 34 | * desc : StateLayout帮助类 35 | * version: 1.0 36 | *37 | */ 38 | 39 | public class LayoutHelper { 40 | 41 | /** 42 | * 解析布局中的可选参数 43 | * 44 | * @param context 45 | * @param attrs 46 | * @param stateLayout 47 | */ 48 | public static void parseAttr(Context context, AttributeSet attrs, StateLayout stateLayout) { 49 | TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.StateLayout, 0, 0); 50 | try { 51 | int errorImg = a.getResourceId(R.styleable.StateLayout_errorImg, -1); 52 | String errorText = a.getString(R.styleable.StateLayout_errorText); 53 | stateLayout.setErrorItem(new ErrorItem(errorImg, errorText)); 54 | 55 | int timeOutImg = a.getResourceId(R.styleable.StateLayout_timeOutImg, -1); 56 | String timeOutText = a.getString(R.styleable.StateLayout_timeOutText); 57 | stateLayout.setTimeOutItem(new TimeOutItem(timeOutImg, timeOutText)); 58 | 59 | int emptyImg = a.getResourceId(R.styleable.StateLayout_emptyImg, -1); 60 | String emptyText = a.getString(R.styleable.StateLayout_emptyText); 61 | stateLayout.setEmptyItem(new EmptyItem(emptyImg, emptyText)); 62 | 63 | int noNetworkImg = a.getResourceId(R.styleable.StateLayout_noNetworkImg, -1); 64 | String noNetworkText = a.getString(R.styleable.StateLayout_noNetworkText); 65 | stateLayout.setNoNetworkItem(new NoNetworkItem(noNetworkImg, noNetworkText)); 66 | 67 | int loginImg = a.getResourceId(R.styleable.StateLayout_loginImg, -1); 68 | String loginText = a.getString(R.styleable.StateLayout_loginText); 69 | stateLayout.setLoginItem(new LoginItem(loginImg, loginText)); 70 | 71 | String loadingText = a.getString(R.styleable.StateLayout_loadingText); 72 | stateLayout.setLoadingItem(new LoadingItem(loadingText)); 73 | } finally { 74 | a.recycle(); 75 | } 76 | } 77 | 78 | /** 79 | * 获取初始的错误View 80 | * 81 | * @param layoutInflater 布局填充器 82 | * @param item 错误bean 83 | * @param layout 容器 84 | * @return 错误View 85 | */ 86 | public static View getErrorView(LayoutInflater layoutInflater, ErrorItem item, 87 | final StateLayout layout) { 88 | View view = layoutInflater.inflate(R.layout.layout_error, null); 89 | if (item != null) { 90 | ErrorViewHolder holder = new ErrorViewHolder(view); 91 | view.setTag(holder); 92 | 93 | if (!TextUtils.isEmpty(item.getTip())) { 94 | holder.tvTip.setText(item.getTip()); 95 | } 96 | if (item.getResId() != -1) { 97 | holder.ivImg.setImageResource(item.getResId()); 98 | } 99 | view.setOnClickListener(new View.OnClickListener() { 100 | @Override 101 | public void onClick(View v) { 102 | if (layout.getRefreshLListener() != null) { 103 | layout.getRefreshLListener().refreshClick(); 104 | } 105 | } 106 | }); 107 | } 108 | return view; 109 | } 110 | 111 | /** 112 | * 获取初始的没有网络View 113 | * 114 | * @param layoutInflater 布局填充器 115 | * @param item 没有网络bean 116 | * @param layout 容器 117 | * @return 没有网络View 118 | */ 119 | public static View getNoNetworkView(LayoutInflater layoutInflater, NoNetworkItem item, 120 | final StateLayout layout) { 121 | View view = layoutInflater.inflate(R.layout.layout_no_network, null); 122 | if (item != null) { 123 | NoNetworkViewHolder holder = new NoNetworkViewHolder(view); 124 | view.setTag(holder); 125 | 126 | if (!TextUtils.isEmpty(item.getTip())) { 127 | holder.tvTip.setText(item.getTip()); 128 | } 129 | if (item.getResId() != -1) { 130 | holder.ivImg.setImageResource(item.getResId()); 131 | } 132 | view.setOnClickListener(new View.OnClickListener() { 133 | @Override 134 | public void onClick(View v) { 135 | if (layout.getRefreshLListener() != null) { 136 | layout.getRefreshLListener().refreshClick(); 137 | } 138 | } 139 | }); 140 | } 141 | return view; 142 | } 143 | 144 | /** 145 | * 获取初始的加载View 146 | * 147 | * @param layoutInflater 布局填充器 148 | * @param item 加载bean 149 | * @return 加载View 150 | */ 151 | public static View getLoadingView(LayoutInflater layoutInflater, LoadingItem item) { 152 | View view = layoutInflater.inflate(R.layout.layout_loading, null); 153 | if (item != null) { 154 | LoadingViewHolder holder = new LoadingViewHolder(view); 155 | view.setTag(holder); 156 | 157 | ProgressBar progressBar = new ProgressBar(view.getContext()); 158 | progressBar.setIndeterminateDrawable(view.getResources().getDrawable(R.drawable.bg_loading)); 159 | holder.frameLayout.addView(progressBar); 160 | 161 | if (!TextUtils.isEmpty(item.getTip())) { 162 | holder.tvTip.setText(item.getTip()); 163 | } 164 | } 165 | return view; 166 | } 167 | 168 | /** 169 | * 获取初始的超时View 170 | * 171 | * @param layoutInflater 布局填充器 172 | * @param item 超时bean 173 | * @param layout 容器 174 | * @return 超时View 175 | */ 176 | public static View getTimeOutView(LayoutInflater layoutInflater, TimeOutItem item, 177 | final StateLayout layout) { 178 | View view = layoutInflater.inflate(R.layout.layout_time_out, null); 179 | if (item != null) { 180 | TimeOutViewHolder holder = new TimeOutViewHolder(view); 181 | view.setTag(holder); 182 | 183 | if (!TextUtils.isEmpty(item.getTip())) { 184 | holder.tvTip.setText(item.getTip()); 185 | } 186 | if (item.getResId() != -1) { 187 | holder.ivImg.setImageResource(item.getResId()); 188 | } 189 | view.setOnClickListener(new View.OnClickListener() { 190 | @Override 191 | public void onClick(View v) { 192 | if (layout.getRefreshLListener() != null) { 193 | layout.getRefreshLListener().refreshClick(); 194 | } 195 | } 196 | }); 197 | } 198 | return view; 199 | } 200 | 201 | /** 202 | * 获取初始的空数据View 203 | * 204 | * @param layoutInflater 布局填充器 205 | * @param item 空数据bean 206 | * @return 空数据View 207 | */ 208 | public static View getEmptyView(LayoutInflater layoutInflater, EmptyItem item) { 209 | View view = layoutInflater.inflate(R.layout.layout_empty, null); 210 | if (item != null) { 211 | EmptyViewHolder holder = new EmptyViewHolder(view); 212 | view.setTag(holder); 213 | 214 | if (!TextUtils.isEmpty(item.getTip())) { 215 | holder.tvTip.setText(item.getTip()); 216 | } 217 | if (item.getResId() != -1) { 218 | holder.ivImg.setImageResource(item.getResId()); 219 | } 220 | } 221 | return view; 222 | } 223 | 224 | 225 | /** 226 | * 获取初始的空数据View 227 | * 228 | * @param layoutInflater 布局填充器 229 | * @param item 空数据bean 230 | * @return 空数据View 231 | */ 232 | public static View getLoginView(LayoutInflater layoutInflater, LoginItem item, 233 | final StateLayout layout) { 234 | View view = layoutInflater.inflate(R.layout.layout_login, null); 235 | if (item != null) { 236 | LoginViewHolder holder = new LoginViewHolder(view); 237 | view.setTag(holder); 238 | 239 | if (!TextUtils.isEmpty(item.getTip())) { 240 | holder.tvTip.setText(item.getTip()); 241 | } 242 | if (item.getResId() != -1) { 243 | holder.ivImg.setImageResource(item.getResId()); 244 | } 245 | view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { 246 | @Override 247 | public void onClick(View v) { 248 | if (layout.getRefreshLListener() != null) { 249 | layout.getRefreshLListener().loginClick(); 250 | } 251 | } 252 | }); 253 | } 254 | return view; 255 | } 256 | 257 | } 258 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /library/src/main/java/com/fingdo/statelayout/StateLayout.java: -------------------------------------------------------------------------------- 1 | package com.fingdo.statelayout; 2 | 3 | import android.content.Context; 4 | import android.graphics.drawable.Drawable; 5 | import android.text.TextUtils; 6 | import android.util.AttributeSet; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.FrameLayout; 11 | 12 | import com.fingdo.statelayout.anim.ViewAnimProvider; 13 | import com.fingdo.statelayout.bean.EmptyItem; 14 | import com.fingdo.statelayout.bean.ErrorItem; 15 | import com.fingdo.statelayout.bean.LoadingItem; 16 | import com.fingdo.statelayout.bean.LoginItem; 17 | import com.fingdo.statelayout.bean.NoNetworkItem; 18 | import com.fingdo.statelayout.bean.TimeOutItem; 19 | import com.fingdo.statelayout.helper.AnimationHelper; 20 | import com.fingdo.statelayout.helper.LayoutHelper; 21 | import com.fingdo.statelayout.holder.EmptyViewHolder; 22 | import com.fingdo.statelayout.holder.ErrorViewHolder; 23 | import com.fingdo.statelayout.holder.LoadingViewHolder; 24 | import com.fingdo.statelayout.holder.LoginViewHolder; 25 | import com.fingdo.statelayout.holder.NoNetworkViewHolder; 26 | import com.fingdo.statelayout.holder.TimeOutViewHolder; 27 | 28 | 29 | /** 30 | *
31 | * author : fingdo 32 | * e-mail : fingdo@qq.com 33 | * time : 2017/03/10 34 | * desc : 多状态Layout动态切换 35 | * version: 1.0 36 | *37 | */ 38 | 39 | public class StateLayout extends FrameLayout { 40 | 41 | public static final int ERROR = 1; 42 | public static final int EMPTY = 2; 43 | public static final int TIMEOUT = 3; 44 | public static final int NOT_NETWORK = 4; 45 | public static final int LOADING = 5; 46 | public static final int LOGIN = 6; 47 | 48 | private View contentView; 49 | private View emptyView; 50 | private View errorView; 51 | private View loadingView; 52 | private View timeOutView; 53 | private View notNetworkView; 54 | private View loginView; 55 | 56 | private ErrorItem errorItem; 57 | private NoNetworkItem noNetworkItem; 58 | private EmptyItem emptyItem; 59 | private LoadingItem loadingItem; 60 | private TimeOutItem timeOutItem; 61 | private LoginItem loginItem; 62 | 63 | private OnViewRefreshListener mListener; 64 | 65 | private ViewAnimProvider viewAnimProvider; 66 | private boolean useAnimation = false; 67 | 68 | public OnViewRefreshListener getRefreshLListener() { 69 | return mListener; 70 | } 71 | 72 | public void setRefreshListener(OnViewRefreshListener listener) { 73 | this.mListener = listener; 74 | } 75 | 76 | public void setErrorItem(ErrorItem errorItem) { 77 | this.errorItem = errorItem; 78 | } 79 | 80 | public void setNoNetworkItem(NoNetworkItem noNetworkItem) { 81 | this.noNetworkItem = noNetworkItem; 82 | } 83 | 84 | public void setEmptyItem(EmptyItem emptyItem) { 85 | this.emptyItem = emptyItem; 86 | } 87 | 88 | public void setLoadingItem(LoadingItem loadingItem) { 89 | this.loadingItem = loadingItem; 90 | } 91 | 92 | public void setTimeOutItem(TimeOutItem timeOutItem) { 93 | this.timeOutItem = timeOutItem; 94 | } 95 | 96 | public void setLoginItem(LoginItem loginItem) { 97 | this.loginItem = loginItem; 98 | } 99 | 100 | private View currentShowingView; 101 | 102 | public StateLayout(Context context) { 103 | this(context, null); 104 | } 105 | 106 | public StateLayout(Context context, AttributeSet attrs) { 107 | super(context, attrs); 108 | init(context, attrs); 109 | } 110 | 111 | public StateLayout(Context context, AttributeSet attrs, int defStyleAttr) { 112 | super(context, attrs, defStyleAttr); 113 | init(context, attrs); 114 | } 115 | 116 | private void init(Context context, AttributeSet attrs) { 117 | LayoutHelper.parseAttr(context, attrs, this); 118 | 119 | LayoutInflater inflater = LayoutInflater.from(context); 120 | 121 | errorView = LayoutHelper.getErrorView(inflater, errorItem, this); 122 | 123 | emptyView = LayoutHelper.getEmptyView(inflater, emptyItem); 124 | 125 | notNetworkView = LayoutHelper.getNoNetworkView(inflater, noNetworkItem, this); 126 | 127 | timeOutView = LayoutHelper.getTimeOutView(inflater, timeOutItem, this); 128 | 129 | loadingView = LayoutHelper.getLoadingView(inflater, loadingItem); 130 | 131 | loginView = LayoutHelper.getLoginView(inflater, loginItem, this); 132 | } 133 | 134 | private void checkIsContentView(View view) { 135 | if (contentView == null && view != errorView && view != notNetworkView 136 | && view != loadingView && view != timeOutView && view != loginView 137 | && view != emptyView) { 138 | contentView = view; 139 | currentShowingView = contentView; 140 | } 141 | } 142 | 143 | //************ showView ************// 144 | 145 | /** 146 | * 展示错误的界面 147 | */ 148 | public void showErrorView() { 149 | if (errorView.getParent() == null) { 150 | addView(errorView); 151 | } 152 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, errorView); 153 | currentShowingView = errorView; 154 | } 155 | 156 | /** 157 | * 展示错误的界面 158 | * 159 | * @param msgId 提示语 160 | */ 161 | public void showErrorView(int msgId) { 162 | if (errorView.getParent() == null) { 163 | addView(errorView); 164 | } 165 | setTipText(ERROR, msgId); 166 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, errorView); 167 | currentShowingView = errorView; 168 | } 169 | 170 | /** 171 | * 展示错误的界面 172 | * 173 | * @param msg 提示语 174 | */ 175 | public void showErrorView(String msg) { 176 | if (errorView.getParent() == null) { 177 | addView(errorView); 178 | } 179 | setTipText(ERROR, msg); 180 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, errorView); 181 | currentShowingView = errorView; 182 | } 183 | 184 | /** 185 | * 展示错误的界面 186 | * 187 | * @param msgId 提示语 188 | * @param imgId 图片Id 189 | */ 190 | public void showErrorView(int msgId, int imgId) { 191 | if (errorView.getParent() == null) { 192 | addView(errorView); 193 | } 194 | setTipText(ERROR, msgId); 195 | setTipImg(ERROR, imgId); 196 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, errorView); 197 | currentShowingView = errorView; 198 | } 199 | 200 | /** 201 | * 展示错误的界面 202 | * 203 | * @param msg 提示语 204 | * @param imgId 图片Id 205 | */ 206 | public void showErrorView(String msg, int imgId) { 207 | if (errorView.getParent() == null) { 208 | addView(errorView); 209 | } 210 | setTipText(ERROR, msg); 211 | setTipImg(ERROR, imgId); 212 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, errorView); 213 | currentShowingView = errorView; 214 | } 215 | 216 | /** 217 | * 展示空数据的界面 218 | */ 219 | public void showEmptyView() { 220 | if (emptyView.getParent() == null) { 221 | addView(emptyView); 222 | } 223 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, emptyView); 224 | currentShowingView = emptyView; 225 | } 226 | 227 | /** 228 | * 展示空数据的界面 229 | * 230 | * @param msgId 提示语 231 | */ 232 | public void showEmptyView(int msgId) { 233 | if (emptyView.getParent() == null) { 234 | addView(emptyView); 235 | } 236 | setTipText(EMPTY, msgId); 237 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, emptyView); 238 | currentShowingView = emptyView; 239 | } 240 | 241 | /** 242 | * 展示空数据的界面 243 | * 244 | * @param msg 提示语 245 | */ 246 | public void showEmptyView(String msg) { 247 | if (emptyView.getParent() == null) { 248 | addView(emptyView); 249 | } 250 | setTipText(EMPTY, msg); 251 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, emptyView); 252 | currentShowingView = emptyView; 253 | } 254 | 255 | /** 256 | * 展示空数据的界面 257 | * 258 | * @param msgId 提示语 259 | * @param imgId 图片Id 260 | */ 261 | public void showEmptyView(int msgId, int imgId) { 262 | if (emptyView.getParent() == null) { 263 | addView(emptyView); 264 | } 265 | setTipText(EMPTY, msgId); 266 | setTipImg(EMPTY, imgId); 267 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, emptyView); 268 | currentShowingView = emptyView; 269 | } 270 | 271 | /** 272 | * 展示空数据的界面 273 | * 274 | * @param msg 提示语 275 | * @param imgId 图片Id 276 | */ 277 | public void showEmptyView(String msg, int imgId) { 278 | if (emptyView.getParent() == null) { 279 | addView(emptyView); 280 | } 281 | setTipText(EMPTY, msg); 282 | setTipImg(EMPTY, imgId); 283 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, emptyView); 284 | currentShowingView = emptyView; 285 | } 286 | 287 | /** 288 | * 展示超时的界面 289 | */ 290 | public void showTimeoutView() { 291 | if (timeOutView.getParent() == null) { 292 | addView(timeOutView); 293 | } 294 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, timeOutView); 295 | currentShowingView = timeOutView; 296 | } 297 | 298 | /** 299 | * 展示超时的界面 300 | * 301 | * @param msgId 提示语 302 | */ 303 | public void showTimeoutView(int msgId) { 304 | if (timeOutView.getParent() == null) { 305 | addView(timeOutView); 306 | } 307 | setTipText(TIMEOUT, msgId); 308 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, timeOutView); 309 | currentShowingView = timeOutView; 310 | } 311 | 312 | /** 313 | * 展示超时的界面 314 | * 315 | * @param msg 提示语 316 | */ 317 | public void showTimeoutView(String msg) { 318 | if (timeOutView.getParent() == null) { 319 | addView(timeOutView); 320 | } 321 | setTipText(TIMEOUT, msg); 322 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, timeOutView); 323 | currentShowingView = timeOutView; 324 | } 325 | 326 | /** 327 | * 展示超时的界面 328 | * 329 | * @param msgId 提示语 330 | * @param imgId 图片Id 331 | */ 332 | public void showTimeoutView(int msgId, int imgId) { 333 | if (timeOutView.getParent() == null) { 334 | addView(timeOutView); 335 | } 336 | setTipText(TIMEOUT, msgId); 337 | setTipImg(TIMEOUT, imgId); 338 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, timeOutView); 339 | currentShowingView = timeOutView; 340 | } 341 | 342 | /** 343 | * 展示超时的界面 344 | * 345 | * @param msg 提示语 346 | * @param imgId 图片Id 347 | */ 348 | public void showTimeoutView(String msg, int imgId) { 349 | if (timeOutView.getParent() == null) { 350 | addView(timeOutView); 351 | } 352 | setTipText(TIMEOUT, msg); 353 | setTipImg(TIMEOUT, imgId); 354 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, timeOutView); 355 | currentShowingView = timeOutView; 356 | } 357 | 358 | /** 359 | * 展示没有网络的界面 360 | */ 361 | public void showNoNetworkView() { 362 | if (notNetworkView.getParent() == null) { 363 | addView(notNetworkView); 364 | } 365 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, notNetworkView); 366 | currentShowingView = notNetworkView; 367 | } 368 | 369 | /** 370 | * 展示没有网络的界面 371 | * 372 | * @param msgId 提示语 373 | */ 374 | public void showNoNetworkView(int msgId) { 375 | if (notNetworkView.getParent() == null) { 376 | addView(notNetworkView); 377 | } 378 | setTipText(NOT_NETWORK, msgId); 379 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, notNetworkView); 380 | currentShowingView = notNetworkView; 381 | } 382 | 383 | /** 384 | * 展示没有网络的界面 385 | * 386 | * @param msg 提示语 387 | */ 388 | public void showNoNetworkView(String msg) { 389 | if (notNetworkView.getParent() == null) { 390 | addView(notNetworkView); 391 | } 392 | setTipText(NOT_NETWORK, msg); 393 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, notNetworkView); 394 | currentShowingView = notNetworkView; 395 | } 396 | 397 | /** 398 | * 展示没有网络的界面 399 | * 400 | * @param msgId 提示语 401 | * @param imgId 图片Id 402 | */ 403 | public void showNoNetworkView(int msgId, int imgId) { 404 | if (notNetworkView.getParent() == null) { 405 | addView(notNetworkView); 406 | } 407 | setTipText(NOT_NETWORK, msgId); 408 | setTipImg(NOT_NETWORK, imgId); 409 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, notNetworkView); 410 | currentShowingView = notNetworkView; 411 | } 412 | 413 | /** 414 | * 展示登录的界面 415 | */ 416 | public void showLoginView() { 417 | if (loginView.getParent() == null) { 418 | addView(loginView); 419 | } 420 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, loginView); 421 | currentShowingView = loginView; 422 | } 423 | 424 | /** 425 | * 展示登录的界面 426 | * 427 | * @param msgId 提示语 428 | */ 429 | public void showLoginView(int msgId) { 430 | if (loginView.getParent() == null) { 431 | addView(loginView); 432 | } 433 | setTipText(LOGIN, msgId); 434 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, loginView); 435 | currentShowingView = loginView; 436 | } 437 | 438 | /** 439 | * 展示登录的界面 440 | * 441 | * @param msg 提示语 442 | */ 443 | public void showLoginView(String msg) { 444 | if (loginView.getParent() == null) { 445 | addView(loginView); 446 | } 447 | setTipText(LOGIN, msg); 448 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, loginView); 449 | currentShowingView = loginView; 450 | } 451 | 452 | /** 453 | * 展示登录的界面 454 | * 455 | * @param msgId 提示语 456 | * @param imgId 图片Id 457 | */ 458 | public void showLoginView(int msgId, int imgId) { 459 | if (loginView.getParent() == null) { 460 | addView(loginView); 461 | } 462 | setTipText(LOGIN, msgId); 463 | setTipImg(LOGIN, imgId); 464 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, loginView); 465 | currentShowingView = loginView; 466 | } 467 | 468 | /** 469 | * 展示登录的界面 470 | * 471 | * @param msg 提示语 472 | * @param imgId 图片Id 473 | */ 474 | public void showLoginView(String msg, int imgId) { 475 | if (loginView.getParent() == null) { 476 | addView(loginView); 477 | } 478 | setTipText(LOGIN, msg); 479 | setTipImg(LOGIN, imgId); 480 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, loginView); 481 | currentShowingView = loginView; 482 | } 483 | 484 | 485 | /** 486 | * 展示加载中的界面 487 | */ 488 | public void showLoadingView() { 489 | if (loadingView.getParent() == null) { 490 | addView(loadingView); 491 | } 492 | setLoadingView(null, true); 493 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, loadingView); 494 | currentShowingView = loadingView; 495 | } 496 | 497 | /** 498 | * 展示加载中的界面 499 | * 500 | * @param view 进度条部分 501 | */ 502 | public void showLoadingView(View view) { 503 | if (loadingView.getParent() == null) { 504 | addView(loadingView); 505 | } 506 | setLoadingView(view, true); 507 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, loadingView); 508 | currentShowingView = loadingView; 509 | } 510 | 511 | /** 512 | * 展示加载中的界面 513 | * 514 | * @param view 进度条部分 515 | * @param showTip 是否显示提示 516 | */ 517 | public void showLoadingView(View view, boolean showTip) { 518 | if (loadingView.getParent() == null) { 519 | addView(loadingView); 520 | } 521 | setLoadingView(view, showTip); 522 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, loadingView); 523 | currentShowingView = loadingView; 524 | } 525 | 526 | 527 | /** 528 | * 展示加载中的界面 529 | * 530 | * @param msgId 提示语 531 | */ 532 | public void showLoadingView(int msgId) { 533 | if (loadingView.getParent() == null) { 534 | addView(loadingView); 535 | } 536 | setTipText(LOADING, msgId); 537 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, loadingView); 538 | currentShowingView = loadingView; 539 | } 540 | 541 | /** 542 | * 展示加载中的界面 543 | * 544 | * @param msg 提示语 545 | */ 546 | public void showLoadingView(String msg) { 547 | if (loadingView.getParent() == null) { 548 | addView(loadingView); 549 | } 550 | setTipText(LOADING, msg); 551 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, loadingView); 552 | currentShowingView = loadingView; 553 | } 554 | 555 | /** 556 | * 展示内容的界面 557 | */ 558 | public void showContentView() { 559 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, contentView); 560 | currentShowingView = contentView; 561 | } 562 | 563 | /** 564 | * 添加用户自定义的View 565 | * 566 | * @param view 自定义View 567 | */ 568 | public void showCustomView(View view) { 569 | if (view.getParent() == null) { //当前的view没有父类 570 | addView(view); 571 | } else { 572 | view.setLayoutParams(this.getLayoutParams()); 573 | } 574 | AnimationHelper.switchViewByAnim(useAnimation, viewAnimProvider, currentShowingView, view); 575 | currentShowingView = view; 576 | } 577 | 578 | //************ update ************// 579 | 580 | /** 581 | * 修改提示文字 582 | * 583 | * @param type 传入修改哪个 584 | * @param text 文字 585 | */ 586 | public void setTipText(int type, String text) { 587 | if (text == null) { //text is null 588 | return; 589 | } 590 | switch (type) { 591 | case ERROR: 592 | ((ErrorViewHolder) errorView.getTag()).tvTip.setText(text); 593 | break; 594 | case EMPTY: 595 | ((EmptyViewHolder) emptyView.getTag()).tvTip.setText(text); 596 | break; 597 | case TIMEOUT: 598 | ((TimeOutViewHolder) timeOutView.getTag()).tvTip.setText(text); 599 | break; 600 | case NOT_NETWORK: 601 | ((NoNetworkViewHolder) notNetworkView.getTag()).tvTip.setText(text); 602 | break; 603 | case LOADING: 604 | ((LoadingViewHolder) loadingView.getTag()).tvTip.setText(text); 605 | break; 606 | case LOGIN: 607 | ((LoginViewHolder) loginView.getTag()).tvTip.setText(text); 608 | break; 609 | } 610 | } 611 | 612 | /** 613 | * 修改提示文字 614 | * 615 | * @param type 传入修改哪个 616 | * @param textId 文字资源id 617 | */ 618 | public void setTipText(int type, int textId) { 619 | switch (type) { 620 | case ERROR: 621 | ((ErrorViewHolder) errorView.getTag()).tvTip.setText(textId); 622 | break; 623 | case EMPTY: 624 | ((EmptyViewHolder) emptyView.getTag()).tvTip.setText(textId); 625 | break; 626 | case TIMEOUT: 627 | ((TimeOutViewHolder) timeOutView.getTag()).tvTip.setText(textId); 628 | break; 629 | case NOT_NETWORK: 630 | ((NoNetworkViewHolder) notNetworkView.getTag()).tvTip.setText(textId); 631 | break; 632 | case LOADING: 633 | ((LoadingViewHolder) loadingView.getTag()).tvTip.setText(textId); 634 | break; 635 | case LOGIN: 636 | ((LoginViewHolder) loginView.getTag()).tvTip.setText(textId); 637 | break; 638 | } 639 | } 640 | 641 | /** 642 | * 设置提示图片资源 643 | * 644 | * @param type 传入修改哪个,除了Loading 645 | * @param drawable 图片资源drawable 646 | */ 647 | public void setTipImg(int type, Drawable drawable) { 648 | switch (type) { 649 | case ERROR: 650 | ((ErrorViewHolder) errorView.getTag()).ivImg.setBackgroundDrawable(drawable); 651 | break; 652 | case EMPTY: 653 | ((EmptyViewHolder) emptyView.getTag()).ivImg.setBackgroundDrawable(drawable); 654 | break; 655 | case TIMEOUT: 656 | ((TimeOutViewHolder) timeOutView.getTag()).ivImg.setBackgroundDrawable(drawable); 657 | break; 658 | case NOT_NETWORK: 659 | ((NoNetworkViewHolder) notNetworkView.getTag()).ivImg.setBackgroundDrawable(drawable); 660 | break; 661 | case LOGIN: 662 | ((LoginViewHolder) loginView.getTag()).ivImg.setBackgroundDrawable(drawable); 663 | break; 664 | } 665 | } 666 | 667 | /** 668 | * 设置提示图片资源 669 | * 670 | * @param type 传入修改哪个,除了Loading 671 | * @param imgId 图片资源id 672 | */ 673 | public void setTipImg(int type, int imgId) { 674 | switch (type) { 675 | case ERROR: 676 | ((ErrorViewHolder) errorView.getTag()).ivImg.setImageResource(imgId); 677 | break; 678 | case EMPTY: 679 | ((EmptyViewHolder) emptyView.getTag()).ivImg.setImageResource(imgId); 680 | break; 681 | case TIMEOUT: 682 | ((TimeOutViewHolder) timeOutView.getTag()).ivImg.setImageResource(imgId); 683 | break; 684 | case NOT_NETWORK: 685 | ((NoNetworkViewHolder) notNetworkView.getTag()).ivImg.setImageResource(imgId); 686 | break; 687 | case LOGIN: 688 | ((LoginViewHolder) loginView.getTag()).ivImg.setImageResource(imgId); 689 | break; 690 | } 691 | } 692 | 693 | /** 694 | * 设置加载界面的View 695 | * 696 | * @param view 显示的View 697 | */ 698 | public void setLoadingView(View view, boolean showTip) { 699 | LoadingViewHolder holder = (LoadingViewHolder) loadingView.getTag(); 700 | if (view != null) { 701 | holder.frameLayout.removeAllViews(); 702 | holder.frameLayout.addView(view); 703 | } 704 | if (showTip) { 705 | holder.tvTip.setVisibility(VISIBLE); 706 | } else { 707 | holder.tvTip.setVisibility(GONE); 708 | } 709 | } 710 | 711 | //************ animation ************// 712 | 713 | public void setViewSwitchAnimProvider(ViewAnimProvider animProvider) { 714 | if (animProvider != null) { 715 | this.viewAnimProvider = animProvider; 716 | } 717 | } 718 | 719 | public ViewAnimProvider getViewAnimProvider() { 720 | return viewAnimProvider; 721 | } 722 | 723 | public boolean isUseAnimation() { 724 | return useAnimation; 725 | } 726 | 727 | public void setUseAnimation(boolean useAnimation) { 728 | this.useAnimation = useAnimation; 729 | } 730 | 731 | //************ callBack ************// 732 | public interface OnViewRefreshListener { 733 | //刷新界面 734 | void refreshClick(); 735 | 736 | //登录点击 737 | void loginClick(); 738 | } 739 | 740 | //************ addView ************// 741 | @Override 742 | public void addView(View child) { 743 | checkIsContentView(child); 744 | super.addView(child); 745 | } 746 | 747 | @Override 748 | public void addView(View child, int index) { 749 | checkIsContentView(child); 750 | super.addView(child, index); 751 | } 752 | 753 | @Override 754 | public void addView(View child, int index, ViewGroup.LayoutParams params) { 755 | checkIsContentView(child); 756 | super.addView(child, index, params); 757 | } 758 | 759 | @Override 760 | public void addView(View child, ViewGroup.LayoutParams params) { 761 | checkIsContentView(child); 762 | super.addView(child, params); 763 | } 764 | 765 | @Override 766 | public void addView(View child, int width, int height) { 767 | checkIsContentView(child); 768 | super.addView(child, width, height); 769 | } 770 | 771 | @Override 772 | protected boolean addViewInLayout(View child, int index, ViewGroup.LayoutParams params) { 773 | checkIsContentView(child); 774 | return super.addViewInLayout(child, index, params); 775 | } 776 | 777 | @Override 778 | protected boolean addViewInLayout(View child, int index, ViewGroup.LayoutParams params, boolean preventRequestLayout) { 779 | checkIsContentView(child); 780 | return super.addViewInLayout(child, index, params, preventRequestLayout); 781 | } 782 | } 783 | --------------------------------------------------------------------------------