From 747f9c5b78e68a274c0f82a4709c2a84cf559fcf Mon Sep 17 00:00:00 2001 From: Qs Date: Thu, 18 Jun 2015 17:35:50 +0800 Subject: [PATCH 1/2] added ScrollView-loadmore added it --- .../ui/loadmore/LoadMoreHomeFragment.java | 7 + .../loadmore/LoadMoreScrollViewFragment.java | 127 ++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 src/in/srain/cube/demo/ui/loadmore/LoadMoreScrollViewFragment.java diff --git a/src/in/srain/cube/demo/ui/loadmore/LoadMoreHomeFragment.java b/src/in/srain/cube/demo/ui/loadmore/LoadMoreHomeFragment.java index 60f5131..6a518ae 100644 --- a/src/in/srain/cube/demo/ui/loadmore/LoadMoreHomeFragment.java +++ b/src/in/srain/cube/demo/ui/loadmore/LoadMoreHomeFragment.java @@ -26,6 +26,13 @@ public void onClick(View v) { getContext().pushFragmentToBackStack(LoadMoreGridViewFragment.class, null); } })); + itemInfos.add(newItemInfo(R.string.cube_demo_load_more_grid_view, "#4d90fe", new OnClickListener() { + + @Override + public void onClick(View v) { + getContext().pushFragmentToBackStack(LoadMoreScrollViewFragment.class, null); + } + })); } @Override diff --git a/src/in/srain/cube/demo/ui/loadmore/LoadMoreScrollViewFragment.java b/src/in/srain/cube/demo/ui/loadmore/LoadMoreScrollViewFragment.java new file mode 100644 index 0000000..1fa6907 --- /dev/null +++ b/src/in/srain/cube/demo/ui/loadmore/LoadMoreScrollViewFragment.java @@ -0,0 +1,127 @@ +package in.srain.cube.demo.ui.loadmore; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AbsListView; +import android.widget.Button; +import android.widget.ListView; +import in.srain.cube.demo.R; +import in.srain.cube.demo.base.DemoTitleBaseFragment; +import in.srain.cube.demo.data.ImageListItem; +import in.srain.cube.demo.datamodel.ImageListDataModel; +import in.srain.cube.demo.event.DemoSimpleEventHandler; +import in.srain.cube.demo.event.ErrorMessageDataEvent; +import in.srain.cube.demo.event.EventCenter; +import in.srain.cube.demo.event.ImageListDataEvent; +import in.srain.cube.demo.ui.viewholders.ImageListItemSmallImageViewHolder; +import in.srain.cube.image.ImageLoader; +import in.srain.cube.image.ImageLoaderFactory; +import in.srain.cube.util.LocalDisplay; +import in.srain.cube.views.list.PagedListViewDataAdapter; +import in.srain.cube.views.loadmore.CubeScrollView; +import in.srain.cube.views.loadmore.LoadMoreContainer; +import in.srain.cube.views.loadmore.LoadMoreHandler; +import in.srain.cube.views.loadmore.LoadMoreListViewContainer; +import in.srain.cube.views.loadmore.LoadMoreScrollViewContainer; +import in.srain.cube.views.ptr.PtrDefaultHandler; +import in.srain.cube.views.ptr.PtrFrameLayout; +import in.srain.cube.views.ptr.PtrHandler; + +public class LoadMoreScrollViewFragment extends DemoTitleBaseFragment { + + private ImageListDataModel mDataModel; + private ImageLoader mImageLoader; + private PtrFrameLayout mPtrFrameLayout; + private CubeScrollView mCubeScrollView; + + @Override + public View createView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { + + setHeaderTitle(R.string.cube_demo_load_more_scroll_view); + + mImageLoader = ImageLoaderFactory.create(getContext()).attachToCubeFragment(this); + + // set up data + mDataModel = new ImageListDataModel(5); + + + // set up views + final View view = inflater.inflate(R.layout.fragment_load_more_scroll_view, null); + + // pull to refresh + mPtrFrameLayout = (PtrFrameLayout) view.findViewById(R.id.load_more_list_view_ptr_frame); + + mPtrFrameLayout.setLoadingMinTime(1000); + mPtrFrameLayout.setPtrHandler(new PtrHandler() { + @Override + public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) { + + // here check list view, not content. + return PtrDefaultHandler.checkContentCanBePulledDown(frame, mCubeScrollView, header); + } + + @Override + public void onRefreshBegin(PtrFrameLayout frame) { + mDataModel.queryFirstPage(); + } + }); + + // list view + mCubeScrollView = (CubeScrollView) view.findViewById(R.id.load_more_small_image_scroll_view); + for (int i = 0; i < 25; i++) { + Button button = new Button(getActivity()); + button.setText(""+i); + ((ViewGroup)mCubeScrollView.getChildAt(0)).addView(button); + + } + + // header place holder + View headerMarginView = new View(getContext()); + headerMarginView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, LocalDisplay.dp2px(20))); + + // load more container + final LoadMoreScrollViewContainer loadMoreListViewContainer = (LoadMoreScrollViewContainer) view.findViewById(R.id.load_more_list_view_container); + loadMoreListViewContainer.useDefaultHeader(); + + // binding view and data + loadMoreListViewContainer.setLoadMoreHandler(new LoadMoreHandler() { + @Override + public void onLoadMore(LoadMoreContainer loadMoreContainer) { + mDataModel.queryNextPage(); + } + }); + + // process data + EventCenter.bindContainerAndHandler(this, new DemoSimpleEventHandler() { + + public void onEvent(ImageListDataEvent event) { + + // ptr + mPtrFrameLayout.refreshComplete(); + + // load more + Button button = new Button(getActivity()); + loadMoreListViewContainer.loadMoreFinish(mDataModel.getListPageInfo().isEmpty(), mDataModel.getListPageInfo().hasMore()); + button.setText(((ViewGroup)mCubeScrollView.getChildAt(0)).getChildCount()-1+""); + ((ViewGroup)mCubeScrollView.getChildAt(0)).addView(button,((ViewGroup)mCubeScrollView.getChildAt(0)).getChildCount()-1); + } + + public void onEvent(ErrorMessageDataEvent event) { + loadMoreListViewContainer.loadMoreError(0, event.message); + } + + }).tryToRegisterIfNot(); + + // auto load data + mPtrFrameLayout.postDelayed(new Runnable() { + @Override + public void run() { + mPtrFrameLayout.autoRefresh(false); + } + }, 150); + + return view; + } +} From 2e33c2884e98de9c4bf52fbdd06a35834bb67d7f Mon Sep 17 00:00:00 2001 From: qs-lll Date: Thu, 18 Jun 2015 17:42:19 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 121 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 62 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index d323b89..4a29e0c 100644 --- a/README.md +++ b/README.md @@ -1,59 +1,62 @@ -[![Android Gems](http://www.android-gems.com/badge/liaohuqiu/android-cube-app.svg)](http://www.android-gems.com/lib/liaohuqiu/android-cube-app) - -##### 欢迎关注我 - -Github: https://github.com/liaohuqiu - -twitter: https://twitter.com/liaohuqiu - -blog: http://liaohuqiu.net - -微博: http://weibo.com/liaohuqiu - ---- - - -[![Build Status](https://travis-ci.org/liaohuqiu/android-cube-app.svg?branch=master)](https://travis-ci.org/liaohuqiu/android-cube-app) - -这个项目的目的是作为一个APP开发参考。 - -#### 功能点 - -* 加载更多 -
- - -
- - -### 依赖 - -* support-v4, 版本: r7 -* clog, 版本: 1.0.2, https://github.com/liaohuqiu/android-CLog -* cube-sdk, 版本: 1.0.44.33-SNAPSHOT, https://github.com/etao-open-source/cube-sdk -* ultra-pull-to-refresh, 版本: 1.0.9.1-SNAPSHOT, https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh -* eventbus, 版本: 2.4.0, https://github.com/greenrobot/EventBus - -### 关于Eclipse运行项目 - -通过gradle(Android Studio / Intellij IDEA)以及maven可以无阻碍地运行项目。但对于eclipse的同学来说,可能会遇到一些障碍。 - -一些依赖,直接是jar包, (support-v4, clog, event-bus), 我都放在了libs目录下,直接引入到工程即可。 - -另外依赖的一些项目因为含有资源文件,无法仅打包成jar, 需要打包成aar或者apklib,而Eclipse是没有办法直接使用这两种格式的。 - -建议:将这些依赖的类库的项目在Eclipse作为工程打开,引入到你的项目中。以下是需要引入的项目: - -* cube-sdk. https://github.com/etao-open-source/cube-sdk core文件夹作为一个类库项目引入 - -* ultra-ptr. https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh. ptr-lib文件夹,作为一个类库项目引入。 - -注意: **请使用dev分支中最新的代码** - -### 联系方式和问题建议 - -* 微博: http://weibo.com/liaohuqiu -* 博客: http://www.liaohuqiu.net -* QQ 群: 271918140 -* srain@php.net -* twitter: https://twitter.com/liaohuqiu +[![Android Gems](http://www.android-gems.com/badge/liaohuqiu/android-cube-app.svg)](http://www.android-gems.com/lib/liaohuqiu/android-cube-app) + +##### 欢迎关注我 + +Github: https://github.com/liaohuqiu + +twitter: https://twitter.com/liaohuqiu + +blog: http://liaohuqiu.net + +微博: http://weibo.com/liaohuqiu + +--- + + +[![Build Status](https://travis-ci.org/liaohuqiu/android-cube-app.svg?branch=master)](https://travis-ci.org/liaohuqiu/android-cube-app) +### 添加scrollview的加载更多功能 + 必须引用https://github.com/qs-lll/cube-sdk + 更改cube- sdk 源码 + +这个项目的目的是作为一个APP开发参考。 + +#### 功能点 + +* 加载更多 +
+ + +
+ + +### 依赖 + +* support-v4, 版本: r7 +* clog, 版本: 1.0.2, https://github.com/liaohuqiu/android-CLog +* cube-sdk, 版本: 1.0.44.33-SNAPSHOT, https://github.com/etao-open-source/cube-sdk +* ultra-pull-to-refresh, 版本: 1.0.9.1-SNAPSHOT, https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh +* eventbus, 版本: 2.4.0, https://github.com/greenrobot/EventBus + +### 关于Eclipse运行项目 + +通过gradle(Android Studio / Intellij IDEA)以及maven可以无阻碍地运行项目。但对于eclipse的同学来说,可能会遇到一些障碍。 + +一些依赖,直接是jar包, (support-v4, clog, event-bus), 我都放在了libs目录下,直接引入到工程即可。 + +另外依赖的一些项目因为含有资源文件,无法仅打包成jar, 需要打包成aar或者apklib,而Eclipse是没有办法直接使用这两种格式的。 + +建议:将这些依赖的类库的项目在Eclipse作为工程打开,引入到你的项目中。以下是需要引入的项目: + +* cube-sdk. https://github.com/etao-open-source/cube-sdk core文件夹作为一个类库项目引入 + +* ultra-ptr. https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh. ptr-lib文件夹,作为一个类库项目引入。 + +注意: **请使用dev分支中最新的代码** + +### 联系方式和问题建议 + +* 微博: http://weibo.com/liaohuqiu +* 博客: http://www.liaohuqiu.net +* QQ 群: 271918140 +* srain@php.net +* twitter: https://twitter.com/liaohuqiu