root / src / com / rackspacecloud / android / ContainerObjectDetails.java @ 6b8dad86
History | View | Annotate | Download (18.9 kB)
1 |
package com.rackspacecloud.android; |
---|---|
2 |
|
3 |
import java.io.BufferedOutputStream; |
4 |
import java.io.File; |
5 |
import java.io.FileNotFoundException; |
6 |
import java.io.FileOutputStream; |
7 |
import java.io.IOException; |
8 |
import java.io.StringReader; |
9 |
|
10 |
import javax.xml.parsers.FactoryConfigurationError; |
11 |
import javax.xml.parsers.ParserConfigurationException; |
12 |
import javax.xml.parsers.SAXParser; |
13 |
import javax.xml.parsers.SAXParserFactory; |
14 |
|
15 |
import org.apache.http.HttpEntity; |
16 |
import org.apache.http.HttpResponse; |
17 |
import org.apache.http.client.ClientProtocolException; |
18 |
import org.apache.http.impl.client.BasicResponseHandler; |
19 |
import org.apache.http.util.EntityUtils; |
20 |
import org.xml.sax.InputSource; |
21 |
import org.xml.sax.SAXException; |
22 |
import org.xml.sax.XMLReader; |
23 |
|
24 |
import android.app.Activity; |
25 |
import android.app.AlertDialog; |
26 |
import android.app.Dialog; |
27 |
import android.app.ProgressDialog; |
28 |
import android.content.Context; |
29 |
import android.content.DialogInterface; |
30 |
import android.content.Intent; |
31 |
import android.net.Uri; |
32 |
import android.os.AsyncTask; |
33 |
import android.os.Bundle; |
34 |
import android.os.Environment; |
35 |
import android.util.Log; |
36 |
import android.view.Menu; |
37 |
import android.view.MenuInflater; |
38 |
import android.view.MenuItem; |
39 |
import android.view.View; |
40 |
import android.widget.Button; |
41 |
import android.widget.TextView; |
42 |
import android.widget.Toast; |
43 |
|
44 |
import com.rackspace.cloud.files.api.client.ContainerObjectManager; |
45 |
import com.rackspace.cloud.files.api.client.ContainerObjects; |
46 |
import com.rackspace.cloud.servers.api.client.CloudServersException; |
47 |
import com.rackspace.cloud.servers.api.client.http.HttpBundle; |
48 |
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser; |
49 |
|
50 |
/**
|
51 |
*
|
52 |
* @author Phillip Toohill
|
53 |
*
|
54 |
*/
|
55 |
|
56 |
//doesn't extend cloud activity because of the complex
|
57 |
//dialog management needed for the listeners
|
58 |
public class ContainerObjectDetails extends GaActivity { |
59 |
|
60 |
private static final int deleteObject = 0; |
61 |
private final String DOWNLOAD_DIRECTORY = "/RackspaceCloud"; |
62 |
|
63 |
private ContainerObjects objects;
|
64 |
private String containerNames; |
65 |
private String cdnURL; |
66 |
private String cdnEnabled; |
67 |
public String LOG = "ViewObject"; |
68 |
private int bConver = 1048576; |
69 |
private int kbConver = 1024; |
70 |
private double megaBytes; |
71 |
private double kiloBytes; |
72 |
public Button previewButton; |
73 |
public Button downloadButton; |
74 |
public Context context; |
75 |
private boolean displayDialog; |
76 |
private ProgressDialog dialog;
|
77 |
private Boolean isDownloaded; |
78 |
private AndroidCloudApplication app;
|
79 |
private DeleteObjectListenerTask deleteObjTask;
|
80 |
private DownloadObjectListenerTask downloadObjTask;
|
81 |
|
82 |
/** Called when the activity is first created. */
|
83 |
@Override
|
84 |
public void onCreate(Bundle savedInstanceState) { |
85 |
super.onCreate(savedInstanceState);
|
86 |
trackPageView(PAGE_STORAGE_OBJECT); |
87 |
|
88 |
context = getApplicationContext(); |
89 |
|
90 |
objects = (ContainerObjects) this.getIntent().getExtras().get("container"); |
91 |
containerNames = (String) this.getIntent().getExtras().get("containerNames"); |
92 |
cdnURL = (String) this.getIntent().getExtras().get("cdnUrl"); |
93 |
cdnEnabled = (String) this.getIntent().getExtras().get("isCdnEnabled"); |
94 |
|
95 |
|
96 |
setContentView(R.layout.viewobject); |
97 |
restoreState(savedInstanceState); |
98 |
|
99 |
} |
100 |
|
101 |
@Override
|
102 |
protected void onSaveInstanceState(Bundle outState) { |
103 |
super.onSaveInstanceState(outState);
|
104 |
outState.putSerializable("container", objects);
|
105 |
outState.putBoolean("isDownloaded", isDownloaded);
|
106 |
outState.putBoolean("displayDialog", displayDialog);
|
107 |
|
108 |
if(displayDialog){
|
109 |
hideDialog(); |
110 |
displayDialog = true;
|
111 |
} |
112 |
} |
113 |
|
114 |
private void restoreState(Bundle state) { |
115 |
|
116 |
/*
|
117 |
* need reference to the app so you can access curDirFiles
|
118 |
* as well as processing status
|
119 |
*/
|
120 |
app = (AndroidCloudApplication)this.getApplication();
|
121 |
|
122 |
if (state != null && state.containsKey("displayDialog") && state.getBoolean("displayDialog")) { |
123 |
showDialog(); |
124 |
} else {
|
125 |
hideDialog(); |
126 |
} |
127 |
|
128 |
if (state != null && state.containsKey("container")) { |
129 |
objects = (ContainerObjects) state.getSerializable("container");
|
130 |
} |
131 |
loadObjectData(); |
132 |
|
133 |
if ( cdnEnabled.equals("true")) { |
134 |
this.previewButton = (Button) findViewById(R.id.preview_button); |
135 |
previewButton.setOnClickListener(new MyOnClickListener());
|
136 |
} else {
|
137 |
this.previewButton = (Button) findViewById(R.id.preview_button); |
138 |
previewButton.setVisibility(View.GONE);
|
139 |
} |
140 |
|
141 |
if (state != null && state.containsKey("isDownloaded")){ |
142 |
isDownloaded = state.getBoolean("isDownloaded");
|
143 |
} |
144 |
else{
|
145 |
isDownloaded = fileIsDownloaded(); |
146 |
} |
147 |
this.downloadButton = (Button) findViewById(R.id.download_button); |
148 |
if ( isDownloaded ) {
|
149 |
downloadButton.setText("Open File");
|
150 |
} else {
|
151 |
downloadButton.setText("Download File");
|
152 |
} |
153 |
downloadButton.setOnClickListener(new MyOnClickListener());
|
154 |
|
155 |
if(app.isDeletingObject()){
|
156 |
deleteObjTask = new DeleteObjectListenerTask();
|
157 |
deleteObjTask.execute(); |
158 |
} |
159 |
|
160 |
if(app.isDownloadingObject()){
|
161 |
downloadObjTask = new DownloadObjectListenerTask();
|
162 |
downloadObjTask.execute(); |
163 |
} |
164 |
} |
165 |
|
166 |
@Override
|
167 |
protected void onStart(){ |
168 |
super.onStart();
|
169 |
if(displayDialog){
|
170 |
showDialog(); |
171 |
} |
172 |
} |
173 |
|
174 |
|
175 |
@Override
|
176 |
protected void onStop(){ |
177 |
super.onStop();
|
178 |
|
179 |
if(displayDialog){
|
180 |
hideDialog(); |
181 |
displayDialog = true;
|
182 |
} |
183 |
|
184 |
/*
|
185 |
* Need to stop running listener task
|
186 |
* if we exit
|
187 |
*/
|
188 |
if(deleteObjTask != null){ |
189 |
deleteObjTask.cancel(true);
|
190 |
} |
191 |
|
192 |
if(downloadObjTask != null){ |
193 |
downloadObjTask.cancel(true);
|
194 |
} |
195 |
} |
196 |
|
197 |
|
198 |
private void loadObjectData() { |
199 |
//Object Name
|
200 |
TextView name = (TextView) findViewById(R.id.view_container_name); |
201 |
name.setText(objects.getCName().toString()); |
202 |
|
203 |
//File size
|
204 |
if (objects.getBytes() >= bConver) {
|
205 |
megaBytes = Math.abs(objects.getBytes()/bConver + 0.2); |
206 |
TextView sublabel = (TextView) findViewById(R.id.view_file_bytes); |
207 |
sublabel.setText(megaBytes + " MB");
|
208 |
} else if (objects.getBytes() >= kbConver){ |
209 |
kiloBytes = Math.abs(objects.getBytes()/kbConver + 0.2); |
210 |
TextView sublabel = (TextView) findViewById(R.id.view_file_bytes); |
211 |
sublabel.setText(kiloBytes + " KB");
|
212 |
} else {
|
213 |
TextView sublabel = (TextView) findViewById(R.id.view_file_bytes); |
214 |
sublabel.setText(objects.getBytes() + " B");
|
215 |
} |
216 |
|
217 |
//Content Type
|
218 |
TextView cType = (TextView) findViewById(R.id.view_content_type); |
219 |
cType.setText(objects.getContentType().toString()); |
220 |
|
221 |
//Last Modification date
|
222 |
String strDate = objects.getLastMod();
|
223 |
strDate = strDate.substring(0, strDate.indexOf('T')); |
224 |
/*
|
225 |
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.ssssss");
|
226 |
Date dateStr = null;
|
227 |
try {
|
228 |
dateStr = formatter.parse(strDate);
|
229 |
} catch (ParseException e1) {
|
230 |
e1.printStackTrace();
|
231 |
}
|
232 |
String formattedDate = formatter.format(dateStr);
|
233 |
|
234 |
Date date1 = null;
|
235 |
try {
|
236 |
date1 = formatter.parse(formattedDate);
|
237 |
} catch (ParseException e) {
|
238 |
e.printStackTrace();
|
239 |
}
|
240 |
formatter = new SimpleDateFormat("MMM-dd-yyyy");
|
241 |
formattedDate = formatter.format(date1);
|
242 |
*/
|
243 |
TextView lastmod = (TextView) findViewById(R.id.view_file_modification); |
244 |
lastmod.setText(strDate); |
245 |
|
246 |
} |
247 |
|
248 |
private class MyOnClickListener implements View.OnClickListener { |
249 |
@Override
|
250 |
public void onClick(View v) { |
251 |
if(v.equals(findViewById(R.id.preview_button))){
|
252 |
Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse(cdnURL + "/" + objects.getCName())); |
253 |
startActivity(viewIntent); |
254 |
} |
255 |
/*
|
256 |
* need to perform different functions based on if
|
257 |
* the file is in the devices filesystem
|
258 |
*/
|
259 |
if(v.equals(findViewById(R.id.download_button))){
|
260 |
if(!isDownloaded){
|
261 |
if(storageIsReady()){
|
262 |
new ContainerObjectDownloadTask().execute();
|
263 |
} |
264 |
else{
|
265 |
showAlert("Error", "Storage not found."); |
266 |
} |
267 |
} |
268 |
else{
|
269 |
openFile(); |
270 |
} |
271 |
} |
272 |
} |
273 |
} |
274 |
|
275 |
private void showAlert(String title, String message) { |
276 |
AlertDialog alert = new AlertDialog.Builder(this).create(); |
277 |
alert.setTitle(title); |
278 |
alert.setMessage(message); |
279 |
alert.setButton("OK", new DialogInterface.OnClickListener() { |
280 |
public void onClick(DialogInterface dialog, int which) { |
281 |
return;
|
282 |
} }); |
283 |
alert.show(); |
284 |
} |
285 |
//Create the Menu options
|
286 |
@Override
|
287 |
public boolean onCreateOptionsMenu(Menu menu) { |
288 |
super.onCreateOptionsMenu(menu);
|
289 |
MenuInflater inflater = getMenuInflater(); |
290 |
inflater.inflate(R.menu.container_object_list_menu, menu); |
291 |
return true; |
292 |
} |
293 |
|
294 |
@Override
|
295 |
public boolean onOptionsItemSelected(MenuItem item) { |
296 |
switch (item.getItemId()) {
|
297 |
case R.id.delete_object:
|
298 |
showDialog(deleteObject); |
299 |
return true; |
300 |
case R.id.refresh:
|
301 |
loadObjectData(); |
302 |
return true; |
303 |
} |
304 |
return false; |
305 |
} |
306 |
|
307 |
@Override
|
308 |
protected Dialog onCreateDialog(int id ) { |
309 |
switch (id) {
|
310 |
case deleteObject:
|
311 |
return new AlertDialog.Builder(ContainerObjectDetails.this) |
312 |
.setIcon(R.drawable.alert_dialog_icon) |
313 |
.setTitle("Delete File")
|
314 |
.setMessage("Are you sure you want to delete this file?")
|
315 |
.setPositiveButton("Delete File", new DialogInterface.OnClickListener() { |
316 |
public void onClick(DialogInterface dialog, int whichButton) { |
317 |
// User clicked OK so do some stuff
|
318 |
trackEvent(CATEGORY_FILE, EVENT_DELETE, "", -1); |
319 |
new ContainerObjectDeleteTask().execute((Void[]) null); |
320 |
} |
321 |
}) |
322 |
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
323 |
public void onClick(DialogInterface dialog, int whichButton) { |
324 |
// User clicked Cancel so do some stuff
|
325 |
} |
326 |
}) |
327 |
.create(); |
328 |
} |
329 |
return null; |
330 |
} |
331 |
/**
|
332 |
* @return the file
|
333 |
*/
|
334 |
public ContainerObjects getViewFile() {
|
335 |
return objects;
|
336 |
} |
337 |
|
338 |
/**
|
339 |
* @param File the file to set
|
340 |
*/
|
341 |
public void setViewFile(ContainerObjects object) { |
342 |
this.objects = object;
|
343 |
} |
344 |
|
345 |
/*
|
346 |
* returns false if external storage is not avaliable
|
347 |
* (if its mounted, missing, read-only, etc)
|
348 |
* from: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
|
349 |
*/
|
350 |
private boolean storageIsReady(){ |
351 |
boolean mExternalStorageAvailable = false; |
352 |
boolean mExternalStorageWriteable = false; |
353 |
String state = Environment.getExternalStorageState();
|
354 |
|
355 |
if (Environment.MEDIA_MOUNTED.equals(state)) {
|
356 |
// We can read and write the media
|
357 |
mExternalStorageAvailable = mExternalStorageWriteable = true;
|
358 |
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { |
359 |
// We can only read the media
|
360 |
mExternalStorageAvailable = true;
|
361 |
mExternalStorageWriteable = false;
|
362 |
} else {
|
363 |
// Something else is wrong. It may be one of many other states, but all we need
|
364 |
// to know is we can neither read nor write
|
365 |
mExternalStorageAvailable = mExternalStorageWriteable = false;
|
366 |
} |
367 |
return mExternalStorageAvailable && mExternalStorageWriteable;
|
368 |
} |
369 |
|
370 |
private boolean fileIsDownloaded(){ |
371 |
if(storageIsReady()){
|
372 |
String fileName = Environment.getExternalStorageDirectory().getPath() + "/RackspaceCloud/" + objects.getCName(); |
373 |
File f = new File(fileName); |
374 |
return f.isFile();
|
375 |
} |
376 |
return false; |
377 |
} |
378 |
|
379 |
private void openFile(){ |
380 |
File object = new File(Environment.getExternalStorageDirectory().getPath() + "/RackspaceCloud/" + objects.getCName()); |
381 |
Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW);
|
382 |
File file = new File(object.getAbsolutePath()); |
383 |
String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
|
384 |
String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
385 |
myIntent.setDataAndType(Uri.fromFile(file),mimetype); |
386 |
//myIntent.setData(Uri.fromFile(file));
|
387 |
try{
|
388 |
startActivity(myIntent); |
389 |
} |
390 |
catch(Exception e){ |
391 |
Toast.makeText(this, "Could not open file.", Toast.LENGTH_SHORT).show(); |
392 |
} |
393 |
} |
394 |
|
395 |
private boolean writeFile(byte[] data){ |
396 |
String directoryName = Environment.getExternalStorageDirectory().getPath() + DOWNLOAD_DIRECTORY;
|
397 |
File f = new File(directoryName); |
398 |
|
399 |
if(!f.isDirectory()){
|
400 |
if(!f.mkdir()){
|
401 |
return false; |
402 |
} |
403 |
} |
404 |
|
405 |
String filename = directoryName + "/" + objects.getCName(); |
406 |
File object = new File(filename); |
407 |
BufferedOutputStream bos = null; |
408 |
|
409 |
try{
|
410 |
FileOutputStream fos = new FileOutputStream(object); |
411 |
bos = new BufferedOutputStream(fos); |
412 |
bos.write(data); |
413 |
} |
414 |
catch(FileNotFoundException e){ |
415 |
e.printStackTrace(); |
416 |
} |
417 |
catch(IOException e){ |
418 |
e.printStackTrace(); |
419 |
} |
420 |
finally{
|
421 |
if(bos != null){ |
422 |
try {
|
423 |
bos.flush(); |
424 |
bos.close(); |
425 |
} catch (IOException e) { |
426 |
// TODO Auto-generated catch block
|
427 |
e.printStackTrace(); |
428 |
} |
429 |
} |
430 |
} |
431 |
return true; |
432 |
} |
433 |
|
434 |
//Task's
|
435 |
|
436 |
private CloudServersException parseCloudServersException(HttpResponse response) {
|
437 |
CloudServersException cse = new CloudServersException();
|
438 |
try {
|
439 |
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
440 |
String body = responseHandler.handleResponse(response);
|
441 |
CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
|
442 |
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); |
443 |
XMLReader xmlReader = saxParser.getXMLReader(); |
444 |
xmlReader.setContentHandler(parser); |
445 |
xmlReader.parse(new InputSource(new StringReader(body))); |
446 |
cse = parser.getException(); |
447 |
} catch (ClientProtocolException e) {
|
448 |
cse = new CloudServersException();
|
449 |
cse.setMessage(e.getLocalizedMessage()); |
450 |
} catch (IOException e) { |
451 |
cse = new CloudServersException();
|
452 |
cse.setMessage(e.getLocalizedMessage()); |
453 |
} catch (ParserConfigurationException e) { |
454 |
cse = new CloudServersException();
|
455 |
cse.setMessage(e.getLocalizedMessage()); |
456 |
} catch (SAXException e) {
|
457 |
cse = new CloudServersException();
|
458 |
cse.setMessage(e.getLocalizedMessage()); |
459 |
} catch (FactoryConfigurationError e) { |
460 |
cse = new CloudServersException();
|
461 |
cse.setMessage(e.getLocalizedMessage()); |
462 |
} |
463 |
return cse;
|
464 |
} |
465 |
|
466 |
private void startFileError(String message, HttpBundle bundle){ |
467 |
Intent viewIntent = new Intent(getApplicationContext(), ServerErrorActivity.class);
|
468 |
viewIntent.putExtra("errorMessage", message);
|
469 |
viewIntent.putExtra("response", bundle.getResponseText());
|
470 |
viewIntent.putExtra("request", bundle.getCurlRequest());
|
471 |
startActivity(viewIntent); |
472 |
} |
473 |
|
474 |
private void showDialog() { |
475 |
if(dialog == null || !dialog.isShowing()){ |
476 |
displayDialog = true;
|
477 |
dialog = ProgressDialog.show(ContainerObjectDetails.this, "", "Loading...", true); |
478 |
} |
479 |
} |
480 |
|
481 |
private void hideDialog() { |
482 |
if(dialog != null){ |
483 |
dialog.dismiss(); |
484 |
} |
485 |
displayDialog = false;
|
486 |
} |
487 |
|
488 |
private class ContainerObjectDeleteTask extends AsyncTask<Void, Void, HttpBundle> { |
489 |
|
490 |
private CloudServersException exception;
|
491 |
|
492 |
protected void onPreExecute(){ |
493 |
//dialog = ProgressDialog.show(ContainerObjectDetails.this, "", "Deleting...", true);
|
494 |
showDialog(); |
495 |
app.setDeleteingObject(true);
|
496 |
deleteObjTask = new DeleteObjectListenerTask();
|
497 |
deleteObjTask.execute(); |
498 |
} |
499 |
|
500 |
@Override
|
501 |
protected HttpBundle doInBackground(Void... arg0) { |
502 |
HttpBundle bundle = null;
|
503 |
try {
|
504 |
bundle = (new ContainerObjectManager(context)).deleteObject(containerNames, objects.getCName() );
|
505 |
} catch (CloudServersException e) {
|
506 |
exception = e; |
507 |
} |
508 |
|
509 |
return bundle;
|
510 |
} |
511 |
|
512 |
@Override
|
513 |
protected void onPostExecute(HttpBundle bundle) { |
514 |
//dialog.dismiss();
|
515 |
app.setDeleteingObject(false);
|
516 |
hideDialog(); |
517 |
HttpResponse response = bundle.getResponse(); |
518 |
if (response != null) { |
519 |
int statusCode = response.getStatusLine().getStatusCode();
|
520 |
if (statusCode == 204) { |
521 |
//handled by listner
|
522 |
} else {
|
523 |
CloudServersException cse = parseCloudServersException(response); |
524 |
if ("".equals(cse.getMessage())) { |
525 |
startFileError("There was a problem deleting your File.", bundle);
|
526 |
} else {
|
527 |
startFileError("There was a problem deleting your file: " + cse.getMessage(), bundle);
|
528 |
} |
529 |
} |
530 |
} else if (exception != null) { |
531 |
startFileError("There was a problem deleting your file: " + exception.getMessage(), bundle);
|
532 |
} |
533 |
} |
534 |
} |
535 |
|
536 |
private class ContainerObjectDownloadTask extends AsyncTask<Void, Void, HttpBundle> { |
537 |
|
538 |
private CloudServersException exception;
|
539 |
|
540 |
@Override
|
541 |
protected void onPreExecute(){ |
542 |
showDialog(); |
543 |
app.setDownloadingObject(true);
|
544 |
downloadObjTask = new DownloadObjectListenerTask();
|
545 |
downloadObjTask.execute(); |
546 |
} |
547 |
|
548 |
@Override
|
549 |
protected HttpBundle doInBackground(Void... arg0) { |
550 |
HttpBundle bundle = null;
|
551 |
try {
|
552 |
bundle = (new ContainerObjectManager(context)).getObject(containerNames, objects.getCName());
|
553 |
} catch (CloudServersException e) {
|
554 |
exception = e; |
555 |
} |
556 |
return bundle;
|
557 |
} |
558 |
|
559 |
@Override
|
560 |
protected void onPostExecute(HttpBundle bundle) { |
561 |
app.setDownloadingObject(false);
|
562 |
hideDialog(); |
563 |
HttpResponse response = bundle.getResponse(); |
564 |
if (response != null) { |
565 |
int statusCode = response.getStatusLine().getStatusCode();
|
566 |
if (statusCode == 200) { |
567 |
setResult(Activity.RESULT_OK); |
568 |
HttpEntity entity = response.getEntity(); |
569 |
app.setDownloadedEntity(entity); |
570 |
/*
|
571 |
try {
|
572 |
if(writeFile(EntityUtils.toByteArray(entity))){
|
573 |
downloadButton.setText("Open File");
|
574 |
isDownloaded = true;
|
575 |
}
|
576 |
else{
|
577 |
showAlert("Error", "There was a problem downloading your file.");
|
578 |
}
|
579 |
|
580 |
} catch (IOException e) {
|
581 |
showAlert("Error", "There was a problem downloading your file.");
|
582 |
e.printStackTrace();
|
583 |
}
|
584 |
*/
|
585 |
|
586 |
} else {
|
587 |
CloudServersException cse = parseCloudServersException(response); |
588 |
if ("".equals(cse.getMessage())) { |
589 |
startFileError("There was a problem downloading your File.", bundle);
|
590 |
} else {
|
591 |
startFileError("There was a problem downloading your file: " + cse.getMessage(), bundle);
|
592 |
} |
593 |
} |
594 |
} else if (exception != null) { |
595 |
startFileError("There was a problem downloading your file: " + exception.getMessage(), bundle);
|
596 |
} |
597 |
} |
598 |
} |
599 |
|
600 |
private class DeleteObjectListenerTask extends |
601 |
AsyncTask<Void, Void, Void> { |
602 |
|
603 |
@Override
|
604 |
protected Void doInBackground(Void... arg1) { |
605 |
|
606 |
while(app.isDeletingObject()){
|
607 |
// wait for process to finish
|
608 |
// or have it be canceled
|
609 |
if(deleteObjTask.isCancelled()){
|
610 |
return null; |
611 |
} |
612 |
} |
613 |
return null; |
614 |
} |
615 |
|
616 |
/*
|
617 |
* when no longer processing, time to load
|
618 |
* the new files
|
619 |
*/
|
620 |
@Override
|
621 |
protected void onPostExecute(Void arg1) { |
622 |
hideDialog(); |
623 |
setResult(99);
|
624 |
finish(); |
625 |
} |
626 |
} |
627 |
|
628 |
private class DownloadObjectListenerTask extends |
629 |
AsyncTask<Void, Void, Void> { |
630 |
|
631 |
@Override
|
632 |
protected Void doInBackground(Void... arg1) { |
633 |
|
634 |
while(app.isDownloadingObject()){
|
635 |
// wait for process to finish
|
636 |
// or have it be canceled
|
637 |
if(downloadObjTask.isCancelled()){
|
638 |
return null; |
639 |
} |
640 |
} |
641 |
return null; |
642 |
} |
643 |
|
644 |
/*
|
645 |
* when no longer processing, time to load
|
646 |
* the new files
|
647 |
*/
|
648 |
@Override
|
649 |
protected void onPostExecute(Void arg1) { |
650 |
hideDialog(); |
651 |
try {
|
652 |
Log.d("info", "captin starting to write"); |
653 |
if(writeFile(EntityUtils.toByteArray(app.getDownloadedEntity()))){
|
654 |
downloadButton.setText("Open File");
|
655 |
isDownloaded = true;
|
656 |
Log.d("info", "captin wrote"); |
657 |
} |
658 |
else{
|
659 |
showAlert("Error", "There was a problem downloading your file."); |
660 |
} |
661 |
|
662 |
} catch (IOException e) { |
663 |
showAlert("Error", "There was a problem downloading your file."); |
664 |
e.printStackTrace(); |
665 |
} catch (Exception e) { |
666 |
showAlert("Error", "There was a problem downloading your file."); |
667 |
e.printStackTrace(); |
668 |
} |
669 |
} |
670 |
} |
671 |
|
672 |
} |