blob: 441763d09b461311d3fbdfa3a3a99c738fe8d793 (
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
|
package se.leap.leapclient;
import java.util.List;
import java.lang.reflect.Array;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TwoLineListItem;
public class ProviderListAdapter<T> extends ArrayAdapter<T> {
T[] items = null;
boolean[] hidden = null;
public void hide(int position) {
hidden[getRealPosition(position)] = true;
notifyDataSetChanged();
notifyDataSetInvalidated();
}
public void unHide(int position) {
hidden[getRealPosition(position)] = false;
notifyDataSetChanged();
notifyDataSetInvalidated();
}
private int getRealPosition(int position) {
int hElements = getHiddenCountUpTo(position);
int diff = 0;
for(int i=0;i<hElements;i++) {
diff++;
if(hidden[position+diff])
i--;
}
return (position + diff);
}
private int getHiddenCount() {
int count = 0;
for(int i=0;i<items.length;i++)
if(hidden[i])
count++;
return count;
}
private int getHiddenCountUpTo(int location) {
int count = 0;
for(int i=0;i<=location;i++) {
if(hidden[i])
count++;
}
return count;
}
@Override
public int getCount() {
return (items.length - getHiddenCount());
}
public ProviderListAdapter(Context mContext, int layout, List<T> objects) {
super(mContext, layout, objects);
items = objects.toArray((T[])new Object[0]);
hidden = new boolean[items.length];
for (int i = 0; i < items.length; i++)
hidden[i] = false;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TwoLineListItem row;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = (TwoLineListItem)inflater.inflate(android.R.layout.simple_list_item_2, null);
} else {
row = (TwoLineListItem)convertView;
}
ProviderListContent.ProviderItem data = ProviderListContent.ITEMS.get(position);
row.getText1().setText(data.domain);
row.getText2().setText(data.name);
return row;
}
}
|