Revision c4a37180 src/com/rackspacecloud/android/AddExternalNodeActivity.java
b/src/com/rackspacecloud/android/AddExternalNodeActivity.java | ||
---|---|---|
3 | 3 |
import java.util.regex.Matcher; |
4 | 4 |
import java.util.regex.Pattern; |
5 | 5 |
|
6 |
import com.rackspace.cloud.loadbalancer.api.client.Node; |
|
7 |
|
|
6 | 8 |
import android.content.Intent; |
7 | 9 |
import android.os.Bundle; |
8 | 10 |
import android.view.View; |
... | ... | |
27 | 29 |
private Spinner conditionSpinner; |
28 | 30 |
private EditText ipAddress; |
29 | 31 |
private EditText weightText; |
30 |
|
|
32 |
private Node node; |
|
33 |
|
|
31 | 34 |
public void onCreate(Bundle savedInstanceState) { |
32 | 35 |
super.onCreate(savedInstanceState); |
33 | 36 |
requestWindowFeature(Window.FEATURE_NO_TITLE); |
34 | 37 |
setContentView(R.layout.addexternalnode); |
35 | 38 |
weighted = (Boolean) this.getIntent().getExtras().get("weighted"); |
39 |
node = (Node) this.getIntent().getExtras().get("node"); |
|
36 | 40 |
restoreState(savedInstanceState); |
37 | 41 |
} |
38 | 42 |
|
... | ... | |
42 | 46 |
} |
43 | 47 |
|
44 | 48 |
private void setupInputs(){ |
45 |
|
|
49 |
|
|
46 | 50 |
ipAddress = (EditText) findViewById(R.id.ip_address); |
47 | 51 |
|
48 | 52 |
weightText = (EditText) findViewById(R.id.node_weight_text); |
... | ... | |
57 | 61 |
loadConditionSpinner(); |
58 | 62 |
setUpButton(); |
59 | 63 |
|
64 |
if(node != null){ |
|
65 |
ipAddress.setText(node.getAddress()); |
|
66 |
weightText.setText(node.getWeight()); |
|
67 |
((EditText)findViewById(R.id.node_port_text)).setText(node.getPort()); |
|
68 |
conditionSpinner.setSelection(getLocation(CONDITIONS, node.getCondition())); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
private int getLocation(Object[] objects, Object object){ |
|
73 |
for(int i = 0; i < objects.length; i++){ |
|
74 |
if(object.equals(objects[i])){ |
|
75 |
return i; |
|
76 |
} |
|
77 |
} |
|
78 |
return 0; |
|
60 | 79 |
} |
61 | 80 |
|
62 | 81 |
private void setUpButton(){ |
... | ... | |
75 | 94 |
} else if(ipAddress.getText().toString().equals("")){ |
76 | 95 |
//TODO use regex to validate the ip for IPV4 and IPV6 |
77 | 96 |
showAlert("Error", "Enter an IP Address"); |
78 |
} else if(validIp(ipAddress.getText().toString())) { |
|
97 |
} else if(!validIp(ipAddress.getText().toString())) {
|
|
79 | 98 |
showAlert("Error", "Enter a valid IP Address"); |
80 | 99 |
} else { |
81 | 100 |
Intent data = new Intent(); |
... | ... | |
91 | 110 |
}); |
92 | 111 |
} |
93 | 112 |
|
94 |
public void onBackPressed(){ |
|
95 |
setResult(RESULT_CANCELED); |
|
96 |
finish(); |
|
97 |
} |
|
98 |
|
|
99 | 113 |
private void loadConditionSpinner(){ |
100 | 114 |
conditionSpinner = (Spinner) findViewById(R.id.node_condition_spinner); |
101 | 115 |
|
... | ... | |
128 | 142 |
} |
129 | 143 |
|
130 | 144 |
private boolean validPort(String port){ |
131 |
return !port.equals("") && Integer.valueOf(port) > 0 && Integer.valueOf(port) < 65536; |
|
145 |
boolean result; |
|
146 |
try{ |
|
147 |
result = !port.equals("") && Integer.valueOf(port) > 0 && Integer.valueOf(port) < 65536; |
|
148 |
} catch (NumberFormatException e) { |
|
149 |
result = false; |
|
150 |
} |
|
151 |
return result; |
|
132 | 152 |
} |
133 | 153 |
|
134 | 154 |
private Boolean validWeight(String weight){ |
... | ... | |
136 | 156 |
return false; |
137 | 157 |
} |
138 | 158 |
else{ |
139 |
int w = Integer.valueOf(weight); |
|
159 |
int w; |
|
160 |
try{ |
|
161 |
w = Integer.valueOf(weight); |
|
162 |
} catch (NumberFormatException e){ |
|
163 |
return false; |
|
164 |
} |
|
140 | 165 |
return w >= 1 && w <= 100 ; |
141 | 166 |
} |
142 | 167 |
} |
143 | 168 |
|
169 |
public void onBackPressed(){ |
|
170 |
setResult(RESULT_CANCELED); |
|
171 |
finish(); |
|
172 |
} |
|
173 |
|
|
144 | 174 |
} |
145 | 175 |
|
Also available in: Unified diff