1 /* ownCloud Android client application 
   2  *   Copyright (C) 2012-2013 ownCloud Inc.  
   4  *   This program is free software: you can redistribute it and/or modify 
   5  *   it under the terms of the GNU General Public License as published by 
   6  *   the Free Software Foundation, either version 2 of the License, or 
   7  *   (at your option) any later version. 
   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/>. 
  18 package com
.owncloud
.android
.ui
.preview
; 
  21 import java
.util
.ArrayList
; 
  22 import java
.util
.List
; 
  24 import android
.accounts
.Account
; 
  25 import android
.app
.Activity
; 
  26 import android
.app
.AlertDialog
; 
  27 import android
.content
.ActivityNotFoundException
; 
  28 import android
.content
.ComponentName
; 
  29 import android
.content
.Context
; 
  30 import android
.content
.DialogInterface
; 
  31 import android
.content
.Intent
; 
  32 import android
.content
.ServiceConnection
; 
  33 import android
.media
.MediaPlayer
; 
  34 import android
.media
.MediaPlayer
.OnCompletionListener
; 
  35 import android
.media
.MediaPlayer
.OnErrorListener
; 
  36 import android
.media
.MediaPlayer
.OnPreparedListener
; 
  37 import android
.net
.Uri
; 
  38 import android
.os
.Build
; 
  39 import android
.os
.Bundle
; 
  40 import android
.os
.Handler
; 
  41 import android
.os
.IBinder
; 
  42 import android
.support
.v4
.app
.FragmentTransaction
; 
  43 import android
.util
.Log
; 
  44 import android
.view
.LayoutInflater
; 
  45 import android
.view
.MotionEvent
; 
  46 import android
.view
.View
; 
  47 import android
.view
.View
.OnTouchListener
; 
  48 import android
.view
.ViewGroup
; 
  49 import android
.webkit
.MimeTypeMap
; 
  50 import android
.widget
.ImageView
; 
  51 import android
.widget
.Toast
; 
  52 import android
.widget
.VideoView
; 
  54 import com
.actionbarsherlock
.app
.SherlockFragment
; 
  55 import com
.actionbarsherlock
.view
.Menu
; 
  56 import com
.actionbarsherlock
.view
.MenuInflater
; 
  57 import com
.actionbarsherlock
.view
.MenuItem
; 
  58 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
; 
  59 import com
.owncloud
.android
.datamodel
.OCFile
; 
  60 import com
.owncloud
.android
.media
.MediaControlView
; 
  61 import com
.owncloud
.android
.media
.MediaService
; 
  62 import com
.owncloud
.android
.media
.MediaServiceBinder
; 
  63 import com
.owncloud
.android
.network
.OwnCloudClientUtils
; 
  64 import com
.owncloud
.android
.operations
.OnRemoteOperationListener
; 
  65 import com
.owncloud
.android
.operations
.RemoteOperation
; 
  66 import com
.owncloud
.android
.operations
.RemoteOperationResult
; 
  67 import com
.owncloud
.android
.operations
.RemoveFileOperation
; 
  68 import com
.owncloud
.android
.ui
.activity
.FileDetailActivity
; 
  69 import com
.owncloud
.android
.ui
.activity
.FileDisplayActivity
; 
  70 import com
.owncloud
.android
.ui
.fragment
.ConfirmationDialogFragment
; 
  71 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
; 
  72 import com
.owncloud
.android
.ui
.fragment
.FileFragment
; 
  74 import com
.owncloud
.android
.R
; 
  75 import eu
.alefzero
.webdav
.WebdavClient
; 
  76 import eu
.alefzero
.webdav
.WebdavUtils
; 
  79  * This fragment shows a preview of a downloaded media file (audio or video). 
  81  * Trying to get an instance with NULL {@link OCFile} or ownCloud {@link Account} values will produce an {@link IllegalStateException}. 
  83  * By now, if the {@link OCFile} passed is not downloaded, an {@link IllegalStateException} is generated on instantiation too. 
  85  * @author David A. Velasco 
  87 public class PreviewMediaFragment 
extends SherlockFragment 
implements 
  88         OnTouchListener 
, FileFragment
,   
  89         ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
, OnRemoteOperationListener  
{ 
  91     public static final String EXTRA_FILE 
= "FILE"; 
  92     public static final String EXTRA_ACCOUNT 
= "ACCOUNT"; 
  93     private static final String EXTRA_PLAY_POSITION 
= "PLAY_POSITION"; 
  94     private static final String EXTRA_PLAYING 
= "PLAYING"; 
  98     private Account mAccount
; 
  99     private FileDataStorageManager mStorageManager
; 
 100     private ImageView mImagePreview
; 
 101     private VideoView mVideoPreview
; 
 102     private int mSavedPlaybackPosition
; 
 104     private Handler mHandler
; 
 105     private RemoteOperation mLastRemoteOperation
; 
 107     private MediaServiceBinder mMediaServiceBinder 
= null
; 
 108     private MediaControlView mMediaController 
= null
; 
 109     private MediaServiceConnection mMediaServiceConnection 
= null
; 
 110     private VideoHelper mVideoHelper
; 
 111     private boolean mAutoplay
; 
 113     private static final String TAG 
= PreviewMediaFragment
.class.getSimpleName(); 
 117      * Creates a fragment to preview a file. 
 119      * When 'fileToDetail' or 'ocAccount' are null 
 121      * @param fileToDetail      An {@link OCFile} to preview in the fragment 
 122      * @param ocAccount         An ownCloud account; needed to start downloads 
 124     public PreviewMediaFragment(OCFile fileToDetail
, Account ocAccount
) { 
 125         mFile 
= fileToDetail
; 
 126         mAccount 
= ocAccount
; 
 127         mSavedPlaybackPosition 
= 0; 
 128         mStorageManager 
= null
; // we need a context to init this; the container activity is not available yet at this moment  
 134      *  Creates an empty fragment for previews. 
 136      *  MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically (for instance, when the device is turned a aside). 
 138      *  DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction  
 140     public PreviewMediaFragment() { 
 143         mSavedPlaybackPosition 
= 0; 
 144         mStorageManager 
= null
; 
 153     public void onCreate(Bundle savedInstanceState
) { 
 154         super.onCreate(savedInstanceState
); 
 155         mHandler 
= new Handler(); 
 156         setHasOptionsMenu(true
); 
 164     public View 
onCreateView(LayoutInflater inflater
, ViewGroup container
, 
 165             Bundle savedInstanceState
) { 
 166         super.onCreateView(inflater
, container
, savedInstanceState
); 
 168         mView 
= inflater
.inflate(R
.layout
.file_preview
, container
, false
); 
 170         mImagePreview 
= (ImageView
)mView
.findViewById(R
.id
.image_preview
); 
 171         mVideoPreview 
= (VideoView
)mView
.findViewById(R
.id
.video_preview
); 
 172         mVideoPreview
.setOnTouchListener(this); 
 174         mMediaController 
= (MediaControlView
)mView
.findViewById(R
.id
.media_controller
); 
 184     public void onAttach(Activity activity
) { 
 185         super.onAttach(activity
); 
 186         if (!(activity 
instanceof FileFragment
.ContainerActivity
)) 
 187             throw new ClassCastException(activity
.toString() + " must implement " + FileFragment
.ContainerActivity
.class.getSimpleName()); 
 195     public void onActivityCreated(Bundle savedInstanceState
) { 
 196         super.onActivityCreated(savedInstanceState
); 
 198         mStorageManager 
= new FileDataStorageManager(mAccount
, getActivity().getApplicationContext().getContentResolver()); 
 199         if (savedInstanceState 
!= null
) { 
 200             mFile 
= savedInstanceState
.getParcelable(PreviewMediaFragment
.EXTRA_FILE
); 
 201             mAccount 
= savedInstanceState
.getParcelable(PreviewMediaFragment
.EXTRA_ACCOUNT
); 
 202             mSavedPlaybackPosition 
= savedInstanceState
.getInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
); 
 203             mAutoplay 
= savedInstanceState
.getBoolean(PreviewMediaFragment
.EXTRA_PLAYING
); 
 207             throw new IllegalStateException("Instanced with a NULL OCFile"); 
 209         if (mAccount 
== null
) { 
 210             throw new IllegalStateException("Instanced with a NULL ownCloud Account"); 
 212         if (!mFile
.isDown()) { 
 213             throw new IllegalStateException("There is no local file to preview"); 
 215         if (mFile
.isVideo()) { 
 216             mVideoPreview
.setVisibility(View
.VISIBLE
); 
 217             mImagePreview
.setVisibility(View
.GONE
); 
 221             mVideoPreview
.setVisibility(View
.GONE
); 
 222             mImagePreview
.setVisibility(View
.VISIBLE
); 
 232     public void onSaveInstanceState(Bundle outState
) { 
 233         super.onSaveInstanceState(outState
); 
 234         outState
.putParcelable(PreviewMediaFragment
.EXTRA_FILE
, mFile
); 
 235         outState
.putParcelable(PreviewMediaFragment
.EXTRA_ACCOUNT
, mAccount
); 
 237         if (mFile
.isVideo()) { 
 238             outState
.putInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION 
, mVideoPreview
.getCurrentPosition()); 
 239             outState
.putBoolean(PreviewMediaFragment
.EXTRA_PLAYING 
, mVideoPreview
.isPlaying()); 
 241             outState
.putInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION 
, mMediaServiceBinder
.getCurrentPosition()); 
 242             outState
.putBoolean(PreviewMediaFragment
.EXTRA_PLAYING 
, mMediaServiceBinder
.isPlaying()); 
 248     public void onStart() { 
 252            if (mFile
.isAudio()) { 
 255            } else if (mFile
.isVideo()) { 
 263     private void stopAudio() { 
 264         Intent i 
= new Intent(getSherlockActivity(), MediaService
.class); 
 265         i
.setAction(MediaService
.ACTION_STOP_ALL
); 
 266         getSherlockActivity().startService(i
); 
 274     public void onCreateOptionsMenu(Menu menu
, MenuInflater inflater
) { 
 275         super.onCreateOptionsMenu(menu
, inflater
); 
 277         inflater
.inflate(R
.menu
.file_actions_menu
, menu
); 
 278         List
<Integer
> toHide 
= new ArrayList
<Integer
>();     
 280         MenuItem item 
= null
; 
 281         toHide
.add(R
.id
.action_cancel_download
); 
 282         toHide
.add(R
.id
.action_cancel_upload
); 
 283         toHide
.add(R
.id
.action_download_file
); 
 284         toHide
.add(R
.id
.action_rename_file
);    // by now 
 286         for (int i 
: toHide
) { 
 287             item 
= menu
.findItem(i
); 
 289                 item
.setVisible(false
); 
 290                 item
.setEnabled(false
); 
 301     public boolean onOptionsItemSelected(MenuItem item
) { 
 302         switch (item
.getItemId()) { 
 303             case R
.id
.action_open_file_with
: { 
 307             case R
.id
.action_remove_file
: { 
 311             case R
.id
.action_see_details
: { 
 322     private void seeDetails() { 
 324         ((FileFragment
.ContainerActivity
)getActivity()).showFragmentWithDetails(mFile
);         
 328     private void prepareVideo() { 
 329         // create helper to get more control on the playback 
 330         mVideoHelper 
= new VideoHelper(); 
 331         mVideoPreview
.setOnPreparedListener(mVideoHelper
); 
 332         mVideoPreview
.setOnCompletionListener(mVideoHelper
); 
 333         mVideoPreview
.setOnErrorListener(mVideoHelper
); 
 336     private void playVideo() { 
 337         // create and prepare control panel for the user 
 338         mMediaController
.setMediaPlayer(mVideoPreview
); 
 340         // load the video file in the video player ; when done, VideoHelper#onPrepared() will be called 
 341         mVideoPreview
.setVideoPath(mFile
.getStoragePath());  
 345     private class VideoHelper 
implements OnCompletionListener
, OnPreparedListener
, OnErrorListener 
{ 
 348          * Called when the file is ready to be played. 
 350          * Just starts the playback. 
 352          * @param   mp    {@link MediaPlayer} instance performing the playback. 
 355         public void onPrepared(MediaPlayer vp
) { 
 356             Log
.e(TAG
, "onPrepared"); 
 357             mVideoPreview
.seekTo(mSavedPlaybackPosition
); 
 359                 mVideoPreview
.start(); 
 361             mMediaController
.setEnabled(true
); 
 362             mMediaController
.updatePausePlay(); 
 367          * Called when the file is finished playing. 
 369          * Finishes the activity. 
 371          * @param   mp    {@link MediaPlayer} instance performing the playback. 
 374         public void onCompletion(MediaPlayer  mp
) { 
 375             Log
.e(TAG
, "completed"); 
 377                 mVideoPreview
.seekTo(0); 
 378                 // next lines are necessary to work around undesired video loops 
 379                 if (Build
.VERSION
.SDK_INT 
== Build
.VERSION_CODES
.GINGERBREAD
) { 
 380                     mVideoPreview
.pause();    
 382                 } else if (Build
.VERSION
.SDK_INT 
== Build
.VERSION_CODES
.GINGERBREAD_MR1
) { 
 383                     // mVideePreview.pause() is not enough 
 385                     mMediaController
.setEnabled(false
); 
 386                     mVideoPreview
.stopPlayback(); 
 388                     mSavedPlaybackPosition 
= 0; 
 389                     mVideoPreview
.setVideoPath(mFile
.getStoragePath()); 
 391             } // else : called from onError() 
 392             mMediaController
.updatePausePlay(); 
 397          * Called when an error in playback occurs. 
 399          * @param   mp      {@link MediaPlayer} instance performing the playback. 
 400          * @param   what    Type of error 
 401          * @param   extra   Extra code specific to the error 
 404         public boolean onError(MediaPlayer mp
, int what
, int extra
) { 
 405             if (mVideoPreview
.getWindowToken() != null
) { 
 406                 String message 
= MediaService
.getMessageForMediaError(getActivity(), what
, extra
); 
 407                 new AlertDialog
.Builder(getActivity()) 
 409                         .setPositiveButton(android
.R
.string
.VideoView_error_button
, 
 410                                 new DialogInterface
.OnClickListener() { 
 411                                     public void onClick(DialogInterface dialog
, int whichButton
) { 
 413                                         VideoHelper
.this.onCompletion(null
); 
 416                         .setCancelable(false
) 
 426     public void onStop() { 
 429         if (mMediaServiceConnection 
!= null
) { 
 430             Log
.d(TAG
, "Unbinding from MediaService ..."); 
 431             if (mMediaServiceBinder 
!= null 
&& mMediaController 
!= null
) { 
 432                 mMediaServiceBinder
.unregisterMediaController(mMediaController
); 
 434             getActivity().unbindService(mMediaServiceConnection
); 
 435             mMediaServiceConnection 
= null
; 
 436             mMediaServiceBinder 
= null
; 
 441     public boolean onTouch(View v
, MotionEvent event
) { 
 442         if (event
.getAction() == MotionEvent
.ACTION_DOWN 
&& v 
== mVideoPreview
) { 
 443             startFullScreenVideo(); 
 450     private void startFullScreenVideo() { 
 451         Intent i 
= new Intent(getActivity(), PreviewVideoActivity
.class); 
 452         i
.putExtra(PreviewVideoActivity
.EXTRA_ACCOUNT
, mAccount
); 
 453         i
.putExtra(PreviewVideoActivity
.EXTRA_FILE
, mFile
); 
 454         i
.putExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, mVideoPreview
.isPlaying()); 
 455         mVideoPreview
.pause(); 
 456         i
.putExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, mVideoPreview
.getCurrentPosition()); 
 457         startActivityForResult(i
, 0); 
 462     public void onActivityResult (int requestCode
, int resultCode
, Intent data
) { 
 463         super.onActivityResult(requestCode
, resultCode
, data
); 
 464         if (resultCode 
== Activity
.RESULT_OK
) { 
 465             mSavedPlaybackPosition 
= data
.getExtras().getInt(PreviewVideoActivity
.EXTRA_START_POSITION
); 
 466             mAutoplay 
= data
.getExtras().getBoolean(PreviewVideoActivity
.EXTRA_AUTOPLAY
);  
 471     private void playAudio() { 
 472         if (!mMediaServiceBinder
.isPlaying(mFile
)) { 
 473             Log
.d(TAG
, "starting playback of " + mFile
.getStoragePath()); 
 474             mMediaServiceBinder
.start(mAccount
, mFile
, mAutoplay
, mSavedPlaybackPosition
); 
 477             if (!mMediaServiceBinder
.isPlaying() && mAutoplay
) { 
 478                 mMediaServiceBinder
.start(); 
 479                 mMediaController
.updatePausePlay(); 
 485     private void bindMediaService() { 
 486         Log
.d(TAG
, "Binding to MediaService..."); 
 487         if (mMediaServiceConnection 
== null
) { 
 488             mMediaServiceConnection 
= new MediaServiceConnection(); 
 490         getActivity().bindService(  new Intent(getActivity(),  
 492                                     mMediaServiceConnection
,  
 493                                     Context
.BIND_AUTO_CREATE
); 
 494             // follow the flow in MediaServiceConnection#onServiceConnected(...) 
 497     /** Defines callbacks for service binding, passed to bindService() */ 
 498     private class MediaServiceConnection 
implements ServiceConnection 
{ 
 501         public void onServiceConnected(ComponentName component
, IBinder service
) { 
 502             if (component
.equals(new ComponentName(getActivity(), MediaService
.class))) { 
 503                 Log
.d(TAG
, "Media service connected"); 
 504                 mMediaServiceBinder 
= (MediaServiceBinder
) service
; 
 505                 if (mMediaServiceBinder 
!= null
) { 
 506                     prepareMediaController(); 
 507                     playAudio();    // do not wait for the touch of nobody to play audio 
 509                     Log
.d(TAG
, "Successfully bound to MediaService, MediaController ready"); 
 512                     Log
.e(TAG
, "Unexpected response from MediaService while binding"); 
 517         private void prepareMediaController() { 
 518             mMediaServiceBinder
.registerMediaController(mMediaController
); 
 519             if (mMediaController 
!= null
) { 
 520                 mMediaController
.setMediaPlayer(mMediaServiceBinder
); 
 521                 mMediaController
.setEnabled(true
); 
 522                 mMediaController
.updatePausePlay(); 
 527         public void onServiceDisconnected(ComponentName component
) { 
 528             if (component
.equals(new ComponentName(getActivity(), MediaService
.class))) { 
 529                 Log
.e(TAG
, "Media service suddenly disconnected"); 
 530                 if (mMediaController 
!= null
) { 
 531                     mMediaController
.setMediaPlayer(null
); 
 533                     Toast
.makeText(getActivity(), "No media controller to release when disconnected from media service", Toast
.LENGTH_SHORT
).show(); 
 535                 mMediaServiceBinder 
= null
; 
 536                 mMediaServiceConnection 
= null
; 
 544      * Opens the previewed file with an external application. 
 546      * TODO - improve this; instead of prioritize the actions available for the MIME type in the server,  
 547      * we should get a list of available apps for MIME tpye in the server and join it with the list of  
 548      * available apps for the MIME type known from the file extension, to let the user choose 
 550     private void openFile() { 
 552         String storagePath 
= mFile
.getStoragePath(); 
 553         String encodedStoragePath 
= WebdavUtils
.encodePath(storagePath
); 
 555             Intent i 
= new Intent(Intent
.ACTION_VIEW
); 
 556             i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), mFile
.getMimetype()); 
 557             i
.setFlags(Intent
.FLAG_GRANT_READ_URI_PERMISSION 
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
); 
 560         } catch (Throwable t
) { 
 561             Log
.e(TAG
, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile
.getMimetype()); 
 562             boolean toastIt 
= true
;  
 563             String mimeType 
= ""; 
 565                 Intent i 
= new Intent(Intent
.ACTION_VIEW
); 
 566                 mimeType 
= MimeTypeMap
.getSingleton().getMimeTypeFromExtension(storagePath
.substring(storagePath
.lastIndexOf('.') + 1)); 
 567                 if (mimeType 
== null 
|| !mimeType
.equals(mFile
.getMimetype())) { 
 568                     if (mimeType 
!= null
) { 
 569                         i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), mimeType
); 
 572                         i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), "*-/*"); 
 574                     i
.setFlags(Intent
.FLAG_GRANT_READ_URI_PERMISSION 
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
); 
 579             } catch (IndexOutOfBoundsException e
) { 
 580                 Log
.e(TAG
, "Trying to find out MIME type of a file without extension: " + storagePath
); 
 582             } catch (ActivityNotFoundException e
) { 
 583                 Log
.e(TAG
, "No activity found to handle: " + storagePath 
+ " with MIME type " + mimeType 
+ " obtained from extension"); 
 585             } catch (Throwable th
) { 
 586                 Log
.e(TAG
, "Unexpected problem when opening: " + storagePath
, th
); 
 590                     Toast
.makeText(getActivity(), "There is no application to handle file " + mFile
.getFileName(), Toast
.LENGTH_SHORT
).show(); 
 599      * Starts a the removal of the previewed file. 
 601      * Shows a confirmation dialog. The action continues in {@link #onConfirmation(String)} , {@link #onNeutral(String)} or {@link #onCancel(String)}, 
 602      * depending upon the user selection in the dialog.  
 604     private void removeFile() { 
 605         ConfirmationDialogFragment confDialog 
= ConfirmationDialogFragment
.newInstance( 
 606                 R
.string
.confirmation_remove_alert
, 
 607                 new String
[]{mFile
.getFileName()}, 
 608                 R
.string
.confirmation_remove_remote_and_local
, 
 609                 R
.string
.confirmation_remove_local
, 
 610                 R
.string
.common_cancel
); 
 611         confDialog
.setOnConfirmationListener(this); 
 612         confDialog
.show(getFragmentManager(), ConfirmationDialogFragment
.FTAG_CONFIRMATION
); 
 617      * Performs the removal of the previewed file, both locally and in the server. 
 620     public void onConfirmation(String callerTag
) { 
 621         if (mStorageManager
.getFileById(mFile
.getFileId()) != null
) {   // check that the file is still there; 
 623             mLastRemoteOperation 
= new RemoveFileOperation( mFile
,      // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters 
 626             WebdavClient wc 
= OwnCloudClientUtils
.createOwnCloudClient(mAccount
, getSherlockActivity().getApplicationContext()); 
 627             mLastRemoteOperation
.execute(wc
, this, mHandler
); 
 629             boolean inDisplayActivity 
= getActivity() instanceof FileDisplayActivity
; 
 630             getActivity().showDialog((inDisplayActivity
)? FileDisplayActivity
.DIALOG_SHORT_WAIT 
: FileDetailActivity
.DIALOG_SHORT_WAIT
); 
 636      * Removes the file from local storage 
 639     public void onNeutral(String callerTag
) { 
 640         // TODO this code should be made in a secondary thread, 
 641         if (mFile
.isDown()) {   // checks it is still there 
 643             File f 
= new File(mFile
.getStoragePath()); 
 645             mFile
.setStoragePath(null
); 
 646             mStorageManager
.saveFile(mFile
); 
 652      * User cancelled the removal action. 
 655     public void onCancel(String callerTag
) { 
 656         // nothing to do here 
 663     public OCFile 
getFile(){ 
 669      * Use this method to signal this Activity that it shall update its view. 
 671      * @param file : An {@link OCFile} 
 673     public void updateFileDetails(OCFile file, Account ocAccount) { 
 675         if (ocAccount != null && (  
 676                 mStorageManager == null ||  
 677                 (mAccount != null && !mAccount.equals(ocAccount)) 
 679             mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver()); 
 681         mAccount = ocAccount; 
 682         updateFileDetails(false); 
 688      * Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment} to be previewed. 
 690      * @param file      File to test if can be previewed. 
 691      * @return          'True' if the file can be handled by the fragment. 
 693     public static boolean canBePreviewed(OCFile file
) { 
 694         return (file 
!= null 
&& (file
.isAudio() || file
.isVideo())); 
 701     public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) { 
 702         if (operation
.equals(mLastRemoteOperation
)) { 
 703             if (operation 
instanceof RemoveFileOperation
) { 
 704                 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
); 
 709     private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) { 
 710         boolean inDisplayActivity 
= getActivity() instanceof FileDisplayActivity
; 
 711         getActivity().dismissDialog((inDisplayActivity
)? FileDisplayActivity
.DIALOG_SHORT_WAIT 
: FileDetailActivity
.DIALOG_SHORT_WAIT
); 
 713         if (result
.isSuccess()) { 
 714             Toast msg 
= Toast
.makeText(getActivity().getApplicationContext(), R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
); 
 719             Toast msg 
= Toast
.makeText(getActivity(), R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);  
 721             if (result
.isSslRecoverableException()) { 
 722                 // TODO show the SSL warning dialog 
 727     private void stopPreview(boolean stopAudio
) { 
 728         if (mFile
.isAudio() && stopAudio
) { 
 729             mMediaServiceBinder
.pause(); 
 731         } else if (mFile
.isVideo()) { 
 732             mVideoPreview
.stopPlayback(); 
 739      * Finishes the preview 
 741     private void finish() { 
 742         Activity container 
= getActivity(); 
 743         if (container 
instanceof FileDisplayActivity
) { 
 745             FragmentTransaction transaction 
= getActivity().getSupportFragmentManager().beginTransaction(); 
 746             transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
); // empty FileDetailFragment 
 747             transaction
.commit(); 
 748             ((FileFragment
.ContainerActivity
)container
).onFileStateChanged();