1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2011 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of JSampler. |
7 |
* |
8 |
* JSampler is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License version 2 |
10 |
* as published by the Free Software Foundation. |
11 |
* |
12 |
* JSampler is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with JSampler; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
* MA 02111-1307 USA |
21 |
*/ |
22 |
|
23 |
package org.jsampler.android.view; |
24 |
|
25 |
import net.sf.juife.event.GenericEvent; |
26 |
import net.sf.juife.event.GenericListener; |
27 |
|
28 |
import org.jsampler.CC; |
29 |
|
30 |
import android.content.Context; |
31 |
import android.view.View; |
32 |
import android.view.ViewGroup; |
33 |
import android.widget.Checkable; |
34 |
import android.widget.RadioButton; |
35 |
|
36 |
public class ServerListAdapter extends AbstractListAdapter implements GenericListener { |
37 |
public ServerListAdapter() { |
38 |
CC.getServerList().addChangeListener(this); |
39 |
} |
40 |
|
41 |
public void |
42 |
uninstall() { CC.getServerList().removeChangeListener(this); } |
43 |
|
44 |
private static class ItemView extends RadioButton implements Checkable { |
45 |
|
46 |
public ItemView(Context context) { |
47 |
super(context); |
48 |
} |
49 |
|
50 |
} |
51 |
|
52 |
@Override |
53 |
public void |
54 |
jobDone(GenericEvent e) { notifyDataSetChanged(); } |
55 |
|
56 |
@Override |
57 |
public int |
58 |
getCount() { return CC.getServerList().getServerCount(); } |
59 |
|
60 |
@Override |
61 |
public Object |
62 |
getItem(int position) { return CC.getServerList().getServer(position); } |
63 |
|
64 |
@Override |
65 |
public View |
66 |
getView(int position, View convertView, ViewGroup parent) { |
67 |
ItemView rb; |
68 |
if(convertView != null && convertView instanceof ItemView) { |
69 |
rb = (ItemView) convertView; |
70 |
|
71 |
} else { |
72 |
rb = new ItemView(parent.getContext()); |
73 |
rb.setFocusable(false); |
74 |
rb.setFocusableInTouchMode(false); |
75 |
rb.setClickable(false); |
76 |
} |
77 |
rb.setText(getItem(position).toString()); |
78 |
|
79 |
return rb; |
80 |
} |
81 |
} |