Revision b722cab3 src/com/rackspacecloud/android/AddNodeActivity.java
b/src/com/rackspacecloud/android/AddNodeActivity.java | ||
---|---|---|
1 | 1 |
package com.rackspacecloud.android; |
2 | 2 |
|
3 |
import android.app.Activity; |
|
4 |
import android.app.AlertDialog; |
|
5 |
import android.content.Context; |
|
6 |
import android.content.DialogInterface; |
|
7 | 3 |
import android.content.Intent; |
8 | 4 |
import android.os.Bundle; |
5 |
import android.util.Log; |
|
9 | 6 |
import android.view.View; |
10 | 7 |
import android.view.View.OnClickListener; |
11 | 8 |
import android.view.Window; |
... | ... | |
15 | 12 |
import android.widget.Button; |
16 | 13 |
import android.widget.Spinner; |
17 | 14 |
import android.widget.EditText; |
15 |
import android.widget.TextView; |
|
18 | 16 |
|
19 |
public class AddNodeActivity extends Activity{ |
|
17 |
public class AddNodeActivity extends CloudActivity{
|
|
20 | 18 |
|
21 | 19 |
private final String[] CONDITIONS = {"Enabled", "Disabled", "Draining"}; |
22 | 20 |
private String[] ipAddresses; |
23 |
private Spinner conditionSpinner; |
|
24 |
private Spinner ipAddressSpinner; |
|
21 |
private String name; |
|
25 | 22 |
private String selectedPort; |
26 | 23 |
private String selectedIp; |
24 |
private String selectedWeight; |
|
25 |
private boolean weighted; |
|
27 | 26 |
private String selectedCondition; |
27 |
private Spinner conditionSpinner; |
|
28 |
private Spinner ipAddressSpinner; |
|
29 |
private EditText weightText; |
|
28 | 30 |
|
29 | 31 |
public void onCreate(Bundle savedInstanceState) { |
30 | 32 |
super.onCreate(savedInstanceState); |
31 | 33 |
requestWindowFeature(Window.FEATURE_NO_TITLE); |
32 | 34 |
setContentView(R.layout.addnode); |
33 | 35 |
ipAddresses = (String[]) this.getIntent().getExtras().get("ipAddresses"); |
36 |
name = (String) this.getIntent().getExtras().get("name"); |
|
37 |
weighted = (Boolean) this.getIntent().getExtras().get("weighted"); |
|
34 | 38 |
restoreState(savedInstanceState); |
39 |
} |
|
40 |
|
|
41 |
protected void restoreState(Bundle state) { |
|
42 |
super.restoreState(state); |
|
43 |
setupInputs(); |
|
44 |
} |
|
45 |
|
|
46 |
private void setupInputs(){ |
|
47 |
|
|
48 |
((TextView)findViewById(R.id.node_name)).setText(name); |
|
49 |
|
|
50 |
weightText = (EditText) findViewById(R.id.node_weight_text); |
|
51 |
|
|
52 |
//if algorithm is not weighted then then node's weight will be null |
|
53 |
if(!weighted){ |
|
54 |
TextView weightLabel = (TextView) findViewById(R.id.node_weight_label); |
|
55 |
weightLabel.setVisibility(View.GONE); |
|
56 |
weightText.setVisibility(View.GONE); |
|
57 |
} |
|
58 |
|
|
35 | 59 |
loadConditionSpinner(); |
36 | 60 |
loadIpSpinner(); |
37 | 61 |
setUpButton(); |
38 |
} |
|
39 |
|
|
40 |
private void restoreState(Bundle state) { |
|
41 | 62 |
|
42 | 63 |
} |
43 | 64 |
|
... | ... | |
48 | 69 |
@Override |
49 | 70 |
public void onClick(View v) { |
50 | 71 |
selectedPort = ((EditText)findViewById(R.id.node_port_text)).getText().toString(); |
72 |
selectedWeight = weightText.getText().toString(); |
|
51 | 73 |
if(!validPort()){ |
52 | 74 |
showAlert("Error", "Must have a protocol port number that is between 1 and 65535."); |
75 |
} else if(!(weightText.getVisibility() == View.GONE || (weightText.getVisibility() != View.GONE && validWeight(selectedWeight)))){ |
|
76 |
showAlert("Error", "Weight must be between 1 and 100."); |
|
53 | 77 |
} |
78 |
|
|
54 | 79 |
else{ |
55 | 80 |
Intent data = new Intent(); |
56 | 81 |
data.putExtra("nodeIp", selectedIp); |
57 | 82 |
data.putExtra("nodePort", selectedPort); |
58 | 83 |
data.putExtra("nodeCondition", selectedCondition); |
84 |
Log.d("info", "saving the weight as " + selectedWeight); |
|
85 |
data.putExtra("nodeWeight", selectedWeight); |
|
59 | 86 |
setResult(RESULT_OK, data); |
60 | 87 |
finish(); |
61 | 88 |
} |
... | ... | |
116 | 143 |
return !selectedPort.equals("") && Integer.valueOf(selectedPort) > 0 && Integer.valueOf(selectedPort) < 65536; |
117 | 144 |
} |
118 | 145 |
|
119 |
private void showAlert(String title, String message) { |
|
120 |
AlertDialog alert = new AlertDialog.Builder(this).create(); |
|
121 |
alert.setTitle(title); |
|
122 |
alert.setMessage(message); |
|
123 |
alert.setButton("OK", new DialogInterface.OnClickListener() { |
|
124 |
public void onClick(DialogInterface dialog, int which) { |
|
125 |
return; |
|
126 |
} }); |
|
127 |
alert.show(); |
|
146 |
private Boolean validWeight(String weight){ |
|
147 |
if(weight.equals("")){ |
|
148 |
return false; |
|
149 |
} |
|
150 |
else{ |
|
151 |
int w = Integer.valueOf(weight); |
|
152 |
return w >= 1 && w <= 100 ; |
|
153 |
} |
|
128 | 154 |
} |
129 | 155 |
|
130 | 156 |
} |
Also available in: Unified diff