Revision 01340459 src/com/rackspacecloud/android/AddMoreNodesActivity.java
b/src/com/rackspacecloud/android/AddMoreNodesActivity.java | ||
---|---|---|
128 | 128 |
finish(); |
129 | 129 |
} |
130 | 130 |
|
131 |
//When a list item is click just change the checkbox state |
|
132 |
//and then the checkbox's onClick will be performed |
|
133 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
|
134 |
if (servers != null && servers.size() > 0) { |
|
135 |
LinearLayout linear = (LinearLayout) findViewById(R.id.nodes_linear_layout); |
|
136 |
ListView serversList = (ListView) linear.findViewById(android.R.id.list); |
|
137 |
View row = serversList.getChildAt(position); |
|
138 |
CheckBox checkBox = (CheckBox)row.findViewById(R.id.add_node_checkbox); |
|
139 |
if(!checkBox.isChecked()){ |
|
140 |
//if the checkbox was not previously checked, treat the listItemClick |
|
141 |
//the same as checking the checkbox |
|
142 |
checkBox.setChecked(!checkBox.isChecked()); |
|
143 |
} else { |
|
144 |
//if the checkbox was already checked when the listItemClick occurred, |
|
145 |
//then treat it like an edit |
|
146 |
|
|
147 |
Server server = servers.get(position); |
|
148 |
|
|
149 |
//Need to put all the ip's of the server into one |
|
150 |
//list so they can all be displayed in one spinner |
|
151 |
String[] ipAddresses = getAllIpsOfServer(server); |
|
152 |
|
|
153 |
Node node = getNodeFromServer(server); |
|
154 |
|
|
155 |
lastCheckedPos = position; |
|
156 |
Intent viewIntent = new Intent(getContext(), AddNodeActivity.class); |
|
157 |
viewIntent.putExtra("ipAddresses", ipAddresses); |
|
158 |
viewIntent.putExtra("name", server.getName()); |
|
159 |
if(node != null){ |
|
160 |
viewIntent.putExtra("node", node); |
|
161 |
} |
|
162 |
//weighted is false, because on initial node add |
|
163 |
//weight is not option |
|
164 |
viewIntent.putExtra("weighted", false); |
|
165 |
startActivityForResult(viewIntent, ADD_NODE_CODE); |
|
166 |
} |
|
167 |
|
|
168 |
} |
|
169 |
} |
|
170 |
|
|
131 | 171 |
private void displayNoServersCell() { |
132 | 172 |
String a[] = new String[1]; |
133 | 173 |
a[0] = "No Servers"; |
... | ... | |
413 | 453 |
return false; |
414 | 454 |
} |
415 | 455 |
|
456 |
//returns the node that is using an ip from server |
|
457 |
private Node getNodeFromServer(Server server){ |
|
458 |
for(Node node : nodesToAdd){ |
|
459 |
if(serverHasIp(server, node.getAddress())){ |
|
460 |
return node; |
|
461 |
} |
|
462 |
} |
|
463 |
return null; |
|
464 |
} |
|
465 |
|
|
466 |
//returns an array of all the ip's of server |
|
467 |
private String[] getAllIpsOfServer(Server server){ |
|
468 |
String[] publicIp = server.getPublicIpAddresses(); |
|
469 |
String[] privateIp = server.getPrivateIpAddresses(); |
|
470 |
if(publicIp == null){ |
|
471 |
publicIp = new String[0]; |
|
472 |
} |
|
473 |
if(privateIp == null){ |
|
474 |
privateIp = new String[0]; |
|
475 |
} |
|
476 |
String[] ipAddresses = new String[privateIp.length + publicIp.length]; |
|
477 |
for(int i = 0; i < privateIp.length; i++){ |
|
478 |
ipAddresses[i] = privateIp[i]; |
|
479 |
} |
|
480 |
for(int i = 0; i < publicIp.length; i++){ |
|
481 |
ipAddresses[i+privateIp.length] = publicIp[i]; |
|
482 |
} |
|
483 |
|
|
484 |
return ipAddresses; |
|
485 |
} |
|
486 |
|
|
416 | 487 |
protected void onActivityResult(int requestCode, int resultCode, Intent data){ |
417 | 488 |
int pos = lastCheckedPos; |
418 | 489 |
if(requestCode == ADD_NODE_CODE && resultCode == RESULT_OK){ |
419 |
Node node = new Node(); |
|
420 |
node.setAddress(data.getStringExtra("nodeIp")); |
|
421 |
node.setCondition(data.getStringExtra("nodeCondition")); |
|
422 |
node.setName(servers.get(pos).getName()); |
|
423 |
node.setPort(data.getStringExtra("nodePort")); |
|
424 |
Log.d("info", "setting the weight in addmore to " + data.getStringExtra("nodeWeight")); |
|
425 |
node.setWeight(data.getStringExtra("nodeWeight")); |
|
426 |
nodesToAdd.add(node); |
|
490 |
//data will be null is user back out on edit |
|
491 |
//we dont need to do anything then |
|
492 |
//if new node added data won't be null |
|
493 |
//so create the new node and add it to the list |
|
494 |
if(data != null){ |
|
495 |
Node node = new Node(); |
|
496 |
node.setAddress(data.getStringExtra("nodeIp")); |
|
497 |
node.setCondition(data.getStringExtra("nodeCondition")); |
|
498 |
node.setName(servers.get(pos).getName()); |
|
499 |
node.setPort(data.getStringExtra("nodePort")); |
|
500 |
node.setWeight(data.getStringExtra("nodeWeight")); |
|
501 |
nodesToAdd.add(node); |
|
502 |
} |
|
427 | 503 |
} |
428 | 504 |
else if(requestCode == ADD_NODE_CODE && resultCode == RESULT_CANCELED){ |
429 | 505 |
//uncheck the node at lastCheckedPos |
Also available in: Unified diff