Revision 6b8dad86 src/com/rackspacecloud/android/AddServerActivity.java
b/src/com/rackspacecloud/android/AddServerActivity.java | ||
---|---|---|
7 | 7 |
import java.util.Iterator; |
8 | 8 |
|
9 | 9 |
import android.app.Activity; |
10 |
import android.app.AlertDialog; |
|
11 |
import android.content.DialogInterface; |
|
12 | 10 |
import android.os.AsyncTask; |
13 | 11 |
import android.os.Bundle; |
14 | 12 |
import android.view.View; |
... | ... | |
17 | 15 |
import android.widget.ArrayAdapter; |
18 | 16 |
import android.widget.Button; |
19 | 17 |
import android.widget.EditText; |
20 |
import android.widget.ProgressBar; |
|
21 | 18 |
import android.widget.SeekBar; |
22 | 19 |
import android.widget.SeekBar.OnSeekBarChangeListener; |
23 | 20 |
import android.widget.Spinner; |
... | ... | |
34 | 31 |
* @author Mike Mayo - mike.mayo@rackspace.com - twitter.com/greenisus |
35 | 32 |
* |
36 | 33 |
*/ |
37 |
public class AddServerActivity extends GaActivity implements OnItemSelectedListener, OnClickListener {
|
|
34 |
public class AddServerActivity extends CloudActivity implements OnItemSelectedListener, OnClickListener {
|
|
38 | 35 |
|
39 | 36 |
private Image[] images; |
40 | 37 |
private Flavor[] flavors; |
... | ... | |
54 | 51 |
super.onCreate(savedInstanceState); |
55 | 52 |
trackPageView(PAGE_ADD_SERVER); |
56 | 53 |
setContentView(R.layout.createserver); |
54 |
restoreState(savedInstanceState); |
|
55 |
} |
|
56 |
|
|
57 |
protected void restoreState(Bundle state){ |
|
58 |
super.restoreState(state); |
|
57 | 59 |
serverName = (EditText) findViewById(R.id.server_name); |
58 | 60 |
((Button) findViewById(R.id.save_button)).setOnClickListener(this); |
59 | 61 |
((TextView)findViewById(R.id.names_number)).setText(" "); |
... | ... | |
62 | 64 |
loadFlavorSpinner(); |
63 | 65 |
loadServerCount(); |
64 | 66 |
} |
65 |
|
|
67 |
|
|
66 | 68 |
private void setUpNameText(){ |
67 | 69 |
serverName = (EditText) findViewById(R.id.server_name); |
68 | 70 |
} |
... | ... | |
174 | 176 |
showAlert("Required Fields Missing", "Server name is required."); |
175 | 177 |
} else { |
176 | 178 |
trackEvent(CATEGORY_SERVER, EVENT_CREATE, "", numberBar.getProgress()+1); |
177 |
showActivityIndicators(); |
|
178 | 179 |
server = new Server(); |
179 | 180 |
server.setName(serverName.getText().toString()); |
180 | 181 |
server.setImageId(selectedImageId); |
... | ... | |
183 | 184 |
} |
184 | 185 |
} |
185 | 186 |
|
186 |
private void showAlert(String title, String message) { |
|
187 |
AlertDialog alert = new AlertDialog.Builder(this).create(); |
|
188 |
alert.setTitle(title); |
|
189 |
alert.setMessage(message); |
|
190 |
alert.setButton("OK", new DialogInterface.OnClickListener() { |
|
191 |
public void onClick(DialogInterface dialog, int which) { |
|
192 |
return; |
|
193 |
} }); |
|
194 |
alert.show(); |
|
195 |
hideActivityIndicators(); |
|
196 |
} |
|
197 |
|
|
198 |
private void setActivityIndicatorsVisibility(int visibility) { |
|
199 |
ProgressBar pb = (ProgressBar) findViewById(R.id.save_server_progress_bar); |
|
200 |
TextView tv = (TextView) findViewById(R.id.saving_server_label); |
|
201 |
pb.setVisibility(visibility); |
|
202 |
tv.setVisibility(visibility); |
|
203 |
} |
|
204 |
|
|
205 |
private void showActivityIndicators() { |
|
206 |
setActivityIndicatorsVisibility(View.VISIBLE); |
|
207 |
} |
|
208 |
|
|
209 |
private void hideActivityIndicators() { |
|
210 |
setActivityIndicatorsVisibility(View.INVISIBLE); |
|
211 |
} |
|
212 |
|
|
213 | 187 |
private class SaveServerTask extends AsyncTask<Void, Void, Server> { |
214 | 188 |
|
215 | 189 |
private CloudServersException exception; |
216 | 190 |
|
217 | 191 |
@Override |
192 |
protected void onPreExecute(){ |
|
193 |
showDialog(); |
|
194 |
} |
|
195 |
|
|
196 |
@Override |
|
218 | 197 |
protected Server doInBackground(Void... arg0) { |
219 | 198 |
try { |
220 | 199 |
if(numberBar.getProgress() == 0){ |
221 |
(new ServerManager()).create(server, getApplicationContext());
|
|
200 |
(new ServerManager()).create(server, getContext()); |
|
222 | 201 |
} |
223 | 202 |
else{ |
224 | 203 |
for(int i = 0; i < numberBar.getProgress() + 1; i++){ |
225 | 204 |
server.setName(serverName.getText().toString() + Integer.toString(i+1)); |
226 |
(new ServerManager()).create(server, getApplicationContext());
|
|
205 |
(new ServerManager()).create(server, getContext()); |
|
227 | 206 |
} |
228 | 207 |
} |
229 | 208 |
} catch (CloudServersException e) { |
... | ... | |
234 | 213 |
|
235 | 214 |
@Override |
236 | 215 |
protected void onPostExecute(Server result) { |
216 |
hideDialog(); |
|
237 | 217 |
if (exception != null) { |
238 | 218 |
showAlert("Error", "There was a problem creating your server: " + exception.getMessage()); |
239 | 219 |
} else { |
240 |
hideActivityIndicators(); |
|
241 | 220 |
setResult(Activity.RESULT_OK); |
242 | 221 |
finish(); |
243 | 222 |
} |
Also available in: Unified diff