-/* ownCloud Android client application
- * Copyright (C) 2012-2013 ownCloud Inc.
+/**
+ * ownCloud Android client application
+ *
+ * @author David A. Velasco
+ * Copyright (C) 2015 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Configuration;
+import android.content.res.Resources;
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;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Toast;
import android.widget.VideoView;
-import com.actionbarsherlock.view.Menu;
-import com.actionbarsherlock.view.MenuInflater;
-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;
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;
/**
* This fragment shows a preview of a downloaded media file (audio or video).
*
- * Trying to get an instance with NULL {@link OCFile} or ownCloud {@link Account} values will produce an {@link IllegalStateException}.
- *
- * By now, if the {@link OCFile} passed is not downloaded, an {@link IllegalStateException} is generated on instantiation too.
+ * Trying to get an instance with NULL {@link OCFile} or ownCloud {@link Account} values will
+ * produce an {@link IllegalStateException}.
*
- * @author David A. Velasco
+ * By now, if the {@link OCFile} passed is not downloaded, an {@link IllegalStateException} is
+ * generated on instantiation too.
*/
public class PreviewMediaFragment extends FileFragment implements
OnTouchListener {
private void stopAudio() {
- Intent i = new Intent(getSherlockActivity(), MediaService.class);
+ Intent i = new Intent(getActivity(), MediaService.class);
i.setAction(MediaService.ACTION_STOP_ALL);
- getSherlockActivity().startService(i);
+ getActivity().startService(i);
}
getFile(),
mContainerActivity.getStorageManager().getAccount(),
mContainerActivity,
- getSherlockActivity()
+ getActivity()
);
mf.filter(menu);
}
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);
+ }
}
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());
+ Uri uri = Uri.parse(getFile().getStoragePath());
+ mVideoPreview.setVideoPath(uri.encode(getFile().getStoragePath()));
}
*
* Just starts the playback.
*
- * @param mp {@link MediaPlayer} instance performing the playback.
+ * @param vp {@link MediaPlayer} instance performing the playback.
*/
@Override
public void onPrepared(MediaPlayer vp) {
public boolean onError(MediaPlayer mp, int what, int extra) {
if (mVideoPreview.getWindowToken() != null) {
String message = MediaService.getMessageForMediaError(
- getSherlockActivity(), what, extra);
- new AlertDialog.Builder(getSherlockActivity())
+ getActivity(), what, extra);
+ new AlertDialog.Builder(getActivity())
.setMessage(message)
.setPositiveButton(android.R.string.VideoView_error_button,
new DialogInterface.OnClickListener() {
if (mMediaServiceBinder != null && mMediaController != null) {
mMediaServiceBinder.unregisterMediaController(mMediaController);
}
- getSherlockActivity().unbindService(mMediaServiceConnection);
+ getActivity().unbindService(mMediaServiceConnection);
mMediaServiceConnection = null;
mMediaServiceBinder = null;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN && v == mVideoPreview) {
- startFullScreenVideo();
+ // added a margin on the left to avoid interfering with gesture to open navigation drawer
+ if (event.getX() / Resources.getSystem().getDisplayMetrics().density > 24.0) {
+ startFullScreenVideo();
+ }
return true;
}
return false;
private void startFullScreenVideo() {
- Intent i = new Intent(getSherlockActivity(), PreviewVideoActivity.class);
+ Intent i = new Intent(getActivity(), PreviewVideoActivity.class);
i.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount);
i.putExtra(FileActivity.EXTRA_FILE, getFile());
i.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, mVideoPreview.isPlaying());
if (mMediaServiceConnection == null) {
mMediaServiceConnection = new MediaServiceConnection();
}
- getSherlockActivity().bindService( new Intent(getSherlockActivity(),
+ getActivity().bindService( new Intent(getActivity(),
MediaService.class),
mMediaServiceConnection,
Context.BIND_AUTO_CREATE);
@Override
public void onServiceConnected(ComponentName component, IBinder service) {
- if (getSherlockActivity() != null) {
+ if (getActivity() != null) {
if (component.equals(
- new ComponentName(getSherlockActivity(), MediaService.class))) {
+ new ComponentName(getActivity(), MediaService.class))) {
Log_OC.d(TAG, "Media service connected");
mMediaServiceBinder = (MediaServiceBinder) service;
if (mMediaServiceBinder != null) {
@Override
public void onServiceDisconnected(ComponentName component) {
- if (component.equals(new ComponentName(getSherlockActivity(), MediaService.class))) {
+ if (component.equals(new ComponentName(getActivity(), MediaService.class))) {
Log_OC.e(TAG, "Media service suddenly disconnected");
if (mMediaController != null) {
mMediaController.setMediaPlayer(null);
} else {
Toast.makeText(
- getSherlockActivity(),
+ getActivity(),
"No media controller to release when disconnected from media service",
Toast.LENGTH_SHORT).show();
}
* Finishes the preview
*/
private void finish() {
- getSherlockActivity().onBackPressed();
+ getActivity().onBackPressed();
}