diff --git a/README.md b/README.md
index 828370d..adbf673 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,39 @@
-# ProgressLayout
-A simple progress layout
+#ProgressLayout
-![](https://github.com/SmartDengg/ProgressLayout/blob/master/ScreenShot/progressLayout.gif)
+![](https://github.com/SmartDengg/ProgressLayout/blob/master/screenShot/launcher.png)
+
+
+
+
+##Sketch
+-----------------
+
+
+
+##Usage
+-----------------
+
+
+
+##ScreenShot
+-----------------
+
+![](https://github.com/SmartDengg/ProgressLayout/blob/master/screenShot/progressLayout.gif)
+
+
+##Developed By
+-----------------
+
+- 小鄧子 - Hi4Joker@gmail.com
+
+[小鄧子的简书](http://www.jianshu.com/users/df40282480b4/latest_articles)
+
+[小鄧子的慕课网专题](http://www.imooc.com/myclub/article/uid/2536335)
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/progressLayout/src/main/java/com/lianjiatech/infrastructure/ProgressLayout.java b/progressLayout/src/main/java/com/lianjiatech/infrastructure/ProgressLayout.java
index 2f3a2f7..d357186 100644
--- a/progressLayout/src/main/java/com/lianjiatech/infrastructure/ProgressLayout.java
+++ b/progressLayout/src/main/java/com/lianjiatech/infrastructure/ProgressLayout.java
@@ -17,6 +17,7 @@
public class ProgressLayout extends RelativeLayout {
private static final int defStyleAttr = R.attr.progressLayoutDefStyle;
+ private static final int NOT_SET = -1;
private static final String LOADING_TAG = "ProgressLayout.loading_tag";
private static final String NONE_TAG = "ProgressLayout.none_tag";
@@ -48,7 +49,8 @@ public class ProgressLayout extends RelativeLayout {
@IntDef(value = { LOADING, NONE, CONTENT, NETWORK_ERROR, FAILED })
public @interface LAYOUT_TYPE {}
- @LAYOUT_TYPE private int currentState = LOADING;
+ @LAYOUT_TYPE
+ private int currentState = LOADING;
public ProgressLayout(Context context) {
this(context, null);
@@ -67,16 +69,25 @@ public ProgressLayout(Context context, AttributeSet attrs, int defStyleAttr) {
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
- this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ProgressLayout, defStyleAttr, R.style.DefaultSmartStyle);
+ this.layoutInflater =
+ (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ TypedArray typedArray =
+ context.obtainStyledAttributes(attrs, R.styleable.ProgressLayout, defStyleAttr,
+ R.style.DefaultSmartStyle);
- if (typedArray == null) return;
+ if (typedArray == null) {
+ return;
+ }
try {
- this.loadingId = typedArray.getResourceId(R.styleable.ProgressLayout_loading_layout, -1);
- this.noneId = typedArray.getResourceId(R.styleable.ProgressLayout_none_content, -1);
- this.networkErrorId = typedArray.getResourceId(R.styleable.ProgressLayout_network_content, -1);
- this.failedId = typedArray.getResourceId(R.styleable.ProgressLayout_failed_content, -1);
+ this.loadingId =
+ typedArray.getResourceId(R.styleable.ProgressLayout_loading_layout, NOT_SET);
+ this.noneId =
+ typedArray.getResourceId(R.styleable.ProgressLayout_none_content, NOT_SET);
+ this.networkErrorId =
+ typedArray.getResourceId(R.styleable.ProgressLayout_network_content, NOT_SET);
+ this.failedId =
+ typedArray.getResourceId(R.styleable.ProgressLayout_failed_content, NOT_SET);
} finally {
typedArray.recycle();
}
@@ -87,7 +98,8 @@ public void addView(View child, int index, ViewGroup.LayoutParams params) {
super.addView(child, index, params);
if (child.getTag() == null ||
- (!child.getTag().equals(LOADING_TAG) && !child.getTag().equals(NONE_TAG) && !child.getTag().equals(ERROR_TAG))) {
+ (!child.getTag().equals(LOADING_TAG) && !child.getTag().equals(NONE_TAG) &&
+ !child.getTag().equals(ERROR_TAG))) {
this.contentViews.add(child);
this.setContentVisibility(false);
@@ -98,7 +110,7 @@ public void showLoading() {
ProgressLayout.this.showLoadingView();
- ProgressLayout.this.hideNoContentView();
+ ProgressLayout.this.hideNoneView();
ProgressLayout.this.hideNetErrorView();
ProgressLayout.this.hideFailedView();
ProgressLayout.this.setContentVisibility(false);
@@ -127,7 +139,7 @@ public void showNetError(@Nullable OnClickListener retryListener) {
ProgressLayout.this.showNetErrorView(retryListener);
ProgressLayout.this.hideLoadingView();
- ProgressLayout.this.hideNoContentView();
+ ProgressLayout.this.hideNoneView();
ProgressLayout.this.hideFailedView();
ProgressLayout.this.setContentVisibility(false);
}
@@ -141,7 +153,7 @@ public void showFailed(@Nullable OnClickListener retryListener) {
ProgressLayout.this.showFailedView(retryListener);
ProgressLayout.this.hideLoadingView();
- ProgressLayout.this.hideNoContentView();
+ ProgressLayout.this.hideNoneView();
ProgressLayout.this.hideNetErrorView();
ProgressLayout.this.setContentVisibility(false);
}
@@ -149,7 +161,7 @@ public void showFailed(@Nullable OnClickListener retryListener) {
public void showContent() {
ProgressLayout.this.hideLoadingView();
- ProgressLayout.this.hideNoContentView();
+ ProgressLayout.this.hideNoneView();
ProgressLayout.this.hideNetErrorView();
ProgressLayout.this.hideFailedView();
@@ -166,7 +178,13 @@ private void showLoadingView() {
if (this.loadingContainer == null) {
- this.loadingContainer = this.layoutInflater.inflate(loadingId, ProgressLayout.this, false);
+ if (loadingId == NOT_SET) {
+ throw new IllegalStateException(
+ "cannot call showLoadingView() when loadingId was equals -1");
+ }
+
+ this.loadingContainer =
+ this.layoutInflater.inflate(loadingId, ProgressLayout.this, false);
this.loadingContainer.setTag(LOADING_TAG);
LayoutParams layoutParams = (LayoutParams) loadingContainer.getLayoutParams();
@@ -188,6 +206,11 @@ private void showNoneView(OnClickListener retryListener) {
if (this.noneContainer == null) {
+ if (noneId == NOT_SET) {
+ throw new IllegalStateException(
+ "cannot call showNoneView() when noneId was equals -1");
+ }
+
this.noneContainer = this.layoutInflater.inflate(noneId, ProgressLayout.this, false);
this.noneContainer.setTag(NONE_TAG);
@@ -215,7 +238,13 @@ private void showNetErrorView(OnClickListener retryListener) {
if (this.networkErrorContainer == null) {
- this.networkErrorContainer = this.layoutInflater.inflate(networkErrorId, ProgressLayout.this, false);
+ if (networkErrorId == NOT_SET) {
+ throw new IllegalStateException(
+ "cannot call showNetErrorView() when networkErrorId was equals -1");
+ }
+
+ this.networkErrorContainer =
+ this.layoutInflater.inflate(networkErrorId, ProgressLayout.this, false);
this.networkErrorContainer.setTag(ERROR_TAG);
LayoutParams layoutParams = (LayoutParams) networkErrorContainer.getLayoutParams();
@@ -242,7 +271,13 @@ private void showFailedView(OnClickListener retryListener) {
if (this.failedContainer == null) {
- this.failedContainer = this.layoutInflater.inflate(failedId, ProgressLayout.this, false);
+ if (failedId == NOT_SET) {
+ throw new IllegalStateException(
+ "cannot call showFailedView() when failedId was equals -1");
+ }
+
+ this.failedContainer =
+ this.layoutInflater.inflate(failedId, ProgressLayout.this, false);
this.failedContainer.setTag(ERROR_TAG);
LayoutParams layoutParams = (LayoutParams) failedContainer.getLayoutParams();
@@ -267,7 +302,7 @@ private void hideLoadingView() {
}
/** 隐藏无内容界面 */
- private void hideNoContentView() {
+ private void hideNoneView() {
if (noneContainer != null && noneContainer.getVisibility() != GONE) {
this.noneContainer.setVisibility(GONE);
}
@@ -280,7 +315,7 @@ private void hideNetErrorView() {
}
}
- /** 隐藏网络错误界面 */
+ /** 隐藏数据错误界面 */
private void hideFailedView() {
if (failedContainer != null && failedContainer.getVisibility() != GONE) {
this.failedContainer.setVisibility(GONE);
@@ -291,22 +326,22 @@ public boolean isLoading() {
return this.currentState == LOADING;
}
- public boolean isnOContent() {
- return this.currentState == NONE;
- }
-
public boolean isContent() {
return this.currentState == CONTENT;
}
- public boolean isFailed() {
- return this.currentState == FAILED;
+ public boolean isNone() {
+ return this.currentState == NONE;
}
public boolean isNetworkError() {
return this.currentState == NETWORK_ERROR;
}
+ public boolean isFailed() {
+ return this.currentState == FAILED;
+ }
+
private void setContentVisibility(boolean visible) {
for (View contentView : contentViews) {
contentView.setVisibility(visible ? View.VISIBLE : View.GONE);
diff --git a/sample/src/main/java/com/lianjiatech/infrastructure/example/MainActivity.java b/sample/src/main/java/com/lianjiatech/infrastructure/example/MainActivity.java
index dcd3a94..cc588f1 100644
--- a/sample/src/main/java/com/lianjiatech/infrastructure/example/MainActivity.java
+++ b/sample/src/main/java/com/lianjiatech/infrastructure/example/MainActivity.java
@@ -25,7 +25,7 @@ public void onClick(View v) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
+ setContentView(R.layout.main_layout);
ButterKnife.bind(MainActivity.this);
this.progressLayout.showLoading();
diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/main_layout.xml
similarity index 98%
rename from sample/src/main/res/layout/activity_main.xml
rename to sample/src/main/res/layout/main_layout.xml
index 1a87c7f..34b4256 100644
--- a/sample/src/main/res/layout/activity_main.xml
+++ b/sample/src/main/res/layout/main_layout.xml
@@ -88,7 +88,7 @@
android:textSize="@dimen/material_23sp"
android:shadowDy="10"
android:shadowRadius="4"
- android:textColor="@android:color/holo_green_dark"
+ android:textColor="@color/homeLinkGreen"
android:shadowColor="@android:color/holo_orange_light"
android:text="@string/homelink"
/>
diff --git a/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
index 539752c..5696c49 100644
Binary files a/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/sample/src/main/res/values/colors.xml b/sample/src/main/res/values/colors.xml
index 5a077b3..ccee739 100644
--- a/sample/src/main/res/values/colors.xml
+++ b/sample/src/main/res/values/colors.xml
@@ -3,4 +3,6 @@
#3F51B5
#303F9F
#FF4081
+
+ #00ae66
diff --git a/screenShot/launcher.png b/screenShot/launcher.png
new file mode 100644
index 0000000..1aca55e
Binary files /dev/null and b/screenShot/launcher.png differ