1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
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.
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
;
21 import com
.actionbarsherlock
.app
.SherlockFragment
;
22 import com
.owncloud
.android
.R
;
23 import com
.owncloud
.android
.ui
.fragment
.LocalFileListFragment
;
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
;
35 public class FragmentListView
extends SherlockFragment
implements
36 OnItemClickListener
, OnItemLongClickListener
{
37 protected ExtendedListView mList
;
40 public void onCreate(Bundle savedInstanceState
) {
41 super.onCreate(savedInstanceState
);
44 public void setListAdapter(ListAdapter listAdapter
) {
45 mList
.setAdapter(listAdapter
);
49 public ListView
getListView() {
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);
67 public void onItemClick(AdapterView
<?
> arg0
, View arg1
, int arg2
, long arg3
) {
71 public boolean onItemLongClick(AdapterView
<?
> arg0
, View arg1
, int arg2
,
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.
81 * THe current policy is take as a reference the visible item in the center of the screen.
83 * @return The position in the list of the visible item in the center of the screen.
85 protected int getReferencePosition() {
86 return (mList
.getFirstVisiblePosition() + mList
.getLastVisiblePosition()) / 2;
91 * Sets the visible part of the list from the reference position.
93 * @param position Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()}
95 protected void setReferencePosition(int position
) {
96 mList
.setAndCenterSelection(position
);