Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Jan 23, 2012
0 parents commit c4a076d
Show file tree
Hide file tree
Showing 35 changed files with 1,643 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.classpath
.project
.settings
bin
gen
217 changes: 217 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
The first thing that i have to say is render thanks to johannilsson because
all the part of pull to refresh listview is based in the code of his repository
at <https://github.com/johannilsson/android-pulltorefresh>.

The target of this project is help other to apply the interaction pattern
pull to refresh and load more on an android listview.

#Costum Load more listview for android
![Screenshot](https://github.com/shontauro/android-pulltorefresh-and-loadmore/raw/master/loadmore.png)

More information about load more interaction pattern
at <http://www.androidpatterns.com/uap_pattern/dynamic-loading-of-a-list>

#Costum Pull to refresh listview for android
![Screenshot](https://github.com/shontauro/android-pulltorefresh-and-loadmore/raw/master/pulltorefresh.png)

More information about pull to refresh interaction pattern
at <http://www.androidpatterns.com/uap_pattern/pull-to-refresh-2>

Repository at <https://github.com/shontauro/android-pulltorefresh-and-loadmore>.

## Usage

### Layout for loadmore listview

``` xml
<!-- We have to indicate that the listview is now a LoadMoreListView -->

<com.costum.android.widget.LoadMoreListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
```
### Activity to LoadMoreListView


``` java
// set a listener to be invoked when the list reaches the end
((LoadMoreListView) getListView())
.setOnLoadMoreListener(new OnLoadMoreListener() {
public void onLoadMore() {
// Do the work to load more items at the end of list here
new LoadDataTask().execute();
}
});


private class LoadDataTask extends AsyncTask<Void, Void, Void> {

@Override
protected Void doInBackground(Void... params) {

if (isCancelled()) {
return null;
}

// Simulates a background task
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}

for (int i = 0; i < mNames.length; i++)
mListItems.add(mNames[i]);

return null;
}

@Override
protected void onPostExecute(Void result) {
mListItems.add("Added after load more");

// We need notify the adapter that the data have been changed
((BaseAdapter) getListAdapter()).notifyDataSetChanged();

// Call onLoadMoreComplete when the LoadMore task, has finished
((LoadMoreListView) getListView()).onLoadMoreComplete();

super.onPostExecute(result);
}

@Override
protected void onCancelled() {
// Notify the loading more operation has finished
((LoadMoreListView) getListView()).onLoadMoreComplete();
}
}
```


### Layout for pullandload listview

``` xml
<!-- We have to indicate that the listview is now a PullAndLoadListView -->

<com.costum.android.widget.PullAndLoadListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
```
### Activity to PullAndLoadListView

Here we have to pass two listeners one to pull operation and the other to load operation

``` java
// Set a listener to be invoked when the list should be refreshed.
((PullAndLoadListView) getListView())
.setOnRefreshListener(new OnRefreshListener() {

public void onRefresh() {
// Do work to refresh the list here.
new PullToRefreshDataTask().execute();
}
});

// set a listener to be invoked when the list reaches the end
((PullAndLoadListView) getListView())
.setOnLoadMoreListener(new OnLoadMoreListener() {

public void onLoadMore() {
// Do the work to load more items at the end of list
// here
new LoadMoreDataTask().execute();
}
});


private class LoadMoreDataTask extends AsyncTask<Void, Void, Void> {

@Override
protected Void doInBackground(Void... params) {

if (isCancelled()) {
return null;
}

// Simulates a background task
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}

for (int i = 0; i < mNames.length; i++)
mListItems.add(mNames[i]);

return null;
}

@Override
protected void onPostExecute(Void result) {
mListItems.add("Added after load more");

// We need notify the adapter that the data have been changed
((BaseAdapter) getListAdapter()).notifyDataSetChanged();

// Call onLoadMoreComplete when the LoadMore task, has finished
((PullAndLoadListView) getListView()).onLoadMoreComplete();

super.onPostExecute(result);
}

@Override
protected void onCancelled() {
// Notify the loading more operation has finished
((PullAndLoadListView) getListView()).onLoadMoreComplete();
}
}

private class PullToRefreshDataTask extends AsyncTask<Void, Void, Void> {

@Override
protected Void doInBackground(Void... params) {

if (isCancelled()) {
return null;
}

// Simulates a background task
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}

for (int i = 0; i < mAnimals.length; i++)
mListItems.addFirst(mAnimals[i]);

return null;
}

@Override
protected void onPostExecute(Void result) {
mListItems.addFirst("Added after pull to refresh");

// We need notify the adapter that the data have been changed
((BaseAdapter) getListAdapter()).notifyDataSetChanged();

// Call onLoadMoreComplete when the LoadMore task, has finished
((PullAndLoadListView) getListView()).onRefreshComplete();

super.onPostExecute(result);
}

@Override
protected void onCancelled() {
// Notify the loading more operation has finished
((PullAndLoadListView) getListView()).onLoadMoreComplete();
}
}
```


### License
Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)

Copyright (c) 2012 [Fabian Leon](http://yelamablog.blogspot.com/)


Binary file added loadmore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions pull-load-example/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.widget.example"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity android:name="Main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoadMoreExampleActivity"
android:label="@string/app_name" >
</activity>
<activity android:name=".PullAndLoadExampleActivity" >
</activity>
</application>

</manifest>
3 changes: 3 additions & 0 deletions pull-load-example/lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
</lint>
40 changes: 40 additions & 0 deletions pull-load-example/proguard.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
native <methods>;
}

-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
12 changes: 12 additions & 0 deletions pull-load-example/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.

# Project target.
target=android-7
android.library.reference.1=../pulltorefresh-and-loadmore/
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions pull-load-example/res/layout/loadmore.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<!-- We have to indicate that the listview is now a LoadMoreListView -->
<com.costum.android.widget.LoadMoreListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

</LinearLayout>
Expand Down
21 changes: 21 additions & 0 deletions pull-load-example/res/layout/main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="LoadMoreListView" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="PullToRefreshAndLoadMoreListView" />

</LinearLayout>
14 changes: 14 additions & 0 deletions pull-load-example/res/layout/pull_and_load.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<!-- We have to indicate that the listview is now a PullAndLoadListView -->

<com.costum.android.widget.PullAndLoadListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />

</LinearLayout>
7 changes: 7 additions & 0 deletions pull-load-example/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="hello">Hello World, LoadMoreExampleActivity!</string>
<string name="app_name">Loadmoreexample</string>

</resources>
Loading

0 comments on commit c4a076d

Please sign in to comment.