diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..607ac86 --- /dev/null +++ b/.gitignore @@ -0,0 +1,63 @@ +# Created by .ignore support plugin (hsz.mobi) +### Kotlin template +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +### Android template +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# Keystore files +# Uncomment the following line if you do not want to check your keystore files in. +*.jks + +# IntelliJ project files +.idea +*.iml +out +gen diff --git a/app/app.iml b/app/app.iml deleted file mode 100644 index 961bb15..0000000 --- a/app/app.iml +++ /dev/null @@ -1,136 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/library/library.iml b/library/library.iml deleted file mode 100644 index 92cce3a..0000000 --- a/library/library.iml +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/library/src/main/java/ezy/ui/layout/LoadingLayout.java b/library/src/main/java/ezy/ui/layout/LoadingLayout.java index 6063da2..1c95734 100644 --- a/library/src/main/java/ezy/ui/layout/LoadingLayout.java +++ b/library/src/main/java/ezy/ui/layout/LoadingLayout.java @@ -21,6 +21,7 @@ import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; +import android.support.annotation.ColorInt; import android.support.annotation.DrawableRes; import android.support.annotation.LayoutRes; import android.util.AttributeSet; @@ -44,16 +45,18 @@ public interface OnInflateListener { } public static LoadingLayout wrap(Activity activity) { - return wrap(((ViewGroup)activity.findViewById(android.R.id.content)).getChildAt(0)); + return wrap(((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0)); } + public static LoadingLayout wrap(Fragment fragment) { return wrap(fragment.getView()); } + public static LoadingLayout wrap(View view) { if (view == null) { throw new RuntimeException("content view can not be null"); } - ViewGroup parent = (ViewGroup)view.getParent(); + ViewGroup parent = (ViewGroup) view.getParent(); if (view == null) { throw new RuntimeException("parent view can not be null"); } @@ -68,9 +71,11 @@ public static LoadingLayout wrap(View view) { return layout; } + @DrawableRes int mEmptyImage; CharSequence mEmptyText; + @DrawableRes int mErrorImage; CharSequence mErrorText, mRetryText; View.OnClickListener mRetryButtonClickListener = new OnClickListener() { @@ -134,6 +139,7 @@ int dp2px(float dp) { LayoutInflater mInflater; + @Override protected void onFinishInflate() { super.onFinishInflate(); @@ -160,6 +166,7 @@ public LoadingLayout setLoading(@LayoutRes int id) { } return this; } + public LoadingLayout setEmpty(@LayoutRes int id) { if (mEmptyResId != id) { remove(mEmptyResId); @@ -167,6 +174,15 @@ public LoadingLayout setEmpty(@LayoutRes int id) { } return this; } + + public LoadingLayout setError(@LayoutRes int id) { + if (mErrorResId != id) { + remove(mErrorResId); + mErrorResId = id; + } + return this; + } + public LoadingLayout setOnEmptyInflateListener(OnInflateListener listener) { mOnEmptyInflateListener = listener; if (mOnEmptyInflateListener != null && mLayouts.containsKey(mEmptyResId)) { @@ -174,6 +190,7 @@ public LoadingLayout setOnEmptyInflateListener(OnInflateListener listener) { } return this; } + public LoadingLayout setOnErrorInflateListener(OnInflateListener listener) { mOnErrorInflateListener = listener; if (mOnErrorInflateListener != null && mLayouts.containsKey(mErrorResId)) { @@ -187,16 +204,19 @@ public LoadingLayout setEmptyImage(@DrawableRes int resId) { image(mEmptyResId, R.id.empty_image, mEmptyImage); return this; } + public LoadingLayout setEmptyText(String value) { mEmptyText = value; text(mEmptyResId, R.id.empty_text, mEmptyText); return this; } + public LoadingLayout setErrorImage(@DrawableRes int resId) { mErrorImage = resId; image(mErrorResId, R.id.error_image, mErrorImage); return this; } + public LoadingLayout setErrorText(String value) { mErrorText = value; text(mErrorResId, R.id.error_text, mErrorText); @@ -215,26 +235,30 @@ public LoadingLayout setRetryListener(OnClickListener listener) { } -// 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 LoadingLayout setTextColor(@ColorInt int color) { + mTextColor = color; + return this; + } + + public LoadingLayout setTextSize(int dp) { + mTextSize = dp2px(dp); + return this; + } + + public LoadingLayout setButtonTextColor(@ColorInt int color) { + mButtonTextColor = color; + return this; + } + + public LoadingLayout setButtonTextSize(int dp) { + mButtonTextSize = dp2px(dp); + return this; + } + + public LoadingLayout setButtonBackground(Drawable drawable) { + mButtonBackground = drawable; + return this; + } public void showLoading() { show(mLoadingResId); @@ -277,7 +301,7 @@ private View layout(int layoutId) { if (layoutId == mEmptyResId) { ImageView img = (ImageView) layout.findViewById(R.id.empty_image); - if (img != null) { + if (img != null && mEmptyImage != NO_ID) { img.setImageResource(mEmptyImage); } TextView view = (TextView) layout.findViewById(R.id.empty_text); @@ -291,7 +315,7 @@ private View layout(int layoutId) { } } else if (layoutId == mErrorResId) { ImageView img = (ImageView) layout.findViewById(R.id.error_image); - if (img != null) { + if (img != null && mErrorImage != NO_ID) { img.setImageResource(mErrorImage); } TextView txt = (TextView) layout.findViewById(R.id.error_text); diff --git a/loadinglayout.iml b/loadinglayout.iml deleted file mode 100644 index 55301de..0000000 --- a/loadinglayout.iml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file