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 version 2, 
   7  *   as published by the Free Software Foundation. 
   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
.fragment
; 
  21 import com
.actionbarsherlock
.app
.SherlockFragment
; 
  22 import com
.owncloud
.android
.R
; 
  23 import com
.owncloud
.android
.ui
.ExtendedListView
; 
  24 import com
.owncloud
.android
.utils
.Log_OC
; 
  27 import android
.os
.Bundle
; 
  28 import android
.view
.LayoutInflater
; 
  29 import android
.view
.View
; 
  30 import android
.view
.ViewGroup
; 
  31 import android
.widget
.AdapterView
; 
  32 import android
.widget
.ListAdapter
; 
  33 import android
.widget
.AdapterView
.OnItemClickListener
; 
  34 import android
.widget
.ListView
; 
  37  *  TODO extending SherlockListFragment instead of SherlockFragment  
  39 public class ExtendedListFragment 
extends SherlockFragment 
implements OnItemClickListener 
{ 
  41     private static final String TAG 
= ExtendedListFragment
.class.getSimpleName(); 
  43     private static final String KEY_SAVED_LIST_POSITION 
= "SAVED_LIST_POSITION";  
  45     protected ExtendedListView mList
; 
  47     public void setListAdapter(ListAdapter listAdapter
) { 
  48         mList
.setAdapter(listAdapter
); 
  52     public ListView 
getListView() { 
  58     public View 
onCreateView(LayoutInflater inflater
, ViewGroup container
, Bundle savedInstanceState
) { 
  59         Log_OC
.e(TAG
, "onCreateView"); 
  60         //mList = new ExtendedListView(getActivity()); 
  61         View v 
= inflater
.inflate(R
.layout
.list_fragment
, null
); 
  62         mList 
= (ExtendedListView
)(v
.findViewById(R
.id
.list_root
)); 
  63         mList
.setOnItemClickListener(this); 
  64         //mList.setEmptyView(v.findViewById(R.id.empty_list_view));     // looks like it's not a cool idea  
  65         mList
.setDivider(getResources().getDrawable(R
.drawable
.uploader_list_separator
)); 
  66         mList
.setDividerHeight(1); 
  68         if (savedInstanceState 
!= null
) { 
  69             int referencePosition 
= savedInstanceState
.getInt(KEY_SAVED_LIST_POSITION
); 
  70             setReferencePosition(referencePosition
); 
  78     public void onSaveInstanceState(Bundle savedInstanceState
) { 
  79         super.onSaveInstanceState(savedInstanceState
); 
  80         Log_OC
.e(TAG
, "onSaveInstanceState()"); 
  81         savedInstanceState
.putInt(KEY_SAVED_LIST_POSITION
, getReferencePosition()); 
  86      * Calculates the position of the item that will be used as a reference to reposition the visible items in the list when 
  87      * the device is turned to other position.  
  89      * THe current policy is take as a reference the visible item in the center of the screen.   
  91      * @return      The position in the list of the visible item in the center of the screen. 
  93     protected int getReferencePosition() { 
  95             return (mList
.getFirstVisiblePosition() + mList
.getLastVisiblePosition()) / 2; 
 103      * Sets the visible part of the list from the reference position. 
 105      * @param   position    Reference position previously returned by {@link LocalFileListFragment#getReferencePosition()} 
 107     protected void setReferencePosition(int position
) { 
 109             mList
.setAndCenterSelection(position
); 
 114     public void onItemClick(AdapterView
<?
> arg0
, View arg1
, int arg2
, long arg3
) {