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
.Bundle
; 
  39 import android
.os
.Handler
; 
  40 import android
.os
.IBinder
; 
  41 import android
.support
.v4
.app
.FragmentTransaction
; 
  42 import android
.util
.Log
; 
  43 import android
.view
.LayoutInflater
; 
  44 import android
.view
.MotionEvent
; 
  45 import android
.view
.View
; 
  46 import android
.view
.View
.OnTouchListener
; 
  47 import android
.view
.ViewGroup
; 
  48 import android
.webkit
.MimeTypeMap
; 
  49 import android
.widget
.ImageView
; 
  50 import android
.widget
.Toast
; 
  51 import android
.widget
.VideoView
; 
  53 import com
.actionbarsherlock
.app
.SherlockFragment
; 
  54 import com
.actionbarsherlock
.view
.Menu
; 
  55 import com
.actionbarsherlock
.view
.MenuInflater
; 
  56 import com
.actionbarsherlock
.view
.MenuItem
; 
  57 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
; 
  58 import com
.owncloud
.android
.datamodel
.OCFile
; 
  59 import com
.owncloud
.android
.media
.MediaControlView
; 
  60 import com
.owncloud
.android
.media
.MediaService
; 
  61 import com
.owncloud
.android
.media
.MediaServiceBinder
; 
  62 import com
.owncloud
.android
.network
.OwnCloudClientUtils
; 
  63 import com
.owncloud
.android
.operations
.OnRemoteOperationListener
; 
  64 import com
.owncloud
.android
.operations
.RemoteOperation
; 
  65 import com
.owncloud
.android
.operations
.RemoteOperationResult
; 
  66 import com
.owncloud
.android
.operations
.RemoveFileOperation
; 
  67 import com
.owncloud
.android
.ui
.activity
.FileDetailActivity
; 
  68 import com
.owncloud
.android
.ui
.activity
.FileDisplayActivity
; 
  69 import com
.owncloud
.android
.ui
.fragment
.ConfirmationDialogFragment
; 
  70 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
; 
  71 import com
.owncloud
.android
.ui
.fragment
.FileFragment
; 
  73 import com
.owncloud
.android
.R
; 
  74 import eu
.alefzero
.webdav
.WebdavClient
; 
  75 import eu
.alefzero
.webdav
.WebdavUtils
; 
  78  * This fragment shows a preview of a downloaded media file (audio or video). 
  80  * Trying to get an instance with NULL {@link OCFile} or ownCloud {@link Account} values will produce an {@link IllegalStateException}. 
  82  * By now, if the {@link OCFile} passed is not downloaded, an {@link IllegalStateException} is generated on instantiation too. 
  84  * @author David A. Velasco 
  86 public class PreviewMediaFragment 
extends SherlockFragment 
implements 
  87         OnTouchListener 
, FileFragment
,   
  88         ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
, OnRemoteOperationListener  
{ 
  90     public static final String EXTRA_FILE 
= "FILE"; 
  91     public static final String EXTRA_ACCOUNT 
= "ACCOUNT"; 
  92     private static final String EXTRA_PLAY_POSITION 
= "PLAY_POSITION"; 
  96     private Account mAccount
; 
  97     private FileDataStorageManager mStorageManager
; 
  98     private ImageView mImagePreview
; 
  99     private VideoView mVideoPreview
; 
 100     private int mSavedPlaybackPosition
; 
 102     private Handler mHandler
; 
 103     private RemoteOperation mLastRemoteOperation
; 
 105     private MediaServiceBinder mMediaServiceBinder 
= null
; 
 106     private MediaControlView mMediaController 
= null
; 
 107     private MediaServiceConnection mMediaServiceConnection 
= null
; 
 108     private VideoHelper mVideoHelper
; 
 110     private static final String TAG 
= PreviewMediaFragment
.class.getSimpleName(); 
 114      * Creates a fragment to preview a file. 
 116      * When 'fileToDetail' or 'ocAccount' are null 
 118      * @param fileToDetail      An {@link OCFile} to preview in the fragment 
 119      * @param ocAccount         An ownCloud account; needed to start downloads 
 121     public PreviewMediaFragment(OCFile fileToDetail
, Account ocAccount
) { 
 122         mFile 
= fileToDetail
; 
 123         mAccount 
= ocAccount
; 
 124         mSavedPlaybackPosition 
= 0; 
 125         mStorageManager 
= null
; // we need a context to init this; the container activity is not available yet at this moment  
 130      *  Creates an empty fragment for previews. 
 132      *  MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically (for instance, when the device is turned a aside). 
 134      *  DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction  
 136     public PreviewMediaFragment() { 
 139         mSavedPlaybackPosition 
= 0; 
 140         mStorageManager 
= null
; 
 148     public void onCreate(Bundle savedInstanceState
) { 
 149         super.onCreate(savedInstanceState
); 
 150         mHandler 
= new Handler(); 
 151         setHasOptionsMenu(true
); 
 159     public View 
onCreateView(LayoutInflater inflater
, ViewGroup container
, 
 160             Bundle savedInstanceState
) { 
 161         super.onCreateView(inflater
, container
, savedInstanceState
); 
 163         mView 
= inflater
.inflate(R
.layout
.file_preview
, container
, false
); 
 165         mImagePreview 
= (ImageView
)mView
.findViewById(R
.id
.image_preview
); 
 166         mImagePreview
.setOnTouchListener(this); 
 167         mVideoPreview 
= (VideoView
)mView
.findViewById(R
.id
.video_preview
); 
 169         mMediaController 
= (MediaControlView
)mView
.findViewById(R
.id
.media_controller
); 
 179     public void onAttach(Activity activity
) { 
 180         super.onAttach(activity
); 
 181         if (!(activity 
instanceof FileFragment
.ContainerActivity
)) 
 182             throw new ClassCastException(activity
.toString() + " must implement " + FileFragment
.ContainerActivity
.class.getSimpleName()); 
 190     public void onActivityCreated(Bundle savedInstanceState
) { 
 191         super.onActivityCreated(savedInstanceState
); 
 193         mStorageManager 
= new FileDataStorageManager(mAccount
, getActivity().getApplicationContext().getContentResolver()); 
 194         if (savedInstanceState 
!= null
) { 
 195             mFile 
= savedInstanceState
.getParcelable(PreviewMediaFragment
.EXTRA_FILE
); 
 196             mAccount 
= savedInstanceState
.getParcelable(PreviewMediaFragment
.EXTRA_ACCOUNT
); 
 197             mSavedPlaybackPosition 
= savedInstanceState
.getInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
); 
 201             throw new IllegalStateException("Instanced with a NULL OCFile"); 
 203         if (mAccount 
== null
) { 
 204             throw new IllegalStateException("Instanced with a NULL ownCloud Account"); 
 206         if (!mFile
.isDown()) { 
 207             throw new IllegalStateException("There is no local file to preview"); 
 209         if (mFile
.isVideo()) { 
 210             mVideoPreview
.setVisibility(View
.VISIBLE
); 
 211             mImagePreview
.setVisibility(View
.GONE
); 
 215             mVideoPreview
.setVisibility(View
.GONE
); 
 216             mImagePreview
.setVisibility(View
.VISIBLE
); 
 226     public void onSaveInstanceState(Bundle outState
) { 
 227         super.onSaveInstanceState(outState
); 
 229         outState
.putParcelable(PreviewMediaFragment
.EXTRA_FILE
, mFile
); 
 230         outState
.putParcelable(PreviewMediaFragment
.EXTRA_ACCOUNT
, mAccount
); 
 232         if (mVideoPreview
.isPlaying()) { 
 233             outState
.putInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION 
, mVideoPreview
.getCurrentPosition()); 
 239     public void onStart() { 
 243            if (mFile
.isAudio()) { 
 246            } else if (mFile
.isVideo()) { 
 254     private void stopAudio() { 
 255         Intent i 
= new Intent(getSherlockActivity(), MediaService
.class); 
 256         i
.setAction(MediaService
.ACTION_STOP_ALL
); 
 257         getSherlockActivity().startService(i
); 
 265     public void onCreateOptionsMenu(Menu menu
, MenuInflater inflater
) { 
 266         super.onCreateOptionsMenu(menu
, inflater
); 
 268         inflater
.inflate(R
.menu
.file_actions_menu
, menu
); 
 269         List
<Integer
> toHide 
= new ArrayList
<Integer
>();     
 271         MenuItem item 
= null
; 
 272         toHide
.add(R
.id
.action_cancel_download
); 
 273         toHide
.add(R
.id
.action_cancel_upload
); 
 274         toHide
.add(R
.id
.action_download_file
); 
 275         toHide
.add(R
.id
.action_rename_file
);    // by now 
 277         for (int i 
: toHide
) { 
 278             item 
= menu
.findItem(i
); 
 280                 item
.setVisible(false
); 
 281                 item
.setEnabled(false
); 
 292     public boolean onOptionsItemSelected(MenuItem item
) { 
 293         switch (item
.getItemId()) { 
 294             case R
.id
.action_open_file_with
: { 
 298             case R
.id
.action_remove_file
: { 
 302             case R
.id
.action_see_details
: { 
 313     private void seeDetails() { 
 315         ((FileFragment
.ContainerActivity
)getActivity()).showFragmentWithDetails(mFile
);         
 319     private void prepareVideo() { 
 320         // create helper to get more control on the playback 
 321         mVideoHelper 
= new VideoHelper(); 
 322         mVideoPreview
.setOnPreparedListener(mVideoHelper
); 
 323         mVideoPreview
.setOnCompletionListener(mVideoHelper
); 
 324         mVideoPreview
.setOnErrorListener(mVideoHelper
); 
 327     private void playVideo() { 
 328         // create and prepare control panel for the user 
 329         mMediaController
.setMediaPlayer(mVideoPreview
); 
 331         // load the video file in the video player ; when done, VideoHelper#onPrepared() will be called 
 332         mVideoPreview
.setVideoPath(mFile
.getStoragePath());  
 336     private class VideoHelper 
implements OnCompletionListener
, OnPreparedListener
, OnErrorListener 
{ 
 339          * Called when the file is ready to be played. 
 341          * Just starts the playback. 
 343          * @param   mp    {@link MediaPlayer} instance performing the playback. 
 346         public void onPrepared(MediaPlayer vp
) { 
 347             mVideoPreview
.seekTo(mSavedPlaybackPosition
); 
 348             mVideoPreview
.start(); 
 349             mMediaController
.setEnabled(true
); 
 350             mMediaController
.updatePausePlay(); 
 355          * Called when the file is finished playing. 
 357          * Finishes the activity. 
 359          * @param   mp    {@link MediaPlayer} instance performing the playback. 
 362         public void onCompletion(MediaPlayer  mp
) { 
 363             // nothing, right now 
 368          * Called when an error in playback occurs. 
 370          * @param   mp      {@link MediaPlayer} instance performing the playback. 
 371          * @param   what    Type of error 
 372          * @param   extra   Extra code specific to the error 
 375         public boolean onError(MediaPlayer mp
, int what
, int extra
) { 
 376             Log
.e(TAG
, "Error in video playback, what = " + what 
+ ", extra = " + extra
); 
 378             if (mVideoPreview
.getWindowToken() != null
) { 
 379                 String message 
= MediaService
.getMessageForMediaError(getActivity(), what
, extra
); 
 380                 new AlertDialog
.Builder(getActivity()) 
 382                         .setPositiveButton(android
.R
.string
.VideoView_error_button
, 
 383                                 new DialogInterface
.OnClickListener() { 
 384                                     public void onClick(DialogInterface dialog
, int whichButton
) { 
 386                                         VideoHelper
.this.onCompletion(null
); 
 389                         .setCancelable(false
) 
 399     public void onResume() { 
 405     public void onPause() { 
 411     public void onStop() { 
 413         if (mMediaServiceConnection 
!= null
) { 
 414             Log
.d(TAG
, "Unbinding from MediaService ..."); 
 415             if (mMediaServiceBinder 
!= null 
&& mMediaController 
!= null
) { 
 416                 mMediaServiceBinder
.unregisterMediaController(mMediaController
); 
 418             getActivity().unbindService(mMediaServiceConnection
); 
 419             mMediaServiceConnection 
= null
; 
 420             mMediaServiceBinder 
= null
; 
 425     public void onDestroy() { 
 431     public boolean onTouch(View v
, MotionEvent event
) { 
 432         if (event
.getAction() == MotionEvent
.ACTION_DOWN
) {  
 433             if (v 
== mImagePreview 
&& 
 434                     mMediaServiceBinder 
!= null 
&& mFile
.isAudio() && mMediaServiceBinder
.isPlaying(mFile
)) { 
 435                 toggleMediaController(MediaService
.MEDIA_CONTROL_PERMANENT
); 
 438             } else if (v 
== mVideoPreview
) { 
 439                 toggleMediaController(MediaService
.MEDIA_CONTROL_SHORT_LIFE
); 
 447     private void toggleMediaController(int time
) { 
 449         if (mMediaController.isShowing()) { 
 450             mMediaController.hide(); 
 452             mMediaController.show(time); 
 458     private void playAudio() { 
 459         if (!mMediaServiceBinder
.isPlaying(mFile
)) { 
 460             Log
.d(TAG
, "starting playback of " + mFile
.getStoragePath()); 
 461             mMediaServiceBinder
.start(mAccount
, mFile
); 
 464             if (!mMediaServiceBinder
.isPlaying()) { 
 465                 mMediaServiceBinder
.start(); 
 466                 mMediaController
.updatePausePlay(); 
 472     private void bindMediaService() { 
 473         Log
.d(TAG
, "Binding to MediaService..."); 
 474         if (mMediaServiceConnection 
== null
) { 
 475             mMediaServiceConnection 
= new MediaServiceConnection(); 
 477         getActivity().bindService(  new Intent(getActivity(),  
 479                                     mMediaServiceConnection
,  
 480                                     Context
.BIND_AUTO_CREATE
); 
 481             // follow the flow in MediaServiceConnection#onServiceConnected(...) 
 484     /** Defines callbacks for service binding, passed to bindService() */ 
 485     private class MediaServiceConnection 
implements ServiceConnection 
{ 
 488         public void onServiceConnected(ComponentName component
, IBinder service
) { 
 489             if (component
.equals(new ComponentName(getActivity(), MediaService
.class))) { 
 490                 Log
.d(TAG
, "Media service connected"); 
 491                 mMediaServiceBinder 
= (MediaServiceBinder
) service
; 
 492                 if (mMediaServiceBinder 
!= null
) { 
 493                     prepareMediaController(); 
 494                     playAudio();    // do not wait for the touch of nobody to play audio 
 496                     Log
.d(TAG
, "Successfully bound to MediaService, MediaController ready"); 
 499                     Log
.e(TAG
, "Unexpected response from MediaService while binding"); 
 504         private void prepareMediaController() { 
 505             mMediaServiceBinder
.registerMediaController(mMediaController
); 
 506             if (mMediaController 
!= null
) { 
 507                 mMediaController
.setMediaPlayer(mMediaServiceBinder
); 
 508                 mMediaController
.setEnabled(true
); 
 509                 mMediaController
.updatePausePlay(); 
 514         public void onServiceDisconnected(ComponentName component
) { 
 515             if (component
.equals(new ComponentName(getActivity(), MediaService
.class))) { 
 516                 Log
.e(TAG
, "Media service suddenly disconnected"); 
 517                 if (mMediaController 
!= null
) { 
 518                     mMediaController
.setMediaPlayer(null
); 
 520                     Toast
.makeText(getActivity(), "No media controller to release when disconnected from media service", Toast
.LENGTH_SHORT
).show(); 
 522                 mMediaServiceBinder 
= null
; 
 523                 mMediaServiceConnection 
= null
; 
 531      * Opens the previewed file with an external application. 
 533      * TODO - improve this; instead of prioritize the actions available for the MIME type in the server,  
 534      * we should get a list of available apps for MIME tpye in the server and join it with the list of  
 535      * available apps for the MIME type known from the file extension, to let the user choose 
 537     private void openFile() { 
 539         String storagePath 
= mFile
.getStoragePath(); 
 540         String encodedStoragePath 
= WebdavUtils
.encodePath(storagePath
); 
 542             Intent i 
= new Intent(Intent
.ACTION_VIEW
); 
 543             i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), mFile
.getMimetype()); 
 544             i
.setFlags(Intent
.FLAG_GRANT_READ_URI_PERMISSION 
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
); 
 547         } catch (Throwable t
) { 
 548             Log
.e(TAG
, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile
.getMimetype()); 
 549             boolean toastIt 
= true
;  
 550             String mimeType 
= ""; 
 552                 Intent i 
= new Intent(Intent
.ACTION_VIEW
); 
 553                 mimeType 
= MimeTypeMap
.getSingleton().getMimeTypeFromExtension(storagePath
.substring(storagePath
.lastIndexOf('.') + 1)); 
 554                 if (mimeType 
== null 
|| !mimeType
.equals(mFile
.getMimetype())) { 
 555                     if (mimeType 
!= null
) { 
 556                         i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), mimeType
); 
 559                         i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), "*-/*"); 
 561                     i
.setFlags(Intent
.FLAG_GRANT_READ_URI_PERMISSION 
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
); 
 566             } catch (IndexOutOfBoundsException e
) { 
 567                 Log
.e(TAG
, "Trying to find out MIME type of a file without extension: " + storagePath
); 
 569             } catch (ActivityNotFoundException e
) { 
 570                 Log
.e(TAG
, "No activity found to handle: " + storagePath 
+ " with MIME type " + mimeType 
+ " obtained from extension"); 
 572             } catch (Throwable th
) { 
 573                 Log
.e(TAG
, "Unexpected problem when opening: " + storagePath
, th
); 
 577                     Toast
.makeText(getActivity(), "There is no application to handle file " + mFile
.getFileName(), Toast
.LENGTH_SHORT
).show(); 
 586      * Starts a the removal of the previewed file. 
 588      * Shows a confirmation dialog. The action continues in {@link #onConfirmation(String)} , {@link #onNeutral(String)} or {@link #onCancel(String)}, 
 589      * depending upon the user selection in the dialog.  
 591     private void removeFile() { 
 592         ConfirmationDialogFragment confDialog 
= ConfirmationDialogFragment
.newInstance( 
 593                 R
.string
.confirmation_remove_alert
, 
 594                 new String
[]{mFile
.getFileName()}, 
 595                 R
.string
.confirmation_remove_remote_and_local
, 
 596                 R
.string
.confirmation_remove_local
, 
 597                 R
.string
.common_cancel
); 
 598         confDialog
.setOnConfirmationListener(this); 
 599         confDialog
.show(getFragmentManager(), ConfirmationDialogFragment
.FTAG_CONFIRMATION
); 
 604      * Performs the removal of the previewed file, both locally and in the server. 
 607     public void onConfirmation(String callerTag
) { 
 608         if (mStorageManager
.getFileById(mFile
.getFileId()) != null
) {   // check that the file is still there; 
 610             mLastRemoteOperation 
= new RemoveFileOperation( mFile
,      // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters 
 613             WebdavClient wc 
= OwnCloudClientUtils
.createOwnCloudClient(mAccount
, getSherlockActivity().getApplicationContext()); 
 614             mLastRemoteOperation
.execute(wc
, this, mHandler
); 
 616             boolean inDisplayActivity 
= getActivity() instanceof FileDisplayActivity
; 
 617             getActivity().showDialog((inDisplayActivity
)? FileDisplayActivity
.DIALOG_SHORT_WAIT 
: FileDetailActivity
.DIALOG_SHORT_WAIT
); 
 623      * Removes the file from local storage 
 626     public void onNeutral(String callerTag
) { 
 627         // TODO this code should be made in a secondary thread, 
 628         if (mFile
.isDown()) {   // checks it is still there 
 630             File f 
= new File(mFile
.getStoragePath()); 
 632             mFile
.setStoragePath(null
); 
 633             mStorageManager
.saveFile(mFile
); 
 639      * User cancelled the removal action. 
 642     public void onCancel(String callerTag
) { 
 643         // nothing to do here 
 650     public OCFile 
getFile(){ 
 656      * Use this method to signal this Activity that it shall update its view. 
 658      * @param file : An {@link OCFile} 
 660     public void updateFileDetails(OCFile file, Account ocAccount) { 
 662         if (ocAccount != null && (  
 663                 mStorageManager == null ||  
 664                 (mAccount != null && !mAccount.equals(ocAccount)) 
 666             mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver()); 
 668         mAccount = ocAccount; 
 669         updateFileDetails(false); 
 675      * Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment} to be previewed. 
 677      * @param file      File to test if can be previewed. 
 678      * @return          'True' if the file can be handled by the fragment. 
 680     public static boolean canBePreviewed(OCFile file
) { 
 681         return (file 
!= null 
&& (file
.isAudio() || file
.isVideo())); 
 688     public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) { 
 689         if (operation
.equals(mLastRemoteOperation
)) { 
 690             if (operation 
instanceof RemoveFileOperation
) { 
 691                 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
); 
 696     private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) { 
 697         boolean inDisplayActivity 
= getActivity() instanceof FileDisplayActivity
; 
 698         getActivity().dismissDialog((inDisplayActivity
)? FileDisplayActivity
.DIALOG_SHORT_WAIT 
: FileDetailActivity
.DIALOG_SHORT_WAIT
); 
 700         if (result
.isSuccess()) { 
 701             Toast msg 
= Toast
.makeText(getActivity().getApplicationContext(), R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
); 
 706             Toast msg 
= Toast
.makeText(getActivity(), R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);  
 708             if (result
.isSslRecoverableException()) { 
 709                 // TODO show the SSL warning dialog 
 714     private void stopPreview(boolean stopAudio
) { 
 715         if (mFile
.isAudio() && stopAudio
) { 
 716             mMediaServiceBinder
.pause(); 
 718         } else if (mFile
.isVideo()) { 
 719             mVideoPreview
.stopPlayback(); 
 726      * Finishes the preview 
 728     private void finish() { 
 729         Activity container 
= getActivity(); 
 730         if (container 
instanceof FileDisplayActivity
) { 
 732             FragmentTransaction transaction 
= getActivity().getSupportFragmentManager().beginTransaction(); 
 733             transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
); // empty FileDetailFragment 
 734             transaction
.commit(); 
 735             ((FileFragment
.ContainerActivity
)container
).onFileStateChanged();