X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/491780ad1db3917aef6763fd2b0420ec9921dcdd..e901b609baa4dd5f681e2a5257c9e504997e3377:/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java diff --git a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index a2685b8a..7d6489b2 100644 --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@ -29,6 +29,7 @@ import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnErrorListener; import android.media.MediaPlayer.OnPreparedListener; +import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.IBinder; @@ -47,6 +48,7 @@ import com.actionbarsherlock.view.MenuItem; import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.FileMenuFilter; +import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.media.MediaControlView; import com.owncloud.android.media.MediaService; import com.owncloud.android.media.MediaServiceBinder; @@ -54,7 +56,6 @@ import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.dialog.ConfirmationDialogFragment; import com.owncloud.android.ui.dialog.RemoveFileDialogFragment; import com.owncloud.android.ui.fragment.FileFragment; -import com.owncloud.android.utils.Log_OC; /** @@ -98,7 +99,12 @@ public class PreviewMediaFragment extends FileFragment implements * @param fileToDetail An {@link OCFile} to preview in the fragment * @param ocAccount An ownCloud account; needed to start downloads */ - public PreviewMediaFragment(OCFile fileToDetail, Account ocAccount, int startPlaybackPosition, boolean autoplay) { + public PreviewMediaFragment( + OCFile fileToDetail, + Account ocAccount, + int startPlaybackPosition, + boolean autoplay) { + super(fileToDetail); mAccount = ocAccount; mSavedPlaybackPosition = startPlaybackPosition; @@ -109,9 +115,11 @@ public class PreviewMediaFragment extends FileFragment implements /** * Creates an empty fragment for previews. * - * MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically (for instance, when the device is turned a aside). + * MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically + * (for instance, when the device is turned a aside). * - * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful construction + * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful + * construction */ public PreviewMediaFragment() { super(); @@ -161,31 +169,37 @@ public class PreviewMediaFragment extends FileFragment implements super.onActivityCreated(savedInstanceState); Log_OC.e(TAG, "onActivityCreated"); - if (savedInstanceState != null) { - setFile((OCFile)savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE)); + OCFile file = getFile(); + if (savedInstanceState == null) { + if (file == null) { + throw new IllegalStateException("Instanced with a NULL OCFile"); + } + if (mAccount == null) { + throw new IllegalStateException("Instanced with a NULL ownCloud Account"); + } + if (!file.isDown()) { + throw new IllegalStateException("There is no local file to preview"); + } + + } else { + file = (OCFile)savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE); + setFile(file); mAccount = savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_ACCOUNT); - mSavedPlaybackPosition = savedInstanceState.getInt(PreviewMediaFragment.EXTRA_PLAY_POSITION); + mSavedPlaybackPosition = + savedInstanceState.getInt(PreviewMediaFragment.EXTRA_PLAY_POSITION); mAutoplay = savedInstanceState.getBoolean(PreviewMediaFragment.EXTRA_PLAYING); } - OCFile file = getFile(); - if (file == null) { - throw new IllegalStateException("Instanced with a NULL OCFile"); - } - if (mAccount == null) { - throw new IllegalStateException("Instanced with a NULL ownCloud Account"); - } - if (!file.isDown()) { - throw new IllegalStateException("There is no local file to preview"); - } - if (file.isVideo()) { - mVideoPreview.setVisibility(View.VISIBLE); - mImagePreview.setVisibility(View.GONE); - prepareVideo(); + if (file != null && file.isDown()) { + if (file.isVideo()) { + mVideoPreview.setVisibility(View.VISIBLE); + mImagePreview.setVisibility(View.GONE); + prepareVideo(); - } else { - mVideoPreview.setVisibility(View.GONE); - mImagePreview.setVisibility(View.VISIBLE); + } else { + mVideoPreview.setVisibility(View.GONE); + mImagePreview.setVisibility(View.VISIBLE); + } } } @@ -208,8 +222,11 @@ public class PreviewMediaFragment extends FileFragment implements outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION , mSavedPlaybackPosition); outState.putBoolean(PreviewMediaFragment.EXTRA_PLAYING , mAutoplay); } else { - outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION , mMediaServiceBinder.getCurrentPosition()); - outState.putBoolean(PreviewMediaFragment.EXTRA_PLAYING , mMediaServiceBinder.isPlaying()); + outState.putInt( + PreviewMediaFragment.EXTRA_PLAY_POSITION , + mMediaServiceBinder.getCurrentPosition()); + outState.putBoolean( + PreviewMediaFragment.EXTRA_PLAYING , mMediaServiceBinder.isPlaying()); } } @@ -220,7 +237,7 @@ public class PreviewMediaFragment extends FileFragment implements Log_OC.e(TAG, "onStart"); OCFile file = getFile(); - if (file != null) { + if (file != null && file.isDown()) { if (file.isAudio()) { bindMediaService(); @@ -273,6 +290,13 @@ public class PreviewMediaFragment extends FileFragment implements item.setVisible(false); item.setEnabled(false); } + + // additional restriction for this fragment + item = menu.findItem(R.id.action_move); + if (item != null) { + item.setVisible(false); + item.setEnabled(false); + } } @@ -307,6 +331,7 @@ public class PreviewMediaFragment extends FileFragment implements } case R.id.action_send_file: { sendFile(); + return true; } case R.id.action_sync_file: { mContainerActivity.getFileOperationsHelper().syncFile(getFile()); @@ -348,12 +373,15 @@ public class PreviewMediaFragment extends FileFragment implements mVideoPreview.setOnErrorListener(mVideoHelper); } + @SuppressWarnings("static-access") private void playVideo() { // create and prepare control panel for the user mMediaController.setMediaPlayer(mVideoPreview); - // load the video file in the video player ; when done, VideoHelper#onPrepared() will be called - mVideoPreview.setVideoPath(getFile().getStoragePath()); + // load the video file in the video player ; + // when done, VideoHelper#onPrepared() will be called + Uri uri = Uri.parse(getFile().getStoragePath()); + mVideoPreview.setVideoPath(uri.encode(getFile().getStoragePath())); } @@ -419,7 +447,8 @@ public class PreviewMediaFragment extends FileFragment implements @Override public boolean onError(MediaPlayer mp, int what, int extra) { if (mVideoPreview.getWindowToken() != null) { - String message = MediaService.getMessageForMediaError(getSherlockActivity(), what, extra); + String message = MediaService.getMessageForMediaError( + getSherlockActivity(), what, extra); new AlertDialog.Builder(getSherlockActivity()) .setMessage(message) .setPositiveButton(android.R.string.VideoView_error_button, @@ -440,8 +469,8 @@ public class PreviewMediaFragment extends FileFragment implements @Override public void onPause() { - super.onPause(); Log_OC.e(TAG, "onPause"); + super.onPause(); } @Override @@ -452,14 +481,13 @@ public class PreviewMediaFragment extends FileFragment implements @Override public void onDestroy() { - super.onDestroy(); Log_OC.e(TAG, "onDestroy"); + super.onDestroy(); } @Override public void onStop() { Log_OC.e(TAG, "onStop"); - super.onStop(); mPrepared = false; if (mMediaServiceConnection != null) { @@ -471,6 +499,8 @@ public class PreviewMediaFragment extends FileFragment implements mMediaServiceConnection = null; mMediaServiceBinder = null; } + + super.onStop(); } @Override @@ -503,7 +533,8 @@ public class PreviewMediaFragment extends FileFragment implements Log_OC.e(TAG, "onActivityResult " + this); super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) { - mSavedPlaybackPosition = data.getExtras().getInt(PreviewVideoActivity.EXTRA_START_POSITION); + mSavedPlaybackPosition = data.getExtras().getInt( + PreviewVideoActivity.EXTRA_START_POSITION); mAutoplay = data.getExtras().getBoolean(PreviewVideoActivity.EXTRA_AUTOPLAY); } } @@ -542,7 +573,8 @@ public class PreviewMediaFragment extends FileFragment implements @Override public void onServiceConnected(ComponentName component, IBinder service) { if (getSherlockActivity() != null) { - if (component.equals(new ComponentName(getSherlockActivity(), MediaService.class))) { + if (component.equals( + new ComponentName(getSherlockActivity(), MediaService.class))) { Log_OC.d(TAG, "Media service connected"); mMediaServiceBinder = (MediaServiceBinder) service; if (mMediaServiceBinder != null) { @@ -574,7 +606,10 @@ public class PreviewMediaFragment extends FileFragment implements if (mMediaController != null) { mMediaController.setMediaPlayer(null); } else { - Toast.makeText(getSherlockActivity(), "No media controller to release when disconnected from media service", Toast.LENGTH_SHORT).show(); + Toast.makeText( + getSherlockActivity(), + "No media controller to release when disconnected from media service", + Toast.LENGTH_SHORT).show(); } mMediaServiceBinder = null; mMediaServiceConnection = null; @@ -594,7 +629,8 @@ public class PreviewMediaFragment extends FileFragment implements } /** - * Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment} to be previewed. + * Helper method to test if an {@link OCFile} can be passed to a {@link PreviewMediaFragment} + * to be previewed. * * @param file File to test if can be previewed. * @return 'True' if the file can be handled by the fragment.