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
.OCFile
;
74 import com
.owncloud
.android
.files
.services
.FileUploader
;
75 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
76 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
77 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
78 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
79 import com
.owncloud
.android
.ui
.dialog
.CreateFolderDialogFragment
;
80 import com
.owncloud
.android
.ui
.dialog
.LoadingDialog
;
81 import com
.owncloud
.android
.utils
.CopyTmpFileAsyncTask
;
82 import com
.owncloud
.android
.utils
.DisplayUtils
;
83 import com
.owncloud
.android
.utils
.ErrorMessageAdapter
;
87 * This can be used to upload things to an ownCloud instance.
89 public class Uploader
extends FileActivity
90 implements OnItemClickListener
, android
.view
.View
.OnClickListener
,
91 CopyTmpFileAsyncTask
.OnCopyTmpFileTaskListener
{
93 private static final String TAG
= Uploader
.class.getSimpleName();
95 private AccountManager mAccountManager
;
96 private Stack
<String
> mParents
;
97 private ArrayList
<Parcelable
> mStreamsToUpload
;
98 private boolean mCreateDir
;
99 private String mUploadPath
;
100 private OCFile mFile
;
101 private boolean mAccountSelected
;
102 private boolean mAccountSelectionShowing
;
104 private ArrayList
<String
> mRemoteCacheData
;
105 private int mNumCacheFile
;
107 private final static int DIALOG_NO_ACCOUNT
= 0;
108 private final static int DIALOG_WAITING
= 1;
109 private final static int DIALOG_NO_STREAM
= 2;
110 private final static int DIALOG_MULTIPLE_ACCOUNT
= 3;
112 private final static int REQUEST_CODE_SETUP_ACCOUNT
= 0;
114 private final static String KEY_PARENTS
= "PARENTS";
115 private final static String KEY_FILE
= "FILE";
116 private final static String KEY_ACCOUNT_SELECTED
= "ACCOUNT_SELECTED";
117 private final static String KEY_ACCOUNT_SELECTION_SHOWING
= "ACCOUNT_SELECTION_SHOWING";
118 private final static String KEY_NUM_CACHE_FILE
= "NUM_CACHE_FILE";
119 private final static String KEY_REMOTE_CACHE_DATA
= "REMOTE_CACHE_DATA";
121 private static final String DIALOG_WAIT_COPY_FILE
= "DIALOG_WAIT_COPY_FILE";
124 protected void onCreate(Bundle savedInstanceState
) {
125 prepareStreamsToUpload();
127 if (savedInstanceState
== null
) {
128 mParents
= new Stack
<String
>();
129 mAccountSelected
= false
;
130 mAccountSelectionShowing
= false
;
133 // ArrayList for files with path in private storage
134 mRemoteCacheData
= new ArrayList
<String
>();
136 mParents
= (Stack
<String
>) savedInstanceState
.getSerializable(KEY_PARENTS
);
137 mFile
= savedInstanceState
.getParcelable(KEY_FILE
);
138 mAccountSelected
= savedInstanceState
.getBoolean(KEY_ACCOUNT_SELECTED
);
139 mAccountSelectionShowing
= savedInstanceState
.getBoolean(KEY_ACCOUNT_SELECTION_SHOWING
);
140 mNumCacheFile
= savedInstanceState
.getInt(KEY_NUM_CACHE_FILE
);
141 mRemoteCacheData
= savedInstanceState
.getStringArrayList(KEY_REMOTE_CACHE_DATA
);
144 super.onCreate(savedInstanceState
);
146 if (mAccountSelected
) {
147 setAccount((Account
) savedInstanceState
.getParcelable(FileActivity
.EXTRA_ACCOUNT
));
151 ActionBar actionBar
= getSupportActionBar();
152 actionBar
.setIcon(DisplayUtils
.getSeasonalIconId());
157 protected void setAccount(Account account
, boolean savedAccount
) {
158 if (somethingToUpload()) {
159 mAccountManager
= (AccountManager
) getSystemService(Context
.ACCOUNT_SERVICE
);
160 Account
[] accounts
= mAccountManager
.getAccountsByType(MainApp
.getAccountType());
161 if (accounts
.length
== 0) {
162 Log_OC
.i(TAG
, "No ownCloud account is available");
163 showDialog(DIALOG_NO_ACCOUNT
);
164 } else if (accounts
.length
> 1 && !mAccountSelected
&& !mAccountSelectionShowing
) {
165 Log_OC
.i(TAG
, "More than one ownCloud is available");
166 showDialog(DIALOG_MULTIPLE_ACCOUNT
);
167 mAccountSelectionShowing
= true
;
170 setAccount(accounts
[0]);
175 showDialog(DIALOG_NO_STREAM
);
178 super.setAccount(account
, savedAccount
);
182 protected void onAccountSet(boolean stateWasRecovered
) {
183 super.onAccountSet(mAccountWasRestored
);
185 populateDirectoryList();
189 protected void onSaveInstanceState(Bundle outState
) {
190 Log_OC
.d(TAG
, "onSaveInstanceState() start");
191 super.onSaveInstanceState(outState
);
192 outState
.putSerializable(KEY_PARENTS
, mParents
);
193 //outState.putParcelable(KEY_ACCOUNT, mAccount);
194 outState
.putParcelable(KEY_FILE
, mFile
);
195 outState
.putBoolean(KEY_ACCOUNT_SELECTED
, mAccountSelected
);
196 outState
.putBoolean(KEY_ACCOUNT_SELECTION_SHOWING
, mAccountSelectionShowing
);
197 outState
.putInt(KEY_NUM_CACHE_FILE
, mNumCacheFile
);
198 outState
.putStringArrayList(KEY_REMOTE_CACHE_DATA
, mRemoteCacheData
);
199 outState
.putParcelable(FileActivity
.EXTRA_ACCOUNT
, getAccount());
201 Log_OC
.d(TAG
, "onSaveInstanceState() end");
205 protected Dialog
onCreateDialog(final int id
) {
206 final AlertDialog
.Builder builder
= new Builder(this);
209 ProgressDialog pDialog
= new ProgressDialog(this);
210 pDialog
.setIndeterminate(false
);
211 pDialog
.setCancelable(false
);
212 pDialog
.setMessage(getResources().getString(R
.string
.uploader_info_uploading
));
214 case DIALOG_NO_ACCOUNT
:
215 builder
.setIcon(android
.R
.drawable
.ic_dialog_alert
);
216 builder
.setTitle(R
.string
.uploader_wrn_no_account_title
);
217 builder
.setMessage(String
.format(
218 getString(R
.string
.uploader_wrn_no_account_text
), getString(R
.string
.app_name
)));
219 builder
.setCancelable(false
);
220 builder
.setPositiveButton(R
.string
.uploader_wrn_no_account_setup_btn_text
, new OnClickListener() {
222 public void onClick(DialogInterface dialog
, int which
) {
223 if (android
.os
.Build
.VERSION
.SDK_INT
> android
.os
.Build
.VERSION_CODES
.ECLAIR_MR1
) {
224 // using string value since in API7 this
225 // constatn is not defined
226 // in API7 < this constatant is defined in
227 // Settings.ADD_ACCOUNT_SETTINGS
228 // and Settings.EXTRA_AUTHORITIES
229 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
230 intent
.putExtra("authorities", new String
[] { MainApp
.getAuthTokenType() });
231 startActivityForResult(intent
, REQUEST_CODE_SETUP_ACCOUNT
);
233 // since in API7 there is no direct call for
234 // account setup, so we need to
235 // show our own AccountSetupAcricity, get
236 // desired results and setup
237 // everything for ourself
238 Intent intent
= new Intent(getBaseContext(), AccountAuthenticator
.class);
239 startActivityForResult(intent
, REQUEST_CODE_SETUP_ACCOUNT
);
243 builder
.setNegativeButton(R
.string
.uploader_wrn_no_account_quit_btn_text
, new OnClickListener() {
245 public void onClick(DialogInterface dialog
, int which
) {
249 return builder
.create();
250 case DIALOG_MULTIPLE_ACCOUNT
:
251 CharSequence ac
[] = new CharSequence
[
252 mAccountManager
.getAccountsByType(MainApp
.getAccountType()).length
];
253 for (int i
= 0; i
< ac
.length
; ++i
) {
254 ac
[i
] = DisplayUtils
.convertIdn(
255 mAccountManager
.getAccountsByType(MainApp
.getAccountType())[i
].name
, false
);
257 builder
.setTitle(R
.string
.common_choose_account
);
258 builder
.setItems(ac
, new OnClickListener() {
260 public void onClick(DialogInterface dialog
, int which
) {
261 setAccount(mAccountManager
.getAccountsByType(MainApp
.getAccountType())[which
]);
262 onAccountSet(mAccountWasRestored
);
264 mAccountSelected
= true
;
265 mAccountSelectionShowing
= false
;
268 builder
.setCancelable(true
);
269 builder
.setOnCancelListener(new OnCancelListener() {
271 public void onCancel(DialogInterface dialog
) {
272 mAccountSelectionShowing
= false
;
277 return builder
.create();
278 case DIALOG_NO_STREAM
:
279 builder
.setIcon(android
.R
.drawable
.ic_dialog_alert
);
280 builder
.setTitle(R
.string
.uploader_wrn_no_content_title
);
281 builder
.setMessage(R
.string
.uploader_wrn_no_content_text
);
282 builder
.setCancelable(false
);
283 builder
.setNegativeButton(R
.string
.common_cancel
, new OnClickListener() {
285 public void onClick(DialogInterface dialog
, int which
) {
289 return builder
.create();
291 throw new IllegalArgumentException("Unknown dialog id: " + id
);
295 class a
implements OnClickListener
{
299 public a(String path
, EditText dirname
) {
305 public void onClick(DialogInterface dialog
, int which
) {
306 Uploader
.this.mUploadPath
= mPath
+ mDirname
.getText().toString();
307 Uploader
.this.mCreateDir
= true
;
313 public void onBackPressed() {
315 if (mParents
.size() <= 1) {
316 super.onBackPressed();
320 populateDirectoryList();
325 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
326 // click on folder in the list
327 Log_OC
.d(TAG
, "on item click");
328 // TODO Enable when "On Device" is recovered ?
329 Vector
<OCFile
> tmpfiles
= getStorageManager().getFolderContent(mFile
/*, false*/);
330 if (tmpfiles
.size() <= 0) return;
332 Vector
<OCFile
> files
= new Vector
<OCFile
>();
333 for (OCFile f
: tmpfiles
)
336 if (files
.size() < position
) {
337 throw new IndexOutOfBoundsException("Incorrect item selected");
339 mParents
.push(files
.get(position
).getFileName());
340 populateDirectoryList();
344 public void onClick(View v
) {
347 case R
.id
.uploader_choose_folder
:
348 mUploadPath
= ""; // first element in mParents is root dir, represented by "";
349 // init mUploadPath with "/" results in a "//" prefix
350 for (String p
: mParents
)
351 mUploadPath
+= p
+ OCFile
.PATH_SEPARATOR
;
352 Log_OC
.d(TAG
, "Uploading file to dir " + mUploadPath
);
358 case R
.id
.uploader_new_folder
:
359 CreateFolderDialogFragment dialog
= CreateFolderDialogFragment
.newInstance(mFile
);
360 dialog
.show(getSupportFragmentManager(), "createdirdialog");
365 throw new IllegalArgumentException("Wrong element clicked");
370 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
371 super.onActivityResult(requestCode
, resultCode
, data
);
372 Log_OC
.i(TAG
, "result received. req: " + requestCode
+ " res: " + resultCode
);
373 if (requestCode
== REQUEST_CODE_SETUP_ACCOUNT
) {
374 dismissDialog(DIALOG_NO_ACCOUNT
);
375 if (resultCode
== RESULT_CANCELED
) {
378 Account
[] accounts
= mAccountManager
.getAccountsByType(MainApp
.getAuthTokenType());
379 if (accounts
.length
== 0) {
380 showDialog(DIALOG_NO_ACCOUNT
);
382 // there is no need for checking for is there more then one
383 // account at this point
384 // since account setup can set only one account at time
385 setAccount(accounts
[0]);
386 populateDirectoryList();
391 private void populateDirectoryList() {
392 setContentView(R
.layout
.uploader_layout
);
394 ListView mListView
= (ListView
) findViewById(android
.R
.id
.list
);
396 String current_dir
= mParents
.peek();
397 if(current_dir
.equals("")){
398 getSupportActionBar().setTitle(getString(R
.string
.default_display_name_for_root_folder
));
401 getSupportActionBar().setTitle(current_dir
);
403 boolean notRoot
= (mParents
.size() > 1);
404 ActionBar actionBar
= getSupportActionBar();
405 actionBar
.setDisplayHomeAsUpEnabled(notRoot
);
406 actionBar
.setHomeButtonEnabled(notRoot
);
408 String full_path
= generatePath(mParents
);
410 Log_OC
.d(TAG
, "Populating view with content of : " + full_path
);
412 mFile
= getStorageManager().getFileByPath(full_path
);
414 // TODO Enable when "On Device" is recovered ?
415 Vector
<OCFile
> files
= getStorageManager().getFolderContent(mFile
/*, false*/);
416 List
<HashMap
<String
, Object
>> data
= new LinkedList
<HashMap
<String
,Object
>>();
417 for (OCFile f
: files
) {
418 HashMap
<String
, Object
> h
= new HashMap
<String
, Object
>();
420 h
.put("dirname", f
.getFileName());
424 SimpleAdapter sa
= new SimpleAdapter(this,
426 R
.layout
.uploader_list_item_layout
,
427 new String
[] {"dirname"},
428 new int[] {R
.id
.textView1
});
430 mListView
.setAdapter(sa
);
431 Button btnChooseFolder
= (Button
) findViewById(R
.id
.uploader_choose_folder
);
432 btnChooseFolder
.setOnClickListener(this);
434 Button btnNewFolder
= (Button
) findViewById(R
.id
.uploader_new_folder
);
435 btnNewFolder
.setOnClickListener(this);
437 mListView
.setOnItemClickListener(this);
441 private String
generatePath(Stack
<String
> dirs
) {
442 String full_path
= "";
444 for (String a
: dirs
)
445 full_path
+= a
+ "/";
449 private void prepareStreamsToUpload() {
450 if (getIntent().getAction().equals(Intent
.ACTION_SEND
)) {
451 mStreamsToUpload
= new ArrayList
<Parcelable
>();
452 mStreamsToUpload
.add(getIntent().getParcelableExtra(Intent
.EXTRA_STREAM
));
453 } else if (getIntent().getAction().equals(Intent
.ACTION_SEND_MULTIPLE
)) {
454 mStreamsToUpload
= getIntent().getParcelableArrayListExtra(Intent
.EXTRA_STREAM
);
458 private boolean somethingToUpload() {
459 return (mStreamsToUpload
!= null
&& mStreamsToUpload
.get(0) != null
);
462 public void uploadFiles() {
465 // ArrayList for files with path in external storage
466 ArrayList
<String
> local
= new ArrayList
<String
>();
467 ArrayList
<String
> remote
= new ArrayList
<String
>();
469 // this checks the mimeType
470 for (Parcelable mStream
: mStreamsToUpload
) {
472 Uri uri
= (Uri
) mStream
;
474 String filePath
= "";
477 if (uri
.getScheme().equals("content")) {
478 String mimeType
= getContentResolver().getType(uri
);
480 if (mimeType
.contains("image")) {
481 String
[] CONTENT_PROJECTION
= { Images
.Media
.DATA
,
482 Images
.Media
.DISPLAY_NAME
, Images
.Media
.MIME_TYPE
,
484 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
487 int index
= c
.getColumnIndex(Images
.Media
.DATA
);
488 data
= c
.getString(index
);
489 filePath
= mUploadPath
+
490 c
.getString(c
.getColumnIndex(Images
.Media
.DISPLAY_NAME
));
492 } else if (mimeType
.contains("video")) {
493 String
[] CONTENT_PROJECTION
= { Video
.Media
.DATA
,
494 Video
.Media
.DISPLAY_NAME
, Video
.Media
.MIME_TYPE
,
495 Video
.Media
.SIZE
, Video
.Media
.DATE_MODIFIED
};
496 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
499 int index
= c
.getColumnIndex(Video
.Media
.DATA
);
500 data
= c
.getString(index
);
501 filePath
= mUploadPath
+
502 c
.getString(c
.getColumnIndex(Video
.Media
.DISPLAY_NAME
));
504 } else if (mimeType
.contains("audio")) {
505 String
[] CONTENT_PROJECTION
= { Audio
.Media
.DATA
,
506 Audio
.Media
.DISPLAY_NAME
, Audio
.Media
.MIME_TYPE
,
508 Cursor c
= getContentResolver().query(uri
, CONTENT_PROJECTION
, null
,
511 int index
= c
.getColumnIndex(Audio
.Media
.DATA
);
512 data
= c
.getString(index
);
513 filePath
= mUploadPath
+
514 c
.getString(c
.getColumnIndex(Audio
.Media
.DISPLAY_NAME
));
517 Cursor cursor
= getContentResolver().query(uri
,
518 new String
[]{MediaStore
.MediaColumns
.DISPLAY_NAME
},
520 cursor
.moveToFirst();
521 int nameIndex
= cursor
.getColumnIndex(cursor
.getColumnNames()[0]);
522 if (nameIndex
>= 0) {
523 filePath
= mUploadPath
+ cursor
.getString(nameIndex
);
527 } else if (uri
.getScheme().equals("file")) {
528 filePath
= Uri
.decode(uri
.toString()).replace(uri
.getScheme() +
530 if (filePath
.contains("mnt")) {
531 String splitedFilePath
[] = filePath
.split("/mnt");
532 filePath
= splitedFilePath
[1];
534 final File file
= new File(filePath
);
535 data
= file
.getAbsolutePath();
536 filePath
= mUploadPath
+ file
.getName();
539 throw new SecurityException();
542 mRemoteCacheData
.add(filePath
);
543 CopyTmpFileAsyncTask copyTask
= new CopyTmpFileAsyncTask(this);
544 Object
[] params
= { uri
, filePath
, mRemoteCacheData
.size()-1,
545 getAccount().name
, getContentResolver()};
547 showWaitingCopyDialog();
548 copyTask
.execute(params
);
550 remote
.add(filePath
);
555 throw new SecurityException();
558 Intent intent
= new Intent(getApplicationContext(), FileUploader
.class);
559 intent
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
560 intent
.putExtra(FileUploader
.KEY_LOCAL_FILE
, local
.toArray(new String
[local
.size()]));
561 intent
.putExtra(FileUploader
.KEY_REMOTE_FILE
,
562 remote
.toArray(new String
[remote
.size()]));
563 intent
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
564 startService(intent
);
566 //Save the path to shared preferences
567 SharedPreferences
.Editor appPrefs
= PreferenceManager
568 .getDefaultSharedPreferences(getApplicationContext()).edit();
569 appPrefs
.putString("last_upload_path", mUploadPath
);
575 } catch (SecurityException e
) {
576 String message
= String
.format(getString(R
.string
.uploader_error_forbidden_content
),
577 getString(R
.string
.app_name
));
578 Toast
.makeText(this, message
, Toast
.LENGTH_LONG
).show();
583 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
584 super.onRemoteOperationFinish(operation
, result
);
587 if (operation
instanceof CreateFolderOperation
) {
588 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
594 * Updates the view associated to the activity after the finish of an operation
595 * trying create a new folder
597 * @param operation Creation operation performed.
598 * @param result Result of the creation.
600 private void onCreateFolderOperationFinish(CreateFolderOperation operation
,
601 RemoteOperationResult result
) {
602 if (result
.isSuccess()) {
603 dismissLoadingDialog();
604 populateDirectoryList();
606 dismissLoadingDialog();
608 Toast msg
= Toast
.makeText(this,
609 ErrorMessageAdapter
.getErrorCauseMessage(result
, operation
, getResources()),
613 } catch (NotFoundException e
) {
614 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
621 * Loads the target folder initialize shown to the user.
623 * The target account has to be chosen before this method is called.
625 private void initTargetFolder() {
626 if (getStorageManager() == null
) {
627 throw new IllegalStateException("Do not call this method before " +
628 "initializing mStorageManager");
631 SharedPreferences appPreferences
= PreferenceManager
632 .getDefaultSharedPreferences(getApplicationContext());
634 String last_path
= appPreferences
.getString("last_upload_path", "");
635 // "/" equals root-directory
636 if(last_path
.equals("/")) {
639 String
[] dir_names
= last_path
.split("/");
640 for (String dir
: dir_names
)
643 //Make sure that path still exists, if it doesn't pop the stack and try the previous path
644 while(!getStorageManager().fileExists(generatePath(mParents
)) && mParents
.size() > 1){
651 public boolean onOptionsItemSelected(MenuItem item
) {
652 boolean retval
= true
;
653 switch (item
.getItemId()) {
654 case android
.R
.id
.home
:
655 if((mParents
.size() > 1)) {
661 retval
= super.onOptionsItemSelected(item
);
668 * Process the result of CopyTmpFileAsyncTask
673 public void onTmpFileCopied(String result
, int index
) {
674 if (mNumCacheFile
-- == 0) {
675 dismissWaitingCopyDialog();
677 if (result
!= null
) {
678 Intent intent
= new Intent(getApplicationContext(), FileUploader
.class);
679 intent
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
680 intent
.putExtra(FileUploader
.KEY_LOCAL_FILE
, result
);
681 intent
.putExtra(FileUploader
.KEY_REMOTE_FILE
, mRemoteCacheData
.get(index
));
682 intent
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
683 startService(intent
);
686 String message
= String
.format(getString(R
.string
.uploader_error_forbidden_content
),
687 getString(R
.string
.app_name
));
688 Toast
.makeText(this, message
, Toast
.LENGTH_LONG
).show();
689 Log_OC
.d(TAG
, message
);
694 * Show waiting for copy dialog
696 public void showWaitingCopyDialog() {
698 LoadingDialog loading
= new LoadingDialog(
699 getResources().getString(R
.string
.wait_for_tmp_copy_from_private_storage
));
700 FragmentManager fm
= getSupportFragmentManager();
701 FragmentTransaction ft
= fm
.beginTransaction();
702 loading
.show(ft
, DIALOG_WAIT_COPY_FILE
);
708 * Dismiss waiting for copy dialog
710 public void dismissWaitingCopyDialog(){
711 Fragment frag
= getSupportFragmentManager().findFragmentByTag(DIALOG_WAIT_COPY_FILE
);
713 LoadingDialog loading
= (LoadingDialog
) frag
;