├── LICENSE ├── PullToUpdateLibrary ├── AndroidManifest.xml ├── project.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── layout │ │ ├── footer.xml │ │ └── header.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── values │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── pt │ └── fjss │ └── pulltoupdatelibrary │ ├── IonRefreshListener.java │ └── PullToUpdateListView.java └── README.md /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, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /PullToUpdateLibrary/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 9 | 10 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /PullToUpdateLibrary/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | android.library=true 16 | -------------------------------------------------------------------------------- /PullToUpdateLibrary/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fredericojssilva/PullToUpdate-ListView/b1525956dac4219882cd3297c2a95937dab0b0de/PullToUpdateLibrary/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /PullToUpdateLibrary/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fredericojssilva/PullToUpdate-ListView/b1525956dac4219882cd3297c2a95937dab0b0de/PullToUpdateLibrary/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /PullToUpdateLibrary/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fredericojssilva/PullToUpdate-ListView/b1525956dac4219882cd3297c2a95937dab0b0de/PullToUpdateLibrary/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /PullToUpdateLibrary/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fredericojssilva/PullToUpdate-ListView/b1525956dac4219882cd3297c2a95937dab0b0de/PullToUpdateLibrary/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /PullToUpdateLibrary/res/layout/footer.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 19 | 20 | 28 | 29 | -------------------------------------------------------------------------------- /PullToUpdateLibrary/res/layout/header.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 20 | 21 | 29 | 30 | 39 | 40 | 49 | 50 | 51 | 52 | 53 | 54 | 74 | 75 | -------------------------------------------------------------------------------- /PullToUpdateLibrary/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /PullToUpdateLibrary/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /PullToUpdateLibrary/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PullToUpdateLibrary 4 | 5 | 6 | -------------------------------------------------------------------------------- /PullToUpdateLibrary/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /PullToUpdateLibrary/src/pt/fjss/pulltoupdatelibrary/IonRefreshListener.java: -------------------------------------------------------------------------------- 1 | package pt.fjss.pulltoupdatelibrary; 2 | 3 | 4 | /** 5 | * @author frederico 6 | * 7 | */ 8 | public interface IonRefreshListener { 9 | 10 | public void onRefreshUp(); 11 | public void onRefeshDown(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /PullToUpdateLibrary/src/pt/fjss/pulltoupdatelibrary/PullToUpdateListView.java: -------------------------------------------------------------------------------- 1 | package pt.fjss.pulltoupdatelibrary; 2 | 3 | 4 | 5 | 6 | import android.content.Context; 7 | 8 | import android.graphics.drawable.Drawable; 9 | import android.util.AttributeSet; 10 | import android.util.Log; 11 | import android.view.LayoutInflater; 12 | import android.view.MotionEvent; 13 | import android.view.View; 14 | 15 | import android.view.animation.LinearInterpolator; 16 | import android.view.animation.RotateAnimation; 17 | import android.widget.AbsListView; 18 | import android.widget.ImageView; 19 | import android.widget.ListAdapter; 20 | import android.widget.ListView; 21 | import android.widget.AbsListView.OnScrollListener; 22 | import android.widget.ProgressBar; 23 | import android.widget.RelativeLayout; 24 | import android.widget.TextView; 25 | 26 | /** 27 | * @author frederico 28 | * 29 | */ 30 | 31 | public class PullToUpdateListView extends ListView implements OnScrollListener { 32 | private static final int DOING_NOTHING = 0; 33 | private static final int LOADING = 1; 34 | private static final int RELEASE = 2; 35 | 36 | private static String PULL_MESSAGE = "Pull to refresh."; 37 | private static String RELEASE_MESSAGE = "Release to refresh."; 38 | private static String LOADING_MESSAGE = "Loading..."; 39 | 40 | private int pullState; 41 | private int headerHeigh; 42 | private int footerHeigh; 43 | 44 | private float lastY; 45 | 46 | private int scrollState; 47 | 48 | private int headerFixedOriginalHeight; 49 | 50 | private IonRefreshListener refreshListener; 51 | 52 | private RelativeLayout mHeaderView; 53 | private LayoutInflater mInflater; 54 | private TextView headerMessage; 55 | private ImageView headerImage; 56 | private ProgressBar headerProgressBar; 57 | 58 | private RelativeLayout mFooterView; 59 | private TextView footerMessage; 60 | private ProgressBar footerProgressBar; 61 | 62 | private RotateAnimation mImageFlipDownAnimation, mImageFlipUpAnimation; 63 | private MODE mode; 64 | private CurrentState currentState; 65 | private boolean autoLoad; 66 | private int autoLoadPosition; 67 | private boolean isFooterLoading; 68 | private int releaseTrigger; 69 | 70 | public enum MODE { 71 | UP_ONLY, UP_AND_DOWN; 72 | } 73 | 74 | public enum CurrentState { 75 | LOADING_UP, LOADING_DOWN; 76 | } 77 | 78 | public PullToUpdateListView(Context context) { 79 | super(context); 80 | init(context); 81 | } 82 | 83 | public PullToUpdateListView(Context context, AttributeSet attrs, int defStyle) { 84 | super(context, attrs, defStyle); 85 | init(context); 86 | } 87 | 88 | public PullToUpdateListView(Context context, AttributeSet attrs) { 89 | super(context, attrs); 90 | init(context); 91 | } 92 | 93 | private void init(Context context) { 94 | // initial states 95 | pullState = DOING_NOTHING; 96 | mode = MODE.UP_AND_DOWN; 97 | isFooterLoading = false; 98 | /* 99 | * Header 100 | */ 101 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 102 | 103 | mHeaderView = (RelativeLayout) mInflater.inflate(R.layout.header, this, false); 104 | headerMessage = (TextView) mHeaderView.findViewById(R.id.headerMessage); 105 | headerImage = (ImageView) mHeaderView.findViewById(R.id.headerImage); 106 | headerProgressBar = (ProgressBar) mHeaderView.findViewById(R.id.headerProgressbar); 107 | headerImage.setVisibility(View.VISIBLE); 108 | headerProgressBar.setVisibility(View.INVISIBLE); 109 | 110 | headerHeigh = mHeaderView.getPaddingTop();// getLayoutParams().height; 111 | headerFixedOriginalHeight = 100;// mHeaderView.getHeight(); 112 | releaseTrigger = 2; 113 | 114 | /* 115 | * Footer 116 | */ 117 | mFooterView = (RelativeLayout) mInflater.inflate(R.layout.footer, this, false); 118 | footerMessage = (TextView) mFooterView.findViewById(R.id.footer_message); 119 | footerProgressBar = (ProgressBar) mFooterView.findViewById(R.id.footer_progressbar); 120 | 121 | addFooterView(mFooterView); 122 | footerHeigh = mFooterView.getPaddingBottom(); 123 | footerMessage.setVisibility(View.GONE); 124 | 125 | /* 126 | * Animation 127 | */ 128 | // Down 129 | mImageFlipDownAnimation = new RotateAnimation(0, -180, RotateAnimation.RELATIVE_TO_SELF, 0.5f, 130 | RotateAnimation.RELATIVE_TO_SELF, 0.5f); 131 | mImageFlipDownAnimation.setInterpolator(new LinearInterpolator()); 132 | mImageFlipDownAnimation.setDuration(250); 133 | mImageFlipDownAnimation.setFillAfter(true); 134 | // Up 135 | mImageFlipUpAnimation = new RotateAnimation(-180, 0, RotateAnimation.RELATIVE_TO_SELF, 0.5f, 136 | RotateAnimation.RELATIVE_TO_SELF, 0.5f); 137 | mImageFlipUpAnimation.setInterpolator(new LinearInterpolator()); 138 | mImageFlipUpAnimation.setDuration(250); 139 | mImageFlipUpAnimation.setFillAfter(true); 140 | /* 141 | * 142 | */ 143 | 144 | setVerticalFadingEdgeEnabled(false); 145 | setSmoothScrollbarEnabled(true); 146 | 147 | super.setOnScrollListener(this); 148 | 149 | Log.d("FRED", "init: " + (getHeight() + " - " + mFooterView.getBottom())); 150 | 151 | } 152 | 153 | @Override 154 | public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 155 | 156 | if (firstVisibleItem == 0 && pullState == DOING_NOTHING && scrollState == SCROLL_STATE_FLING 157 | && getHeaderViewsCount() == 1) { 158 | setSelection(0); 159 | 160 | try { 161 | removeHeaderView(mHeaderView); 162 | } catch (Exception e) { 163 | // TODO: handle exception 164 | } 165 | 166 | } 167 | 168 | if (mode == MODE.UP_AND_DOWN && autoLoad 169 | && (getLastVisiblePosition() >= getCount() - (1 + autoLoadPosition)) 170 | && (getCount() - (1 + autoLoadPosition) > getFirstVisiblePosition()) && !isFooterLoading) { 171 | isFooterLoading = true; 172 | refreshDown(); 173 | 174 | } 175 | } 176 | 177 | @Override 178 | public void onScrollStateChanged(AbsListView view, int scrollState) { 179 | this.scrollState = scrollState; 180 | 181 | } 182 | 183 | public void setOnRefreshListener(IonRefreshListener onRefreshListener) { 184 | refreshListener = onRefreshListener; 185 | Log.d("FRED", "setOnRefreshListener: " + (getHeight() + " - " + mFooterView.getBottom())); 186 | 187 | } 188 | 189 | @Override 190 | public boolean onTouchEvent(MotionEvent ev) { 191 | final int y = (int) ev.getY(); 192 | switch (ev.getAction()) { 193 | case MotionEvent.ACTION_MOVE: 194 | if ((getFirstVisiblePosition() == 0 || getFirstVisiblePosition() == 0) 195 | && (pullState == RELEASE || pullState == DOING_NOTHING)) { 196 | setHeaderTopPadding(ev); 197 | if (getFirstVisiblePosition() == 0 198 | && mHeaderView.getBottom() >= (headerFixedOriginalHeight * releaseTrigger)) { 199 | headerMessage.setText(RELEASE_MESSAGE); 200 | 201 | if (pullState != RELEASE) { 202 | headerImage.clearAnimation(); 203 | headerImage.startAnimation(mImageFlipDownAnimation); 204 | } 205 | 206 | pullState = RELEASE; 207 | 208 | } else { 209 | headerMessage.setText(PULL_MESSAGE); 210 | if (pullState != DOING_NOTHING) { 211 | headerImage.clearAnimation(); 212 | headerImage.startAnimation(mImageFlipUpAnimation); 213 | } 214 | pullState = DOING_NOTHING; 215 | } 216 | 217 | } 218 | Log.d("FRED", "lASTP: " + getLastVisiblePosition() + " - " + getCount()); 219 | if (!autoLoad && getLastVisiblePosition() == getCount() - 1) { 220 | setFooterBottomPadding(ev); 221 | 222 | } 223 | 224 | break; 225 | 226 | case MotionEvent.ACTION_UP: 227 | setVerticalScrollBarEnabled(true); 228 | if (getFirstVisiblePosition() == 0 229 | && mHeaderView.getBottom() >= (headerFixedOriginalHeight * releaseTrigger)) { 230 | Log.d("FRED", "LOADING"); 231 | pullState = LOADING; 232 | 233 | resetHeader(); 234 | setSelection(0); 235 | headerMessage.setText(LOADING_MESSAGE); 236 | refresh(); 237 | } else if (getFirstVisiblePosition() == 0 && pullState != LOADING && getHeaderViewsCount() == 1) { 238 | Log.d("FRED", "NHAA"); 239 | 240 | removeHeaderView(mHeaderView); 241 | 242 | if (getHeaderViewsCount() == 0) 243 | setSelection(0); 244 | else 245 | setSelection(1); 246 | 247 | } else { 248 | // removeHeaderView(mHeaderView); 249 | } 250 | 251 | resetHeader(); 252 | resetFooter(); 253 | 254 | if (pullState != LOADING && getLastVisiblePosition() == getCount() - 1) { 255 | // go to bottom 256 | // setSelection(getCount() - 2); 257 | 258 | if ((getHeight() - mFooterView.getTop()) >= (headerFixedOriginalHeight * releaseTrigger)) { 259 | Log.d("FRED", "TRIGGER"); 260 | refreshDown(); 261 | } 262 | } 263 | 264 | break; 265 | case MotionEvent.ACTION_DOWN: 266 | lastY = y; 267 | 268 | break; 269 | } 270 | return super.onTouchEvent(ev); 271 | } 272 | 273 | @Override 274 | public void setAdapter(ListAdapter adapter) { 275 | super.setAdapter(adapter); 276 | 277 | setSelection(0); 278 | } 279 | 280 | @Override 281 | protected void onAttachedToWindow() { 282 | super.onAttachedToWindow(); 283 | setSelection(0); 284 | } 285 | 286 | /** 287 | * Increase header top padding 288 | */ 289 | private void setHeaderTopPadding(MotionEvent me) { 290 | // Know if swipe is UP 291 | if (lastY > me.getY()) 292 | return; 293 | 294 | if (getHeaderViewsCount() == 0) { 295 | if (mFooterView.getBottom() != 0) { 296 | 297 | mFooterView.setPadding(mFooterView.getPaddingLeft(), mFooterView.getPaddingTop(), 298 | mFooterView.getPaddingRight(), (getHeight() - mFooterView.getBottom()) + footerHeigh); 299 | } 300 | addHeaderView(mHeaderView); 301 | setSelection(1); 302 | } 303 | 304 | setVerticalFadingEdgeEnabled(false); 305 | mHeaderView.setVisibility(View.VISIBLE); 306 | 307 | for (int p = 0; p < me.getHistorySize(); p++) { 308 | setVerticalScrollBarEnabled(false); 309 | 310 | int topPadding = (int) (((me.getHistoricalY(p) - lastY) - headerHeigh) / 2); 311 | mHeaderView.setPadding(mHeaderView.getPaddingLeft(), topPadding, mHeaderView.getPaddingRight(), 312 | mHeaderView.getPaddingBottom()); 313 | 314 | } 315 | 316 | } 317 | 318 | /** 319 | * Increase footer bootom padding 320 | */ 321 | private void setFooterBottomPadding(MotionEvent me) { 322 | 323 | if (lastY < me.getY()) 324 | return; 325 | 326 | footerProgressBar.setVisibility(View.VISIBLE); 327 | 328 | setVerticalFadingEdgeEnabled(false); 329 | 330 | for (int p = 0; p < me.getHistorySize(); p++) { 331 | setVerticalScrollBarEnabled(false); 332 | 333 | int bottomPadding = (int) (((lastY - me.getHistoricalY(p)) + footerHeigh) / 2); 334 | 335 | mFooterView.setPadding(mFooterView.getPaddingLeft(), mFooterView.getPaddingTop(), 336 | mFooterView.getPaddingRight(), bottomPadding); 337 | 338 | } 339 | 340 | } 341 | 342 | private void resetHeader() { 343 | headerImage.clearAnimation(); 344 | mHeaderView.setPadding(mHeaderView.getPaddingLeft(), headerHeigh, mHeaderView.getPaddingRight(), 345 | mHeaderView.getPaddingBottom()); 346 | 347 | } 348 | 349 | private void resetFooter() { 350 | 351 | mFooterView.setPadding(mFooterView.getPaddingLeft(), 10, mFooterView.getPaddingRight(), footerHeigh); 352 | 353 | } 354 | 355 | private void refresh() { 356 | headerImage.setVisibility(View.INVISIBLE); 357 | headerProgressBar.setVisibility(View.VISIBLE); 358 | currentState = CurrentState.LOADING_UP; 359 | if (refreshListener != null) { 360 | refreshListener.onRefreshUp(); 361 | } 362 | } 363 | 364 | private void refreshDown() { 365 | 366 | footerMessage.setVisibility(View.GONE); 367 | footerProgressBar.setVisibility(View.VISIBLE); 368 | currentState = CurrentState.LOADING_DOWN; 369 | 370 | if (refreshListener != null) { 371 | refreshListener.onRefeshDown(); 372 | } 373 | 374 | } 375 | 376 | /******************** 377 | * PUBLIC METHODSS 378 | ******************/ 379 | 380 | /* 381 | * Reset up header list 382 | */ 383 | public void onRefreshUpComplete() { 384 | resetHeader(); 385 | headerImage.setVisibility(View.VISIBLE); 386 | headerProgressBar.setVisibility(View.INVISIBLE); 387 | removeHeaderView(mHeaderView); 388 | /* 389 | * if (getFirstVisiblePosition() == 0) { invalidateViews(); 390 | * setSelection(0); } 391 | */ 392 | setSelection(0); 393 | 394 | pullState = DOING_NOTHING; 395 | } 396 | 397 | /* 398 | * Reset down header list 399 | */ 400 | public void onRefreshDownComplete(String message) { 401 | if (message != null) { 402 | footerMessage.setText(message); 403 | footerMessage.setVisibility(View.VISIBLE); 404 | footerProgressBar.setVisibility(View.GONE); 405 | } 406 | isFooterLoading = false; 407 | 408 | } 409 | 410 | public void onRefresh() { 411 | if (currentState == null) 412 | return; 413 | 414 | switch (currentState) { 415 | case LOADING_DOWN: 416 | onRefreshDownComplete(null); 417 | break; 418 | case LOADING_UP: 419 | onRefreshUpComplete(); 420 | break; 421 | } 422 | 423 | } 424 | 425 | /** 426 | * Set mode 427 | * 428 | * @param mode 429 | * 430 | * MODE.UP_ONLY -> Only up pull active MODE.UP_AND_DOWN -> Up and 431 | * down pull active 432 | */ 433 | public void setPullMode(MODE mode) { 434 | this.mode = mode; 435 | if (mode == MODE.UP_ONLY) { 436 | removeFooterView(mFooterView); 437 | } 438 | } 439 | 440 | /** 441 | * call onRefreshDown() when autoLoadDistanceToEnd Value to end of the list 442 | * is reached 443 | * 444 | * @param autoload 445 | * @param autoLoadDistanceToEnd 446 | * distance to end of list 447 | */ 448 | public void setAutoLoad(boolean autoload, int autoLoadDistanceToEnd) { 449 | this.autoLoad = autoload; 450 | this.autoLoadPosition = autoLoadDistanceToEnd; 451 | 452 | } 453 | 454 | /** 455 | * Set pull to refresh message 456 | * 457 | * @param message 458 | */ 459 | public void setPullMessage(String message) { 460 | PULL_MESSAGE = message; 461 | } 462 | 463 | /** 464 | * Set release to refresh message 465 | * 466 | * @param message 467 | */ 468 | public void setReleaseMessage(String message) { 469 | RELEASE_MESSAGE = message; 470 | } 471 | 472 | /** 473 | * Set loading message 474 | * 475 | * @param message 476 | */ 477 | public void setLoadingMessage(String message) { 478 | LOADING_MESSAGE = message; 479 | } 480 | 481 | /** 482 | * 483 | * @param color 484 | */ 485 | public void setPullMessageColor(int color) { 486 | headerMessage.setTextColor(color); 487 | } 488 | 489 | /** 490 | * @param size 491 | */ 492 | public void setPullMessageSize(float size) { 493 | headerMessage.setTextSize(size); 494 | 495 | } 496 | 497 | public void setPullRotateImage(Drawable image) { 498 | headerImage.setImageDrawable(image); 499 | } 500 | 501 | /** 502 | * Release TRigger >1 503 | * 504 | * @param t 505 | */ 506 | public void setReleaseTrigger(int t) { 507 | releaseTrigger = t; 508 | } 509 | 510 | public void setFooterWarning(String message) { 511 | footerMessage.setText(message); 512 | footerMessage.setVisibility(View.VISIBLE); 513 | footerProgressBar.setVisibility(View.GONE); 514 | } 515 | 516 | } 517 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | PullToUpdate 2 | ============ 3 | 4 | ##Features 5 | 6 | 7 | ##Usage 8 | 9 | ###Layout 10 | ``` xml 11 | 16 | ``` 17 | ###JAVA 18 | ``` java 19 | PullToUpdateListView list = (PullToUpdateListView) this.findViewById(R.id.list); 20 | ... 21 | 22 | list.setPullMode(PullToUpdateListView.MODE.UP_AND_DOWN); 23 | list.setAutoLoad(true, 8); 24 | list.setPullMessageColor(Color.BLUE); 25 | list.setLoadingMessage("Loading Message"); 26 | list.setPullRotateImage(getResources().getDrawable(R.drawable.rotate_img)); 27 | 28 | list.setOnRefreshListener(new IonRefreshListener() { 29 | @Override 30 | public void onRefreshUp() { 31 | //your code 32 | list.onRefreshUpComplete(); 33 | } 34 | 35 | @Override 36 | public void onRefeshDown() { 37 | //your code 38 | list.onRefreshDownComplete(null); 39 | } 40 | 41 | }); 42 | ``` 43 | ##DOCUMENTATION 44 | --------------------------------------------------------------------------------