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