Skip to content

Commit

Permalink
修复下拉刷新在数据很少的时候显示的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoqp2010 committed Nov 26, 2013
1 parent 20666d1 commit 41e4ccc
Show file tree
Hide file tree
Showing 65 changed files with 78 additions and 106 deletions.
Binary file modified AndBase/bin/andbase.jar
Binary file not shown.
Binary file modified AndBase/bin/classes/com/ab/view/pullview/AbListViewFooter.class
Binary file not shown.
Binary file not shown.
Binary file modified AndBase/bin/classes/com/ab/view/pullview/AbPullGridView$1.class
Binary file not shown.
Binary file modified AndBase/bin/classes/com/ab/view/pullview/AbPullGridView.class
Binary file not shown.
Binary file modified AndBase/bin/classes/com/ab/view/pullview/AbPullListView$1.class
Binary file not shown.
Binary file modified AndBase/bin/classes/com/ab/view/pullview/AbPullListView.class
Binary file not shown.
3 changes: 0 additions & 3 deletions AndBase/bin/jarlist.cache

This file was deleted.

6 changes: 4 additions & 2 deletions AndBase/src/com/ab/view/pullview/AbListViewFooter.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,23 @@ public AbListViewFooter(Context context, AttributeSet attrs) {
*/
public void setState(int state) {

footerView.setVisibility(View.VISIBLE);

if (state == STATE_READY) {
footerView.setVisibility(View.VISIBLE);
footerTextView.setVisibility(View.VISIBLE);
footerProgressBar.setVisibility(View.GONE);
footerTextView.setText("载入更多");
} else if (state == STATE_LOADING) {
footerView.setVisibility(View.VISIBLE);
footerTextView.setVisibility(View.VISIBLE);
footerProgressBar.setVisibility(View.VISIBLE);
footerTextView.setText("正在加载...");
}else if(state == STATE_NO){
footerView.setVisibility(View.GONE);
footerTextView.setVisibility(View.VISIBLE);
footerProgressBar.setVisibility(View.GONE);
footerTextView.setText("已是全部");
}else if(state == STATE_EMPTY){
footerView.setVisibility(View.GONE);
footerTextView.setVisibility(View.GONE);
footerProgressBar.setVisibility(View.GONE);
footerTextView.setText("没有数据");
Expand Down
23 changes: 10 additions & 13 deletions AndBase/src/com/ab/view/pullview/AbMultiColumnListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ public class AbMultiColumnListView extends AbMultiColumnBaseListView implements
/** The Constant OFFSET_RADIO. */
private final static float OFFSET_RADIO = 1.8f; // support iOS like pull
// feature.

/**上一次的数量*/
private int count = 0;

/**
* Instantiates a new ab multi column list view.
*
Expand Down Expand Up @@ -140,8 +142,6 @@ private void initWithContext(Context context) {

mFooterViewHeight= mFooterView.getFooterHeight();

mFooterView.hide();

}

/**
Expand Down Expand Up @@ -219,15 +219,16 @@ public void stopRefresh() {
/**
* stop load more, reset footer view.
*
* @param more the more
*/
public void stopLoadMore(boolean more) {
public void stopLoadMore() {
mFooterView.hide();
if (mPullLoading == true) {
mPullLoading = false;
mFooterView.setState(AbListViewFooter.STATE_READY);
}
int countNew = mAdapter.getCount();
//判断有没有更多数据了
if(more){
if(countNew > count){
mFooterView.setState(AbListViewFooter.STATE_READY);
}else{
mFooterView.setState(AbListViewFooter.STATE_NO);
Expand Down Expand Up @@ -293,6 +294,7 @@ private void updateFooterHeight(float delta) {
* Start load more.
*/
private void startLoadMore() {
mFooterView.show();
mPullLoading = true;
mFooterView.setState(AbListViewFooter.STATE_LOADING);
if (mListViewListener != null) {
Expand Down Expand Up @@ -323,8 +325,8 @@ public boolean onTouchEvent(MotionEvent ev) {
mLastY = ev.getRawY();
if (getFirstVisiblePosition() == 0 && (mHeaderView.getVisiableHeight() > 0 || deltaY > 0)) {
updateHeaderHeight(deltaY / OFFSET_RADIO);
} else if (getLastVisiblePosition() == mTotalItemCount - 1 && mFooterView.getVisiableHeight() < mFooterViewHeight) {
updateFooterHeight(-deltaY / OFFSET_RADIO);
} else if (getLastVisiblePosition() == mTotalItemCount - 1 && deltaY < 0) {
startLoadMore();
}
break;
case MotionEvent.ACTION_UP:
Expand All @@ -341,11 +343,6 @@ public boolean onTouchEvent(MotionEvent ev) {
}
//根据mPullRefreshing判断显示的header
resetHeaderHeight();
} else if (getLastVisiblePosition() == mTotalItemCount - 1) {
// invoke load more.
if (mEnablePullLoad && mFooterView.getVisiableHeight() > mFooterViewHeight-2) {
startLoadMore();
}
}
break;
default:
Expand Down
15 changes: 11 additions & 4 deletions AndBase/src/com/ab/view/pullview/AbPullGridView.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public class AbPullGridView extends AbBaseGridView implements OnScrollListener,O
/** 外层是否可滚动. */
private boolean childScrollState = false;

/**上一次的数量*/
private int count = 0;

/**
* Instantiates a new ab pull view.
*
Expand Down Expand Up @@ -230,14 +233,16 @@ private void startLoadMore() {
*
* @param more the more
*/
public void stopLoadMore(boolean more) {
public void stopLoadMore() {
mFooterView.hide();
if (mPullLoading == true) {
mPullLoading = false;
mFooterView.setState(AbListViewFooter.STATE_READY);
}
//判断有没有更多数据了
if(more){
int countNew = mAdapter.getCount();

if(countNew > count){
mFooterView.setState(AbListViewFooter.STATE_READY);
}else{
mFooterView.setState(AbListViewFooter.STATE_NO);
Expand Down Expand Up @@ -313,7 +318,6 @@ public boolean onTouchEvent(MotionEvent ev) {
if (mEnablePullRefresh && (mHeaderView.getVisiableHeight() > 0 || deltaY > 0)) {
//下拉更新高度
updateHeaderHeight(deltaY / OFFSET_RADIO);

}
break;
case MotionEvent.ACTION_UP:
Expand Down Expand Up @@ -391,7 +395,10 @@ public void onScrollStateChanged(AbsListView view, int scrollState) {
if(view.getFirstVisiblePosition() == 0){
Log.i("TAG", "滚动到顶部");
childScrollState = false;

if (mEnablePullLoad && view.getLastVisiblePosition()==(view.getCount() - 1)) {
Log.i("TAG", "滚动到底部");
startLoadMore();
}
}else if (view.getLastVisiblePosition() == (view.getCount() - 1)) {
Log.i("TAG", "滚动到底部");
startLoadMore();
Expand Down
40 changes: 13 additions & 27 deletions AndBase/src/com/ab/view/pullview/AbPullListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public class AbPullListView extends ListView implements OnScrollListener {
/** 数据相关. */
private ListAdapter mAdapter = null;

/**上一次的数量*/
private int count = 0;

/**
* Instantiates a new ab pull list view.
*
Expand Down Expand Up @@ -146,6 +149,8 @@ private void initWithContext(Context context) {
//默认是打开刷新与更多
setPullRefreshEnable(true);
setPullLoadEnable(true);

mFooterView.hide();
}

/**
Expand Down Expand Up @@ -213,7 +218,7 @@ public void stopRefresh() {
resetHeaderHeight();
}

int count = mAdapter.getCount();
count = mAdapter.getCount();
//判断有没有数据
if(count>0){
mFooterView.setState(AbListViewFooter.STATE_READY);
Expand All @@ -225,15 +230,16 @@ public void stopRefresh() {
/**
* stop load more, reset footer view.
*
* @param more the more
*/
public void stopLoadMore(boolean more) {
public void stopLoadMore() {
mFooterView.hide();
if (mPullLoading == true) {
mPullLoading = false;
mFooterView.setState(AbListViewFooter.STATE_READY);
}
int countNew = mAdapter.getCount();
//判断有没有更多数据了
if(more){
if(countNew > count){
mFooterView.setState(AbListViewFooter.STATE_READY);
}else{
mFooterView.setState(AbListViewFooter.STATE_NO);
Expand Down Expand Up @@ -279,27 +285,12 @@ private void resetHeaderHeight() {
invalidate();
}

/**
* 更新 footer的显示.
* @param delta 增加值
*/
private void updateFooterHeight(float delta) {
int newHeight = mFooterView.getVisiableHeight() + (int) delta;
if(newHeight > mFooterViewHeight){
newHeight = mFooterViewHeight;
}
mFooterView.setVisiableHeight(newHeight);
if (mEnablePullLoad && !mPullLoading) {
if (newHeight >= mFooterViewHeight) {
mFooterView.setState(AbListViewFooter.STATE_READY);
}
}
}

/**
* Start load more.
*/
private void startLoadMore() {
mFooterView.show();
mPullLoading = true;
mFooterView.setState(AbListViewFooter.STATE_LOADING);
if (mListViewListener != null) {
Expand Down Expand Up @@ -327,8 +318,8 @@ public boolean onTouchEvent(MotionEvent ev) {
mLastY = ev.getRawY();
if (mEnablePullRefresh && getFirstVisiblePosition() == 0 && (mHeaderView.getVisiableHeight() > 0 || deltaY > 0)) {
updateHeaderHeight(deltaY / OFFSET_RADIO);
} else if (mEnablePullRefresh && getLastVisiblePosition() == mTotalItemCount - 1 && mFooterView.getVisiableHeight() < mFooterViewHeight) {
updateFooterHeight(-deltaY / OFFSET_RADIO);
} else if (mEnablePullLoad && getLastVisiblePosition() == mTotalItemCount - 1 && deltaY<0) {
startLoadMore();
}
break;
case MotionEvent.ACTION_UP:
Expand All @@ -348,11 +339,6 @@ public boolean onTouchEvent(MotionEvent ev) {
//弹回
resetHeaderHeight();
}
//在到底部就加载下一页
}else if (getLastVisiblePosition() == mTotalItemCount-1) {
if (mEnablePullLoad && mFooterView.getVisiableHeight() > mFooterViewHeight-2) {
startLoadMore();
}
}
break;
default:
Expand Down
Binary file modified AndBaseDemo/bin/AndBaseDemo.apk
Binary file not shown.
Binary file modified AndBaseDemo/bin/classes.dex
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified AndBaseDemo/bin/classes/com/andbase/demo/activity/Fragment1$3.class
Binary file not shown.
Binary file not shown.
Binary file modified AndBaseDemo/bin/classes/com/andbase/demo/activity/Fragment1.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified AndBaseDemo/bin/resources.ap_
Binary file not shown.
24 changes: 12 additions & 12 deletions AndBaseDemo/src/com/andbase/demo/activity/Fragment1.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class Fragment1 extends Fragment {
private AbTaskQueue mAbTaskQueue = null;
private ArrayList<String> mPhotoList = new ArrayList<String>();
private ImageListAdapter myListViewAdapter = null;
private int total = 50;
private int pageSize = 5;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand Down Expand Up @@ -104,11 +106,11 @@ public void get() {
newList = new ArrayList<Map<String, Object>>();
Map<String, Object> map = null;

for (int i = 0; i < 10; i++) {
for (int i = 0; i < pageSize; i++) {
map = new HashMap<String, Object>();
map.put("itemsIcon",mPhotoList.get(new Random().nextInt(mPhotoList.size())));
map.put("itemsTitle", "[Fragment1]"+i);
map.put("itemsText", "[Fragment1]..."+i);
map.put("itemsTitle", "[Fragment1]"+(i+1));
map.put("itemsText", "[Fragment1]..."+(i+1));
newList.add(map);
}
} catch (Exception e) {
Expand All @@ -125,12 +127,8 @@ public void update() {
list.addAll(newList);
myListViewAdapter.notifyDataSetChanged();
newList.clear();
mAbPullListView.stopLoadMore(true);
}else{
//没有新数据了
mAbPullListView.stopLoadMore(false);
}

mAbPullListView.stopLoadMore();
}

@Override
Expand All @@ -141,12 +139,14 @@ public void get() {
newList = new ArrayList<Map<String, Object>>();
Map<String, Object> map = null;

for (int i = 0; i < 10; i++) {
for (int i = 0; i < pageSize; i++) {
map = new HashMap<String, Object>();
map.put("itemsIcon",mPhotoList.get(new Random().nextInt(mPhotoList.size())));
map.put("itemsTitle", "item上拉"+i);
map.put("itemsText", "item上拉..."+i);
newList.add(map);
map.put("itemsTitle", "item上拉"+((currentPage-1)*pageSize+(i+1)));
map.put("itemsText", "item上拉..."+((currentPage-1)*pageSize+(i+1)));
if((list.size()+newList.size()) < total){
newList.add(map);
}
}
} catch (Exception e) {
currentPage--;
Expand Down
6 changes: 1 addition & 5 deletions AndBaseDemo/src/com/andbase/demo/activity/Fragment2.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,8 @@ public void update() {
list.addAll(newList);
myListViewAdapter.notifyDataSetChanged();
newList.clear();
mAbPullListView.stopLoadMore(true);
}else{
//没有新数据了
mAbPullListView.stopLoadMore(false);
}

mAbPullListView.stopLoadMore();
}

@Override
Expand Down
5 changes: 1 addition & 4 deletions AndBaseDemo/src/com/andbase/demo/activity/Fragment3.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,8 @@ public void update() {
list.addAll(newList);
myListViewAdapter.notifyDataSetChanged();
newList.clear();
mAbPullListView.stopLoadMore(true);
}else{
//没有新数据了
mAbPullListView.stopLoadMore(false);
}
mAbPullListView.stopLoadMore();

}

Expand Down
6 changes: 1 addition & 5 deletions AndBaseDemo/src/com/andbase/demo/activity/Fragment4.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,8 @@ public void update() {
list.addAll(newList);
myListViewAdapter.notifyDataSetChanged();
newList.clear();
mAbPullListView.stopLoadMore(true);
}else{
//没有新数据了
mAbPullListView.stopLoadMore(false);
}

mAbPullListView.stopLoadMore();
}

@Override
Expand Down
5 changes: 1 addition & 4 deletions AndBaseDemo/src/com/andbase/demo/activity/Fragment5.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,8 @@ public void update() {
list.addAll(newList);
myListViewAdapter.notifyDataSetChanged();
newList.clear();
mAbPullListView.stopLoadMore(true);
}else{
//没有新数据了
mAbPullListView.stopLoadMore(false);
}
mAbPullListView.stopLoadMore();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,8 @@ public void update() {
list.addAll(newList);
myListViewAdapter.notifyDataSetChanged();
newList.clear();
mAbPullListView.stopLoadMore(true);
}else{
//没有新数据了
mAbPullListView.stopLoadMore(false);
}

mAbPullListView.stopLoadMore();
}

@Override
Expand Down
Loading

0 comments on commit 41e4ccc

Please sign in to comment.