Revision 240418be
b/src/com/rackspace/cloud/files/api/client/parsers/ContainerObjectXMLparser.java | ||
---|---|---|
8 | 8 |
import android.util.Log; |
9 | 9 |
|
10 | 10 |
import com.rackspace.cloud.files.api.client.ContainerObjects; |
11 |
/** |
|
11 |
|
|
12 |
/** |
|
12 | 13 |
* |
13 | 14 |
* @author Phillip Toohill |
14 |
* |
|
15 |
*
|
|
15 | 16 |
*/ |
16 | 17 |
public class ContainerObjectXMLparser extends DefaultHandler { |
17 | 18 |
|
... | ... | |
20 | 21 |
|
21 | 22 |
private StringBuffer currentData; |
22 | 23 |
public String LOG = "ViewFilesXMLparser"; |
23 |
|
|
24 |
|
|
24 | 25 |
public void startDocument() { |
25 | 26 |
Log.v(LOG, "startDocument"); |
26 | 27 |
} |
... | ... | |
29 | 30 |
Log.v(LOG, "endDocument = true"); |
30 | 31 |
} |
31 | 32 |
|
32 |
public void startElement(String uri, String name, String qName, Attributes atts) { |
|
33 |
public void startElement(String uri, String name, String qName, |
|
34 |
Attributes atts) { |
|
33 | 35 |
|
34 | 36 |
currentData = new StringBuffer(); |
35 | 37 |
if ("container".equals(name)) { |
36 |
files = new ArrayList<ContainerObjects>();
|
|
38 |
files = new ArrayList<ContainerObjects>(); |
|
37 | 39 |
} else if ("object".equals(name)) { |
38 | 40 |
object = new ContainerObjects(); |
39 | 41 |
} |
... | ... | |
42 | 44 |
public void endElement(String uri, String name, String qName) { |
43 | 45 |
|
44 | 46 |
String value = currentData.toString().trim(); |
45 |
|
|
46 |
if ("container".equals(name)) {
|
|
47 |
|
|
47 |
|
|
48 |
if ("container".equals(name)) { |
|
49 |
|
|
48 | 50 |
} else if ("object".equals(name)) { |
49 | 51 |
if (files != null) { |
50 | 52 |
files.add(object); |
51 | 53 |
} |
52 |
}else if ("name".equals(name)){
|
|
54 |
} else if ("name".equals(name)) {
|
|
53 | 55 |
object.setCName(value); |
54 |
}else if ("content_type".equals(name)){
|
|
56 |
} else if ("content_type".equals(name)) {
|
|
55 | 57 |
object.setContentType(value); |
56 |
}else if ("hash".equals(name)){
|
|
58 |
} else if ("hash".equals(name)) {
|
|
57 | 59 |
object.setHash(value); |
58 |
}else if ("bytes".equals(name)){
|
|
60 |
} else if ("bytes".equals(name)) {
|
|
59 | 61 |
object.setBytes(Integer.parseInt(value)); |
60 |
}else if ("last_modified".equals(name)){
|
|
62 |
} else if ("last_modified".equals(name)) {
|
|
61 | 63 |
object.setLastMod(value); |
62 |
|
|
63 |
|
|
64 |
|
|
64 | 65 |
} |
65 | 66 |
} |
66 | 67 |
|
67 |
|
|
68 | 68 |
public void characters(char ch[], int start, int length) { |
69 |
|
|
69 |
|
|
70 | 70 |
System.out.print("Characters: \""); |
71 |
|
|
71 |
|
|
72 | 72 |
for (int i = start; i < start + length; i++) { |
73 | 73 |
switch (ch[i]) { |
74 | 74 |
case '\\': |
... | ... | |
92 | 92 |
} |
93 | 93 |
} |
94 | 94 |
System.out.print("\"\n"); |
95 |
//String strCharacters = new String(ch, start, length);
|
|
95 |
// String strCharacters = new String(ch, start, length);
|
|
96 | 96 |
for (int i = start; i < (start + length); i++) { |
97 | 97 |
currentData.append(ch[i]); |
98 | 98 |
} |
99 | 99 |
} |
100 |
|
|
100 |
|
|
101 | 101 |
public ContainerObjects getObject() { |
102 | 102 |
return object; |
103 | 103 |
} |
... | ... | |
114 | 114 |
} |
115 | 115 |
|
116 | 116 |
/** |
117 |
* @param files the servers to set |
|
117 |
* @param files |
|
118 |
* the servers to set |
|
118 | 119 |
*/ |
119 | 120 |
public void setFiles(ArrayList<ContainerObjects> files) { |
120 | 121 |
this.files = files; |
121 | 122 |
} |
122 | 123 |
|
123 |
|
|
124 | 124 |
} |
b/src/com/rackspace/cloud/files/api/client/parsers/ContainerXMLParser.java | ||
---|---|---|
6 | 6 |
import org.xml.sax.helpers.DefaultHandler; |
7 | 7 |
|
8 | 8 |
import com.rackspace.cloud.files.api.client.Container; |
9 |
/** |
|
9 |
|
|
10 |
/** |
|
10 | 11 |
* |
11 | 12 |
* @author Phillip Toohill |
12 |
* |
|
13 |
*
|
|
13 | 14 |
*/ |
14 | 15 |
public class ContainerXMLParser extends DefaultHandler { |
15 | 16 |
|
16 | 17 |
private Container container; |
17 | 18 |
private ArrayList<Container> containers; |
18 | 19 |
private StringBuffer currentData; |
19 |
|
|
20 |
public void startElement(String uri, String name, String qName, Attributes atts) { |
|
21 |
|
|
20 |
|
|
21 |
public void startElement(String uri, String name, String qName, |
|
22 |
Attributes atts) { |
|
23 |
|
|
22 | 24 |
currentData = new StringBuffer(); |
23 | 25 |
if ("account".equals(name)) { |
24 | 26 |
containers = new ArrayList<Container>(); |
25 | 27 |
} else if ("container".equals(name)) { |
26 | 28 |
container = new Container(); |
27 |
}
|
|
29 |
} |
|
28 | 30 |
} |
29 | 31 |
|
30 | 32 |
public void endElement(String uri, String name, String qName) { |
31 |
|
|
33 |
|
|
32 | 34 |
String value = currentData.toString().trim(); |
33 |
|
|
35 |
|
|
34 | 36 |
if ("account".equals(name)) { |
35 | 37 |
|
36 | 38 |
} else if ("container".equals(name)) { |
... | ... | |
39 | 41 |
containers = new ArrayList<Container>(); |
40 | 42 |
} |
41 | 43 |
containers.add(container); |
42 |
|
|
44 |
|
|
43 | 45 |
} else if ("name".equals(name)) { |
44 | 46 |
container.setName(value); |
45 | 47 |
} else if ("count".equals(name)) { |
... | ... | |
50 | 52 |
container.setCdnEnabled("True".equals(value)); |
51 | 53 |
} else if ("ttl".equals(name)) { |
52 | 54 |
container.setTtl(Integer.parseInt(value)); |
53 |
} else if ("cdn_url".equals(name)) {
|
|
55 |
} else if ("cdn_url".equals(name)) { |
|
54 | 56 |
container.setCdnUrl(value); |
55 | 57 |
} else if ("log_retention".equals(name)) { |
56 | 58 |
container.setLogRetention("True".equals(value)); |
57 | 59 |
} |
58 |
|
|
60 |
|
|
59 | 61 |
} |
60 | 62 |
|
61 | 63 |
public void characters(char ch[], int start, int length) { |
62 |
|
|
64 |
|
|
65 |
System.out.print("Characters: \""); |
|
66 |
|
|
63 | 67 |
for (int i = start; i < start + length; i++) { |
64 | 68 |
switch (ch[i]) { |
65 | 69 |
case '\\': |
... | ... | |
87 | 91 |
currentData.append(ch[i]); |
88 | 92 |
} |
89 | 93 |
} |
90 |
|
|
94 |
|
|
91 | 95 |
public Container getContainer() { |
92 | 96 |
return container; |
93 | 97 |
} |
... | ... | |
104 | 108 |
} |
105 | 109 |
|
106 | 110 |
/** |
107 |
* @param containers the servers to set |
|
111 |
* @param containers |
|
112 |
* the servers to set |
|
108 | 113 |
*/ |
109 | 114 |
public void setContainers(ArrayList<Container> containers) { |
110 | 115 |
this.containers = containers; |
b/src/com/rackspacecloud/android/ContainerObjectsActivity.java | ||
---|---|---|
42 | 42 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
43 | 43 |
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser; |
44 | 44 |
|
45 |
/**
|
|
45 |
/** |
|
46 | 46 |
* |
47 | 47 |
* @author Phillip Toohill |
48 |
* |
|
48 |
*
|
|
49 | 49 |
*/ |
50 | 50 |
public class ContainerObjectsActivity extends ListActivity { |
51 |
|
|
52 | 51 |
|
53 | 52 |
private static final int deleteContainer = 0; |
54 | 53 |
private ContainerObjects[] files; |
... | ... | |
59 | 58 |
public Object kiloBytes; |
60 | 59 |
public int bConver = 1048576; |
61 | 60 |
public int kbConver = 1024; |
62 |
|
|
61 |
|
|
63 | 62 |
@Override |
64 |
public void onCreate(Bundle savedInstanceState) {
|
|
65 |
super.onCreate(savedInstanceState);
|
|
66 |
container = (Container) this.getIntent().getExtras().get("container");
|
|
67 |
if (container.isCdnEnabled()== true){
|
|
68 |
cdnEnabledIs = "true";
|
|
69 |
}else{
|
|
70 |
cdnEnabledIs = "false";
|
|
71 |
}
|
|
72 |
restoreState(savedInstanceState);
|
|
73 |
}
|
|
74 |
|
|
63 |
public void onCreate(Bundle savedInstanceState) {
|
|
64 |
super.onCreate(savedInstanceState);
|
|
65 |
container = (Container) this.getIntent().getExtras().get("container");
|
|
66 |
if (container.isCdnEnabled() == true) {
|
|
67 |
cdnEnabledIs = "true";
|
|
68 |
} else {
|
|
69 |
cdnEnabledIs = "false";
|
|
70 |
}
|
|
71 |
restoreState(savedInstanceState);
|
|
72 |
}
|
|
73 |
|
|
75 | 74 |
@Override |
76 | 75 |
protected void onSaveInstanceState(Bundle outState) { |
77 | 76 |
super.onSaveInstanceState(outState); |
78 | 77 |
outState.putSerializable("container", files); |
79 | 78 |
} |
80 | 79 |
|
81 |
private void restoreState(Bundle state) {
|
|
82 |
if (state != null && state.containsKey("container")) {
|
|
83 |
files = (ContainerObjects[]) state.getSerializable("container");
|
|
84 |
if (files.length == 0) {
|
|
85 |
displayNoServersCell();
|
|
86 |
} else {
|
|
87 |
getListView().setDividerHeight(1); // restore divider lines
|
|
88 |
setListAdapter(new FileAdapter());
|
|
89 |
|
|
90 |
}
|
|
91 |
} else {
|
|
92 |
loadFiles();
|
|
93 |
|
|
94 |
}
|
|
95 |
}
|
|
96 |
|
|
80 |
private void restoreState(Bundle state) {
|
|
81 |
if (state != null && state.containsKey("container")) {
|
|
82 |
files = (ContainerObjects[]) state.getSerializable("container");
|
|
83 |
if (files.length == 0) {
|
|
84 |
displayNoServersCell();
|
|
85 |
} else {
|
|
86 |
getListView().setDividerHeight(1); // restore divider lines
|
|
87 |
setListAdapter(new FileAdapter());
|
|
88 |
|
|
89 |
}
|
|
90 |
} else {
|
|
91 |
loadFiles();
|
|
92 |
|
|
93 |
}
|
|
94 |
}
|
|
95 |
|
|
97 | 96 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
98 |
if (files != null && files.length > 0) {
|
|
99 |
Intent viewIntent = new Intent(this, ContainerObjectDetails.class);
|
|
100 |
viewIntent.putExtra("container", files[position]);
|
|
101 |
viewIntent.putExtra("cdnUrl", container.getCdnUrl());
|
|
102 |
viewIntent.putExtra("containerNames", container.getName());
|
|
103 |
viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
|
|
104 |
startActivityForResult(viewIntent, 55); // arbitrary number; never used again
|
|
105 |
}
|
|
106 |
}
|
|
107 |
|
|
108 |
private void loadFiles() { |
|
109 |
displayLoadingCell();
|
|
110 |
new LoadFilesTask().execute((Void[]) null);
|
|
111 |
|
|
112 |
} |
|
113 |
|
|
114 |
|
|
97 |
if (files != null && files.length > 0) { |
|
98 |
Intent viewIntent = new Intent(this, ContainerObjectDetails.class);
|
|
99 |
viewIntent.putExtra("container", files[position]);
|
|
100 |
viewIntent.putExtra("cdnUrl", container.getCdnUrl());
|
|
101 |
viewIntent.putExtra("containerNames", container.getName());
|
|
102 |
viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
|
|
103 |
startActivityForResult(viewIntent, 55); // arbitrary number; never
|
|
104 |
// used again
|
|
105 |
}
|
|
106 |
} |
|
107 |
|
|
108 |
private void loadFiles() {
|
|
109 |
displayLoadingCell();
|
|
110 |
new LoadFilesTask().execute((Void[]) null); |
|
111 |
|
|
112 |
} |
|
113 |
|
|
115 | 114 |
private void setFileList(ArrayList<ContainerObjects> files) { |
116 |
if (files == null) {
|
|
117 |
files = new ArrayList<ContainerObjects>();
|
|
118 |
}
|
|
119 |
String[] fileNames = new String[files.size()];
|
|
120 |
this.files = new ContainerObjects[files.size()];
|
|
121 |
|
|
122 |
if (files != null) {
|
|
115 |
if (files == null) {
|
|
116 |
files = new ArrayList<ContainerObjects>();
|
|
117 |
}
|
|
118 |
String[] fileNames = new String[files.size()];
|
|
119 |
this.files = new ContainerObjects[files.size()];
|
|
120 |
|
|
121 |
if (files != null) { |
|
123 | 122 |
for (int i = 0; i < files.size(); i++) { |
124 |
ContainerObjects file= files.get(i); |
|
123 |
ContainerObjects file = files.get(i);
|
|
125 | 124 |
this.files[i] = file; |
126 | 125 |
fileNames[i] = file.getName(); |
127 | 126 |
} |
128 | 127 |
} |
129 |
|
|
128 |
|
|
130 | 129 |
if (fileNames.length == 0) { |
131 | 130 |
displayNoServersCell(); |
132 | 131 |
} else { |
133 |
getListView().setDividerHeight(1); // restore divider lines
|
|
132 |
getListView().setDividerHeight(1); // restore divider lines |
|
134 | 133 |
setListAdapter(new FileAdapter()); |
135 | 134 |
} |
136 |
} |
|
137 |
|
|
138 |
private void displayLoadingCell() { |
|
139 |
String a[] = new String[1]; |
|
140 |
a[0] = "Loading..."; |
|
141 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.loadingcell, R.id.loading_label, a)); |
|
142 |
getListView().setTextFilterEnabled(true); |
|
143 |
getListView().setDividerHeight(0); // hide the dividers so it won't look like a list row |
|
144 |
getListView().setItemsCanFocus(false); |
|
145 |
} |
|
146 |
|
|
147 |
private void displayNoServersCell() { |
|
148 |
String a[] = new String[1]; |
|
149 |
a[0] = "No Files"; |
|
150 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.noobjectscell, R.id.no_files_label, a)); |
|
151 |
getListView().setTextFilterEnabled(true); |
|
152 |
getListView().setDividerHeight(0); // hide the dividers so it won't look like a list row |
|
153 |
getListView().setItemsCanFocus(false); |
|
154 |
} |
|
155 |
|
|
156 |
private void showAlert(String title, String message) { |
|
157 |
//Can't create handler inside thread that has not called Looper.prepare() |
|
158 |
//Looper.prepare(); |
|
159 |
try { |
|
160 |
AlertDialog alert = new AlertDialog.Builder(this).create(); |
|
161 |
alert.setTitle(title); |
|
162 |
alert.setMessage(message); |
|
163 |
alert.setButton("OK", new DialogInterface.OnClickListener() { |
|
164 |
public void onClick(DialogInterface dialog, int which) { |
|
165 |
return; |
|
166 |
} }); |
|
167 |
alert.show(); |
|
168 |
} catch (Exception e) { |
|
169 |
e.printStackTrace(); |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
|
|
174 |
private class LoadFilesTask extends AsyncTask<Void, Void, ArrayList<ContainerObjects>> { |
|
175 |
|
|
176 |
private CloudServersException exception; |
|
177 |
|
|
135 |
} |
|
136 |
|
|
137 |
private void displayLoadingCell() { |
|
138 |
String a[] = new String[1]; |
|
139 |
a[0] = "Loading..."; |
|
140 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.loadingcell, |
|
141 |
R.id.loading_label, a)); |
|
142 |
getListView().setTextFilterEnabled(true); |
|
143 |
getListView().setDividerHeight(0); // hide the dividers so it won't look |
|
144 |
// like a list row |
|
145 |
getListView().setItemsCanFocus(false); |
|
146 |
} |
|
147 |
|
|
148 |
private void displayNoServersCell() { |
|
149 |
String a[] = new String[1]; |
|
150 |
a[0] = "No Files"; |
|
151 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.noobjectscell, |
|
152 |
R.id.no_files_label, a)); |
|
153 |
getListView().setTextFilterEnabled(true); |
|
154 |
getListView().setDividerHeight(0); // hide the dividers so it won't look |
|
155 |
// like a list row |
|
156 |
getListView().setItemsCanFocus(false); |
|
157 |
} |
|
158 |
|
|
159 |
private void showAlert(String title, String message) { |
|
160 |
// Can't create handler inside thread that has not called |
|
161 |
// Looper.prepare() |
|
162 |
// Looper.prepare(); |
|
163 |
try { |
|
164 |
AlertDialog alert = new AlertDialog.Builder(this).create(); |
|
165 |
alert.setTitle(title); |
|
166 |
alert.setMessage(message); |
|
167 |
alert.setButton("OK", new DialogInterface.OnClickListener() { |
|
168 |
public void onClick(DialogInterface dialog, int which) { |
|
169 |
return; |
|
170 |
} |
|
171 |
}); |
|
172 |
alert.show(); |
|
173 |
} catch (Exception e) { |
|
174 |
e.printStackTrace(); |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
private class LoadFilesTask extends |
|
179 |
AsyncTask<Void, Void, ArrayList<ContainerObjects>> { |
|
180 |
|
|
181 |
private CloudServersException exception; |
|
182 |
|
|
178 | 183 |
@Override |
179 | 184 |
protected ArrayList<ContainerObjects> doInBackground(Void... arg0) { |
180 | 185 |
ArrayList<ContainerObjects> files = null; |
181 | 186 |
try { |
182 |
files = (new ContainerObjectManager()).createList(true, container.getName()); |
|
187 |
files = (new ContainerObjectManager()).createList(true, |
|
188 |
container.getName()); |
|
183 | 189 |
} catch (CloudServersException e) { |
184 | 190 |
exception = e; |
185 | 191 |
e.printStackTrace(); |
186 | 192 |
} |
187 | 193 |
return files; |
188 | 194 |
} |
189 |
|
|
195 |
|
|
190 | 196 |
@Override |
191 | 197 |
protected void onPostExecute(ArrayList<ContainerObjects> result) { |
192 | 198 |
if (exception != null) { |
193 | 199 |
showAlert("Error", exception.getMessage()); |
194 |
}
|
|
200 |
} |
|
195 | 201 |
setFileList(result); |
196 | 202 |
} |
197 |
} |
|
198 |
class FileAdapter extends ArrayAdapter<ContainerObjects> { |
|
203 |
} |
|
204 |
|
|
205 |
class FileAdapter extends ArrayAdapter<ContainerObjects> { |
|
199 | 206 |
FileAdapter() { |
200 |
super(ContainerObjectsActivity.this, R.layout.listcontainerobjectcell, files); |
|
207 |
super(ContainerObjectsActivity.this, |
|
208 |
R.layout.listcontainerobjectcell, files); |
|
201 | 209 |
} |
202 |
|
|
210 |
|
|
203 | 211 |
public View getView(int position, View convertView, ViewGroup parent) { |
204 |
|
|
212 |
|
|
205 | 213 |
ContainerObjects file = files[position]; |
206 | 214 |
LayoutInflater inflater = getLayoutInflater(); |
207 |
View row = inflater.inflate(R.layout.listcontainerobjectcell, parent, false); |
|
215 |
View row = inflater.inflate(R.layout.listcontainerobjectcell, |
|
216 |
parent, false); |
|
208 | 217 |
|
209 | 218 |
TextView label = (TextView) row.findViewById(R.id.label); |
210 | 219 |
label.setText(file.getCName()); |
211 |
|
|
212 | 220 |
|
213 | 221 |
if (file.getBytes() >= bConver) { |
214 |
megaBytes = Math.abs(file.getBytes()/bConver + 0.2);
|
|
215 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
|
|
216 |
sublabel.setText(megaBytes + " MB");
|
|
217 |
} else if (file.getBytes() >= kbConver){ |
|
218 |
kiloBytes = Math.abs(file.getBytes()/kbConver + 0.2);
|
|
219 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
|
|
220 |
sublabel.setText(kiloBytes + " KB");
|
|
222 |
megaBytes = Math.abs(file.getBytes() / bConver + 0.2);
|
|
223 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel); |
|
224 |
sublabel.setText(megaBytes + " MB"); |
|
225 |
} else if (file.getBytes() >= kbConver) {
|
|
226 |
kiloBytes = Math.abs(file.getBytes() / kbConver + 0.2);
|
|
227 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel); |
|
228 |
sublabel.setText(kiloBytes + " KB"); |
|
221 | 229 |
} else { |
222 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
|
|
223 |
sublabel.setText( file.getBytes() + " B");
|
|
230 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel); |
|
231 |
sublabel.setText(file.getBytes() + " B");
|
|
224 | 232 |
} |
225 |
|
|
226 |
return(row); |
|
233 |
|
|
234 |
return (row);
|
|
227 | 235 |
} |
228 |
}
|
|
229 |
|
|
230 |
//Create the Menu options
|
|
231 |
@Override
|
|
232 |
public boolean onCreateOptionsMenu(Menu menu) {
|
|
236 |
} |
|
237 |
|
|
238 |
// Create the Menu options
|
|
239 |
@Override
|
|
240 |
public boolean onCreateOptionsMenu(Menu menu) {
|
|
233 | 241 |
super.onCreateOptionsMenu(menu); |
234 | 242 |
MenuInflater inflater = getMenuInflater(); |
235 | 243 |
inflater.inflate(R.menu.view_container_object_list_menu, menu); |
236 | 244 |
return true; |
237 |
}
|
|
238 |
|
|
239 |
@Override
|
|
240 |
public boolean onOptionsItemSelected(MenuItem item) {
|
|
245 |
} |
|
246 |
|
|
247 |
@Override
|
|
248 |
public boolean onOptionsItemSelected(MenuItem item) {
|
|
241 | 249 |
switch (item.getItemId()) { |
242 | 250 |
case R.id.delete_container: |
243 | 251 |
showDialog(deleteContainer); |
244 | 252 |
return true; |
245 | 253 |
case R.id.enable_cdn: |
246 | 254 |
Intent viewIntent1 = new Intent(this, EnableCDNActivity.class); |
247 |
viewIntent1.putExtra("Cname", container.getName());
|
|
248 |
startActivityForResult(viewIntent1, 55);
|
|
255 |
viewIntent1.putExtra("Cname", container.getName());
|
|
256 |
startActivityForResult(viewIntent1, 56);
|
|
249 | 257 |
return true; |
250 | 258 |
case R.id.refresh: |
251 | 259 |
loadFiles(); |
252 |
return true;
|
|
260 |
return true;
|
|
253 | 261 |
} |
254 | 262 |
return false; |
255 |
} |
|
256 |
@Override |
|
257 |
protected Dialog onCreateDialog(int id ) { |
|
258 |
switch (id) { |
|
259 |
case deleteContainer: |
|
260 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
|
261 |
.setIcon(R.drawable.alert_dialog_icon) |
|
262 |
.setTitle("Delete Container") |
|
263 |
.setMessage("Are you sure you want to delete this Container?") |
|
264 |
.setPositiveButton("Delete Container", new DialogInterface.OnClickListener() { |
|
265 |
public void onClick(DialogInterface dialog, int whichButton) { |
|
266 |
// User clicked OK so do some stuff |
|
267 |
new DeleteContainerTask().execute((Void[]) null); |
|
268 |
} |
|
269 |
}) |
|
270 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
|
271 |
public void onClick(DialogInterface dialog, int whichButton) { |
|
272 |
// User clicked Cancel so do some stuff |
|
273 |
} |
|
274 |
}) |
|
275 |
.create(); |
|
276 |
|
|
277 |
} |
|
278 |
return null; |
|
279 |
} |
|
263 |
} |
|
264 |
|
|
280 | 265 |
@Override |
281 |
public void onActivityResult(int requestCode, int resultCode, Intent data) { |
|
282 |
super.onActivityResult(requestCode, resultCode, data); |
|
283 |
|
|
284 |
if (resultCode == RESULT_OK) { |
|
285 |
// a sub-activity kicked back, so we want to refresh the server list |
|
286 |
loadFiles(); |
|
287 |
|
|
288 |
} |
|
266 |
protected Dialog onCreateDialog(int id) { |
|
267 |
switch (id) { |
|
268 |
case deleteContainer: |
|
269 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
|
270 |
.setIcon(R.drawable.alert_dialog_icon) |
|
271 |
.setTitle("Delete Container") |
|
272 |
.setMessage( |
|
273 |
"Are you sure you want to delete this Container?") |
|
274 |
.setPositiveButton("Delete Container", |
|
275 |
new DialogInterface.OnClickListener() { |
|
276 |
public void onClick(DialogInterface dialog, |
|
277 |
int whichButton) { |
|
278 |
// User clicked OK so do some stuff |
|
279 |
new DeleteContainerTask() |
|
280 |
.execute((Void[]) null); |
|
281 |
} |
|
282 |
}) |
|
283 |
.setNegativeButton("Cancel", |
|
284 |
new DialogInterface.OnClickListener() { |
|
285 |
public void onClick(DialogInterface dialog, |
|
286 |
int whichButton) { |
|
287 |
// User clicked Cancel so do some stuff |
|
288 |
} |
|
289 |
}).create(); |
|
290 |
|
|
291 |
} |
|
292 |
return null; |
|
289 | 293 |
} |
290 | 294 |
|
291 |
private CloudServersException parseCloudServersException(HttpResponse response) { |
|
292 |
CloudServersException cse = new CloudServersException(); |
|
293 |
try { |
|
294 |
BasicResponseHandler responseHandler = new BasicResponseHandler(); |
|
295 |
String body = responseHandler.handleResponse(response); |
|
296 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser(); |
|
297 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
|
298 |
XMLReader xmlReader = saxParser.getXMLReader(); |
|
299 |
xmlReader.setContentHandler(parser); |
|
300 |
xmlReader.parse(new InputSource(new StringReader(body))); |
|
301 |
cse = parser.getException(); |
|
302 |
} catch (ClientProtocolException e) { |
|
303 |
cse = new CloudServersException(); |
|
304 |
cse.setMessage(e.getLocalizedMessage()); |
|
305 |
} catch (IOException e) { |
|
306 |
cse = new CloudServersException(); |
|
307 |
cse.setMessage(e.getLocalizedMessage()); |
|
308 |
} catch (ParserConfigurationException e) { |
|
309 |
cse = new CloudServersException(); |
|
310 |
cse.setMessage(e.getLocalizedMessage()); |
|
311 |
} catch (SAXException e) { |
|
312 |
cse = new CloudServersException(); |
|
313 |
cse.setMessage(e.getLocalizedMessage()); |
|
314 |
} catch (FactoryConfigurationError e) { |
|
315 |
cse = new CloudServersException(); |
|
316 |
cse.setMessage(e.getLocalizedMessage()); |
|
295 |
@Override |
|
296 |
public void onActivityResult(int requestCode, int resultCode, Intent data) { |
|
297 |
super.onActivityResult(requestCode, resultCode, data); |
|
298 |
|
|
299 |
if (resultCode == RESULT_OK) { |
|
300 |
// a sub-activity kicked back, so we want to refresh the server list |
|
301 |
loadFiles(); |
|
302 |
} |
|
303 |
if (requestCode == 56) { |
|
304 |
if (resultCode == RESULT_OK) { |
|
305 |
Intent viewIntent1 = new Intent(this, ListContainerActivity.class); |
|
306 |
startActivityForResult(viewIntent1, 56); |
|
317 | 307 |
} |
318 |
return cse; |
|
319 |
} |
|
320 |
private class DeleteContainerTask extends AsyncTask<Void, Void, HttpResponse> { |
|
321 |
|
|
308 |
} |
|
309 |
} |
|
310 |
|
|
311 |
private CloudServersException parseCloudServersException( |
|
312 |
HttpResponse response) { |
|
313 |
CloudServersException cse = new CloudServersException(); |
|
314 |
try { |
|
315 |
BasicResponseHandler responseHandler = new BasicResponseHandler(); |
|
316 |
String body = responseHandler.handleResponse(response); |
|
317 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser(); |
|
318 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
|
319 |
XMLReader xmlReader = saxParser.getXMLReader(); |
|
320 |
xmlReader.setContentHandler(parser); |
|
321 |
xmlReader.parse(new InputSource(new StringReader(body))); |
|
322 |
cse = parser.getException(); |
|
323 |
} catch (ClientProtocolException e) { |
|
324 |
cse = new CloudServersException(); |
|
325 |
cse.setMessage(e.getLocalizedMessage()); |
|
326 |
} catch (IOException e) { |
|
327 |
cse = new CloudServersException(); |
|
328 |
cse.setMessage(e.getLocalizedMessage()); |
|
329 |
} catch (ParserConfigurationException e) { |
|
330 |
cse = new CloudServersException(); |
|
331 |
cse.setMessage(e.getLocalizedMessage()); |
|
332 |
} catch (SAXException e) { |
|
333 |
cse = new CloudServersException(); |
|
334 |
cse.setMessage(e.getLocalizedMessage()); |
|
335 |
} catch (FactoryConfigurationError e) { |
|
336 |
cse = new CloudServersException(); |
|
337 |
cse.setMessage(e.getLocalizedMessage()); |
|
338 |
} |
|
339 |
return cse; |
|
340 |
} |
|
341 |
|
|
342 |
private class DeleteContainerTask extends |
|
343 |
AsyncTask<Void, Void, HttpResponse> { |
|
344 |
|
|
322 | 345 |
private CloudServersException exception; |
323 | 346 |
|
324 | 347 |
@Override |
... | ... | |
332 | 355 |
} |
333 | 356 |
return resp; |
334 | 357 |
} |
335 |
|
|
358 |
|
|
336 | 359 |
@Override |
337 |
protected void onPostExecute(HttpResponse response) {
|
|
360 |
protected void onPostExecute(HttpResponse response) { |
|
338 | 361 |
if (response != null) { |
339 | 362 |
int statusCode = response.getStatusLine().getStatusCode(); |
340 | 363 |
if (statusCode == 409) { |
341 |
showAlert("Error", "Container must be empty in order to delete"); |
|
364 |
showAlert("Error", |
|
365 |
"Container must be empty in order to delete"); |
|
342 | 366 |
} |
343 | 367 |
if (statusCode == 204) { |
344 | 368 |
setResult(Activity.RESULT_OK); |
345 | 369 |
finish(); |
346 |
|
|
370 |
|
|
347 | 371 |
} else { |
348 | 372 |
CloudServersException cse = parseCloudServersException(response); |
349 | 373 |
if ("".equals(cse.getMessage())) { |
350 |
showAlert("Error", "There was a problem deleting your container."); |
|
374 |
showAlert("Error", |
|
375 |
"There was a problem deleting your container."); |
|
351 | 376 |
} else { |
352 |
showAlert("Error", "There was a problem deleting your container: " + cse.getMessage()); |
|
377 |
showAlert("Error", |
|
378 |
"There was a problem deleting your container: " |
|
379 |
+ cse.getMessage()); |
|
353 | 380 |
} |
354 | 381 |
} |
355 | 382 |
} else if (exception != null) { |
356 |
showAlert("Error", "There was a problem deleting your server: " + exception.getMessage()); |
|
357 |
} |
|
383 |
showAlert("Error", "There was a problem deleting your server: " |
|
384 |
+ exception.getMessage()); |
|
385 |
} |
|
358 | 386 |
} |
359 |
}
|
|
387 |
}
|
|
360 | 388 |
|
361 |
|
|
362 | 389 |
} |
363 |
|
|
364 |
|
b/src/com/rackspacecloud/android/EnableCDNActivity.java | ||
---|---|---|
35 | 35 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
36 | 36 |
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser; |
37 | 37 |
|
38 |
public class EnableCDNActivity extends Activity implements OnClickListener, OnItemSelectedListener {
|
|
39 |
|
|
38 |
public class EnableCDNActivity extends Activity implements OnClickListener,
|
|
39 |
OnItemSelectedListener { |
|
40 | 40 |
|
41 | 41 |
public static String containerName = null; |
42 | 42 |
private String selectedTtlId; |
... | ... | |
45 | 45 |
private Spinner ttlSpinner; |
46 | 46 |
private Spinner logRetSpinner; |
47 | 47 |
private Spinner cdnSpinner; |
48 |
|
|
49 |
/** Called when the activity is first created. */
|
|
50 |
@Override
|
|
51 |
public void onCreate(Bundle savedInstanceState) {
|
|
52 |
super.onCreate(savedInstanceState);
|
|
53 |
setContentView(R.layout.enable_cdn_container);
|
|
54 |
containerName = (String) this.getIntent().getExtras().get("Cname");
|
|
55 |
setupButtons();
|
|
56 |
loadTtlSpinner();
|
|
48 |
|
|
49 |
/** Called when the activity is first created. */
|
|
50 |
@Override
|
|
51 |
public void onCreate(Bundle savedInstanceState) {
|
|
52 |
super.onCreate(savedInstanceState);
|
|
53 |
setContentView(R.layout.enable_cdn_container);
|
|
54 |
containerName = (String) this.getIntent().getExtras().get("Cname");
|
|
55 |
setupButtons();
|
|
56 |
loadTtlSpinner();
|
|
57 | 57 |
loadLogRetSpinner(); |
58 | 58 |
loadCdnSpinner(); |
59 |
|
|
60 |
} |
|
61 |
private void setupButton(int resourceId, OnClickListener onClickListener) { |
|
59 |
|
|
60 |
} |
|
61 |
|
|
62 |
private void setupButton(int resourceId, OnClickListener onClickListener) { |
|
62 | 63 |
Button button = (Button) findViewById(resourceId); |
63 | 64 |
button.setOnClickListener(onClickListener); |
64 |
} |
|
65 |
|
|
66 |
private void setupButtons() { |
|
67 |
setupButton(R.id.enable_button, new OnClickListener() { |
|
68 |
public void onClick(View v) { |
|
69 |
showDialog(R.id.enable_button); |
|
70 |
} |
|
71 |
}); |
|
72 |
|
|
73 |
setupButton(R.id.disable_button, new OnClickListener() { |
|
74 |
public void onClick(View v) { |
|
75 |
showDialog(R.id.disable_button); |
|
76 |
} |
|
77 |
}); |
|
78 |
} |
|
79 |
|
|
80 |
private void loadCdnSpinner(){ |
|
81 |
cdnSpinner = (Spinner) findViewById(R.id.cdn_spinner); |
|
82 |
cdnSpinner.setOnItemSelectedListener(this); |
|
83 |
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( |
|
84 |
this, R.array.cdn, android.R.layout.simple_spinner_item); |
|
85 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
86 |
cdnSpinner.setAdapter(adapter); |
|
87 |
|
|
88 |
|
|
89 |
} |
|
90 |
|
|
91 |
private void loadTtlSpinner() { |
|
92 |
ttlSpinner = (Spinner) findViewById(R.id.ttl_spinner); |
|
93 |
ttlSpinner.setOnItemSelectedListener(this); |
|
94 |
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( |
|
95 |
this, R.array.ttl, android.R.layout.simple_spinner_item); |
|
96 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
97 |
ttlSpinner.setAdapter(adapter); |
|
98 |
|
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
|
|
103 |
private void loadLogRetSpinner() { |
|
104 |
logRetSpinner = (Spinner) findViewById(R.id.log_retention_spinner); |
|
105 |
logRetSpinner.setOnItemSelectedListener(this); |
|
106 |
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( |
|
107 |
this, R.array.logRet, android.R.layout.simple_spinner_item); |
|
108 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
109 |
logRetSpinner.setAdapter(adapter); |
|
110 |
|
|
111 |
} |
|
112 |
|
|
113 |
public void onItemSelected(AdapterView<?> parent, View view, int id, |
|
114 |
long arg3) { |
|
115 |
if (parent == cdnSpinner) { |
|
116 |
selectedCdnId = cdnSpinner.getSelectedItem().toString(); |
|
117 |
} |
|
65 |
} |
|
66 |
|
|
67 |
private void setupButtons() { |
|
68 |
setupButton(R.id.enable_button, new OnClickListener() { |
|
69 |
public void onClick(View v) { |
|
70 |
showDialog(R.id.enable_button); |
|
71 |
} |
|
72 |
}); |
|
73 |
|
|
74 |
setupButton(R.id.disable_button, new OnClickListener() { |
|
75 |
public void onClick(View v) { |
|
76 |
showDialog(R.id.disable_button); |
|
77 |
} |
|
78 |
}); |
|
79 |
} |
|
80 |
|
|
81 |
private void loadCdnSpinner() { |
|
82 |
cdnSpinner = (Spinner) findViewById(R.id.cdn_spinner); |
|
83 |
cdnSpinner.setOnItemSelectedListener(this); |
|
84 |
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( |
|
85 |
this, R.array.cdn, android.R.layout.simple_spinner_item); |
|
86 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
87 |
cdnSpinner.setAdapter(adapter); |
|
88 |
|
|
89 |
} |
|
90 |
|
|
91 |
private void loadTtlSpinner() { |
|
92 |
ttlSpinner = (Spinner) findViewById(R.id.ttl_spinner); |
|
93 |
ttlSpinner.setOnItemSelectedListener(this); |
|
94 |
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( |
|
95 |
this, R.array.ttl, android.R.layout.simple_spinner_item); |
|
96 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
97 |
ttlSpinner.setAdapter(adapter); |
|
98 |
|
|
99 |
} |
|
100 |
|
|
101 |
private void loadLogRetSpinner() { |
|
102 |
logRetSpinner = (Spinner) findViewById(R.id.log_retention_spinner); |
|
103 |
logRetSpinner.setOnItemSelectedListener(this); |
|
104 |
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( |
|
105 |
this, R.array.logRet, android.R.layout.simple_spinner_item); |
|
106 |
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
107 |
logRetSpinner.setAdapter(adapter); |
|
108 |
|
|
109 |
} |
|
110 |
|
|
111 |
public void onItemSelected(AdapterView<?> parent, View view, int id, |
|
112 |
long arg3) { |
|
113 |
if (parent == cdnSpinner) { |
|
114 |
selectedCdnId = cdnSpinner.getSelectedItem().toString(); |
|
115 |
} |
|
118 | 116 |
if (parent == ttlSpinner) { |
119 | 117 |
selectedTtlId = ttlSpinner.getSelectedItem().toString(); |
120 | 118 |
} else if (parent == logRetSpinner) { |
121 | 119 |
selectedLogRetId = logRetSpinner.getSelectedItem().toString(); |
122 | 120 |
} |
123 |
} |
|
124 |
public void onNothingSelected(AdapterView<?> parent) { |
|
125 |
|
|
126 |
} |
|
121 |
} |
|
122 |
|
|
123 |
public void onNothingSelected(AdapterView<?> parent) { |
|
124 |
|
|
125 |
} |
|
126 |
|
|
127 | 127 |
private void showAlert(String title, String message) { |
128 | 128 |
AlertDialog alert = new AlertDialog.Builder(this).create(); |
129 | 129 |
alert.setTitle(title); |
130 | 130 |
alert.setMessage(message); |
131 | 131 |
alert.setButton("OK", new DialogInterface.OnClickListener() { |
132 |
public void onClick(DialogInterface dialog, int which) { |
|
133 |
return; |
|
134 |
} }); |
|
132 |
public void onClick(DialogInterface dialog, int which) { |
|
133 |
return; |
|
134 |
} |
|
135 |
}); |
|
135 | 136 |
alert.show(); |
136 | 137 |
hideActivityIndicators(); |
137 |
} |
|
138 |
@Override |
|
139 |
protected Dialog onCreateDialog(int id) { |
|
140 |
switch (id) { |
|
141 |
case R.id.enable_button: |
|
142 |
return new AlertDialog.Builder(EnableCDNActivity.this) |
|
143 |
.setIcon(R.drawable.alert_dialog_icon) |
|
144 |
.setTitle("Enable CDN") |
|
145 |
.setMessage("Are you sure you want to enable CDN on this container?") |
|
146 |
.setPositiveButton("Enable CDN", new DialogInterface.OnClickListener() { |
|
147 |
public void onClick(DialogInterface dialog, int whichButton) { |
|
148 |
// User clicked OK so do some stuff |
|
149 |
new EnableCDNTask().execute((Void[]) null); |
|
150 |
} |
|
151 |
}) |
|
152 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
|
153 |
public void onClick(DialogInterface dialog, int whichButton) { |
|
154 |
// User clicked Cancel so do some stuff |
|
155 |
} |
|
156 |
}) |
|
157 |
.create(); |
|
158 |
case R.id.disable_button: |
|
159 |
return new AlertDialog.Builder(EnableCDNActivity.this) |
|
160 |
.setIcon(R.drawable.alert_dialog_icon) |
|
161 |
.setTitle("Change Attributes") |
|
162 |
.setMessage("Are you sure you want to disable CDN, and/or change attributes?") |
|
163 |
.setPositiveButton("Change Attributes", new DialogInterface.OnClickListener() { |
|
164 |
public void onClick(DialogInterface dialog, int whichButton) { |
|
165 |
// User clicked OK so do some stuff |
|
166 |
new DisableCDNTask().execute((Void[]) null); |
|
167 |
} |
|
168 |
}) |
|
169 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
|
170 |
public void onClick(DialogInterface dialog, int whichButton) { |
|
171 |
// User clicked Cancel so do some stuff |
|
172 |
} |
|
173 |
}) |
|
174 |
.create(); |
|
175 |
} |
|
176 |
return null; |
|
177 |
} |
|
178 |
private void setActivityIndicatorsVisibility(int visibility) { |
|
179 |
ProgressBar pb = (ProgressBar) findViewById(R.id.save_container_progress_bar); |
|
180 |
TextView tv = (TextView) findViewById(R.id.saving_container_label); |
|
181 |
pb.setVisibility(visibility); |
|
182 |
tv.setVisibility(visibility); |
|
183 |
} |
|
184 |
|
|
185 |
@SuppressWarnings("unused") |
|
138 |
} |
|
139 |
|
|
140 |
@Override |
|
141 |
protected Dialog onCreateDialog(int id) { |
|
142 |
switch (id) { |
|
143 |
case R.id.enable_button: |
|
144 |
return new AlertDialog.Builder(EnableCDNActivity.this) |
|
145 |
.setIcon(R.drawable.alert_dialog_icon) |
|
146 |
.setTitle("Enable CDN") |
|
147 |
.setMessage( |
|
148 |
"Are you sure you want to enable CDN on this container?") |
|
149 |
.setPositiveButton("Enable CDN", |
|
150 |
new DialogInterface.OnClickListener() { |
|
151 |
public void onClick(DialogInterface dialog, |
|
152 |
int whichButton) { |
|
153 |
// User clicked OK so do some stuff |
|
154 |
new EnableCDNTask().execute((Void[]) null); |
|
155 |
} |
|
156 |
}) |
|
157 |
.setNegativeButton("Cancel", |
|
158 |
new DialogInterface.OnClickListener() { |
|
159 |
public void onClick(DialogInterface dialog, |
|
160 |
int whichButton) { |
|
161 |
// User clicked Cancel so do some stuff |
|
162 |
} |
|
163 |
}).create(); |
|
164 |
case R.id.disable_button: |
|
165 |
return new AlertDialog.Builder(EnableCDNActivity.this) |
|
166 |
.setIcon(R.drawable.alert_dialog_icon) |
|
167 |
.setTitle("Change Attributes") |
|
168 |
.setMessage( |
|
169 |
"Are you sure you want to disable CDN, and/or change attributes?") |
|
170 |
.setPositiveButton("Change Attributes", |
|
171 |
new DialogInterface.OnClickListener() { |
|
172 |
public void onClick(DialogInterface dialog, |
|
173 |
int whichButton) { |
|
174 |
// User clicked OK so do some stuff |
|
175 |
new ChangeAttributesCDNTask().execute((Void[]) null); |
|
176 |
} |
|
177 |
}) |
|
178 |
.setNegativeButton("Cancel", |
|
179 |
new DialogInterface.OnClickListener() { |
|
180 |
public void onClick(DialogInterface dialog, |
|
181 |
int whichButton) { |
|
182 |
// User clicked Cancel so do some stuff |
|
183 |
} |
|
184 |
}).create(); |
|
185 |
} |
|
186 |
return null; |
|
187 |
} |
|
188 |
|
|
189 |
private void setActivityIndicatorsVisibility(int visibility) { |
|
190 |
ProgressBar pb = (ProgressBar) findViewById(R.id.save_container_progress_bar); |
|
191 |
TextView tv = (TextView) findViewById(R.id.saving_container_label); |
|
192 |
pb.setVisibility(visibility); |
|
193 |
tv.setVisibility(visibility); |
|
194 |
} |
|
195 |
|
|
196 |
@SuppressWarnings("unused") |
|
186 | 197 |
private void showActivityIndicators() { |
187 |
setActivityIndicatorsVisibility(View.VISIBLE); |
|
188 |
} |
|
189 |
|
|
190 |
private void hideActivityIndicators() { |
|
191 |
setActivityIndicatorsVisibility(View.INVISIBLE); |
|
192 |
} |
|
193 |
//using CloudServersException, it works for us too |
|
194 |
private CloudServersException parseCloudServersException(HttpResponse response) { |
|
198 |
setActivityIndicatorsVisibility(View.VISIBLE); |
|
199 |
} |
|
200 |
|
|
201 |
private void hideActivityIndicators() { |
|
202 |
setActivityIndicatorsVisibility(View.INVISIBLE); |
|
203 |
} |
|
204 |
|
|
205 |
// using CloudServersException, it works for us too |
|
206 |
private CloudServersException parseCloudServersException( |
|
207 |
HttpResponse response) { |
|
195 | 208 |
CloudServersException cse = new CloudServersException(); |
196 | 209 |
try { |
197 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
|
198 |
String body = responseHandler.handleResponse(response);
|
|
199 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
|
200 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
|
|
201 |
XMLReader xmlReader = saxParser.getXMLReader();
|
|
202 |
xmlReader.setContentHandler(parser);
|
|
203 |
xmlReader.parse(new InputSource(new StringReader(body)));
|
|
204 |
cse = parser.getException();
|
|
210 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
|
211 |
String body = responseHandler.handleResponse(response);
|
|
212 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
|
213 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
|
|
214 |
XMLReader xmlReader = saxParser.getXMLReader();
|
|
215 |
xmlReader.setContentHandler(parser);
|
|
216 |
xmlReader.parse(new InputSource(new StringReader(body)));
|
|
217 |
cse = parser.getException();
|
|
205 | 218 |
} catch (ClientProtocolException e) { |
206 | 219 |
cse = new CloudServersException(); |
207 | 220 |
cse.setMessage(e.getLocalizedMessage()); |
... | ... | |
219 | 232 |
cse.setMessage(e.getLocalizedMessage()); |
220 | 233 |
} |
221 | 234 |
return cse; |
222 |
}
|
|
223 |
|
|
224 |
public class EnableCDNTask extends AsyncTask<Void, Void, HttpResponse> {
|
|
225 |
private CloudServersException exception;
|
|
226 |
|
|
227 |
@Override
|
|
235 |
}
|
|
236 |
|
|
237 |
public class EnableCDNTask extends AsyncTask<Void, Void, HttpResponse> {
|
|
238 |
private CloudServersException exception;
|
|
239 |
|
|
240 |
@Override
|
|
228 | 241 |
protected HttpResponse doInBackground(Void... arg0) { |
229 | 242 |
HttpResponse resp = null; |
230 | 243 |
try { |
231 |
resp = (new ContainerManager()).enable(containerName, selectedTtlId, selectedLogRetId); |
|
244 |
resp = (new ContainerManager()).enable(containerName, |
|
245 |
selectedTtlId, selectedLogRetId); |
|
232 | 246 |
} catch (CloudServersException e) { |
233 | 247 |
exception = e; |
234 | 248 |
} |
235 | 249 |
return resp; |
236 | 250 |
} |
237 |
|
|
251 |
|
|
238 | 252 |
@Override |
239 | 253 |
protected void onPostExecute(HttpResponse response) { |
240 | 254 |
if (response != null) { |
... | ... | |
243 | 257 |
setResult(Activity.RESULT_OK); |
244 | 258 |
finish(); |
245 | 259 |
} else if (statusCode == 202) { |
246 |
showAlert("Accepted", "Container is already cdn enabled");
|
|
247 |
finish();
|
|
248 |
} else {
|
|
260 |
showAlert("Accepted", "Container is already cdn enabled"); |
|
261 |
finish(); |
|
262 |
} else {
|
|
249 | 263 |
CloudServersException cse = parseCloudServersException(response); |
250 | 264 |
if ("".equals(cse.getMessage())) { |
251 |
showAlert("Error", "There was a problem creating your container."); |
|
265 |
showAlert("Error", |
|
266 |
"There was a problem creating your container."); |
|
252 | 267 |
} else { |
253 |
showAlert("Error", "There was a problem creating your container: " + cse.getMessage() + " Check container name and try again"); |
|
268 |
showAlert("Error", |
|
269 |
"There was a problem creating your container: " |
|
270 |
+ cse.getMessage() |
|
271 |
+ " Check container name and try again"); |
|
254 | 272 |
} |
255 | 273 |
} |
256 | 274 |
} else if (exception != null) { |
257 |
showAlert("Error", "There was a problem creating your container: " + exception.getMessage()+" Check container name and try again"); |
|
258 |
} |
|
275 |
showAlert("Error", |
|
276 |
"There was a problem creating your container: " |
|
277 |
+ exception.getMessage() |
|
278 |
+ " Check container name and try again"); |
|
279 |
} |
|
259 | 280 |
} |
260 |
} |
|
261 |
public class DisableCDNTask extends AsyncTask<Void, Void, HttpResponse> { |
|
262 |
private CloudServersException exception; |
|
263 |
|
|
264 |
@Override |
|
281 |
} |
|
282 |
|
|
283 |
public class ChangeAttributesCDNTask extends AsyncTask<Void, Void, HttpResponse> { |
|
284 |
private CloudServersException exception; |
|
285 |
|
|
286 |
@Override |
|
265 | 287 |
protected HttpResponse doInBackground(Void... arg0) { |
266 | 288 |
HttpResponse resp = null; |
267 | 289 |
try { |
268 |
resp = (new ContainerManager()).disable(containerName, selectedCdnId, selectedTtlId, selectedLogRetId); |
|
290 |
resp = (new ContainerManager()).disable(containerName, |
|
291 |
selectedCdnId, selectedTtlId, selectedLogRetId); |
|
269 | 292 |
} catch (CloudServersException e) { |
270 | 293 |
exception = e; |
271 | 294 |
} |
272 | 295 |
return resp; |
273 | 296 |
} |
274 |
|
|
297 |
|
|
275 | 298 |
@Override |
276 | 299 |
protected void onPostExecute(HttpResponse response) { |
277 | 300 |
if (response != null) { |
... | ... | |
282 | 305 |
} else { |
283 | 306 |
CloudServersException cse = parseCloudServersException(response); |
284 | 307 |
if ("".equals(cse.getMessage())) { |
285 |
showAlert("Error", "There was a problem creating your container."); |
|
308 |
showAlert("Error", |
|
309 |
"There was a problem creating your container."); |
|
286 | 310 |
} else { |
287 |
showAlert("Error", "There was a problem creating your container: " + cse.getMessage() + " Check container name and try again"); |
|
311 |
showAlert("Error", |
|
312 |
"There was a problem creating your container: " |
|
313 |
+ cse.getMessage() |
|
314 |
+ " Check container name and try again"); |
|
288 | 315 |
} |
289 | 316 |
} |
290 | 317 |
} else if (exception != null) { |
291 |
showAlert("Error", "There was a problem creating your container: " + exception.getMessage()+" Check container name and try again"); |
|
292 |
} |
|
318 |
showAlert("Error", |
|
319 |
"There was a problem creating your container: " |
|
320 |
+ exception.getMessage() |
|
321 |
+ " Check container name and try again"); |
|
322 |
} |
|
293 | 323 |
} |
294 |
} |
|
324 |
} |
|
325 |
|
|
295 | 326 |
public void onClick(View v) { |
296 | 327 |
// TODO Auto-generated method stub |
297 |
|
|
298 |
} |
|
299 |
|
|
300 | 328 |
|
329 |
} |
|
301 | 330 |
|
302 |
} |
|
331 |
} |
b/src/com/rackspacecloud/android/ListContainerActivity.java | ||
---|---|---|
23 | 23 |
import com.rackspace.cloud.files.api.client.ContainerManager; |
24 | 24 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
25 | 25 |
|
26 |
/**
|
|
26 |
/** |
|
27 | 27 |
* |
28 | 28 |
* @author Phillip Toohill |
29 |
* |
|
29 |
*
|
|
30 | 30 |
*/ |
31 | 31 |
public class ListContainerActivity extends ListActivity { |
32 | 32 |
|
... | ... | |
39 | 39 |
public int bConver = 1048576; |
40 | 40 |
public int kbConver = 1024; |
41 | 41 |
protected static final int DELETE_ID = 0; |
42 |
|
|
42 |
|
|
43 | 43 |
@Override |
44 |
public void onCreate(Bundle savedInstanceState) {
|
|
45 |
super.onCreate(savedInstanceState);
|
|
46 |
restoreState(savedInstanceState);
|
|
47 |
}
|
|
48 |
|
|
44 |
public void onCreate(Bundle savedInstanceState) {
|
|
45 |
super.onCreate(savedInstanceState);
|
|
46 |
restoreState(savedInstanceState);
|
|
47 |
}
|
|
48 |
|
|
49 | 49 |
@Override |
50 | 50 |
protected void onSaveInstanceState(Bundle outState) { |
51 | 51 |
super.onSaveInstanceState(outState); |
52 | 52 |
outState.putSerializable("container", containers); |
53 | 53 |
} |
54 | 54 |
|
55 |
private void restoreState(Bundle state) { |
|
56 |
if (state != null && state.containsKey("container")) { |
|
57 |
containers = (Container[]) state.getSerializable("container"); |
|
58 |
if (containers.length == 0) { |
|
59 |
displayNoServersCell(); |
|
60 |
} else { |
|
61 |
getListView().setDividerHeight(1); // restore divider lines |
|
62 |
setListAdapter(new FileAdapter()); |
|
63 |
} |
|
64 |
} else { |
|
65 |
loadContainers(); |
|
66 |
registerForContextMenu(getListView()); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
|
73 |
if (containers != null && containers.length > 0) { |
|
74 |
Intent viewIntent = new Intent(this, ContainerObjectsActivity.class); |
|
75 |
viewIntent.putExtra("container", containers[position]); |
|
76 |
startActivityForResult(viewIntent, 55); |
|
77 |
|
|
78 |
//startActivityForResult(viewIntent, 55); // arbitrary number; never used again |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
private void loadContainers() { |
|
83 |
displayLoadingCell(); |
|
84 |
new LoadContainersTask().execute((Void[]) null); |
|
85 |
} |
|
86 |
|
|
87 |
private void setContainerList() { |
|
55 |
private void restoreState(Bundle state) { |
|
56 |
if (state != null && state.containsKey("container")) { |
|
57 |
containers = (Container[]) state.getSerializable("container"); |
|
58 |
if (containers.length == 0) { |
|
59 |
displayNoServersCell(); |
|
60 |
} else { |
|
61 |
getListView().setDividerHeight(1); // restore divider lines |
|
62 |
setListAdapter(new FileAdapter()); |
|
63 |
} |
|
64 |
} else { |
|
65 |
loadContainers(); |
|
66 |
registerForContextMenu(getListView()); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
|
71 |
if (containers != null && containers.length > 0) { |
|
72 |
Intent viewIntent = new Intent(this, ContainerObjectsActivity.class); |
|
73 |
viewIntent.putExtra("container", containers[position]); |
|
74 |
startActivityForResult(viewIntent, 55); |
|
75 |
|
|
76 |
// startActivityForResult(viewIntent, 55); // arbitrary number; |
|
77 |
// never used again |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
private void loadContainers() { |
|
82 |
displayLoadingCell(); |
|
83 |
new LoadContainersTask().execute((Void[]) null); |
|
84 |
} |
|
85 |
|
|
86 |
private void setContainerList() { |
|
88 | 87 |
if (containerNames.length == 0) { |
89 | 88 |
displayNoServersCell(); |
90 | 89 |
} else { |
91 |
getListView().setDividerHeight(1); // restore divider lines
|
|
90 |
getListView().setDividerHeight(1); // restore divider lines |
|
92 | 91 |
setListAdapter(new FileAdapter()); |
93 | 92 |
} |
94 |
} |
|
95 |
|
|
96 |
private void displayLoadingCell() { |
|
97 |
String a[] = new String[1]; |
|
98 |
a[0] = "Loading..."; |
|
99 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.loadingcell, R.id.loading_label, a)); |
|
100 |
getListView().setTextFilterEnabled(true); |
|
101 |
getListView().setDividerHeight(0); // hide the dividers so it won't look like a list row |
|
102 |
getListView().setItemsCanFocus(false); |
|
103 |
} |
|
104 |
|
|
105 |
private void displayNoServersCell() { |
|
106 |
String a[] = new String[1]; |
|
107 |
a[0] = "No Files"; |
|
108 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.nocontainerscell, R.id.no_containers_label, a)); |
|
109 |
getListView().setTextFilterEnabled(true); |
|
110 |
getListView().setDividerHeight(0); // hide the dividers so it won't look like a list row |
|
111 |
getListView().setItemsCanFocus(false); |
|
112 |
} |
|
113 |
|
|
114 |
private void showAlert(String title, String message) { |
|
115 |
//Can't create handler inside thread that has not called Looper.prepare() |
|
116 |
//Looper.prepare(); |
|
117 |
try { |
|
118 |
AlertDialog alert = new AlertDialog.Builder(this).create(); |
|
119 |
alert.setTitle(title); |
|
120 |
alert.setMessage(message); |
|
121 |
alert.setButton("OK", new DialogInterface.OnClickListener() { |
|
122 |
public void onClick(DialogInterface dialog, int which) { |
|
123 |
return; |
|
124 |
} }); |
|
125 |
alert.show(); |
|
126 |
} catch (Exception e) { |
|
127 |
e.printStackTrace(); |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
private class LoadContainersTask extends AsyncTask<Void, Void, ArrayList<Container>> { |
|
134 |
|
|
135 |
private CloudServersException exception; |
|
136 |
|
|
93 |
} |
|
94 |
|
|
95 |
private void displayLoadingCell() { |
|
96 |
String a[] = new String[1]; |
|
97 |
a[0] = "Loading..."; |
|
98 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.loadingcell, |
|
99 |
R.id.loading_label, a)); |
|
100 |
getListView().setTextFilterEnabled(true); |
|
101 |
getListView().setDividerHeight(0); // hide the dividers so it won't look |
|
102 |
// like a list row |
|
103 |
getListView().setItemsCanFocus(false); |
|
104 |
} |
|
105 |
|
|
106 |
private void displayNoServersCell() { |
|
107 |
String a[] = new String[1]; |
|
108 |
a[0] = "No Files"; |
|
109 |
setListAdapter(new ArrayAdapter<String>(this, |
|
110 |
R.layout.nocontainerscell, R.id.no_containers_label, a)); |
|
111 |
getListView().setTextFilterEnabled(true); |
|
112 |
getListView().setDividerHeight(0); // hide the dividers so it won't look |
|
113 |
// like a list row |
|
114 |
getListView().setItemsCanFocus(false); |
|
115 |
} |
|
116 |
|
|
117 |
private void showAlert(String title, String message) { |
|
118 |
// Can't create handler inside thread that has not called |
|
119 |
// Looper.prepare() |
|
120 |
// Looper.prepare(); |
|
121 |
try { |
|
122 |
AlertDialog alert = new AlertDialog.Builder(this).create(); |
|
123 |
alert.setTitle(title); |
|
124 |
alert.setMessage(message); |
|
125 |
alert.setButton("OK", new DialogInterface.OnClickListener() { |
|
126 |
public void onClick(DialogInterface dialog, int which) { |
|
127 |
return; |
|
128 |
} |
|
129 |
}); |
|
130 |
alert.show(); |
|
131 |
} catch (Exception e) { |
|
132 |
e.printStackTrace(); |
|
133 |
} |
|
134 |
} |
|
135 |
|
|
136 |
private class LoadContainersTask extends |
|
137 |
AsyncTask<Void, Void, ArrayList<Container>> { |
|
138 |
|
|
139 |
private CloudServersException exception; |
|
140 |
|
|
137 | 141 |
@Override |
138 | 142 |
protected ArrayList<Container> doInBackground(Void... arg0) { |
139 | 143 |
ArrayList<Container> containers = null; |
140 |
|
|
144 |
|
|
141 | 145 |
try { |
142 | 146 |
containers = (new ContainerManager()).createList(true); |
143 | 147 |
} catch (CloudServersException e) { |
144 |
exception = e;
|
|
148 |
exception = e; |
|
145 | 149 |
} |
146 | 150 |
return containers; |
147 | 151 |
} |
148 |
|
|
149 | 152 |
|
150 | 153 |
@Override |
151 | 154 |
protected void onPostExecute(ArrayList<Container> result) { |
... | ... | |
153 | 156 |
showAlert("Error", exception.getMessage()); |
154 | 157 |
} |
155 | 158 |
ArrayList<Container> containerList = result; |
156 |
containerNames= new String[containerList.size()]; |
|
159 |
containerNames = new String[containerList.size()];
|
|
157 | 160 |
containers = new Container[containerList.size()]; |
158 |
if(containerList != null) { |
|
159 |
for(int i = 0; i < containerList.size(); i++){
|
|
161 |
if (containerList != null) {
|
|
162 |
for (int i = 0; i < containerList.size(); i++) {
|
|
160 | 163 |
Container container = containerList.get(i); |
161 | 164 |
containers[i] = container; |
162 | 165 |
containerNames[i] = container.getName(); |
163 | 166 |
} |
164 | 167 |
} |
165 |
|
|
166 |
new LoadCDNContainersTask().execute((Void[]) null);
|
|
168 |
|
|
169 |
new LoadCDNContainersTask().execute((Void[]) null);
|
|
167 | 170 |
} |
168 |
} |
|
171 |
} |
|
172 |
|
|
173 |
private class LoadCDNContainersTask extends |
|
174 |
AsyncTask<Void, Void, ArrayList<Container>> { |
|
175 |
|
|
176 |
private CloudServersException exception; |
|
169 | 177 |
|
170 |
private class LoadCDNContainersTask extends AsyncTask<Void, Void, ArrayList<Container>> { |
|
171 |
|
|
172 |
private CloudServersException exception; |
|
173 |
|
|
174 | 178 |
@Override |
175 | 179 |
protected ArrayList<Container> doInBackground(Void... arg0) { |
176 | 180 |
ArrayList<Container> cdnContainers = null; |
177 |
|
|
181 |
|
|
178 | 182 |
try { |
179 | 183 |
cdnContainers = (new ContainerManager()).createCDNList(true); |
180 | 184 |
} catch (CloudServersException e) { |
181 |
exception = e;
|
|
185 |
exception = e; |
|
182 | 186 |
} |
183 | 187 |
return cdnContainers; |
184 | 188 |
} |
185 |
|
|
189 |
|
|
186 | 190 |
@Override |
187 | 191 |
protected void onPostExecute(ArrayList<Container> result) { |
188 | 192 |
Log.v("listcontainerActivity", "onPostExecute loadCDNcontainerTask"); |
Also available in: Unified diff