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 as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
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.
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/>.
20 package com
.owncloud
.android
.ui
;
22 import com
.actionbarsherlock
.app
.SherlockFragment
;
23 import com
.owncloud
.android
.R
;
24 import com
.owncloud
.android
.ui
.fragment
.LocalFileListFragment
;
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
;
36 public class FragmentListView
extends SherlockFragment
implements
37 OnItemClickListener
, OnItemLongClickListener
{
38 protected ExtendedListView mList
;
41 public void onCreate(Bundle savedInstanceState
) {
42 super.onCreate(savedInstanceState
);
45 public void setListAdapter(ListAdapter listAdapter
) {
46 mList
.setAdapter(listAdapter
);
50 public ListView
getListView() {
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);
68 public void onItemClick(AdapterView
<?
> arg0
, View arg1
, int arg2
, long arg3
) {
72 public boolean onItemLongClick(AdapterView
<?
> arg0
, View arg1
, int arg2
,
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.
82 * THe current policy is take as a reference the visible item in the center of the screen.
84 * @return The position in the list of the visible item in the center of the screen.
86 protected int getReferencePosition() {
87 return (mList
.getFirstVisiblePosition() + mList
.getLastVisiblePosition()) / 2;
92 * Sets the visible part of the list from the reference position.
94 * @param position Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()}
96 protected void setReferencePosition(int position
) {
97 mList
.setAndCenterSelection(position
);