+ // Display the new folder right away\r
+ dialog.dismiss();\r
+ mFileList.listDirectory(mCurrentDir);\r
+ }\r
+ });\r
+ builder.setNegativeButton(R.string.common_cancel,\r
+ new OnClickListener() {\r
+ public void onClick(DialogInterface dialog, int which) {\r
+ dialog.cancel();\r
+ }\r
+ });\r
+ dialog = builder.create();\r
+ break;\r
+ }\r
+ default:\r
+ dialog = null;\r
+ }\r
+ \r
+ return dialog;\r
+ }\r
+\r
+ \r
+ /**\r
+ * Responds to the "There are no ownCloud Accounts setup" dialog\r
+ * TODO: Dialog is 100% useless -> Remove\r
+ */\r
+ @Override\r
+ public void onClick(DialogInterface dialog, int which) {\r
+ // In any case - we won't need it anymore\r
+ dialog.dismiss();\r
+ switch (which) {\r
+ case DialogInterface.BUTTON_POSITIVE:\r
+ Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");\r
+ intent.putExtra("authorities",\r
+ new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });\r
+ startActivity(intent);\r
+ break;\r
+ case DialogInterface.BUTTON_NEGATIVE:\r
+ finish();\r
+ }\r
+ \r
+ }\r
+\r
+ /**\r
+ * Translates a content URI of an image to a physical path\r
+ * on the disk\r
+ * @param uri The URI to resolve\r
+ * @return The path to the image or null if it could not be found\r
+ */\r
+ public String getPath(Uri uri) {\r
+ String[] projection = { MediaStore.Images.Media.DATA };\r
+ Cursor cursor = managedQuery(uri, projection, null, null, null);\r
+ if (cursor != null) {\r
+ int column_index = cursor\r
+ .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);\r
+ cursor.moveToFirst();\r
+ return cursor.getString(column_index);\r
+ } \r
+ return null;\r
+ }\r
+ \r
+ /**\r
+ * Pushes a directory to the drop down list\r
+ * @param directory to push\r
+ * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.\r
+ */\r
+ public void pushDirname(OCFile directory) {\r
+ if(!directory.isDirectory()){\r
+ throw new IllegalArgumentException("Only directories may be pushed!");\r
+ }\r
+ mDirectories.insert(directory.getFileName(), 0);\r
+ mCurrentDir = directory;\r
+ }\r
+\r
+ /**\r
+ * Pops a directory name from the drop down list\r
+ * @return True, unless the stack is empty\r
+ */\r
+ public boolean popDirname() {\r
+ mDirectories.remove(mDirectories.getItem(0));\r
+ return !mDirectories.isEmpty();\r
+ }\r
+\r
+ private class DirectoryCreator implements Runnable {\r
+ private String mTargetPath;\r
+ private Account mAccount;\r
+ private AccountManager mAm;\r
+ \r
+ public DirectoryCreator(String targetPath, Account account) {\r
+ mTargetPath = targetPath;\r
+ mAccount = account;\r
+ mAm = (AccountManager) getSystemService(ACCOUNT_SERVICE);\r
+ }\r
+ \r
+ @Override\r
+ public void run() {\r
+ WebdavClient wdc = new WebdavClient(mAccount, getApplicationContext());\r
+ \r
+ String username = mAccount.name.substring(0,\r
+ mAccount.name.lastIndexOf('@'));\r
+ String password = mAm.getPassword(mAccount);\r
+ \r
+ wdc.setCredentials(username, password);\r
+ wdc.allowSelfsignedCertificates();\r
+ wdc.createDirectory(mTargetPath);\r
+ }\r
+ \r
+ }\r
+\r
+ // Custom array adapter to override text colors\r
+ private class CustomArrayAdapter<T> extends ArrayAdapter<T> {\r
+ \r
+ public CustomArrayAdapter(FileDisplayActivity ctx, int view) {\r
+ super(ctx, view);\r
+ }\r
+ \r
+ public View getView(int position, View convertView, ViewGroup parent) {\r
+ View v = super.getView(position, convertView, parent);\r
+ \r
+ ((TextView) v).setTextColor(getResources().getColorStateList(\r
+ android.R.color.white));\r
+ return v;\r
+ }\r
+ \r
+ public View getDropDownView(int position, View convertView,\r
+ ViewGroup parent) {\r
+ View v = super.getDropDownView(position, convertView, parent);\r
+ \r
+ ((TextView) v).setTextColor(getResources().getColorStateList(\r
+ android.R.color.white));\r
+ \r
+ return v;\r
+ }\r
+ \r
+ }\r
+\r
+ private class SyncBroadcastReceiver extends BroadcastReceiver {\r
+ /**\r
+ * {@link BroadcastReceiver} to enable syncing feedback in UI\r
+ */\r
+ @Override\r
+ public void onReceive(Context context, Intent intent) {\r
+ boolean inProgress = intent.getBooleanExtra(\r
+ FileSyncService.IN_PROGRESS, false);\r
+ String account_name = intent\r
+ .getStringExtra(FileSyncService.ACCOUNT_NAME);\r
+ Log.d("FileDisplay", "sync of account " + account_name\r
+ + " is in_progress: " + inProgress);\r
+ setSupportProgressBarIndeterminateVisibility(inProgress);\r
+ \r
+ long OCDirId = intent.getLongExtra(FileSyncService.SYNC_FOLDER, -1);\r
+ if (OCDirId > 0) {\r
+ OCFile syncDir = mStorageManager.getFileById(OCDirId);\r
+ if (syncDir != null && (\r
+ (mCurrentDir == null && syncDir.getFileName().equals("/")) ||\r
+ syncDir.equals(mCurrentDir))\r
+ ) {\r
+ FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager().findFragmentById(R.id.fileList);\r
+ if (fileListFragment != null) { \r
+ fileListFragment.listDirectory();\r
+ }\r
+ }\r
+ }\r
+ \r
+ if (!inProgress) {\r
+ FileListFragment fileListFragment = (FileListFragment) getSupportFragmentManager()\r
+ .findFragmentById(R.id.fileList);\r
+ if (fileListFragment != null)\r
+ fileListFragment.listDirectory();\r
+ }\r
+ }\r