Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持TargetView嵌套 #94

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
#【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.

##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
Expand Down Expand Up @@ -46,23 +56,22 @@ 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.
Look over [Quick Setup](https://github.com/Aspsine/SwipeToLoadLayout/wiki/Quick-Setup) for more details.
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: [email protected]
- WeiBo: [@Aspsine](http://weibo.com/wetze)
- Linkedin: cn.linkedin.com/in/aspsine
- Github: github.com/PigFlyy
- Email: [email protected]


##License

Expand Down
15 changes: 11 additions & 4 deletions README_CN.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
####【写在前面】
##这个项目是克隆自 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

##支持的View
理论上支持所有的View

##Demo
[Download](https://raw.githubusercontent.com/Aspsine/SwipeToLoadLayout/master/art/demo.apk)


##Demo 截图 & 视频(Youku)
- ListView & GridView
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ android {
applicationId "com.aspsine.swipetoloadlayout"
minSdkVersion 10
targetSdkVersion 24
versionCode 3
versionName "1.0.3"
versionCode 1
versionName "0.0.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}


repositories {
maven { url "https://jitpack.io" }
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Empty file modified gradlew
100644 → 100755
Empty file.
9 changes: 7 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 24
versionCode 3
versionName "1.0.3"
versionCode 1
versionName "0.0.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}

}

dependencies {
Expand Down
84 changes: 76 additions & 8 deletions library/src/main/java/com/aspsine/swipetoloadlayout/SwipeToLoadLayout.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class SwipeToLoadLayout extends ViewGroup {

private View mTargetView;

private View mTargetViewContainer;

private View mFooterView;

private int mHeaderHeight;
Expand Down Expand Up @@ -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;

/**
* <b>ATTRIBUTE:</b>
* the style default classic
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -416,23 +446,23 @@ 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);
}

/**
* {@inheritDoc}
*/
@Override
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
return new SwipeToLoadLayout.LayoutParams(p);
return new LayoutParams(p);
}

/**
* {@inheritDoc}
*/
@Override
public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
return new SwipeToLoadLayout.LayoutParams(getContext(), attrs);
return new LayoutParams(getContext(), attrs);
}

@Override
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Expand Down