1 /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 package org
.libreoffice
.ui
;
12 import android
.content
.Context
;
13 import android
.util
.Log
;
14 import android
.view
.LayoutInflater
;
15 import android
.view
.View
;
16 import android
.view
.ViewGroup
;
17 import android
.widget
.BaseAdapter
;
18 import android
.widget
.ImageView
;
19 import android
.widget
.TextView
;
21 import org
.libreoffice
.R
;
22 import org
.libreoffice
.storage
.IFile
;
24 import java
.util
.List
;
26 public class GridItemAdapter
extends BaseAdapter
{
28 List
<IFile
> filePaths
;
29 IFile currentDirectory
;
30 String LOGTAG
= "GridItemAdapter";
32 public GridItemAdapter(Context mContext
, IFile currentDirectory
,
33 List
<IFile
> filteredFiles
) {
34 this.mContext
= mContext
;
35 this.currentDirectory
= currentDirectory
;
36 filePaths
= filteredFiles
;
37 Log
.d(LOGTAG
, "currentDirectory.getName(): " + currentDirectory
.getName());
40 public int getCount() {
41 return filePaths
!= null ? filePaths
.size() : 0;
44 public Object
getItem(int position
) {
45 return null; //filePaths[ position ];
48 public long getItemId(int position
) {
49 // TODO Auto-generated method stub
53 public View
getView(int position
, View convertView
, ViewGroup parent
) {
54 LayoutInflater inflater
= (LayoutInflater
) mContext
.getSystemService(
55 Context
.LAYOUT_INFLATER_SERVICE
);
59 if (convertView
== null) {
60 gridView
= new View(mContext
);
62 gridView
= convertView
;
65 // get layout from mobile.xml
66 gridView
= inflater
.inflate(R
.layout
.file_explorer_grid_item
, null);
68 // set value into textview
69 TextView textView
= (TextView
) gridView
70 .findViewById(R
.id
.grid_item_label
);
71 textView
.setText(filePaths
.get(position
).getName());
72 // set image based on selected text
73 ImageView imageView
= (ImageView
) gridView
74 .findViewById(R
.id
.grid_item_image
);
75 if (filePaths
.get(position
).isDirectory()) { // Is a folder
76 // Default view is a generic folder icon.
77 imageView
.setImageResource(R
.drawable
.folder
);
80 File thumbnailFile = new File( filePaths[position].getParent() , "."
81 + filePaths[position].getName().split("[.]")[0] + ".png");
82 BitmapFactory factory = new BitmapFactory();
83 Bitmap thumb = factory.decodeFile( thumbnailFile.getAbsolutePath() );
85 Log.i( "GRID" , "true" );
87 Log.i( "GRID" , thumbnailFile.getAbsolutePath() );
90 switch (FileUtilities
.getType(filePaths
.get(position
).getName()))
92 case FileUtilities
.DOC
:
95 imageView.setImageBitmap( thumb );
99 imageView
.setImageResource(R
.drawable
.writer
);
101 case FileUtilities
.CALC
:
102 imageView
.setImageResource(R
.drawable
.calc
);
104 case FileUtilities
.DRAWING
:
105 imageView
.setImageResource(R
.drawable
.draw
);
107 case FileUtilities
.IMPRESS
:
108 imageView
.setImageResource(R
.drawable
.impress
);
110 case FileUtilities
.UNKNOWN
:
112 break; // FIXME something prettier ?
118 public void update() {
119 this.notifyDataSetChanged();
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */