import android.accounts.Account;\r
import android.accounts.AccountManager;\r
import android.app.AlertDialog;\r
+import android.app.ProgressDialog;\r
import android.app.AlertDialog.Builder;\r
import android.app.Dialog;\r
import android.content.BroadcastReceiver;\r
import android.content.SharedPreferences;\r
import android.content.pm.PackageInfo;\r
import android.content.pm.PackageManager.NameNotFoundException;\r
+import android.content.res.Resources.NotFoundException;\r
import android.database.Cursor;\r
import android.net.Uri;\r
import android.os.Bundle;\r
+import android.os.Handler;\r
import android.preference.PreferenceManager;\r
import android.provider.MediaStore;\r
import android.support.v4.app.FragmentTransaction;\r
private static final int DIALOG_SETUP_ACCOUNT = 0;\r
private static final int DIALOG_CREATE_DIR = 1;\r
private static final int DIALOG_ABOUT_APP = 2;\r
+ private static final int DIALOG_SHORT_WAIT = 3;\r
\r
private static final int ACTION_SELECT_FILE = 1;\r
\r
+ private static final String TAG = "FileDisplayActivity";\r
+ \r
+ \r
@Override\r
public void onCreate(Bundle savedInstanceState) {\r
Log.i(getClass().toString(), "onCreate() start");\r
} catch (NameNotFoundException e) {\r
builder = null;\r
dialog = null;\r
- e.printStackTrace();\r
+ Log.e(TAG, "Error while showing about dialog", e);\r
}\r
break;\r
}\r
\r
// Create directory\r
path += directoryName + OCFile.PATH_SEPARATOR;\r
- Thread thread = new Thread(new DirectoryCreator(path, a));\r
+ Thread thread = new Thread(new DirectoryCreator(path, a, new Handler()));\r
thread.start();\r
- \r
- // Save new directory in local database\r
- OCFile newDir = new OCFile(path);\r
- newDir.setMimetype("DIR");\r
- newDir.setParentId(mCurrentDir.getFileId());\r
- mStorageManager.saveFile(newDir);\r
- \r
- // Display the new folder right away\r
+ \r
dialog.dismiss();\r
- mFileList.listDirectory(mCurrentDir);\r
+ \r
+ showDialog(DIALOG_SHORT_WAIT);\r
}\r
});\r
builder.setNegativeButton(R.string.common_cancel,\r
dialog = builder.create();\r
break;\r
}\r
+ case DIALOG_SHORT_WAIT: {\r
+ ProgressDialog working_dialog = new ProgressDialog(this);\r
+ working_dialog.setMessage(getResources().getString(\r
+ R.string.wait_a_moment));\r
+ working_dialog.setIndeterminate(true);\r
+ working_dialog.setCancelable(false);\r
+ dialog = working_dialog;\r
+ break;\r
+ }\r
default:\r
dialog = null;\r
}\r
private String mTargetPath;\r
private Account mAccount;\r
private AccountManager mAm;\r
+ private Handler mHandler; \r
\r
- public DirectoryCreator(String targetPath, Account account) {\r
+ public DirectoryCreator(String targetPath, Account account, Handler handler) {\r
mTargetPath = targetPath;\r
mAccount = account;\r
mAm = (AccountManager) getSystemService(ACCOUNT_SERVICE);\r
+ mHandler = handler;\r
}\r
\r
@Override\r
\r
wdc.setCredentials(username, password);\r
wdc.allowSelfsignedCertificates();\r
- wdc.createDirectory(mTargetPath);\r
+ boolean created = wdc.createDirectory(mTargetPath);\r
+ if (created) {\r
+ mHandler.post(new Runnable() {\r
+ @Override\r
+ public void run() { \r
+ dismissDialog(DIALOG_SHORT_WAIT);\r
+ \r
+ // Save new directory in local database\r
+ OCFile newDir = new OCFile(mTargetPath);\r
+ newDir.setMimetype("DIR");\r
+ newDir.setParentId(mCurrentDir.getFileId());\r
+ mStorageManager.saveFile(newDir);\r
+ \r
+ // Display the new folder right away\r
+ mFileList.listDirectory(mCurrentDir);\r
+ }\r
+ });\r
+ \r
+ } else {\r
+ mHandler.post(new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ dismissDialog(DIALOG_SHORT_WAIT);\r
+ try {\r
+ Toast msg = Toast.makeText(FileDisplayActivity.this, R.string.create_dir_fail_msg, Toast.LENGTH_LONG); \r
+ msg.show();\r
+ \r
+ } catch (NotFoundException e) {\r
+ Log.e(TAG, "Error while trying to show fail message " , e);\r
+ }\r
+ }\r
+ });\r
+ }\r
}\r
\r
}\r
*/\r
public boolean downloadFile(String remoteFilepath, File targetFile) {\r
boolean ret = false;\r
- boolean caughtException = false;\r
GetMethod get = new GetMethod(mUri.toString() + WebdavUtils.encodePath(remoteFilepath));\r
\r
int status = -1;\r
\r
} catch (HttpException e) {\r
Log.e(TAG, "HTTP exception downloading " + remoteFilepath, e);\r
- caughtException = true;\r
\r
} catch (IOException e) {\r
Log.e(TAG, "I/O exception downloading " + remoteFilepath, e);\r
- caughtException = true;\r
\r
} catch (Exception e) {\r
Log.e(TAG, "Unexpected exception downloading " + remoteFilepath, e);\r
- caughtException = true;\r
\r
} finally {\r
if (!ret) {\r
- if (!caughtException) {\r
+ if (status >= 0) {\r
Log.e(TAG, "Download of " + remoteFilepath + " to " + targetFile + " failed with HTTP status " + status);\r
}\r
if (targetFile.exists()) {\r
*/\r
public boolean putFile(String localFile, String remoteTarget, String contentType) {\r
boolean result = false;\r
- boolean caughtException = false;\r
- int status = 0;\r
+ int status = -1;\r
\r
try {\r
File f = new File(localFile);\r
\r
} catch (HttpException e) {\r
Log.e(TAG, "HTTP exception uploading " + localFile + " to " + remoteTarget, e);\r
- caughtException = true;\r
\r
} catch (IOException e) {\r
Log.e(TAG, "I/O exception uploading " + localFile + " to " + remoteTarget, e);\r
- caughtException = true;\r
\r
} catch (Exception e) {\r
Log.e(TAG, "Unexpected exception uploading " + localFile + " to " + remoteTarget, e);\r
- caughtException = true;\r
}\r
\r
- if (!result && !caughtException) Log.e(TAG, "Upload of " + localFile + " to " + remoteTarget + " FAILED with HTTP status " + status);\r
+ if (!result && status >= 0) Log.e(TAG, "Upload of " + localFile + " to " + remoteTarget + " FAILED with HTTP status " + status);\r
\r
return result;\r
}\r
* @return 'True' when the directory is successfully created\r
*/\r
public boolean createDirectory(String path) {\r
+ boolean result = false;\r
+ int status = -1;\r
try {\r
MkColMethod mkcol = new MkColMethod(mUri.toString() + WebdavUtils.encodePath(path));\r
- int status = executeMethod(mkcol);\r
- Log.d(TAG, "Status returned " + status);\r
- Log.d(TAG, "uri: " + mkcol.getURI().toString());\r
- Log.i(TAG, "Creating dir completed");\r
- } catch (final Exception e) {\r
- e.printStackTrace();\r
- return false;\r
+ Log.d(TAG, "Creating directory " + path);\r
+ status = executeMethod(mkcol);\r
+ Log.d(TAG, "Status returned: " + status);\r
+ result = mkcol.succeeded();\r
+ \r
+ } catch (HttpException e) {\r
+ Log.e(TAG, "HTTP exception creating directory " + path, e);\r
+\r
+ } catch (IOException e) {\r
+ Log.e(TAG, "I/O exception creating directory " + path, e);\r
+\r
+ } catch (Exception e) {\r
+ Log.e(TAG, "Unexpected exception creating directory " + path, e);\r
+ \r
}\r
- return true;\r
+ if (!result && status >= 0) {\r
+ Log.e(TAG, "Creation of directory " + path + " failed with HTTP status " + status);\r
+ }\r
+ return result;\r
}\r
\r
\r