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 requestWindowFeature(Window
.FEATURE_INDETERMINATE_PROGRESS
);
142 super.onCreate(savedInstanceState
); // this calls onAccountChanged() when ownCloud Account is valid
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();
179 if (!isRedirectingToSetupAccount()) {
180 initFragmentsWithFile();
185 mDirectories
= new CustomArrayAdapter
<String
>(this, R
.layout
.sherlock_spinner_dropdown_item
);
186 OCFile currFile
= getFile();
187 if (mStorageManager
!= null
) {
188 while(currFile
!= null
&& currFile
.getFileName() != OCFile
.PATH_SEPARATOR
) {
189 if (currFile
.isDirectory()) {
190 mDirectories
.add(currFile
.getFileName());
192 currFile
= mStorageManager
.getFileById(currFile
.getParentId());
195 mDirectories
.add(OCFile
.PATH_SEPARATOR
);
196 ActionBar actionBar
= getSupportActionBar();
197 actionBar
.setHomeButtonEnabled(true
); // mandatory since Android ICS, according to the official documentation
198 setSupportProgressBarIndeterminateVisibility(false
); // always AFTER setContentView(...) ; to workaround bug in its implementation
200 Log_OC
.d(TAG
, "onCreate() end");
205 protected void onDestroy() {
207 if (mDownloadConnection
!= null
)
208 unbindService(mDownloadConnection
);
209 if (mUploadConnection
!= null
)
210 unbindService(mUploadConnection
);
215 * Called when the ownCloud {@link Account} associated to the Activity was just updated.
218 protected void onAccountSet(boolean stateWasRecovered
) {
219 if (getAccount() != null
) {
220 mStorageManager
= new FileDataStorageManager(getAccount(), getContentResolver());
222 /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
223 OCFile file
= getFile();
225 file
= mStorageManager
.getFileByPath(file
.getRemotePath()); // currentDir = null if not in the current Account
228 // fall back to root folder
229 file
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
); // never should return null
233 if (findViewById(android
.R
.id
.content
) != null
&& !stateWasRecovered
) {
234 Log_OC
.e(TAG
, "Initializing Fragments in onAccountChanged..");
235 initFragmentsWithFile();
237 Log_OC
.e(TAG
, "Fragment initializacion ignored in onAccountChanged due to lack of CONTENT VIEW");
241 Log_OC
.wtf(TAG
, "onAccountChanged was called with NULL account associated!");
246 private void createMinFragments() {
247 OCFileListFragment listOfFiles
= new OCFileListFragment();
248 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
249 transaction
.add(R
.id
.left_fragment_container
, listOfFiles
, TAG_LIST_OF_FILES
);
250 transaction
.commit();
253 private void initFragmentsWithFile() {
254 if (getAccount() != null
&& getFile() != null
) {
256 OCFile file
= getFile();
257 Fragment secondFragment
= chooseInitialSecondFragment(file
);
258 if (secondFragment
!= null
) {
259 setSecondFragment(secondFragment
);
263 Log
.wtf(TAG
, "initFragments() called with invalid NULLs!");
264 if (getAccount() == null
) {
265 Log
.wtf(TAG
, "\t account is NULL");
267 if (getFile() == null
) {
268 Log
.wtf(TAG
, "\t file is NULL");
273 private Fragment
chooseInitialSecondFragment(OCFile file
) {
274 Fragment secondFragment
= null
;
275 if (file
!= null
&& !file
.isDirectory()) {
276 if (file
.isDown() && PreviewMediaFragment
.canBePreviewed(file
)) {
277 int startPlaybackPosition
= getIntent().getIntExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, 0);
278 boolean autoplay
= getIntent().getBooleanExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, true
);
279 secondFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
282 secondFragment
= new FileDetailFragment(file
, getAccount());
285 return secondFragment
;
290 * Replaces the second fragment managed by the activity with the received as
293 * Assumes never will be more than two fragments managed at the same time.
295 * @param fragment New second Fragment to set.
297 private void setSecondFragment(Fragment fragment
) {
298 FragmentTransaction transaction
= getSupportFragmentManager().beginTransaction();
299 transaction
.replace(R
.id
.right_fragment_container
, fragment
, TAG_SECOND_FRAGMENT
);
300 transaction
.commit();
304 private void updateFragmentsVisibility(boolean existsSecondFragment
) {
306 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
307 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
309 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
310 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
313 } else if (existsSecondFragment
) {
314 if (mLeftFragmentContainer
.getVisibility() != View
.GONE
) {
315 mLeftFragmentContainer
.setVisibility(View
.GONE
);
317 if (mRightFragmentContainer
.getVisibility() != View
.VISIBLE
) {
318 mRightFragmentContainer
.setVisibility(View
.VISIBLE
);
322 if (mLeftFragmentContainer
.getVisibility() != View
.VISIBLE
) {
323 mLeftFragmentContainer
.setVisibility(View
.VISIBLE
);
325 if (mRightFragmentContainer
.getVisibility() != View
.GONE
) {
326 mRightFragmentContainer
.setVisibility(View
.GONE
);
332 private OCFileListFragment
getListOfFilesFragment() {
333 Fragment listOfFiles
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_LIST_OF_FILES
);
334 if (listOfFiles
!= null
) {
335 return (OCFileListFragment
)listOfFiles
;
337 Log_OC
.wtf(TAG
, "Access to unexisting list of files fragment!!");
341 protected FileFragment
getSecondFragment() {
342 Fragment second
= getSupportFragmentManager().findFragmentByTag(FileDisplayActivity
.TAG_SECOND_FRAGMENT
);
343 if (second
!= null
) {
344 return (FileFragment
)second
;
349 public void cleanSecondFragment() {
350 Fragment second
= getSecondFragment();
351 if (second
!= null
) {
352 FragmentTransaction tr
= getSupportFragmentManager().beginTransaction();
355 updateFragmentsVisibility(false
);
359 protected void refeshListOfFilesFragment() {
360 OCFileListFragment fileListFragment
= getListOfFilesFragment();
361 if (fileListFragment
!= null
) {
362 fileListFragment
.listDirectory();
366 protected void refreshSecondFragment(String downloadEvent
, String downloadedRemotePath
, boolean success
) {
367 FileFragment secondFragment
= getSecondFragment();
368 boolean waitedPreview
= (mWaitingToPreview
!= null
&& mWaitingToPreview
.getRemotePath().equals(downloadedRemotePath
));
369 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
370 FileDetailFragment detailsFragment
= (FileDetailFragment
) secondFragment
;
371 OCFile fileInFragment
= detailsFragment
.getFile();
372 if (fileInFragment
!= null
&& !downloadedRemotePath
.equals(fileInFragment
.getRemotePath())) {
373 // the user browsed to other file ; forget the automatic preview
374 mWaitingToPreview
= null
;
376 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
)) {
377 // grant that the right panel updates the progress bar
378 detailsFragment
.listenForTransferProgress();
379 detailsFragment
.updateFileDetails(true
, false
);
381 } else if (downloadEvent
.equals(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
)) {
382 // update the right panel
383 if (success
&& waitedPreview
) {
384 mWaitingToPreview
= mStorageManager
.getFileById(mWaitingToPreview
.getFileId()); // update the file from database, for the local storage path
385 if (PreviewMediaFragment
.canBePreviewed(mWaitingToPreview
)) {
386 startMediaPreview(mWaitingToPreview
, 0, true
);
389 detailsFragment
.updateFileDetails(false
, (success
));
390 openFile(mWaitingToPreview
);
392 mWaitingToPreview
= null
;
395 detailsFragment
.updateFileDetails(false
, (success
));
403 public boolean onCreateOptionsMenu(Menu menu
) {
404 MenuInflater inflater
= getSherlock().getMenuInflater();
405 inflater
.inflate(R
.menu
.main_menu
, menu
);
410 public boolean onOptionsItemSelected(MenuItem item
) {
411 boolean retval
= true
;
412 switch (item
.getItemId()) {
413 case R
.id
.action_create_dir
: {
414 EditNameDialog dialog
= EditNameDialog
.newInstance(getString(R
.string
.uploader_info_dirname
), "", -1, -1, this);
415 dialog
.show(getSupportFragmentManager(), "createdirdialog");
418 case R
.id
.action_sync_account
: {
419 startSynchronization();
422 case R
.id
.action_upload
: {
423 showDialog(DIALOG_CHOOSE_UPLOAD_SOURCE
);
426 case R
.id
.action_settings
: {
427 Intent settingsIntent
= new Intent(this, Preferences
.class);
428 startActivity(settingsIntent
);
431 case android
.R
.id
.home
: {
432 FileFragment second
= getSecondFragment();
433 OCFile currentDir
= getCurrentDir();
434 if((currentDir
!= null
&& currentDir
.getParentId() != 0) ||
435 (second
!= null
&& second
.getFile() != null
)) {
441 retval
= super.onOptionsItemSelected(item
);
446 private void startSynchronization() {
447 ContentResolver
.cancelSync(null
, AccountAuthenticator
.AUTHORITY
); // cancel the current synchronizations of any ownCloud account
448 Bundle bundle
= new Bundle();
449 bundle
.putBoolean(ContentResolver
.SYNC_EXTRAS_MANUAL
, true
);
450 ContentResolver
.requestSync(
452 AccountAuthenticator
.AUTHORITY
, bundle
);
457 public boolean onNavigationItemSelected(int itemPosition
, long itemId
) {
458 int i
= itemPosition
;
462 // the next operation triggers a new call to this method, but it's necessary to
463 // ensure that the name exposed in the action bar is the current directory when the
464 // user selected it in the navigation list
465 if (itemPosition
!= 0)
466 getSupportActionBar().setSelectedNavigationItem(0);
471 * Called, when the user selected something for uploading
473 protected void onActivityResult(int requestCode
, int resultCode
, Intent data
) {
474 super.onActivityResult(requestCode
, resultCode
, data
);
476 if (requestCode
== ACTION_SELECT_CONTENT_FROM_APPS
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
477 requestSimpleUpload(data
, resultCode
);
479 } else if (requestCode
== ACTION_SELECT_MULTIPLE_FILES
&& (resultCode
== RESULT_OK
|| resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)) {
480 requestMultipleUpload(data
, resultCode
);
485 private void requestMultipleUpload(Intent data
, int resultCode
) {
486 String
[] filePaths
= data
.getStringArrayExtra(UploadFilesActivity
.EXTRA_CHOSEN_FILES
);
487 if (filePaths
!= null
) {
488 String
[] remotePaths
= new String
[filePaths
.length
];
489 String remotePathBase
= "";
490 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
491 remotePathBase
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
493 if (!remotePathBase
.endsWith(OCFile
.PATH_SEPARATOR
))
494 remotePathBase
+= OCFile
.PATH_SEPARATOR
;
495 for (int j
= 0; j
< remotePaths
.length
; j
++) {
496 remotePaths
[j
] = remotePathBase
+ (new File(filePaths
[j
])).getName();
499 Intent i
= new Intent(this, FileUploader
.class);
500 i
.putExtra(FileUploader
.KEY_ACCOUNT
, getAccount());
501 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filePaths
);
502 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotePaths
);
503 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_MULTIPLE_FILES
);
504 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
505 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
509 Log_OC
.d(TAG
, "User clicked on 'Update' with no selection");
510 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_no_file_selected
), Toast
.LENGTH_LONG
);
517 private void requestSimpleUpload(Intent data
, int resultCode
) {
518 String filepath
= null
;
520 Uri selectedImageUri
= data
.getData();
522 String filemanagerstring
= selectedImageUri
.getPath();
523 String selectedImagePath
= getPath(selectedImageUri
);
525 if (selectedImagePath
!= null
)
526 filepath
= selectedImagePath
;
528 filepath
= filemanagerstring
;
530 } catch (Exception e
) {
531 Log_OC
.e(TAG
, "Unexpected exception when trying to read the result of Intent.ACTION_GET_CONTENT", e
);
535 if (filepath
== null
) {
536 Log_OC
.e(TAG
, "Couldnt resolve path to file");
537 Toast t
= Toast
.makeText(this, getString(R
.string
.filedisplay_unexpected_bad_get_content
), Toast
.LENGTH_LONG
);
543 Intent i
= new Intent(this, FileUploader
.class);
544 i
.putExtra(FileUploader
.KEY_ACCOUNT
,
546 String remotepath
= new String();
547 for (int j
= mDirectories
.getCount() - 2; j
>= 0; --j
) {
548 remotepath
+= OCFile
.PATH_SEPARATOR
+ mDirectories
.getItem(j
);
550 if (!remotepath
.endsWith(OCFile
.PATH_SEPARATOR
))
551 remotepath
+= OCFile
.PATH_SEPARATOR
;
552 remotepath
+= new File(filepath
).getName();
554 i
.putExtra(FileUploader
.KEY_LOCAL_FILE
, filepath
);
555 i
.putExtra(FileUploader
.KEY_REMOTE_FILE
, remotepath
);
556 i
.putExtra(FileUploader
.KEY_UPLOAD_TYPE
, FileUploader
.UPLOAD_SINGLE_FILE
);
557 if (resultCode
== UploadFilesActivity
.RESULT_OK_AND_MOVE
)
558 i
.putExtra(FileUploader
.KEY_LOCAL_BEHAVIOUR
, FileUploader
.LOCAL_BEHAVIOUR_MOVE
);
563 public void onBackPressed() {
564 OCFileListFragment listOfFiles
= getListOfFilesFragment();
565 if (mDualPane
|| getSecondFragment() == null
) {
566 if (listOfFiles
!= null
) { // should never be null, indeed
567 if (mDirectories
.getCount() <= 1) {
572 listOfFiles
.onBrowseUp();
575 if (listOfFiles
!= null
) { // should never be null, indeed
576 setFile(listOfFiles
.getCurrentFile());
578 cleanSecondFragment();
579 updateNavigationElementsInActionBar(null
);
583 protected void onSaveInstanceState(Bundle outState
) {
584 // responsibility of restore is preferred in onCreate() before than in onRestoreInstanceState when there are Fragments involved
585 Log_OC
.e(TAG
, "onSaveInstanceState() start");
586 super.onSaveInstanceState(outState
);
587 outState
.putParcelable(FileDisplayActivity
.KEY_WAITING_TO_PREVIEW
, mWaitingToPreview
);
588 Log_OC
.d(TAG
, "onSaveInstanceState() end");
592 protected void onStart() {
594 FileFragment second
= getSecondFragment();
595 updateFragmentsVisibility(second
!= null
);
596 updateNavigationElementsInActionBar((second
== null
) ? null
: second
.getFile());
600 protected void onResume() {
602 Log_OC
.e(TAG
, "onResume() start");
604 // Listen for sync messages
605 IntentFilter syncIntentFilter
= new IntentFilter(FileSyncService
.SYNC_MESSAGE
);
606 mSyncBroadcastReceiver
= new SyncBroadcastReceiver();
607 registerReceiver(mSyncBroadcastReceiver
, syncIntentFilter
);
609 // Listen for upload messages
610 IntentFilter uploadIntentFilter
= new IntentFilter(FileUploader
.UPLOAD_FINISH_MESSAGE
);
611 mUploadFinishReceiver
= new UploadFinishReceiver();
612 registerReceiver(mUploadFinishReceiver
, uploadIntentFilter
);
614 // Listen for download messages
615 IntentFilter downloadIntentFilter
= new IntentFilter(FileDownloader
.DOWNLOAD_ADDED_MESSAGE
);
616 downloadIntentFilter
.addAction(FileDownloader
.DOWNLOAD_FINISH_MESSAGE
);
617 mDownloadFinishReceiver
= new DownloadFinishReceiver();
618 registerReceiver(mDownloadFinishReceiver
, downloadIntentFilter
);
620 // List current directory
621 OCFileListFragment listOfFiles
= getListOfFilesFragment();
622 if (listOfFiles
!= null
) {
623 listOfFiles
.listDirectory(getCurrentDir()); // TODO we should find the way to avoid the need of this (maybe it's not necessary yet; to check)
626 Log_OC
.d(TAG
, "onResume() end");
631 protected void onPause() {
633 Log_OC
.e(TAG
, "onPause() start");
634 if (mSyncBroadcastReceiver
!= null
) {
635 unregisterReceiver(mSyncBroadcastReceiver
);
636 mSyncBroadcastReceiver
= null
;
638 if (mUploadFinishReceiver
!= null
) {
639 unregisterReceiver(mUploadFinishReceiver
);
640 mUploadFinishReceiver
= null
;
642 if (mDownloadFinishReceiver
!= null
) {
643 unregisterReceiver(mDownloadFinishReceiver
);
644 mDownloadFinishReceiver
= null
;
647 Log_OC
.d(TAG
, "onPause() end");
652 protected void onPrepareDialog(int id
, Dialog dialog
, Bundle args
) {
653 if (id
== DIALOG_SSL_VALIDATOR
&& mLastSslUntrustedServerResult
!= null
) {
654 ((SslValidatorDialog
)dialog
).updateResult(mLastSslUntrustedServerResult
);
660 protected Dialog
onCreateDialog(int id
) {
661 Dialog dialog
= null
;
662 AlertDialog
.Builder builder
;
664 case DIALOG_SHORT_WAIT
: {
665 ProgressDialog working_dialog
= new ProgressDialog(this);
666 working_dialog
.setMessage(getResources().getString(
667 R
.string
.wait_a_moment
));
668 working_dialog
.setIndeterminate(true
);
669 working_dialog
.setCancelable(false
);
670 dialog
= working_dialog
;
673 case DIALOG_CHOOSE_UPLOAD_SOURCE
: {
675 String
[] items
= null
;
677 String
[] allTheItems
= { getString(R
.string
.actionbar_upload_files
),
678 getString(R
.string
.actionbar_upload_from_apps
),
679 getString(R
.string
.actionbar_failed_instant_upload
) };
681 String
[] commonItems
= { getString(R
.string
.actionbar_upload_files
),
682 getString(R
.string
.actionbar_upload_from_apps
) };
684 if (InstantUploadActivity
.IS_ENABLED
)
689 builder
= new AlertDialog
.Builder(this);
690 builder
.setTitle(R
.string
.actionbar_upload
);
691 builder
.setItems(items
, new DialogInterface
.OnClickListener() {
692 public void onClick(DialogInterface dialog
, int item
) {
695 Intent action
= new Intent(FileDisplayActivity
.this, UploadFilesActivity
.class);
696 action
.putExtra(UploadFilesActivity
.EXTRA_ACCOUNT
, FileDisplayActivity
.this.getAccount());
697 startActivityForResult(action
, ACTION_SELECT_MULTIPLE_FILES
);
699 // TODO create and handle new fragment
700 // LocalFileListFragment
702 } else if (item
== 1) {
703 Intent action
= new Intent(Intent
.ACTION_GET_CONTENT
);
704 action
= action
.setType("*/*").addCategory(Intent
.CATEGORY_OPENABLE
);
705 startActivityForResult(Intent
.createChooser(action
, getString(R
.string
.upload_chooser_title
)),
706 ACTION_SELECT_CONTENT_FROM_APPS
);
707 } else if (item
== 2 && InstantUploadActivity
.IS_ENABLED
) {
708 Intent action
= new Intent(FileDisplayActivity
.this, InstantUploadActivity
.class);
709 action
.putExtra(FileUploader
.KEY_ACCOUNT
, FileDisplayActivity
.this.getAccount());
710 startActivity(action
);
714 dialog
= builder
.create();
717 case DIALOG_SSL_VALIDATOR
: {
718 dialog
= SslValidatorDialog
.newInstance(this, mLastSslUntrustedServerResult
, this);
721 case DIALOG_CERT_NOT_SAVED
: {
722 builder
= new AlertDialog
.Builder(this);
723 builder
.setMessage(getResources().getString(R
.string
.ssl_validator_not_saved
));
724 builder
.setCancelable(false
);
725 builder
.setPositiveButton(R
.string
.common_ok
, new DialogInterface
.OnClickListener() {
727 public void onClick(DialogInterface dialog
, int which
) {
731 dialog
= builder
.create();
743 * Translates a content URI of an image to a physical path
745 * @param uri The URI to resolve
746 * @return The path to the image or null if it could not be found
748 public String
getPath(Uri uri
) {
749 String
[] projection
= { MediaStore
.Images
.Media
.DATA
};
750 Cursor cursor
= managedQuery(uri
, projection
, null
, null
, null
);
751 if (cursor
!= null
) {
752 int column_index
= cursor
753 .getColumnIndexOrThrow(MediaStore
.Images
.Media
.DATA
);
754 cursor
.moveToFirst();
755 return cursor
.getString(column_index
);
761 * Pushes a directory to the drop down list
762 * @param directory to push
763 * @throws IllegalArgumentException If the {@link OCFile#isDirectory()} returns false.
765 public void pushDirname(OCFile directory
) {
766 if(!directory
.isDirectory()){
767 throw new IllegalArgumentException("Only directories may be pushed!");
769 mDirectories
.insert(directory
.getFileName(), 0);
774 * Pops a directory name from the drop down list
775 * @return True, unless the stack is empty
777 public boolean popDirname() {
778 mDirectories
.remove(mDirectories
.getItem(0));
779 return !mDirectories
.isEmpty();
782 // Custom array adapter to override text colors
783 private class CustomArrayAdapter
<T
> extends ArrayAdapter
<T
> {
785 public CustomArrayAdapter(FileDisplayActivity ctx
, int view
) {
789 public View
getView(int position
, View convertView
, ViewGroup parent
) {
790 View v
= super.getView(position
, convertView
, parent
);
792 ((TextView
) v
).setTextColor(getResources().getColorStateList(
793 android
.R
.color
.white
));
797 public View
getDropDownView(int position
, View convertView
,
799 View v
= super.getDropDownView(position
, convertView
, parent
);
801 ((TextView
) v
).setTextColor(getResources().getColorStateList(
802 android
.R
.color
.white
));
809 private class SyncBroadcastReceiver
extends BroadcastReceiver
{
812 * {@link BroadcastReceiver} to enable syncing feedback in UI
815 public void onReceive(Context context
, Intent intent
) {
816 boolean inProgress
= intent
.getBooleanExtra(FileSyncService
.IN_PROGRESS
, false
);
817 String accountName
= intent
.getStringExtra(FileSyncService
.ACCOUNT_NAME
);
819 Log_OC
.d(TAG
, "sync of account " + accountName
+ " is in_progress: " + inProgress
);
821 if (getAccount() != null
&& accountName
.equals(getAccount().name
)) {
823 String synchFolderRemotePath
= intent
.getStringExtra(FileSyncService
.SYNC_FOLDER_REMOTE_PATH
);
825 boolean fillBlankRoot
= false
;
826 OCFile currentDir
= getCurrentDir();
827 if (currentDir
== null
) {
828 currentDir
= mStorageManager
.getFileByPath(OCFile
.PATH_SEPARATOR
);
829 fillBlankRoot
= (currentDir
!= null
);
832 if ((synchFolderRemotePath
!= null
&& currentDir
!= null
&& (currentDir
.getRemotePath().equals(synchFolderRemotePath
)))
835 currentDir
= getStorageManager().getFileByPath(synchFolderRemotePath
);
836 OCFileListFragment fileListFragment
= getListOfFilesFragment();
837 if (fileListFragment
!= null
) {
838 fileListFragment
.listDirectory(currentDir
);
843 setSupportProgressBarIndeterminateVisibility(inProgress
);
844 removeStickyBroadcast(intent
);
848 RemoteOperationResult synchResult
= (RemoteOperationResult
)intent
.getSerializableExtra(FileSyncService
.SYNC_RESULT
);
849 if (synchResult
!= null
) {
850 if (synchResult
.getCode().equals(RemoteOperationResult
.ResultCode
.SSL_RECOVERABLE_PEER_UNVERIFIED
)) {
851 mLastSslUntrustedServerResult
= synchResult
;
852 showDialog(DIALOG_SSL_VALIDATOR
);
859 private class UploadFinishReceiver
extends BroadcastReceiver
{
861 * Once the file upload has finished -> update view
862 * @author David A. Velasco
863 * {@link BroadcastReceiver} to enable upload feedback in UI
866 public void onReceive(Context context
, Intent intent
) {
867 String uploadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
868 String accountName
= intent
.getStringExtra(FileUploader
.ACCOUNT_NAME
);
869 boolean sameAccount
= getAccount() != null
&& accountName
.equals(getAccount().name
);
870 OCFile currentDir
= getCurrentDir();
871 boolean isDescendant
= (currentDir
!= null
) && (uploadedRemotePath
!= null
) && (uploadedRemotePath
.startsWith(currentDir
.getRemotePath()));
872 if (sameAccount
&& isDescendant
) {
873 refeshListOfFilesFragment();
881 * Class waiting for broadcast events from the {@link FielDownloader} service.
883 * Updates the UI when a download is started or finished, provided that it is relevant for the
886 private class DownloadFinishReceiver
extends BroadcastReceiver
{
888 public void onReceive(Context context
, Intent intent
) {
889 boolean sameAccount
= isSameAccount(context
, intent
);
890 String downloadedRemotePath
= intent
.getStringExtra(FileDownloader
.EXTRA_REMOTE_PATH
);
891 boolean isDescendant
= isDescendant(downloadedRemotePath
);
893 if (sameAccount
&& isDescendant
) {
894 refeshListOfFilesFragment();
895 refreshSecondFragment(intent
.getAction(), downloadedRemotePath
, intent
.getBooleanExtra(FileDownloader
.EXTRA_DOWNLOAD_RESULT
, false
));
898 removeStickyBroadcast(intent
);
901 private boolean isDescendant(String downloadedRemotePath
) {
902 OCFile currentDir
= getCurrentDir();
903 return (currentDir
!= null
&& downloadedRemotePath
!= null
&& downloadedRemotePath
.startsWith(currentDir
.getRemotePath()));
906 private boolean isSameAccount(Context context
, Intent intent
) {
907 String accountName
= intent
.getStringExtra(FileDownloader
.ACCOUNT_NAME
);
908 return (accountName
!= null
&& getAccount() != null
&& accountName
.equals(getAccount().name
));
917 public DataStorageManager
getStorageManager() {
918 return mStorageManager
;
925 * Updates action bar and second fragment, if in dual pane mode.
928 public void onBrowsedDownTo(OCFile directory
) {
929 pushDirname(directory
);
930 cleanSecondFragment();
931 updateNavigationElementsInActionBar(null
);
935 * Opens the image gallery showing the image {@link OCFile} received as parameter.
937 * @param file Image {@link OCFile} to show.
940 public void startImagePreview(OCFile file
) {
941 Intent showDetailsIntent
= new Intent(this, PreviewImageActivity
.class);
942 showDetailsIntent
.putExtra(EXTRA_FILE
, file
);
943 showDetailsIntent
.putExtra(EXTRA_ACCOUNT
, getAccount());
944 startActivity(showDetailsIntent
);
948 * Stars the preview of an already down media {@link OCFile}.
950 * @param file Media {@link OCFile} to preview.
951 * @param startPlaybackPosition Media position where the playback will be started, in milliseconds.
952 * @param autoplay When 'true', the playback will start without user interactions.
955 public void startMediaPreview(OCFile file
, int startPlaybackPosition
, boolean autoplay
) {
956 Fragment mediaFragment
= new PreviewMediaFragment(file
, getAccount(), startPlaybackPosition
, autoplay
);
957 setSecondFragment(mediaFragment
);
958 updateFragmentsVisibility(true
);
959 updateNavigationElementsInActionBar(file
);
964 * Requests the download of the received {@link OCFile} , updates the UI
965 * to monitor the download progress and prepares the activity to preview
966 * or open the file when the download finishes.
968 * @param file {@link OCFile} to download and preview.
971 public void startDownloadForPreview(OCFile file
) {
972 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
973 setSecondFragment(detailFragment
);
974 mWaitingToPreview
= file
;
975 requestForDownload();
976 updateFragmentsVisibility(true
);
977 updateNavigationElementsInActionBar(file
);
983 * Shows the information of the {@link OCFile} received as a
984 * parameter in the second fragment.
986 * @param file {@link OCFile} whose details will be shown
989 public void showDetails(OCFile file
) {
990 Fragment detailFragment
= new FileDetailFragment(file
, getAccount());
991 setSecondFragment(detailFragment
);
992 updateFragmentsVisibility(true
);
993 updateNavigationElementsInActionBar(file
);
1001 private void updateNavigationElementsInActionBar(OCFile currentFile
) {
1002 ActionBar actionBar
= getSupportActionBar();
1003 if (currentFile
== null
|| mDualPane
) {
1004 // only list of files - set for browsing through folders
1005 OCFile currentDir
= getCurrentDir();
1006 actionBar
.setDisplayHomeAsUpEnabled(currentDir
!= null
&& currentDir
.getParentId() != 0);
1007 actionBar
.setDisplayShowTitleEnabled(false
);
1008 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_LIST
);
1009 actionBar
.setListNavigationCallbacks(mDirectories
, this); // assuming mDirectories is updated
1012 actionBar
.setDisplayHomeAsUpEnabled(true
);
1013 actionBar
.setDisplayShowTitleEnabled(true
);
1014 actionBar
.setTitle(currentFile
.getFileName());
1015 actionBar
.setNavigationMode(ActionBar
.NAVIGATION_MODE_STANDARD
);
1024 public OCFile
getInitialDirectory() {
1025 return getCurrentDir();
1033 public void onFileStateChanged() {
1034 refeshListOfFilesFragment();
1042 public FileDownloaderBinder
getFileDownloaderBinder() {
1043 return mDownloaderBinder
;
1051 public FileUploaderBinder
getFileUploaderBinder() {
1052 return mUploaderBinder
;
1056 /** Defines callbacks for service binding, passed to bindService() */
1057 private class ListServiceConnection
implements ServiceConnection
{
1060 public void onServiceConnected(ComponentName component
, IBinder service
) {
1061 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1062 Log_OC
.d(TAG
, "Download service connected");
1063 mDownloaderBinder
= (FileDownloaderBinder
) service
;
1064 if (mWaitingToPreview
!= null
) {
1065 requestForDownload();
1068 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1069 Log_OC
.d(TAG
, "Upload service connected");
1070 mUploaderBinder
= (FileUploaderBinder
) service
;
1074 // a new chance to get the mDownloadBinder through getFileDownloadBinder() - THIS IS A MESS
1075 OCFileListFragment listOfFiles
= getListOfFilesFragment();
1076 if (listOfFiles
!= null
) {
1077 listOfFiles
.listDirectory();
1079 FileFragment secondFragment
= getSecondFragment();
1080 if (secondFragment
!= null
&& secondFragment
instanceof FileDetailFragment
) {
1081 FileDetailFragment detailFragment
= (FileDetailFragment
)secondFragment
;
1082 detailFragment
.listenForTransferProgress();
1083 detailFragment
.updateFileDetails(false
, false
);
1088 public void onServiceDisconnected(ComponentName component
) {
1089 if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileDownloader
.class))) {
1090 Log_OC
.d(TAG
, "Download service disconnected");
1091 mDownloaderBinder
= null
;
1092 } else if (component
.equals(new ComponentName(FileDisplayActivity
.this, FileUploader
.class))) {
1093 Log_OC
.d(TAG
, "Upload service disconnected");
1094 mUploaderBinder
= null
;
1102 * Launch an intent to request the PIN code to the user before letting him use the app
1104 private void requestPinCode() {
1105 boolean pinStart
= false
;
1106 SharedPreferences appPrefs
= PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
1107 pinStart
= appPrefs
.getBoolean("set_pincode", false
);
1109 Intent i
= new Intent(getApplicationContext(), PinCodeActivity
.class);
1110 i
.putExtra(PinCodeActivity
.EXTRA_ACTIVITY
, "FileDisplayActivity");
1117 public void onSavedCertificate() {
1118 startSynchronization();
1123 public void onFailedSavingCertificate() {
1124 showDialog(DIALOG_CERT_NOT_SAVED
);
1129 * Updates the view associated to the activity after the finish of some operation over files
1130 * in the current account.
1132 * @param operation Removal operation performed.
1133 * @param result Result of the removal.
1136 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
1137 if (operation
instanceof RemoveFileOperation
) {
1138 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
1140 } else if (operation
instanceof RenameFileOperation
) {
1141 onRenameFileOperationFinish((RenameFileOperation
)operation
, result
);
1143 } else if (operation
instanceof SynchronizeFileOperation
) {
1144 onSynchronizeFileOperationFinish((SynchronizeFileOperation
)operation
, result
);
1146 } else if (operation
instanceof CreateFolderOperation
) {
1147 onCreateFolderOperationFinish((CreateFolderOperation
)operation
, result
);
1153 * Updates the view associated to the activity after the finish of an operation trying to remove a
1156 * @param operation Removal operation performed.
1157 * @param result Result of the removal.
1159 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
1160 dismissDialog(DIALOG_SHORT_WAIT
);
1161 if (result
.isSuccess()) {
1162 Toast msg
= Toast
.makeText(this, R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
1164 OCFile removedFile
= operation
.getFile();
1165 getSecondFragment();
1166 FileFragment second
= getSecondFragment();
1167 if (second
!= null
&& removedFile
.equals(second
.getFile())) {
1168 cleanSecondFragment();
1170 if (mStorageManager
.getFileById(removedFile
.getParentId()).equals(getCurrentDir())) {
1171 refeshListOfFilesFragment();
1175 Toast msg
= Toast
.makeText(this, R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
1177 if (result
.isSslRecoverableException()) {
1178 mLastSslUntrustedServerResult
= result
;
1179 showDialog(DIALOG_SSL_VALIDATOR
);
1185 * Updates the view associated to the activity after the finish of an operation trying create a new folder
1187 * @param operation Creation operation performed.
1188 * @param result Result of the creation.
1190 private void onCreateFolderOperationFinish(CreateFolderOperation operation
, RemoteOperationResult result
) {
1191 if (result
.isSuccess()) {
1192 dismissDialog(DIALOG_SHORT_WAIT
);
1193 refeshListOfFilesFragment();
1196 dismissDialog(DIALOG_SHORT_WAIT
);
1198 Toast msg
= Toast
.makeText(FileDisplayActivity
.this, R
.string
.create_dir_fail_msg
, Toast
.LENGTH_LONG
);
1201 } catch (NotFoundException e
) {
1202 Log_OC
.e(TAG
, "Error while trying to show fail message " , e
);
1209 * Updates the view associated to the activity after the finish of an operation trying to rename a
1212 * @param operation Renaming operation performed.
1213 * @param result Result of the renaming.
1215 private void onRenameFileOperationFinish(RenameFileOperation operation
, RemoteOperationResult result
) {
1216 dismissDialog(DIALOG_SHORT_WAIT
);
1217 OCFile renamedFile
= operation
.getFile();
1218 if (result
.isSuccess()) {
1220 FileFragment details
= getSecondFragment();
1221 if (details
!= null
&& details
instanceof FileDetailFragment
&& renamedFile
.equals(details
.getFile()) ) {
1222 ((FileDetailFragment
) details
).updateFileDetails(renamedFile
, getAccount());
1225 if (mStorageManager
.getFileById(renamedFile
.getParentId()).equals(getCurrentDir())) {
1226 refeshListOfFilesFragment();
1230 if (result
.getCode().equals(ResultCode
.INVALID_LOCAL_FILE_NAME
)) {
1231 Toast msg
= Toast
.makeText(this, R
.string
.rename_local_fail_msg
, Toast
.LENGTH_LONG
);
1233 // TODO throw again the new rename dialog
1235 Toast msg
= Toast
.makeText(this, R
.string
.rename_server_fail_msg
, Toast
.LENGTH_LONG
);
1237 if (result
.isSslRecoverableException()) {
1238 mLastSslUntrustedServerResult
= result
;
1239 showDialog(DIALOG_SSL_VALIDATOR
);
1246 private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation
, RemoteOperationResult result
) {
1247 dismissDialog(DIALOG_SHORT_WAIT
);
1248 OCFile syncedFile
= operation
.getLocalFile();
1249 if (!result
.isSuccess()) {
1250 if (result
.getCode() == ResultCode
.SYNC_CONFLICT
) {
1251 Intent i
= new Intent(this, ConflictsResolveActivity
.class);
1252 i
.putExtra(ConflictsResolveActivity
.EXTRA_FILE
, syncedFile
);
1253 i
.putExtra(ConflictsResolveActivity
.EXTRA_ACCOUNT
, getAccount());
1257 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_fail_msg
, Toast
.LENGTH_LONG
);
1262 if (operation
.transferWasRequested()) {
1263 refeshListOfFilesFragment();
1264 onTransferStateChanged(syncedFile
, true
, true
);
1267 Toast msg
= Toast
.makeText(this, R
.string
.sync_file_nothing_to_do_msg
, Toast
.LENGTH_LONG
);
1278 public void onTransferStateChanged(OCFile file
, boolean downloading
, boolean uploading
) {
1280 FileFragment details
= getSecondFragment();
1281 if (details
!= null
&& details
instanceof FileDetailFragment
&& file
.equals(details
.getFile()) ) {
1282 if (downloading
|| uploading
) {
1283 ((FileDetailFragment
)details
).updateFileDetails(file
, getAccount());
1285 ((FileDetailFragment
)details
).updateFileDetails(false
, true
);
1292 public void onDismiss(EditNameDialog dialog
) {
1293 if (dialog
.getResult()) {
1294 String newDirectoryName
= dialog
.getNewFilename().trim();
1295 Log_OC
.d(TAG
, "'create directory' dialog dismissed with new name " + newDirectoryName
);
1296 if (newDirectoryName
.length() > 0) {
1297 String path
= getCurrentDir().getRemotePath();
1300 path
+= newDirectoryName
+ OCFile
.PATH_SEPARATOR
;
1301 RemoteOperation operation
= new CreateFolderOperation(path
, getCurrentDir().getFileId(), mStorageManager
);
1302 operation
.execute( getAccount(),
1303 FileDisplayActivity
.this,
1304 FileDisplayActivity
.this,
1306 FileDisplayActivity
.this);
1308 showDialog(DIALOG_SHORT_WAIT
);
1314 private void requestForDownload() {
1315 Account account
= getAccount();
1316 if (!mDownloaderBinder
.isDownloading(account
, mWaitingToPreview
)) {
1317 Intent i
= new Intent(this, FileDownloader
.class);
1318 i
.putExtra(FileDownloader
.EXTRA_ACCOUNT
, account
);
1319 i
.putExtra(FileDownloader
.EXTRA_FILE
, mWaitingToPreview
);
1325 private OCFile
getCurrentDir() {
1326 OCFile file
= getFile();
1328 if (file
.isDirectory()) {
1331 return mStorageManager
.getFileById(file
.getParentId());