source: other-projects/tipple-android/trunk-restructured/workspace/tipple-lib/src/org/greenstone/android/tipple/base/TippleLogFileBrowserIconAdapter.java@ 24807

Last change on this file since 24807 was 24807, checked in by davidb, 12 years ago

Reloating base files into 'base' package

  • Property svn:executable set to *
File size: 3.1 KB
Line 
1/*
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Based on FileBrowserIconAdapter.java from mapsforge.org
17 *
18 */
19package org.greenstone.android.tipple.base;
20
21import java.io.File;
22
23import org.greenstone.android.tipple.R;
24
25import android.content.Context;
26import android.view.Gravity;
27import android.view.View;
28import android.view.ViewGroup;
29import android.widget.BaseAdapter;
30import android.widget.TextView;
31
32/**
33 * An adapter for the FileBrowser GridView.
34 */
35class TippleLogFileBrowserIconAdapter extends BaseAdapter
36{
37 private Context context;
38 private File currentFile;
39 private File[] files;
40 private boolean hasParentFolder;
41 private TextView textView;
42
43 /**
44 * Create a new FileBrowserIconAdapter with the given context.
45 *
46 * @param context
47 * the context of this adapter, through which new Views can be created.
48 */
49 TippleLogFileBrowserIconAdapter(Context context) {
50 this.context = context;
51 }
52
53 @Override
54 public int getCount() {
55 if (this.files == null) {
56 return 0;
57 }
58 return this.files.length;
59 }
60
61 @Override
62 public Object getItem(int index) {
63 return this.files[index];
64 }
65
66 @Override
67 public long getItemId(int index) {
68 return index;
69 }
70
71 @Override
72 public View getView(int index, View convertView, ViewGroup parent) {
73 if (convertView instanceof TextView) {
74 // recycle the old view
75 this.textView = (TextView) convertView;
76 } else {
77 // create a new view object
78 this.textView = new TextView(this.context);
79 this.textView.setLines(2);
80 this.textView.setGravity(Gravity.CENTER_HORIZONTAL);
81 this.textView.setPadding(5, 10, 5, 10);
82 }
83
84 if (index == 0 && this.hasParentFolder) {
85 // the parent directory of the current folder
86 this.textView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_menu_back,
87 0, 0);
88 this.textView.setText("..");
89 } else {
90 this.currentFile = this.files[index];
91 if (this.currentFile.isDirectory()) {
92 this.textView.setCompoundDrawablesWithIntrinsicBounds(0,
93 R.drawable.ic_menu_archive, 0, 0);
94 } else {
95 this.textView.setCompoundDrawablesWithIntrinsicBounds(0,
96 R.drawable.ic_menu_mapmode, 0, 0);
97 }
98 this.textView.setText(this.currentFile.getName());
99 }
100 return this.textView;
101 }
102
103 /**
104 * Call this method to change the data of the adapter.
105 *
106 * @param newFiles
107 * the new files for this adapter.
108 * @param newHasParentFolder
109 * true if the files array has a parent folder at index 0, false otherwise.
110 */
111 void updateFiles(File[] newFiles, boolean newHasParentFolder) {
112 this.files = newFiles;
113 this.hasParentFolder = newHasParentFolder;
114 }
115}
Note: See TracBrowser for help on using the repository browser.