1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package net.sourceforge.subsonic.androidapp.util; |
17 |
|
|
18 |
|
import android.database.DataSetObserver; |
19 |
|
import android.view.View; |
20 |
|
import android.view.ViewGroup; |
21 |
|
import android.widget.BaseAdapter; |
22 |
|
import android.widget.ListAdapter; |
23 |
|
|
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.List; |
26 |
|
import java.util.Arrays; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
|
|
| 88,9% |
Uncovered Elements: 9 (81) |
Complexity: 21 |
Complexity Density: 0,39 |
|
37 |
|
public class MergeAdapter extends BaseAdapter { |
38 |
|
|
39 |
|
private final CascadeDataSetObserver observer = new CascadeDataSetObserver(); |
40 |
|
private final ArrayList<ListAdapter> pieces = new ArrayList<ListAdapter>(); |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
16
|
public MergeAdapter() {... |
46 |
16
|
super(); |
47 |
|
} |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
@param |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
55 |
35
|
public void addAdapter(ListAdapter adapter) {... |
56 |
35
|
pieces.add(adapter); |
57 |
35
|
adapter.registerDataSetObserver(observer); |
58 |
|
} |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
60 |
0
|
public void removeAdapter(ListAdapter adapter) {... |
61 |
0
|
adapter.unregisterDataSetObserver(observer); |
62 |
0
|
pieces.remove(adapter); |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@param |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
2
|
public ListAdapter addView(View view) {... |
72 |
2
|
return addView(view, false); |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
@param |
80 |
|
@param |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
15
|
public ListAdapter addView(View view, boolean enabled) {... |
83 |
15
|
return addViews(Arrays.asList(view), enabled); |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
@param |
91 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
92 |
0
|
public ListAdapter addViews(List<View> views) {... |
93 |
0
|
return addViews(views, false); |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
@param |
101 |
|
@param |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0,67 |
|
103 |
33
|
public ListAdapter addViews(List<View> views, boolean enabled) {... |
104 |
33
|
ListAdapter adapter = enabled ? new EnabledSackAdapter(views) : new SackOfViewsAdapter(views); |
105 |
33
|
addAdapter(adapter); |
106 |
33
|
return adapter; |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
|
@param |
114 |
|
|
|
|
| 87,5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
115 |
2
|
@Override... |
116 |
|
public Object getItem(int position) { |
117 |
2
|
for (ListAdapter piece : pieces) { |
118 |
6
|
int size = piece.getCount(); |
119 |
|
|
120 |
6
|
if (position < size) { |
121 |
2
|
return (piece.getItem(position)); |
122 |
|
} |
123 |
|
|
124 |
4
|
position -= size; |
125 |
|
} |
126 |
|
|
127 |
0
|
return (null); |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
134 |
172
|
@Override... |
135 |
|
public int getCount() { |
136 |
172
|
int total = 0; |
137 |
|
|
138 |
172
|
for (ListAdapter piece : pieces) { |
139 |
380
|
total += piece.getCount(); |
140 |
|
} |
141 |
|
|
142 |
172
|
return (total); |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0,25 |
|
149 |
16
|
@Override... |
150 |
|
public int getViewTypeCount() { |
151 |
16
|
int total = 0; |
152 |
|
|
153 |
16
|
for (ListAdapter piece : pieces) { |
154 |
35
|
total += piece.getViewTypeCount(); |
155 |
|
} |
156 |
|
|
157 |
16
|
return (Math.max(total, 1)); |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
@param |
165 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0,2 |
|
166 |
340
|
@Override... |
167 |
|
public int getItemViewType(int position) { |
168 |
340
|
int typeOffset = 0; |
169 |
340
|
int result = -1; |
170 |
|
|
171 |
340
|
for (ListAdapter piece : pieces) { |
172 |
811
|
int size = piece.getCount(); |
173 |
|
|
174 |
811
|
if (position < size) { |
175 |
340
|
result = typeOffset + piece.getItemViewType(position); |
176 |
340
|
break; |
177 |
|
} |
178 |
|
|
179 |
471
|
position -= size; |
180 |
471
|
typeOffset += piece.getViewTypeCount(); |
181 |
|
} |
182 |
|
|
183 |
340
|
return (result); |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
190 |
16
|
@Override... |
191 |
|
public boolean areAllItemsEnabled() { |
192 |
16
|
return (false); |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
@param |
200 |
|
|
|
|
| 87,5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
201 |
2541
|
@Override... |
202 |
|
public boolean isEnabled(int position) { |
203 |
2541
|
for (ListAdapter piece : pieces) { |
204 |
6569
|
int size = piece.getCount(); |
205 |
|
|
206 |
6569
|
if (position < size) { |
207 |
2541
|
return (piece.isEnabled(position)); |
208 |
|
} |
209 |
|
|
210 |
4028
|
position -= size; |
211 |
|
} |
212 |
|
|
213 |
0
|
return (false); |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
@param |
221 |
|
@param |
222 |
|
@param |
223 |
|
|
|
|
| 87,5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
224 |
80
|
@Override... |
225 |
|
public View getView(int position, View convertView, |
226 |
|
ViewGroup parent) { |
227 |
80
|
for (ListAdapter piece : pieces) { |
228 |
186
|
int size = piece.getCount(); |
229 |
|
|
230 |
186
|
if (position < size) { |
231 |
|
|
232 |
80
|
return (piece.getView(position, convertView, parent)); |
233 |
|
} |
234 |
|
|
235 |
106
|
position -= size; |
236 |
|
} |
237 |
|
|
238 |
0
|
return (null); |
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
@param |
246 |
|
|
|
|
| 87,5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0,33 |
|
247 |
24
|
@Override... |
248 |
|
public long getItemId(int position) { |
249 |
24
|
for (ListAdapter piece : pieces) { |
250 |
42
|
int size = piece.getCount(); |
251 |
|
|
252 |
42
|
if (position < size) { |
253 |
24
|
return (piece.getItemId(position)); |
254 |
|
} |
255 |
|
|
256 |
18
|
position -= size; |
257 |
|
} |
258 |
|
|
259 |
0
|
return (-1); |
260 |
|
} |
261 |
|
|
|
|
| 66,7% |
Uncovered Elements: 2 (6) |
Complexity: 3 |
Complexity Density: 1 |
|
262 |
|
private static class EnabledSackAdapter extends SackOfViewsAdapter { |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
263 |
23
|
public EnabledSackAdapter(List<View> views) {... |
264 |
23
|
super(views); |
265 |
|
} |
266 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
267 |
0
|
@Override... |
268 |
|
public boolean areAllItemsEnabled() { |
269 |
0
|
return (true); |
270 |
|
} |
271 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
272 |
2067
|
@Override... |
273 |
|
public boolean isEnabled(int position) { |
274 |
2067
|
return (true); |
275 |
|
} |
276 |
|
} |
277 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
278 |
|
private class CascadeDataSetObserver extends DataSetObserver { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
279 |
0
|
@Override... |
280 |
|
public void onChanged() { |
281 |
0
|
notifyDataSetChanged(); |
282 |
|
} |
283 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
284 |
0
|
@Override... |
285 |
|
public void onInvalidated() { |
286 |
0
|
notifyDataSetInvalidated(); |
287 |
|
} |
288 |
|
} |
289 |
|
} |
290 |
|
|