Revision 4f9d1a69 src/com/rackspacecloud/android/AddNodesActivity.java
b/src/com/rackspacecloud/android/AddNodesActivity.java | ||
---|---|---|
20 | 20 |
import android.util.Log; |
21 | 21 |
import android.view.LayoutInflater; |
22 | 22 |
import android.view.View; |
23 |
import android.view.View.OnClickListener; |
|
23 | 24 |
import android.view.ViewGroup; |
24 | 25 |
import android.view.WindowManager; |
25 | 26 |
import android.view.ViewGroup.LayoutParams; |
26 | 27 |
import android.widget.ArrayAdapter; |
28 |
import android.widget.Button; |
|
27 | 29 |
import android.widget.CheckBox; |
28 | 30 |
import android.widget.CompoundButton; |
31 |
import android.widget.LinearLayout; |
|
29 | 32 |
import android.widget.ListView; |
30 | 33 |
import android.widget.CompoundButton.OnCheckedChangeListener; |
31 | 34 |
import android.widget.ImageView; |
... | ... | |
35 | 38 |
public class AddNodesActivity extends ListActivity { |
36 | 39 |
|
37 | 40 |
private static final int ADD_NODE_CODE = 178; |
41 |
|
|
38 | 42 |
private Server[] servers; |
39 | 43 |
private Context context; |
40 | 44 |
private int lastCheckedPos; |
... | ... | |
44 | 48 |
@Override |
45 | 49 |
public void onCreate(Bundle savedInstanceState) { |
46 | 50 |
super.onCreate(savedInstanceState); |
51 |
nodes = (ArrayList<Node>) this.getIntent().getExtras().get("nodes"); |
|
47 | 52 |
setContentView(R.layout.addnodes); |
48 | 53 |
restoreState(savedInstanceState); |
49 | 54 |
} |
50 |
|
|
55 |
|
|
51 | 56 |
@Override |
52 | 57 |
protected void onSaveInstanceState(Bundle outState) { |
53 | 58 |
super.onSaveInstanceState(outState); |
54 | 59 |
outState.putSerializable("nodes", nodes); |
55 | 60 |
} |
61 |
|
|
62 |
private void print(ArrayList<Node> nodes){ |
|
63 |
for(Node n : nodes){ |
|
64 |
Log.d("info", "the node is " + n.getName()); |
|
65 |
} |
|
66 |
} |
|
56 | 67 |
|
57 | 68 |
private void restoreState(Bundle state) { |
69 |
|
|
58 | 70 |
context = getApplicationContext(); |
59 | 71 |
|
60 |
if (state != null && state.containsKey("node")){ |
|
72 |
if(nodes != null){ |
|
73 |
print(nodes); |
|
74 |
} |
|
75 |
|
|
76 |
if (state != null && state.containsKey("nodes")){ |
|
61 | 77 |
nodes = (ArrayList<Node>) state.getSerializable("nodes"); |
62 | 78 |
if(nodes == null){ |
63 | 79 |
nodes = new ArrayList<Node>(); |
64 | 80 |
} |
65 | 81 |
} |
66 |
else{ |
|
67 |
nodes = new ArrayList<Node>(); |
|
68 |
} |
|
69 |
|
|
82 |
|
|
70 | 83 |
if (state != null && state.containsKey("server")) { |
71 | 84 |
servers = (Server[]) state.getSerializable("servers"); |
72 | 85 |
if (servers.length == 0) { |
... | ... | |
78 | 91 |
} else { |
79 | 92 |
loadServers(); |
80 | 93 |
} |
94 |
|
|
95 |
Button submitNodes = (Button) findViewById(R.id.submit_nodes_button); |
|
96 |
submitNodes.setOnClickListener(new OnClickListener() { |
|
97 |
|
|
98 |
@Override |
|
99 |
public void onClick(View v) { |
|
100 |
Intent viewIntent = new Intent(); |
|
101 |
viewIntent.putExtra("nodes", nodes); |
|
102 |
setResult(RESULT_OK, viewIntent); |
|
103 |
finish(); |
|
104 |
} |
|
105 |
}); |
|
106 |
} |
|
107 |
|
|
108 |
@Override |
|
109 |
public void onBackPressed(){ |
|
110 |
setResult(RESULT_CANCELED); |
|
111 |
finish(); |
|
81 | 112 |
} |
82 | 113 |
|
83 | 114 |
private void displayNoServersCell() { |
... | ... | |
175 | 206 |
|
176 | 207 |
public View getView(int position, View convertView, ViewGroup parent) { |
177 | 208 |
|
178 |
Server server = servers[position]; |
|
209 |
final Server server = servers[position];
|
|
179 | 210 |
LayoutInflater inflater = getLayoutInflater(); |
180 | 211 |
View row = inflater.inflate(R.layout.listservernodecell, parent, false); |
181 | 212 |
|
... | ... | |
190 | 221 |
|
191 | 222 |
String[] publicIp = server.getPublicIpAddresses(); |
192 | 223 |
String[] privateIp = server.getPrivateIpAddresses(); |
193 |
|
|
194 |
/* |
|
224 |
|
|
225 |
|
|
195 | 226 |
final String[] ipAddresses = new String[privateIp.length + publicIp.length]; |
196 | 227 |
for(int i = 0; i < privateIp.length; i++){ |
197 | 228 |
ipAddresses[i] = privateIp[i]; |
... | ... | |
200 | 231 |
ipAddresses[i+privateIp.length] = publicIp[i]; |
201 | 232 |
} |
202 | 233 |
|
203 |
Log.d("info", "The lenght 1 is " + ipAddresses.length); |
|
204 |
|
|
205 | 234 |
final int pos = position; |
206 | 235 |
CheckBox add = (CheckBox) row.findViewById(R.id.add_node_checkbox); |
236 |
|
|
237 |
if(inNodeList(server)){ |
|
238 |
add.setChecked(true); |
|
239 |
} |
|
240 |
|
|
207 | 241 |
add.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
208 |
|
|
242 |
|
|
209 | 243 |
@Override |
210 | 244 |
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
211 | 245 |
if(isChecked){ |
... | ... | |
215 | 249 |
startActivityForResult(viewIntent, ADD_NODE_CODE); |
216 | 250 |
} |
217 | 251 |
else{ |
218 |
removeNodeFromList(server[pos]);
|
|
252 |
removeNodeFromList(server); |
|
219 | 253 |
} |
220 |
|
|
221 | 254 |
} |
222 | 255 |
}); |
223 |
*/ |
|
256 |
|
|
224 | 257 |
return(row); |
225 | 258 |
} |
226 | 259 |
} |
227 | 260 |
|
228 |
@Override |
|
229 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
|
230 |
|
|
231 |
Log.d("info", "captin clicked"); |
|
232 |
|
|
233 |
Server server = servers[position]; |
|
234 |
LayoutInflater inflater = getLayoutInflater(); |
|
235 |
View row = inflater.inflate(R.layout.listservernodecell, l, false); |
|
236 |
|
|
237 |
String[] publicIp = server.getPublicIpAddresses(); |
|
238 |
String[] privateIp = server.getPrivateIpAddresses(); |
|
239 |
|
|
240 |
|
|
241 |
final String[] ipAddresses = new String[privateIp.length + publicIp.length]; |
|
242 |
for(int i = 0; i < privateIp.length; i++){ |
|
243 |
ipAddresses[i] = privateIp[i]; |
|
244 |
} |
|
245 |
for(int i = 0; i < publicIp.length; i++){ |
|
246 |
ipAddresses[i+privateIp.length] = publicIp[i]; |
|
247 |
} |
|
248 |
|
|
249 |
|
|
250 |
CheckBox add = (CheckBox) row.findViewById(R.id.add_node_checkbox); |
|
251 |
|
|
252 |
Log.d("info", "captin the checkbox is checked: " + add.isChecked()); |
|
253 |
add.setChecked(!add.isChecked()); |
|
254 |
Log.d("info", "captin the checkbox is checked: " + add.isChecked()); |
|
255 |
|
|
256 |
if(add.isChecked()){ |
|
257 |
lastCheckedPos = position; |
|
258 |
Intent viewIntent = new Intent(context, AddNodeActivity.class); |
|
259 |
viewIntent.putExtra("ipAddresses", ipAddresses); |
|
260 |
startActivityForResult(viewIntent, ADD_NODE_CODE); |
|
261 |
} |
|
262 |
else{ |
|
263 |
removeNodeFromList(server); |
|
261 |
private boolean inNodeList(Server server){ |
|
262 |
Log.d("info", "the server is " + server.getName()); |
|
263 |
for(Node node : nodes){ |
|
264 |
Log.d("info", "the node is " + node.getName()); |
|
265 |
String nodeIp = node.getAddress(); |
|
266 |
if(serverHasIp(server, nodeIp)){ |
|
267 |
return true; |
|
268 |
} |
|
264 | 269 |
} |
265 |
}
|
|
266 |
|
|
267 |
|
|
270 |
return false;
|
|
271 |
} |
|
272 |
|
|
268 | 273 |
/* |
269 | 274 |
* need to remove by id because that is |
270 | 275 |
* what is unique |
... | ... | |
278 | 283 |
} |
279 | 284 |
} |
280 | 285 |
} |
281 |
|
|
286 |
|
|
282 | 287 |
private boolean serverHasIp(Server server, String address){ |
283 | 288 |
String[] addresses = server.getPrivateIpAddresses(); |
284 | 289 |
for(int i = 0; i < addresses.length; i++){ |
... | ... | |
296 | 301 |
} |
297 | 302 |
|
298 | 303 |
protected void onActivityResult(int requestCode, int resultCode, Intent data){ |
299 |
if(requestCode == ADD_NODE_CODE && resultCode == 111){
|
|
300 |
int pos = lastCheckedPos;
|
|
304 |
int pos = lastCheckedPos;
|
|
305 |
if(requestCode == ADD_NODE_CODE && resultCode == RESULT_OK){
|
|
301 | 306 |
Node node = new Node(); |
302 | 307 |
node.setAddress(data.getStringExtra("nodeIp")); |
303 | 308 |
node.setCondition(data.getStringExtra("nodeCondition")); |
... | ... | |
305 | 310 |
node.setPort(data.getStringExtra("nodePort")); |
306 | 311 |
nodes.add(node); |
307 | 312 |
} |
308 |
else if(requestCode == ADD_NODE_CODE && resultCode == 112){ |
|
309 |
//Node not added so do thing |
|
313 |
else if(requestCode == ADD_NODE_CODE && resultCode == RESULT_CANCELED){ |
|
314 |
//uncheck the node at lastCheckedPos |
|
315 |
LinearLayout linear = (LinearLayout) findViewById(R.id.nodes_linear_layout); |
|
316 |
ListView serversList = (ListView) linear.findViewById(android.R.id.list); |
|
317 |
View row = serversList.getChildAt(pos); |
|
318 |
CheckBox checkBox = (CheckBox)row.findViewById(R.id.add_node_checkbox); |
|
319 |
checkBox.setChecked(false); |
|
310 | 320 |
} |
311 | 321 |
} |
312 | 322 |
|
Also available in: Unified diff