diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 23130df..bfa7d8f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -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" /> - + android:windowSoftInputMode="stateAlwaysHidden|adjustResize" /> + + + + + + + + + + + + + + + + + + + + diff --git a/res/layout/activity_ptr_expandable_list.xml b/res/layout/activity_ptr_expandable_list.xml new file mode 100644 index 0000000..f4e337a --- /dev/null +++ b/res/layout/activity_ptr_expandable_list.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file diff --git a/res/layout/activity_ptr_grid.xml b/res/layout/activity_ptr_grid.xml new file mode 100644 index 0000000..7ac97ad --- /dev/null +++ b/res/layout/activity_ptr_grid.xml @@ -0,0 +1,22 @@ + + + + + + + \ No newline at end of file diff --git a/res/layout/activity_ptr_horizontalscrollview.xml b/res/layout/activity_ptr_horizontalscrollview.xml new file mode 100644 index 0000000..e37e9f8 --- /dev/null +++ b/res/layout/activity_ptr_horizontalscrollview.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/activity_ptr_list.xml b/res/layout/activity_ptr_list.xml new file mode 100644 index 0000000..a3b5561 --- /dev/null +++ b/res/layout/activity_ptr_list.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/res/layout/activity_ptr_list_fragment.xml b/res/layout/activity_ptr_list_fragment.xml new file mode 100644 index 0000000..eb9c1c2 --- /dev/null +++ b/res/layout/activity_ptr_list_fragment.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/res/layout/activity_ptr_list_in_vp.xml b/res/layout/activity_ptr_list_in_vp.xml new file mode 100644 index 0000000..a047376 --- /dev/null +++ b/res/layout/activity_ptr_list_in_vp.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/res/layout/activity_ptr_scrollview.xml b/res/layout/activity_ptr_scrollview.xml new file mode 100644 index 0000000..9b08062 --- /dev/null +++ b/res/layout/activity_ptr_scrollview.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/activity_ptr_viewpager.xml b/res/layout/activity_ptr_viewpager.xml new file mode 100644 index 0000000..15924da --- /dev/null +++ b/res/layout/activity_ptr_viewpager.xml @@ -0,0 +1,17 @@ + + + + + + + + \ No newline at end of file diff --git a/res/layout/activity_ptr_webview.xml b/res/layout/activity_ptr_webview.xml new file mode 100644 index 0000000..309cf46 --- /dev/null +++ b/res/layout/activity_ptr_webview.xml @@ -0,0 +1,16 @@ + + + + + + + + \ No newline at end of file diff --git a/res/layout/activity_ptr_webview2.xml b/res/layout/activity_ptr_webview2.xml new file mode 100644 index 0000000..541d872 --- /dev/null +++ b/res/layout/activity_ptr_webview2.xml @@ -0,0 +1,16 @@ + + + + + + + + \ No newline at end of file diff --git a/res/layout/layout_listview_in_viewpager.xml b/res/layout/layout_listview_in_viewpager.xml new file mode 100644 index 0000000..3bfc689 --- /dev/null +++ b/res/layout/layout_listview_in_viewpager.xml @@ -0,0 +1,6 @@ + + diff --git a/res/raw/pull_event.mp3 b/res/raw/pull_event.mp3 new file mode 100644 index 0000000..075ad08 Binary files /dev/null and b/res/raw/pull_event.mp3 differ diff --git a/res/raw/refreshing_sound.mp3 b/res/raw/refreshing_sound.mp3 new file mode 100644 index 0000000..9ebe0b6 Binary files /dev/null and b/res/raw/refreshing_sound.mp3 differ diff --git a/res/raw/reset_sound.mp3 b/res/raw/reset_sound.mp3 new file mode 100644 index 0000000..8e4c9e3 Binary files /dev/null and b/res/raw/reset_sound.mp3 differ diff --git a/res/values/strings_sample.xml b/res/values/strings_sample.xml index f78ee62..2ab3dbc 100644 --- a/res/values/strings_sample.xml +++ b/res/values/strings_sample.xml @@ -22,6 +22,7 @@ 水平/垂直滚动+首行首列固定+翻页Listview 下拉ScrollView背景回弹效果 FadingActionBar官方DEMO + PullToReresh官方DEMO @@ -151,5 +152,9 @@ Choose a city Change dataset WebView sample + + + 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. + \ No newline at end of file diff --git a/res/values/styles_sample.xml b/res/values/styles_sample.xml index 9ac8b1b..f6d5924 100644 --- a/res/values/styles_sample.xml +++ b/res/values/styles_sample.xml @@ -119,5 +119,14 @@ true @null + + + \ No newline at end of file diff --git a/src/com/zftlive/android/sample/fadingactionbar/HeaderOverlayActivity.java b/src/com/zftlive/android/sample/fadingactionbar/HeaderOverlayActivity.java index 9cdc7c2..a23bc9e 100644 --- a/src/com/zftlive/android/sample/fadingactionbar/HeaderOverlayActivity.java +++ b/src/com/zftlive/android/sample/fadingactionbar/HeaderOverlayActivity.java @@ -51,7 +51,7 @@ public class HeaderOverlayActivity extends Activity { listView.setAdapter(adapter); //初始化带返回按钮的标题栏 - ActionBarManager.initBackTitle(this, getActionBar(), "HeaderOverlayActivity"); + ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName()); } /** diff --git a/src/com/zftlive/android/sample/pulltorefresh/LauncherActivity.java b/src/com/zftlive/android/sample/pulltorefresh/LauncherActivity.java new file mode 100644 index 0000000..d66158f --- /dev/null +++ b/src/com/zftlive/android/sample/pulltorefresh/LauncherActivity.java @@ -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(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); + } + +} diff --git a/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshExpandableListActivity.java b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshExpandableListActivity.java new file mode 100644 index 0000000..09e0c00 --- /dev/null +++ b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshExpandableListActivity.java @@ -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> groupData = new ArrayList>(); + private List>> childData = new ArrayList>>(); + + 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() { + @Override + public void onRefresh(PullToRefreshBase refreshView) { + // Do work to refresh the list here. + new GetDataTask().execute(); + } + }); + + for (String group : mGroupStrings) { + Map groupMap1 = new HashMap(); + groupData.add(groupMap1); + groupMap1.put(KEY, group); + + List> childList = new ArrayList>(); + for (String string : mChildStrings) { + Map childMap = new HashMap(); + 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 { + + @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 newMap = new HashMap(); + newMap.put(KEY, "Added after refresh..."); + groupData.add(newMap); + + List> childList = new ArrayList>(); + for (String string : mChildStrings) { + Map childMap = new HashMap(); + 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" }; +} diff --git a/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshGridActivity.java b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshGridActivity.java new file mode 100644 index 0000000..5bd8c60 --- /dev/null +++ b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshGridActivity.java @@ -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 mListItems; + private PullToRefreshGridView mPullRefreshGridView; + private GridView mGridView; + private ArrayAdapter 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() { + + @Override + public void onPullDownToRefresh(PullToRefreshBase refreshView) { + Toast.makeText(PullToRefreshGridActivity.this, "Pull Down!", Toast.LENGTH_SHORT).show(); + new GetDataTask().execute(); + } + + @Override + public void onPullUpToRefresh(PullToRefreshBase refreshView) { + Toast.makeText(PullToRefreshGridActivity.this, "Pull Up!", Toast.LENGTH_SHORT).show(); + new GetDataTask().execute(); + } + + }); + + mListItems = new LinkedList(); + + 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(this, android.R.layout.simple_list_item_1, mListItems); + mGridView.setAdapter(mAdapter); + //初始化带返回按钮的标题栏 + ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName()); + } + + private class GetDataTask extends AsyncTask { + + @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" }; +} diff --git a/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshHorizontalScrollViewActivity.java b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshHorizontalScrollViewActivity.java new file mode 100644 index 0000000..2e04c41 --- /dev/null +++ b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshHorizontalScrollViewActivity.java @@ -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() { + + @Override + public void onRefresh(PullToRefreshBase refreshView) { + new GetDataTask().execute(); + } + }); + + mScrollView = mPullRefreshScrollView.getRefreshableView(); + //初始化带返回按钮的标题栏 + ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName()); + } + + private class GetDataTask extends AsyncTask { + + @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); + } + } + +} diff --git a/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshListActivity.java b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshListActivity.java new file mode 100644 index 0000000..a6784aa --- /dev/null +++ b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshListActivity.java @@ -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 mListItems; + private PullToRefreshListView mPullRefreshListView; + private ArrayAdapter 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() { + @Override + public void onRefresh(PullToRefreshBase 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(); + mListItems.addAll(Arrays.asList(mStrings)); + + mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, mListItems); + + /** + * Add Sound Event Listener + */ + SoundPullEventListener soundListener = new SoundPullEventListener(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 { + + @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" }; +} diff --git a/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshListFragmentActivity.java b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshListFragmentActivity.java new file mode 100644 index 0000000..f5735ae --- /dev/null +++ b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshListFragmentActivity.java @@ -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 { + + private LinkedList mListItems; + private ArrayAdapter 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(); + mListItems.addAll(Arrays.asList(mStrings)); + mAdapter = new ArrayAdapter(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 refreshView) { + // Do work to refresh the list here. + new GetDataTask().execute(); + } + + private class GetDataTask extends AsyncTask { + + @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" }; +} diff --git a/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshListInViewPagerActivity.java b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshListInViewPagerActivity.java new file mode 100644 index 0000000..9dbff1f --- /dev/null +++ b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshListInViewPagerActivity.java @@ -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 { + + 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(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 refreshView) { + new GetDataTask(refreshView).execute(); + } + + private static class GetDataTask extends AsyncTask { + + 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); + } + } + +} diff --git a/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshScrollViewActivity.java b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshScrollViewActivity.java new file mode 100644 index 0000000..1c2863b --- /dev/null +++ b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshScrollViewActivity.java @@ -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() { + + @Override + public void onRefresh(PullToRefreshBase refreshView) { + new GetDataTask().execute(); + } + }); + + mScrollView = mPullRefreshScrollView.getRefreshableView(); + //初始化带返回按钮的标题栏 + ActionBarManager.initBackTitle(this, getActionBar(), this.getClass().getSimpleName()); + } + + private class GetDataTask extends AsyncTask { + + @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); + } + } + +} diff --git a/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshViewPagerActivity.java b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshViewPagerActivity.java new file mode 100644 index 0000000..c943526 --- /dev/null +++ b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshViewPagerActivity.java @@ -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 { + + 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 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 { + + @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); + } + } + +} diff --git a/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshWebView2Activity.java b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshWebView2Activity.java new file mode 100644 index 0000000..d6d902c --- /dev/null +++ b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshWebView2Activity.java @@ -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 { + + /** 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 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); + } +} diff --git a/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshWebViewActivity.java b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshWebViewActivity.java new file mode 100644 index 0000000..55e90ca --- /dev/null +++ b/src/com/zftlive/android/sample/pulltorefresh/PullToRefreshWebViewActivity.java @@ -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; + } + } + +}