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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
package se.leap.bitmaskclient;
import java.util.List;
import android.content.Context;
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> {
private static 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();
}
public void unHideAll() {
for (int provider_index = 0; provider_index < hidden.length; provider_index++)
hidden[provider_index] = false;
}
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<hidden.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 (hidden.length - getHiddenCount());
}
public ProviderListAdapter(Context mContext, int layout, List<T> objects) {
super(mContext, layout, objects);
if(hidden == null) {
hidden = new boolean[objects.size()];
for (int i = 0; i < objects.size(); i++)
hidden[i] = false;
}
}
public ProviderListAdapter(Context mContext, int layout, List<T> objects, boolean show_all_providers) {
super(mContext, layout, objects);
if(show_all_providers) {
hidden = new boolean[objects.size()];
for (int i = 0; i < objects.size(); i++)
hidden[i] = false;
}
}
@Override
public void add(T item) {
super.add(item);
boolean[] new_hidden = new boolean[hidden.length+1];
System.arraycopy(hidden, 0, new_hidden, 0, hidden.length);
new_hidden[hidden.length] = false;
hidden = new_hidden;
}
@Override
public void remove(T item) {
super.remove(item);
boolean[] new_hidden = new boolean[hidden.length-1];
System.arraycopy(hidden, 0, new_hidden, 0, hidden.length-1);
hidden = new_hidden;
}
@Override
public View getView(int index, View convertView, ViewGroup parent) {
TwoLineListItem row;
int position = getRealPosition(index);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = (TwoLineListItem)inflater.inflate(R.layout.provider_list_item, null);
} else {
row = (TwoLineListItem)convertView;
}
ProviderListContent.ProviderItem data = ProviderListContent.ITEMS.get(position);
row.getText1().setText(data.domain());
row.getText2().setText(data.name());
return row;
}
}
|