Swiperefresh sample

Change-Id: Ifc5736c91e61b592a010bd212752347e141849cc
diff --git a/samples/Support4Demos/AndroidManifest.xml b/samples/Support4Demos/AndroidManifest.xml
index 46a4831..5b43488 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
new file mode 100644
index 0000000..d65c15f
--- /dev/null
+++ b/samples/Support4Demos/res/drawable-hdpi/refresh.png
Binary files differ
diff --git a/samples/Support4Demos/res/drawable-mdpi/refresh.png b/samples/Support4Demos/res/drawable-mdpi/refresh.png
new file mode 100644
index 0000000..dc96718
--- /dev/null
+++ b/samples/Support4Demos/res/drawable-mdpi/refresh.png
Binary files differ
diff --git a/samples/Support4Demos/res/drawable-xhdpi/refresh.png b/samples/Support4Demos/res/drawable-xhdpi/refresh.png
new file mode 100644
index 0000000..47da13e
--- /dev/null
+++ b/samples/Support4Demos/res/drawable-xhdpi/refresh.png
Binary files differ
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 0000000..698024e
--- /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 0000000..214c637
--- /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 04c6f3f..c21e6d8 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 a52502e..ce3d633 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 ce41aaf..1c2835a 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 97cdb6f..689555b 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 0000000..7a0543c
--- /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