Skip to content

Commit 107a9e5

Browse files
committed
1. add getState method
2. update sample
1 parent 8dcc8b3 commit 107a9e5

12 files changed

Lines changed: 76 additions & 21 deletions

File tree

multistatelayout/src/main/java/cn/refactor/multistatelayout/MultiStateLayout.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,34 @@ public void setCustomState(int customStateKey, boolean displayContentLayout) {
185185
showCustomViewByState(customStateKey);
186186
}
187187

188+
/**
189+
* Put customise state view by customise key
190+
* @param customStateKey key
191+
* @param stateView view
192+
*/
188193
@SuppressWarnings("unused")
189194
public void putCustomStateView(int customStateKey, View stateView) {
190195
mCustomStateViewArray.put(customStateKey, stateView);
191196
addView(stateView, stateView.getLayoutParams());
192197
stateView.setVisibility(GONE);
193198
}
194199

200+
/**
201+
* @return current state value
202+
*/
203+
@SuppressWarnings("unused")
204+
public int getState() {
205+
return mIsSystemState ? mCurState : mCurCustomStateKey;
206+
}
207+
208+
/**
209+
* @return current state is customise state
210+
*/
211+
@SuppressWarnings("unused")
212+
public boolean isCustomiseState() {
213+
return !mIsSystemState;
214+
}
215+
195216
@SuppressWarnings("unused")
196217
public View findCustomStateViewByKey(int customStateKey) {
197218
return mCustomStateViewArray.get(customStateKey);

sample/src/main/java/cn/refactor/multistatelayoutdemo/MainActivity.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
package cn.refactor.multistatelayoutdemo;
22

3-
import android.animation.ObjectAnimator;
43
import android.content.Intent;
54
import android.os.Bundle;
65
import android.support.v7.app.AppCompatActivity;
76
import android.support.v7.widget.Toolbar;
7+
import android.util.Log;
88
import android.view.LayoutInflater;
99
import android.view.Menu;
1010
import android.view.MenuItem;
1111
import android.view.View;
12-
import android.view.animation.AccelerateInterpolator;
1312
import android.widget.Toast;
1413

1514
import cn.refactor.multistatelayout.MultiStateLayout;
16-
import cn.refactor.multistatelayout.TransitionAnimatorLoader;
1715

1816
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
1917

18+
private static final String TAG = MainActivity.class.getSimpleName();
2019
private static final int KEY_CUSTOM_NOTICE = 1024;
2120

2221
private MultiStateLayout mStateLayout;
@@ -55,16 +54,6 @@ public void onClick(View view) {
5554
// setup custom notice message view
5655
View customNoticeMsgView = LayoutInflater.from(this).inflate(R.layout.layout_custom_notice, mStateLayout, false);
5756
mStateLayout.putCustomStateView(KEY_CUSTOM_NOTICE, customNoticeMsgView);
58-
59-
mStateLayout.setTransitionAnimator(new TransitionAnimatorLoader() {
60-
@Override
61-
public ObjectAnimator loadAnimator(View targetView) {
62-
ObjectAnimator customAnimator = ObjectAnimator.ofFloat(targetView, "alpha", 0.0f, 1.0f)
63-
.setDuration(500);
64-
customAnimator.setInterpolator(new AccelerateInterpolator());
65-
return customAnimator;
66-
}
67-
});
6857
}
6958

7059
private void setupToolbar() {
@@ -96,6 +85,7 @@ public boolean onMenuItemClick(MenuItem item) {
9685
default:
9786
break;
9887
}
88+
Log.d(TAG, String.valueOf(mStateLayout.getState()));
9989
return true;
10090
}
10191
});
122 KB
Loading
133 KB
Loading
142 KB
Loading
128 KB
Loading

sample/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
android:layout_height="match_parent"
2323
state:layout_network_error="@layout/layout_custom_network_error"
2424
state:animEnable="true"
25-
state:animDuration="250">
25+
state:animDuration="300">
2626

2727
<TextView
2828
android:id="@+id/tv_content"
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<TextView
2+
<LinearLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
android:layout_width="wrap_content"
55
android:layout_height="wrap_content"
66
android:layout_gravity="center"
7-
android:text="@string/empty"/>
7+
android:orientation="vertical">
88

9+
<ImageView
10+
android:layout_width="wrap_content"
11+
android:layout_height="wrap_content"
12+
android:src="@drawable/ic_no_data"/>
13+
14+
<TextView
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:gravity="center_horizontal"
18+
android:layout_gravity="center_horizontal"
19+
android:text="@string/empty"/>
20+
</LinearLayout>
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<TextView
2+
<LinearLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
android:layout_width="wrap_content"
55
android:layout_height="wrap_content"
66
android:layout_gravity="center"
7-
android:text="@string/error"/>
7+
android:orientation="vertical">
8+
9+
<ImageView
10+
android:layout_width="wrap_content"
11+
android:layout_height="wrap_content"
12+
android:src="@drawable/ic_no_server"/>
13+
14+
<TextView
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:layout_gravity="center"
18+
android:text="@string/error"/>
19+
</LinearLayout>
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<TextView
2+
<LinearLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
android:layout_width="wrap_content"
55
android:layout_height="wrap_content"
66
android:layout_gravity="center"
7-
android:text="@string/network_error"/>
7+
android:orientation="vertical">
8+
9+
<ImageView
10+
android:layout_width="wrap_content"
11+
android:layout_height="wrap_content"
12+
android:src="@drawable/ic_no_network"/>
13+
14+
<TextView
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:layout_gravity="center_horizontal"
18+
android:text="@string/network_error"/>
19+
</LinearLayout>

0 commit comments

Comments
 (0)