Added help text in background of empty files list
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / FragmentListView.java
1 package com.owncloud.android.ui;
2
3 import com.actionbarsherlock.app.SherlockFragment;
4 import com.owncloud.android.R;
5 import com.owncloud.android.ui.fragment.LocalFileListFragment;
6
7 import android.os.Bundle;
8 import android.view.LayoutInflater;
9 import android.view.View;
10 import android.view.ViewGroup;
11 import android.widget.AdapterView;
12 import android.widget.AdapterView.OnItemLongClickListener;
13 import android.widget.ListAdapter;
14 import android.widget.AdapterView.OnItemClickListener;
15 import android.widget.ListView;
16
17 public class FragmentListView extends SherlockFragment implements
18 OnItemClickListener, OnItemLongClickListener {
19 protected ExtendedListView mList;
20
21 @Override
22 public void onCreate(Bundle savedInstanceState) {
23 super.onCreate(savedInstanceState);
24 }
25
26 public void setListAdapter(ListAdapter listAdapter) {
27 mList.setAdapter(listAdapter);
28 mList.invalidate();
29 }
30
31 public ListView getListView() {
32 return mList;
33 }
34
35 @Override
36 public View onCreateView(LayoutInflater inflater, ViewGroup container,
37 Bundle savedInstanceState) {
38 //mList = new ExtendedListView(getActivity());
39 View v = inflater.inflate(R.layout.list_fragment, null);
40 mList = (ExtendedListView)(v.findViewById(R.id.list_root));
41 mList.setOnItemClickListener(this);
42 mList.setOnItemLongClickListener(this);
43 mList.setEmptyView(v.findViewById(R.id.empty_list_view));
44 mList.setDivider(getResources().getDrawable(R.drawable.uploader_list_separator));
45 mList.setDividerHeight(1);
46 return v;
47 }
48
49 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
50 }
51
52 @Override
53 public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
54 long arg3) {
55 return false;
56 }
57
58
59 /**
60 * Calculates the position of the item that will be used as a reference to reposition the visible items in the list when
61 * the device is turned to other position.
62 *
63 * THe current policy is take as a reference the visible item in the center of the screen.
64 *
65 * @return The position in the list of the visible item in the center of the screen.
66 */
67 protected int getReferencePosition() {
68 return (mList.getFirstVisiblePosition() + mList.getLastVisiblePosition()) / 2;
69 }
70
71
72 /**
73 * Sets the visible part of the list from the reference position.
74 *
75 * @param position Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()}
76 */
77 protected void setReferencePosition(int position) {
78 mList.setAndCenterSelection(position);
79 }
80
81
82 }