2424import android .support .annotation .DrawableRes ;
2525import android .support .annotation .LayoutRes ;
2626import android .util .AttributeSet ;
27- import android .util .Log ;
2827import android .util .TypedValue ;
2928import android .view .LayoutInflater ;
3029import android .view .View ;
4039
4140
4241public class LoadingLayout extends FrameLayout {
42+ public interface OnInflateListener {
43+ void onInflate (View inflated );
44+ }
4345
4446 public static LoadingLayout wrap (Activity activity ) {
4547 return wrap (((ViewGroup )activity .findViewById (android .R .id .content )).getChildAt (0 ));
@@ -81,6 +83,9 @@ public void onClick(View v) {
8183 };
8284 View .OnClickListener mRetryListener ;
8385
86+ OnInflateListener mOnEmptyInflateListener ;
87+ OnInflateListener mOnErrorInflateListener ;
88+
8489 int mTextColor , mTextSize ;
8590 int mButtonTextColor , mButtonTextSize ;
8691 Drawable mButtonBackground ;
@@ -131,7 +136,6 @@ int dp2px(float dp) {
131136 LayoutInflater mInflater ;
132137 @ Override
133138 protected void onFinishInflate () {
134- Log .e ("ezy" , "onFinishInflate" );
135139 super .onFinishInflate ();
136140 if (getChildCount () == 0 ) {
137141 return ;
@@ -163,10 +167,17 @@ public LoadingLayout setEmpty(@LayoutRes int id) {
163167 }
164168 return this ;
165169 }
166- public LoadingLayout setError (@ LayoutRes int id ) {
167- if (mErrorResId != id ) {
168- remove (mErrorResId );
169- mErrorResId = id ;
170+ public LoadingLayout setOnEmptyInflateListener (OnInflateListener listener ) {
171+ mOnEmptyInflateListener = listener ;
172+ if (mOnEmptyInflateListener != null && mLayouts .containsKey (mEmptyResId )) {
173+ listener .onInflate (mLayouts .get (mEmptyResId ));
174+ }
175+ return this ;
176+ }
177+ public LoadingLayout setOnErrorInflateListener (OnInflateListener listener ) {
178+ mOnErrorInflateListener = listener ;
179+ if (mOnErrorInflateListener != null && mLayouts .containsKey (mErrorResId )) {
180+ listener .onInflate (mLayouts .get (mErrorResId ));
170181 }
171182 return this ;
172183 }
@@ -203,6 +214,28 @@ public LoadingLayout setRetryListener(OnClickListener listener) {
203214 return this ;
204215 }
205216
217+
218+ // public LoadingLayout setTextColor(@ColorInt int color) {
219+ // mTextColor = color;
220+ // return this;
221+ // }
222+ // public LoadingLayout setTextSize(@ColorInt int dp) {
223+ // mTextColor = dp2px(dp);
224+ // return this;
225+ // }
226+ // public LoadingLayout setButtonTextColor(@ColorInt int color) {
227+ // mButtonTextColor = color;
228+ // return this;
229+ // }
230+ // public LoadingLayout setButtonTextSize(@ColorInt int dp) {
231+ // mButtonTextColor = dp2px(dp);
232+ // return this;
233+ // }
234+ // public LoadingLayout setButtonBackground(Drawable drawable) {
235+ // mButtonBackground = drawable;
236+ // return this;
237+ // }
238+
206239 public void showLoading () {
207240 show (mLoadingResId );
208241 }
@@ -253,6 +286,9 @@ private View layout(int layoutId) {
253286 view .setTextColor (mTextColor );
254287 view .setTextSize (TypedValue .COMPLEX_UNIT_PX , mTextSize );
255288 }
289+ if (mOnEmptyInflateListener != null ) {
290+ mOnEmptyInflateListener .onInflate (layout );
291+ }
256292 } else if (layoutId == mErrorResId ) {
257293 ImageView img = (ImageView ) layout .findViewById (R .id .error_image );
258294 if (img != null ) {
@@ -272,6 +308,9 @@ private View layout(int layoutId) {
272308 btn .setBackground (mButtonBackground );
273309 btn .setOnClickListener (mRetryButtonClickListener );
274310 }
311+ if (mOnErrorInflateListener != null ) {
312+ mOnErrorInflateListener .onInflate (layout );
313+ }
275314 }
276315 return layout ;
277316 }
0 commit comments