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
.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
.operations
.OnRemoteOperationListener
;
63 import com
.owncloud
.android
.operations
.RemoteOperation
;
64 import com
.owncloud
.android
.operations
.RemoteOperationResult
;
65 import com
.owncloud
.android
.operations
.RemoveFileOperation
;
66 import com
.owncloud
.android
.ui
.activity
.FileDetailActivity
;
67 import com
.owncloud
.android
.ui
.activity
.FileDisplayActivity
;
68 import com
.owncloud
.android
.ui
.fragment
.ConfirmationDialogFragment
;
69 import com
.owncloud
.android
.ui
.fragment
.FileDetailFragment
;
70 import com
.owncloud
.android
.ui
.fragment
.FileFragment
;
72 import com
.owncloud
.android
.Log_OC
;
73 import com
.owncloud
.android
.R
;
74 import eu
.alefzero
.webdav
.WebdavUtils
;
77 * This fragment shows a preview of a downloaded media file (audio or video).
79 * Trying to get an instance with NULL {@link OCFile} or ownCloud {@link Account} values will produce an {@link IllegalStateException}.
81 * By now, if the {@link OCFile} passed is not downloaded, an {@link IllegalStateException} is generated on instantiation too.
83 * @author David A. Velasco
85 public class PreviewMediaFragment
extends SherlockFragment
implements
86 OnTouchListener
, FileFragment
,
87 ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
, OnRemoteOperationListener
{
89 public static final String EXTRA_FILE
= "FILE";
90 public static final String EXTRA_ACCOUNT
= "ACCOUNT";
91 private static final String EXTRA_PLAY_POSITION
= "PLAY_POSITION";
92 private static final String EXTRA_PLAYING
= "PLAYING";
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
;
109 private boolean mAutoplay
;
110 public boolean mPrepared
;
112 private static final String TAG
= PreviewMediaFragment
.class.getSimpleName();
116 * Creates a fragment to preview a file.
118 * When 'fileToDetail' or 'ocAccount' are null
120 * @param fileToDetail An {@link OCFile} to preview in the fragment
121 * @param ocAccount An ownCloud account; needed to start downloads
123 public PreviewMediaFragment(OCFile fileToDetail
, Account ocAccount
, int startPlaybackPosition
, boolean autoplay
) {
124 mFile
= fileToDetail
;
125 mAccount
= ocAccount
;
126 mSavedPlaybackPosition
= startPlaybackPosition
;
127 mStorageManager
= null
; // we need a context to init this; the container activity is not available yet at this moment
128 mAutoplay
= autoplay
;
133 * Creates an empty fragment for previews.
135 * MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically (for instance, when the device is turned a aside).
137 * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction
139 public PreviewMediaFragment() {
142 mSavedPlaybackPosition
= 0;
143 mStorageManager
= null
;
152 public void onCreate(Bundle savedInstanceState
) {
153 super.onCreate(savedInstanceState
);
154 mHandler
= new Handler();
155 setHasOptionsMenu(true
);
163 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
164 Bundle savedInstanceState
) {
165 super.onCreateView(inflater
, container
, savedInstanceState
);
166 Log_OC
.e(TAG
, "onCreateView");
169 mView
= inflater
.inflate(R
.layout
.file_preview
, container
, false
);
171 mImagePreview
= (ImageView
)mView
.findViewById(R
.id
.image_preview
);
172 mVideoPreview
= (VideoView
)mView
.findViewById(R
.id
.video_preview
);
173 mVideoPreview
.setOnTouchListener(this);
175 mMediaController
= (MediaControlView
)mView
.findViewById(R
.id
.media_controller
);
185 public void onAttach(Activity activity
) {
186 super.onAttach(activity
);
187 Log_OC
.e(TAG
, "onAttach");
189 if (!(activity
instanceof FileFragment
.ContainerActivity
))
190 throw new ClassCastException(activity
.toString() + " must implement " + FileFragment
.ContainerActivity
.class.getSimpleName());
198 public void onActivityCreated(Bundle savedInstanceState
) {
199 super.onActivityCreated(savedInstanceState
);
200 Log_OC
.e(TAG
, "onActivityCreated");
202 mStorageManager
= new FileDataStorageManager(mAccount
, getActivity().getApplicationContext().getContentResolver());
203 if (savedInstanceState
!= null
) {
204 mFile
= savedInstanceState
.getParcelable(PreviewMediaFragment
.EXTRA_FILE
);
205 mAccount
= savedInstanceState
.getParcelable(PreviewMediaFragment
.EXTRA_ACCOUNT
);
206 mSavedPlaybackPosition
= savedInstanceState
.getInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
);
207 mAutoplay
= savedInstanceState
.getBoolean(PreviewMediaFragment
.EXTRA_PLAYING
);
211 throw new IllegalStateException("Instanced with a NULL OCFile");
213 if (mAccount
== null
) {
214 throw new IllegalStateException("Instanced with a NULL ownCloud Account");
216 if (!mFile
.isDown()) {
217 throw new IllegalStateException("There is no local file to preview");
219 if (mFile
.isVideo()) {
220 mVideoPreview
.setVisibility(View
.VISIBLE
);
221 mImagePreview
.setVisibility(View
.GONE
);
225 mVideoPreview
.setVisibility(View
.GONE
);
226 mImagePreview
.setVisibility(View
.VISIBLE
);
236 public void onSaveInstanceState(Bundle outState
) {
237 super.onSaveInstanceState(outState
);
238 Log_OC
.e(TAG
, "onSaveInstanceState");
240 outState
.putParcelable(PreviewMediaFragment
.EXTRA_FILE
, mFile
);
241 outState
.putParcelable(PreviewMediaFragment
.EXTRA_ACCOUNT
, mAccount
);
243 if (mFile
.isVideo()) {
244 mSavedPlaybackPosition
= mVideoPreview
.getCurrentPosition();
245 mAutoplay
= mVideoPreview
.isPlaying();
246 outState
.putInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
, mSavedPlaybackPosition
);
247 outState
.putBoolean(PreviewMediaFragment
.EXTRA_PLAYING
, mAutoplay
);
249 outState
.putInt(PreviewMediaFragment
.EXTRA_PLAY_POSITION
, mMediaServiceBinder
.getCurrentPosition());
250 outState
.putBoolean(PreviewMediaFragment
.EXTRA_PLAYING
, mMediaServiceBinder
.isPlaying());
256 public void onStart() {
258 Log_OC
.e(TAG
, "onStart");
261 if (mFile
.isAudio()) {
264 } else if (mFile
.isVideo()) {
272 private void stopAudio() {
273 Intent i
= new Intent(getSherlockActivity(), MediaService
.class);
274 i
.setAction(MediaService
.ACTION_STOP_ALL
);
275 getSherlockActivity().startService(i
);
283 public void onCreateOptionsMenu(Menu menu
, MenuInflater inflater
) {
284 super.onCreateOptionsMenu(menu
, inflater
);
286 inflater
.inflate(R
.menu
.file_actions_menu
, menu
);
287 List
<Integer
> toHide
= new ArrayList
<Integer
>();
289 MenuItem item
= null
;
290 toHide
.add(R
.id
.action_cancel_download
);
291 toHide
.add(R
.id
.action_cancel_upload
);
292 toHide
.add(R
.id
.action_download_file
);
293 toHide
.add(R
.id
.action_sync_file
);
294 toHide
.add(R
.id
.action_rename_file
); // by now
296 for (int i
: toHide
) {
297 item
= menu
.findItem(i
);
299 item
.setVisible(false
);
300 item
.setEnabled(false
);
311 public boolean onOptionsItemSelected(MenuItem item
) {
312 switch (item
.getItemId()) {
313 case R
.id
.action_open_file_with
: {
317 case R
.id
.action_remove_file
: {
321 case R
.id
.action_see_details
: {
332 private void seeDetails() {
334 ((FileFragment
.ContainerActivity
)getActivity()).showFragmentWithDetails(mFile
);
338 private void prepareVideo() {
339 // create helper to get more control on the playback
340 mVideoHelper
= new VideoHelper();
341 mVideoPreview
.setOnPreparedListener(mVideoHelper
);
342 mVideoPreview
.setOnCompletionListener(mVideoHelper
);
343 mVideoPreview
.setOnErrorListener(mVideoHelper
);
346 private void playVideo() {
347 // create and prepare control panel for the user
348 mMediaController
.setMediaPlayer(mVideoPreview
);
350 // load the video file in the video player ; when done, VideoHelper#onPrepared() will be called
351 mVideoPreview
.setVideoPath(mFile
.getStoragePath());
355 private class VideoHelper
implements OnCompletionListener
, OnPreparedListener
, OnErrorListener
{
358 * Called when the file is ready to be played.
360 * Just starts the playback.
362 * @param mp {@link MediaPlayer} instance performing the playback.
365 public void onPrepared(MediaPlayer vp
) {
366 Log_OC
.e(TAG
, "onPrepared");
367 mVideoPreview
.seekTo(mSavedPlaybackPosition
);
369 mVideoPreview
.start();
371 mMediaController
.setEnabled(true
);
372 mMediaController
.updatePausePlay();
378 * Called when the file is finished playing.
380 * Finishes the activity.
382 * @param mp {@link MediaPlayer} instance performing the playback.
385 public void onCompletion(MediaPlayer mp
) {
386 Log_OC
.e(TAG
, "completed");
388 mVideoPreview
.seekTo(0);
389 // next lines are necessary to work around undesired video loops
390 if (Build
.VERSION
.SDK_INT
== Build
.VERSION_CODES
.GINGERBREAD
) {
391 mVideoPreview
.pause();
393 } else if (Build
.VERSION
.SDK_INT
== Build
.VERSION_CODES
.GINGERBREAD_MR1
) {
394 // mVideePreview.pause() is not enough
396 mMediaController
.setEnabled(false
);
397 mVideoPreview
.stopPlayback();
399 mSavedPlaybackPosition
= 0;
400 mVideoPreview
.setVideoPath(mFile
.getStoragePath());
402 } // else : called from onError()
403 mMediaController
.updatePausePlay();
408 * Called when an error in playback occurs.
410 * @param mp {@link MediaPlayer} instance performing the playback.
411 * @param what Type of error
412 * @param extra Extra code specific to the error
415 public boolean onError(MediaPlayer mp
, int what
, int extra
) {
416 if (mVideoPreview
.getWindowToken() != null
) {
417 String message
= MediaService
.getMessageForMediaError(getActivity(), what
, extra
);
418 new AlertDialog
.Builder(getActivity())
420 .setPositiveButton(android
.R
.string
.VideoView_error_button
,
421 new DialogInterface
.OnClickListener() {
422 public void onClick(DialogInterface dialog
, int whichButton
) {
424 VideoHelper
.this.onCompletion(null
);
427 .setCancelable(false
)
437 public void onPause() {
439 Log_OC
.e(TAG
, "onPause");
443 public void onResume() {
445 Log_OC
.e(TAG
, "onResume");
449 public void onDestroy() {
451 Log_OC
.e(TAG
, "onDestroy");
455 public void onStop() {
456 Log_OC
.e(TAG
, "onStop");
460 if (mMediaServiceConnection
!= null
) {
461 Log_OC
.d(TAG
, "Unbinding from MediaService ...");
462 if (mMediaServiceBinder
!= null
&& mMediaController
!= null
) {
463 mMediaServiceBinder
.unregisterMediaController(mMediaController
);
465 getActivity().unbindService(mMediaServiceConnection
);
466 mMediaServiceConnection
= null
;
467 mMediaServiceBinder
= null
;
472 public boolean onTouch(View v
, MotionEvent event
) {
473 if (event
.getAction() == MotionEvent
.ACTION_DOWN
&& v
== mVideoPreview
) {
474 startFullScreenVideo();
481 private void startFullScreenVideo() {
482 Intent i
= new Intent(getActivity(), PreviewVideoActivity
.class);
483 i
.putExtra(PreviewVideoActivity
.EXTRA_ACCOUNT
, mAccount
);
484 i
.putExtra(PreviewVideoActivity
.EXTRA_FILE
, mFile
);
485 i
.putExtra(PreviewVideoActivity
.EXTRA_AUTOPLAY
, mVideoPreview
.isPlaying());
486 mVideoPreview
.pause();
487 i
.putExtra(PreviewVideoActivity
.EXTRA_START_POSITION
, mVideoPreview
.getCurrentPosition());
488 startActivityForResult(i
, 0);
492 public void onConfigurationChanged (Configuration newConfig
) {
493 Log_OC
.e(TAG
, "onConfigurationChanged " + this);
497 public void onActivityResult (int requestCode
, int resultCode
, Intent data
) {
498 Log_OC
.e(TAG
, "onActivityResult " + this);
499 super.onActivityResult(requestCode
, resultCode
, data
);
500 if (resultCode
== Activity
.RESULT_OK
) {
501 mSavedPlaybackPosition
= data
.getExtras().getInt(PreviewVideoActivity
.EXTRA_START_POSITION
);
502 mAutoplay
= data
.getExtras().getBoolean(PreviewVideoActivity
.EXTRA_AUTOPLAY
);
507 private void playAudio() {
508 if (!mMediaServiceBinder
.isPlaying(mFile
)) {
509 Log_OC
.d(TAG
, "starting playback of " + mFile
.getStoragePath());
510 mMediaServiceBinder
.start(mAccount
, mFile
, mAutoplay
, mSavedPlaybackPosition
);
513 if (!mMediaServiceBinder
.isPlaying() && mAutoplay
) {
514 mMediaServiceBinder
.start();
515 mMediaController
.updatePausePlay();
521 private void bindMediaService() {
522 Log_OC
.d(TAG
, "Binding to MediaService...");
523 if (mMediaServiceConnection
== null
) {
524 mMediaServiceConnection
= new MediaServiceConnection();
526 getActivity().bindService( new Intent(getActivity(),
528 mMediaServiceConnection
,
529 Context
.BIND_AUTO_CREATE
);
530 // follow the flow in MediaServiceConnection#onServiceConnected(...)
533 /** Defines callbacks for service binding, passed to bindService() */
534 private class MediaServiceConnection
implements ServiceConnection
{
537 public void onServiceConnected(ComponentName component
, IBinder service
) {
538 if (component
.equals(new ComponentName(getActivity(), MediaService
.class))) {
539 Log_OC
.d(TAG
, "Media service connected");
540 mMediaServiceBinder
= (MediaServiceBinder
) service
;
541 if (mMediaServiceBinder
!= null
) {
542 prepareMediaController();
543 playAudio(); // do not wait for the touch of nobody to play audio
545 Log_OC
.d(TAG
, "Successfully bound to MediaService, MediaController ready");
548 Log_OC
.e(TAG
, "Unexpected response from MediaService while binding");
553 private void prepareMediaController() {
554 mMediaServiceBinder
.registerMediaController(mMediaController
);
555 if (mMediaController
!= null
) {
556 mMediaController
.setMediaPlayer(mMediaServiceBinder
);
557 mMediaController
.setEnabled(true
);
558 mMediaController
.updatePausePlay();
563 public void onServiceDisconnected(ComponentName component
) {
564 if (component
.equals(new ComponentName(getActivity(), MediaService
.class))) {
565 Log_OC
.e(TAG
, "Media service suddenly disconnected");
566 if (mMediaController
!= null
) {
567 mMediaController
.setMediaPlayer(null
);
569 Toast
.makeText(getActivity(), "No media controller to release when disconnected from media service", Toast
.LENGTH_SHORT
).show();
571 mMediaServiceBinder
= null
;
572 mMediaServiceConnection
= null
;
580 * Opens the previewed file with an external application.
582 * TODO - improve this; instead of prioritize the actions available for the MIME type in the server,
583 * we should get a list of available apps for MIME tpye in the server and join it with the list of
584 * available apps for the MIME type known from the file extension, to let the user choose
586 private void openFile() {
588 String storagePath
= mFile
.getStoragePath();
589 String encodedStoragePath
= WebdavUtils
.encodePath(storagePath
);
591 Intent i
= new Intent(Intent
.ACTION_VIEW
);
592 i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), mFile
.getMimetype());
593 i
.setFlags(Intent
.FLAG_GRANT_READ_URI_PERMISSION
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
);
596 } catch (Throwable t
) {
597 Log_OC
.e(TAG
, "Fail when trying to open with the mimeType provided from the ownCloud server: " + mFile
.getMimetype());
598 boolean toastIt
= true
;
599 String mimeType
= "";
601 Intent i
= new Intent(Intent
.ACTION_VIEW
);
602 mimeType
= MimeTypeMap
.getSingleton().getMimeTypeFromExtension(storagePath
.substring(storagePath
.lastIndexOf('.') + 1));
603 if (mimeType
== null
|| !mimeType
.equals(mFile
.getMimetype())) {
604 if (mimeType
!= null
) {
605 i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), mimeType
);
608 i
.setDataAndType(Uri
.parse("file://"+ encodedStoragePath
), "*-/*");
610 i
.setFlags(Intent
.FLAG_GRANT_READ_URI_PERMISSION
| Intent
.FLAG_GRANT_WRITE_URI_PERMISSION
);
615 } catch (IndexOutOfBoundsException e
) {
616 Log_OC
.e(TAG
, "Trying to find out MIME type of a file without extension: " + storagePath
);
618 } catch (ActivityNotFoundException e
) {
619 Log_OC
.e(TAG
, "No activity found to handle: " + storagePath
+ " with MIME type " + mimeType
+ " obtained from extension");
621 } catch (Throwable th
) {
622 Log_OC
.e(TAG
, "Unexpected problem when opening: " + storagePath
, th
);
626 Toast
.makeText(getActivity(), "There is no application to handle file " + mFile
.getFileName(), Toast
.LENGTH_SHORT
).show();
635 * Starts a the removal of the previewed file.
637 * Shows a confirmation dialog. The action continues in {@link #onConfirmation(String)} , {@link #onNeutral(String)} or {@link #onCancel(String)},
638 * depending upon the user selection in the dialog.
640 private void removeFile() {
641 ConfirmationDialogFragment confDialog
= ConfirmationDialogFragment
.newInstance(
642 R
.string
.confirmation_remove_alert
,
643 new String
[]{mFile
.getFileName()},
644 R
.string
.confirmation_remove_remote_and_local
,
645 R
.string
.confirmation_remove_local
,
646 R
.string
.common_cancel
);
647 confDialog
.setOnConfirmationListener(this);
648 confDialog
.show(getFragmentManager(), ConfirmationDialogFragment
.FTAG_CONFIRMATION
);
653 * Performs the removal of the previewed file, both locally and in the server.
656 public void onConfirmation(String callerTag
) {
657 if (mStorageManager
.getFileById(mFile
.getFileId()) != null
) { // check that the file is still there;
659 mLastRemoteOperation
= new RemoveFileOperation( mFile
, // TODO we need to review the interface with RemoteOperations, and use OCFile IDs instead of OCFile objects as parameters
662 mLastRemoteOperation
.execute(mAccount
, getSherlockActivity(), this, mHandler
, getSherlockActivity());
664 boolean inDisplayActivity
= getActivity() instanceof FileDisplayActivity
;
665 getActivity().showDialog((inDisplayActivity
)? FileDisplayActivity
.DIALOG_SHORT_WAIT
: FileDetailActivity
.DIALOG_SHORT_WAIT
);
671 * Removes the file from local storage
674 public void onNeutral(String callerTag
) {
675 // TODO this code should be made in a secondary thread,
676 if (mFile
.isDown()) { // checks it is still there
678 File f
= new File(mFile
.getStoragePath());
680 mFile
.setStoragePath(null
);
681 mStorageManager
.saveFile(mFile
);
687 * User cancelled the removal action.
690 public void onCancel(String callerTag
) {
691 // nothing to do here
698 public OCFile
getFile(){
704 * Use this method to signal this Activity that it shall update its view.
706 * @param file : An {@link OCFile}
708 public void updateFileDetails(OCFile file, Account ocAccount) {
710 if (ocAccount != null && (
711 mStorageManager == null ||
712 (mAccount != null && !mAccount.equals(ocAccount))
714 mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());
716 mAccount = ocAccount;
717 updateFileDetails(false);
723 * Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment} to be previewed.
725 * @param file File to test if can be previewed.
726 * @return 'True' if the file can be handled by the fragment.
728 public static boolean canBePreviewed(OCFile file
) {
729 return (file
!= null
&& (file
.isAudio() || file
.isVideo()));
736 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
737 if (operation
.equals(mLastRemoteOperation
)) {
738 if (operation
instanceof RemoveFileOperation
) {
739 onRemoveFileOperationFinish((RemoveFileOperation
)operation
, result
);
744 private void onRemoveFileOperationFinish(RemoveFileOperation operation
, RemoteOperationResult result
) {
745 boolean inDisplayActivity
= getActivity() instanceof FileDisplayActivity
;
746 getActivity().dismissDialog((inDisplayActivity
)? FileDisplayActivity
.DIALOG_SHORT_WAIT
: FileDetailActivity
.DIALOG_SHORT_WAIT
);
748 if (result
.isSuccess()) {
749 Toast msg
= Toast
.makeText(getActivity().getApplicationContext(), R
.string
.remove_success_msg
, Toast
.LENGTH_LONG
);
754 Toast msg
= Toast
.makeText(getActivity(), R
.string
.remove_fail_msg
, Toast
.LENGTH_LONG
);
756 if (result
.isSslRecoverableException()) {
757 // TODO show the SSL warning dialog
762 private void stopPreview(boolean stopAudio
) {
763 if (mFile
.isAudio() && stopAudio
) {
764 mMediaServiceBinder
.pause();
766 } else if (mFile
.isVideo()) {
767 mVideoPreview
.stopPlayback();
774 * Finishes the preview
776 private void finish() {
777 Activity container
= getActivity();
778 if (container
instanceof FileDisplayActivity
) {
780 FragmentTransaction transaction
= getActivity().getSupportFragmentManager().beginTransaction();
781 transaction
.replace(R
.id
.file_details_container
, new FileDetailFragment(null
, null
), FileDetailFragment
.FTAG
); // empty FileDetailFragment
782 transaction
.commit();
783 ((FileFragment
.ContainerActivity
)container
).onFileStateChanged();
790 public int getPosition() {
792 mSavedPlaybackPosition
= mVideoPreview
.getCurrentPosition();
794 Log_OC
.e(TAG
, "getting position: " + mSavedPlaybackPosition
);
795 return mSavedPlaybackPosition
;
798 public boolean isPlaying() {
800 mAutoplay
= mVideoPreview
.isPlaying();