1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package com
.owncloud
.android
.ui
.activity
;
23 import android
.accounts
.Account
;
24 import android
.app
.AlertDialog
;
25 import android
.app
.ProgressDialog
;
26 import android
.app
.Dialog
;
27 import android
.content
.BroadcastReceiver
;
28 import android
.content
.ComponentName
;
29 import android
.content
.ContentResolver
;
30 import android
.content
.Context
;
31 import android
.content
.DialogInterface
;
32 import android
.content
.Intent
;
33 import android
.content
.IntentFilter
;
34 import android
.content
.ServiceConnection
;
35 import android
.content
.SharedPreferences
;
36 import android
.content
.res
.Resources
.NotFoundException
;
37 import android
.database
.Cursor
;
38 import android
.net
.Uri
;
39 import android
.os
.Bundle
;
40 import android
.os
.Handler
;
41 import android
.os
.IBinder
;
42 import android
.preference
.PreferenceManager
;
43 import android
.provider
.MediaStore
;
44 import android
.support
.v4
.app
.Fragment
;
45 import android
.support
.v4
.app
.FragmentTransaction
;
46 import android
.util
.Log
;
47 import android
.view
.View
;
48 import android
.view
.ViewGroup
;
49 import android
.widget
.ArrayAdapter
;
50 import android
.widget
.TextView
;
51 import android
.widget
.Toast
;
53 import com
.actionbarsherlock
.app
.ActionBar
;
54 import com
.actionbarsherlock
.app
.ActionBar
.OnNavigationListener
;
55 import com
.actionbarsherlock
.view
.Menu
;
56 import com
.actionbarsherlock
.view
.MenuInflater
;
57 import com
.actionbarsherlock
.view
.MenuItem
;
58 import com
.actionbarsherlock
.view
.Window
;
59 import com
.owncloud
.android
.Log_OC
;
60 import com
.owncloud
.android
.R
;
61 import com
.owncloud
.android
.authentication
.AccountAuthenticator
;
62 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
63 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
64 import com
.owncloud
.android
.datamodel
.OCFile
;
65 import com
.owncloud
.android
.files
.services
.FileDownloader
;
66 import com
.owncloud
.android
.files
.services
.FileDownloader
.FileDownloaderBinder
;
67 import com
.owncloud
.android
.files
.services
.FileObserverService
;
68 import com
.owncloud
.android
.files
.services
.FileUploader
;
69 import com
.owncloud
.android
.files
.services
.FileUploader
.FileUploaderBinder
;
70 import com
.owncloud
.android
.operations
.CreateFolderOperation
;
71 import com
.owncloud
.android
.operations
.OnRemoteOperationListener
;
72 import com
.owncloud
.android
.operations
.RemoteOperation
;
73 import com
.owncloud
.android
.operations
.RemoteOperationResult
;
74 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
75 import com
.owncloud
.android
.operations
.RenameFileOperation
;
76 import com
.owncloud
.android
.operations
.SynchronizeFileOperation
;
77 import com
.owncloud
.android
.operations
.RemoteOperationResult
.ResultCode
;
78 import com
.owncloud
.android
.syncadapter
.FileSyncService
;
79 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
;
80 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
;
81 import com
.owncloud
.android
.ui
.dialog
.EditNameDialog
.EditNameDialogListener
;
82 import com
.owncloud
.android
.ui
.dialog
.SslValidatorDialog
.OnSslValidatorListener
;
83 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
84 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
85 import com
.owncloud
.android
.ui
.fragment
.OCFileListFragment
;
86 import com
.owncloud
.android
.ui
.preview
.PreviewImageActivity
;
87 import com
.owncloud
.android
.ui
.preview
.PreviewMediaFragment
;
88 import com
.owncloud
.android
.ui
.preview
.PreviewVideoActivity
;
91 * Displays, what files the user has available in his ownCloud.
93 * @author Bartek Przybylski
94 * @author David A. Velasco
97 public class FileDisplayActivity
extends FileActivity
implements
98 OCFileListFragment
.ContainerActivity
, FileDetailFragment
.ContainerActivity
, OnNavigationListener
, OnSslValidatorListener
, OnRemoteOperationListener
, EditNameDialogListener
{
100 private ArrayAdapter
<String
> mDirectories
;
102 /** Access point to the cached database for the current ownCloud {@link Account} */
103 private DataStorageManager mStorageManager
= null
;
105 private SyncBroadcastReceiver mSyncBroadcastReceiver
;
106 private UploadFinishReceiver mUploadFinishReceiver
;
107 private DownloadFinishReceiver mDownloadFinishReceiver
;
108 private FileDownloaderBinder mDownloaderBinder
= null
;
109 private FileUploaderBinder mUploaderBinder
= null
;
110 private ServiceConnection mDownloadConnection
= null
, mUploadConnection
= null
;
111 private RemoteOperationResult mLastSslUntrustedServerResult
= null
;
113 private boolean mDualPane
;
114 private View mLeftFragmentContainer
;
115 private View mRightFragmentContainer
;
117 private static final String KEY_WAITING_TO_PREVIEW
= "WAITING_TO_PREVIEW";
119 public static final int DIALOG_SHORT_WAIT
= 0;
120 private static final int DIALOG_CHOOSE_UPLOAD_SOURCE
= 1;
121 private static final int DIALOG_SSL_VALIDATOR
= 2;
122 private static final int DIALOG_CERT_NOT_SAVED
= 3;
124 public static final String ACTION_DETAILS
= "com.owncloud.android.ui.activity.action.DETAILS";
126 private static final int ACTION_SELECT_CONTENT_FROM_APPS
= 1;
127 private static final int ACTION_SELECT_MULTIPLE_FILES
= 2;
129 private static final String TAG
= FileDisplayActivity
.class.getSimpleName();
131 private static final String TAG_LIST_OF_FILES
= "LIST_OF_FILES";
132 private static final String TAG_SECOND_FRAGMENT
= "SECOND_FRAGMENT";
134 private OCFile mWaitingToPreview
;
135 private Handler mHandler
;
138 protected void onCreate(Bundle savedInstanceState
) {
139 Log_OC
.d(TAG
, "onCreate() start");
140 super.onCreate(savedInstanceState
);
142 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
144 mHandler
= new Handler();
146 /// bindings to transference services
147 mUploadConnection
= new ListServiceConnection();
148 mDownloadConnection
= new ListServiceConnection();
149 bindService(new Intent(this, FileUploader
.class), mUploadConnection
, Context
.BIND_AUTO_CREATE
);
150 bindService(new Intent(this, FileDownloader
.class), mDownloadConnection
, Context
.BIND_AUTO_CREATE
);
152 // PIN CODE request ; best location is to decide, let's try this first
153 if (getIntent().getAction() != null
&& getIntent().getAction().equals(Intent
.ACTION_MAIN
) && savedInstanceState
== null
) {
158 Intent observer_intent
= new Intent(this, FileObserverService
.class);
159 observer_intent
.putExtra(FileObserverService
.KEY_FILE_CMD
, FileObserverService
.CMD_INIT_OBSERVED_LIST
);
160 startService(observer_intent
);
162 /// Load of saved instance state
163 if(savedInstanceState
!= null
) {
164 mWaitingToPreview
= (OCFile
) savedInstanceState
.getParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
);
167 mWaitingToPreview
= null
;
172 // Inflate and set the layout view
173 setContentView(R
.layout
.files
);
174 mDualPane
= getResources().getBoolean(R
.bool
.large_land_layout
);
175 mLeftFragmentContainer
= findViewById(R
.id
.left_fragment_container
);
176 mRightFragmentContainer
= findViewById(R
.id
.right_fragment_container
);
177 if (savedInstanceState
== null
) {
178 createMinFragments();
182 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
183 getSupportActionBar().setHomeButtonEnabled(true
); // mandatory since Android ICS, according to the official documentation
184 setSupportProgressBarIndeterminateVisibility(false
); // always AFTER setContentView(...) ; to work around bug in its implementation
186 Log_OC
.d(TAG
, "onCreate() end");
191 protected void onDestroy() {
193 if (mDownloadConnection
!= null
)
194 unbindService(mDownloadConnection
);
195 if (mUploadConnection
!= null
)
196 unbindService(mUploadConnection
);
201 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
204 protected void onAccountSet(boolean stateWasRecovered
) {
205 if (getAccount() != null
) {
206 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
208 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
209 OCFile file
= getFile();
211 file
= mStorageManager
.getFileByPath(file
.getRemotePath()); // currentDir = null if not in the current Account
214 // fall back to root folder
215 file
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
); // never returns null
218 mDirectories
.clear();
219 while(file
!= null
&& file
.getFileName() != OCFile
.PATH_SEPARATOR
) {
220 if (file
.isDirectory()) {
221 mDirectories
.add(file
.getFileName());
223 file
= mStorageManager
.getFileById(file
.getParentId());
225 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
226 if (!stateWasRecovered
) {
227 Log_OC
.e(TAG
, "Initializing Fragments in onAccountChanged..");
228 initFragmentsWithFile();
232 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
237 private void createMinFragments() {
238 OCFileListFragment listOfFiles
= new OCFileListFragment();
239 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
240 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
241 transaction
.commit();
244 private void initFragmentsWithFile() {
245 if (getAccount() != null
&& getFile() != null
) {
247 OCFile file
= getFile();
248 Fragment secondFragment
= chooseInitialSecondFragment(file
);
249 if (secondFragment
!= null
) {
250 setSecondFragment(secondFragment
);
251 updateFragmentsVisibility(true
);
252 updateNavigationElementsInActionBar(file
);
255 cleanSecondFragment();
259 Log
.wtf(TAG
, "initFragments() called with invalid NULLs!");
260 if (getAccount() == null
) {
261 Log
.wtf(TAG
, "\t account is NULL");
263 if (getFile() == null
) {
264 Log
.wtf(TAG
, "\t file is NULL");
269 private Fragment
chooseInitialSecondFragment(OCFile file
) {
270 Fragment secondFragment
= null
;
271 if (file
!= null
&& !file
.isDirectory()) {
272 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)) {
273 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
274 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
275 secondFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
278 secondFragment
= new FileDetailFragment(file
, getAccount());
281 return secondFragment
;
286 * Replaces the second fragment managed by the activity with the received as
289 * Assumes never will be more than two fragments managed at the same time.
291 * @param fragment New second Fragment to set.
293 private void setSecondFragment(Fragment fragment
) {
294 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
295 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
296 transaction
.commit();
300 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
302 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
303 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
305 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
306 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
309 } else if (existsSecondFragment
) {
310 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
311 mLeftFragmentContainer
.setVisibility(View
.GONE
);
313 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
314 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
318 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
319 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
321 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
322 mRightFragmentContainer
.setVisibility(View
.GONE
);
328 private OCFileListFragment
getListOfFilesFragment() {
329 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_LIST_OF_FILES
);
330 if (listOfFiles
!= null
) {
331 return (OCFileListFragment
)listOfFiles
;
333 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
337 protected FileFragment
getSecondFragment() {
338 Fragment second
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
339 if (second
!= null
) {
340 return (FileFragment
)second
;
345 public void cleanSecondFragment() {
346 Fragment second
= getSecondFragment();
347 if (second
!= null
) {
348 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
352 updateFragmentsVisibility(false
);
353 updateNavigationElementsInActionBar(null
);
356 protected void refeshListOfFilesFragment() {
357 OCFileListFragment fileListFragment
= getListOfFilesFragment();
358 if (fileListFragment
!= null
) {
359 fileListFragment
.listDirectory();
363 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
364 FileFragment secondFragment
= getSecondFragment();
365 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
366 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
367 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
368 OCFile fileInFragment
= detailsFragment
.getFile();
369 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
370 // the user browsed to other file ; forget the automatic preview
371 mWaitingToPreview
= null
;
373 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
)) {
374 // grant that the right panel updates the progress bar
375 detailsFragment
.listenForTransferProgress();
376 detailsFragment
.updateFileDetails(true
, false
);
378 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
)) {
379 // update the right panel
380 boolean detailsFragmentChanged
= false
;
383 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
384 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
385 startMediaPreview(mWaitingToPreview
, 0, true
);
386 detailsFragmentChanged
= true
;
388 openFile(mWaitingToPreview
);
391 mWaitingToPreview
= null
;
393 if (!detailsFragmentChanged
) {
394 detailsFragment
.updateFileDetails(false
, (success
));
402 public boolean onCreateOptionsMenu(Menu menu
) {
403 MenuInflater inflater
= getSherlock().getMenuInflater();
404 inflater
.inflate(R
.menu
.main_menu
, menu
);
409 public boolean onOptionsItemSelected(MenuItem item
) {
410 boolean retval
= true
;
411 switch (item
.getItemId()) {
412 case R
.id
.action_create_dir
: {
413 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
414 dialog
.show(getSupportFragmentManager(), "createdirdialog");
417 case R
.id
.action_sync_account
: {
418 startSynchronization();
421 case R
.id
.action_upload
: {
422 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
425 case R
.id
.action_settings
: {
426 Intent settingsIntent
= new Intent(this, Preferences
.class);
427 startActivity(settingsIntent
);
430 case android
.R
.id
.home
: {
431 FileFragment second
= getSecondFragment();
432 OCFile currentDir
= getCurrentDir();
433 if((currentDir
!= null
&& currentDir
.getParentId() != 0) ||
434 (second
!= null
&& second
.getFile() != null
)) {
440 retval
= super.onOptionsItemSelected(item
);
445 private void startSynchronization() {
446 ContentResolver
.cancelSync(null
, AccountAuthenticator
.AUTHORITY
); // cancel the current synchronizations of any ownCloud account
447 Bundle bundle
= new Bundle();
448 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
449 ContentResolver
.requestSync(
451 AccountAuthenticator
.AUTHORITY
, bundle
);
456 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
457 int i
= itemPosition
;
461 // the next operation triggers a new call to this method, but it's necessary to
462 // ensure that the name exposed in the action bar is the current directory when the
463 // user selected it in the navigation list
464 if (itemPosition
!= 0)
465 getSupportActionBar().setSelectedNavigationItem(0);
470 * Called, when the user selected something for uploading
472 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
473 super.onActivityResult(requestCode
, resultCode
, data
);
475 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
476 requestSimpleUpload(data
, resultCode
);
478 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
479 requestMultipleUpload(data
, resultCode
);
484 private void requestMultipleUpload(Intent data
, int resultCode
) {
485 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
486 if (filePaths
!= null
) {
487 String
[] remotePaths
= new String
[filePaths
.length
];
488 String remotePathBase
= "";
489 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
490 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
492 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
493 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
494 for (int j
= 0; j
< remotePaths
.length
; j
++) {
495 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
498 Intent i
= new Intent(this, FileUploader
.class);
499 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
500 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
501 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
502 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
503 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
504 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
508 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
509 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
516 private void requestSimpleUpload(Intent data
, int resultCode
) {
517 String filepath
= null
;
519 Uri selectedImageUri
= data
.getData();
521 String filemanagerstring
= selectedImageUri
.getPath();
522 String selectedImagePath
= getPath(selectedImageUri
);
524 if (selectedImagePath
!= null
)
525 filepath
= selectedImagePath
;
527 filepath
= filemanagerstring
;
529 } catch (Exception e
) {
530 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
534 if (filepath
== null
) {
535 Log_OC
.e(TAG
, "Couldnt resolve path to file");
536 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
542 Intent i
= new Intent(this, FileUploader
.class);
543 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
545 String remotepath
= new String();
546 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
547 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
549 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
550 remotepath
+= OCFile
.PATH_SEPARATOR
;
551 remotepath
+= new File(filepath
).getName();
553 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
554 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
555 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
556 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
557 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
562 public void onBackPressed() {
563 OCFileListFragment listOfFiles
= getListOfFilesFragment();
564 if (mDualPane
|| getSecondFragment() == null
) {
565 if (listOfFiles
!= null
) { // should never be null, indeed
566 if (mDirectories
.getCount() <= 1) {
571 listOfFiles
.onBrowseUp();
574 if (listOfFiles
!= null
) { // should never be null, indeed
575 setFile(listOfFiles
.getCurrentFile());
577 cleanSecondFragment();
581 protected void onSaveInstanceState(Bundle outState
) {
582 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
583 Log_OC
.e(TAG
, "onSaveInstanceState() start");
584 super.onSaveInstanceState(outState
);
585 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
586 Log_OC
.d(TAG
, "onSaveInstanceState() end");
591 protected void onResume() {
593 Log_OC
.e(TAG
, "onResume() start");
595 // Listen for sync messages
596 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
597 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
598 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
600 // Listen for upload messages
601 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
602 mUploadFinishReceiver
= new UploadFinishReceiver();
603 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
605 // Listen for download messages
606 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
);
607 downloadIntentFilter
.addAction(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
);
608 mDownloadFinishReceiver
= new DownloadFinishReceiver();
609 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
611 // List current directory
612 OCFileListFragment listOfFiles
= getListOfFilesFragment();
613 if (listOfFiles
!= null
) {
614 listOfFiles
.listDirectory(getCurrentDir()); // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check)
617 Log_OC
.d(TAG
, "onResume() end");
622 protected void onPause() {
624 Log_OC
.e(TAG
, "onPause() start");
625 if (mSyncBroadcastReceiver
!= null
) {
626 unregisterReceiver(mSyncBroadcastReceiver
);
627 mSyncBroadcastReceiver
= null
;
629 if (mUploadFinishReceiver
!= null
) {
630 unregisterReceiver(mUploadFinishReceiver
);
631 mUploadFinishReceiver
= null
;
633 if (mDownloadFinishReceiver
!= null
) {
634 unregisterReceiver(mDownloadFinishReceiver
);
635 mDownloadFinishReceiver
= null
;
638 Log_OC
.d(TAG
, "onPause() end");
643 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
644 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
645 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
651 protected Dialog
onCreateDialog(int id
) {
652 Dialog dialog
= null
;
653 AlertDialog
.Builder builder
;
655 case DIALOG_SHORT_WAIT
: {
656 ProgressDialog working_dialog
= new ProgressDialog(this);
657 working_dialog
.setMessage(getResources().getString(
658 R
.string
.wait_a_moment
));
659 working_dialog
.setIndeterminate(true
);
660 working_dialog
.setCancelable(false
);
661 dialog
= working_dialog
;
664 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
666 String
[] items
= null
;
668 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
669 getString(R
.string
.actionbar_upload_from_apps
),
670 getString(R
.string
.actionbar_failed_instant_upload
) };
672 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
673 getString(R
.string
.actionbar_upload_from_apps
) };
675 if (InstantUploadActivity
.IS_ENABLED
)
680 builder
= new AlertDialog
.Builder(this);
681 builder
.setTitle(R
.string
.actionbar_upload
);
682 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
683 public void onClick(DialogInterface dialog
, int item
) {
686 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
687 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
688 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
690 // TODO create and handle new fragment
691 // LocalFileListFragment
693 } else if (item
== 1) {
694 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
695 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
696 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
697 ACTION_SELECT_CONTENT_FROM_APPS
);
698 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
699 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
700 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
701 startActivity(action
);
705 dialog
= builder
.create();
708 case DIALOG_SSL_VALIDATOR
: {
709 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
712 case DIALOG_CERT_NOT_SAVED
: {
713 builder
= new AlertDialog
.Builder(this);
714 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
715 builder
.setCancelable(false
);
716 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
718 public void onClick(DialogInterface dialog
, int which
) {
722 dialog
= builder
.create();
734 * Translates a content URI of an image to a physical path
736 * @param uri The URI to resolve
737 * @return The path to the image or null if it could not be found
739 public String
getPath(Uri uri
) {
740 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
741 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
742 if (cursor
!= null
) {
743 int column_index
= cursor
744 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
745 cursor
.moveToFirst();
746 return cursor
.getString(column_index
);
752 * Pushes a directory to the drop down list
753 * @param directory to push
754 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
756 public void pushDirname(OCFile directory
) {
757 if(!directory
.isDirectory()){
758 throw new IllegalArgumentException("Only directories may be pushed!");
760 mDirectories
.insert(directory
.getFileName(), 0);
765 * Pops a directory name from the drop down list
766 * @return True, unless the stack is empty
768 public boolean popDirname() {
769 mDirectories
.remove(mDirectories
.getItem(0));
770 return !mDirectories
.isEmpty();
773 // Custom array adapter to override text colors
774 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
776 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
780 public View
getView(int position
, View convertView
, ViewGroup parent
) {
781 View v
= super.getView(position
, convertView
, parent
);
783 ((TextView
) v
).setTextColor(getResources().getColorStateList(
784 android
.R
.color
.white
));
788 public View
getDropDownView(int position
, View convertView
,
790 View v
= super.getDropDownView(position
, convertView
, parent
);
792 ((TextView
) v
).setTextColor(getResources().getColorStateList(
793 android
.R
.color
.white
));
800 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
803 * {@link BroadcastReceiver} to enable syncing feedback in UI
806 public void onReceive(Context context
, Intent intent
) {
807 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
808 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
810 Log_OC
.d(TAG
, "sync of account " + accountName
+ " is in_progress: " + inProgress
);
812 if (getAccount() != null
&& accountName
.equals(getAccount().name
)) {
814 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
816 boolean fillBlankRoot
= false
;
817 OCFile currentDir
= getCurrentDir();
818 if (currentDir
== null
) {
819 currentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
820 fillBlankRoot
= (currentDir
!= null
);
823 if ((synchFolderRemotePath
!= null
&& currentDir
!= null
&& (currentDir
.getRemotePath().equals(synchFolderRemotePath
)))
826 currentDir
= getStorageManager().getFileByPath(synchFolderRemotePath
);
827 OCFileListFragment fileListFragment
= getListOfFilesFragment();
828 if (fileListFragment
!= null
) {
829 fileListFragment
.listDirectory(currentDir
);
834 setSupportProgressBarIndeterminateVisibility(inProgress
);
835 removeStickyBroadcast(intent
);
839 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
840 if (synchResult
!= null
) {
841 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
842 mLastSslUntrustedServerResult
= synchResult
;
843 showDialog(DIALOG_SSL_VALIDATOR
);
850 private class UploadFinishReceiver
extends BroadcastReceiver
{
852 * Once the file upload has finished -> update view
853 * @author David A. Velasco
854 * {@link BroadcastReceiver} to enable upload feedback in UI
857 public void onReceive(Context context
, Intent intent
) {
858 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
859 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
860 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
861 OCFile currentDir
= getCurrentDir();
862 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
863 if (sameAccount
&& isDescendant
) {
864 refeshListOfFilesFragment();
872 * Class waiting for broadcast events from the {@link FielDownloader} service.
874 * Updates the UI when a download is started or finished, provided that it is relevant for the
877 private class DownloadFinishReceiver
extends BroadcastReceiver
{
879 public void onReceive(Context context
, Intent intent
) {
880 boolean sameAccount
= isSameAccount(context
, intent
);
881 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
882 boolean isDescendant
= isDescendant(downloadedRemotePath
);
884 if (sameAccount
&& isDescendant
) {
885 refeshListOfFilesFragment();
886 refreshSecondFragment(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
889 removeStickyBroadcast(intent
);
892 private boolean isDescendant(String downloadedRemotePath
) {
893 OCFile currentDir
= getCurrentDir();
894 return (currentDir
!= null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(currentDir
.getRemotePath()));
897 private boolean isSameAccount(Context context
, Intent intent
) {
898 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
899 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
908 public DataStorageManager
getStorageManager() {
909 return mStorageManager
;
916 * Updates action bar and second fragment, if in dual pane mode.
919 public void onBrowsedDownTo(OCFile directory
) {
920 pushDirname(directory
);
921 cleanSecondFragment();
925 * Opens the image gallery showing the image {@link OCFile} received as parameter.
927 * @param file Image {@link OCFile} to show.
930 public void startImagePreview(OCFile file
) {
931 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
932 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
933 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
934 startActivity(showDetailsIntent
);
938 * Stars the preview of an already down media {@link OCFile}.
940 * @param file Media {@link OCFile} to preview.
941 * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
942 * @param autoplay When 'true', the playback will start without user interactions.
945 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
946 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
947 setSecondFragment(mediaFragment
);
948 updateFragmentsVisibility(true
);
949 updateNavigationElementsInActionBar(file
);
954 * Requests the download of the received {@link OCFile} , updates the UI
955 * to monitor the download progress and prepares the activity to preview
956 * or open the file when the download finishes.
958 * @param file {@link OCFile} to download and preview.
961 public void startDownloadForPreview(OCFile file
) {
962 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
963 setSecondFragment(detailFragment
);
964 mWaitingToPreview
= file
;
965 requestForDownload();
966 updateFragmentsVisibility(true
);
967 updateNavigationElementsInActionBar(file
);
973 * Shows the information of the {@link OCFile} received as a
974 * parameter in the second fragment.
976 * @param file {@link OCFile} whose details will be shown
979 public void showDetails(OCFile file
) {
980 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
981 setSecondFragment(detailFragment
);
982 updateFragmentsVisibility(true
);
983 updateNavigationElementsInActionBar(file
);
991 private void updateNavigationElementsInActionBar(OCFile currentFile
) {
992 ActionBar actionBar
= getSupportActionBar();
993 if (currentFile
== null
|| mDualPane
) {
994 // only list of files - set for browsing through folders
995 OCFile currentDir
= getCurrentDir();
996 actionBar
.setDisplayHomeAsUpEnabled(currentDir
!= null
&& currentDir
.getParentId() != 0);
997 actionBar
.setDisplayShowTitleEnabled(false
);
998 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
999 actionBar
.setListNavigationCallbacks(mDirectories
, this); // assuming mDirectories is updated
1002 actionBar
.setDisplayHomeAsUpEnabled(true
);
1003 actionBar
.setDisplayShowTitleEnabled(true
);
1004 actionBar
.setTitle(currentFile
.getFileName());
1005 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1014 public OCFile
getInitialDirectory() {
1015 return getCurrentDir();
1023 public void onFileStateChanged() {
1024 refeshListOfFilesFragment();
1032 public FileDownloaderBinder
getFileDownloaderBinder() {
1033 return mDownloaderBinder
;
1041 public FileUploaderBinder
getFileUploaderBinder() {
1042 return mUploaderBinder
;
1046 /** Defines callbacks for service binding, passed to bindService() */
1047 private class ListServiceConnection
implements ServiceConnection
{
1050 public void onServiceConnected(ComponentName component
, IBinder service
) {
1051 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1052 Log_OC
.d(TAG
, "Download service connected");
1053 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1054 if (mWaitingToPreview
!= null
) {
1055 requestForDownload();
1058 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1059 Log_OC
.d(TAG
, "Upload service connected");
1060 mUploaderBinder
= (FileUploaderBinder
) service
;
1064 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1065 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1066 if (listOfFiles
!= null
) {
1067 listOfFiles
.listDirectory();
1069 FileFragment secondFragment
= getSecondFragment();
1070 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1071 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1072 detailFragment
.listenForTransferProgress();
1073 detailFragment
.updateFileDetails(false
, false
);
1078 public void onServiceDisconnected(ComponentName component
) {
1079 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1080 Log_OC
.d(TAG
, "Download service disconnected");
1081 mDownloaderBinder
= null
;
1082 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1083 Log_OC
.d(TAG
, "Upload service disconnected");
1084 mUploaderBinder
= null
;
1092 * Launch an intent to request the PIN code to the user before letting him use the app
1094 private void requestPinCode() {
1095 boolean pinStart
= false
;
1096 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1097 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1099 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1100 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1107 public void onSavedCertificate() {
1108 startSynchronization();
1113 public void onFailedSavingCertificate() {
1114 showDialog(DIALOG_CERT_NOT_SAVED
);
1119 * Updates the view associated to the activity after the finish of some operation over files
1120 * in the current account.
1122 * @param operation Removal operation performed.
1123 * @param result Result of the removal.
1126 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1127 if (operation
instanceof RemoveFileOperation
) {
1128 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1130 } else if (operation
instanceof RenameFileOperation
) {
1131 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1133 } else if (operation
instanceof SynchronizeFileOperation
) {
1134 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1136 } else if (operation
instanceof CreateFolderOperation
) {
1137 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1143 * Updates the view associated to the activity after the finish of an operation trying to remove a
1146 * @param operation Removal operation performed.
1147 * @param result Result of the removal.
1149 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1150 dismissDialog(DIALOG_SHORT_WAIT
);
1151 if (result
.isSuccess()) {
1152 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1154 OCFile removedFile
= operation
.getFile();
1155 getSecondFragment();
1156 FileFragment second
= getSecondFragment();
1157 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1158 cleanSecondFragment();
1160 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1161 refeshListOfFilesFragment();
1165 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1167 if (result
.isSslRecoverableException()) {
1168 mLastSslUntrustedServerResult
= result
;
1169 showDialog(DIALOG_SSL_VALIDATOR
);
1175 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1177 * @param operation Creation operation performed.
1178 * @param result Result of the creation.
1180 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1181 if (result
.isSuccess()) {
1182 dismissDialog(DIALOG_SHORT_WAIT
);
1183 refeshListOfFilesFragment();
1186 dismissDialog(DIALOG_SHORT_WAIT
);
1188 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1191 } catch (NotFoundException e
) {
1192 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1199 * Updates the view associated to the activity after the finish of an operation trying to rename a
1202 * @param operation Renaming operation performed.
1203 * @param result Result of the renaming.
1205 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1206 dismissDialog(DIALOG_SHORT_WAIT
);
1207 OCFile renamedFile
= operation
.getFile();
1208 if (result
.isSuccess()) {
1210 FileFragment details
= getSecondFragment();
1211 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1212 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1215 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getCurrentDir())) {
1216 refeshListOfFilesFragment();
1220 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1221 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1223 // TODO throw again the new rename dialog
1225 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1227 if (result
.isSslRecoverableException()) {
1228 mLastSslUntrustedServerResult
= result
;
1229 showDialog(DIALOG_SSL_VALIDATOR
);
1236 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1237 dismissDialog(DIALOG_SHORT_WAIT
);
1238 OCFile syncedFile
= operation
.getLocalFile();
1239 if (!result
.isSuccess()) {
1240 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1241 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1242 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1243 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1247 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_fail_msg
, Toast
.LENGTH_LONG
);
1252 if (operation
.transferWasRequested()) {
1253 refeshListOfFilesFragment();
1254 onTransferStateChanged(syncedFile
, true
, true
);
1257 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1268 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1270 FileFragment details
= getSecondFragment();
1271 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1272 if (downloading
|| uploading
) {
1273 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1275 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1282 public void onDismiss(EditNameDialog dialog
) {
1283 if (dialog
.getResult()) {
1284 String newDirectoryName
= dialog
.getNewFilename().trim();
1285 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1286 if (newDirectoryName
.length() > 0) {
1287 String path
= getCurrentDir().getRemotePath();
1290 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1291 RemoteOperation operation
= new CreateFolderOperation(path
, getCurrentDir().getFileId(), mStorageManager
);
1292 operation
.execute( getAccount(),
1293 FileDisplayActivity
.this,
1294 FileDisplayActivity
.this,
1296 FileDisplayActivity
.this);
1298 showDialog(DIALOG_SHORT_WAIT
);
1304 private void requestForDownload() {
1305 Account account
= getAccount();
1306 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1307 Intent i
= new Intent(this, FileDownloader
.class);
1308 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1309 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1315 private OCFile
getCurrentDir() {
1316 OCFile file
= getFile();
1318 if (file
.isDirectory()) {
1321 return mStorageManager
.getFileById(file
.getParentId());