blob: 6f7f58798916309f950e0a03c05d72a08aa3684b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package cgeo.geocaching.ui;
import butterknife.InjectView;
import cgeo.geocaching.R;
import cgeo.geocaching.files.IFileSelectionView;
import cgeo.geocaching.utils.Log;
import android.app.Activity;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import java.io.File;
import java.util.List;
public class FileSelectionListAdapter extends ArrayAdapter<File> {
private final IFileSelectionView parentView;
private final LayoutInflater inflater;
public FileSelectionListAdapter(final IFileSelectionView parentIn, final List<File> listIn) {
super(parentIn.getContext(), 0, listIn);
parentView = parentIn;
inflater = ((Activity) getContext()).getLayoutInflater();
}
@Override
public View getView(final int position, final View rowView, final ViewGroup parent) {
if (position > getCount()) {
Log.w("FileSelectionListAdapter.getView: Attempt to access missing item #" + position);
return null;
}
final File file = getItem(position);
View v = rowView;
final ViewHolder holder;
if (v == null) {
v = inflater.inflate(R.layout.mapfile_item, parent, false);
holder = new ViewHolder(v);
} else {
holder = (ViewHolder) v.getTag();
}
final String currentFile = parentView.getCurrentFile();
if (currentFile != null && file.equals(new File(currentFile))) {
holder.filename.setTypeface(holder.filename.getTypeface(), Typeface.BOLD);
} else {
holder.filename.setTypeface(holder.filename.getTypeface(), Typeface.NORMAL);
}
final TouchListener touchLst = new TouchListener(file);
v.setOnClickListener(touchLst);
holder.filepath.setText(file.getParent());
holder.filename.setText(file.getName());
return v;
}
private class TouchListener implements View.OnClickListener {
private File file = null;
public TouchListener(final File fileIn) {
file = fileIn;
}
// tap on item
@Override
public void onClick(final View view) {
parentView.setCurrentFile(file.toString());
parentView.close();
}
}
protected static final class ViewHolder extends AbstractViewHolder {
@InjectView(R.id.mapfilepath) protected TextView filepath;
@InjectView(R.id.mapfilename) protected TextView filename;
public ViewHolder(final View view) {
super(view);
}
}
}
|