整合PullRefresh官方DEMO

This commit is contained in:
zengfantian 2015-03-26 01:55:55 +08:00
parent 8b1503d6b9
commit 151e11b7a8
29 changed files with 1480 additions and 4 deletions

View File

@ -481,7 +481,7 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.TranslucentActionBar"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<activity
android:name=".sample.fadingactionbar.NoParallaxActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
@ -511,8 +511,72 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.TranslucentActionBar"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<!-- PullToReresh官方DEMO -->
<activity
android:name=".sample.pulltorefresh.LauncherActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/PullToReresh"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="com.zftlive.android.SAMPLE_CODE" />
</intent-filter>
</activity>
<activity
android:name=".sample.pulltorefresh.PullToRefreshExpandableListActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<activity
android:name=".sample.pulltorefresh.PullToRefreshGridActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<activity
android:name=".sample.pulltorefresh.PullToRefreshHorizontalScrollViewActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<activity
android:name=".sample.pulltorefresh.PullToRefreshListActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<activity
android:name=".sample.pulltorefresh.PullToRefreshListFragmentActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<activity
android:name=".sample.pulltorefresh.PullToRefreshListInViewPagerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<activity
android:name=".sample.pulltorefresh.PullToRefreshScrollViewActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<activity
android:name=".sample.pulltorefresh.PullToRefreshViewPagerActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<activity
android:name=".sample.pulltorefresh.PullToRefreshWebView2Activity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<activity
android:name=".sample.pulltorefresh.PullToRefreshWebViewActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />
<!-- 静态注册短信广播接收器 -->
<receiver android:name=".sample.sms.SMSBroadcastReceiver" >
<intent-filter android:priority="2147483647" >

View File

@ -0,0 +1,18 @@
<?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" >
<!-- The PullToRefreshExpandableListView replaces a standard ExpandableListView widget. -->
<com.zftlive.android.view.pulltorefresh.PullToRefreshExpandableListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/pull_refresh_expandable_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
ptr:ptrHeaderBackground="@android:color/darker_gray"
ptr:ptrHeaderTextColor="@android:color/white"
ptr:ptrMode="pullUpFromBottom" />
</LinearLayout>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- The PullToRefreshGridView replaces a standard GridView widget. -->
<com.zftlive.android.view.pulltorefresh.PullToRefreshGridView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/pull_refresh_grid"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp"
android:columnWidth="100dp"
android:stretchMode="columnWidth"
android:gravity="fill"
ptr:ptrMode="both"
ptr:ptrDrawable="@drawable/ic_launcher" />
</LinearLayout>

View File

@ -0,0 +1,67 @@
<?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" >
<!-- The PullToRefreshScrollView replaces a standard PullToRefreshScrollView widget. -->
<com.zftlive.android.view.pulltorefresh.PullToRefreshHorizontalScrollView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/pull_refresh_horizontalscrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
ptr:ptrAnimationStyle="flip"
ptr:ptrMode="both" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
style="@style/HorizScrollViewItem"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#ff99cc00" />
<TextView
style="@style/HorizScrollViewItem"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#ffff4444" />
<TextView
style="@style/HorizScrollViewItem"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#ff33b5e5" />
<TextView
style="@style/HorizScrollViewItem"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#ffcc0000" />
<TextView
style="@style/HorizScrollViewItem"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#ffffbb33" />
<TextView
style="@style/HorizScrollViewItem"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#ff00ddff" />
<TextView
style="@style/HorizScrollViewItem"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#ff669900" />
</LinearLayout>
</com.zftlive.android.view.pulltorefresh.PullToRefreshHorizontalScrollView>
</LinearLayout>

View File

@ -0,0 +1,22 @@
<?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" >
<!-- The PullToRefreshListView replaces a standard ListView widget. -->
<com.zftlive.android.view.pulltorefresh.PullToRefreshListView
android:id="@+id/pull_refresh_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:divider="#19000000"
android:dividerHeight="4dp"
android:fadingEdge="none"
android:fastScrollEnabled="false"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:smoothScrollbar="true" />
</LinearLayout>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/frag_ptr_list"
android:name="com.zftlive.android.view.pulltorefresh.extras.listfragment.PullToRefreshListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>

View File

@ -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" >
<!-- The PullToRefreshListView replaces a standard ListView widget. -->
<android.support.v4.view.ViewPager
android:id="@+id/vp_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>

View File

@ -0,0 +1,25 @@
<?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" >
<!-- The PullToRefreshScrollView replaces a standard PullToRefreshScrollView widget. -->
<com.zftlive.android.view.pulltorefresh.PullToRefreshScrollView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/pull_refresh_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
ptr:ptrAnimationStyle="flip"
ptr:ptrMode="both" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="8dp"
android:text="@string/filler_text"
android:textSize="16sp" />
</com.zftlive.android.view.pulltorefresh.PullToRefreshScrollView>
</LinearLayout>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- The PullToRefreshScrollView replaces a standard PullToRefreshScrollView widget. -->
<com.zftlive.android.view.pulltorefresh.extras.viewpager.PullToRefreshViewPager
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/pull_refresh_viewpager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
ptr:ptrAnimationStyle="flip"
ptr:ptrHeaderBackground="@android:color/darker_gray"
ptr:ptrMode="both" />
</FrameLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- The PullToRefreshWebView replaces a standard WebView widget. -->
<com.zftlive.android.view.pulltorefresh.PullToRefreshWebView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/pull_refresh_webview"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
ptr:ptrMode="both" />
</LinearLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- The PullToRefreshWebView replaces a standard WebView widget. -->
<com.zftlive.android.view.pulltorefresh.extras.PullToRefreshWebView2
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/pull_refresh_webview2"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
ptr:ptrMode="both" />
</LinearLayout>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<com.handmark.pulltorefresh.library.PullToRefreshListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
ptr:ptrHeaderBackground="@android:color/darker_gray" />

BIN
res/raw/pull_event.mp3 Normal file

Binary file not shown.

Binary file not shown.

BIN
res/raw/reset_sound.mp3 Normal file

Binary file not shown.

View File

@ -22,6 +22,7 @@
<string name="HVScorllListviewActivity">水平/垂直滚动+首行首列固定+翻页Listview</string>
<string name="PulldownViewActivity">下拉ScrollView背景回弹效果</string>
<string name="FadingActionBar">FadingActionBar官方DEMO</string>
<string name="PullToReresh">PullToReresh官方DEMO</string>
<!-- Android样例锦集label(结束) -->
@ -151,5 +152,9 @@
<string name="choose_city">Choose a city</string>
<string name="action_change_dataset">Change dataset</string>
<string name="activity_title_webview">WebView sample</string>
<!-- PullToRefresh -->
<string name="filler_text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sollicitudin mauris varius lacus porttitor eget blandit massa facilisis. Nulla pellentesque odio sed purus fermentum vitae viverra orci faucibus. Sed ullamcorper condimentum vulputate. Curabitur sit amet convallis velit. Vestibulum posuere eleifend risus ac adipiscing. Nam pulvinar nulla a velit faucibus imperdiet. Praesent eget nisi ac justo blandit sagittis. Maecenas at leo nisi, nec varius nisl.\nIn hac habitasse platea dictumst. Morbi neque tortor, vestibulum sed viverra a, luctus vel lorem. Nunc turpis eros, varius eget commodo et, euismod at eros. Sed tincidunt mi purus, vel posuere dui. Vestibulum ante lectus, porta sed mattis bibendum, scelerisque cursus sapien. Cras ultrices imperdiet fermentum. Aenean nisi nulla, euismod non blandit ac, dictum quis libero. Morbi consectetur tempor mollis. Suspendisse eget nunc arcu, vel ullamcorper augue. Integer malesuada, diam nec faucibus mollis, nisl velit euismod enim, ac mattis justo neque sit amet mauris. Vivamus pretium imperdiet pharetra.\nInteger sagittis augue sit amet lectus pulvinar sit amet commodo tortor mattis. Maecenas quis tellus eget ante eleifend sollicitudin non et nibh. Maecenas luctus euismod tristique. Fusce in odio nec diam blandit facilisis. Sed nec arcu eros. Vivamus quis tortor a metus tempus aliquam eget volutpat magna. Pellentesque id ultrices dolor. Sed blandit aliquet quam. Phasellus dapibus euismod vulputate. Aenean blandit, elit vitae vestibulum tincidunt, metus dui accumsan nulla, sit amet vehicula mauris lacus in est. Etiam dignissim pellentesque nulla vel malesuada. Cras vel lorem justo.\nSed condimentum nisl sit amet libero vestibulum hendrerit. Duis auctor tempus placerat. Proin velit ante, ornare nec dictum nec, hendrerit eu arcu. Etiam ut diam ornare quam venenatis pulvinar vitae vel leo. Vivamus consectetur, ante id interdum rhoncus, magna eros pulvinar lacus, a gravida nibh arcu vitae eros. Nulla scelerisque laoreet feugiat. Mauris sit amet gravida felis.\nNulla ac dolor sapien, vestibulum venenatis justo. Cras placerat velit vitae nibh pellentesque ultricies. Suspendisse adipiscing enim eu justo iaculis eu pretium urna fermentum. Duis porttitor nunc non nunc mattis vestibulum. Etiam elit tellus, feugiat in bibendum eget, adipiscing nec metus. Ut ut sem lacus, quis faucibus diam. Curabitur a nulla fermentum tortor dignissim posuere. Fusce faucibus ante ut sem imperdiet imperdiet eget vitae lorem. Etiam fringilla ornare ipsum, in sagittis quam ornare vitae. Nullam venenatis orci sit amet sapien adipiscing gravida. Proin turpis lectus, hendrerit vitae vehicula ut, auctor ac lectus. Pellentesque sollicitudin blandit ligula quis commodo. Mauris vulputate lectus in velit luctus aliquam. Quisque eget tincidunt elit. Quisque et augue quam, sed scelerisque eros.</string>
</resources>

View File

@ -119,5 +119,14 @@
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
<!-- PullToRefresh -->
<style name="HorizScrollViewItem">
<item name="android:paddingRight">50dp</item>
<item name="android:paddingLeft">50dp</item>
<item name="android:gravity">center</item>
<item name="android:textAppearance">?android:attr/textAppearanceMedium</item>
<item name="android:text">Sample Item</item>
</style>
</resources>

View File

@ -51,7 +51,7 @@ public class HeaderOverlayActivity extends Activity {
listView.setAdapter(adapter);
//初始化带返回按钮的标题栏
ActionBarManager.initBackTitle(this, getActionBar(), "HeaderOverlayActivity");
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}
/**

View File

@ -0,0 +1,81 @@
/*******************************************************************************
* Copyright 2011, 2012 Chris Banes.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.zftlive.android.sample.pulltorefresh;
import com.zftlive.android.common.ActionBarManager;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class LauncherActivity extends ListActivity {
public static final String[] options = { "ListView", "ExpandableListView", "GridView", "WebView", "ScrollView",
"Horizontal ScrollView", "ViewPager", "ListView Fragment", "WebView Advanced", "ListView in ViewPager" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, options));
//初始化带返回按钮的标题栏
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent intent;
switch (position) {
default:
case 0:
intent = new Intent(this, PullToRefreshListActivity.class);
break;
case 1:
intent = new Intent(this, PullToRefreshExpandableListActivity.class);
break;
case 2:
intent = new Intent(this, PullToRefreshGridActivity.class);
break;
case 3:
intent = new Intent(this, PullToRefreshWebViewActivity.class);
break;
case 4:
intent = new Intent(this, PullToRefreshScrollViewActivity.class);
break;
case 5:
intent = new Intent(this, PullToRefreshHorizontalScrollViewActivity.class);
break;
case 6:
intent = new Intent(this, PullToRefreshViewPagerActivity.class);
break;
case 7:
intent = new Intent(this, PullToRefreshListFragmentActivity.class);
break;
case 8:
intent = new Intent(this, PullToRefreshWebView2Activity.class);
break;
case 9:
intent = new Intent(this, PullToRefreshListInViewPagerActivity.class);
break;
}
startActivity(intent);
}
}

View File

@ -0,0 +1,121 @@
/*******************************************************************************
* Copyright 2011, 2012 Chris Banes.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.zftlive.android.sample.pulltorefresh;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.ExpandableListActivity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
import com.zftlive.android.R;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.OnRefreshListener;
import com.zftlive.android.view.pulltorefresh.PullToRefreshExpandableListView;
public final class PullToRefreshExpandableListActivity extends ExpandableListActivity {
private static final String KEY = "key";
private List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
private List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
private PullToRefreshExpandableListView mPullRefreshListView;
private SimpleExpandableListAdapter mAdapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ptr_expandable_list);
mPullRefreshListView = (PullToRefreshExpandableListView) findViewById(R.id.pull_refresh_expandable_list);
// Set a listener to be invoked when the list should be refreshed.
mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ExpandableListView>() {
@Override
public void onRefresh(PullToRefreshBase<ExpandableListView> refreshView) {
// Do work to refresh the list here.
new GetDataTask().execute();
}
});
for (String group : mGroupStrings) {
Map<String, String> groupMap1 = new HashMap<String, String>();
groupData.add(groupMap1);
groupMap1.put(KEY, group);
List<Map<String, String>> childList = new ArrayList<Map<String, String>>();
for (String string : mChildStrings) {
Map<String, String> childMap = new HashMap<String, String>();
childList.add(childMap);
childMap.put(KEY, string);
}
childData.add(childList);
}
mAdapter = new SimpleExpandableListAdapter(this, groupData, android.R.layout.simple_expandable_list_item_1,
new String[] { KEY }, new int[] { android.R.id.text1 }, childData,
android.R.layout.simple_expandable_list_item_2, new String[] { KEY }, new int[] { android.R.id.text1 });
setListAdapter(mAdapter);
//初始化带返回按钮的标题栏
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}
private class GetDataTask extends AsyncTask<Void, Void, String[]> {
@Override
protected String[] doInBackground(Void... params) {
// Simulates a background job.
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
return mChildStrings;
}
@Override
protected void onPostExecute(String[] result) {
Map<String, String> newMap = new HashMap<String, String>();
newMap.put(KEY, "Added after refresh...");
groupData.add(newMap);
List<Map<String, String>> childList = new ArrayList<Map<String, String>>();
for (String string : mChildStrings) {
Map<String, String> childMap = new HashMap<String, String>();
childMap.put(KEY, string);
childList.add(childMap);
}
childData.add(childList);
mAdapter.notifyDataSetChanged();
// Call onRefreshComplete when the list has been refreshed.
mPullRefreshListView.onRefreshComplete();
super.onPostExecute(result);
}
}
private String[] mChildStrings = { "Child One", "Child Two", "Child Three", "Child Four", "Child Five", "Child Six" };
private String[] mGroupStrings = { "Group One", "Group Two", "Group Three" };
}

View File

@ -0,0 +1,145 @@
/*******************************************************************************
* Copyright 2011, 2012 Chris Banes.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.zftlive.android.sample.pulltorefresh;
import java.util.Arrays;
import java.util.LinkedList;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import com.zftlive.android.R;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.Mode;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.OnRefreshListener2;
import com.zftlive.android.view.pulltorefresh.PullToRefreshGridView;
public final class PullToRefreshGridActivity extends Activity {
static final int MENU_SET_MODE = 0;
private LinkedList<String> mListItems;
private PullToRefreshGridView mPullRefreshGridView;
private GridView mGridView;
private ArrayAdapter<String> mAdapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ptr_grid);
mPullRefreshGridView = (PullToRefreshGridView) findViewById(R.id.pull_refresh_grid);
mGridView = mPullRefreshGridView.getRefreshableView();
// Set a listener to be invoked when the list should be refreshed.
mPullRefreshGridView.setOnRefreshListener(new OnRefreshListener2<GridView>() {
@Override
public void onPullDownToRefresh(PullToRefreshBase<GridView> refreshView) {
Toast.makeText(PullToRefreshGridActivity.this, "Pull Down!", Toast.LENGTH_SHORT).show();
new GetDataTask().execute();
}
@Override
public void onPullUpToRefresh(PullToRefreshBase<GridView> refreshView) {
Toast.makeText(PullToRefreshGridActivity.this, "Pull Up!", Toast.LENGTH_SHORT).show();
new GetDataTask().execute();
}
});
mListItems = new LinkedList<String>();
TextView tv = new TextView(this);
tv.setGravity(Gravity.CENTER);
tv.setText("Empty View, Pull Down/Up to Add Items");
mPullRefreshGridView.setEmptyView(tv);
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems);
mGridView.setAdapter(mAdapter);
//初始化带返回按钮的标题栏
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}
private class GetDataTask extends AsyncTask<Void, Void, String[]> {
@Override
protected String[] doInBackground(Void... params) {
// Simulates a background job.
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
return mStrings;
}
@Override
protected void onPostExecute(String[] result) {
mListItems.addFirst("Added after refresh...");
mListItems.addAll(Arrays.asList(result));
mAdapter.notifyDataSetChanged();
// Call onRefreshComplete when the list has been refreshed.
mPullRefreshGridView.onRefreshComplete();
super.onPostExecute(result);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_SET_MODE, 0,
mPullRefreshGridView.getMode() == Mode.BOTH ? "Change to MODE_PULL_DOWN"
: "Change to MODE_PULL_BOTH");
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem setModeItem = menu.findItem(MENU_SET_MODE);
setModeItem.setTitle(mPullRefreshGridView.getMode() == Mode.BOTH ? "Change to MODE_PULL_FROM_START"
: "Change to MODE_PULL_BOTH");
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_SET_MODE:
mPullRefreshGridView
.setMode(mPullRefreshGridView.getMode() == Mode.BOTH ? Mode.PULL_FROM_START
: Mode.BOTH);
break;
}
return super.onOptionsItemSelected(item);
}
private String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
"Allgauer Emmentaler" };
}

View File

@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright 2011, 2012 Chris Banes.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.zftlive.android.sample.pulltorefresh;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.HorizontalScrollView;
import com.zftlive.android.R;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.OnRefreshListener;
import com.zftlive.android.view.pulltorefresh.PullToRefreshHorizontalScrollView;
public final class PullToRefreshHorizontalScrollViewActivity extends Activity {
PullToRefreshHorizontalScrollView mPullRefreshScrollView;
HorizontalScrollView mScrollView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ptr_horizontalscrollview);
mPullRefreshScrollView = (PullToRefreshHorizontalScrollView) findViewById(R.id.pull_refresh_horizontalscrollview);
mPullRefreshScrollView.setOnRefreshListener(new OnRefreshListener<HorizontalScrollView>() {
@Override
public void onRefresh(PullToRefreshBase<HorizontalScrollView> refreshView) {
new GetDataTask().execute();
}
});
mScrollView = mPullRefreshScrollView.getRefreshableView();
//初始化带返回按钮的标题栏
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}
private class GetDataTask extends AsyncTask<Void, Void, String[]> {
@Override
protected String[] doInBackground(Void... params) {
// Simulates a background job.
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
}
return null;
}
@Override
protected void onPostExecute(String[] result) {
// Do some stuff here
// Call onRefreshComplete when the list has been refreshed.
mPullRefreshScrollView.onRefreshComplete();
super.onPostExecute(result);
}
}
}

View File

@ -0,0 +1,206 @@
/*******************************************************************************
* Copyright 2011, 2012 Chris Banes.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.zftlive.android.sample.pulltorefresh;
import java.util.Arrays;
import java.util.LinkedList;
import android.app.ListActivity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.format.DateUtils;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.zftlive.android.R;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.Mode;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.OnLastItemVisibleListener;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.OnRefreshListener;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.State;
import com.zftlive.android.view.pulltorefresh.PullToRefreshListView;
import com.zftlive.android.view.pulltorefresh.extras.SoundPullEventListener;
public final class PullToRefreshListActivity extends ListActivity {
static final int MENU_MANUAL_REFRESH = 0;
static final int MENU_DISABLE_SCROLL = 1;
static final int MENU_SET_MODE = 2;
static final int MENU_DEMO = 3;
private LinkedList<String> mListItems;
private PullToRefreshListView mPullRefreshListView;
private ArrayAdapter<String> mAdapter;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ptr_list);
mPullRefreshListView = (PullToRefreshListView) findViewById(R.id.pull_refresh_list);
// Set a listener to be invoked when the list should be refreshed.
mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
String label = DateUtils.formatDateTime(getApplicationContext(), System.currentTimeMillis(),
DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
// Update the LastUpdatedLabel
refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
// Do work to refresh the list here.
new GetDataTask().execute();
}
});
// Add an end-of-list listener
mPullRefreshListView.setOnLastItemVisibleListener(new OnLastItemVisibleListener() {
@Override
public void onLastItemVisible() {
Toast.makeText(PullToRefreshListActivity.this, "End of List!", Toast.LENGTH_SHORT).show();
}
});
ListView actualListView = mPullRefreshListView.getRefreshableView();
// Need to use the Actual ListView when registering for Context Menu
registerForContextMenu(actualListView);
mListItems = new LinkedList<String>();
mListItems.addAll(Arrays.asList(mStrings));
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems);
/**
* Add Sound Event Listener
*/
SoundPullEventListener<ListView> soundListener = new SoundPullEventListener<ListView>(this);
soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event);
soundListener.addSoundEvent(State.RESET, R.raw.reset_sound);
soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound);
mPullRefreshListView.setOnPullEventListener(soundListener);
// You can also just use setListAdapter(mAdapter) or
// mPullRefreshListView.setAdapter(mAdapter)
actualListView.setAdapter(mAdapter);
//初始化带返回按钮的标题栏
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}
private class GetDataTask extends AsyncTask<Void, Void, String[]> {
@Override
protected String[] doInBackground(Void... params) {
// Simulates a background job.
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
}
return mStrings;
}
@Override
protected void onPostExecute(String[] result) {
mListItems.addFirst("Added after refresh...");
mAdapter.notifyDataSetChanged();
// Call onRefreshComplete when the list has been refreshed.
mPullRefreshListView.onRefreshComplete();
super.onPostExecute(result);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_MANUAL_REFRESH, 0, "Manual Refresh");
menu.add(0, MENU_DISABLE_SCROLL, 1,
mPullRefreshListView.isScrollingWhileRefreshingEnabled() ? "Disable Scrolling while Refreshing"
: "Enable Scrolling while Refreshing");
menu.add(0, MENU_SET_MODE, 0, mPullRefreshListView.getMode() == Mode.BOTH ? "Change to MODE_PULL_DOWN"
: "Change to MODE_PULL_BOTH");
menu.add(0, MENU_DEMO, 0, "Demo");
return super.onCreateOptionsMenu(menu);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
menu.setHeaderTitle("Item: " + getListView().getItemAtPosition(info.position));
menu.add("Item 1");
menu.add("Item 2");
menu.add("Item 3");
menu.add("Item 4");
super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
MenuItem disableItem = menu.findItem(MENU_DISABLE_SCROLL);
disableItem
.setTitle(mPullRefreshListView.isScrollingWhileRefreshingEnabled() ? "Disable Scrolling while Refreshing"
: "Enable Scrolling while Refreshing");
MenuItem setModeItem = menu.findItem(MENU_SET_MODE);
setModeItem.setTitle(mPullRefreshListView.getMode() == Mode.BOTH ? "Change to MODE_FROM_START"
: "Change to MODE_PULL_BOTH");
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case MENU_MANUAL_REFRESH:
new GetDataTask().execute();
mPullRefreshListView.setRefreshing(false);
break;
case MENU_DISABLE_SCROLL:
mPullRefreshListView.setScrollingWhileRefreshingEnabled(!mPullRefreshListView
.isScrollingWhileRefreshingEnabled());
break;
case MENU_SET_MODE:
mPullRefreshListView.setMode(mPullRefreshListView.getMode() == Mode.BOTH ? Mode.PULL_FROM_START
: Mode.BOTH);
break;
case MENU_DEMO:
mPullRefreshListView.demo();
break;
}
return super.onOptionsItemSelected(item);
}
private String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
"Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
"Allgauer Emmentaler" };
}

View File

@ -0,0 +1,108 @@
/*******************************************************************************
* Copyright 2011, 2012 Chris Banes.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.zftlive.android.sample.pulltorefresh;
import java.util.Arrays;
import java.util.LinkedList;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.zftlive.android.R;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.view.pulltorefresh.extras.listfragment.PullToRefreshListFragment;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.OnRefreshListener;
import com.zftlive.android.view.pulltorefresh.PullToRefreshListView;
public final class PullToRefreshListFragmentActivity extends FragmentActivity implements OnRefreshListener<ListView> {
private LinkedList<String> mListItems;
private ArrayAdapter<String> mAdapter;
private PullToRefreshListFragment mPullRefreshListFragment;
private PullToRefreshListView mPullRefreshListView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ptr_list_fragment);
mPullRefreshListFragment = (PullToRefreshListFragment) getSupportFragmentManager().findFragmentById(
R.id.frag_ptr_list);
// Get PullToRefreshListView from Fragment
mPullRefreshListView = mPullRefreshListFragment.getPullToRefreshListView();
// Set a listener to be invoked when the list should be refreshed.
mPullRefreshListView.setOnRefreshListener(this);
// You can also just use mPullRefreshListFragment.getListView()
ListView actualListView = mPullRefreshListView.getRefreshableView();
mListItems = new LinkedList<String>();
mListItems.addAll(Arrays.asList(mStrings));
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mListItems);
// You can also just use setListAdapter(mAdapter) or
// mPullRefreshListView.setAdapter(mAdapter)
actualListView.setAdapter(mAdapter);
mPullRefreshListFragment.setListShown(true);
//初始化带返回按钮的标题栏
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
// Do work to refresh the list here.
new GetDataTask().execute();
}
private class GetDataTask extends AsyncTask<Void, Void, String[]> {
@Override
protected String[] doInBackground(Void... params) {
// Simulates a background job.
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
}
return mStrings;
}
@Override
protected void onPostExecute(String[] result) {
mListItems.addFirst("Added after refresh...");
mAdapter.notifyDataSetChanged();
// Call onRefreshComplete when the list has been refreshed.
mPullRefreshListView.onRefreshComplete();
super.onPostExecute(result);
}
}
private String[] mStrings = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
"Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
"Allgauer Emmentaler" };
}

View File

@ -0,0 +1,114 @@
package com.zftlive.android.sample.pulltorefresh;
import java.util.Arrays;
import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import com.zftlive.android.R;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.OnRefreshListener;
import com.zftlive.android.view.pulltorefresh.PullToRefreshListView;
public class PullToRefreshListInViewPagerActivity extends Activity implements OnRefreshListener<ListView> {
private static final String[] STRINGS = { "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance",
"Ackawi", "Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
"Allgauer Emmentaler", "Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale", "Aisy Cendre",
"Allgauer Emmentaler" };
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ptr_list_in_vp);
mViewPager = (ViewPager) findViewById(R.id.vp_list);
mViewPager.setAdapter(new ListViewPagerAdapter());
//初始化带返回按钮的标题栏
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}
private class ListViewPagerAdapter extends PagerAdapter {
@Override
public View instantiateItem(ViewGroup container, int position) {
Context context = container.getContext();
PullToRefreshListView plv = (PullToRefreshListView) LayoutInflater.from(context).inflate(
R.layout.layout_listview_in_viewpager, container, false);
ListAdapter adapter = new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1,
Arrays.asList(STRINGS));
plv.setAdapter(adapter);
plv.setOnRefreshListener(PullToRefreshListInViewPagerActivity.this);
// Now just add ListView to ViewPager and return it
container.addView(plv, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
return plv;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public int getCount() {
return 3;
}
}
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
new GetDataTask(refreshView).execute();
}
private static class GetDataTask extends AsyncTask<Void, Void, Void> {
PullToRefreshBase<?> mRefreshedView;
public GetDataTask(PullToRefreshBase<?> refreshedView) {
mRefreshedView = refreshedView;
}
@Override
protected Void doInBackground(Void... params) {
// Simulates a background job.
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mRefreshedView.onRefreshComplete();
super.onPostExecute(result);
}
}
}

View File

@ -0,0 +1,77 @@
/*******************************************************************************
* Copyright 2011, 2012 Chris Banes.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.zftlive.android.sample.pulltorefresh;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ScrollView;
import com.zftlive.android.R;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.OnRefreshListener;
import com.zftlive.android.view.pulltorefresh.PullToRefreshScrollView;
public final class PullToRefreshScrollViewActivity extends Activity {
PullToRefreshScrollView mPullRefreshScrollView;
ScrollView mScrollView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ptr_scrollview);
mPullRefreshScrollView = (PullToRefreshScrollView) findViewById(R.id.pull_refresh_scrollview);
mPullRefreshScrollView.setOnRefreshListener(new OnRefreshListener<ScrollView>() {
@Override
public void onRefresh(PullToRefreshBase<ScrollView> refreshView) {
new GetDataTask().execute();
}
});
mScrollView = mPullRefreshScrollView.getRefreshableView();
//初始化带返回按钮的标题栏
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}
private class GetDataTask extends AsyncTask<Void, Void, String[]> {
@Override
protected String[] doInBackground(Void... params) {
// Simulates a background job.
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
}
return null;
}
@Override
protected void onPostExecute(String[] result) {
// Do some stuff here
// Call onRefreshComplete when the list has been refreshed.
mPullRefreshScrollView.onRefreshComplete();
super.onPostExecute(result);
}
}
}

View File

@ -0,0 +1,108 @@
/*******************************************************************************
* Copyright 2011, 2012 Chris Banes.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.zftlive.android.sample.pulltorefresh;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import com.zftlive.android.R;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.view.pulltorefresh.extras.viewpager.PullToRefreshViewPager;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.OnRefreshListener;
public class PullToRefreshViewPagerActivity extends Activity implements OnRefreshListener<ViewPager> {
private PullToRefreshViewPager mPullToRefreshViewPager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ptr_viewpager);
mPullToRefreshViewPager = (PullToRefreshViewPager) findViewById(R.id.pull_refresh_viewpager);
mPullToRefreshViewPager.setOnRefreshListener(this);
ViewPager vp = mPullToRefreshViewPager.getRefreshableView();
vp.setAdapter(new SamplePagerAdapter());
//初始化带返回按钮的标题栏
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}
@Override
public void onRefresh(PullToRefreshBase<ViewPager> refreshView) {
new GetDataTask().execute();
}
static class SamplePagerAdapter extends PagerAdapter {
private static int[] sDrawables = { R.drawable.default_icon, R.drawable.default_icon, R.drawable.default_icon,
R.drawable.default_icon, R.drawable.default_icon, R.drawable.default_icon };
@Override
public int getCount() {
return sDrawables.length;
}
@Override
public View instantiateItem(ViewGroup container, int position) {
ImageView imageView = new ImageView(container.getContext());
imageView.setImageResource(sDrawables[position]);
// Now just add ImageView to ViewPager and return it
container.addView(imageView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
private class GetDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
// Simulates a background job.
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mPullToRefreshViewPager.onRefreshComplete();
super.onPostExecute(result);
}
}
}

View File

@ -0,0 +1,70 @@
/*******************************************************************************
* Copyright 2011, 2012 Chris Banes.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.zftlive.android.sample.pulltorefresh;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.zftlive.android.R;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase;
import com.zftlive.android.view.pulltorefresh.PullToRefreshBase.OnRefreshListener;
import com.zftlive.android.view.pulltorefresh.extras.PullToRefreshWebView2;
public final class PullToRefreshWebView2Activity extends Activity implements OnRefreshListener<WebView> {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ptr_webview2);
PullToRefreshWebView2 pullRefreshWebView = (PullToRefreshWebView2) findViewById(R.id.pull_refresh_webview2);
pullRefreshWebView.setOnRefreshListener(this);
WebView webView = pullRefreshWebView.getRefreshableView();
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new SampleWebViewClient());
// We just load a prepared HTML page from the assets folder for this
// sample, see that file for the Javascript implementation
webView.loadUrl("file:///android_asset/ptr_webview2_sample.html");
//初始化带返回按钮的标题栏
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}
private static class SampleWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
@Override
public void onRefresh(final PullToRefreshBase<WebView> refreshView) {
// This is very contrived example, we just wait 2 seconds, then call
// onRefreshComplete()
refreshView.postDelayed(new Runnable() {
@Override
public void run() {
refreshView.onRefreshComplete();
}
}, 2 * 1000);
}
}

View File

@ -0,0 +1,56 @@
/*******************************************************************************
* Copyright 2011, 2012 Chris Banes.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.zftlive.android.sample.pulltorefresh;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.zftlive.android.R;
import com.zftlive.android.common.ActionBarManager;
import com.zftlive.android.view.pulltorefresh.PullToRefreshWebView;
public final class PullToRefreshWebViewActivity extends Activity {
PullToRefreshWebView mPullRefreshWebView;
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ptr_webview);
mPullRefreshWebView = (PullToRefreshWebView) findViewById(R.id.pull_refresh_webview);
mWebView = mPullRefreshWebView.getRefreshableView();
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new SampleWebViewClient());
mWebView.loadUrl("http://www.google.com");
//初始化带返回按钮的标题栏
ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName());
}
private static class SampleWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}