2 * ownCloud Android client application
4 * @author Bartek Przybylski
6 * Copyright (C) 2012 Bartek Przybylski
7 * Copyright (C) 2015 ownCloud Inc.
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2,
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 package com
.owncloud
.android
.ui
.activity
;
26 import java
.util
.ArrayList
;
27 import java
.util
.HashMap
;
28 import java
.util
.LinkedList
;
29 import java
.util
.List
;
30 import java
.util
.Stack
;
31 import java
.util
.Vector
;
34 import android
.accounts
.Account
;
35 import android
.accounts
.AccountManager
;
36 import android
.app
.AlertDialog
;
37 import android
.app
.AlertDialog
.Builder
;
38 import android
.app
.Dialog
;
39 import android
.app
.ProgressDialog
;
40 import android
.content
.Context
;
41 import android
.content
.DialogInterface
;
42 import android
.content
.DialogInterface
.OnCancelListener
;
43 import android
.content
.DialogInterface
.OnClickListener
;
44 import android
.content
.Intent
;
45 import android
.content
.SharedPreferences
;
46 import android
.content
.res
.Resources
.NotFoundException
;
47 import android
.database
.Cursor
;
48 import android
.net
.Uri
;
49 import android
.os
.Bundle
;
50 import android
.os
.Parcelable
;
51 import android
.preference
.PreferenceManager
;
52 import android
.provider
.MediaStore
;
53 import android
.provider
.MediaStore
.Audio
;
54 import android
.provider
.MediaStore
.Images
;
55 import android
.provider
.MediaStore
.Video
;
56 import android
.support
.v4
.app
.Fragment
;
57 import android
.support
.v4
.app
.FragmentManager
;
58 import android
.support
.v4
.app
.FragmentTransaction
;
59 import android
.view
.View
;
60 import android
.widget
.AdapterView
;
61 import android
.widget
.AdapterView
.OnItemClickListener
;
62 import android
.widget
.Button
;
63 import android
.widget
.EditText
;
64 import android
.widget
.ListView
;
65 import android
.widget
.SimpleAdapter
;
66 import android
.widget
.Toast
;
68 import com
.actionbarsherlock
.app
.ActionBar
;
69 import com
.actionbarsherlock
.view
.MenuItem
;
70 import com
.owncloud
.android
.MainApp
;
71 import com
.owncloud
.android
.R
;
72 import com
.owncloud
.android
.authentication
.AccountAuthenticator
;
73 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
74 import com
.owncloud
.android
.datamodel
.OCFile
;
75 import com
.owncloud
.android
.files
.services
.FileUploader
;
76 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
77 import com
.owncloud
.android
.MainApp
;
78 import com
.owncloud
.android
.R
;
79 import com
.owncloud
.android
.authentication
.AccountAuthenticator
;
80 import com
.owncloud
.android
.datamodel
.OCFile
;
81 import com
.owncloud
.android
.files
.services
.FileUploader
;
82 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
83 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
84 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
85 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
86 import com
.owncloud
.android
.ui
.dialog
.CreateFolderDialogFragment
;
87 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
88 import com
.owncloud
.android
.utils
.CopyTmpFileAsyncTask
;
89 import com
.owncloud
.android
.utils
.DisplayUtils
;
90 import com
.owncloud
.android
.utils
.ErrorMessageAdapter
;
94 * This can be used to upload things to an ownCloud instance.
96 public class Uploader
extends FileActivity
97 implements OnItemClickListener
, android
.view
.View
.OnClickListener
,
98 CopyTmpFileAsyncTask
.OnCopyTmpFileTaskListener
{
100 private static final String TAG
= Uploader
.class.getSimpleName();
102 private AccountManager mAccountManager
;
103 private Stack
<String
> mParents
;
104 private ArrayList
<Parcelable
> mStreamsToUpload
;
105 private boolean mCreateDir
;
106 private String mUploadPath
;
107 private OCFile mFile
;
108 private boolean mAccountSelected
;
109 private boolean mAccountSelectionShowing
;
111 private ArrayList
<String
> mRemoteCacheData
;
112 private int mNumCacheFile
;
114 private final static int DIALOG_NO_ACCOUNT
= 0;
115 private final static int DIALOG_WAITING
= 1;
116 private final static int DIALOG_NO_STREAM
= 2;
117 private final static int DIALOG_MULTIPLE_ACCOUNT
= 3;
119 private final static int REQUEST_CODE_SETUP_ACCOUNT
= 0;
121 private final static String KEY_PARENTS
= "PARENTS";
122 private final static String KEY_FILE
= "FILE";
123 private final static String KEY_ACCOUNT_SELECTED
= "ACCOUNT_SELECTED";
124 private final static String KEY_ACCOUNT_SELECTION_SHOWING
= "ACCOUNT_SELECTION_SHOWING";
125 private final static String KEY_NUM_CACHE_FILE
= "NUM_CACHE_FILE";
126 private final static String KEY_REMOTE_CACHE_DATA
= "REMOTE_CACHE_DATA";
128 private static final String DIALOG_WAIT_COPY_FILE
= "DIALOG_WAIT_COPY_FILE";
131 protected void onCreate(Bundle savedInstanceState
) {
132 prepareStreamsToUpload();
134 if (savedInstanceState
== null
) {
135 mParents
= new Stack
<String
>();
136 mAccountSelected
= false
;
137 mAccountSelectionShowing
= false
;
140 // ArrayList for files with path in private storage
141 mRemoteCacheData
= new ArrayList
<String
>();
143 mParents
= (Stack
<String
>) savedInstanceState
.getSerializable(KEY_PARENTS
);
144 mFile
= savedInstanceState
.getParcelable(KEY_FILE
);
145 mAccountSelected
= savedInstanceState
.getBoolean(KEY_ACCOUNT_SELECTED
);
146 mAccountSelectionShowing
= savedInstanceState
.getBoolean(KEY_ACCOUNT_SELECTION_SHOWING
);
147 mNumCacheFile
= savedInstanceState
.getInt(KEY_NUM_CACHE_FILE
);
148 mRemoteCacheData
= savedInstanceState
.getStringArrayList(KEY_REMOTE_CACHE_DATA
);
151 super.onCreate(savedInstanceState
);
153 if (mAccountSelected
) {
154 setAccount((Account
) savedInstanceState
.getParcelable(FileActivity
.EXTRA_ACCOUNT
));
158 ActionBar actionBar
= getSupportActionBar();
159 actionBar
.setIcon(DisplayUtils
.getSeasonalIconId());
164 protected void setAccount(Account account
, boolean savedAccount
) {
165 if (somethingToUpload()) {
166 mAccountManager
= (AccountManager
) getSystemService(Context
.ACCOUNT_SERVICE
);
167 Account
[] accounts
= mAccountManager
.getAccountsByType(MainApp
.getAccountType());
168 if (accounts
.length
== 0) {
169 Log_OC
.i(TAG
, "No ownCloud account is available");
170 showDialog(DIALOG_NO_ACCOUNT
);
171 } else if (accounts
.length
> 1 && !mAccountSelected
&& !mAccountSelectionShowing
) {
172 Log_OC
.i(TAG
, "More than one ownCloud is available");
173 showDialog(DIALOG_MULTIPLE_ACCOUNT
);
174 mAccountSelectionShowing
= true
;
177 setAccount(accounts
[0]);
182 showDialog(DIALOG_NO_STREAM
);
185 super.setAccount(account
, savedAccount
);
189 protected void onAccountSet(boolean stateWasRecovered
) {
190 super.onAccountSet(mAccountWasRestored
);
192 populateDirectoryList();
196 protected void onSaveInstanceState(Bundle outState
) {
197 Log_OC
.d(TAG
, "onSaveInstanceState() start");
198 super.onSaveInstanceState(outState
);
199 outState
.putSerializable(KEY_PARENTS
, mParents
);
200 //outState.putParcelable(KEY_ACCOUNT, mAccount);
201 outState
.putParcelable(KEY_FILE
, mFile
);
202 outState
.putBoolean(KEY_ACCOUNT_SELECTED
, mAccountSelected
);
203 outState
.putBoolean(KEY_ACCOUNT_SELECTION_SHOWING
, mAccountSelectionShowing
);
204 outState
.putInt(KEY_NUM_CACHE_FILE
, mNumCacheFile
);
205 outState
.putStringArrayList(KEY_REMOTE_CACHE_DATA
, mRemoteCacheData
);
206 outState
.putParcelable(FileActivity
.EXTRA_ACCOUNT
, getAccount());
208 Log_OC
.d(TAG
, "onSaveInstanceState() end");
212 protected Dialog
onCreateDialog(final int id
) {
213 final AlertDialog
.Builder builder
= new Builder(this);
216 ProgressDialog pDialog
= new ProgressDialog(this);
217 pDialog
.setIndeterminate(false
);
218 pDialog
.setCancelable(false
);
219 pDialog
.setMessage(getResources().getString(R
.string
.uploader_info_uploading
));
221 case DIALOG_NO_ACCOUNT
:
222 builder
.setIcon(android
.R
.drawable
.ic_dialog_alert
);
223 builder
.setTitle(R
.string
.uploader_wrn_no_account_title
);
224 builder
.setMessage(String
.format(
225 getString(R
.string
.uploader_wrn_no_account_text
), getString(R
.string
.app_name
)));
226 builder
.setCancelable(false
);
227 builder
.setPositiveButton(R
.string
.uploader_wrn_no_account_setup_btn_text
, new OnClickListener() {
229 public void onClick(DialogInterface dialog
, int which
) {
230 if (android
.os
.Build
.VERSION
.SDK_INT
> android
.os
.Build
.VERSION_CODES
.ECLAIR_MR1
) {
231 // using string value since in API7 this
232 // constatn is not defined
233 // in API7 < this constatant is defined in
234 // Settings.ADD_ACCOUNT_SETTINGS
235 // and Settings.EXTRA_AUTHORITIES
236 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
237 intent
.putExtra("authorities", new String
[] { MainApp
.getAuthTokenType() });
238 startActivityForResult(intent
, REQUEST_CODE_SETUP_ACCOUNT
);
240 // since in API7 there is no direct call for
241 // account setup, so we need to
242 // show our own AccountSetupAcricity, get
243 // desired results and setup
244 // everything for ourself
245 Intent intent
= new Intent(getBaseContext(), AccountAuthenticator
.class);
246 startActivityForResult(intent
, REQUEST_CODE_SETUP_ACCOUNT
);
250 builder
.setNegativeButton(R
.string
.uploader_wrn_no_account_quit_btn_text
, new OnClickListener() {
252 public void onClick(DialogInterface dialog
, int which
) {
256 return builder
.create();
257 case DIALOG_MULTIPLE_ACCOUNT
:
258 CharSequence ac
[] = new CharSequence
[
259 mAccountManager
.getAccountsByType(MainApp
.getAccountType()).length
];
260 for (int i
= 0; i
< ac
.length
; ++i
) {
261 ac
[i
] = DisplayUtils
.convertIdn(
262 mAccountManager
.getAccountsByType(MainApp
.getAccountType())[i
].name
, false
);
264 builder
.setTitle(R
.string
.common_choose_account
);
265 builder
.setItems(ac
, new OnClickListener() {
267 public void onClick(DialogInterface dialog
, int which
) {
268 setAccount(mAccountManager
.getAccountsByType(MainApp
.getAccountType())[which
]);
269 onAccountSet(mAccountWasRestored
);
271 mAccountSelected
= true
;
272 mAccountSelectionShowing
= false
;
275 builder
.setCancelable(true
);
276 builder
.setOnCancelListener(new OnCancelListener() {
278 public void onCancel(DialogInterface dialog
) {
279 mAccountSelectionShowing
= false
;
284 return builder
.create();
285 case DIALOG_NO_STREAM
:
286 builder
.setIcon(android
.R
.drawable
.ic_dialog_alert
);
287 builder
.setTitle(R
.string
.uploader_wrn_no_content_title
);
288 builder
.setMessage(R
.string
.uploader_wrn_no_content_text
);
289 builder
.setCancelable(false
);
290 builder
.setNegativeButton(R
.string
.common_cancel
, new OnClickListener() {
292 public void onClick(DialogInterface dialog
, int which
) {
296 return builder
.create();
298 throw new IllegalArgumentException("Unknown dialog id: " + id
);
302 class a
implements OnClickListener
{
306 public a(String path
, EditText dirname
) {
312 public void onClick(DialogInterface dialog
, int which
) {
313 Uploader
.this.mUploadPath
= mPath
+ mDirname
.getText().toString();
314 Uploader
.this.mCreateDir
= true
;
320 public void onBackPressed() {
322 if (mParents
.size() <= 1) {
323 super.onBackPressed();
327 populateDirectoryList();
332 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
333 // click on folder in the list
334 Log_OC
.d(TAG
, "on item click");
335 // TODO Enable when "On Device" is recovered ?
336 Vector
<OCFile
> tmpfiles
= getStorageManager().getFolderContent(mFile
/*, false*/);
337 if (tmpfiles
.size() <= 0) return;
339 Vector
<OCFile
> files
= new Vector
<OCFile
>();
340 for (OCFile f
: tmpfiles
)
343 if (files
.size() < position
) {
344 throw new IndexOutOfBoundsException("Incorrect item selected");
346 mParents
.push(files
.get(position
).getFileName());
347 populateDirectoryList();
351 public void onClick(View v
) {
354 case R
.id
.uploader_choose_folder
:
355 mUploadPath
= ""; // first element in mParents is root dir, represented by "";
356 // init mUploadPath with "/" results in a "//" prefix
357 for (String p
: mParents
)
358 mUploadPath
+= p
+ OCFile
.PATH_SEPARATOR
;
359 Log_OC
.d(TAG
, "Uploading file to dir " + mUploadPath
);
365 case R
.id
.uploader_new_folder
:
366 CreateFolderDialogFragment dialog
= CreateFolderDialogFragment
.newInstance(mFile
);
367 dialog
.show(getSupportFragmentManager(), "createdirdialog");
372 throw new IllegalArgumentException("Wrong element clicked");
377 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
378 super.onActivityResult(requestCode
, resultCode
, data
);
379 Log_OC
.i(TAG
, "result received. req: " + requestCode
+ " res: " + resultCode
);
380 if (requestCode
== REQUEST_CODE_SETUP_ACCOUNT
) {
381 dismissDialog(DIALOG_NO_ACCOUNT
);
382 if (resultCode
== RESULT_CANCELED
) {
385 Account
[] accounts
= mAccountManager
.getAccountsByType(MainApp
.getAuthTokenType());
386 if (accounts
.length
== 0) {
387 showDialog(DIALOG_NO_ACCOUNT
);
389 // there is no need for checking for is there more then one
390 // account at this point
391 // since account setup can set only one account at time
392 setAccount(accounts
[0]);
393 populateDirectoryList();
398 private void populateDirectoryList() {
399 setContentView(R
.layout
.uploader_layout
);
401 ListView mListView
= (ListView
) findViewById(android
.R
.id
.list
);
403 String current_dir
= mParents
.peek();
404 if(current_dir
.equals("")){
405 getSupportActionBar().setTitle(getString(R
.string
.default_display_name_for_root_folder
));
408 getSupportActionBar().setTitle(current_dir
);
410 boolean notRoot
= (mParents
.size() > 1);
411 ActionBar actionBar
= getSupportActionBar();
412 actionBar
.setDisplayHomeAsUpEnabled(notRoot
);
413 actionBar
.setHomeButtonEnabled(notRoot
);
415 String full_path
= generatePath(mParents
);
417 Log_OC
.d(TAG
, "Populating view with content of : " + full_path
);
419 mFile
= getStorageManager().getFileByPath(full_path
);
421 // TODO Enable when "On Device" is recovered ?
422 Vector
<OCFile
> files
= getStorageManager().getFolderContent(mFile
/*, false*/);
423 List
<HashMap
<String
, Object
>> data
= new LinkedList
<HashMap
<String
,Object
>>();
424 for (OCFile f
: files
) {
425 HashMap
<String
, Object
> h
= new HashMap
<String
, Object
>();
427 h
.put("dirname", f
.getFileName());
431 SimpleAdapter sa
= new SimpleAdapter(this,
433 R
.layout
.uploader_list_item_layout
,
434 new String
[] {"dirname"},
435 new int[] {R
.id
.textView1
});
437 mListView
.setAdapter(sa
);
438 Button btnChooseFolder
= (Button
) findViewById(R
.id
.uploader_choose_folder
);
439 btnChooseFolder
.setOnClickListener(this);
441 Button btnNewFolder
= (Button
) findViewById(R
.id
.uploader_new_folder
);
442 btnNewFolder
.setOnClickListener(this);
444 mListView
.setOnItemClickListener(this);
448 private String
generatePath(Stack
<String
> dirs
) {
449 String full_path
= "";
451 for (String a
: dirs
)
452 full_path
+= a
+ "/";
456 private void prepareStreamsToUpload() {
457 if (getIntent().getAction().equals(Intent
.ACTION_SEND
)) {
458 mStreamsToUpload
= new ArrayList
<Parcelable
>();
459 mStreamsToUpload
.add(getIntent().getParcelableExtra(Intent
.EXTRA_STREAM
));
460 } else if (getIntent().getAction().equals(Intent
.ACTION_SEND_MULTIPLE
)) {
461 mStreamsToUpload
= getIntent().getParcelableArrayListExtra(Intent
.EXTRA_STREAM
);
465 private boolean somethingToUpload() {
466 return (mStreamsToUpload
!= null
&& mStreamsToUpload
.get(0) != null
);
469 public void uploadFiles() {
472 // ArrayList for files with path in external storage
473 ArrayList
<String
> local
= new ArrayList
<String
>();
474 ArrayList
<String
> remote
= new ArrayList
<String
>();
476 // this checks the mimeType
477 for (Parcelable mStream
: mStreamsToUpload
) {
479 Uri uri
= (Uri
) mStream
;
481 String filePath
= "";
484 if (uri
.getScheme().equals("content")) {
485 String mimeType
= getContentResolver().getType(uri
);
487 if (mimeType
.contains("image")) {
488 String
[] CONTENT_PROJECTION
= { Images
.Media
.DATA
,
489 Images
.Media
.DISPLAY_NAME
, Images
.Media
.MIME_TYPE
,
491 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
494 int index
= c
.getColumnIndex(Images
.Media
.DATA
);
495 data
= c
.getString(index
);
496 filePath
= mUploadPath
+
497 c
.getString(c
.getColumnIndex(Images
.Media
.DISPLAY_NAME
));
499 } else if (mimeType
.contains("video")) {
500 String
[] CONTENT_PROJECTION
= { Video
.Media
.DATA
,
501 Video
.Media
.DISPLAY_NAME
, Video
.Media
.MIME_TYPE
,
502 Video
.Media
.SIZE
, Video
.Media
.DATE_MODIFIED
};
503 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
506 int index
= c
.getColumnIndex(Video
.Media
.DATA
);
507 data
= c
.getString(index
);
508 filePath
= mUploadPath
+
509 c
.getString(c
.getColumnIndex(Video
.Media
.DISPLAY_NAME
));
511 } else if (mimeType
.contains("audio")) {
512 String
[] CONTENT_PROJECTION
= { Audio
.Media
.DATA
,
513 Audio
.Media
.DISPLAY_NAME
, Audio
.Media
.MIME_TYPE
,
515 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
518 int index
= c
.getColumnIndex(Audio
.Media
.DATA
);
519 data
= c
.getString(index
);
520 filePath
= mUploadPath
+
521 c
.getString(c
.getColumnIndex(Audio
.Media
.DISPLAY_NAME
));
524 Cursor cursor
= getContentResolver().query(uri
,
525 new String
[]{MediaStore
.MediaColumns
.DISPLAY_NAME
},
527 cursor
.moveToFirst();
528 int nameIndex
= cursor
.getColumnIndex(cursor
.getColumnNames()[0]);
529 if (nameIndex
>= 0) {
530 filePath
= mUploadPath
+ cursor
.getString(nameIndex
);
534 } else if (uri
.getScheme().equals("file")) {
535 filePath
= Uri
.decode(uri
.toString()).replace(uri
.getScheme() +
537 if (filePath
.contains("mnt")) {
538 String splitedFilePath
[] = filePath
.split("/mnt");
539 filePath
= splitedFilePath
[1];
541 final File file
= new File(filePath
);
542 data
= file
.getAbsolutePath();
543 filePath
= mUploadPath
+ file
.getName();
546 throw new SecurityException();
549 mRemoteCacheData
.add(filePath
);
550 CopyTmpFileAsyncTask copyTask
= new CopyTmpFileAsyncTask(this);
551 Object
[] params
= { uri
, filePath
, mRemoteCacheData
.size()-1,
552 getAccount().name
, getContentResolver()};
554 showWaitingCopyDialog();
555 copyTask
.execute(params
);
557 remote
.add(filePath
);
562 throw new SecurityException();
565 Intent intent
= new Intent(getApplicationContext(), FileUploader
.class);
566 intent
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
567 intent
.putExtra(FileUploader
.KEY_LOCAL_FILE
, local
.toArray(new String
[local
.size()]));
568 intent
.putExtra(FileUploader
.KEY_REMOTE_FILE
,
569 remote
.toArray(new String
[remote
.size()]));
570 intent
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
571 startService(intent
);
573 //Save the path to shared preferences
574 SharedPreferences
.Editor appPrefs
= PreferenceManager
575 .getDefaultSharedPreferences(getApplicationContext()).edit();
576 appPrefs
.putString("last_upload_path", mUploadPath
);
582 } catch (SecurityException e
) {
583 String message
= String
.format(getString(R
.string
.uploader_error_forbidden_content
),
584 getString(R
.string
.app_name
));
585 Toast
.makeText(this, message
, Toast
.LENGTH_LONG
).show();
590 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
591 super.onRemoteOperationFinish(operation
, result
);
594 if (operation
instanceof CreateFolderOperation
) {
595 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
601 * Updates the view associated to the activity after the finish of an operation
602 * trying create a new folder
604 * @param operation Creation operation performed.
605 * @param result Result of the creation.
607 private void onCreateFolderOperationFinish(CreateFolderOperation operation
,
608 RemoteOperationResult result
) {
609 if (result
.isSuccess()) {
610 dismissLoadingDialog();
611 populateDirectoryList();
613 dismissLoadingDialog();
615 Toast msg
= Toast
.makeText(this,
616 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
620 } catch (NotFoundException e
) {
621 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
628 * Loads the target folder initialize shown to the user.
630 * The target account has to be chosen before this method is called.
632 private void initTargetFolder() {
633 if (getStorageManager() == null
) {
634 throw new IllegalStateException("Do not call this method before " +
635 "initializing mStorageManager");
638 SharedPreferences appPreferences
= PreferenceManager
639 .getDefaultSharedPreferences(getApplicationContext());
641 String last_path
= appPreferences
.getString("last_upload_path", "");
642 // "/" equals root-directory
643 if(last_path
.equals("/")) {
646 String
[] dir_names
= last_path
.split("/");
647 for (String dir
: dir_names
)
650 //Make sure that path still exists, if it doesn't pop the stack and try the previous path
651 while(!getStorageManager().fileExists(generatePath(mParents
)) && mParents
.size() > 1){
658 public boolean onOptionsItemSelected(MenuItem item
) {
659 boolean retval
= true
;
660 switch (item
.getItemId()) {
661 case android
.R
.id
.home
:
662 if((mParents
.size() > 1)) {
668 retval
= super.onOptionsItemSelected(item
);
675 * Process the result of CopyTmpFileAsyncTask
680 public void onTmpFileCopied(String result
, int index
) {
681 if (mNumCacheFile
-- == 0) {
682 dismissWaitingCopyDialog();
684 if (result
!= null
) {
685 Intent intent
= new Intent(getApplicationContext(), FileUploader
.class);
686 intent
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
687 intent
.putExtra(FileUploader
.KEY_LOCAL_FILE
, result
);
688 intent
.putExtra(FileUploader
.KEY_REMOTE_FILE
, mRemoteCacheData
.get(index
));
689 intent
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
690 startService(intent
);
693 String message
= String
.format(getString(R
.string
.uploader_error_forbidden_content
),
694 getString(R
.string
.app_name
));
695 Toast
.makeText(this, message
, Toast
.LENGTH_LONG
).show();
696 Log_OC
.d(TAG
, message
);
701 * Show waiting for copy dialog
703 public void showWaitingCopyDialog() {
705 LoadingDialog loading
= new LoadingDialog(
706 getResources().getString(R
.string
.wait_for_tmp_copy_from_private_storage
));
707 FragmentManager fm
= getSupportFragmentManager();
708 FragmentTransaction ft
= fm
.beginTransaction();
709 loading
.show(ft
, DIALOG_WAIT_COPY_FILE
);
715 * Dismiss waiting for copy dialog
717 public void dismissWaitingCopyDialog(){
718 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_COPY_FILE
);
720 LoadingDialog loading
= (LoadingDialog
) frag
;