Revision a597c658
b/src/com/rackspace/cloud/servers/api/client/FlavorManager.java | ||
---|---|---|
21 | 21 |
import org.xml.sax.SAXException; |
22 | 22 |
import org.xml.sax.XMLReader; |
23 | 23 |
|
24 |
import android.content.Context; |
|
25 |
|
|
26 |
import com.rackspace.cloud.files.api.client.CustomHttpClient; |
|
24 | 27 |
import com.rackspace.cloud.servers.api.client.parsers.FlavorsXMLParser; |
25 | 28 |
|
26 | 29 |
/** |
... | ... | |
29 | 32 |
*/ |
30 | 33 |
public class FlavorManager extends EntityManager { |
31 | 34 |
|
32 |
public ArrayList<Flavor> createList(boolean detail) { |
|
35 |
public ArrayList<Flavor> createList(boolean detail, Context context) {
|
|
33 | 36 |
|
34 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
37 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
35 | 38 |
HttpGet get = new HttpGet(Account.getServerUrl() + "/flavors/detail.xml?now=cache_time2"); |
36 | 39 |
ArrayList<Flavor> flavors = new ArrayList<Flavor>(); |
37 | 40 |
|
b/src/com/rackspace/cloud/servers/api/client/ImageManager.java | ||
---|---|---|
21 | 21 |
import org.xml.sax.SAXException; |
22 | 22 |
import org.xml.sax.XMLReader; |
23 | 23 |
|
24 |
import android.content.Context; |
|
25 |
import android.util.Log; |
|
26 |
|
|
27 |
import com.rackspace.cloud.files.api.client.CustomHttpClient; |
|
24 | 28 |
import com.rackspace.cloud.servers.api.client.parsers.ImagesXMLParser; |
25 | 29 |
|
26 | 30 |
/** |
... | ... | |
29 | 33 |
*/ |
30 | 34 |
public class ImageManager extends EntityManager { |
31 | 35 |
|
32 |
public ArrayList<Image> createList(boolean detail) { |
|
36 |
public ArrayList<Image> createList(boolean detail, Context context) {
|
|
33 | 37 |
|
34 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
38 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
35 | 39 |
HttpGet get = new HttpGet(Account.getServerUrl() + "/images/detail.xml?now=cache_time2"); |
36 | 40 |
ArrayList<Image> images = new ArrayList<Image>(); |
37 | 41 |
|
b/src/com/rackspace/cloud/servers/api/client/ServerManager.java | ||
---|---|---|
26 | 26 |
import org.xml.sax.SAXException; |
27 | 27 |
import org.xml.sax.XMLReader; |
28 | 28 |
|
29 |
import android.content.Context; |
|
30 |
|
|
31 |
import com.rackspace.cloud.files.api.client.CustomHttpClient; |
|
29 | 32 |
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser; |
30 | 33 |
import com.rackspace.cloud.servers.api.client.parsers.ServersXMLParser; |
31 | 34 |
|
... | ... | |
38 | 41 |
public static final String SOFT_REBOOT = "SOFT"; |
39 | 42 |
public static final String HARD_REBOOT = "HARD"; |
40 | 43 |
|
41 |
public void create(Server entity) throws CloudServersException { |
|
44 |
public void create(Server entity, Context context) throws CloudServersException {
|
|
42 | 45 |
|
43 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
46 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
44 | 47 |
HttpPost post = new HttpPost(Account.getServerUrl() + "/servers.xml"); |
45 | 48 |
|
46 | 49 |
post.addHeader("X-Auth-Token", Account.getAuthToken()); |
... | ... | |
102 | 105 |
} |
103 | 106 |
} |
104 | 107 |
|
105 |
public ArrayList<Server> createList(boolean detail) throws CloudServersException { |
|
108 |
public ArrayList<Server> createList(boolean detail, Context context) throws CloudServersException {
|
|
106 | 109 |
|
107 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
110 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
108 | 111 |
HttpGet get = new HttpGet(Account.getServerUrl() + "/servers/detail.xml" + cacheBuster()); |
109 | 112 |
ArrayList<Server> servers = new ArrayList<Server>(); |
110 | 113 |
|
... | ... | |
157 | 160 |
return servers; |
158 | 161 |
} |
159 | 162 |
|
160 |
public Server find(long id) throws CloudServersException { |
|
163 |
public Server find(long id, Context context) throws CloudServersException {
|
|
161 | 164 |
Server server = null; |
162 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
165 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
163 | 166 |
HttpGet get = new HttpGet(Account.getServerUrl() + "/servers/" + id + ".xml" + cacheBuster()); |
164 | 167 |
|
165 | 168 |
get.addHeader("X-Auth-Token", Account.getAuthToken()); |
... | ... | |
210 | 213 |
return server; |
211 | 214 |
} |
212 | 215 |
|
213 |
public HttpResponse reboot(Server server, String rebootType) throws CloudServersException { |
|
216 |
public HttpResponse reboot(Server server, String rebootType, Context context) throws CloudServersException {
|
|
214 | 217 |
HttpResponse resp = null; |
215 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
218 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
216 | 219 |
HttpPost post = new HttpPost(Account.getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
217 | 220 |
|
218 | 221 |
post.addHeader("X-Auth-Token", Account.getAuthToken()); |
... | ... | |
248 | 251 |
return resp; |
249 | 252 |
} |
250 | 253 |
|
251 |
public HttpResponse resize(Server server, int flavorId) throws CloudServersException { |
|
254 |
public HttpResponse resize(Server server, int flavorId, Context context) throws CloudServersException {
|
|
252 | 255 |
HttpResponse resp = null; |
253 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
256 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
254 | 257 |
HttpPost post = new HttpPost(Account.getServerUrl() + "/servers/" + server.getId() + "/action.xml"); |
255 | 258 |
|
256 | 259 |
post.addHeader("X-Auth-Token", Account.getAuthToken()); |
... | ... | |
286 | 289 |
} |
287 | 290 |
|
288 | 291 |
|
289 |
public HttpResponse delete(Server server) throws CloudServersException { |
|
292 |
public HttpResponse delete(Server server, Context context) throws CloudServersException {
|
|
290 | 293 |
HttpResponse resp = null; |
291 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
294 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
292 | 295 |
HttpDelete delete = new HttpDelete(Account.getServerUrl() + "/servers/" + server.getId() + ".xml"); |
293 | 296 |
|
294 | 297 |
delete.addHeader("X-Auth-Token", Account.getAuthToken()); |
b/src/com/rackspace/cloud/servers/api/client/http/Authentication.java | ||
---|---|---|
10 | 10 |
import org.apache.http.client.methods.HttpGet; |
11 | 11 |
import org.apache.http.impl.client.DefaultHttpClient; |
12 | 12 |
|
13 |
import android.content.Context; |
|
14 |
|
|
15 |
import com.rackspace.cloud.files.api.client.CustomHttpClient; |
|
13 | 16 |
import com.rackspace.cloud.servers.api.client.Account; |
14 | 17 |
|
15 | 18 |
/** |
... | ... | |
18 | 21 |
*/ |
19 | 22 |
public class Authentication { |
20 | 23 |
|
21 |
public static boolean authenticate() { |
|
22 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
24 |
public static boolean authenticate(Context context) {
|
|
25 |
CustomHttpClient httpclient = new CustomHttpClient(context);
|
|
23 | 26 |
HttpGet get = new HttpGet(Account.getAuthServer()); |
24 | 27 |
|
25 | 28 |
get.addHeader("X-Auth-User", Account.getUsername()); |
b/src/com/rackspacecloud/android/ListServersActivity.java | ||
---|---|---|
7 | 7 |
|
8 | 8 |
import android.app.AlertDialog; |
9 | 9 |
import android.app.ListActivity; |
10 |
import android.content.Context; |
|
10 | 11 |
import android.content.DialogInterface; |
11 | 12 |
import android.content.Intent; |
12 | 13 |
import android.os.AsyncTask; |
... | ... | |
33 | 34 |
public class ListServersActivity extends ListActivity { |
34 | 35 |
|
35 | 36 |
private Server[] servers; |
37 |
Context context; |
|
36 | 38 |
|
37 | 39 |
@Override |
38 | 40 |
public void onCreate(Bundle savedInstanceState) { |
39 | 41 |
super.onCreate(savedInstanceState); |
42 |
context = getApplicationContext(); |
|
40 | 43 |
restoreState(savedInstanceState); |
41 | 44 |
} |
42 | 45 |
|
... | ... | |
140 | 143 |
protected ArrayList<Server> doInBackground(Void... arg0) { |
141 | 144 |
ArrayList<Server> servers = null; |
142 | 145 |
try { |
143 |
servers = (new ServerManager()).createList(true); |
|
146 |
servers = (new ServerManager()).createList(true, context);
|
|
144 | 147 |
} catch (CloudServersException e) { |
145 | 148 |
exception = e; |
146 | 149 |
} |
b/src/com/rackspacecloud/android/RackspaceCloudActivity.java | ||
---|---|---|
46 | 46 |
|
47 | 47 |
private Intent tabViewIntent; |
48 | 48 |
private boolean authenticating; |
49 |
private Context context; |
|
49 | 50 |
|
50 | 51 |
/** Called when the activity is first created. */ |
51 | 52 |
@Override |
... | ... | |
55 | 56 |
|
56 | 57 |
final CheckBox show_clear = (CheckBox) findViewById(R.id.show_clear); |
57 | 58 |
final EditText loginApiKey = (EditText) findViewById(R.id.login_apikey); |
58 |
|
|
59 |
|
|
60 |
context = getApplicationContext(); |
|
61 |
|
|
59 | 62 |
show_clear.setOnClickListener(new OnClickListener() { |
60 | 63 |
@Override |
61 | 64 |
public void onClick(View v) { |
... | ... | |
216 | 219 |
@Override |
217 | 220 |
protected Boolean doInBackground(Void... arg0) { |
218 | 221 |
authenticating = true; |
219 |
return new Boolean(Authentication.authenticate()); |
|
222 |
return new Boolean(Authentication.authenticate(context));
|
|
220 | 223 |
} |
221 | 224 |
|
222 | 225 |
@Override |
... | ... | |
235 | 238 |
|
236 | 239 |
@Override |
237 | 240 |
protected ArrayList<Flavor> doInBackground(Void... arg0) { |
238 |
return (new FlavorManager()).createList(true); |
|
241 |
return (new FlavorManager()).createList(true, context);
|
|
239 | 242 |
} |
240 | 243 |
|
241 | 244 |
@Override |
... | ... | |
259 | 262 |
|
260 | 263 |
@Override |
261 | 264 |
protected ArrayList<Image> doInBackground(Void... arg0) { |
262 |
return (new ImageManager()).createList(true); |
|
265 |
return (new ImageManager()).createList(true, context);
|
|
263 | 266 |
} |
264 | 267 |
|
265 | 268 |
@Override |
b/src/com/rackspacecloud/android/ViewServerActivity.java | ||
---|---|---|
22 | 22 |
import android.app.Activity; |
23 | 23 |
import android.app.AlertDialog; |
24 | 24 |
import android.app.Dialog; |
25 |
import android.content.Context; |
|
25 | 26 |
import android.content.DialogInterface; |
26 | 27 |
import android.graphics.Color; |
27 | 28 |
import android.os.AsyncTask; |
... | ... | |
51 | 52 |
private String[] flavorNames; |
52 | 53 |
private String selectedFlavorId; |
53 | 54 |
private boolean imageLoaded; |
55 |
Context context; |
|
54 | 56 |
|
55 | 57 |
/** Called when the activity is first created. */ |
56 | 58 |
@Override |
57 | 59 |
public void onCreate(Bundle savedInstanceState) { |
58 | 60 |
super.onCreate(savedInstanceState); |
59 | 61 |
server = (Server) this.getIntent().getExtras().get("server"); |
62 |
context = getApplicationContext(); |
|
60 | 63 |
setContentView(R.layout.viewserver); |
61 | 64 |
restoreState(savedInstanceState); |
62 | 65 |
} |
... | ... | |
333 | 336 |
@Override |
334 | 337 |
protected Server doInBackground(Void... arg0) { |
335 | 338 |
try { |
336 |
server = (new ServerManager()).find(Integer.parseInt(server.getId())); |
|
339 |
server = (new ServerManager()).find(Integer.parseInt(server.getId()), context);
|
|
337 | 340 |
} catch (NumberFormatException e) { |
338 | 341 |
// we're polling, so need to show exceptions |
339 | 342 |
} catch (CloudServersException e) { |
... | ... | |
358 | 361 |
protected HttpResponse doInBackground(Void... arg0) { |
359 | 362 |
HttpResponse resp = null; |
360 | 363 |
try { |
361 |
resp = (new ServerManager()).reboot(server, ServerManager.SOFT_REBOOT); |
|
364 |
resp = (new ServerManager()).reboot(server, ServerManager.SOFT_REBOOT, context);
|
|
362 | 365 |
} catch (CloudServersException e) { |
363 | 366 |
exception = e; |
364 | 367 |
} |
... | ... | |
393 | 396 |
protected HttpResponse doInBackground(Void... arg0) { |
394 | 397 |
HttpResponse resp = null; |
395 | 398 |
try { |
396 |
resp = (new ServerManager()).reboot(server, ServerManager.HARD_REBOOT); |
|
399 |
resp = (new ServerManager()).reboot(server, ServerManager.HARD_REBOOT, context);
|
|
397 | 400 |
} catch (CloudServersException e) { |
398 | 401 |
exception = e; |
399 | 402 |
} |
... | ... | |
427 | 430 |
protected HttpResponse doInBackground(Void... arg0) { |
428 | 431 |
HttpResponse resp = null; |
429 | 432 |
try { |
430 |
resp = (new ServerManager()).resize(server, Integer.parseInt(selectedFlavorId)); |
|
433 |
resp = (new ServerManager()).resize(server, Integer.parseInt(selectedFlavorId), context);
|
|
431 | 434 |
} catch (CloudServersException e) { |
432 | 435 |
exception = e; |
433 | 436 |
} |
... | ... | |
464 | 467 |
protected HttpResponse doInBackground(Void... arg0) { |
465 | 468 |
HttpResponse resp = null; |
466 | 469 |
try { |
467 |
resp = (new ServerManager()).delete(server); |
|
470 |
resp = (new ServerManager()).delete(server, context);
|
|
468 | 471 |
} catch (CloudServersException e) { |
469 | 472 |
exception = e; |
470 | 473 |
} |
Also available in: Unified diff