diff options
author | Mindy Pereira <mindyp@google.com> | 2013-11-06 16:32:56 -0800 |
---|---|---|
committer | Mindy Pereira <mindyp@google.com> | 2013-11-19 17:14:06 -0800 |
commit | 18152c7cea21bcd1dc5224dee39d8b072abe3b47 (patch) | |
tree | a0e05ef0370fc6f66310e743bd06f1ddc154d9e8 | |
parent | 469e5a18f8bca5d883937356e0787c3485558335 (diff) | |
download | android_development-18152c7cea21bcd1dc5224dee39d8b072abe3b47.tar.gz android_development-18152c7cea21bcd1dc5224dee39d8b072abe3b47.tar.bz2 android_development-18152c7cea21bcd1dc5224dee39d8b072abe3b47.zip |
Swiperefresh sample
Change-Id: Ifc5736c91e61b592a010bd212752347e141849cc
-rw-r--r-- | samples/Support4Demos/AndroidManifest.xml | 9 | ||||
-rw-r--r-- | samples/Support4Demos/res/drawable-hdpi/refresh.png | bin | 0 -> 1739 bytes | |||
-rw-r--r-- | samples/Support4Demos/res/drawable-mdpi/refresh.png | bin | 0 -> 1169 bytes | |||
-rw-r--r-- | samples/Support4Demos/res/drawable-xhdpi/refresh.png | bin | 0 -> 2288 bytes | |||
-rw-r--r-- | samples/Support4Demos/res/layout/swipe_refresh_widget_sample.xml | 26 | ||||
-rw-r--r-- | samples/Support4Demos/res/menu/swipe_refresh_menu.xml | 22 | ||||
-rw-r--r-- | samples/Support4Demos/res/values-v11/styles.xml | 4 | ||||
-rw-r--r-- | samples/Support4Demos/res/values/colors.xml | 6 | ||||
-rw-r--r-- | samples/Support4Demos/res/values/strings.xml | 2 | ||||
-rw-r--r-- | samples/Support4Demos/res/values/styles.xml | 9 | ||||
-rw-r--r-- | samples/Support4Demos/src/com/example/android/supportv4/widget/SwipeRefreshLayoutActivity.java | 139 |
11 files changed, 215 insertions, 2 deletions
diff --git a/samples/Support4Demos/AndroidManifest.xml b/samples/Support4Demos/AndroidManifest.xml index 46a4831be..5b434886d 100644 --- a/samples/Support4Demos/AndroidManifest.xml +++ b/samples/Support4Demos/AndroidManifest.xml @@ -305,6 +305,15 @@ </intent-filter> </activity> + <activity android:name=".widget.SwipeRefreshLayoutActivity" + android:label="@string/swipe" + android:theme="@style/ThemeHoloLight"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="com.example.android.supportv4.SUPPORT4_SAMPLE_CODE" /> + </intent-filter> + </activity> + <activity android:name=".widget.ContentLoadingProgressBarActivity" android:label="@string/content_loading_progress_bar"> <intent-filter> diff --git a/samples/Support4Demos/res/drawable-hdpi/refresh.png b/samples/Support4Demos/res/drawable-hdpi/refresh.png Binary files differnew file mode 100644 index 000000000..d65c15f0d --- /dev/null +++ b/samples/Support4Demos/res/drawable-hdpi/refresh.png diff --git a/samples/Support4Demos/res/drawable-mdpi/refresh.png b/samples/Support4Demos/res/drawable-mdpi/refresh.png Binary files differnew file mode 100644 index 000000000..dc967187d --- /dev/null +++ b/samples/Support4Demos/res/drawable-mdpi/refresh.png diff --git a/samples/Support4Demos/res/drawable-xhdpi/refresh.png b/samples/Support4Demos/res/drawable-xhdpi/refresh.png Binary files differnew file mode 100644 index 000000000..47da13e9a --- /dev/null +++ b/samples/Support4Demos/res/drawable-xhdpi/refresh.png diff --git a/samples/Support4Demos/res/layout/swipe_refresh_widget_sample.xml b/samples/Support4Demos/res/layout/swipe_refresh_widget_sample.xml new file mode 100644 index 000000000..698024e22 --- /dev/null +++ b/samples/Support4Demos/res/layout/swipe_refresh_widget_sample.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2013 The Android Open Source Project + + 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. +--> + +<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/swipe_refresh_widget" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <!-- some full screen pullable view that will be the offsetable content --> + <ListView + android:layout_width="match_parent" + android:layout_height="match_parent" + android:id="@+id/content"/> +</android.support.v4.widget.SwipeRefreshLayout>
\ No newline at end of file diff --git a/samples/Support4Demos/res/menu/swipe_refresh_menu.xml b/samples/Support4Demos/res/menu/swipe_refresh_menu.xml new file mode 100644 index 000000000..214c637ef --- /dev/null +++ b/samples/Support4Demos/res/menu/swipe_refresh_menu.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2013 The Android Open Source Project + + 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. +--> + +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:id="@+id/force_refresh" + android:showAsAction="ifRoom" + android:icon="@drawable/refresh" + android:title="Refresh" /> +</menu>
\ No newline at end of file diff --git a/samples/Support4Demos/res/values-v11/styles.xml b/samples/Support4Demos/res/values-v11/styles.xml index 04c6f3f72..c21e6d8b2 100644 --- a/samples/Support4Demos/res/values-v11/styles.xml +++ b/samples/Support4Demos/res/values-v11/styles.xml @@ -19,6 +19,10 @@ <style name="ThemeHolo" parent="android:Theme.Holo"> </style> + <!-- For API level 11 or later, the Holo theme is available and we prefer that. --> + <style name="ThemeHoloLight" parent="android:Theme.Holo.Light"> + </style> + <!-- For API level 11 or later, we can use the magical DialogWhenLarge theme. --> <style name="ThemeDialogWhenLarge" parent="android:style/Theme.Holo.DialogWhenLarge"> </style> diff --git a/samples/Support4Demos/res/values/colors.xml b/samples/Support4Demos/res/values/colors.xml index a52502efa..ce3d63327 100644 --- a/samples/Support4Demos/res/values/colors.xml +++ b/samples/Support4Demos/res/values/colors.xml @@ -18,5 +18,9 @@ <drawable name="red">#7f00</drawable> <drawable name="blue">#770000ff</drawable> <drawable name="green">#7700ff00</drawable> - <drawable name="yellow">#77ffff00</drawable> + <drawable name="yellow">#77ffff00</drawable> + <color name="color1">#ff0f9d58</color> + <color name="color2">#ffdb4437</color> + <color name="color3">#ff4285f4</color> + <color name="color4">#fff4b400</color> </resources> diff --git a/samples/Support4Demos/res/values/strings.xml b/samples/Support4Demos/res/values/strings.xml index ce41aafc7..1c2835a2c 100644 --- a/samples/Support4Demos/res/values/strings.xml +++ b/samples/Support4Demos/res/values/strings.xml @@ -176,4 +176,6 @@ <!-- ContentLoadingProgressBar --> <string name="content_loading_progress_bar">Widget/Content Loading Progress Bar</string> + <!-- Swipe refresh --> + <string name="swipe">Widget/SwipeRefreshLayout</string> </resources> diff --git a/samples/Support4Demos/res/values/styles.xml b/samples/Support4Demos/res/values/styles.xml index 97cdb6f89..689555b69 100644 --- a/samples/Support4Demos/res/values/styles.xml +++ b/samples/Support4Demos/res/values/styles.xml @@ -21,7 +21,14 @@ selected when the holographic theme is available. --> <style name="ThemeHolo" parent="android:Theme"> </style> - + + <!-- This is a theme that will adjust itself depending on the API version. + The default definition is the safe one, using a theme that has always + been defined. Look at values-11/styles.xml for a variation that is + selected when the holographic theme is available. --> + <style name="ThemeHoloLight" parent="android:Theme.Light"> + </style> + <!-- Older platforms don't have Theme.Holo.DialogWhenLarge; we will define our own wrapper theme that uses it only when running on the appropriate platform version. On older platforms, we always use the generic diff --git a/samples/Support4Demos/src/com/example/android/supportv4/widget/SwipeRefreshLayoutActivity.java b/samples/Support4Demos/src/com/example/android/supportv4/widget/SwipeRefreshLayoutActivity.java new file mode 100644 index 000000000..7a0543cb8 --- /dev/null +++ b/samples/Support4Demos/src/com/example/android/supportv4/widget/SwipeRefreshLayoutActivity.java @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * 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.example.android.supportv4.widget; + +import android.app.Activity; +import android.os.Bundle; +import android.os.Handler; +import android.support.v4.widget.SwipeRefreshLayout; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.MotionEvent; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListView; +import android.widget.Toast; + +import com.example.android.supportv4.R; +import com.example.android.supportv4.Shakespeare; + +import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener; + +/** + * Example of using the SwipeRefreshLayout. + */ +public class SwipeRefreshLayoutActivity extends Activity implements OnRefreshListener { + public static final String[] TITLES = + { + "Henry IV (1)", + "Henry V", + "Henry VIII", + "Richard II", + "Richard III", + "Merchant of Venice", + "Othello", + "King Lear", + "Henry IV (1)", + "Henry V", + "Henry VIII", + "Richard II", + "Richard III", + "Merchant of Venice", + "Othello", + "King Lear", + "Henry IV (1)", + "Henry V", + "Henry VIII", + "Richard II", + "Richard III", + "Merchant of Venice", + "Othello", + "King Lear", + "Henry IV (1)", + "Henry V", + "Henry VIII", + "Richard II", + "Richard III", + "Merchant of Venice", + "Othello", + "King Lear" + }; + // Try a SUPER quick refresh to make sure we don't get extra refreshes + // while the user's finger is still down. + private static final boolean SUPER_QUICK_REFRESH = false; + private View mContent; + private SwipeRefreshLayout mSwipeRefreshWidget; + private ListView mList; + private Handler mHandler = new Handler(); + private final Runnable mRefreshDone = new Runnable() { + + @Override + public void run() { + mSwipeRefreshWidget.setRefreshing(false); + } + + }; + @Override + public void onCreate(Bundle bundle) { + super.onCreate(bundle); + setContentView(R.layout.swipe_refresh_widget_sample); + mSwipeRefreshWidget = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_widget); + mSwipeRefreshWidget.setColorScheme(R.color.color1, R.color.color2, R.color.color3, + R.color.color4); + mList = (ListView) findViewById(R.id.content); + ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, + android.R.layout.simple_list_item_1, android.R.id.text1, TITLES); + mList.setAdapter(arrayAdapter); + mSwipeRefreshWidget.setOnRefreshListener(this); + } + + @Override + public void onRefresh() { + refresh(); + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.swipe_refresh_menu, menu); + return true; + } + + /** + * Click handler for the menu item to force a refresh. + */ + @Override + public boolean onOptionsItemSelected(MenuItem item) { + final int id = item.getItemId(); + switch(id) { + case R.id.force_refresh: + mSwipeRefreshWidget.setRefreshing(true); + refresh(); + return true; + } + return false; + } + + private void refresh() { + mHandler.removeCallbacks(mRefreshDone); + mHandler.postDelayed(mRefreshDone, 1000); + } +}
\ No newline at end of file |