Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
add OnInflateListener
Browse files Browse the repository at this point in the history
  • Loading branch information
czy1121 committed Dec 5, 2016
1 parent de4c1d3 commit 953a78b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.czy1121:loadinglayout:1.0.0'
compile 'com.github.czy1121:loadinglayout:1.0.1'
}
```

Expand All @@ -33,7 +33,7 @@ dependencies {
</style>
```

**在布局中使用**
**用法一:在布局中使用**

``` xml
<ezy.ui.layout.LoadingLayout
Expand All @@ -51,7 +51,7 @@ dependencies {

```

**包裹并替换内容元素**
**用法二:包裹并替换内容元素**

``` java
@Override
Expand Down
16 changes: 8 additions & 8 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
Expand All @@ -82,6 +74,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand Down
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group='com.github.czy1121'
version='1.0.0'
version='1.0.1'
archivesBaseName='loadinglayout'

android {
Expand Down
51 changes: 45 additions & 6 deletions library/src/main/java/ezy/ui/layout/LoadingLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -40,6 +39,9 @@


public class LoadingLayout extends FrameLayout {
public interface OnInflateListener {
void onInflate(View inflated);
}

public static LoadingLayout wrap(Activity activity) {
return wrap(((ViewGroup)activity.findViewById(android.R.id.content)).getChildAt(0));
Expand Down Expand Up @@ -81,6 +83,9 @@ public void onClick(View v) {
};
View.OnClickListener mRetryListener;

OnInflateListener mOnEmptyInflateListener;
OnInflateListener mOnErrorInflateListener;

int mTextColor, mTextSize;
int mButtonTextColor, mButtonTextSize;
Drawable mButtonBackground;
Expand Down Expand Up @@ -131,7 +136,6 @@ int dp2px(float dp) {
LayoutInflater mInflater;
@Override
protected void onFinishInflate() {
Log.e("ezy", "onFinishInflate");
super.onFinishInflate();
if (getChildCount() == 0) {
return;
Expand Down Expand Up @@ -163,10 +167,17 @@ public LoadingLayout setEmpty(@LayoutRes int id) {
}
return this;
}
public LoadingLayout setError(@LayoutRes int id) {
if (mErrorResId != id) {
remove(mErrorResId);
mErrorResId = id;
public LoadingLayout setOnEmptyInflateListener(OnInflateListener listener) {
mOnEmptyInflateListener = listener;
if (mOnEmptyInflateListener != null && mLayouts.containsKey(mEmptyResId)) {
listener.onInflate(mLayouts.get(mEmptyResId));
}
return this;
}
public LoadingLayout setOnErrorInflateListener(OnInflateListener listener) {
mOnErrorInflateListener = listener;
if (mOnErrorInflateListener != null && mLayouts.containsKey(mErrorResId)) {
listener.onInflate(mLayouts.get(mErrorResId));
}
return this;
}
Expand Down Expand Up @@ -203,6 +214,28 @@ public LoadingLayout setRetryListener(OnClickListener listener) {
return this;
}


// public LoadingLayout setTextColor(@ColorInt int color) {
// mTextColor = color;
// return this;
// }
// public LoadingLayout setTextSize(@ColorInt int dp) {
// mTextColor = dp2px(dp);
// return this;
// }
// public LoadingLayout setButtonTextColor(@ColorInt int color) {
// mButtonTextColor = color;
// return this;
// }
// public LoadingLayout setButtonTextSize(@ColorInt int dp) {
// mButtonTextColor = dp2px(dp);
// return this;
// }
// public LoadingLayout setButtonBackground(Drawable drawable) {
// mButtonBackground = drawable;
// return this;
// }

public void showLoading() {
show(mLoadingResId);
}
Expand Down Expand Up @@ -253,6 +286,9 @@ private View layout(int layoutId) {
view.setTextColor(mTextColor);
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
}
if (mOnEmptyInflateListener != null) {
mOnEmptyInflateListener.onInflate(layout);
}
} else if (layoutId == mErrorResId) {
ImageView img = (ImageView) layout.findViewById(R.id.error_image);
if (img != null) {
Expand All @@ -272,6 +308,9 @@ private View layout(int layoutId) {
btn.setBackground(mButtonBackground);
btn.setOnClickListener(mRetryButtonClickListener);
}
if (mOnErrorInflateListener != null) {
mOnErrorInflateListener.onInflate(layout);
}
}
return layout;
}
Expand Down

0 comments on commit 953a78b

Please sign in to comment.