Revision c4a37180 src/com/rackspacecloud/android/AddLoadBalancerActivity.java
b/src/com/rackspacecloud/android/AddLoadBalancerActivity.java | ||
---|---|---|
12 | 12 |
import com.rackspace.cloud.loadbalancer.api.client.VirtualIp; |
13 | 13 |
import com.rackspace.cloud.servers.api.client.Account; |
14 | 14 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
15 |
import com.rackspace.cloud.servers.api.client.Server; |
|
15 | 16 |
import com.rackspace.cloud.servers.api.client.http.HttpBundle; |
16 | 17 |
|
17 | 18 |
import android.app.Activity; |
... | ... | |
20 | 21 |
import android.os.Bundle; |
21 | 22 |
import android.text.Editable; |
22 | 23 |
import android.text.TextWatcher; |
24 |
import android.util.Log; |
|
23 | 25 |
import android.view.View; |
24 | 26 |
import android.view.View.OnClickListener; |
25 | 27 |
import android.widget.AdapterView; |
... | ... | |
38 | 40 |
private static final int SHARED_VIP_ACTIVITY_CODE = 235; |
39 | 41 |
|
40 | 42 |
private ArrayList<Node> nodes; |
43 |
private ArrayList<Server> possibleNodes; |
|
41 | 44 |
private LoadBalancer loadBalancer; |
42 | 45 |
private Protocol[] protocols; |
43 | 46 |
private Protocol selectedProtocol; |
... | ... | |
74 | 77 |
else{ |
75 | 78 |
nodes = new ArrayList<Node>(); |
76 | 79 |
} |
80 |
|
|
81 |
if(state != null && state.containsKey("possibleNodes")){ |
|
82 |
possibleNodes = (ArrayList<Server>) state.getSerializable("possibleNodes"); |
|
83 |
} |
|
84 |
else{ |
|
85 |
possibleNodes = new ArrayList<Server>(); |
|
86 |
} |
|
77 | 87 |
|
78 | 88 |
setupText(); |
79 | 89 |
loadProtocolSpinner(); |
... | ... | |
88 | 98 |
protected void onSaveInstanceState(Bundle outState) { |
89 | 99 |
super.onSaveInstanceState(outState); |
90 | 100 |
outState.putSerializable("nodes", nodes); |
101 |
outState.putSerializable("possibleNodes", possibleNodes); |
|
91 | 102 |
} |
92 | 103 |
|
93 | 104 |
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { |
... | ... | |
146 | 157 |
public void onClick(View v) { |
147 | 158 |
Intent viewIntent = new Intent(getApplicationContext(), AddNodesActivity.class); |
148 | 159 |
viewIntent.putExtra("nodes", nodes); |
160 |
viewIntent.putExtra("possibleNodes", possibleNodes); |
|
149 | 161 |
startActivityForResult(viewIntent, ADD_NODES_ACTIVITY_CODE); |
150 | 162 |
} |
151 | 163 |
}); |
... | ... | |
159 | 171 |
//selectedPort = ((EditText)findViewById(R.id.edit_port_text)).getText().toString(); |
160 | 172 |
if(!validName()){ |
161 | 173 |
showAlert("Error", "Load balancer name cannot be blank."); |
162 |
} else if(!validPort()){ |
|
174 |
} else if(!validPort(selectedPort)){
|
|
163 | 175 |
showAlert("Error", "Must have a protocol port number that is between 1 and 65535."); |
164 | 176 |
} else if(!validVip()){ |
165 | 177 |
showAlert("Error", "Please select a valid Virtual IP."); |
... | ... | |
189 | 201 |
return !selectedName.equals(""); |
190 | 202 |
} |
191 | 203 |
|
192 |
private boolean validPort(){ |
|
193 |
return !selectedPort.equals("") && Integer.valueOf(selectedPort) > 0 && Integer.valueOf(selectedPort) < 65536; |
|
204 |
private boolean validPort(String selectedPort){ |
|
205 |
boolean result; |
|
206 |
try{ |
|
207 |
result = !selectedPort.equals("") && Integer.valueOf(selectedPort) > 0 && Integer.valueOf(selectedPort) < 65536; |
|
208 |
} catch (NumberFormatException e){ |
|
209 |
result = false; |
|
210 |
} |
|
211 |
return result; |
|
194 | 212 |
} |
195 | 213 |
|
196 | 214 |
private boolean validNodes(){ |
197 |
return nodes != null && nodes.size() > 0; |
|
198 |
} |
|
199 |
|
|
200 |
private void updateNodesIndicatorLight(){ |
|
201 |
if(validNodes()){ |
|
202 |
selectNodesButton.setCompoundDrawablesWithIntrinsicBounds(0,0,0,0); |
|
203 |
} else { |
|
204 |
selectNodesButton.setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.ic_notification_overlay,0); |
|
215 |
boolean exist = nodes != null && nodes.size() > 0; |
|
216 |
boolean enabled = false; |
|
217 |
for(Node n: nodes){ |
|
218 |
enabled = enabled || n.getCondition().equalsIgnoreCase("enabled"); |
|
205 | 219 |
} |
220 |
return exist && enabled; |
|
206 | 221 |
} |
207 | 222 |
|
208 | 223 |
private boolean validVip(){ |
... | ... | |
218 | 233 |
||(selectedVip != null && !selectedVip.getLoadBalancer().getPort().equals(selectedPort) |
219 | 234 |
&& selectedVip.getLoadBalancer().getRegion().equals(selectedRegion)); |
220 | 235 |
} |
236 |
|
|
237 |
private void updateNodesIndicatorLight(){ |
|
238 |
if(validNodes()){ |
|
239 |
selectNodesButton.setCompoundDrawablesWithIntrinsicBounds(0,0,0,0); |
|
240 |
} else { |
|
241 |
selectNodesButton.setCompoundDrawablesWithIntrinsicBounds(0,0,R.drawable.ic_notification_overlay,0); |
|
242 |
} |
|
243 |
} |
|
221 | 244 |
|
222 | 245 |
private void updateVipIndicatorLight(){ |
223 | 246 |
if(validVip()){ |
... | ... | |
310 | 333 |
|
311 | 334 |
for(int i = 0; i < Algorithm.getAlgorithms().size(); i++){ |
312 | 335 |
algorithms[i] = Algorithm.getAlgorithms().get(i); |
313 |
algorithmNames[i] = Algorithm.getAlgorithms().get(i).getName();
|
|
336 |
algorithmNames[i] = getPrettyAlgoName(Algorithm.getAlgorithms().get(i).getName());
|
|
314 | 337 |
} |
315 | 338 |
|
316 | 339 |
ArrayAdapter<String> algorithmAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, algorithmNames); |
... | ... | |
318 | 341 |
algorithmSpinner.setAdapter(algorithmAdapter); |
319 | 342 |
} |
320 | 343 |
|
344 |
private String getPrettyAlgoName(String name){ |
|
345 |
if(name == null || name.length() == 0){ |
|
346 |
return ""; |
|
347 |
} else { |
|
348 |
String result = name.charAt(0) + ""; |
|
349 |
boolean previousWasSpace = false;; |
|
350 |
for(int i = 1; i < name.length(); i++){ |
|
351 |
char curLetter = name.charAt(i); |
|
352 |
if(curLetter == '_'){ |
|
353 |
result += " "; |
|
354 |
previousWasSpace = true; |
|
355 |
} else { |
|
356 |
if(previousWasSpace){ |
|
357 |
result += Character.toUpperCase(curLetter); |
|
358 |
} else { |
|
359 |
result += Character.toLowerCase(curLetter); |
|
360 |
} |
|
361 |
previousWasSpace = false; |
|
362 |
} |
|
363 |
} |
|
364 |
return result; |
|
365 |
} |
|
366 |
} |
|
367 |
|
|
321 | 368 |
private class AddLoadBalancerTask extends AsyncTask<Void, Void, HttpBundle> { |
322 | 369 |
private CloudServersException exception; |
323 | 370 |
|
... | ... | |
361 | 408 |
} |
362 | 409 |
} |
363 | 410 |
|
411 |
private void printNodes(ArrayList<Node> nodes){ |
|
412 |
for(Node n : nodes){ |
|
413 |
Log.d("info", "node is: " + n.getAddress()); |
|
414 |
} |
|
415 |
} |
|
416 |
|
|
364 | 417 |
@SuppressWarnings("unchecked") |
365 | 418 |
@Override |
366 | 419 |
protected void onActivityResult (int requestCode, int resultCode, Intent data){ |
... | ... | |
368 | 421 |
//set node list |
369 | 422 |
nodes = ((ArrayList<Node>)data.getSerializableExtra("nodes")); |
370 | 423 |
updateNodesIndicatorLight(); |
424 |
printNodes(nodes); |
|
371 | 425 |
} |
372 | 426 |
else if(requestCode == ADD_NODES_ACTIVITY_CODE && resultCode == RESULT_CANCELED){ |
373 | 427 |
//don't change list |
Also available in: Unified diff