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
.support
.v7
.app
.AlertDialog
;
37 import android
.support
.v7
.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
.support
.v7
.app
.ActionBar
;
60 import android
.view
.MenuItem
;
61 import android
.view
.View
;
62 import android
.widget
.AdapterView
;
63 import android
.widget
.AdapterView
.OnItemClickListener
;
64 import android
.widget
.Button
;
65 import android
.widget
.EditText
;
66 import android
.widget
.ListView
;
67 import android
.widget
.ProgressBar
;
68 import android
.widget
.SimpleAdapter
;
69 import android
.widget
.Toast
;
71 import com
.owncloud
.android
.MainApp
;
72 import com
.owncloud
.android
.R
;
73 import com
.owncloud
.android
.authentication
.AccountAuthenticator
;
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
.lib
.common
.operations
.RemoteOperation
;
78 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
79 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
80 import com
.owncloud
.android
.ui
.dialog
.CreateFolderDialogFragment
;
81 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
82 import com
.owncloud
.android
.utils
.CopyTmpFileAsyncTask
;
83 import com
.owncloud
.android
.utils
.DisplayUtils
;
84 import com
.owncloud
.android
.utils
.ErrorMessageAdapter
;
88 * This can be used to upload things to an ownCloud instance.
90 public class Uploader
extends FileActivity
91 implements OnItemClickListener
, android
.view
.View
.OnClickListener
,
92 CopyTmpFileAsyncTask
.OnCopyTmpFileTaskListener
{
94 private static final String TAG
= Uploader
.class.getSimpleName();
96 private AccountManager mAccountManager
;
97 private Stack
<String
> mParents
;
98 private ArrayList
<Parcelable
> mStreamsToUpload
;
99 private boolean mCreateDir
;
100 private String mUploadPath
;
101 private OCFile mFile
;
102 private boolean mAccountSelected
;
103 private boolean mAccountSelectionShowing
;
105 private ArrayList
<String
> mRemoteCacheData
;
106 private int mNumCacheFile
;
108 private final static int DIALOG_NO_ACCOUNT
= 0;
109 private final static int DIALOG_WAITING
= 1;
110 private final static int DIALOG_NO_STREAM
= 2;
111 private final static int DIALOG_MULTIPLE_ACCOUNT
= 3;
113 private final static int REQUEST_CODE_SETUP_ACCOUNT
= 0;
115 private final static String KEY_PARENTS
= "PARENTS";
116 private final static String KEY_FILE
= "FILE";
117 private final static String KEY_ACCOUNT_SELECTED
= "ACCOUNT_SELECTED";
118 private final static String KEY_ACCOUNT_SELECTION_SHOWING
= "ACCOUNT_SELECTION_SHOWING";
119 private final static String KEY_NUM_CACHE_FILE
= "NUM_CACHE_FILE";
120 private final static String KEY_REMOTE_CACHE_DATA
= "REMOTE_CACHE_DATA";
122 private static final String DIALOG_WAIT_COPY_FILE
= "DIALOG_WAIT_COPY_FILE";
125 protected void onCreate(Bundle savedInstanceState
) {
126 prepareStreamsToUpload();
128 if (savedInstanceState
== null
) {
129 mParents
= new Stack
<String
>();
130 mAccountSelected
= false
;
131 mAccountSelectionShowing
= false
;
134 // ArrayList for files with path in private storage
135 mRemoteCacheData
= new ArrayList
<String
>();
137 mParents
= (Stack
<String
>) savedInstanceState
.getSerializable(KEY_PARENTS
);
138 mFile
= savedInstanceState
.getParcelable(KEY_FILE
);
139 mAccountSelected
= savedInstanceState
.getBoolean(KEY_ACCOUNT_SELECTED
);
140 mAccountSelectionShowing
= savedInstanceState
.getBoolean(KEY_ACCOUNT_SELECTION_SHOWING
);
141 mNumCacheFile
= savedInstanceState
.getInt(KEY_NUM_CACHE_FILE
);
142 mRemoteCacheData
= savedInstanceState
.getStringArrayList(KEY_REMOTE_CACHE_DATA
);
145 super.onCreate(savedInstanceState
);
147 if (mAccountSelected
) {
148 setAccount((Account
) savedInstanceState
.getParcelable(FileActivity
.EXTRA_ACCOUNT
));
153 protected void setAccount(Account account
, boolean savedAccount
) {
154 if (somethingToUpload()) {
155 mAccountManager
= (AccountManager
) getSystemService(Context
.ACCOUNT_SERVICE
);
156 Account
[] accounts
= mAccountManager
.getAccountsByType(MainApp
.getAccountType());
157 if (accounts
.length
== 0) {
158 Log_OC
.i(TAG
, "No ownCloud account is available");
159 showDialog(DIALOG_NO_ACCOUNT
);
160 } else if (accounts
.length
> 1 && !mAccountSelected
&& !mAccountSelectionShowing
) {
161 Log_OC
.i(TAG
, "More than one ownCloud is available");
162 showDialog(DIALOG_MULTIPLE_ACCOUNT
);
163 mAccountSelectionShowing
= true
;
166 setAccount(accounts
[0]);
171 showDialog(DIALOG_NO_STREAM
);
174 super.setAccount(account
, savedAccount
);
178 protected void onAccountSet(boolean stateWasRecovered
) {
179 super.onAccountSet(mAccountWasRestored
);
181 populateDirectoryList();
185 protected void onSaveInstanceState(Bundle outState
) {
186 Log_OC
.d(TAG
, "onSaveInstanceState() start");
187 super.onSaveInstanceState(outState
);
188 outState
.putSerializable(KEY_PARENTS
, mParents
);
189 //outState.putParcelable(KEY_ACCOUNT, mAccount);
190 outState
.putParcelable(KEY_FILE
, mFile
);
191 outState
.putBoolean(KEY_ACCOUNT_SELECTED
, mAccountSelected
);
192 outState
.putBoolean(KEY_ACCOUNT_SELECTION_SHOWING
, mAccountSelectionShowing
);
193 outState
.putInt(KEY_NUM_CACHE_FILE
, mNumCacheFile
);
194 outState
.putStringArrayList(KEY_REMOTE_CACHE_DATA
, mRemoteCacheData
);
195 outState
.putParcelable(FileActivity
.EXTRA_ACCOUNT
, getAccount());
197 Log_OC
.d(TAG
, "onSaveInstanceState() end");
201 protected Dialog
onCreateDialog(final int id
) {
202 final AlertDialog
.Builder builder
= new Builder(this);
205 final ProgressDialog pDialog
= new ProgressDialog(this, R
.style
.ProgressDialogTheme
);
206 pDialog
.setIndeterminate(false
);
207 pDialog
.setCancelable(false
);
208 pDialog
.setMessage(getResources().getString(R
.string
.uploader_info_uploading
));
209 pDialog
.setOnShowListener(new DialogInterface
.OnShowListener() {
211 public void onShow(DialogInterface dialog
) {
212 ProgressBar v
= (ProgressBar
) pDialog
.findViewById(android
.R
.id
.progress
);
213 v
.getIndeterminateDrawable().setColorFilter(getResources().getColor(R
.color
.color_accent
),
214 android
.graphics
.PorterDuff
.Mode
.MULTIPLY
);
219 case DIALOG_NO_ACCOUNT
:
220 builder
.setIcon(android
.R
.drawable
.ic_dialog_alert
);
221 builder
.setTitle(R
.string
.uploader_wrn_no_account_title
);
222 builder
.setMessage(String
.format(
223 getString(R
.string
.uploader_wrn_no_account_text
), getString(R
.string
.app_name
)));
224 builder
.setCancelable(false
);
225 builder
.setPositiveButton(R
.string
.uploader_wrn_no_account_setup_btn_text
, new OnClickListener() {
227 public void onClick(DialogInterface dialog
, int which
) {
228 if (android
.os
.Build
.VERSION
.SDK_INT
>
229 android
.os
.Build
.VERSION_CODES
.ECLAIR_MR1
) {
230 // using string value since in API7 this
231 // constatn is not defined
232 // in API7 < this constatant is defined in
233 // Settings.ADD_ACCOUNT_SETTINGS
234 // and Settings.EXTRA_AUTHORITIES
235 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
236 intent
.putExtra("authorities", new String
[] { MainApp
.getAuthTokenType() });
237 startActivityForResult(intent
, REQUEST_CODE_SETUP_ACCOUNT
);
239 // since in API7 there is no direct call for
240 // account setup, so we need to
241 // show our own AccountSetupAcricity, get
242 // desired results and setup
243 // everything for ourself
244 Intent intent
= new Intent(getBaseContext(), AccountAuthenticator
.class);
245 startActivityForResult(intent
, REQUEST_CODE_SETUP_ACCOUNT
);
249 builder
.setNegativeButton(R
.string
.uploader_wrn_no_account_quit_btn_text
, new OnClickListener() {
251 public void onClick(DialogInterface dialog
, int which
) {
255 return builder
.create();
256 case DIALOG_MULTIPLE_ACCOUNT
:
257 CharSequence ac
[] = new CharSequence
[
258 mAccountManager
.getAccountsByType(MainApp
.getAccountType()).length
];
259 for (int i
= 0; i
< ac
.length
; ++i
) {
260 ac
[i
] = DisplayUtils
.convertIdn(
261 mAccountManager
.getAccountsByType(MainApp
.getAccountType())[i
].name
, false
);
263 builder
.setTitle(R
.string
.common_choose_account
);
264 builder
.setItems(ac
, new OnClickListener() {
266 public void onClick(DialogInterface dialog
, int which
) {
267 setAccount(mAccountManager
.getAccountsByType(MainApp
.getAccountType())[which
]);
268 onAccountSet(mAccountWasRestored
);
270 mAccountSelected
= true
;
271 mAccountSelectionShowing
= false
;
274 builder
.setCancelable(true
);
275 builder
.setOnCancelListener(new OnCancelListener() {
277 public void onCancel(DialogInterface dialog
) {
278 mAccountSelectionShowing
= false
;
283 return builder
.create();
284 case DIALOG_NO_STREAM
:
285 builder
.setIcon(android
.R
.drawable
.ic_dialog_alert
);
286 builder
.setTitle(R
.string
.uploader_wrn_no_content_title
);
287 builder
.setMessage(R
.string
.uploader_wrn_no_content_text
);
288 builder
.setCancelable(false
);
289 builder
.setNegativeButton(R
.string
.common_cancel
, new OnClickListener() {
291 public void onClick(DialogInterface dialog
, int which
) {
295 return builder
.create();
297 throw new IllegalArgumentException("Unknown dialog id: " + id
);
301 class a
implements OnClickListener
{
305 public a(String path
, EditText dirname
) {
311 public void onClick(DialogInterface dialog
, int which
) {
312 Uploader
.this.mUploadPath
= mPath
+ mDirname
.getText().toString();
313 Uploader
.this.mCreateDir
= true
;
319 public void onBackPressed() {
321 if (mParents
.size() <= 1) {
322 super.onBackPressed();
326 populateDirectoryList();
331 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
332 // click on folder in the list
333 Log_OC
.d(TAG
, "on item click");
334 // TODO Enable when "On Device" is recovered ?
335 Vector
<OCFile
> tmpfiles
= getStorageManager().getFolderContent(mFile
/*, false*/);
336 if (tmpfiles
.size() <= 0) return;
338 Vector
<OCFile
> files
= new Vector
<OCFile
>();
339 for (OCFile f
: tmpfiles
)
342 if (files
.size() < position
) {
343 throw new IndexOutOfBoundsException("Incorrect item selected");
345 mParents
.push(files
.get(position
).getFileName());
346 populateDirectoryList();
350 public void onClick(View v
) {
353 case R
.id
.uploader_choose_folder
:
354 mUploadPath
= ""; // first element in mParents is root dir, represented by "";
355 // init mUploadPath with "/" results in a "//" prefix
356 for (String p
: mParents
)
357 mUploadPath
+= p
+ OCFile
.PATH_SEPARATOR
;
358 Log_OC
.d(TAG
, "Uploading file to dir " + mUploadPath
);
364 case R
.id
.uploader_new_folder
:
365 CreateFolderDialogFragment dialog
= CreateFolderDialogFragment
.newInstance(mFile
);
366 dialog
.show(getSupportFragmentManager(), "createdirdialog");
371 throw new IllegalArgumentException("Wrong element clicked");
376 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
377 super.onActivityResult(requestCode
, resultCode
, data
);
378 Log_OC
.i(TAG
, "result received. req: " + requestCode
+ " res: " + resultCode
);
379 if (requestCode
== REQUEST_CODE_SETUP_ACCOUNT
) {
380 dismissDialog(DIALOG_NO_ACCOUNT
);
381 if (resultCode
== RESULT_CANCELED
) {
384 Account
[] accounts
= mAccountManager
.getAccountsByType(MainApp
.getAuthTokenType());
385 if (accounts
.length
== 0) {
386 showDialog(DIALOG_NO_ACCOUNT
);
388 // there is no need for checking for is there more then one
389 // account at this point
390 // since account setup can set only one account at time
391 setAccount(accounts
[0]);
392 populateDirectoryList();
397 private void populateDirectoryList() {
398 setContentView(R
.layout
.uploader_layout
);
400 ListView mListView
= (ListView
) findViewById(android
.R
.id
.list
);
402 String current_dir
= mParents
.peek();
403 if(current_dir
.equals("")){
404 getSupportActionBar().setTitle(getString(R
.string
.default_display_name_for_root_folder
));
407 getSupportActionBar().setTitle(current_dir
);
409 boolean notRoot
= (mParents
.size() > 1);
410 ActionBar actionBar
= getSupportActionBar();
411 actionBar
.setDisplayHomeAsUpEnabled(notRoot
);
412 actionBar
.setHomeButtonEnabled(notRoot
);
414 String full_path
= generatePath(mParents
);
416 Log_OC
.d(TAG
, "Populating view with content of : " + full_path
);
418 mFile
= getStorageManager().getFileByPath(full_path
);
420 // TODO Enable when "On Device" is recovered ?
421 Vector
<OCFile
> files
= getStorageManager().getFolderContent(mFile
/*, false*/);
422 List
<HashMap
<String
, Object
>> data
= new LinkedList
<HashMap
<String
,Object
>>();
423 for (OCFile f
: files
) {
424 HashMap
<String
, Object
> h
= new HashMap
<String
, Object
>();
426 h
.put("dirname", f
.getFileName());
430 SimpleAdapter sa
= new SimpleAdapter(this,
432 R
.layout
.uploader_list_item_layout
,
433 new String
[] {"dirname"},
434 new int[] {R
.id
.filename
});
436 mListView
.setAdapter(sa
);
437 Button btnChooseFolder
= (Button
) findViewById(R
.id
.uploader_choose_folder
);
438 btnChooseFolder
.setOnClickListener(this);
440 Button btnNewFolder
= (Button
) findViewById(R
.id
.uploader_new_folder
);
441 btnNewFolder
.setOnClickListener(this);
443 mListView
.setOnItemClickListener(this);
447 private String
generatePath(Stack
<String
> dirs
) {
448 String full_path
= "";
450 for (String a
: dirs
)
451 full_path
+= a
+ "/";
455 private void prepareStreamsToUpload() {
456 if (getIntent().getAction().equals(Intent
.ACTION_SEND
)) {
457 mStreamsToUpload
= new ArrayList
<Parcelable
>();
458 mStreamsToUpload
.add(getIntent().getParcelableExtra(Intent
.EXTRA_STREAM
));
459 } else if (getIntent().getAction().equals(Intent
.ACTION_SEND_MULTIPLE
)) {
460 mStreamsToUpload
= getIntent().getParcelableArrayListExtra(Intent
.EXTRA_STREAM
);
464 private boolean somethingToUpload() {
465 return (mStreamsToUpload
!= null
&& mStreamsToUpload
.get(0) != null
);
468 public void uploadFiles() {
471 // ArrayList for files with path in external storage
472 ArrayList
<String
> local
= new ArrayList
<String
>();
473 ArrayList
<String
> remote
= new ArrayList
<String
>();
475 // this checks the mimeType
476 for (Parcelable mStream
: mStreamsToUpload
) {
478 Uri uri
= (Uri
) mStream
;
480 String filePath
= "";
483 if (uri
.getScheme().equals("content")) {
484 String mimeType
= getContentResolver().getType(uri
);
486 if (mimeType
.contains("image")) {
487 String
[] CONTENT_PROJECTION
= { Images
.Media
.DATA
,
488 Images
.Media
.DISPLAY_NAME
, Images
.Media
.MIME_TYPE
,
490 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
493 int index
= c
.getColumnIndex(Images
.Media
.DATA
);
494 data
= c
.getString(index
);
495 filePath
= mUploadPath
+
496 c
.getString(c
.getColumnIndex(Images
.Media
.DISPLAY_NAME
));
498 } else if (mimeType
.contains("video")) {
499 String
[] CONTENT_PROJECTION
= { Video
.Media
.DATA
,
500 Video
.Media
.DISPLAY_NAME
, Video
.Media
.MIME_TYPE
,
501 Video
.Media
.SIZE
, Video
.Media
.DATE_MODIFIED
};
502 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
505 int index
= c
.getColumnIndex(Video
.Media
.DATA
);
506 data
= c
.getString(index
);
507 filePath
= mUploadPath
+
508 c
.getString(c
.getColumnIndex(Video
.Media
.DISPLAY_NAME
));
510 } else if (mimeType
.contains("audio")) {
511 String
[] CONTENT_PROJECTION
= { Audio
.Media
.DATA
,
512 Audio
.Media
.DISPLAY_NAME
, Audio
.Media
.MIME_TYPE
,
514 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
517 int index
= c
.getColumnIndex(Audio
.Media
.DATA
);
518 data
= c
.getString(index
);
519 filePath
= mUploadPath
+
520 c
.getString(c
.getColumnIndex(Audio
.Media
.DISPLAY_NAME
));
523 Cursor cursor
= getContentResolver().query(uri
,
524 new String
[]{MediaStore
.MediaColumns
.DISPLAY_NAME
},
526 cursor
.moveToFirst();
527 int nameIndex
= cursor
.getColumnIndex(cursor
.getColumnNames()[0]);
528 if (nameIndex
>= 0) {
529 filePath
= mUploadPath
+ cursor
.getString(nameIndex
);
533 } else if (uri
.getScheme().equals("file")) {
534 filePath
= Uri
.decode(uri
.toString()).replace(uri
.getScheme() +
536 if (filePath
.contains("mnt")) {
537 String splitedFilePath
[] = filePath
.split("/mnt");
538 filePath
= splitedFilePath
[1];
540 final File file
= new File(filePath
);
541 data
= file
.getAbsolutePath();
542 filePath
= mUploadPath
+ file
.getName();
545 throw new SecurityException();
548 mRemoteCacheData
.add(filePath
);
549 CopyTmpFileAsyncTask copyTask
= new CopyTmpFileAsyncTask(this);
550 Object
[] params
= { uri
, filePath
, mRemoteCacheData
.size()-1,
551 getAccount().name
, getContentResolver()};
553 showWaitingCopyDialog();
554 copyTask
.execute(params
);
556 remote
.add(filePath
);
561 throw new SecurityException();
564 Intent intent
= new Intent(getApplicationContext(), FileUploader
.class);
565 intent
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
566 intent
.putExtra(FileUploader
.KEY_LOCAL_FILE
, local
.toArray(new String
[local
.size()]));
567 intent
.putExtra(FileUploader
.KEY_REMOTE_FILE
,
568 remote
.toArray(new String
[remote
.size()]));
569 intent
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
570 startService(intent
);
572 //Save the path to shared preferences
573 SharedPreferences
.Editor appPrefs
= PreferenceManager
574 .getDefaultSharedPreferences(getApplicationContext()).edit();
575 appPrefs
.putString("last_upload_path", mUploadPath
);
581 } catch (SecurityException e
) {
582 String message
= String
.format(getString(R
.string
.uploader_error_forbidden_content
),
583 getString(R
.string
.app_name
));
584 Toast
.makeText(this, message
, Toast
.LENGTH_LONG
).show();
589 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
590 super.onRemoteOperationFinish(operation
, result
);
593 if (operation
instanceof CreateFolderOperation
) {
594 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
600 * Updates the view associated to the activity after the finish of an operation
601 * trying create a new folder
603 * @param operation Creation operation performed.
604 * @param result Result of the creation.
606 private void onCreateFolderOperationFinish(CreateFolderOperation operation
,
607 RemoteOperationResult result
) {
608 if (result
.isSuccess()) {
609 dismissLoadingDialog();
610 populateDirectoryList();
612 dismissLoadingDialog();
614 Toast msg
= Toast
.makeText(this,
615 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
619 } catch (NotFoundException e
) {
620 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
627 * Loads the target folder initialize shown to the user.
629 * The target account has to be chosen before this method is called.
631 private void initTargetFolder() {
632 if (getStorageManager() == null
) {
633 throw new IllegalStateException("Do not call this method before " +
634 "initializing mStorageManager");
637 SharedPreferences appPreferences
= PreferenceManager
638 .getDefaultSharedPreferences(getApplicationContext());
640 String last_path
= appPreferences
.getString("last_upload_path", "");
641 // "/" equals root-directory
642 if(last_path
.equals("/")) {
645 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
;