3dbe16daa57bf9dbfa12f4e65370d15cec446c37
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / FragmentListView.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
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.
13 *
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/>.
16 *
17 */
18
19 package com.owncloud.android.ui;
20
21 import com.actionbarsherlock.app.SherlockFragment;
22 import com.owncloud.android.R;
23 import com.owncloud.android.ui.fragment.LocalFileListFragment;
24
25 import android.os.Bundle;
26 import android.view.LayoutInflater;
27 import android.view.View;
28 import android.view.ViewGroup;
29 import android.widget.AdapterView;
30 import android.widget.AdapterView.OnItemLongClickListener;
31 import android.widget.ListAdapter;
32 import android.widget.AdapterView.OnItemClickListener;
33 import android.widget.ListView;
34
35 public class FragmentListView extends SherlockFragment implements
36 OnItemClickListener, OnItemLongClickListener {
37 protected ExtendedListView mList;
38
39 @Override
40 public void onCreate(Bundle savedInstanceState) {
41 super.onCreate(savedInstanceState);
42 }
43
44 public void setListAdapter(ListAdapter listAdapter) {
45 mList.setAdapter(listAdapter);
46 mList.invalidate();
47 }
48
49 public ListView getListView() {
50 return mList;
51 }
52
53 @Override
54 public View onCreateView(LayoutInflater inflater, ViewGroup container,
55 Bundle savedInstanceState) {
56 //mList = new ExtendedListView(getActivity());
57 View v = inflater.inflate(R.layout.list_fragment, null);
58 mList = (ExtendedListView)(v.findViewById(R.id.list_root));
59 mList.setOnItemClickListener(this);
60 mList.setOnItemLongClickListener(this);
61 //mList.setEmptyView(v.findViewById(R.id.empty_list_view)); // looks like it's not a cool idea
62 mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
63 mList.setDividerHeight(1);
64 return v;
65 }
66
67 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
68 }
69
70 @Override
71 public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
72 long arg3) {
73 return false;
74 }
75
76
77 /**
78 * Calculates the position of the item that will be used as a reference to reposition the visible items in the list when
79 * the device is turned to other position.
80 *
81 * THe current policy is take as a reference the visible item in the center of the screen.
82 *
83 * @return The position in the list of the visible item in the center of the screen.
84 */
85 protected int getReferencePosition() {
86 return (mList.getFirstVisiblePosition() + mList.getLastVisiblePosition()) / 2;
87 }
88
89
90 /**
91 * Sets the visible part of the list from the reference position.
92 *
93 * @param position Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()}
94 */
95 protected void setReferencePosition(int position) {
96 mList.setAndCenterSelection(position);
97 }
98
99
100 }