├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── libraries │ ├── appcompat_v7_23_1_1.xml │ ├── design_23_1_1.xml │ ├── hamcrest_core_1_3.xml │ ├── junit_4_12.xml │ ├── recyclerview_v7_23_1_1.xml │ ├── support_annotations_23_1_1.xml │ └── support_v4_23_1_1.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml ├── vcs.xml └── workspace.xml ├── LICENSE ├── LoadingView.iml ├── PageStateLayout.iml ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── z │ │ └── sye │ │ └── space │ │ └── loadingview │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── z │ │ │ └── sye │ │ │ └── space │ │ │ └── loadingview │ │ │ ├── AppApplication.java │ │ │ └── MainActivity.java │ └── res │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── content_main.xml │ │ ├── custom_layout_empty.xml │ │ ├── custom_layout_error.xml │ │ ├── custom_layout_loading.xml │ │ └── layout_succeed.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── no_datas.png │ │ └── no_network.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── z │ └── sye │ └── space │ └── loadingview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── library.iml ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── z │ │ └── sye │ │ └── space │ │ └── loadingviewlibrary │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── z │ │ │ └── sye │ │ │ └── space │ │ │ └── library │ │ │ ├── PageStateLayout.java │ │ │ ├── PageStateListener.java │ │ │ ├── utils │ │ │ ├── DimenUtils.java │ │ │ └── PageState.java │ │ │ └── widget │ │ │ ├── MaterialProgress.java │ │ │ └── RippleView.java │ └── res │ │ ├── layout │ │ ├── empty.xml │ │ ├── error.xml │ │ └── loading.xml │ │ ├── mipmap-hdpi │ │ ├── no_datas.png │ │ └── no_network.png │ │ ├── values-en │ │ └── strings.xml │ │ ├── values-zh │ │ └── strings.xml │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── z │ └── sye │ └── space │ └── loadingviewlibrary │ └── ExampleUnitTest.java └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 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 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | MaterialPageStateLayout -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/libraries/appcompat_v7_23_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/libraries/design_23_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/junit_4_12.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/recyclerview_v7_23_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/support_annotations_23_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/support_v4_23_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2015 Gordon Wong 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /LoadingView.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /PageStateLayout.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PageStateLayout 2 | PageStateLayout could let you show [Loading][Empty][Error][Succeed][Requesting] state in Activity, Fragment, ViewGroup as you want. 3 | 4 | Improt library: 5 | 6 | allprojects { 7 | repositories { 8 | ... 9 | maven { url "https://jitpack.io" } 10 | } 11 | } 12 | 13 | dependencies { 14 | compile 'com.github.Syehunter:PageStateLayout:0.1.2.2' 15 | } 16 | 17 | 18 | ![](http://7xn4z4.com1.z0.glb.clouddn.com/PageStateLayout.gif) 19 | 20 | U can use the layout wherever u want! 21 | 22 | Following Methods are supported: 23 | 24 | //replace activity.setContentView() 25 | pageStateLayout.load(activity, succeedView); 26 | 27 | //parent instanceof ViewGroup 28 | pageStateLayout.load(parent, suuccedView); 29 | 30 | //use this if u don't want any containers 31 | //such as in fragment.onCreateView, just return pageStateLayout 32 | pageStateLayout.load(succeedView); 33 | 34 | It has 5 states: 35 | 36 | onLoading(); 37 | 38 | onEmpty(); 39 | 40 | onError(); 41 | 42 | onSucceed(); 43 | 44 | //In some activities u may want to show both the progressbar and succeedView, such as LoginActivity, then switch on this state 45 | onRequesting(); 46 | 47 | If u wan't to replace these pages with some others designed by yourself(you'd better do it in you application or BaseActivity) 48 | 49 | PageStateLayout.Builder.setLoadingView(resId); 50 | 51 | PageStateLayout.Builder.setEmptyView(resId); 52 | 53 | PageSateLayout.Builder.setErrorView(resId); 54 | 55 | U can use other methods in PageStateLayout.Builder to change the progressColor, the errorImage, the emptyPromt and so on; 56 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "z.sye.space.loadingview" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.1.1' 26 | compile 'com.android.support:design:23.1.1' 27 | compile project(':library') 28 | } 29 | -------------------------------------------------------------------------------- /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/Syehunter/Documents/android-sdk-macosx/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/androidTest/java/z/sye/space/loadingview/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package z.sye.space.loadingview; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/z/sye/space/loadingview/AppApplication.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @(#) z.sye.space.loadingview 2016/1/11; 3 | *

4 | * Copyright (c), 2009 深圳孔方兄金融信息服务有限公司(Shenzhen kfxiong 5 | * Financial Information Service Co. Ltd.) 6 | *

7 | * 著作权人保留一切权利,任何使用需经授权。 8 | */ 9 | package z.sye.space.loadingview; 10 | 11 | import android.app.Application; 12 | 13 | import z.sye.space.library.PageStateLayout; 14 | 15 | /** 16 | * Created by Syehunter on 2016/1/11. 17 | */ 18 | public class AppApplication extends Application { 19 | 20 | @Override 21 | public void onCreate() { 22 | super.onCreate(); 23 | 24 | // PageStateLayout.Builder.setLoadingView(R.layout.custom_layout_loading) 25 | // .setEmptyView(R.layout.custom_layout_empty) 26 | // .setErrorView(R.layout.custom_layout_error); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/z/sye/space/loadingview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package z.sye.space.loadingview; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.os.Message; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.support.v7.widget.Toolbar; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.Menu; 11 | import android.view.MenuItem; 12 | import android.widget.Button; 13 | import android.widget.FrameLayout; 14 | import android.widget.Toast; 15 | 16 | import z.sye.space.library.PageStateLayout; 17 | import z.sye.space.library.utils.PageState; 18 | 19 | 20 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 21 | 22 | private static final int LOADING = 0; 23 | private static final int EMPTY = 1; 24 | private static final int ERROR = 2; 25 | private static final int SUCCEED = 3; 26 | private static final int REQUESTING = 4; 27 | private long msgDelayed = 4000; 28 | 29 | private PageStateLayout mLayout; 30 | 31 | private PageState currentState = PageState.SUCCEED; 32 | 33 | private Handler mHandler = new Handler() { 34 | @Override 35 | public void handleMessage(Message msg) { 36 | switch (msg.what) { 37 | case LOADING: 38 | mLayout.onLoading(); 39 | break; 40 | case EMPTY: 41 | mLayout.onEmpty(); 42 | currentState = PageState.EMPTY; 43 | break; 44 | case ERROR: 45 | mLayout.onError(); 46 | currentState = PageState.ERROR; 47 | break; 48 | case SUCCEED: 49 | mLayout.onSucceed(); 50 | currentState = PageState.SUCCEED; 51 | break; 52 | case REQUESTING: 53 | mLayout.onRequesting(); 54 | currentState = PageState.REQEUSTING; 55 | break; 56 | } 57 | super.handleMessage(msg); 58 | } 59 | }; 60 | 61 | @Override 62 | protected void onCreate(Bundle savedInstanceState) { 63 | super.onCreate(savedInstanceState); 64 | setContentView(R.layout.activity_main); 65 | 66 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 67 | setSupportActionBar(toolbar); 68 | 69 | FrameLayout mParent = (FrameLayout) findViewById(R.id.fl_parent); 70 | 71 | View succeedView = LayoutInflater.from(this).inflate(R.layout.layout_succeed, null, false); 72 | mLayout = new PageStateLayout(this); 73 | mLayout.setOnEmptyListener(mOnEmptyListener) 74 | .setOnErrorListener(mOnErrorListener) 75 | .load(mParent, succeedView); 76 | 77 | mLayout.onLoading(); 78 | Message msg = new Message(); 79 | msg.what = SUCCEED; 80 | mHandler.sendMessageDelayed(msg, msgDelayed); 81 | 82 | Button emptyBtn = (Button) succeedView.findViewById(R.id.btn_empty); 83 | Button errorBtn = (Button) succeedView.findViewById(R.id.btn_error); 84 | Button requestBtn = (Button) succeedView.findViewById(R.id.btn_requesting); 85 | emptyBtn.setOnClickListener(this); 86 | errorBtn.setOnClickListener(this); 87 | requestBtn.setOnClickListener(this); 88 | 89 | } 90 | 91 | private View.OnClickListener mOnEmptyListener = new View.OnClickListener() { 92 | @Override 93 | public void onClick(View v) { 94 | Toast.makeText(MainActivity.this, "Do something when empty", Toast.LENGTH_SHORT).show(); 95 | } 96 | }; 97 | 98 | private View.OnClickListener mOnErrorListener = new View.OnClickListener() { 99 | @Override 100 | public void onClick(View v) { 101 | Toast.makeText(MainActivity.this, "Do something when error", Toast.LENGTH_SHORT).show(); 102 | } 103 | }; 104 | 105 | 106 | @Override 107 | public boolean onCreateOptionsMenu(Menu menu) { 108 | // Inflate the menu; this adds items to the action bar if it is present. 109 | getMenuInflater().inflate(R.menu.menu_main, menu); 110 | return true; 111 | } 112 | 113 | @Override 114 | public boolean onOptionsItemSelected(MenuItem item) { 115 | // Handle action bar item clicks here. The action bar will 116 | // automatically handle clicks on the Home/Up button, so long 117 | // as you specify a parent activity in AndroidManifest.xml. 118 | int id = item.getItemId(); 119 | 120 | //noinspection SimplifiableIfStatement 121 | if (id == R.id.action_settings) { 122 | return true; 123 | } 124 | 125 | return super.onOptionsItemSelected(item); 126 | } 127 | 128 | @Override 129 | public void onClick(View v) { 130 | Message msg = new Message(); 131 | switch (v.getId()) { 132 | case R.id.btn_empty: 133 | mLayout.onLoading();//simulate network loading 134 | msg.what = EMPTY; 135 | mHandler.sendMessageDelayed(msg, msgDelayed); 136 | break; 137 | case R.id.btn_error: 138 | mLayout.onLoading();//simulate network loading 139 | msg.what = ERROR; 140 | currentState = PageState.ERROR; 141 | mHandler.sendMessageDelayed(msg, msgDelayed); 142 | break; 143 | case R.id.btn_requesting: 144 | mLayout.onRequesting(); 145 | msg.what = SUCCEED;//show Succeed View when Requesting end 146 | currentState = PageState.REQEUSTING; 147 | mHandler.sendMessageDelayed(msg, msgDelayed); 148 | break; 149 | } 150 | } 151 | 152 | @Override 153 | public void onBackPressed() { 154 | if (currentState != PageState.SUCCEED) { 155 | mLayout.onSucceed(); 156 | currentState = PageState.SUCCEED; 157 | } else { 158 | super.onBackPressed(); 159 | } 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/custom_layout_empty.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/custom_layout_error.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/custom_layout_loading.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_succeed.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 |