├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── PagingListViewProject ├── PagingListView │ ├── build.gradle │ ├── gradle.properties │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── paging │ │ │ └── listview │ │ │ ├── LoadingView.java │ │ │ ├── PagingBaseAdapter.java │ │ │ └── PagingListView.java │ │ └── res │ │ ├── layout │ │ └── loading_view.xml │ │ └── values │ │ ├── dimens.xml │ │ └── strings.xml ├── PagingListViewSample │ ├── build.gradle │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── ic_launcher-web.png │ │ ├── java │ │ └── com │ │ │ └── paging │ │ │ └── listview │ │ │ └── sample │ │ │ ├── MainActivity.java │ │ │ ├── MyPagingAdaper.java │ │ │ └── SafeAsyncTask.java │ │ └── res │ │ ├── drawable-hdpi │ │ ├── ic_action_refresh.png │ │ └── ic_launcher.png │ │ ├── drawable-mdpi │ │ ├── ic_action_refresh.png │ │ └── ic_launcher.png │ │ ├── drawable-xhdpi │ │ ├── ic_action_refresh.png │ │ └── ic_launcher.png │ │ ├── drawable-xxhdpi │ │ ├── ic_action_refresh.png │ │ └── ic_launcher.png │ │ ├── layout │ │ └── activity_main.xml │ │ ├── menu │ │ └── options_menu.xml │ │ ├── values-sw600dp │ │ └── dimens.xml │ │ ├── values-sw720dp-land │ │ └── dimens.xml │ │ ├── values-v11 │ │ └── styles.xml │ │ ├── values-v14 │ │ └── styles.xml │ │ └── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | target/ 15 | tmp/ 16 | 17 | # Local configuration file (sdk path, etc) 18 | local.properties 19 | lint.xml 20 | 21 | 22 | # Eclipse project files 23 | .classpath 24 | .project 25 | .metadata/ 26 | .settings/ 27 | 28 | # Android Studio project files 29 | .idea/ 30 | modules.xml 31 | workspace.xml 32 | *.iml 33 | out/ 34 | .gradle 35 | build/ 36 | 37 | # Mac OS file 38 | .DS_Store 39 | 40 | # Windows File 41 | .thumb 42 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | 4 | Version 1.3 *(2015-05-29)* 5 | ---------------------------- 6 | 7 | * Merged: Add addMoreItems(int, List) to the PagingBaseAdapter. 8 | 9 | Version 1.2 *(2014-12-28)* 10 | ---------------------------- 11 | 12 | * Merged: PagingListView can now reload if requested. Before, after clearing the list, setting hasMoreItems to true had no 13 | effect on reloading. This removes the item count check and re-adds the 14 | footer view if hasMoreItems is set to true. 15 | 16 | Version 1.1 *(2014-05-13)* 17 | ---------------------------- 18 | 19 | * Merged: Reserve the setOnScrollListener() method for PagingListView. 20 | 21 | 22 | Version 1.0.0 *(2014-04-15)* 23 | ---------------------------- 24 | 25 | Initial release. 26 | 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 13 | owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities 16 | that control, are controlled by, or are under common control with that entity. 17 | For the purposes of this definition, "control" means (i) the power, direct or 18 | indirect, to cause the direction or management of such entity, whether by 19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, including 26 | but not limited to software source code, documentation source, and configuration 27 | files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object code, 31 | generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, made 34 | available under the License, as indicated by a copyright notice that is included 35 | in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that 38 | is based on (or derived from) the Work and for which the editorial revisions, 39 | annotations, elaborations, or other modifications represent, as a whole, an 40 | original work of authorship. For the purposes of this License, Derivative Works 41 | shall not include works that remain separable from, or merely link (or bind by 42 | name) to the interfaces of, the Work and Derivative Works thereof. 43 | 44 | "Contribution" shall mean any work of authorship, including the original version 45 | of the Work and any modifications or additions to that Work or Derivative Works 46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 47 | by the copyright owner or by an individual or Legal Entity authorized to submit 48 | on behalf of the copyright owner. For the purposes of this definition, 49 | "submitted" means any form of electronic, verbal, or written communication sent 50 | to the Licensor or its representatives, including but not limited to 51 | communication on electronic mailing lists, source code control systems, and 52 | issue tracking systems that are managed by, or on behalf of, the Licensor for 53 | the purpose of discussing and improving the Work, but excluding communication 54 | that is conspicuously marked or otherwise designated in writing by the copyright 55 | owner as "Not a Contribution." 56 | 57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 58 | of whom a Contribution has been received by Licensor and subsequently 59 | incorporated within the Work. 60 | 61 | 2. Grant of Copyright License. 62 | 63 | Subject to the terms and conditions of this License, each Contributor hereby 64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 65 | irrevocable copyright license to reproduce, prepare Derivative Works of, 66 | publicly display, publicly perform, sublicense, and distribute the Work and such 67 | Derivative Works in Source or Object form. 68 | 69 | 3. Grant of Patent License. 70 | 71 | Subject to the terms and conditions of this License, each Contributor hereby 72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 73 | irrevocable (except as stated in this section) patent license to make, have 74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 75 | such license applies only to those patent claims licensable by such Contributor 76 | that are necessarily infringed by their Contribution(s) alone or by combination 77 | of their Contribution(s) with the Work to which such Contribution(s) was 78 | submitted. If You institute patent litigation against any entity (including a 79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 80 | Contribution incorporated within the Work constitutes direct or contributory 81 | patent infringement, then any patent licenses granted to You under this License 82 | for that Work shall terminate as of the date such litigation is filed. 83 | 84 | 4. Redistribution. 85 | 86 | You may reproduce and distribute copies of the Work or Derivative Works thereof 87 | in any medium, with or without modifications, and in Source or Object form, 88 | provided that You meet the following conditions: 89 | 90 | You must give any other recipients of the Work or Derivative Works a copy of 91 | this License; and 92 | You must cause any modified files to carry prominent notices stating that You 93 | changed the files; and 94 | You must retain, in the Source form of any Derivative Works that You distribute, 95 | all copyright, patent, trademark, and attribution notices from the Source form 96 | of the Work, excluding those notices that do not pertain to any part of the 97 | Derivative Works; and 98 | If the Work includes a "NOTICE" text file as part of its distribution, then any 99 | Derivative Works that You distribute must include a readable copy of the 100 | attribution notices contained within such NOTICE file, excluding those notices 101 | that do not pertain to any part of the Derivative Works, in at least one of the 102 | following places: within a NOTICE text file distributed as part of the 103 | Derivative Works; within the Source form or documentation, if provided along 104 | with the Derivative Works; or, within a display generated by the Derivative 105 | Works, if and wherever such third-party notices normally appear. The contents of 106 | the NOTICE file are for informational purposes only and do not modify the 107 | License. You may add Your own attribution notices within Derivative Works that 108 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 109 | provided that such additional attribution notices cannot be construed as 110 | modifying the License. 111 | You may add Your own copyright statement to Your modifications and may provide 112 | additional or different license terms and conditions for use, reproduction, or 113 | distribution of Your modifications, or for any such Derivative Works as a whole, 114 | provided Your use, reproduction, and distribution of the Work otherwise complies 115 | with the conditions stated in this License. 116 | 117 | 5. Submission of Contributions. 118 | 119 | Unless You explicitly state otherwise, any Contribution intentionally submitted 120 | for inclusion in the Work by You to the Licensor shall be under the terms and 121 | conditions of this License, without any additional terms or conditions. 122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 123 | any separate license agreement you may have executed with Licensor regarding 124 | such Contributions. 125 | 126 | 6. Trademarks. 127 | 128 | This License does not grant permission to use the trade names, trademarks, 129 | service marks, or product names of the Licensor, except as required for 130 | reasonable and customary use in describing the origin of the Work and 131 | reproducing the content of the NOTICE file. 132 | 133 | 7. Disclaimer of Warranty. 134 | 135 | Unless required by applicable law or agreed to in writing, Licensor provides the 136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, 137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 138 | including, without limitation, any warranties or conditions of TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 140 | solely responsible for determining the appropriateness of using or 141 | redistributing the Work and assume any risks associated with Your exercise of 142 | permissions under this License. 143 | 144 | 8. Limitation of Liability. 145 | 146 | In no event and under no legal theory, whether in tort (including negligence), 147 | contract, or otherwise, unless required by applicable law (such as deliberate 148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 149 | liable to You for damages, including any direct, indirect, special, incidental, 150 | or consequential damages of any character arising as a result of this License or 151 | out of the use or inability to use the Work (including but not limited to 152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 153 | any and all other commercial damages or losses), even if such Contributor has 154 | been advised of the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. 157 | 158 | While redistributing the Work or Derivative Works thereof, You may choose to 159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 160 | other liability obligations and/or rights consistent with this License. However, 161 | in accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if You 163 | agree to indemnify, defend, and hold each Contributor harmless for any liability 164 | incurred by, or claims asserted against, such Contributor by reason of your 165 | accepting any such warranty or additional liability. 166 | 167 | END OF TERMS AND CONDITIONS 168 | 169 | APPENDIX: How to apply the Apache License to your work 170 | 171 | To apply the Apache License to your work, attach the following boilerplate 172 | notice, with the fields enclosed by brackets "[]" replaced with your own 173 | identifying information. (Don't include the brackets!) The text should be 174 | enclosed in the appropriate comment syntax for the file format. We also 175 | recommend that a file or class name and description of purpose be included on 176 | the same "printed page" as the copyright notice for easier identification within 177 | third-party archives. 178 | 179 | Copyright [yyyy] [name of copyright owner] 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListView/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'maven' 3 | 4 | android { 5 | compileSdkVersion 22 6 | buildToolsVersion "22.0.1" 7 | 8 | defaultConfig { 9 | minSdkVersion 9 10 | targetSdkVersion 22 11 | versionCode 1 12 | versionName '1.3' 13 | } 14 | } 15 | 16 | //group = 'com.paginglistview' 17 | //archivesBaseName = 'paging-listview' 18 | //version = '1.0' 19 | // 20 | //uploadArchives { 21 | // repositories { 22 | // mavenDeployer { 23 | // repository(url: uri("../paginglistview_aar")) 24 | // } 25 | // } 26 | //} 27 | 28 | apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle' 29 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListView/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Settings specified in this file will override any Gradle settings 5 | # configured through the IDE. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | POM_NAME=PagingListView Library 20 | POM_ARTIFACT_ID=paginglistview 21 | POM_PACKAGING=aar -------------------------------------------------------------------------------- /PagingListViewProject/PagingListView/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListView/src/main/java/com/paging/listview/LoadingView.java: -------------------------------------------------------------------------------- 1 | package com.paging.listview; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.LinearLayout; 6 | 7 | 8 | public class LoadingView extends LinearLayout { 9 | 10 | public LoadingView(Context context) { 11 | super(context); 12 | init(); 13 | } 14 | 15 | public LoadingView(Context context, AttributeSet attrs) { 16 | super(context, attrs); 17 | init(); 18 | } 19 | 20 | private void init() { 21 | inflate(getContext(), R.layout.loading_view, this); 22 | } 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListView/src/main/java/com/paging/listview/PagingBaseAdapter.java: -------------------------------------------------------------------------------- 1 | package com.paging.listview; 2 | 3 | import android.widget.BaseAdapter; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | 9 | public abstract class PagingBaseAdapter extends BaseAdapter { 10 | 11 | protected List items; 12 | 13 | public PagingBaseAdapter() { 14 | this.items = new ArrayList(); 15 | } 16 | 17 | public PagingBaseAdapter(List items) { 18 | this.items = items; 19 | } 20 | 21 | public void addMoreItems(List newItems) { 22 | this.items.addAll(newItems); 23 | notifyDataSetChanged(); 24 | } 25 | 26 | public void addMoreItems(int location, List newItems) { 27 | this.items.addAll(location, newItems); 28 | notifyDataSetChanged(); 29 | } 30 | 31 | public void removeAllItems() { 32 | this.items.clear(); 33 | notifyDataSetChanged(); 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListView/src/main/java/com/paging/listview/PagingListView.java: -------------------------------------------------------------------------------- 1 | package com.paging.listview; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.AbsListView; 6 | import android.widget.HeaderViewListAdapter; 7 | import android.widget.ListAdapter; 8 | import android.widget.ListView; 9 | 10 | import java.util.List; 11 | 12 | 13 | public class PagingListView extends ListView { 14 | 15 | private boolean isLoading; 16 | private boolean hasMoreItems; 17 | private Pagingable pagingableListener; 18 | private LoadingView loadingView; 19 | private OnScrollListener onScrollListener; 20 | 21 | public PagingListView(Context context) { 22 | super(context); 23 | init(); 24 | } 25 | 26 | public PagingListView(Context context, AttributeSet attrs) { 27 | super(context, attrs); 28 | init(); 29 | } 30 | 31 | public PagingListView(Context context, AttributeSet attrs, int defStyle) { 32 | super(context, attrs, defStyle); 33 | init(); 34 | } 35 | 36 | public boolean isLoading() { 37 | return this.isLoading; 38 | } 39 | 40 | public void setIsLoading(boolean isLoading) { 41 | this.isLoading = isLoading; 42 | } 43 | 44 | public void setPagingableListener(Pagingable pagingableListener) { 45 | this.pagingableListener = pagingableListener; 46 | } 47 | 48 | public void setHasMoreItems(boolean hasMoreItems) { 49 | this.hasMoreItems = hasMoreItems; 50 | if (!this.hasMoreItems) { 51 | removeFooterView(loadingView); 52 | } else if (findViewById(R.id.loading_view) == null) { 53 | addFooterView(loadingView); 54 | ListAdapter adapter = ((HeaderViewListAdapter) getAdapter()).getWrappedAdapter(); 55 | setAdapter(adapter); 56 | } 57 | } 58 | 59 | public boolean hasMoreItems() { 60 | return this.hasMoreItems; 61 | } 62 | 63 | public void onFinishLoading(boolean hasMoreItems, List newItems) { 64 | setHasMoreItems(hasMoreItems); 65 | setIsLoading(false); 66 | if (newItems != null && newItems.size() > 0) { 67 | ListAdapter adapter = ((HeaderViewListAdapter) getAdapter()).getWrappedAdapter(); 68 | if (adapter instanceof PagingBaseAdapter) { 69 | ((PagingBaseAdapter) adapter).addMoreItems(newItems); 70 | } 71 | } 72 | } 73 | 74 | private void init() { 75 | isLoading = false; 76 | loadingView = new LoadingView(getContext()); 77 | addFooterView(loadingView); 78 | super.setOnScrollListener(new OnScrollListener() { 79 | @Override 80 | public void onScrollStateChanged(AbsListView view, int scrollState) { 81 | //Dispatch to child OnScrollListener 82 | if (onScrollListener != null) { 83 | onScrollListener.onScrollStateChanged(view, scrollState); 84 | } 85 | } 86 | 87 | @Override 88 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 89 | 90 | //Dispatch to child OnScrollListener 91 | if (onScrollListener != null) { 92 | onScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount); 93 | } 94 | 95 | int lastVisibleItem = firstVisibleItem + visibleItemCount; 96 | if (!isLoading && hasMoreItems && (lastVisibleItem == totalItemCount)) { 97 | if (pagingableListener != null) { 98 | isLoading = true; 99 | pagingableListener.onLoadMoreItems(); 100 | } 101 | 102 | } 103 | } 104 | }); 105 | } 106 | 107 | @Override 108 | public void setOnScrollListener(OnScrollListener listener) { 109 | onScrollListener = listener; 110 | } 111 | 112 | public interface Pagingable { 113 | void onLoadMoreItems(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListView/src/main/res/layout/loading_view.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 16 | 17 | 22 | 23 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListView/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 50dp 4 | 10dp 5 | 5dp 6 | 7 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListView/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Loading… 4 | 5 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | dependencies { 4 | compile files('libs/android-support-v4.jar') 5 | compile project(':PagingListView') 6 | } 7 | 8 | android { 9 | compileSdkVersion 22 10 | buildToolsVersion "22.0.1" 11 | 12 | defaultConfig { 13 | minSdkVersion 9 14 | targetSdkVersion 22 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasjafelle/PagingListView/222ba2a63f54edf9820166e4bde3ad72494a9b25/PagingListViewProject/PagingListViewSample/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/java/com/paging/listview/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.paging.listview.sample; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.view.Menu; 6 | import android.view.MenuItem; 7 | 8 | import com.paging.listview.PagingListView; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public class MainActivity extends Activity { 14 | 15 | private PagingListView listView; 16 | private MyPagingAdaper adapter; 17 | 18 | private List firstList; 19 | private List secondList; 20 | private List thirdList; 21 | 22 | private int pager = 0; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_main); 28 | 29 | listView = (PagingListView) findViewById(R.id.paging_list_view); 30 | adapter = new MyPagingAdaper(); 31 | 32 | initData(); 33 | 34 | listView.setAdapter(adapter); 35 | listView.setHasMoreItems(true); 36 | listView.setPagingableListener(new PagingListView.Pagingable() { 37 | @Override 38 | public void onLoadMoreItems() { 39 | if (pager < 3) { 40 | new CountryAsyncTask().execute(); 41 | } else { 42 | listView.onFinishLoading(false, null); 43 | } 44 | } 45 | }); 46 | } 47 | 48 | private void clearData() { 49 | pager = 0; 50 | adapter.removeAllItems(); 51 | listView.setHasMoreItems(true); 52 | } 53 | 54 | @Override 55 | public boolean onCreateOptionsMenu(Menu menu) { 56 | getMenuInflater().inflate(R.menu.options_menu, menu); 57 | return true; 58 | } 59 | 60 | 61 | @Override 62 | public boolean onOptionsItemSelected(MenuItem item) { 63 | switch (item.getItemId()) { 64 | case R.id.refresh: 65 | clearData(); 66 | return true; 67 | default: 68 | return super.onOptionsItemSelected(item); 69 | } 70 | } 71 | 72 | private void initData() { 73 | firstList = new ArrayList(); 74 | firstList.add("Afghanistan"); 75 | firstList.add("Albania"); 76 | firstList.add("Algeria"); 77 | firstList.add("Andorra"); 78 | firstList.add("Angola"); 79 | firstList.add("Antigua and Barbuda"); 80 | firstList.add("Argentina"); 81 | firstList.add("Armenia"); 82 | firstList.add("Aruba"); 83 | firstList.add("Australia"); 84 | firstList.add("Austria"); 85 | firstList.add("Azerbaijan"); 86 | 87 | secondList = new ArrayList(); 88 | secondList.add("Bahamas, The"); 89 | secondList.add("Bahrain"); 90 | secondList.add("Bangladesh"); 91 | secondList.add("Barbados"); 92 | secondList.add("Belarus"); 93 | secondList.add("Belgium"); 94 | secondList.add("Belize"); 95 | secondList.add("Benin"); 96 | secondList.add("Bhutan"); 97 | secondList.add("Bolivia"); 98 | secondList.add("Bosnia and Herzegovina"); 99 | secondList.add("Botswana"); 100 | secondList.add("Brazil"); 101 | secondList.add("Brunei"); 102 | secondList.add("Bulgaria"); 103 | secondList.add("Burkina Faso"); 104 | secondList.add("Burma"); 105 | secondList.add("Burundi"); 106 | 107 | thirdList = new ArrayList(); 108 | thirdList.add("Denmark"); 109 | thirdList.add("Djibouti"); 110 | thirdList.add("Dominica"); 111 | thirdList.add("Dominican Republic"); 112 | } 113 | 114 | private class CountryAsyncTask extends SafeAsyncTask> { 115 | 116 | @Override 117 | public List call() throws Exception { 118 | List result = null; 119 | switch (pager) { 120 | case 0: 121 | result = firstList; 122 | break; 123 | case 1: 124 | result = secondList; 125 | break; 126 | case 2: 127 | result = thirdList; 128 | break; 129 | } 130 | Thread.sleep(3000); 131 | return result; 132 | } 133 | 134 | @Override 135 | protected void onSuccess(List newItems) throws Exception { 136 | super.onSuccess(newItems); 137 | pager++; 138 | listView.onFinishLoading(true, newItems); 139 | } 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/java/com/paging/listview/sample/MyPagingAdaper.java: -------------------------------------------------------------------------------- 1 | package com.paging.listview.sample; 2 | 3 | import android.R; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import com.paging.listview.PagingBaseAdapter; 10 | 11 | 12 | public class MyPagingAdaper extends PagingBaseAdapter { 13 | 14 | @Override 15 | public int getCount() { 16 | return items.size(); 17 | } 18 | 19 | @Override 20 | public String getItem(int position) { 21 | return items.get(position); 22 | } 23 | 24 | @Override 25 | public long getItemId(int position) { 26 | return position; 27 | } 28 | 29 | @Override 30 | public View getView(int position, View convertView, ViewGroup parent) { 31 | TextView textView; 32 | String text = getItem(position); 33 | 34 | if (convertView != null) { 35 | textView = (TextView) convertView; 36 | } else { 37 | textView = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.simple_list_item_1, null); 38 | } 39 | textView.setText(text); 40 | return textView; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/java/com/paging/listview/sample/SafeAsyncTask.java: -------------------------------------------------------------------------------- 1 | package com.paging.listview.sample; 2 | 3 | import android.os.Handler; 4 | import android.os.Looper; 5 | import android.util.Log; 6 | 7 | import java.io.InterruptedIOException; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | import java.util.concurrent.Callable; 11 | import java.util.concurrent.CountDownLatch; 12 | import java.util.concurrent.Executor; 13 | import java.util.concurrent.Executors; 14 | import java.util.concurrent.FutureTask; 15 | 16 | 17 | /** 18 | * A class similar but unrelated to android's {@link android.os.AsyncTask}. 19 | *

20 | * Unlike AsyncTask, this class properly propagates exceptions. 21 | *

22 | * If you're familiar with AsyncTask and are looking for {@link android.os.AsyncTask#doInBackground(Object[])}, 23 | * we've named it {@link #call()} here to conform with java 1.5's {@link java.util.concurrent.Callable} interface. 24 | *

25 | * Current limitations: does not yet handle progress, although it shouldn't be 26 | * hard to add. 27 | *

28 | * If using your own executor, you must call future() to get a runnable you can execute. 29 | * 30 | * @param 31 | */ 32 | public abstract class SafeAsyncTask implements Callable { 33 | public static final int DEFAULT_POOL_SIZE = 25; 34 | protected static final Executor DEFAULT_EXECUTOR = Executors.newFixedThreadPool(DEFAULT_POOL_SIZE); 35 | 36 | protected Handler handler; 37 | protected Executor executor; 38 | protected StackTraceElement[] launchLocation; 39 | protected FutureTask future; 40 | 41 | 42 | /** 43 | * Sets executor to Executors.newFixedThreadPool(DEFAULT_POOL_SIZE) and 44 | * Handler to new Handler() 45 | */ 46 | public SafeAsyncTask() { 47 | this.executor = DEFAULT_EXECUTOR; 48 | } 49 | 50 | /** 51 | * Sets executor to Executors.newFixedThreadPool(DEFAULT_POOL_SIZE) 52 | */ 53 | public SafeAsyncTask(Handler handler) { 54 | this.handler = handler; 55 | this.executor = DEFAULT_EXECUTOR; 56 | } 57 | 58 | /** 59 | * Sets Handler to new Handler() 60 | */ 61 | public SafeAsyncTask(Executor executor) { 62 | this.executor = executor; 63 | } 64 | 65 | public SafeAsyncTask(Handler handler, Executor executor) { 66 | this.handler = handler; 67 | this.executor = executor; 68 | } 69 | 70 | 71 | public FutureTask future() { 72 | future = new FutureTask(newTask()); 73 | return future; 74 | } 75 | 76 | public SafeAsyncTask executor(Executor executor) { 77 | this.executor = executor; 78 | return this; 79 | } 80 | 81 | public Executor executor() { 82 | return executor; 83 | } 84 | 85 | public SafeAsyncTask handler(Handler handler) { 86 | this.handler = handler; 87 | return this; 88 | } 89 | 90 | public Handler handler() { 91 | return handler; 92 | } 93 | 94 | public void execute() { 95 | execute(Thread.currentThread().getStackTrace()); 96 | } 97 | 98 | protected void execute(StackTraceElement[] launchLocation) { 99 | this.launchLocation = launchLocation; 100 | executor.execute(future()); 101 | } 102 | 103 | public boolean cancel(boolean mayInterruptIfRunning) { 104 | if (future == null) throw new UnsupportedOperationException("You cannot cancel this task before calling future()"); 105 | 106 | return future.cancel(mayInterruptIfRunning); 107 | } 108 | 109 | 110 | /** 111 | * @throws Exception, captured on passed to onException() if present. 112 | */ 113 | protected void onPreExecute() throws Exception { 114 | } 115 | 116 | /** 117 | * @param t the result of {@link #call()} 118 | * @throws Exception, captured on passed to onException() if present. 119 | */ 120 | @SuppressWarnings({"UnusedDeclaration"}) 121 | protected void onSuccess(ResultT t) throws Exception { 122 | } 123 | 124 | /** 125 | * Called when the thread has been interrupted, likely because 126 | * the task was canceled. 127 | *

128 | * By default, calls {@link #onException(Exception)}, but this method 129 | * may be overridden to handle interruptions differently than other 130 | * exceptions. 131 | * 132 | * @param e an InterruptedException or InterruptedIOException 133 | */ 134 | protected void onInterrupted(Exception e) { 135 | onException(e); 136 | } 137 | 138 | /** 139 | * Logs the exception as an Error by default, but this method may 140 | * be overridden by subclasses. 141 | * 142 | * @param e the exception thrown from {@link #onPreExecute()}, {@link #call()}, or {@link #onSuccess(Object)} 143 | * @throws RuntimeException, ignored 144 | */ 145 | protected void onException(Exception e) throws RuntimeException { 146 | onThrowable(e); 147 | } 148 | 149 | protected void onThrowable(Throwable t) throws RuntimeException { 150 | Log.e("roboguice", "Throwable caught during background processing", t); 151 | } 152 | 153 | /** 154 | * @throws RuntimeException, ignored 155 | */ 156 | protected void onFinally() throws RuntimeException { 157 | } 158 | 159 | 160 | protected Task newTask() { 161 | return new Task(this); 162 | } 163 | 164 | 165 | public static class Task implements Callable { 166 | protected SafeAsyncTask parent; 167 | protected Handler handler; 168 | 169 | public Task(SafeAsyncTask parent) { 170 | this.parent = parent; 171 | this.handler = parent.handler != null ? parent.handler : new Handler(Looper.getMainLooper()); 172 | } 173 | 174 | public Void call() throws Exception { 175 | try { 176 | doPreExecute(); 177 | doSuccess(doCall()); 178 | 179 | } catch (final Exception e) { 180 | try { 181 | doException(e); 182 | } catch (Exception f) { 183 | // logged but ignored 184 | Log.e("BACKGROUND_TASK", "Exception in", f); 185 | } 186 | 187 | } catch (final Throwable t) { 188 | try { 189 | doThrowable(t); 190 | } catch (Exception f) { 191 | // logged but ignored 192 | Log.e("BACKGROUND_TASK", "Exception in", f); 193 | } 194 | } finally { 195 | doFinally(); 196 | } 197 | 198 | return null; 199 | } 200 | 201 | protected void doPreExecute() throws Exception { 202 | postToUiThreadAndWait(new Callable() { 203 | public Object call() throws Exception { 204 | parent.onPreExecute(); 205 | return null; 206 | } 207 | }); 208 | } 209 | 210 | protected ResultT doCall() throws Exception { 211 | return parent.call(); 212 | } 213 | 214 | protected void doSuccess(final ResultT r) throws Exception { 215 | postToUiThreadAndWait(new Callable() { 216 | public Object call() throws Exception { 217 | parent.onSuccess(r); 218 | return null; 219 | } 220 | }); 221 | } 222 | 223 | protected void doException(final Exception e) throws Exception { 224 | if (parent.launchLocation != null) { 225 | final ArrayList stack = new ArrayList(Arrays.asList(e.getStackTrace())); 226 | stack.addAll(Arrays.asList(parent.launchLocation)); 227 | e.setStackTrace(stack.toArray(new StackTraceElement[stack.size()])); 228 | } 229 | postToUiThreadAndWait(new Callable() { 230 | public Object call() throws Exception { 231 | if (e instanceof InterruptedException || e instanceof InterruptedIOException) parent.onInterrupted(e); 232 | else parent.onException(e); 233 | return null; 234 | } 235 | }); 236 | } 237 | 238 | protected void doThrowable(final Throwable e) throws Exception { 239 | if (parent.launchLocation != null) { 240 | final ArrayList stack = new ArrayList(Arrays.asList(e.getStackTrace())); 241 | stack.addAll(Arrays.asList(parent.launchLocation)); 242 | e.setStackTrace(stack.toArray(new StackTraceElement[stack.size()])); 243 | } 244 | postToUiThreadAndWait(new Callable() { 245 | public Object call() throws Exception { 246 | parent.onThrowable(e); 247 | return null; 248 | } 249 | }); 250 | } 251 | 252 | protected void doFinally() throws Exception { 253 | postToUiThreadAndWait(new Callable() { 254 | public Object call() throws Exception { 255 | parent.onFinally(); 256 | return null; 257 | } 258 | }); 259 | } 260 | 261 | 262 | /** 263 | * Posts the specified runnable to the UI thread using a handler, 264 | * and waits for operation to finish. If there's an exception, 265 | * it captures it and rethrows it. 266 | * 267 | * @param c the callable to post 268 | * @throws Exception on error 269 | */ 270 | protected void postToUiThreadAndWait(final Callable c) throws Exception { 271 | final CountDownLatch latch = new CountDownLatch(1); 272 | final Exception[] exceptions = new Exception[1]; 273 | 274 | // Execute onSuccess in the UI thread, but wait 275 | // for it to complete. 276 | // If it throws an exception, capture that exception 277 | // and rethrow it later. 278 | handler.post(new Runnable() { 279 | public void run() { 280 | try { 281 | c.call(); 282 | } catch (Exception e) { 283 | exceptions[0] = e; 284 | } finally { 285 | latch.countDown(); 286 | } 287 | } 288 | }); 289 | 290 | // Wait for onSuccess to finish 291 | latch.await(); 292 | 293 | if (exceptions[0] != null) throw exceptions[0]; 294 | 295 | } 296 | 297 | } 298 | 299 | } 300 | 301 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/drawable-hdpi/ic_action_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasjafelle/PagingListView/222ba2a63f54edf9820166e4bde3ad72494a9b25/PagingListViewProject/PagingListViewSample/src/main/res/drawable-hdpi/ic_action_refresh.png -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasjafelle/PagingListView/222ba2a63f54edf9820166e4bde3ad72494a9b25/PagingListViewProject/PagingListViewSample/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/drawable-mdpi/ic_action_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasjafelle/PagingListView/222ba2a63f54edf9820166e4bde3ad72494a9b25/PagingListViewProject/PagingListViewSample/src/main/res/drawable-mdpi/ic_action_refresh.png -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasjafelle/PagingListView/222ba2a63f54edf9820166e4bde3ad72494a9b25/PagingListViewProject/PagingListViewSample/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/drawable-xhdpi/ic_action_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasjafelle/PagingListView/222ba2a63f54edf9820166e4bde3ad72494a9b25/PagingListViewProject/PagingListViewSample/src/main/res/drawable-xhdpi/ic_action_refresh.png -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasjafelle/PagingListView/222ba2a63f54edf9820166e4bde3ad72494a9b25/PagingListViewProject/PagingListViewSample/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/drawable-xxhdpi/ic_action_refresh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasjafelle/PagingListView/222ba2a63f54edf9820166e4bde3ad72494a9b25/PagingListViewProject/PagingListViewSample/src/main/res/drawable-xxhdpi/ic_action_refresh.png -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasjafelle/PagingListView/222ba2a63f54edf9820166e4bde3ad72494a9b25/PagingListViewProject/PagingListViewSample/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/menu/options_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 128dp 5 | 6 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | PagingListView Sample 5 | Refresh 6 | Loading countries… 7 | 8 | -------------------------------------------------------------------------------- /PagingListViewProject/PagingListViewSample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /PagingListViewProject/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | mavenCentral() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:1.2.3' 9 | } 10 | } 11 | 12 | allprojects { 13 | repositories { 14 | mavenCentral() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /PagingListViewProject/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Settings specified in this file will override any Gradle settings 5 | # configured through the IDE. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | VERSION_NAME=1.3 20 | VERSION_CODE=1 21 | GROUP=com.github.nicolasjafelle 22 | 23 | POM_DESCRIPTION=PagingListView is a ListView with the ability to add more items on it when reaches the end of the list. 24 | POM_URL=https://github.com/nicolasjafelle/PagingListView 25 | POM_SCM_URL=https://github.com/nicolasjafelle/PagingListView 26 | POM_SCM_CONNECTION=scm:git@github.com:nicolasjafelle/PagingListView.git 27 | POM_SCM_DEV_CONNECTION=scm:git@github.com:nicolasjafelle/PagingListView.git 28 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 29 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 30 | POM_LICENCE_DIST=repo 31 | POM_DEVELOPER_ID=nicolasjafelle 32 | POM_DEVELOPER_NAME=Nicolas Jafelle 33 | -------------------------------------------------------------------------------- /PagingListViewProject/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nicolasjafelle/PagingListView/222ba2a63f54edf9820166e4bde3ad72494a9b25/PagingListViewProject/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /PagingListViewProject/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Dec 24 22:04:58 CET 2014 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /PagingListViewProject/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /PagingListViewProject/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /PagingListViewProject/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':PagingListView', ':PagingListViewSample' 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PagingListView 2 | ============== 3 | 4 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-PagingListView-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/251) 5 | 6 | PagingListView has the ability to add more items on it like Gmail does. Basically is a ListView with the ability to add more items on it when reaches the end of the list.
7 | While "pull to refresh" pattern works at the top of the List and show the latest added items, the PagingListView works at the bottom of the List and shows the first added items. 8 | 9 | Instructions - Maven Central 10 | ============ 11 | 12 | 1. Add this library in your build.gradle: 13 | 14 | ```groovy 15 | dependencies { 16 | compile 'com.github.nicolasjafelle:paginglistview:1.2' 17 | } 18 | ``` 19 | 20 | Instructions - Library Module 21 | ============ 22 | 23 | 1. Clone the git repo 24 | 2. Import the "PagingListView" module into your Android-gradle project. 25 | 3. Add "PagingListView" module in your settings.gradle 26 | 4. DONE 27 | 28 | 29 | 30 | How to Use it 31 | ================ 32 | 33 | Simple create your PagingAdapter and add it to com.paging.listview.PagingListView.
34 | You have to implements the new Pagingable interface and its onLoadMoreItems() method. For example:
35 | ``` java 36 | listView.setHasMoreItems(true); 37 | listView.setPagingableListener(new PagingListView.Pagingable() { 38 | @Override 39 | public void onLoadMoreItems() { 40 | if (pager < 3) { 41 | new CountryAsyncTask(false).execute(); 42 | } else { 43 | listView.onFinishLoading(false, null); 44 | } 45 | } 46 | }); 47 | ``` 48 | 49 | Finally you can use the onFinishLoading(boolean hasMoreItems, List newItems) method to update the list. 50 | ``` java 51 | listView.onFinishLoading(true, newItems); 52 | ``` 53 | Also remember to use this package in your layout files: 54 | 55 | ```xml 56 | 60 | ``` 61 | 62 | Developed By 63 | ================ 64 | 65 | * Nicolas Jafelle - 66 | 67 | 68 | License 69 | ================ 70 | 71 | Copyright 2013 Nicolas Jafelle 72 | 73 | Licensed under the Apache License, Version 2.0 (the "License"); 74 | you may not use this file except in compliance with the License. 75 | You may obtain a copy of the License at 76 | 77 | http://www.apache.org/licenses/LICENSE-2.0 78 | 79 | Unless required by applicable law or agreed to in writing, software 80 | distributed under the License is distributed on an "AS IS" BASIS, 81 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 82 | See the License for the specific language governing permissions and 83 | limitations under the License. 84 | --------------------------------------------------------------------------------