- \r
- IntentFilter f = new IntentFilter(FileSyncService.SYNC_MESSAGE);\r
- b = new BR();\r
- registerReceiver(b, f);\r
- if (getSupportFragmentManager().findFragmentById(R.id.fileList) == null)\r
- setContentView(R.layout.files);\r
- \r
- mDirectories = new CustomArrayAdapter<String>(this,\r
- R.layout.sherlock_spinner_dropdown_item);\r
- mDirectories.add("/");\r
- \r
- mStorageManager = new FileDataStorageManager(AccountUtils.getCurrentOwnCloudAccount(this), getContentResolver());\r
- ActionBar action_bar = getSupportActionBar();\r
- action_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);\r
- action_bar.setDisplayShowTitleEnabled(false);\r
- action_bar.setListNavigationCallbacks(mDirectories, this);\r
- action_bar.setDisplayHomeAsUpEnabled(true);\r
- }\r
- \r
- public void onActivityResult(int requestCode, int resultCode, Intent data) {\r
- if (resultCode == RESULT_OK) {\r
- if (requestCode == ACTION_SELECT_FILE) {\r
- Uri selectedImageUri = data.getData();\r
-\r
- String filemanagerstring = selectedImageUri.getPath();\r
-\r
- String selectedImagePath = getPath(selectedImageUri);\r
-\r
- //DEBUG PURPOSE - you can delete this if you want\r
- if(selectedImagePath!=null)\r
- System.out.println(selectedImagePath);\r
- else System.out.println("selectedImagePath is null");\r
- if(filemanagerstring!=null)\r
- System.out.println(filemanagerstring);\r
- else System.out.println("filemanagerstring is null");\r
-\r
- //NOW WE HAVE OUR WANTED STRING\r
- if(selectedImagePath!=null)\r
- System.out.println("selectedImagePath is the right one for you!");\r
- else\r
- System.out.println("filemanagerstring is the right one for you!");\r
- }\r
- }\r
- }\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
- {\r
- //HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL\r
- //THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA\r
- int column_index = cursor\r
- .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);\r
- cursor.moveToFirst();\r
- return cursor.getString(column_index);\r
- }\r
- else return null;\r
- }\r
- \r
- @Override\r
- protected void onPause() {\r
- super.onPause();\r
- if (b != null) {\r
- unregisterReceiver(b);\r
- b = null;\r
- }\r
- \r
- }\r
- \r
- @Override\r
- public boolean onNavigationItemSelected(int itemPosition, long itemId) {\r
- int i = itemPosition;\r
- while (i-- != 0) {\r
- onBackPressed();\r
- }\r
- return true;\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(Uri.parse(mAm.getUserData(\r
- mAccount, AccountAuthenticator.KEY_OC_URL)));\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.allowUnsignedCertificates();\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,\r
- int view) {\r
- super(ctx, view);\r
- }\r
-\r
- public View getView(int position, View convertView,\r
- ViewGroup parent) {\r
+\r
+ @Override\r
+ protected void onResume() {\r
+ super.onResume();\r
+ if (!accountsAreSetup()) {\r
+ showDialog(DIALOG_SETUP_ACCOUNT);\r
+ return;\r
+ }\r
+\r
+ IntentFilter f = new IntentFilter(FileSyncService.SYNC_MESSAGE);\r
+ syncBroadcastRevceiver = new SyncBroadcastReceiver();\r
+ registerReceiver(syncBroadcastRevceiver, f);\r
+\r
+ mDirectories = new CustomArrayAdapter<String>(this, R.layout.sherlock_spinner_dropdown_item);\r
+ mDirectories.add("/");\r
+ if (mDirs != null) {\r
+ for (String s : mDirs)\r
+ mDirectories.insert(s, 0);\r
+ FileListFragment fileListFramgent = (FileListFragment) getSupportFragmentManager()\r
+ .findFragmentById(R.id.fileList);\r
+ if (fileListFramgent != null) fileListFramgent.listDirectory();\r
+ }\r
+\r
+ mStorageManager = new FileDataStorageManager(\r
+ AccountUtils.getCurrentOwnCloudAccount(this),\r
+ getContentResolver());\r
+ ActionBar action_bar = getSupportActionBar();\r
+ action_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);\r
+ action_bar.setDisplayShowTitleEnabled(false);\r
+ action_bar.setListNavigationCallbacks(mDirectories, this);\r
+ action_bar.setDisplayHomeAsUpEnabled(true);\r
+ }\r
+\r
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {\r
+ if (resultCode == RESULT_OK) {\r
+ if (requestCode == ACTION_SELECT_FILE) {\r
+ Uri selectedImageUri = data.getData();\r
+\r
+ String filemanagerstring = selectedImageUri.getPath();\r
+ String selectedImagePath = getPath(selectedImageUri);\r
+ String filepath;\r
+\r
+ if (selectedImagePath != null)\r
+ filepath = selectedImagePath;\r
+ else\r
+ filepath = filemanagerstring;\r
+\r
+ if (filepath == null) {\r
+ Log.e("FileDisplay", "Couldnt resolve path to file");\r
+ return;\r
+ }\r
+\r
+ Intent i = new Intent(this, FileUploader.class);\r
+ i.putExtra(FileUploader.KEY_ACCOUNT,\r
+ AccountUtils.getCurrentOwnCloudAccount(this));\r
+ String remotepath = new String();\r
+ for (int j = mDirectories.getCount() - 2; j >= 0; --j) {\r
+ remotepath += "/" + URLEncoder.encode(mDirectories.getItem(j));\r
+ }\r
+ if (!remotepath.endsWith("/"))\r
+ remotepath += "/";\r
+ remotepath += URLEncoder.encode(new File(filepath).getName());\r
+ Log.e("ASD", remotepath + "");\r
+\r
+ i.putExtra(FileUploader.KEY_LOCAL_FILE, filepath);\r
+ i.putExtra(FileUploader.KEY_REMOTE_FILE, remotepath);\r
+ i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);\r
+ startService(i);\r
+ }\r
+ }\r
+ }\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
+ } else\r
+ return null;\r
+ }\r
+\r
+ @Override\r
+ protected void onPause() {\r
+ super.onPause();\r
+ if (syncBroadcastRevceiver != null) {\r
+ unregisterReceiver(syncBroadcastRevceiver);\r
+ syncBroadcastRevceiver = null;\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ public boolean onNavigationItemSelected(int itemPosition, long itemId) {\r
+ int i = itemPosition;\r
+ while (i-- != 0) {\r
+ onBackPressed();\r
+ }\r
+ return true;\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(Uri.parse(mAm.getUserData(\r
+ mAccount, AccountAuthenticator.KEY_OC_URL)));\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.allowUnsignedCertificates();\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