diff --git a/README.md b/README.md index a6f9dda..dc532ea 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,15 @@ +#【First of all】 + +###this project is cloned from Aspsine's SwipeToLoadLayout ,I'm not the author of it.if you want to know more about it,please visit https://github.com/Aspsine/SwipeToLoadLayout + +###I create this branch because I think Aspsine update slowly, If you like this project and want to make it better and better,please ###star me or pull your idea!I will merge it quickly as my best! + +#【The Difference】 + +### 1、Add a switcher to hide headerView/footView while refreshing/loadingmore,not keep them always! + + + [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-SwipeToLoadLayout-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/2812) # SwipeToLoadLayout SwipeToLoadLayout is a reusable pull-to-refresh and pull-to-load-more widget. @@ -5,8 +17,6 @@ SwipeToLoadLayout is a reusable pull-to-refresh and pull-to-load-more widget. ##Supported View Theoretically support all kinds of views. -##Demo -[Download](https://raw.githubusercontent.com/Aspsine/SwipeToLoadLayout/master/art/demo.apk) ##Demo ScreenShot & Video(Youtube) - ListView & GridView @@ -46,7 +56,7 @@ repositories { - Step 2. Add the dependency in the form ``` dependencies { - compile 'com.github.Aspsine:SwipeToLoadLayout:1.0.3' + compile 'com.github.PigFlyy:SwipeToLoadLayout:v0.0.1' } ``` - Step 3. @@ -54,15 +64,14 @@ Look over [Quick Setup](https://github.com/Aspsine/SwipeToLoadLayout/wiki/Quick- You can find more customized header view and footer view in the demo app. ##Thanks -- Google SwipeRefreshLayout +- Aspsine SwipeToLoadLayout - [liaohuqiu android-Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh) - [Yalantis Phoenix](https://github.com/Yalantis/Phoenix) ##Contact Me -- Github: github.com/aspsine -- Email: littleximail@gmail.com -- WeiBo: [@Aspsine](http://weibo.com/wetze) -- Linkedin: cn.linkedin.com/in/aspsine +- Github: github.com/PigFlyy +- Email: 1015121748@qq.com + ##License diff --git a/README_CN.md b/README_CN.md index 1a7c60c..7003000 100644 --- a/README_CN.md +++ b/README_CN.md @@ -1,3 +1,11 @@ +####【写在前面】 +##这个项目是克隆自 Aspsine的 SwipeToLoadLayout ,我不是这个项目的原作者,如果你想了解更多关于原作品的信息,请访问 ##https://github.com/Aspsine/SwipeToLoadLayout +##我创建这个分支是因为我觉得原作者更新太慢,如果你也喜欢这个作品并且希望它能变得更好,欢迎Star我或者提交你的idea到这个项目,我会尽我最快的速度更新! + + +###【区别】 +##1、添加一个选择器,可以当你上拉刷新或者加载更多时隐藏头布局或者尾布局,而不是一直保持它们。 + [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-SwipeToLoadLayout-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/2812) # SwipeToLoadLayout SwipeToLoadLayout是一个可以帮助你实现下拉刷新和加载更多的Layout @@ -5,8 +13,7 @@ SwipeToLoadLayout是一个可以帮助你实现下拉刷新和加载更多的Lay ##支持的View 理论上支持所有的View -##Demo -[Download](https://raw.githubusercontent.com/Aspsine/SwipeToLoadLayout/master/art/demo.apk) + ##Demo 截图 & 视频(Youku) - ListView & GridView @@ -46,13 +53,13 @@ repositories { - Step 2. 在你的app build.gradle 的 dependencies 中添加依赖 ``` dependencies { - compile 'com.github.Aspsine:SwipeToLoadLayout:1.0.3' + compile 'com.github.PigFlyy:SwipeToLoadLayout:v0.0.1' } ``` - Step 3. 查看[快速集成文档](https://github.com/Aspsine/SwipeToLoadLayout/wiki/Quick-Setup) ##致谢 -- Google SwipeRefreshLayout +- Aspsine SwipeRefreshLayout - [liaohuqiu android-Ultra-Pull-To-Refresh](https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh) - [Yalantis Phoenix](https://github.com/Yalantis/Phoenix) diff --git a/app/build.gradle b/app/build.gradle index 6823ba0..44d987e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.aspsine.swipetoloadlayout" minSdkVersion 10 targetSdkVersion 24 - versionCode 3 - versionName "1.0.3" + versionCode 1 + versionName "0.0.1" } buildTypes { release { @@ -17,6 +17,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + lintOptions { + abortOnError false + } + repositories { maven { url "https://jitpack.io" } diff --git a/build.gradle b/build.gradle index 03bced9..e7fc6a7 100644 --- a/build.gradle +++ b/build.gradle @@ -5,11 +5,12 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.0' + classpath 'com.android.tools.build:gradle:2.2.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } + } allprojects { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c8c90b9..63fa4ad 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Sep 02 10:00:37 CST 2015 +#Fri Dec 09 17:31:34 CST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/library/build.gradle b/library/build.gradle index 11b9e50..fa711a8 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 24 - versionCode 3 - versionName "1.0.3" + versionCode 1 + versionName "0.0.1" } buildTypes { release { @@ -16,6 +16,11 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + lintOptions { + abortOnError false + checkReleaseBuilds false + } + } dependencies { diff --git a/library/src/main/java/com/aspsine/swipetoloadlayout/SwipeToLoadLayout.java b/library/src/main/java/com/aspsine/swipetoloadlayout/SwipeToLoadLayout.java old mode 100644 new mode 100755 index 9233ab0..564ff51 --- a/library/src/main/java/com/aspsine/swipetoloadlayout/SwipeToLoadLayout.java +++ b/library/src/main/java/com/aspsine/swipetoloadlayout/SwipeToLoadLayout.java @@ -59,6 +59,8 @@ public class SwipeToLoadLayout extends ViewGroup { private View mTargetView; + private View mTargetViewContainer; + private View mFooterView; private int mHeaderHeight; @@ -140,6 +142,18 @@ public class SwipeToLoadLayout extends ViewGroup { */ private boolean mLoadMoreEnabled = true; + /** + * a switcher whither hiding headerView when refreshing + */ + + private boolean isHideHeaderWhenRefreshing = true; + + /** + * a switcher whither hiding footerView when loadingmore + */ + + private boolean isHideFooterWhenLoadingMore = true; + /** * ATTRIBUTE: * the style default classic @@ -334,6 +348,22 @@ protected void onFinishInflate() { } else if (0 < childNum && childNum < 4) { mHeaderView = findViewById(R.id.swipe_refresh_header); mTargetView = findViewById(R.id.swipe_target); + try { + mTargetViewContainer = (View) mTargetView.getParent(); + if(mTargetViewContainer instanceof SwipeToLoadLayout) { + mTargetViewContainer = null; + }else{ + while(mTargetViewContainer.getParent() != null){ + if(mTargetViewContainer.getParent() instanceof SwipeToLoadLayout){ + break; + } + mTargetViewContainer = (View) mTargetViewContainer.getParent(); + } + } + } catch (Exception e) { + e.printStackTrace(); + mTargetViewContainer = null; + } mFooterView = findViewById(R.id.swipe_load_more_footer); } else { // more than three children: unsupported! @@ -365,7 +395,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { } // target if (mTargetView != null) { - final View targetView = mTargetView; + final View targetView = mTargetViewContainer == null ? mTargetView : mTargetViewContainer; measureChildWithMargins(targetView, widthMeasureSpec, 0, heightMeasureSpec, 0); } // footer @@ -416,7 +446,7 @@ public LayoutParams(ViewGroup.LayoutParams source) { */ @Override protected ViewGroup.LayoutParams generateDefaultLayoutParams() { - return new SwipeToLoadLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + return new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); } /** @@ -424,7 +454,7 @@ protected ViewGroup.LayoutParams generateDefaultLayoutParams() { */ @Override protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) { - return new SwipeToLoadLayout.LayoutParams(p); + return new LayoutParams(p); } /** @@ -432,7 +462,7 @@ protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) */ @Override public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) { - return new SwipeToLoadLayout.LayoutParams(getContext(), attrs); + return new LayoutParams(getContext(), attrs); } @Override @@ -496,6 +526,19 @@ public boolean onInterceptTouchEvent(MotionEvent event) { if (mActivePointerId == INVALID_POINTER) { return false; } + + //hide headerView when refreshing , it will improve the user experience + if (mHasHeaderView && isRefreshing() && isHideHeaderWhenRefreshing){ + mRefreshCallback.onReset(); + scrollRefreshingToDefault(); + } + + //hide footerView when loadingmore , it will improve the user experience + if (mHasFooterView && isLoadingMore() && isHideFooterWhenLoadingMore){ + mLoadMoreCallback.onReset(); + scrollLoadingMoreToDefault(); + } + float y = getMotionEventY(event, mActivePointerId); float x = getMotionEventX(event, mActivePointerId); final float yInitDiff = y - mInitDownY; @@ -513,6 +556,7 @@ public boolean onInterceptTouchEvent(MotionEvent event) { // intercept the move action event and pass it to SwipeToLoadLayout#onTouchEvent() return true; } + break; case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(event); @@ -538,6 +582,7 @@ public boolean onTouchEvent(MotionEvent event) { return true; case MotionEvent.ACTION_MOVE: + // take over the ACTION_MOVE event from SwipeToLoadLayout#onInterceptTouchEvent() // if condition is true final float y = getMotionEventY(event, mActivePointerId); @@ -687,6 +732,24 @@ public boolean isLoadingMore() { return STATUS.isLoadingMore(mStatus); } + /** + * a switcher whither hiding headerView when refreshing + * + * @param hideable + */ + public void setHideHeaderWhenRefreshing(boolean hideable) { + this.isHideHeaderWhenRefreshing = hideable; + } + + /** + * a switcher whither hiding footerView when loadingmore + * + * @param hideable + */ + public void setHideFooterWhenLoadingMore(boolean hideable) { + this.isHideFooterWhenLoadingMore = hideable; + } + /** * set refresh header view, the view must at lease be an implement of {@code SwipeRefreshTrigger}. * the view can also implement {@code SwipeTrigger} for more extension functions @@ -934,16 +997,18 @@ public void run() { * @param loadingMore */ public void setLoadingMore(boolean loadingMore) { - if (!isLoadMoreEnabled() || mFooterView == null) { + if (mFooterView == null) { return; } this.mAutoLoading = loadingMore; - if (loadingMore) { + if (loadingMore && isLoadMoreEnabled()) { + mAutoLoading = true; if (STATUS.isStatusDefault(mStatus)) { setStatus(STATUS.STATUS_SWIPING_TO_LOAD_MORE); scrollDefaultToLoadingMore(); } } else { + mAutoLoading = false; if (STATUS.isLoadingMore(mStatus)) { mLoadMoreCallback.onComplete(); postDelayed(new Runnable() { @@ -1050,7 +1115,7 @@ private void layoutChildren() { // layout target if (mTargetView != null) { - final View targetView = mTargetView; + final View targetView = mTargetViewContainer == null ? mTargetView : mTargetViewContainer; MarginLayoutParams lp = (MarginLayoutParams) targetView.getLayoutParams(); final int targetLeft = paddingLeft + lp.leftMargin; final int targetTop; @@ -1125,7 +1190,10 @@ private void layoutChildren() { mFooterView.bringToFront(); } } else if (mStyle == STYLE.BLEW || mStyle == STYLE.SCALE) { - if (mTargetView != null) { + if(mTargetViewContainer != null){ + mTargetViewContainer.bringToFront(); + } + else if (mTargetView != null) { mTargetView.bringToFront(); } }