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 version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package com
.owncloud
.android
.ui
.preview
;
19 import java
.util
.ArrayList
;
20 import java
.util
.List
;
22 import android
.accounts
.Account
;
23 import android
.app
.Activity
;
24 import android
.app
.AlertDialog
;
25 import android
.content
.ActivityNotFoundException
;
26 import android
.content
.ComponentName
;
27 import android
.content
.Context
;
28 import android
.content
.DialogInterface
;
29 import android
.content
.Intent
;
30 import android
.content
.ServiceConnection
;
31 import android
.content
.res
.Configuration
;
32 import android
.media
.MediaPlayer
;
33 import android
.media
.MediaPlayer
.OnCompletionListener
;
34 import android
.media
.MediaPlayer
.OnErrorListener
;
35 import android
.media
.MediaPlayer
.OnPreparedListener
;
36 import android
.net
.Uri
;
37 import android
.os
.Build
;
38 import android
.os
.Bundle
;
39 import android
.os
.Handler
;
40 import android
.os
.IBinder
;
41 import android
.view
.LayoutInflater
;
42 import android
.view
.MotionEvent
;
43 import android
.view
.View
;
44 import android
.view
.View
.OnTouchListener
;
45 import android
.view
.ViewGroup
;
46 import android
.webkit
.MimeTypeMap
;
47 import android
.widget
.ImageView
;
48 import android
.widget
.Toast
;
49 import android
.widget
.VideoView
;
51 import com
.actionbarsherlock
.view
.Menu
;
52 import com
.actionbarsherlock
.view
.MenuInflater
;
53 import com
.actionbarsherlock
.view
.MenuItem
;
54 import com
.owncloud
.android
.R
;
55 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
;
56 import com
.owncloud
.android
.datamodel
.OCFile
;
57 import com
.owncloud
.android
.media
.MediaControlView
;
58 import com
.owncloud
.android
.media
.MediaService
;
59 import com
.owncloud
.android
.media
.MediaServiceBinder
;
60 import com
.owncloud
.android
.lib
.common
.network
.WebdavUtils
;
61 import com
.owncloud
.android
.lib
.common
.operations
.OnRemoteOperationListener
;
62 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperation
;
63 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
64 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
65 import com
.owncloud
.android
.ui
.activity
.FileActivity
;
66 import com
.owncloud
.android
.ui
.activity
.FileDisplayActivity
;
67 import com
.owncloud
.android
.ui
.fragment
.ConfirmationDialogFragment
;
68 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
69 import com
.owncloud
.android
.utils
.Log_OC
;
73 * This fragment shows a preview of a downloaded media file (audio or video).
75 * Trying to get an instance with NULL {@link OCFile} or ownCloud {@link Account} values will produce an {@link IllegalStateException}.
77 * By now, if the {@link OCFile} passed is not downloaded, an {@link IllegalStateException} is generated on instantiation too.
79 * @author David A. Velasco
81 public class PreviewMediaFragment
extends FileFragment
implements
83 ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
, OnRemoteOperationListener
{
85 public static final String EXTRA_FILE
= "FILE";
86 public static final String EXTRA_ACCOUNT
= "ACCOUNT";
87 private static final String EXTRA_PLAY_POSITION
= "PLAY_POSITION";
88 private static final String EXTRA_PLAYING
= "PLAYING";
91 private Account mAccount
;
92 private FileDataStorageManager mStorageManager
;
93 private ImageView mImagePreview
;
94 private VideoView mVideoPreview
;
95 private int mSavedPlaybackPosition
;
97 private Handler mHandler
;
98 private RemoteOperation mLastRemoteOperation
;
100 private MediaServiceBinder mMediaServiceBinder
= null
;
101 private MediaControlView mMediaController
= null
;
102 private MediaServiceConnection mMediaServiceConnection
= null
;
103 private VideoHelper mVideoHelper
;
104 private boolean mAutoplay
;
105 public boolean mPrepared
;
107 private static final String TAG
= PreviewMediaFragment
.class.getSimpleName();
111 * Creates a fragment to preview a file.
113 * When 'fileToDetail' or 'ocAccount' are null
115 * @param fileToDetail An {@link OCFile} to preview in the fragment
116 * @param ocAccount An ownCloud account; needed to start downloads
118 public PreviewMediaFragment(OCFile fileToDetail
, Account ocAccount
, int startPlaybackPosition
, boolean autoplay
) {
120 mAccount
= ocAccount
;
121 mSavedPlaybackPosition
= startPlaybackPosition
;
122 mStorageManager
= null
; // we need a context to init this; the container activity is not available yet at this moment
123 mAutoplay
= autoplay
;
128 * Creates an empty fragment for previews.
130 * MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically (for instance, when the device is turned a aside).
132 * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction
134 public PreviewMediaFragment() {
137 mSavedPlaybackPosition
= 0;
138 mStorageManager
= null
;
147 public void onCreate(Bundle savedInstanceState
) {
148 super.onCreate(savedInstanceState
);
149 mHandler
= new Handler();
150 setHasOptionsMenu(true
);
158 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
159 Bundle savedInstanceState
) {
160 super.onCreateView(inflater
, container
, savedInstanceState
);
161 Log_OC
.e(TAG
, "onCreateView");
164 mView
= inflater
.inflate(R
.layout
.file_preview
, container
, false
);
166 mImagePreview
= (ImageView
)mView
.findViewById(R
.id
.image_preview
);
167 mVideoPreview
= (VideoView
)mView
.findViewById(R
.id
.video_preview
);
168 mVideoPreview
.setOnTouchListener(this);
170 mMediaController
= (MediaControlView
)mView
.findViewById(R
.id
.media_controller
);
180 public void onAttach(Activity activity
) {
181 super.onAttach(activity
);
182 Log_OC
.e(TAG
, "onAttach");
184 if (!(activity
instanceof FileFragment
.ContainerActivity
))
185 throw new ClassCastException(activity
.toString() + " must implement " + FileFragment
.ContainerActivity
.class.getSimpleName());
193 public void onActivityCreated(Bundle savedInstanceState
) {
194 super.onActivityCreated(savedInstanceState
);
195 Log_OC
.e(TAG
, "onActivityCreated");
197 mStorageManager
= new FileDataStorageManager(mAccount
, getActivity().getApplicationContext().getContentResolver());
198 if (savedInstanceState
!= null
) {
199 setFile((OCFile
)savedInstanceState
.getParcelable(PreviewMediaFragment
.EXTRA_FILE
));
200 mAccount
= savedInstanceState
.getParcelable(PreviewMediaFragment
.EXTRA_ACCOUNT
);
201 mSavedPlaybackPosition
= savedInstanceState
.getInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
);
202 mAutoplay
= savedInstanceState
.getBoolean(PreviewMediaFragment
.EXTRA_PLAYING
);
205 OCFile file
= getFile();
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 (!file
.isDown()) {
213 throw new IllegalStateException("There is no local file to preview");
215 if (file
.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 Log_OC
.e(TAG
, "onSaveInstanceState");
236 outState
.putParcelable(PreviewMediaFragment
.EXTRA_FILE
, getFile());
237 outState
.putParcelable(PreviewMediaFragment
.EXTRA_ACCOUNT
, mAccount
);
239 if (getFile().isVideo()) {
240 mSavedPlaybackPosition
= mVideoPreview
.getCurrentPosition();
241 mAutoplay
= mVideoPreview
.isPlaying();
242 outState
.putInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
, mSavedPlaybackPosition
);
243 outState
.putBoolean(PreviewMediaFragment
.EXTRA_PLAYING
, mAutoplay
);
245 outState
.putInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
, mMediaServiceBinder
.getCurrentPosition());
246 outState
.putBoolean(PreviewMediaFragment
.EXTRA_PLAYING
, mMediaServiceBinder
.isPlaying());
252 public void onStart() {
254 Log_OC
.e(TAG
, "onStart");
256 OCFile file
= getFile();
258 if (file
.isAudio()) {
261 } else if (file
.isVideo()) {
269 private void stopAudio() {
270 Intent i
= new Intent(getSherlockActivity(), MediaService
.class);
271 i
.setAction(MediaService
.ACTION_STOP_ALL
);
272 getSherlockActivity().startService(i
);
280 public void onCreateOptionsMenu(Menu menu
, MenuInflater inflater
) {
281 super.onCreateOptionsMenu(menu
, inflater
);
283 inflater
.inflate(R
.menu
.file_actions_menu
, menu
);
284 List
<Integer
> toHide
= new ArrayList
<Integer
>();
286 MenuItem item
= null
;
287 toHide
.add(R
.id
.action_cancel_download
);
288 toHide
.add(R
.id
.action_cancel_upload
);
289 toHide
.add(R
.id
.action_download_file
);
290 toHide
.add(R
.id
.action_sync_file
);
291 toHide
.add(R
.id
.action_rename_file
); // by now
294 if (!getFile().isShareByLink()) {
295 toHide
.add(R
.id
.action_unshare_file
);
299 boolean sendEnabled
= getString(R
.string
.send_files_to_other_apps
).equalsIgnoreCase("on");
301 toHide
.add(R
.id
.action_send_file
);
304 for (int i
: toHide
) {
305 item
= menu
.findItem(i
);
307 item
.setVisible(false
);
308 item
.setEnabled(false
);
319 public void onPrepareOptionsMenu(Menu menu
) {
320 super.onPrepareOptionsMenu(menu
);
322 MenuItem item
= menu
.findItem(R
.id
.action_unshare_file
);
324 if (!getFile().isShareByLink()) {
325 item
.setVisible(false
);
326 item
.setEnabled(false
);
328 item
.setVisible(true
);
329 item
.setEnabled(true
);
338 public boolean onOptionsItemSelected(MenuItem item
) {
339 switch (item
.getItemId()) {
340 case R
.id
.action_share_file
: {
344 case R
.id
.action_unshare_file
: {
345 unshareFileWithLink();
348 case R
.id
.action_open_file_with
: {
352 case R
.id
.action_remove_file
: {
356 case R
.id
.action_see_details
: {
360 case R
.id
.action_send_file
: {
372 * Update the file of the fragment with file value
375 public void updateFile(OCFile file
){
379 private void unshareFileWithLink() {
381 FileActivity activity
= (FileActivity
)((FileFragment
.ContainerActivity
)getActivity());
382 activity
.getFileOperationsHelper().unshareFileWithLink(getFile(), activity
);
385 private void shareFileWithLink() {
387 FileActivity activity
= (FileActivity
)((FileFragment
.ContainerActivity
)getActivity());
388 activity
.getFileOperationsHelper().shareFileWithLink(getFile(), activity
);
392 private void sendFile() {
394 FileActivity activity
= (FileActivity
)((FileFragment
.ContainerActivity
)getActivity());
395 activity
.getFileOperationsHelper().sendDownloadedFile(getFile(), activity
);
399 private void seeDetails() {
401 ((FileFragment
.ContainerActivity
)getActivity()).showDetails(getFile());
405 private void prepareVideo() {
406 // create helper to get more control on the playback
407 mVideoHelper
= new VideoHelper();
408 mVideoPreview
.setOnPreparedListener(mVideoHelper
);
409 mVideoPreview
.setOnCompletionListener(mVideoHelper
);
410 mVideoPreview
.setOnErrorListener(mVideoHelper
);
413 private void playVideo() {
414 // create and prepare control panel for the user
415 mMediaController
.setMediaPlayer(mVideoPreview
);
417 // load the video file in the video player ; when done, VideoHelper#onPrepared() will be called
418 mVideoPreview
.setVideoPath(getFile().getStoragePath());
422 private class VideoHelper
implements OnCompletionListener
, OnPreparedListener
, OnErrorListener
{
425 * Called when the file is ready to be played.
427 * Just starts the playback.
429 * @param mp {@link MediaPlayer} instance performing the playback.
432 public void onPrepared(MediaPlayer vp
) {
433 Log_OC
.e(TAG
, "onPrepared");
434 mVideoPreview
.seekTo(mSavedPlaybackPosition
);
436 mVideoPreview
.start();
438 mMediaController
.setEnabled(true
);
439 mMediaController
.updatePausePlay();
445 * Called when the file is finished playing.
447 * Finishes the activity.
449 * @param mp {@link MediaPlayer} instance performing the playback.
452 public void onCompletion(MediaPlayer mp
) {
453 Log_OC
.e(TAG
, "completed");
455 mVideoPreview
.seekTo(0);
456 // next lines are necessary to work around undesired video loops
457 if (Build
.VERSION
.SDK_INT
== Build
.VERSION_CODES
.GINGERBREAD
) {
458 mVideoPreview
.pause();
460 } else if (Build
.VERSION
.SDK_INT
== Build
.VERSION_CODES
.GINGERBREAD_MR1
) {
461 // mVideePreview.pause() is not enough
463 mMediaController
.setEnabled(false
);
464 mVideoPreview
.stopPlayback();
466 mSavedPlaybackPosition
= 0;
467 mVideoPreview
.setVideoPath(getFile().getStoragePath());
469 } // else : called from onError()
470 mMediaController
.updatePausePlay();
475 * Called when an error in playback occurs.
477 * @param mp {@link MediaPlayer} instance performing the playback.
478 * @param what Type of error
479 * @param extra Extra code specific to the error
482 public boolean onError(MediaPlayer mp
, int what
, int extra
) {
483 if (mVideoPreview
.getWindowToken() != null
) {
484 String message
= MediaService
.getMessageForMediaError(getActivity(), what
, extra
);
485 new AlertDialog
.Builder(getActivity())
487 .setPositiveButton(android
.R
.string
.VideoView_error_button
,
488 new DialogInterface
.OnClickListener() {
489 public void onClick(DialogInterface dialog
, int whichButton
) {
491 VideoHelper
.this.onCompletion(null
);
494 .setCancelable(false
)
504 public void onPause() {
506 Log_OC
.e(TAG
, "onPause");
510 public void onResume() {
512 Log_OC
.e(TAG
, "onResume");
516 public void onDestroy() {
518 Log_OC
.e(TAG
, "onDestroy");
522 public void onStop() {
523 Log_OC
.e(TAG
, "onStop");
527 if (mMediaServiceConnection
!= null
) {
528 Log_OC
.d(TAG
, "Unbinding from MediaService ...");
529 if (mMediaServiceBinder
!= null
&& mMediaController
!= null
) {
530 mMediaServiceBinder
.unregisterMediaController(mMediaController
);
532 getActivity().unbindService(mMediaServiceConnection
);
533 mMediaServiceConnection
= null
;
534 mMediaServiceBinder
= null
;
539 public boolean onTouch(View v
, MotionEvent event
) {
540 if (event
.getAction() == MotionEvent
.ACTION_DOWN
&& v
== mVideoPreview
) {
541 startFullScreenVideo();
548 private void startFullScreenVideo() {
549 Intent i
= new Intent(getActivity(), PreviewVideoActivity
.class);
550 i
.putExtra(FileActivity
.EXTRA_ACCOUNT
, mAccount
);
551 i
.putExtra(FileActivity
.EXTRA_FILE
, getFile());
552 i
.putExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, mVideoPreview
.isPlaying());
553 mVideoPreview
.pause();
554 i
.putExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, mVideoPreview
.getCurrentPosition());
555 startActivityForResult(i
, 0);
559 public void onConfigurationChanged (Configuration newConfig
) {
560 Log_OC
.e(TAG
, "onConfigurationChanged " + this);
564 public void onActivityResult (int requestCode
, int resultCode
, Intent data
) {
565 Log_OC
.e(TAG
, "onActivityResult " + this);
566 super.onActivityResult(requestCode
, resultCode
, data
);
567 if (resultCode
== Activity
.RESULT_OK
) {
568 mSavedPlaybackPosition
= data
.getExtras().getInt(PreviewVideoActivity
.EXTRA_START_POSITION
);
569 mAutoplay
= data
.getExtras().getBoolean(PreviewVideoActivity
.EXTRA_AUTOPLAY
);
574 private void playAudio() {
575 OCFile file
= getFile();
576 if (!mMediaServiceBinder
.isPlaying(file
)) {
577 Log_OC
.d(TAG
, "starting playback of " + file
.getStoragePath());
578 mMediaServiceBinder
.start(mAccount
, file
, mAutoplay
, mSavedPlaybackPosition
);
581 if (!mMediaServiceBinder
.isPlaying() && mAutoplay
) {
582 mMediaServiceBinder
.start();
583 mMediaController
.updatePausePlay();
589 private void bindMediaService() {
590 Log_OC
.d(TAG
, "Binding to MediaService...");
591 if (mMediaServiceConnection
== null
) {
592 mMediaServiceConnection
= new MediaServiceConnection();
594 getActivity().bindService( new Intent(getActivity(),
596 mMediaServiceConnection
,
597 Context
.BIND_AUTO_CREATE
);
598 // follow the flow in MediaServiceConnection#onServiceConnected(...)
601 /** Defines callbacks for service binding, passed to bindService() */
602 private class MediaServiceConnection
implements ServiceConnection
{
605 public void onServiceConnected(ComponentName component
, IBinder service
) {
606 if (getActivity() != null
) {
607 if (component
.equals(new ComponentName(getActivity(), MediaService
.class))) {
608 Log_OC
.d(TAG
, "Media service connected");
609 mMediaServiceBinder
= (MediaServiceBinder
) service
;
610 if (mMediaServiceBinder
!= null
) {
611 prepareMediaController();
612 playAudio(); // do not wait for the touch of nobody to play audio
614 Log_OC
.d(TAG
, "Successfully bound to MediaService, MediaController ready");
617 Log_OC
.e(TAG
, "Unexpected response from MediaService while binding");
623 private void prepareMediaController() {
624 mMediaServiceBinder
.registerMediaController(mMediaController
);
625 if (mMediaController
!= null
) {
626 mMediaController
.setMediaPlayer(mMediaServiceBinder
);
627 mMediaController
.setEnabled(true
);
628 mMediaController
.updatePausePlay();
633 public void onServiceDisconnected(ComponentName component
) {
634 if (component
.equals(new ComponentName(getActivity(), MediaService
.class))) {
635 Log_OC
.e(TAG
, "Media service suddenly disconnected");
636 if (mMediaController
!= null
) {
637 mMediaController
.setMediaPlayer(null
);
639 Toast
.makeText(getActivity(), "No media controller to release when disconnected from media service", Toast
.LENGTH_SHORT
).show();
641 mMediaServiceBinder
= null
;
642 mMediaServiceConnection
= null
;
650 * Opens the previewed file with an external application.
652 * TODO - improve this; instead of prioritize the actions available for the MIME type in the server,
653 * we should get a list of available apps for MIME tpye in the server and join it with the list of
654 * available apps for the MIME type known from the file extension, to let the user choose
656 private void openFile() {
657 OCFile file
= getFile();
659 String storagePath
= file
.getStoragePath();
660 String encodedStoragePath
= WebdavUtils
.encodePath(storagePath
);
662 Intent i
= new Intent(Intent
.ACTION_VIEW
);
663 i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), file
.getMimetype());
664 i
.setFlags(Intent
.FLAG_GRANT_READ_URI_PERMISSION
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
);
667 } catch (Throwable t
) {
668 Log_OC
.e(TAG
, "Fail when trying to open with the mimeType provided from the ownCloud server: " + file
.getMimetype());
669 boolean toastIt
= true
;
670 String mimeType
= "";
672 Intent i
= new Intent(Intent
.ACTION_VIEW
);
673 mimeType
= MimeTypeMap
.getSingleton().getMimeTypeFromExtension(storagePath
.substring(storagePath
.lastIndexOf('.') + 1));
674 if (mimeType
== null
|| !mimeType
.equals(file
.getMimetype())) {
675 if (mimeType
!= null
) {
676 i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), mimeType
);
679 i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), "*-/*");
681 i
.setFlags(Intent
.FLAG_GRANT_READ_URI_PERMISSION
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
);
686 } catch (IndexOutOfBoundsException e
) {
687 Log_OC
.e(TAG
, "Trying to find out MIME type of a file without extension: " + storagePath
);
689 } catch (ActivityNotFoundException e
) {
690 Log_OC
.e(TAG
, "No activity found to handle: " + storagePath
+ " with MIME type " + mimeType
+ " obtained from extension");
692 } catch (Throwable th
) {
693 Log_OC
.e(TAG
, "Unexpected problem when opening: " + storagePath
, th
);
697 Toast
.makeText(getActivity(), "There is no application to handle file " + file
.getFileName(), Toast
.LENGTH_SHORT
).show();
706 * Starts a the removal of the previewed file.
708 * Shows a confirmation dialog. The action continues in {@link #onConfirmation(String)} , {@link #onNeutral(String)} or {@link #onCancel(String)},
709 * depending upon the user selection in the dialog.
711 private void removeFile() {
712 ConfirmationDialogFragment confDialog
= ConfirmationDialogFragment
.newInstance(
713 R
.string
.confirmation_remove_alert
,
714 new String
[]{getFile().getFileName()},
715 R
.string
.confirmation_remove_remote_and_local
,
716 R
.string
.confirmation_remove_local
,
717 R
.string
.common_cancel
);
718 confDialog
.setOnConfirmationListener(this);
719 confDialog
.show(getFragmentManager(), ConfirmationDialogFragment
.FTAG_CONFIRMATION
);
724 * Performs the removal of the previewed file, both locally and in the server.
727 public void onConfirmation(String callerTag
) {
728 OCFile file
= getFile();
729 if (mStorageManager
.getFileById(file
.getFileId()) != null
) { // check that the file is still there;
731 mLastRemoteOperation
= new RemoveFileOperation( file
, // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
734 mLastRemoteOperation
.execute(mAccount
, getSherlockActivity(), this, mHandler
, getSherlockActivity());
736 ((FileDisplayActivity
) getActivity()).showLoadingDialog();
742 * Removes the file from local storage
745 public void onNeutral(String callerTag
) {
746 OCFile file
= getFile();
748 mStorageManager
.removeFile(file
, false
, true
); // TODO perform in background task / new thread
753 * User cancelled the removal action.
756 public void onCancel(String callerTag
) {
757 // nothing to do here
762 * Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment} to be previewed.
764 * @param file File to test if can be previewed.
765 * @return 'True' if the file can be handled by the fragment.
767 public static boolean canBePreviewed(OCFile file
) {
768 return (file
!= null
&& (file
.isAudio() || file
.isVideo()));
775 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
776 if (operation
.equals(mLastRemoteOperation
)) {
777 if (operation
instanceof RemoveFileOperation
) {
778 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
783 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
784 ((FileDisplayActivity
) getActivity()).dismissLoadingDialog();
785 if (result
.isSuccess()) {
786 Toast msg
= Toast
.makeText(getActivity().getApplicationContext(), R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
791 Toast msg
= Toast
.makeText(getActivity(), R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
793 if (result
.isSslRecoverableException()) {
794 // TODO show the SSL warning dialog
799 private void stopPreview(boolean stopAudio
) {
800 OCFile file
= getFile();
801 if (file
.isAudio() && stopAudio
) {
802 mMediaServiceBinder
.pause();
804 } else if (file
.isVideo()) {
805 mVideoPreview
.stopPlayback();
812 * Finishes the preview
814 private void finish() {
815 getActivity().onBackPressed();
819 public int getPosition() {
821 mSavedPlaybackPosition
= mVideoPreview
.getCurrentPosition();
823 Log_OC
.e(TAG
, "getting position: " + mSavedPlaybackPosition
);
824 return mSavedPlaybackPosition
;
827 public boolean isPlaying() {
829 mAutoplay
= mVideoPreview
.isPlaying();