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
;
20 import java
.util
.ArrayList
;
21 import java
.util
.List
;
23 import android
.accounts
.Account
;
24 import android
.app
.Activity
;
25 import android
.app
.AlertDialog
;
26 import android
.content
.ActivityNotFoundException
;
27 import android
.content
.ComponentName
;
28 import android
.content
.Context
;
29 import android
.content
.DialogInterface
;
30 import android
.content
.Intent
;
31 import android
.content
.ServiceConnection
;
32 import android
.content
.res
.Configuration
;
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
.Log_OC
;
75 import com
.owncloud
.android
.R
;
76 import eu
.alefzero
.webdav
.WebdavClient
;
77 import eu
.alefzero
.webdav
.WebdavUtils
;
80 * This fragment shows a preview of a downloaded media file (audio or video).
82 * Trying to get an instance with NULL {@link OCFile} or ownCloud {@link Account} values will produce an {@link IllegalStateException}.
84 * By now, if the {@link OCFile} passed is not downloaded, an {@link IllegalStateException} is generated on instantiation too.
86 * @author David A. Velasco
88 public class PreviewMediaFragment
extends SherlockFragment
implements
89 OnTouchListener
, FileFragment
,
90 ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
, OnRemoteOperationListener
{
92 public static final String EXTRA_FILE
= "FILE";
93 public static final String EXTRA_ACCOUNT
= "ACCOUNT";
94 private static final String EXTRA_PLAY_POSITION
= "PLAY_POSITION";
95 private static final String EXTRA_PLAYING
= "PLAYING";
99 private Account mAccount
;
100 private FileDataStorageManager mStorageManager
;
101 private ImageView mImagePreview
;
102 private VideoView mVideoPreview
;
103 private int mSavedPlaybackPosition
;
105 private Handler mHandler
;
106 private RemoteOperation mLastRemoteOperation
;
108 private MediaServiceBinder mMediaServiceBinder
= null
;
109 private MediaControlView mMediaController
= null
;
110 private MediaServiceConnection mMediaServiceConnection
= null
;
111 private VideoHelper mVideoHelper
;
112 private boolean mAutoplay
;
113 public boolean mPrepared
;
115 private static final String TAG
= PreviewMediaFragment
.class.getSimpleName();
119 * Creates a fragment to preview a file.
121 * When 'fileToDetail' or 'ocAccount' are null
123 * @param fileToDetail An {@link OCFile} to preview in the fragment
124 * @param ocAccount An ownCloud account; needed to start downloads
126 public PreviewMediaFragment(OCFile fileToDetail
, Account ocAccount
, int startPlaybackPosition
, boolean autoplay
) {
127 mFile
= fileToDetail
;
128 mAccount
= ocAccount
;
129 mSavedPlaybackPosition
= startPlaybackPosition
;
130 mStorageManager
= null
; // we need a context to init this; the container activity is not available yet at this moment
131 mAutoplay
= autoplay
;
136 * Creates an empty fragment for previews.
138 * MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically (for instance, when the device is turned a aside).
140 * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction
142 public PreviewMediaFragment() {
145 mSavedPlaybackPosition
= 0;
146 mStorageManager
= null
;
155 public void onCreate(Bundle savedInstanceState
) {
156 super.onCreate(savedInstanceState
);
157 mHandler
= new Handler();
158 setHasOptionsMenu(true
);
166 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
167 Bundle savedInstanceState
) {
168 super.onCreateView(inflater
, container
, savedInstanceState
);
169 Log_OC
.e(TAG
, "onCreateView");
172 mView
= inflater
.inflate(R
.layout
.file_preview
, container
, false
);
174 mImagePreview
= (ImageView
)mView
.findViewById(R
.id
.image_preview
);
175 mVideoPreview
= (VideoView
)mView
.findViewById(R
.id
.video_preview
);
176 mVideoPreview
.setOnTouchListener(this);
178 mMediaController
= (MediaControlView
)mView
.findViewById(R
.id
.media_controller
);
188 public void onAttach(Activity activity
) {
189 super.onAttach(activity
);
190 Log_OC
.e(TAG
, "onAttach");
192 if (!(activity
instanceof FileFragment
.ContainerActivity
))
193 throw new ClassCastException(activity
.toString() + " must implement " + FileFragment
.ContainerActivity
.class.getSimpleName());
201 public void onActivityCreated(Bundle savedInstanceState
) {
202 super.onActivityCreated(savedInstanceState
);
203 Log_OC
.e(TAG
, "onActivityCreated");
205 mStorageManager
= new FileDataStorageManager(mAccount
, getActivity().getApplicationContext().getContentResolver());
206 if (savedInstanceState
!= null
) {
207 mFile
= savedInstanceState
.getParcelable(PreviewMediaFragment
.EXTRA_FILE
);
208 mAccount
= savedInstanceState
.getParcelable(PreviewMediaFragment
.EXTRA_ACCOUNT
);
209 mSavedPlaybackPosition
= savedInstanceState
.getInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
);
210 mAutoplay
= savedInstanceState
.getBoolean(PreviewMediaFragment
.EXTRA_PLAYING
);
214 throw new IllegalStateException("Instanced with a NULL OCFile");
216 if (mAccount
== null
) {
217 throw new IllegalStateException("Instanced with a NULL ownCloud Account");
219 if (!mFile
.isDown()) {
220 throw new IllegalStateException("There is no local file to preview");
222 if (mFile
.isVideo()) {
223 mVideoPreview
.setVisibility(View
.VISIBLE
);
224 mImagePreview
.setVisibility(View
.GONE
);
228 mVideoPreview
.setVisibility(View
.GONE
);
229 mImagePreview
.setVisibility(View
.VISIBLE
);
239 public void onSaveInstanceState(Bundle outState
) {
240 super.onSaveInstanceState(outState
);
241 Log_OC
.e(TAG
, "onSaveInstanceState");
243 outState
.putParcelable(PreviewMediaFragment
.EXTRA_FILE
, mFile
);
244 outState
.putParcelable(PreviewMediaFragment
.EXTRA_ACCOUNT
, mAccount
);
246 if (mFile
.isVideo()) {
247 mSavedPlaybackPosition
= mVideoPreview
.getCurrentPosition();
248 mAutoplay
= mVideoPreview
.isPlaying();
249 outState
.putInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
, mSavedPlaybackPosition
);
250 outState
.putBoolean(PreviewMediaFragment
.EXTRA_PLAYING
, mAutoplay
);
252 outState
.putInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
, mMediaServiceBinder
.getCurrentPosition());
253 outState
.putBoolean(PreviewMediaFragment
.EXTRA_PLAYING
, mMediaServiceBinder
.isPlaying());
259 public void onStart() {
261 Log_OC
.e(TAG
, "onStart");
264 if (mFile
.isAudio()) {
267 } else if (mFile
.isVideo()) {
275 private void stopAudio() {
276 Intent i
= new Intent(getSherlockActivity(), MediaService
.class);
277 i
.setAction(MediaService
.ACTION_STOP_ALL
);
278 getSherlockActivity().startService(i
);
286 public void onCreateOptionsMenu(Menu menu
, MenuInflater inflater
) {
287 super.onCreateOptionsMenu(menu
, inflater
);
289 inflater
.inflate(R
.menu
.file_actions_menu
, menu
);
290 List
<Integer
> toHide
= new ArrayList
<Integer
>();
292 MenuItem item
= null
;
293 toHide
.add(R
.id
.action_cancel_download
);
294 toHide
.add(R
.id
.action_cancel_upload
);
295 toHide
.add(R
.id
.action_download_file
);
296 toHide
.add(R
.id
.action_sync_file
);
297 toHide
.add(R
.id
.action_rename_file
); // by now
299 for (int i
: toHide
) {
300 item
= menu
.findItem(i
);
302 item
.setVisible(false
);
303 item
.setEnabled(false
);
314 public boolean onOptionsItemSelected(MenuItem item
) {
315 switch (item
.getItemId()) {
316 case R
.id
.action_open_file_with
: {
320 case R
.id
.action_remove_file
: {
324 case R
.id
.action_see_details
: {
335 private void seeDetails() {
337 ((FileFragment
.ContainerActivity
)getActivity()).showFragmentWithDetails(mFile
);
341 private void prepareVideo() {
342 // create helper to get more control on the playback
343 mVideoHelper
= new VideoHelper();
344 mVideoPreview
.setOnPreparedListener(mVideoHelper
);
345 mVideoPreview
.setOnCompletionListener(mVideoHelper
);
346 mVideoPreview
.setOnErrorListener(mVideoHelper
);
349 private void playVideo() {
350 // create and prepare control panel for the user
351 mMediaController
.setMediaPlayer(mVideoPreview
);
353 // load the video file in the video player ; when done, VideoHelper#onPrepared() will be called
354 mVideoPreview
.setVideoPath(mFile
.getStoragePath());
358 private class VideoHelper
implements OnCompletionListener
, OnPreparedListener
, OnErrorListener
{
361 * Called when the file is ready to be played.
363 * Just starts the playback.
365 * @param mp {@link MediaPlayer} instance performing the playback.
368 public void onPrepared(MediaPlayer vp
) {
369 Log
.e(TAG
, "onPrepared");
370 mVideoPreview
.seekTo(mSavedPlaybackPosition
);
372 mVideoPreview
.start();
374 mMediaController
.setEnabled(true
);
375 mMediaController
.updatePausePlay();
381 * Called when the file is finished playing.
383 * Finishes the activity.
385 * @param mp {@link MediaPlayer} instance performing the playback.
388 public void onCompletion(MediaPlayer mp
) {
389 Log
.e(TAG
, "completed");
391 mVideoPreview
.seekTo(0);
392 // next lines are necessary to work around undesired video loops
393 if (Build
.VERSION
.SDK_INT
== Build
.VERSION_CODES
.GINGERBREAD
) {
394 mVideoPreview
.pause();
396 } else if (Build
.VERSION
.SDK_INT
== Build
.VERSION_CODES
.GINGERBREAD_MR1
) {
397 // mVideePreview.pause() is not enough
399 mMediaController
.setEnabled(false
);
400 mVideoPreview
.stopPlayback();
402 mSavedPlaybackPosition
= 0;
403 mVideoPreview
.setVideoPath(mFile
.getStoragePath());
405 } // else : called from onError()
406 mMediaController
.updatePausePlay();
411 * Called when an error in playback occurs.
413 * @param mp {@link MediaPlayer} instance performing the playback.
414 * @param what Type of error
415 * @param extra Extra code specific to the error
418 public boolean onError(MediaPlayer mp
, int what
, int extra
) {
419 if (mVideoPreview
.getWindowToken() != null
) {
420 String message
= MediaService
.getMessageForMediaError(getActivity(), what
, extra
);
421 new AlertDialog
.Builder(getActivity())
423 .setPositiveButton(android
.R
.string
.VideoView_error_button
,
424 new DialogInterface
.OnClickListener() {
425 public void onClick(DialogInterface dialog
, int whichButton
) {
427 VideoHelper
.this.onCompletion(null
);
430 .setCancelable(false
)
440 public void onPause() {
442 Log_OC
.e(TAG
, "onPause");
446 public void onResume() {
448 Log_OC
.e(TAG
, "onResume");
452 public void onDestroy() {
454 Log_OC
.e(TAG
, "onDestroy");
458 public void onStop() {
459 Log_OC
.e(TAG
, "onStop");
463 if (mMediaServiceConnection
!= null
) {
464 Log
.d(TAG
, "Unbinding from MediaService ...");
465 if (mMediaServiceBinder
!= null
&& mMediaController
!= null
) {
466 mMediaServiceBinder
.unregisterMediaController(mMediaController
);
468 getActivity().unbindService(mMediaServiceConnection
);
469 mMediaServiceConnection
= null
;
470 mMediaServiceBinder
= null
;
475 public boolean onTouch(View v
, MotionEvent event
) {
476 if (event
.getAction() == MotionEvent
.ACTION_DOWN
&& v
== mVideoPreview
) {
477 startFullScreenVideo();
484 private void startFullScreenVideo() {
485 Intent i
= new Intent(getActivity(), PreviewVideoActivity
.class);
486 i
.putExtra(PreviewVideoActivity
.EXTRA_ACCOUNT
, mAccount
);
487 i
.putExtra(PreviewVideoActivity
.EXTRA_FILE
, mFile
);
488 i
.putExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, mVideoPreview
.isPlaying());
489 mVideoPreview
.pause();
490 i
.putExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, mVideoPreview
.getCurrentPosition());
491 startActivityForResult(i
, 0);
495 public void onConfigurationChanged (Configuration newConfig
) {
496 Log_OC
.e(TAG
, "onConfigurationChanged " + this);
500 public void onActivityResult (int requestCode
, int resultCode
, Intent data
) {
501 Log_OC
.e(TAG
, "onActivityResult " + this);
502 super.onActivityResult(requestCode
, resultCode
, data
);
503 if (resultCode
== Activity
.RESULT_OK
) {
504 mSavedPlaybackPosition
= data
.getExtras().getInt(PreviewVideoActivity
.EXTRA_START_POSITION
);
505 mAutoplay
= data
.getExtras().getBoolean(PreviewVideoActivity
.EXTRA_AUTOPLAY
);
510 private void playAudio() {
511 if (!mMediaServiceBinder
.isPlaying(mFile
)) {
512 Log
.d(TAG
, "starting playback of " + mFile
.getStoragePath());
513 mMediaServiceBinder
.start(mAccount
, mFile
, mAutoplay
, mSavedPlaybackPosition
);
516 if (!mMediaServiceBinder
.isPlaying() && mAutoplay
) {
517 mMediaServiceBinder
.start();
518 mMediaController
.updatePausePlay();
524 private void bindMediaService() {
525 Log
.d(TAG
, "Binding to MediaService...");
526 if (mMediaServiceConnection
== null
) {
527 mMediaServiceConnection
= new MediaServiceConnection();
529 getActivity().bindService( new Intent(getActivity(),
531 mMediaServiceConnection
,
532 Context
.BIND_AUTO_CREATE
);
533 // follow the flow in MediaServiceConnection#onServiceConnected(...)
536 /** Defines callbacks for service binding, passed to bindService() */
537 private class MediaServiceConnection
implements ServiceConnection
{
540 public void onServiceConnected(ComponentName component
, IBinder service
) {
541 if (component
.equals(new ComponentName(getActivity(), MediaService
.class))) {
542 Log
.d(TAG
, "Media service connected");
543 mMediaServiceBinder
= (MediaServiceBinder
) service
;
544 if (mMediaServiceBinder
!= null
) {
545 prepareMediaController();
546 playAudio(); // do not wait for the touch of nobody to play audio
548 Log
.d(TAG
, "Successfully bound to MediaService, MediaController ready");
551 Log
.e(TAG
, "Unexpected response from MediaService while binding");
556 private void prepareMediaController() {
557 mMediaServiceBinder
.registerMediaController(mMediaController
);
558 if (mMediaController
!= null
) {
559 mMediaController
.setMediaPlayer(mMediaServiceBinder
);
560 mMediaController
.setEnabled(true
);
561 mMediaController
.updatePausePlay();
566 public void onServiceDisconnected(ComponentName component
) {
567 if (component
.equals(new ComponentName(getActivity(), MediaService
.class))) {
568 Log
.e(TAG
, "Media service suddenly disconnected");
569 if (mMediaController
!= null
) {
570 mMediaController
.setMediaPlayer(null
);
572 Toast
.makeText(getActivity(), "No media controller to release when disconnected from media service", Toast
.LENGTH_SHORT
).show();
574 mMediaServiceBinder
= null
;
575 mMediaServiceConnection
= null
;
583 * Opens the previewed file with an external application.
585 * TODO - improve this; instead of prioritize the actions available for the MIME type in the server,
586 * we should get a list of available apps for MIME tpye in the server and join it with the list of
587 * available apps for the MIME type known from the file extension, to let the user choose
589 private void openFile() {
591 String storagePath
= mFile
.getStoragePath();
592 String encodedStoragePath
= WebdavUtils
.encodePath(storagePath
);
594 Intent i
= new Intent(Intent
.ACTION_VIEW
);
595 i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), mFile
.getMimetype());
596 i
.setFlags(Intent
.FLAG_GRANT_READ_URI_PERMISSION
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
);
599 } catch (Throwable t
) {
600 Log
.e(TAG
, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile
.getMimetype());
601 boolean toastIt
= true
;
602 String mimeType
= "";
604 Intent i
= new Intent(Intent
.ACTION_VIEW
);
605 mimeType
= MimeTypeMap
.getSingleton().getMimeTypeFromExtension(storagePath
.substring(storagePath
.lastIndexOf('.') + 1));
606 if (mimeType
== null
|| !mimeType
.equals(mFile
.getMimetype())) {
607 if (mimeType
!= null
) {
608 i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), mimeType
);
611 i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), "*-/*");
613 i
.setFlags(Intent
.FLAG_GRANT_READ_URI_PERMISSION
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
);
618 } catch (IndexOutOfBoundsException e
) {
619 Log
.e(TAG
, "Trying to find out MIME type of a file without extension: " + storagePath
);
621 } catch (ActivityNotFoundException e
) {
622 Log
.e(TAG
, "No activity found to handle: " + storagePath
+ " with MIME type " + mimeType
+ " obtained from extension");
624 } catch (Throwable th
) {
625 Log
.e(TAG
, "Unexpected problem when opening: " + storagePath
, th
);
629 Toast
.makeText(getActivity(), "There is no application to handle file " + mFile
.getFileName(), Toast
.LENGTH_SHORT
).show();
638 * Starts a the removal of the previewed file.
640 * Shows a confirmation dialog. The action continues in {@link #onConfirmation(String)} , {@link #onNeutral(String)} or {@link #onCancel(String)},
641 * depending upon the user selection in the dialog.
643 private void removeFile() {
644 ConfirmationDialogFragment confDialog
= ConfirmationDialogFragment
.newInstance(
645 R
.string
.confirmation_remove_alert
,
646 new String
[]{mFile
.getFileName()},
647 R
.string
.confirmation_remove_remote_and_local
,
648 R
.string
.confirmation_remove_local
,
649 R
.string
.common_cancel
);
650 confDialog
.setOnConfirmationListener(this);
651 confDialog
.show(getFragmentManager(), ConfirmationDialogFragment
.FTAG_CONFIRMATION
);
656 * Performs the removal of the previewed file, both locally and in the server.
659 public void onConfirmation(String callerTag
) {
660 if (mStorageManager
.getFileById(mFile
.getFileId()) != null
) { // check that the file is still there;
662 mLastRemoteOperation
= new RemoveFileOperation( mFile
, // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
665 WebdavClient wc
= OwnCloudClientUtils
.createOwnCloudClient(mAccount
, getSherlockActivity().getApplicationContext());
666 mLastRemoteOperation
.execute(wc
, this, mHandler
);
668 boolean inDisplayActivity
= getActivity() instanceof FileDisplayActivity
;
669 getActivity().showDialog((inDisplayActivity
)? FileDisplayActivity
.DIALOG_SHORT_WAIT
: FileDetailActivity
.DIALOG_SHORT_WAIT
);
675 * Removes the file from local storage
678 public void onNeutral(String callerTag
) {
679 // TODO this code should be made in a secondary thread,
680 if (mFile
.isDown()) { // checks it is still there
682 File f
= new File(mFile
.getStoragePath());
684 mFile
.setStoragePath(null
);
685 mStorageManager
.saveFile(mFile
);
691 * User cancelled the removal action.
694 public void onCancel(String callerTag
) {
695 // nothing to do here
702 public OCFile
getFile(){
708 * Use this method to signal this Activity that it shall update its view.
710 * @param file : An {@link OCFile}
712 public void updateFileDetails(OCFile file, Account ocAccount) {
714 if (ocAccount != null && (
715 mStorageManager == null ||
716 (mAccount != null && !mAccount.equals(ocAccount))
718 mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());
720 mAccount = ocAccount;
721 updateFileDetails(false);
727 * Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment} to be previewed.
729 * @param file File to test if can be previewed.
730 * @return 'True' if the file can be handled by the fragment.
732 public static boolean canBePreviewed(OCFile file
) {
733 return (file
!= null
&& (file
.isAudio() || file
.isVideo()));
740 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
741 if (operation
.equals(mLastRemoteOperation
)) {
742 if (operation
instanceof RemoveFileOperation
) {
743 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
748 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
749 boolean inDisplayActivity
= getActivity() instanceof FileDisplayActivity
;
750 getActivity().dismissDialog((inDisplayActivity
)? FileDisplayActivity
.DIALOG_SHORT_WAIT
: FileDetailActivity
.DIALOG_SHORT_WAIT
);
752 if (result
.isSuccess()) {
753 Toast msg
= Toast
.makeText(getActivity().getApplicationContext(), R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
758 Toast msg
= Toast
.makeText(getActivity(), R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
760 if (result
.isSslRecoverableException()) {
761 // TODO show the SSL warning dialog
766 private void stopPreview(boolean stopAudio
) {
767 if (mFile
.isAudio() && stopAudio
) {
768 mMediaServiceBinder
.pause();
770 } else if (mFile
.isVideo()) {
771 mVideoPreview
.stopPlayback();
778 * Finishes the preview
780 private void finish() {
781 Activity container
= getActivity();
782 if (container
instanceof FileDisplayActivity
) {
784 FragmentTransaction transaction
= getActivity().getSupportFragmentManager().beginTransaction();
785 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
); // empty FileDetailFragment
786 transaction
.commit();
787 ((FileFragment
.ContainerActivity
)container
).onFileStateChanged();
794 public int getPosition() {
796 mSavedPlaybackPosition
= mVideoPreview
.getCurrentPosition();
798 Log_OC
.e(TAG
, "getting position: " + mSavedPlaybackPosition
);
799 return mSavedPlaybackPosition
;
802 public boolean isPlaying() {
804 mAutoplay
= mVideoPreview
.isPlaying();