Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: patchorang/android-rackspacecloud
base: e6c34a0fdb
...
head fork: patchorang/android-rackspacecloud
compare: 877f6f58b7
  • 3 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 07, 2011
Adam Menz bug fixes 3e180b0
Commits on Jul 08, 2011
Adam Menz fixed Honeycomb specific bugs 969195c
Adam Menz bug fixes 877f6f5
2  AndroidManifest.xml
View
@@ -102,7 +102,7 @@
</application>
- <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11" />
+ <uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>
20 src/com/rackspacecloud/android/AndroidCloudApplication.java
View
@@ -2,6 +2,8 @@
import java.util.ArrayList;
+import org.apache.http.HttpEntity;
+
import com.rackspace.cloud.files.api.client.ContainerObjects;
import android.app.Application;
@@ -11,6 +13,8 @@
private boolean taskProcessing;
private boolean deletingObjectProcessing;
private boolean deletingContainerProcessing;
+ private boolean downloadingObject;
+ private HttpEntity downloadedObject;
private ArrayList<ContainerObjects> curDirFiles;
public void setAddingObject(boolean processing){
@@ -21,6 +25,22 @@ public boolean isAddingObject(){
return taskProcessing;
}
+ public void setDownloadedEntity(HttpEntity obj){
+ downloadedObject = obj;
+ }
+
+ public HttpEntity getDownloadedEntity(){
+ return downloadedObject;
+ }
+
+ public void setDownloadingObject(boolean processing){
+ downloadingObject = processing;
+ }
+
+ public boolean isDownloadingObject(){
+ return downloadingObject;
+ }
+
public void setDeleteingObject(boolean processing){
deletingObjectProcessing = processing;
}
795 src/com/rackspacecloud/android/ContainerObjectDetails.java
View
@@ -50,7 +50,6 @@
import com.rackspace.cloud.servers.api.client.http.HttpBundle;
import com.rackspace.cloud.servers.api.client.parsers.CloudServersFaultXMLParser;
-
/**
*
* @author Phillip Toohill
@@ -58,7 +57,7 @@
*/
public class ContainerObjectDetails extends Activity {
-
+
private static final int deleteObject = 0;
private final String DOWNLOAD_DIRECTORY = "/RackspaceCloud";
private ContainerObjects objects;
@@ -73,193 +72,262 @@
public Button previewButton;
public Button downloadButton;
public Context context;
+ private boolean displayDialog;
private ProgressDialog dialog;
private Boolean isDownloaded;
+ private AndroidCloudApplication app;
+ private DeleteObjectListenerTask deleteObjTask;
+ private DownloadObjectListenerTask downloadObjTask;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- context = getApplicationContext();
-
- objects = (ContainerObjects) this.getIntent().getExtras().get("container");
- containerNames = (String) this.getIntent().getExtras().get("containerNames");
- cdnURL = (String) this.getIntent().getExtras().get("cdnUrl");
- cdnEnabled = (String) this.getIntent().getExtras().get("isCdnEnabled");
-
-
- setContentView(R.layout.viewobject);
- restoreState(savedInstanceState);
-
- }
-
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ context = getApplicationContext();
+
+ objects = (ContainerObjects) this.getIntent().getExtras().get("container");
+ containerNames = (String) this.getIntent().getExtras().get("containerNames");
+ cdnURL = (String) this.getIntent().getExtras().get("cdnUrl");
+ cdnEnabled = (String) this.getIntent().getExtras().get("isCdnEnabled");
+
+
+ setContentView(R.layout.viewobject);
+ restoreState(savedInstanceState);
+
+ }
+
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable("container", objects);
outState.putBoolean("isDownloaded", isDownloaded);
+ outState.putBoolean("displayDialog", displayDialog);
+
+ if(displayDialog){
+ hideDialog();
+ displayDialog = true;
+ }
}
- private void restoreState(Bundle state) {
- if (state != null && state.containsKey("container")) {
- objects = (ContainerObjects) state.getSerializable("container");
- }
- loadObjectData();
+ private void restoreState(Bundle state) {
+
+ /*
+ * need reference to the app so you can access curDirFiles
+ * as well as processing status
+ */
+ app = (AndroidCloudApplication)this.getApplication();
- if ( cdnEnabled.equals("true")) {
- this.previewButton = (Button) findViewById(R.id.preview_button);
- previewButton.setOnClickListener(new MyOnClickListener());
+ if (state != null && state.containsKey("displayDialog") && state.getBoolean("displayDialog")) {
+ showDialog();
} else {
- this.previewButton = (Button) findViewById(R.id.preview_button);
- previewButton.setVisibility(View.GONE);
+ hideDialog();
}
+
+ if (state != null && state.containsKey("container")) {
+ objects = (ContainerObjects) state.getSerializable("container");
+ }
+ loadObjectData();
- if (state != null && state.containsKey("isDownloaded")){
- isDownloaded = state.getBoolean("isDownloaded");
- }
- else{
- isDownloaded = fileIsDownloaded();
- }
- this.downloadButton = (Button) findViewById(R.id.download_button);
- if ( isDownloaded ) {
- downloadButton.setText("Open File");
- } else {
- downloadButton.setText("Download File");
- }
- downloadButton.setOnClickListener(new MyOnClickListener());
- }
+ if ( cdnEnabled.equals("true")) {
+ this.previewButton = (Button) findViewById(R.id.preview_button);
+ previewButton.setOnClickListener(new MyOnClickListener());
+ } else {
+ this.previewButton = (Button) findViewById(R.id.preview_button);
+ previewButton.setVisibility(View.GONE);
+ }
+ if (state != null && state.containsKey("isDownloaded")){
+ isDownloaded = state.getBoolean("isDownloaded");
+ }
+ else{
+ isDownloaded = fileIsDownloaded();
+ }
+ this.downloadButton = (Button) findViewById(R.id.download_button);
+ if ( isDownloaded ) {
+ downloadButton.setText("Open File");
+ } else {
+ downloadButton.setText("Download File");
+ }
+ downloadButton.setOnClickListener(new MyOnClickListener());
+
+ if(app.isDeletingObject()){
+ deleteObjTask = new DeleteObjectListenerTask();
+ deleteObjTask.execute();
+ }
+
+ if(app.isDownloadingObject()){
+ downloadObjTask = new DownloadObjectListenerTask();
+ downloadObjTask.execute();
+ }
+ }
+
+
+ @Override
+ protected void onStart(){
+ super.onStart();
+ if(displayDialog){
+ showDialog();
+ }
+ }
- private void loadObjectData() {
- //Object Name
- TextView name = (TextView) findViewById(R.id.view_container_name);
- name.setText(objects.getCName().toString());
-
- //File size
- if (objects.getBytes() >= bConver) {
+
+ @Override
+ protected void onStop(){
+ super.onStop();
+
+ if(displayDialog){
+ hideDialog();
+ displayDialog = true;
+ }
+
+ /*
+ * Need to stop running listener task
+ * if we exit
+ */
+ if(deleteObjTask != null){
+ deleteObjTask.cancel(true);
+ }
+
+ if(downloadObjTask != null){
+ downloadObjTask.cancel(true);
+ }
+ }
+
+
+ private void loadObjectData() {
+ //Object Name
+ TextView name = (TextView) findViewById(R.id.view_container_name);
+ name.setText(objects.getCName().toString());
+
+ //File size
+ if (objects.getBytes() >= bConver) {
megaBytes = Math.abs(objects.getBytes()/bConver + 0.2);
- TextView sublabel = (TextView) findViewById(R.id.view_file_bytes);
- sublabel.setText(megaBytes + " MB");
+ TextView sublabel = (TextView) findViewById(R.id.view_file_bytes);
+ sublabel.setText(megaBytes + " MB");
} else if (objects.getBytes() >= kbConver){
kiloBytes = Math.abs(objects.getBytes()/kbConver + 0.2);
- TextView sublabel = (TextView) findViewById(R.id.view_file_bytes);
- sublabel.setText(kiloBytes + " KB");
+ TextView sublabel = (TextView) findViewById(R.id.view_file_bytes);
+ sublabel.setText(kiloBytes + " KB");
} else {
- TextView sublabel = (TextView) findViewById(R.id.view_file_bytes);
- sublabel.setText(objects.getBytes() + " B");
+ TextView sublabel = (TextView) findViewById(R.id.view_file_bytes);
+ sublabel.setText(objects.getBytes() + " B");
}
-
- //Content Type
- TextView cType = (TextView) findViewById(R.id.view_content_type);
- cType.setText(objects.getContentType().toString());
-
- //Last Modification date
- String strDate = objects.getLastMod();
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.ssssss");
- Date dateStr = null;
- try {
- dateStr = formatter.parse(strDate);
- } catch (ParseException e1) {
- e1.printStackTrace();
+
+ //Content Type
+ TextView cType = (TextView) findViewById(R.id.view_content_type);
+ cType.setText(objects.getContentType().toString());
+
+ //Last Modification date
+ String strDate = objects.getLastMod();
+ strDate = strDate.substring(0, strDate.indexOf('T'));
+ /*
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.ssssss");
+ Date dateStr = null;
+ try {
+ dateStr = formatter.parse(strDate);
+ } catch (ParseException e1) {
+ e1.printStackTrace();
+ }
+ String formattedDate = formatter.format(dateStr);
+
+ Date date1 = null;
+ try {
+ date1 = formatter.parse(formattedDate);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ formatter = new SimpleDateFormat("MMM-dd-yyyy");
+ formattedDate = formatter.format(date1);
+ */
+ TextView lastmod = (TextView) findViewById(R.id.view_file_modification);
+ lastmod.setText(strDate);
+
+ }
+
+ private class MyOnClickListener implements View.OnClickListener {
+ @Override
+ public void onClick(View v) {
+ if(v.equals(findViewById(R.id.preview_button))){
+ Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse(cdnURL + "/" + objects.getCName()));
+ startActivity(viewIntent);
}
- String formattedDate = formatter.format(dateStr);
- Date date1 = null;
- try {
- date1 = formatter.parse(formattedDate);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- formatter = new SimpleDateFormat("MMM-dd-yyyy");
- formattedDate = formatter.format(date1);
- TextView lastmod = (TextView) findViewById(R.id.view_file_modification);
- lastmod.setText(formattedDate);
-
- }
-
- private class MyOnClickListener implements View.OnClickListener {
- @Override
- public void onClick(View v) {
- if(v.equals(findViewById(R.id.preview_button))){
- Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse(cdnURL + "/" + objects.getCName()));
- startActivity(viewIntent);
- }
- /*
- * need to perform different functions based on if
- * the file is in the devices filesystem
- */
- if(v.equals(findViewById(R.id.download_button))){
- if(!isDownloaded){
- if(storageIsReady()){
- new ContainerObjectDownloadTask().execute();
- }
- else{
- showAlert("Error", "Storage not found.");
- }
- }
- else{
- openFile();
- }
- }
- }
- }
-
- private void showAlert(String title, String message) {
+ /*
+ * need to perform different functions based on if
+ * the file is in the devices filesystem
+ */
+ if(v.equals(findViewById(R.id.download_button))){
+ if(!isDownloaded){
+ if(storageIsReady()){
+ new ContainerObjectDownloadTask().execute();
+ }
+ else{
+ showAlert("Error", "Storage not found.");
+ }
+ }
+ else{
+ openFile();
+ }
+ }
+ }
+ }
+
+ private void showAlert(String title, String message) {
AlertDialog alert = new AlertDialog.Builder(this).create();
alert.setTitle(title);
alert.setMessage(message);
alert.setButton("OK", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- return;
- } });
+ public void onClick(DialogInterface dialog, int which) {
+ return;
+ } });
alert.show();
- }
- //Create the Menu options
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
+ }
+ //Create the Menu options
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.container_object_list_menu, menu);
return true;
}
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.delete_object:
showDialog(deleteObject);
return true;
case R.id.refresh:
loadObjectData();
- return true;
+ return true;
}
return false;
}
-
- @Override
- protected Dialog onCreateDialog(int id ) {
- switch (id) {
- case deleteObject:
- return new AlertDialog.Builder(ContainerObjectDetails.this)
- .setIcon(R.drawable.alert_dialog_icon)
- .setTitle("Delete File")
- .setMessage("Are you sure you want to delete this file?")
- .setPositiveButton("Delete File", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- // User clicked OK so do some stuff
- new ContainerObjectDeleteTask().execute((Void[]) null);
- }
- })
- .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- // User clicked Cancel so do some stuff
- }
- })
- .create();
- }
- return null;
- }
- /**
+
+ @Override
+ protected Dialog onCreateDialog(int id ) {
+ switch (id) {
+ case deleteObject:
+ return new AlertDialog.Builder(ContainerObjectDetails.this)
+ .setIcon(R.drawable.alert_dialog_icon)
+ .setTitle("Delete File")
+ .setMessage("Are you sure you want to delete this file?")
+ .setPositiveButton("Delete File", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ // User clicked OK so do some stuff
+ new ContainerObjectDeleteTask().execute((Void[]) null);
+ }
+ })
+ .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+ // User clicked Cancel so do some stuff
+ }
+ })
+ .create();
+ }
+ return null;
+ }
+ /**
* @return the file
*/
public ContainerObjects getViewFile() {
@@ -272,7 +340,7 @@ public ContainerObjects getViewFile() {
public void setViewFile(ContainerObjects object) {
this.objects = object;
}
-
+
/*
* returns false if external storage is not avaliable
* (if its mounted, missing, read-only, etc)
@@ -284,20 +352,20 @@ private boolean storageIsReady(){
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
- // We can read and write the media
- mExternalStorageAvailable = mExternalStorageWriteable = true;
+ // We can read and write the media
+ mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
- // We can only read the media
- mExternalStorageAvailable = true;
- mExternalStorageWriteable = false;
+ // We can only read the media
+ mExternalStorageAvailable = true;
+ mExternalStorageWriteable = false;
} else {
- // Something else is wrong. It may be one of many other states, but all we need
- // to know is we can neither read nor write
- mExternalStorageAvailable = mExternalStorageWriteable = false;
+ // Something else is wrong. It may be one of many other states, but all we need
+ // to know is we can neither read nor write
+ mExternalStorageAvailable = mExternalStorageWriteable = false;
}
return mExternalStorageAvailable && mExternalStorageWriteable;
}
-
+
private boolean fileIsDownloaded(){
if(storageIsReady()){
String fileName = Environment.getExternalStorageDirectory().getPath() + "/RackspaceCloud/" + objects.getCName();
@@ -306,37 +374,37 @@ private boolean fileIsDownloaded(){
}
return false;
}
-
+
private void openFile(){
File object = new File(Environment.getExternalStorageDirectory().getPath() + "/RackspaceCloud/" + objects.getCName());
Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW);
- File file = new File(object.getAbsolutePath());
- String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
- String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
- myIntent.setDataAndType(Uri.fromFile(file),mimetype);
- //myIntent.setData(Uri.fromFile(file));
- try{
- startActivity(myIntent);
- }
- catch(Exception e){
- Toast.makeText(this, "Could not open file.", Toast.LENGTH_SHORT).show();
- }
+ File file = new File(object.getAbsolutePath());
+ String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
+ String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
+ myIntent.setDataAndType(Uri.fromFile(file),mimetype);
+ //myIntent.setData(Uri.fromFile(file));
+ try{
+ startActivity(myIntent);
+ }
+ catch(Exception e){
+ Toast.makeText(this, "Could not open file.", Toast.LENGTH_SHORT).show();
+ }
}
-
+
private boolean writeFile(byte[] data){
String directoryName = Environment.getExternalStorageDirectory().getPath() + DOWNLOAD_DIRECTORY;
File f = new File(directoryName);
-
+
if(!f.isDirectory()){
if(!f.mkdir()){
return false;
}
}
-
+
String filename = directoryName + "/" + objects.getCName();
File object = new File(filename);
BufferedOutputStream bos = null;
-
+
try{
FileOutputStream fos = new FileOutputStream(object);
bos = new BufferedOutputStream(fos);
@@ -361,146 +429,243 @@ private boolean writeFile(byte[] data){
}
return true;
}
-
+
//Task's
-
- private CloudServersException parseCloudServersException(HttpResponse response) {
- CloudServersException cse = new CloudServersException();
- try {
- BasicResponseHandler responseHandler = new BasicResponseHandler();
- String body = responseHandler.handleResponse(response);
- CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
- SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
- XMLReader xmlReader = saxParser.getXMLReader();
- xmlReader.setContentHandler(parser);
- xmlReader.parse(new InputSource(new StringReader(body)));
- cse = parser.getException();
- } catch (ClientProtocolException e) {
- cse = new CloudServersException();
- cse.setMessage(e.getLocalizedMessage());
- } catch (IOException e) {
- cse = new CloudServersException();
- cse.setMessage(e.getLocalizedMessage());
- } catch (ParserConfigurationException e) {
- cse = new CloudServersException();
- cse.setMessage(e.getLocalizedMessage());
- } catch (SAXException e) {
- cse = new CloudServersException();
- cse.setMessage(e.getLocalizedMessage());
- } catch (FactoryConfigurationError e) {
- cse = new CloudServersException();
- cse.setMessage(e.getLocalizedMessage());
- }
- return cse;
- }
-
- private void startFileError(String message, HttpBundle bundle){
- Intent viewIntent = new Intent(getApplicationContext(), ServerErrorActivity.class);
- viewIntent.putExtra("errorMessage", message);
- viewIntent.putExtra("response", bundle.getResponseText());
- viewIntent.putExtra("request", bundle.getCurlRequest());
- startActivity(viewIntent);
- }
-
- private class ContainerObjectDeleteTask extends AsyncTask<Void, Void, HttpBundle> {
-
- private CloudServersException exception;
-
- protected void onPreExecute(){
- dialog = ProgressDialog.show(ContainerObjectDetails.this, "", "Deleting...", true);
- }
-
- @Override
- protected HttpBundle doInBackground(Void... arg0) {
- HttpBundle bundle = null;
- try {
- bundle = (new ContainerObjectManager(context)).deleteObject(containerNames, objects.getCName() );
- } catch (CloudServersException e) {
- exception = e;
- }
- return bundle;
- }
-
- @Override
- protected void onPostExecute(HttpBundle bundle) {
- dialog.dismiss();
- HttpResponse response = bundle.getResponse();
- if (response != null) {
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode == 204) {
- setResult(Activity.RESULT_OK);
- finish();
-
- } else {
- CloudServersException cse = parseCloudServersException(response);
- if ("".equals(cse.getMessage())) {
- startFileError("There was a problem deleting your File.", bundle);
- } else {
- startFileError("There was a problem deleting your file: " + cse.getMessage(), bundle);
- }
- }
- } else if (exception != null) {
- startFileError("There was a problem deleting your file: " + exception.getMessage(), bundle);
- }
- }
- }
-
- private class ContainerObjectDownloadTask extends AsyncTask<Void, Void, HttpBundle> {
-
- private CloudServersException exception;
-
- @Override
- protected void onPreExecute(){
- dialog = ProgressDialog.show(ContainerObjectDetails.this, "", "Downloading...", true);
- }
-
- @Override
- protected HttpBundle doInBackground(Void... arg0) {
- HttpBundle bundle = null;
- try {
- bundle = (new ContainerObjectManager(context)).getObject(containerNames, objects.getCName());
- } catch (CloudServersException e) {
- exception = e;
- }
- return bundle;
- }
-
- @Override
- protected void onPostExecute(HttpBundle bundle) {
- dialog.dismiss();
- HttpResponse response = bundle.getResponse();
- if (response != null) {
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode == 200) {
- setResult(Activity.RESULT_OK);
- HttpEntity entity = response.getEntity();
-
- try {
- if(writeFile(EntityUtils.toByteArray(entity))){
- downloadButton.setText("Open File");
- isDownloaded = true;
- }
- else{
- showAlert("Error", "There was a problem downloading your file.");
- }
-
- } catch (IOException e) {
- showAlert("Error", "There was a problem downloading your file.");
- e.printStackTrace();
- }
-
- } else {
- CloudServersException cse = parseCloudServersException(response);
- if ("".equals(cse.getMessage())) {
- startFileError("There was a problem downloading your File.", bundle);
- } else {
- startFileError("There was a problem downloading your file: " + cse.getMessage(), bundle);
- }
- }
- } else if (exception != null) {
- startFileError("There was a problem downloading your file: " + exception.getMessage(), bundle);
- }
- }
- }
+
+ private CloudServersException parseCloudServersException(HttpResponse response) {
+ CloudServersException cse = new CloudServersException();
+ try {
+ BasicResponseHandler responseHandler = new BasicResponseHandler();
+ String body = responseHandler.handleResponse(response);
+ CloudServersFaultXMLParser parser = new CloudServersFaultXMLParser();
+ SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
+ XMLReader xmlReader = saxParser.getXMLReader();
+ xmlReader.setContentHandler(parser);
+ xmlReader.parse(new InputSource(new StringReader(body)));
+ cse = parser.getException();
+ } catch (ClientProtocolException e) {
+ cse = new CloudServersException();
+ cse.setMessage(e.getLocalizedMessage());
+ } catch (IOException e) {
+ cse = new CloudServersException();
+ cse.setMessage(e.getLocalizedMessage());
+ } catch (ParserConfigurationException e) {
+ cse = new CloudServersException();
+ cse.setMessage(e.getLocalizedMessage());
+ } catch (SAXException e) {
+ cse = new CloudServersException();
+ cse.setMessage(e.getLocalizedMessage());
+ } catch (FactoryConfigurationError e) {
+ cse = new CloudServersException();
+ cse.setMessage(e.getLocalizedMessage());
+ }
+ return cse;
+ }
+
+ private void startFileError(String message, HttpBundle bundle){
+ Intent viewIntent = new Intent(getApplicationContext(), ServerErrorActivity.class);
+ viewIntent.putExtra("errorMessage", message);
+ viewIntent.putExtra("response", bundle.getResponseText());
+ viewIntent.putExtra("request", bundle.getCurlRequest());
+ startActivity(viewIntent);
+ }
- }
+ private void showDialog() {
+ if(dialog == null || !dialog.isShowing()){
+ displayDialog = true;
+ dialog = ProgressDialog.show(ContainerObjectDetails.this, "", "Loading...", true);
+ }
+ }
+
+ private void hideDialog() {
+ if(dialog != null){
+ dialog.dismiss();
+ }
+ displayDialog = false;
+ }
+
+ private class ContainerObjectDeleteTask extends AsyncTask<Void, Void, HttpBundle> {
+
+ private CloudServersException exception;
+
+ protected void onPreExecute(){
+ //dialog = ProgressDialog.show(ContainerObjectDetails.this, "", "Deleting...", true);
+ showDialog();
+ app.setDeleteingObject(true);
+ deleteObjTask = new DeleteObjectListenerTask();
+ deleteObjTask.execute();
+ }
+
+ @Override
+ protected HttpBundle doInBackground(Void... arg0) {
+ HttpBundle bundle = null;
+ try {
+ bundle = (new ContainerObjectManager(context)).deleteObject(containerNames, objects.getCName() );
+ } catch (CloudServersException e) {
+ exception = e;
+ }
+
+ return bundle;
+ }
+
+ @Override
+ protected void onPostExecute(HttpBundle bundle) {
+ //dialog.dismiss();
+ app.setDeleteingObject(false);
+ hideDialog();
+ HttpResponse response = bundle.getResponse();
+ if (response != null) {
+ int statusCode = response.getStatusLine().getStatusCode();
+ if (statusCode == 204) {
+ //handled by listner
+ } else {
+ CloudServersException cse = parseCloudServersException(response);
+ if ("".equals(cse.getMessage())) {
+ startFileError("There was a problem deleting your File.", bundle);
+ } else {
+ startFileError("There was a problem deleting your file: " + cse.getMessage(), bundle);
+ }
+ }
+ } else if (exception != null) {
+ startFileError("There was a problem deleting your file: " + exception.getMessage(), bundle);
+ }
+ }
+ }
+
+ private class ContainerObjectDownloadTask extends AsyncTask<Void, Void, HttpBundle> {
+
+ private CloudServersException exception;
+
+ @Override
+ protected void onPreExecute(){
+ showDialog();
+ app.setDownloadingObject(true);
+ downloadObjTask = new DownloadObjectListenerTask();
+ downloadObjTask.execute();
+ }
+
+ @Override
+ protected HttpBundle doInBackground(Void... arg0) {
+ HttpBundle bundle = null;
+ try {
+ bundle = (new ContainerObjectManager(context)).getObject(containerNames, objects.getCName());
+ } catch (CloudServersException e) {
+ exception = e;
+ }
+ return bundle;
+ }
+
+ @Override
+ protected void onPostExecute(HttpBundle bundle) {
+ app.setDownloadingObject(false);
+ hideDialog();
+ HttpResponse response = bundle.getResponse();
+ if (response != null) {
+ int statusCode = response.getStatusLine().getStatusCode();
+ if (statusCode == 200) {
+ setResult(Activity.RESULT_OK);
+ HttpEntity entity = response.getEntity();
+ app.setDownloadedEntity(entity);
+ /*
+ try {
+ if(writeFile(EntityUtils.toByteArray(entity))){
+ downloadButton.setText("Open File");
+ isDownloaded = true;
+ }
+ else{
+ showAlert("Error", "There was a problem downloading your file.");
+ }
+
+ } catch (IOException e) {
+ showAlert("Error", "There was a problem downloading your file.");
+ e.printStackTrace();
+ }
+ */
+
+ } else {
+ CloudServersException cse = parseCloudServersException(response);
+ if ("".equals(cse.getMessage())) {
+ startFileError("There was a problem downloading your File.", bundle);
+ } else {
+ startFileError("There was a problem downloading your file: " + cse.getMessage(), bundle);
+ }
+ }
+ } else if (exception != null) {
+ startFileError("There was a problem downloading your file: " + exception.getMessage(), bundle);
+ }
+ }
+ }
+
+ private class DeleteObjectListenerTask extends
+ AsyncTask<Void, Void, Void> {
+
+ @Override
+ protected Void doInBackground(Void... arg1) {
+
+ while(app.isDeletingObject()){
+ // wait for process to finish
+ // or have it be canceled
+ if(deleteObjTask.isCancelled()){
+ return null;
+ }
+ }
+ return null;
+ }
+
+ /*
+ * when no longer processing, time to load
+ * the new files
+ */
+ @Override
+ protected void onPostExecute(Void arg1) {
+ hideDialog();
+ setResult(99);
+ finish();
+ }
+ }
+
+ private class DownloadObjectListenerTask extends
+ AsyncTask<Void, Void, Void> {
+
+ @Override
+ protected Void doInBackground(Void... arg1) {
+
+ while(app.isDownloadingObject()){
+ // wait for process to finish
+ // or have it be canceled
+ if(downloadObjTask.isCancelled()){
+ return null;
+ }
+ }
+ return null;
+ }
+
+ /*
+ * when no longer processing, time to load
+ * the new files
+ */
+ @Override
+ protected void onPostExecute(Void arg1) {
+ hideDialog();
+ try {
+ Log.d("info", "captin starting to write");
+ if(writeFile(EntityUtils.toByteArray(app.getDownloadedEntity()))){
+ downloadButton.setText("Open File");
+ isDownloaded = true;
+ Log.d("info", "captin wrote");
+ }
+ else{
+ showAlert("Error", "There was a problem downloading your file.");
+ }
+
+ } catch (IOException e) {
+ showAlert("Error", "There was a problem downloading your file.");
+ e.printStackTrace();
+ } catch (Exception e) {
+ showAlert("Error", "There was a problem downloading your file.");
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
54 src/com/rackspacecloud/android/ContainerObjectsActivity.java
View
@@ -173,6 +173,12 @@ private void restoreState(Bundle state) {
deleteObjTask = new DeleteObjectListenerTask();
deleteObjTask.execute();
}
+
+ if(app.isDeletingContainer()){
+ displayNoFilesCell();
+ deleteContainerTask = new DeleteContainerListenerTask();
+ deleteContainerTask.execute();
+ }
}
@@ -202,6 +208,15 @@ protected void onStop(){
if(task != null){
task.cancel(true);
}
+
+ if(deleteObjTask != null){
+ deleteObjTask.cancel(true);
+ }
+
+ if(deleteContainerTask != null){
+ deleteContainerTask.cancel(true);
+ }
+
}
/*
@@ -234,18 +249,6 @@ private void loadFiles() {
new LoadFilesTask().execute();
}
- /*
- private void displayLoadingCell() {
- String a[] = new String[1];
- a[0] = "Loading...";
- setListAdapter(new ArrayAdapter<String>(this, R.layout.loadingcell,
- R.id.loading_label, a));
- getListView().setTextFilterEnabled(true);
- getListView().setDividerHeight(0); // hide the dividers so it won't look
- // like a list row
- getListView().setItemsCanFocus(false);
- }
- */
/* load only the files that should display for the
* current directory in the curDirFiles[]
@@ -309,13 +312,6 @@ private void displayCurrentFiles(){
for(int i = 0; i < app.getCurFiles().size(); i++){
tempList.add(app.getCurFiles().get(i));
}
- /*
- adapter.clear();
- for(int i = 0; i < tempList.size(); i++){
- adapter.add(tempList.get(i));
- Log.d("info", "the count is: " + adapter.getCount());
- }
- */
getListView().setDividerHeight(1); // restore divider lines
setListAdapter(new FileAdapter());
}
@@ -568,20 +564,15 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && requestCode == 56) {
- Log.d("info", "top called");
// a sub-activity kicked back, so we want to refresh the server list
loadFiles();
}
- /*
- if (requestCode == 55) {
- Log.d("info", "bottom called");
- if (resultCode == RESULT_OK) {
- Intent viewIntent1 = new Intent(this,
- ListContainerActivity.class);
- startActivityForResult(viewIntent1, 55);
- }
+
+ // deleted file so need to update the list
+ if (requestCode == 55 && resultCode == 99) {
+ loadFiles();
}
- */
+
}
private CloudServersException parseCloudServersException(
@@ -798,7 +789,8 @@ protected void onPostExecute(HttpBundle bundle) {
}
if (statusCode == 204) {
setResult(Activity.RESULT_OK);
- } else {hideDialog();
+ } else {
+ hideDialog();
CloudServersException cse = parseCloudServersException(response);
if ("".equals(cse.getMessage())) {
startFileError("There was a problem deleting your folder.", bundle);
@@ -951,6 +943,8 @@ protected Void doInBackground(Void... arg1) {
*/
@Override
protected void onPostExecute(Void arg1) {
+
+ hideDialog();
setResult(RESULT_OK);
finish();
}
17 src/com/rackspacecloud/android/ListAccountsActivity.java
View
@@ -26,6 +26,7 @@
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
@@ -92,6 +93,7 @@ protected void onRestoreInstanceState(Bundle state) {
loggedIn = false;
}
if (state != null && state.containsKey("authenticating") && state.getBoolean("authenticating")) {
+ Log.d("info", "captin on restore show");
showDialog();
} else {
hideDialog();
@@ -108,7 +110,7 @@ protected void onRestoreInstanceState(Bundle state) {
loadAccounts();
}
}
-
+
@Override
protected void onStart(){
super.onStart();
@@ -121,10 +123,12 @@ protected void onStart(){
protected void onStop(){
super.onStop();
if(authenticating){
+ Log.d("info", "captin onstop called");
hideDialog();
authenticating = true;
}
}
+
/*
* if the application is password protected,
@@ -366,6 +370,10 @@ private int setAccountIcon(Account account){
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
+ if(requestCode == 187){
+ hideDialog();
+ }
+
if (resultCode == RESULT_OK && requestCode == 78) {
Account acc = new Account();
Bundle b = data.getBundleExtra("accountInfo");
@@ -399,7 +407,9 @@ private void setActivityIndicatorsVisibility(int visibility, View v) {
private void showDialog() {
authenticating = true;
- dialog = ProgressDialog.show(ListAccountsActivity.this, "", "Authenticating...", true);
+ if(dialog == null || !dialog.isShowing()){
+ dialog = ProgressDialog.show(ListAccountsActivity.this, "", "Authenticating...", true);
+ }
}
private void hideDialog() {
@@ -413,6 +423,7 @@ private void hideDialog() {
@Override
protected void onPreExecute(){
+ Log.d("info", "auth show called");
showDialog();
}
@@ -451,7 +462,7 @@ protected void onPostExecute(ArrayList<Flavor> result) {
}
Flavor.setFlavors(flavorMap);
hideDialog();
- startActivity(tabViewIntent);
+ startActivityForResult(tabViewIntent, 187);
} else {
hideDialog();
showAlert("Login Failure", "There was a problem loading server flavors. Please try again.");
6 src/com/rackspacecloud/android/ListContainerActivity.java
View
@@ -59,7 +59,11 @@ protected void onSaveInstanceState(Bundle outState) {
}
private void restoreState(Bundle state) {
- if (state != null && state.containsKey("container") && state.getSerializable("container") != null) {
+ if(state != null && state.containsKey("loading") && state.getBoolean("loading")){
+ loadContainers();
+ registerForContextMenu(getListView());
+ }
+ else if (state != null && state.containsKey("container") && state.getSerializable("container") != null) {
containers = (Container[]) state.getSerializable("container");
if (containers.length == 0) {
displayNoServersCell();

No commit comments for this range

Something went wrong with that request. Please try again.