Revision b722cab3 src/com/rackspacecloud/android/ListContainerActivity.java
b/src/com/rackspacecloud/android/ListContainerActivity.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import android.app.AlertDialog; |
6 | 6 |
import android.app.ListActivity; |
7 |
import android.app.ProgressDialog; |
|
8 | 7 |
import android.content.Context; |
9 | 8 |
import android.content.DialogInterface; |
10 | 9 |
import android.content.Intent; |
... | ... | |
17 | 16 |
import android.view.MenuItem; |
18 | 17 |
import android.view.View; |
19 | 18 |
import android.view.ViewGroup; |
20 |
import android.view.WindowManager; |
|
21 |
import android.view.ViewGroup.LayoutParams; |
|
22 | 19 |
import android.widget.ArrayAdapter; |
23 | 20 |
import android.widget.ListView; |
24 |
import android.widget.ProgressBar; |
|
25 | 21 |
import android.widget.TextView; |
26 | 22 |
|
27 | 23 |
import com.rackspace.cloud.files.api.client.Container; |
28 | 24 |
import com.rackspace.cloud.files.api.client.ContainerManager; |
29 | 25 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
30 | 26 |
|
27 |
/** |
|
28 |
* |
|
29 |
* @author Phillip Toohill |
|
30 |
* |
|
31 |
*/ |
|
31 | 32 |
public class ListContainerActivity extends ListActivity { |
32 | 33 |
|
33 | 34 |
protected static final int DELETE_ID = 0; |
... | ... | |
42 | 43 |
public int kbConver = 1024; |
43 | 44 |
private Context context; |
44 | 45 |
private boolean loading; |
45 |
ProgressDialog pDialog; |
|
46 | 46 |
|
47 | 47 |
@Override |
48 | 48 |
public void onCreate(Bundle savedInstanceState) { |
49 | 49 |
super.onCreate(savedInstanceState); |
50 | 50 |
context = getApplicationContext(); |
51 |
setContentView(R.layout.list_containers); |
|
52 | 51 |
restoreState(savedInstanceState); |
53 | 52 |
} |
54 | 53 |
|
... | ... | |
67 | 66 |
else if (state != null && state.containsKey("container") && state.getSerializable("container") != null) { |
68 | 67 |
containers = (Container[]) state.getSerializable("container"); |
69 | 68 |
if (containers.length == 0) { |
70 |
displayNoContainersCell();
|
|
69 |
displayNoServersCell();
|
|
71 | 70 |
} else { |
72 | 71 |
getListView().setDividerHeight(1); // restore divider lines |
73 | 72 |
setListAdapter(new FileAdapter()); |
... | ... | |
87 | 86 |
} |
88 | 87 |
|
89 | 88 |
private void loadContainers() { |
90 |
// displayNoContainersCell();
|
|
89 |
displayLoadingCell();
|
|
91 | 90 |
new LoadContainersTask().execute((Void[]) null); |
92 | 91 |
} |
93 | 92 |
|
94 | 93 |
private void setContainerList() { |
95 | 94 |
if (containerNames.length == 0) { |
96 |
displayNoContainersCell();
|
|
95 |
displayNoServersCell();
|
|
97 | 96 |
} else { |
98 | 97 |
getListView().setDividerHeight(1); // restore divider lines |
99 | 98 |
setListAdapter(new FileAdapter()); |
100 | 99 |
} |
101 | 100 |
} |
102 | 101 |
|
103 |
// private void displayLoadingCell() {
|
|
104 |
// String a[] = new String[1];
|
|
105 |
// a[0] = "Loading...";
|
|
106 |
// setListAdapter(new ArrayAdapter<String>(this, R.layout.loadingcell,
|
|
107 |
// R.id.loading_label, a));
|
|
108 |
// getListView().setTextFilterEnabled(true);
|
|
109 |
// getListView().setDividerHeight(0); // hide the dividers so it won't look
|
|
110 |
// // like a list row
|
|
111 |
// getListView().setItemsCanFocus(false);
|
|
112 |
// }
|
|
113 |
|
|
114 |
private void displayNoContainersCell() {
|
|
102 |
private void displayLoadingCell() { |
|
103 |
String a[] = new String[1]; |
|
104 |
a[0] = "Loading..."; |
|
105 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.loadingcell, |
|
106 |
R.id.loading_label, a)); |
|
107 |
getListView().setTextFilterEnabled(true); |
|
108 |
getListView().setDividerHeight(0); // hide the dividers so it won't look |
|
109 |
// like a list row |
|
110 |
getListView().setItemsCanFocus(false); |
|
111 |
} |
|
112 |
|
|
113 |
private void displayNoServersCell() {
|
|
115 | 114 |
String a[] = new String[1]; |
116 | 115 |
a[0] = "No Files"; |
117 | 116 |
setListAdapter(new ArrayAdapter<String>(this, |
... | ... | |
121 | 120 |
// like a list row |
122 | 121 |
getListView().setItemsCanFocus(false); |
123 | 122 |
} |
124 |
|
|
125 |
protected void showProgressDialog() { |
|
126 |
pDialog = new ProgressDialog(this, R.style.NewDialog); |
|
127 |
// // Set blur to background |
|
128 |
WindowManager.LayoutParams lp = pDialog.getWindow().getAttributes(); |
|
129 |
lp.dimAmount = 0.0f; |
|
130 |
pDialog.getWindow().setAttributes(lp); |
|
131 |
pDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND); |
|
132 |
pDialog.show(); |
|
133 |
pDialog.setContentView(new ProgressBar(this), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); |
|
134 |
} |
|
135 | 123 |
|
136 | 124 |
private void showAlert(String title, String message) { |
137 | 125 |
// Can't create handler inside thread that has not called |
... | ... | |
159 | 147 |
|
160 | 148 |
@Override |
161 | 149 |
protected void onPreExecute(){ |
162 |
showProgressDialog(); |
|
163 | 150 |
loading = true; |
164 | 151 |
} |
165 | 152 |
|
166 | 153 |
@Override |
167 | 154 |
protected ArrayList<Container> doInBackground(Void... arg0) { |
168 | 155 |
ArrayList<Container> containers = null; |
156 |
|
|
169 | 157 |
try { |
170 | 158 |
containers = (new ContainerManager(context)).createList(true); |
171 | 159 |
} catch (CloudServersException e) { |
172 | 160 |
exception = e; |
173 | 161 |
} |
174 |
pDialog.dismiss(); |
|
175 | 162 |
return containers; |
176 | 163 |
} |
177 | 164 |
|
... | ... | |
190 | 177 |
containerNames[i] = container.getName(); |
191 | 178 |
} |
192 | 179 |
} |
193 |
pDialog.dismiss(); |
|
194 | 180 |
loading = false; |
195 | 181 |
new LoadCDNContainersTask().execute((Void[]) null); |
196 | 182 |
} |
... | ... | |
203 | 189 |
|
204 | 190 |
@Override |
205 | 191 |
protected void onPreExecute(){ |
206 |
showProgressDialog(); |
|
207 | 192 |
loading = true; |
208 | 193 |
} |
209 | 194 |
|
210 | 195 |
@Override |
211 | 196 |
protected ArrayList<Container> doInBackground(Void... arg0) { |
212 | 197 |
ArrayList<Container> cdnContainers = null; |
198 |
|
|
213 | 199 |
try { |
214 | 200 |
cdnContainers = (new ContainerManager(context)).createCDNList(true); |
215 | 201 |
} catch (CloudServersException e) { |
216 | 202 |
exception = e; |
217 | 203 |
} |
218 |
pDialog.dismiss(); |
|
219 | 204 |
return cdnContainers; |
220 | 205 |
} |
221 | 206 |
|
... | ... | |
239 | 224 |
} |
240 | 225 |
} |
241 | 226 |
} |
242 |
pDialog.dismiss(); |
|
243 | 227 |
setContainerList(); |
244 | 228 |
loading = false; |
245 | 229 |
} |
Also available in: Unified diff