1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.ui
.fragment
;
21 import android
.os
.Bundle
;
22 import android
.support
.v4
.widget
.SwipeRefreshLayout
;
23 import android
.view
.LayoutInflater
;
24 import android
.view
.View
;
25 import android
.view
.ViewGroup
;
26 import android
.widget
.AdapterView
;
27 import android
.widget
.AdapterView
.OnItemClickListener
;
28 import android
.widget
.ListAdapter
;
29 import android
.widget
.ListView
;
30 import android
.widget
.TextView
;
32 import com
.actionbarsherlock
.app
.SherlockFragment
;
33 import com
.owncloud
.android
.R
;
34 import com
.owncloud
.android
.ui
.ExtendedListView
;
35 import com
.owncloud
.android
.utils
.Log_OC
;
38 * TODO extending SherlockListFragment instead of SherlockFragment
40 public class ExtendedListFragment
extends SherlockFragment
implements OnItemClickListener
, SwipeRefreshLayout
.OnRefreshListener
{
42 private static final String TAG
= ExtendedListFragment
.class.getSimpleName();
44 private static final String KEY_SAVED_LIST_POSITION
= "SAVED_LIST_POSITION";
46 protected ExtendedListView mList
;
48 private SwipeRefreshLayout mRefreshLayout
;
49 private TextView mEmptyListMessage
;
51 public void setListAdapter(ListAdapter listAdapter
) {
52 mList
.setAdapter(listAdapter
);
56 public ListView
getListView() {
62 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
, Bundle savedInstanceState
) {
63 Log_OC
.e(TAG
, "onCreateView");
64 //mList = new ExtendedListView(getActivity());
66 View v
= inflater
.inflate(R
.layout
.list_fragment
, null
);
67 mEmptyListMessage
= (TextView
) v
.findViewById(R
.id
.empty_list_view
);
68 mList
= (ExtendedListView
)(v
.findViewById(R
.id
.list_root
));
69 mList
.setOnItemClickListener(this);
70 mList
.setEmptyView(mEmptyListMessage
); // looks like it's not a cool idea
71 mList
.setDivider(getResources().getDrawable(R
.drawable
.uploader_list_separator
));
72 mList
.setDividerHeight(1);
74 if (savedInstanceState
!= null
) {
75 int referencePosition
= savedInstanceState
.getInt(KEY_SAVED_LIST_POSITION
);
76 setReferencePosition(referencePosition
);
80 mRefreshLayout
= (SwipeRefreshLayout
) v
.findViewById(R
.id
.swipe_refresh_files
);
81 // Colors in animations: background
82 mRefreshLayout
.setColorScheme(R
.color
.background_color
, R
.color
.background_color
,
83 R
.color
.background_color
, R
.color
.background_color
);
85 mRefreshLayout
.setOnRefreshListener(this);
92 public void onSaveInstanceState(Bundle savedInstanceState
) {
93 super.onSaveInstanceState(savedInstanceState
);
94 Log_OC
.e(TAG
, "onSaveInstanceState()");
95 savedInstanceState
.putInt(KEY_SAVED_LIST_POSITION
, getReferencePosition());
100 * Calculates the position of the item that will be used as a reference to reposition the visible items in the list when
101 * the device is turned to other position.
103 * THe current policy is take as a reference the visible item in the center of the screen.
105 * @return The position in the list of the visible item in the center of the screen.
107 protected int getReferencePosition() {
109 return (mList
.getFirstVisiblePosition() + mList
.getLastVisiblePosition()) / 2;
117 * Sets the visible part of the list from the reference position.
119 * @param position Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()}
121 protected void setReferencePosition(int position
) {
123 mList
.setAndCenterSelection(position
);
128 public void onItemClick (AdapterView
<?
> parent
, View view
, int position
, long id
) {
133 public void onRefresh() {
135 mRefreshLayout
.setRefreshing(false
);
139 * Enables swipe gesture
141 public void enableSwipe() {
142 mRefreshLayout
.setEnabled(true
);
146 * Disables swipe gesture. It prevents manual gestures but keeps the option you show
147 * refreshing programmatically.
149 public void disableSwipe() {
150 mRefreshLayout
.setEnabled(false
);
154 * It shows the SwipeRefreshLayout progress
156 public void showSwipeProgress() {
157 mRefreshLayout
.setRefreshing(true
);
161 * It shows the SwipeRefreshLayout progress
163 public void hideSwipeProgress() {
164 mRefreshLayout
.setRefreshing(false
);
168 * Set message for empty list view
170 public void setMessageforEmptyView(String message
) {
171 if (mEmptyListMessage
!= null
) {
172 mEmptyListMessage
.setText(message
);
177 * Get the text of EmptyListMessage TextView
181 public String
getEmptyViewText() {
182 return (mEmptyListMessage
!= null
) ? mEmptyListMessage
.getText().toString() : "";