Select the animation for the SwipeRefreshLayout
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / fragment / ExtendedListFragment.java
index 409c5e6..915e455 100644 (file)
@@ -25,6 +25,7 @@ import com.owncloud.android.utils.Log_OC;
 
 
 import android.os.Bundle;
+import android.support.v4.widget.SwipeRefreshLayout;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -36,7 +37,7 @@ import android.widget.ListView;
 /**
  *  TODO extending SherlockListFragment instead of SherlockFragment 
  */
-public class ExtendedListFragment extends SherlockFragment implements OnItemClickListener {
+public class ExtendedListFragment extends SherlockFragment implements OnItemClickListener, SwipeRefreshLayout.OnRefreshListener{
     
     private static final String TAG = ExtendedListFragment.class.getSimpleName();
 
@@ -44,6 +45,8 @@ public class ExtendedListFragment extends SherlockFragment implements OnItemClic
 
     protected ExtendedListView mList;
     
+    private SwipeRefreshLayout mRefreshLayout;
+    
     public void setListAdapter(ListAdapter listAdapter) {
         mList.setAdapter(listAdapter);
         mList.invalidate();
@@ -58,6 +61,7 @@ public class ExtendedListFragment extends SherlockFragment implements OnItemClic
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         Log_OC.e(TAG, "onCreateView");
         //mList = new ExtendedListView(getActivity());
+        
         View v = inflater.inflate(R.layout.list_fragment, null);
         mList = (ExtendedListView)(v.findViewById(R.id.list_root));
         mList.setOnItemClickListener(this);
@@ -70,6 +74,14 @@ public class ExtendedListFragment extends SherlockFragment implements OnItemClic
             setReferencePosition(referencePosition);
         }
         
+        // Pull down refresh
+        mRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_files);
+        mRefreshLayout.setColorScheme(R.color.refresh_color_start,
+                R.color.refresh_color_middle_1, 
+                R.color.refresh_color_middle_2, 
+                R.color.refresh_color_end);
+        mRefreshLayout.setOnRefreshListener(this);
+        
         return v;
     }
 
@@ -115,5 +127,26 @@ public class ExtendedListFragment extends SherlockFragment implements OnItemClic
         // to be @overriden  
     }
 
+    @Override
+    public void onRefresh() {
+        // to be @overriden  
+        
+    }
+
+    /**
+     * Enables swipe gesture
+     */
+    public void enableSwipe() {
+        mRefreshLayout.setEnabled(true);
+    }
+    /**
+     * Disables swipe gesture. It prevents manual gestures but keeps the option you show
+     * refreshing programmatically.
+     */
+    public void disableSwipe() {
+        mRefreshLayout.setEnabled(false);
+    }
     
 }