import com.owncloud.android.ui.activity.ComponentsGetter;
/**
- * Filters out the file actions available in a given {@link Menu} for a given {@link OCFile}
+ * Filters out the file actions available in a given {@link Menu} for a given {@link OCFile}
* according to the current state of the latest.
*/
public class FileMenuFilter {
private ComponentsGetter mComponentsGetter;
private Account mAccount;
private Context mContext;
-
+
/**
* Constructor
- *
+ *
* @param targetFile {@link OCFile} target of the action to filter in the {@link Menu}.
* @param account ownCloud {@link Account} holding targetFile.
* @param cg Accessor to app components, needed to access the
mComponentsGetter = cg;
mContext = context;
}
-
-
+
+
/**
* Filters out the file actions available in the passed {@link Menu} taken into account
* the state of the {@link OCFile} held by the filter.
- *
+ *
* @param menu Options or context menu to filter.
*/
public void filter(Menu menu) {
- List<Integer> toShow = new ArrayList<Integer>();
- List<Integer> toHide = new ArrayList<Integer>();
-
+ List<Integer> toShow = new ArrayList<Integer>();
+ List<Integer> toHide = new ArrayList<Integer>();
+
filter(toShow, toHide);
-
+
MenuItem item = null;
for (int i : toShow) {
item = menu.findItem(i);
item.setEnabled(true);
}
}
-
+
for (int i : toHide) {
item = menu.findItem(i);
if (item != null) {
/**
* Performs the real filtering, to be applied in the {@link Menu} by the caller methods.
- *
+ *
* Decides what actions must be shown and hidden.
- *
- * @param toShow List to save the options that must be shown in the menu.
+ *
+ * @param toShow List to save the options that must be shown in the menu.
* @param toHide List to save the options that must be shown in the menu.
*/
private void filter(List<Integer> toShow, List <Integer> toHide) {
FileUploaderBinder uploaderBinder = mComponentsGetter.getFileUploaderBinder();
uploading = (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile));
}
-
+
/// decision is taken for each possible action on a file in the menu
-
+
// DOWNLOAD
if (mFile == null || mFile.isDown() || downloading || uploading) {
toHide.add(R.id.action_download_file);
-
+
} else {
toShow.add(R.id.action_download_file);
}
-
+
// RENAME
if (mFile == null || downloading || uploading) {
toHide.add(R.id.action_rename_file);
-
+
} else {
toShow.add(R.id.action_rename_file);
}
- // MOVE
+ // MOVE & COPY
if (mFile == null || downloading || uploading) {
toHide.add(R.id.action_move);
-
+ toHide.add(R.id.action_copy);
} else {
toShow.add(R.id.action_move);
+ toShow.add(R.id.action_copy);
}
-
+
// REMOVE
if (mFile == null || downloading || uploading) {
toHide.add(R.id.action_remove_file);
-
+
} else {
toShow.add(R.id.action_remove_file);
}
-
+
// OPEN WITH (different to preview!)
if (mFile == null || mFile.isFolder() || !mFile.isDown() || downloading || uploading) {
toHide.add(R.id.action_open_file_with);
-
+
} else {
toShow.add(R.id.action_open_file_with);
}
-
-
+
+
// CANCEL DOWNLOAD
if (mFile == null || !downloading) {
toHide.add(R.id.action_cancel_download);
} else {
toShow.add(R.id.action_cancel_download);
}
-
+
// CANCEL UPLOAD
if (mFile == null || !uploading || mFile.isFolder()) {
toHide.add(R.id.action_cancel_upload);
} else {
toShow.add(R.id.action_cancel_upload);
}
-
+
// SYNC FILE CONTENTS
if (mFile == null || mFile.isFolder() || !mFile.isDown() || downloading || uploading) {
toHide.add(R.id.action_sync_file);
} else {
toShow.add(R.id.action_sync_file);
}
-
+
// SHARE FILE
// TODO add check on SHARE available on server side?
boolean shareAllowed = (mContext != null &&
} else {
toShow.add(R.id.action_share_file);
}
-
+
// UNSHARE FILE
// TODO add check on SHARE available on server side?
if ( !shareAllowed || (mFile == null || !mFile.isShareByLink())) {
} else {
toShow.add(R.id.action_see_details);
}
-
+
// SEND
boolean sendAllowed = (mContext != null &&
mContext.getString(R.string.send_files_to_other_apps).equalsIgnoreCase("on"));
/// 1. check copy validity
if (mTargetParentPath.startsWith(mSrcPath)) {
- return new RemoteOperationResult(ResultCode.INVALID_MOVE_INTO_DESCENDANT);
+ return new RemoteOperationResult(ResultCode.INVALID_COPY_INTO_DESCENDANT);
}
mFile = getStorageManager().getFileByPath(mSrcPath);
if (mFile == null) {
*/
package com.owncloud.android.ui.fragment;
-import java.lang.ref.WeakReference;
-
import android.accounts.Account;
-import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.services.observer.FileObserverService;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
import com.owncloud.android.utils.DisplayUtils;
+import java.lang.ref.WeakReference;
+
/**
* This Fragment is used to display the details about a file.
private int mLayout;
private View mView;
private Account mAccount;
-
+
public ProgressListener mProgressListener;
-
+
private static final String TAG = FileDetailFragment.class.getSimpleName();
public static final String FTAG_CONFIRMATION = "REMOVE_CONFIRMATION_FRAGMENT";
public static final String FTAG_RENAME_FILE = "RENAME_FILE_FRAGMENT";
mLayout = R.layout.file_details_empty;
mProgressListener = null;
}
-
+
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
-
+
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
mAccount = getArguments().getParcelable(ARG_ACCOUNT);
if (savedInstanceState != null) {
- setFile((OCFile)savedInstanceState.getParcelable(FileActivity.EXTRA_FILE));
+ setFile((OCFile) savedInstanceState.getParcelable(FileActivity.EXTRA_FILE));
mAccount = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
}
-
- if(getFile() != null && mAccount != null) {
+
+ if (getFile() != null && mAccount != null) {
mLayout = R.layout.file_details_fragment;
}
-
+
mView = inflater.inflate(mLayout, null);
if (mLayout == R.layout.file_details_fragment) {
super.onStart();
listenForTransferProgress();
}
-
+
@Override
public void onStop() {
leaveTransferProgress();
super.onStop();
}
-
+
@Override
public View getView() {
return super.getView() == null ? mView : super.getView();
}
-
+
/**
* {@inheritDoc}
*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.file_actions_menu, menu);
- }
+ }
+
-
/**
* {@inheritDoc}
*/
@Override
- public void onPrepareOptionsMenu (Menu menu) {
+ public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
-
+
if (mContainerActivity.getStorageManager() != null) {
FileMenuFilter mf = new FileMenuFilter(
getFile(),
);
mf.filter(menu);
}
-
+
// additional restriction for this fragment
MenuItem item = menu.findItem(R.id.action_see_details);
if (item != null) {
item.setVisible(false);
item.setEnabled(false);
}
+
+ // additional restriction for this fragment
+ item = menu.findItem(R.id.action_copy);
+ if (item != null) {
+ item.setVisible(false);
+ item.setEnabled(false);
+ }
}
-
+
/**
* {@inheritDoc}
*/
}
case R.id.action_cancel_download:
case R.id.action_cancel_upload: {
- ((FileDisplayActivity)mContainerActivity).cancelTransference(getFile());
+ ((FileDisplayActivity) mContainerActivity).cancelTransference(getFile());
return true;
}
- case R.id.action_download_file:
+ case R.id.action_download_file:
case R.id.action_sync_file: {
mContainerActivity.getFileOperationsHelper().syncFile(getFile());
return true;
// Obtain the file
if (!getFile().isDown()) { // Download the file
Log_OC.d(TAG, getFile().getRemotePath() + " : File must be downloaded");
- ((FileDisplayActivity)mContainerActivity).startDownloadForSending(getFile());
-
- } else {
+ ((FileDisplayActivity) mContainerActivity).startDownloadForSending(getFile());
+
+ }
+ else {
mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile());
}
return true;
break;
}
case R.id.fdCancelBtn: {
- ((FileDisplayActivity)mContainerActivity).cancelTransference(getFile());
+ ((FileDisplayActivity) mContainerActivity).cancelTransference(getFile());
break;
}
default:
/**
* Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced.
- *
- * @return True when the fragment was created with the empty layout.
+ *
+ * @return True when the fragment was created with the empty layout.
*/
public boolean isEmpty() {
return (mLayout == R.layout.file_details_empty || getFile() == null || mAccount == null);
}
-
+
/**
* Use this method to signal this Activity that it shall update its view.
- *
+ *
* @param file : An {@link OCFile}
*/
public void updateFileDetails(OCFile file, Account ocAccount) {
/**
* Updates the view with all relevant details about that file.
+ * <p/>
+ * TODO Remove parameter when the transferring state of files is kept in database.
*
- * TODO Remove parameter when the transferring state of files is kept in database.
- *
- * @param transferring Flag signaling if the file should be considered as downloading or uploading,
- * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and
- * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false.
- *
- * @param refresh If 'true', try to refresh the whole file from the database
+ * @param transferring Flag signaling if the file should be considered as downloading or uploading,
+ * although {@link FileDownloaderBinder#isDownloading(Account, OCFile)} and
+ * {@link FileUploaderBinder#isUploading(Account, OCFile)} return false.
+ * @param refresh If 'true', try to refresh the whole file from the database
*/
public void updateFileDetails(boolean transferring, boolean refresh) {
if (readyToShow()) {
setFile(storageManager.getFileByPath(getFile().getRemotePath()));
}
OCFile file = getFile();
-
+
// set file details
setFilename(file.getFileName());
setFiletype(file.getMimetype(), file.getFileName());
(uploaderBinder != null && uploaderBinder.isUploading(mAccount, file))
) {
setButtonsForTransferring();
-
+
} else if (file.isDown()) {
setButtonsForDown();
}
getView().invalidate();
}
-
+
/**
* Checks if the fragment is ready to show details of a OCFile
- *
- * @return 'True' when the fragment is ready to show details of a file
+ *
+ * @return 'True' when the fragment is ready to show details of a file
*/
private boolean readyToShow() {
- return (getFile() != null && mAccount != null && mLayout == R.layout.file_details_fragment);
+ return (getFile() != null && mAccount != null && mLayout == R.layout.file_details_fragment);
}
/**
* Updates the filename in view
+ *
* @param filename to set
*/
private void setFilename(String filename) {
TextView tv = (TextView) getView().findViewById(R.id.fdFilename);
- if (tv != null)
+ if (tv != null) {
tv.setText(filename);
+ }
}
/**
/**
* Updates the file size in view
+ *
* @param filesize in bytes to set
*/
private void setFilesize(long filesize) {
TextView tv = (TextView) getView().findViewById(R.id.fdSize);
- if (tv != null)
+ if (tv != null) {
tv.setText(DisplayUtils.bytesToHumanReadable(filesize));
+ }
}
-
+
/**
* Updates the time that the file was last modified
+ *
* @param milliseconds Unix time to set
*/
- private void setTimeModified(long milliseconds){
+ private void setTimeModified(long milliseconds) {
TextView tv = (TextView) getView().findViewById(R.id.fdModified);
- if(tv != null){
+ if (tv != null) {
tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds));
}
}
-
+
/**
* Enables or disables buttons for a file being downloaded
*/
// show the progress bar for the transfer
getView().findViewById(R.id.fdProgressBlock).setVisibility(View.VISIBLE);
- TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
+ TextView progressText = (TextView) getView().findViewById(R.id.fdProgressText);
progressText.setVisibility(View.VISIBLE);
FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
//if (getFile().isDownloading()) {
if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, getFile())) {
progressText.setText(R.string.downloader_download_in_progress_ticker);
- } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, getFile())) {
- progressText.setText(R.string.uploader_upload_in_progress_ticker);
+ }
+ else {
+ if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, getFile())) {
+ progressText.setText(R.string.uploader_upload_in_progress_ticker);
+ }
}
}
}
/**
- * Enables or disables buttons for a file locally available
+ * Enables or disables buttons for a file locally available
*/
private void setButtonsForDown() {
if (!isEmpty()) {
// hides the progress bar
getView().findViewById(R.id.fdProgressBlock).setVisibility(View.GONE);
- TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
+ TextView progressText = (TextView) getView().findViewById(R.id.fdProgressText);
progressText.setVisibility(View.GONE);
}
}
/**
- * Enables or disables buttons for a file not locally available
+ * Enables or disables buttons for a file not locally available
*/
private void setButtonsForRemote() {
if (!isEmpty()) {
// hides the progress bar
getView().findViewById(R.id.fdProgressBlock).setVisibility(View.GONE);
- TextView progressText = (TextView)getView().findViewById(R.id.fdProgressText);
+ TextView progressText = (TextView) getView().findViewById(R.id.fdProgressText);
progressText.setVisibility(View.GONE);
}
}
-
+
public void listenForTransferProgress() {
if (mProgressListener != null) {
}
}
}
-
-
+
+
public void leaveTransferProgress() {
if (mProgressListener != null) {
if (mContainerActivity.getFileDownloaderBinder() != null) {
}
-
/**
* Helper class responsible for updating the progress bar shown for file uploading or
* downloading
private class ProgressListener implements OnDatatransferProgressListener {
int mLastPercent = 0;
WeakReference<ProgressBar> mProgressBar = null;
-
+
ProgressListener(ProgressBar progressBar) {
mProgressBar = new WeakReference<ProgressBar>(progressBar);
}
-
+
@Override
public void onTransferProgress(long progressRate, long totalTransferredSoFar,
long totalToTransfer, String filename) {
import android.widget.ProgressBar;
import android.widget.TextView;
+import com.owncloud.android.R;
+import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.utils.Log_OC;
+import com.owncloud.android.ui.fragment.FileFragment;
+
+import java.lang.ref.WeakReference;
/**
public ProgressListener mProgressListener;
private boolean mListening;
-
+
private static final String TAG = FileDownloadFragment.class.getSimpleName();
-
+
private boolean mIgnoreFirstSavedState;
private boolean mError;
mIgnoreFirstSavedState = args.getBoolean(ARG_IGNORE_FIRST);
mAccount = args.getParcelable(ARG_ACCOUNT);
}
-
+
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
+ Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
-
+
if (savedInstanceState != null) {
if (!mIgnoreFirstSavedState) {
- setFile((OCFile)savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_FILE));
+ setFile((OCFile) savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_FILE));
mAccount = savedInstanceState.getParcelable(FileDownloadFragment.EXTRA_ACCOUNT);
mError = savedInstanceState.getBoolean(FileDownloadFragment.EXTRA_ERROR);
- } else {
+ }
+ else {
mIgnoreFirstSavedState = false;
}
}
-
+
View view = null;
view = inflater.inflate(R.layout.file_download_fragment, container, false);
mView = view;
-
- ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.progressBar);
+
+ ProgressBar progressBar = (ProgressBar) mView.findViewById(R.id.progressBar);
mProgressListener = new ProgressListener(progressBar);
-
+
(mView.findViewById(R.id.cancelBtn)).setOnClickListener(this);
(mView.findViewById(R.id.fileDownloadLL)).setOnClickListener(new OnClickListener() {
if (mError) {
setButtonsForRemote();
- } else {
+ }
+ else {
setButtonsForTransferring();
}
-
+
return view;
}
-
+
@Override
public void onSaveInstanceState(Bundle outState) {
super.onStart();
listenForTransferProgress();
}
-
+
@Override
public void onResume() {
super.onResume();
super.onPause();
}
-
+
@Override
public void onStop() {
leaveTransferProgress();
super.onStop();
}
-
+
@Override
public void onDestroy() {
super.onDestroy();
}
-
-
+
+
@Override
public View getView() {
if (!mListening) {
return super.getView() == null ? mView : super.getView();
}
-
+
@Override
public void onClick(View v) {
switch (v.getId()) {
}
}
-
+
/**
* Enables or disables buttons for a file being downloaded
*/
private void setButtonsForTransferring() {
getView().findViewById(R.id.cancelBtn).setVisibility(View.VISIBLE);
-
+
// show the progress bar for the transfer
getView().findViewById(R.id.progressBar).setVisibility(View.VISIBLE);
- TextView progressText = (TextView)getView().findViewById(R.id.progressText);
+ TextView progressText = (TextView) getView().findViewById(R.id.progressText);
progressText.setText(R.string.downloader_download_in_progress_ticker);
progressText.setVisibility(View.VISIBLE);
-
+
// hides the error icon
getView().findViewById(R.id.errorText).setVisibility(View.GONE);
getView().findViewById(R.id.error_image).setVisibility(View.GONE);
}
-
/**
- * Enables or disables buttons for a file locally available
+ * Enables or disables buttons for a file locally available
*/
private void setButtonsForDown() {
getView().findViewById(R.id.cancelBtn).setVisibility(View.GONE);
-
+
// hides the progress bar
getView().findViewById(R.id.progressBar).setVisibility(View.GONE);
-
+
// updates the text message
- TextView progressText = (TextView)getView().findViewById(R.id.progressText);
+ TextView progressText = (TextView) getView().findViewById(R.id.progressText);
progressText.setText(R.string.common_loading);
progressText.setVisibility(View.VISIBLE);
-
+
// hides the error icon
getView().findViewById(R.id.errorText).setVisibility(View.GONE);
getView().findViewById(R.id.error_image).setVisibility(View.GONE);
}
-
+
/**
- * Enables or disables buttons for a file not locally available
- *
+ * Enables or disables buttons for a file not locally available
+ * <p/>
* Currently, this is only used when a download was failed
*/
private void setButtonsForRemote() {
getView().findViewById(R.id.cancelBtn).setVisibility(View.GONE);
-
+
// hides the progress bar and message
getView().findViewById(R.id.progressBar).setVisibility(View.GONE);
getView().findViewById(R.id.progressText).setVisibility(View.GONE);
getView().findViewById(R.id.errorText).setVisibility(View.VISIBLE);
getView().findViewById(R.id.error_image).setVisibility(View.VISIBLE);
}
-
+
public void listenForTransferProgress() {
if (mProgressListener != null && !mListening) {
}
}
}
-
-
+
+
public void leaveTransferProgress() {
if (mProgressListener != null) {
if (mContainerActivity.getFileDownloaderBinder() != null) {
private class ProgressListener implements OnDatatransferProgressListener {
int mLastPercent = 0;
WeakReference<ProgressBar> mProgressBar = null;
-
+
ProgressListener(ProgressBar progressBar) {
mProgressBar = new WeakReference<ProgressBar>(progressBar);
}
-
+
@Override
public void onTransferProgress(
long progressRate, long totalTransferredSoFar, long totalToTransfer, String filename
public void setError(boolean error) {
mError = error;
- };
-
+ }
+
+ ;
}
private ProgressBar mProgressWheel;
public Bitmap mBitmap = null;
-
+
private static final String TAG = PreviewImageFragment.class.getSimpleName();
private boolean mIgnoreFirstSavedState;
-
+
private LoadBitmapTask mLoadBitmapTask = null;
return frag;
}
-
+
/**
* Creates an empty fragment for image previews.
public PreviewImageFragment() {
mIgnoreFirstSavedState = false;
}
-
-
+
+
/**
* {@inheritDoc}
*/
mIgnoreFirstSavedState = args.getBoolean(ARG_IGNORE_FIRST);
setHasOptionsMenu(true);
}
-
+
/**
* {@inheritDoc}
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
+ Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.preview_image_fragment, container, false);
mImageView = (TouchImageViewCustom) view.findViewById(R.id.image);
throw new IllegalStateException("There is no local file to preview");
}
}
-
+
/**
* {@inheritDoc}
super.onSaveInstanceState(outState);
outState.putParcelable(PreviewImageFragment.EXTRA_FILE, getFile());
}
-
+
@Override
public void onStart() {
mLoadBitmapTask.execute(getFile().getStoragePath());
}
}
-
-
+
+
@Override
public void onStop() {
Log_OC.d(TAG, "onStop starts");
}
super.onStop();
}
-
+
/**
* {@inheritDoc}
*/
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
-
+
if (mContainerActivity.getStorageManager() != null) {
// Update the file
setFile(mContainerActivity.getStorageManager().getFileById(getFile().getFileId()));
-
+
FileMenuFilter mf = new FileMenuFilter(
getFile(),
mContainerActivity.getStorageManager().getAccount(),
);
mf.filter(menu);
}
-
+
// additional restriction for this fragment
// TODO allow renaming in PreviewImageFragment
MenuItem item = menu.findItem(R.id.action_rename_file);
item.setVisible(false);
item.setEnabled(false);
}
-
+
// additional restriction for this fragment
// TODO allow refresh file in PreviewImageFragment
item = menu.findItem(R.id.action_sync_file);
item.setVisible(false);
item.setEnabled(false);
}
-
+
+ // additional restriction for this fragment
+ item = menu.findItem(R.id.action_copy);
+ if (item != null) {
+ item.setVisible(false);
+ item.setEnabled(false);
+ }
+
}
-
-
+
/**
* {@inheritDoc}
*/
return false;
}
}
-
+
private void seeDetails() {
- mContainerActivity.showDetails(getFile());
+ mContainerActivity.showDetails(getFile());
}
super.onDestroy();
}
-
+
/**
* Opens the previewed image with an external application.
*/
mContainerActivity.getFileOperationsHelper().openFile(getFile());
finish();
}
-
-
+
+
private class LoadBitmapTask extends AsyncTask<String, Void, Bitmap> {
/**
*/
private final WeakReference<TextView> mMessageViewRef;
-
+
/**
* Weak reference to the target {@link ProgressBar} shown while the load is in progress.
*
*/
private final WeakReference<ProgressBar> mProgressWheelRef;
-
+
/**
- * Error message to show when a load fails
+ * Error message to show when a load fails
*/
private int mErrorMessageId;
-
-
+
+
/**
* Constructor.
- *
- * @param imageView Target {@link ImageView} where the bitmap will be loaded into.
+ *
+ * @param imageView Target {@link ImageView} where the bitmap will be loaded into.
*/
public LoadBitmapTask(ImageViewCustom imageView, TextView messageView,
ProgressBar progressWheel) {
mMessageViewRef = new WeakReference<TextView>(messageView);
mProgressWheelRef = new WeakReference<ProgressBar>(progressWheel);
}
-
-
+
+
@Override
protected Bitmap doInBackground(String... params) {
Bitmap result = null;
} catch (NoSuchFieldError e) {
mErrorMessageId = R.string.common_error_unknown;
- Log_OC.e(TAG, "Error from access to unexisting field despite protection; file "
- + storagePath, e);
-
+ Log_OC.e(TAG, "Error from access to unexisting field despite protection; file "
+ + storagePath, e);
+
} catch (Throwable t) {
mErrorMessageId = R.string.common_error_unknown;
Log_OC.e(TAG, "Unexpected error loading " + getFile().getStoragePath(), t);
-
+
}
-
+
return result;
}
-
+
@Override
protected void onCancelled(Bitmap result) {
if (result != null) {
hideProgressWheel();
if (result != null) {
showLoadedImage(result);
- } else {
+ }
+ else {
showErrorMessage();
}
if (result != null && mBitmap != result) {
result.recycle();
}
}
-
+
@SuppressLint("InlinedApi")
private void showLoadedImage(Bitmap result) {
final ImageViewCustom imageView = mImageViewRef.get();
messageView.setVisibility(View.GONE);
} // else , silently finish, the fragment was destroyed
}
-
+
private void showErrorMessage() {
final ImageView imageView = mImageViewRef.get();
if (imageView != null) {
messageView.setVisibility(View.VISIBLE);
} // else , silently finish, the fragment was destroyed
}
-
+
private void hideProgressWheel() {
final ProgressBar progressWheel = mProgressWheelRef.get();
if (progressWheel != null) {
progressWheel.setVisibility(View.GONE);
}
}
-
+
}
/**
return (file != null && file.isImage());
}
-
+
/**
* Finishes the preview
*/
Activity container = getActivity();
container.finish();
}
-
+
public TouchImageViewCustom getImageView() {
return mImageView;
}
/**
* 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}.
*
private ImageView mImagePreview;
private VideoView mVideoPreview;
private int mSavedPlaybackPosition;
-
+
private MediaServiceBinder mMediaServiceBinder = null;
private MediaControlView mMediaController = null;
private MediaServiceConnection mMediaServiceConnection = null;
private VideoHelper mVideoHelper;
private boolean mAutoplay;
public boolean mPrepared;
-
+
private static final String TAG = PreviewMediaFragment.class.getSimpleName();
-
+
/**
* Creates a fragment to preview a file.
- *
+ * <p/>
* When 'fileToDetail' or 'ocAccount' are null
- *
- * @param fileToDetail An {@link OCFile} to preview in the fragment
- * @param ocAccount An ownCloud account; needed to start downloads
+ *
+ * @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,
+ OCFile fileToDetail,
+ Account ocAccount,
+ int startPlaybackPosition,
boolean autoplay) {
-
+
super(fileToDetail);
mAccount = ocAccount;
mSavedPlaybackPosition = startPlaybackPosition;
mAutoplay = autoplay;
}
-
-
+
+
/**
- * 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).
- *
- * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful
- * construction
+ * Creates an empty fragment for previews.
+ * <p/>
+ * MUST BE KEPT: the system uses it when tries to reinstantiate a fragment automatically
+ * (for instance, when the device is turned a aside).
+ * <p/>
+ * DO NOT CALL IT: an {@link OCFile} and {@link Account} must be provided for a successful
+ * construction
*/
public PreviewMediaFragment() {
super();
mSavedPlaybackPosition = 0;
mAutoplay = true;
}
-
-
+
+
/**
* {@inheritDoc}
*/
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
-
+
/**
* {@inheritDoc}
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
+ Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
Log_OC.e(TAG, "onCreateView");
-
+
mView = inflater.inflate(R.layout.file_preview, container, false);
-
- mImagePreview = (ImageView)mView.findViewById(R.id.image_preview);
- mVideoPreview = (VideoView)mView.findViewById(R.id.video_preview);
+
+ mImagePreview = (ImageView) mView.findViewById(R.id.image_preview);
+ mVideoPreview = (VideoView) mView.findViewById(R.id.video_preview);
mVideoPreview.setOnTouchListener(this);
-
- mMediaController = (MediaControlView)mView.findViewById(R.id.media_controller);
-
+
+ mMediaController = (MediaControlView) mView.findViewById(R.id.media_controller);
+
return mView;
}
-
+
/**
* {@inheritDoc}
if (!file.isDown()) {
throw new IllegalStateException("There is no local file to preview");
}
-
- } else {
- file = (OCFile)savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE);
+
+ }
+ else {
+ file = (OCFile) savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_FILE);
setFile(file);
mAccount = savedInstanceState.getParcelable(PreviewMediaFragment.EXTRA_ACCOUNT);
- mSavedPlaybackPosition =
+ mSavedPlaybackPosition =
savedInstanceState.getInt(PreviewMediaFragment.EXTRA_PLAY_POSITION);
mAutoplay = savedInstanceState.getBoolean(PreviewMediaFragment.EXTRA_PLAYING);
-
+
}
if (file != null && file.isDown()) {
if (file.isVideo()) {
mVideoPreview.setVisibility(View.VISIBLE);
mImagePreview.setVisibility(View.GONE);
prepareVideo();
-
- } else {
+
+ }
+ else {
mVideoPreview.setVisibility(View.GONE);
mImagePreview.setVisibility(View.VISIBLE);
}
}
-
+
}
-
+
/**
* {@inheritDoc}
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Log_OC.e(TAG, "onSaveInstanceState");
-
+
outState.putParcelable(PreviewMediaFragment.EXTRA_FILE, getFile());
outState.putParcelable(PreviewMediaFragment.EXTRA_ACCOUNT, mAccount);
-
+
if (getFile().isVideo()) {
mSavedPlaybackPosition = mVideoPreview.getCurrentPosition();
mAutoplay = mVideoPreview.isPlaying();
- outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION , mSavedPlaybackPosition);
- outState.putBoolean(PreviewMediaFragment.EXTRA_PLAYING , mAutoplay);
- } else {
+ outState.putInt(PreviewMediaFragment.EXTRA_PLAY_POSITION, mSavedPlaybackPosition);
+ outState.putBoolean(PreviewMediaFragment.EXTRA_PLAYING, mAutoplay);
+ }
+ else {
outState.putInt(
- PreviewMediaFragment.EXTRA_PLAY_POSITION ,
+ PreviewMediaFragment.EXTRA_PLAY_POSITION,
mMediaServiceBinder.getCurrentPosition());
outState.putBoolean(
- PreviewMediaFragment.EXTRA_PLAYING , mMediaServiceBinder.isPlaying());
+ PreviewMediaFragment.EXTRA_PLAYING, mMediaServiceBinder.isPlaying());
}
}
-
+
@Override
public void onStart() {
OCFile file = getFile();
if (file != null && file.isDown()) {
- if (file.isAudio()) {
- bindMediaService();
-
- } else if (file.isVideo()) {
- stopAudio();
- playVideo();
- }
+ if (file.isAudio()) {
+ bindMediaService();
+
+ }
+ else {
+ if (file.isVideo()) {
+ stopAudio();
+ playVideo();
+ }
+ }
}
}
-
-
+
+
private void stopAudio() {
Intent i = new Intent(getActivity(), MediaService.class);
i.setAction(MediaService.ACTION_STOP_ALL);
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
-
+
if (mContainerActivity.getStorageManager() != null) {
FileMenuFilter mf = new FileMenuFilter(
getFile(),
item.setVisible(false);
item.setEnabled(false);
}
+
+ // additional restriction for this fragment
+ item = menu.findItem(R.id.action_copy);
+ if (item != null) {
+ item.setVisible(false);
+ item.setEnabled(false);
+ }
}
-
-
+
+
/**
* {@inheritDoc}
*/
return false;
}
}
-
/**
* Update the file of the fragment with file value
+ *
* @param file
*/
- public void updateFile(OCFile file){
+ public void updateFile(OCFile file) {
setFile(file);
}
-
+
private void sendFile() {
stopPreview(false);
mContainerActivity.getFileOperationsHelper().sendDownloadedFile(getFile());
-
+
}
private void seeDetails() {
stopPreview(false);
- mContainerActivity.showDetails(getFile());
+ mContainerActivity.showDetails(getFile());
}
mVideoPreview.setOnCompletionListener(mVideoHelper);
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
Uri uri = Uri.parse(getFile().getStoragePath());
mVideoPreview.setVideoPath(uri.encode(getFile().getStoragePath()));
}
-
+
private class VideoHelper implements OnCompletionListener, OnPreparedListener, OnErrorListener {
-
- /**
+
+ /**
* Called when the file is ready to be played.
- *
+ * <p/>
* Just starts the playback.
- *
+ *
* @param vp {@link MediaPlayer} instance performing the playback.
*/
@Override
public void onPrepared(MediaPlayer vp) {
Log_OC.e(TAG, "onPrepared");
mVideoPreview.seekTo(mSavedPlaybackPosition);
- if (mAutoplay) {
+ if (mAutoplay) {
mVideoPreview.start();
}
mMediaController.setEnabled(true);
mMediaController.updatePausePlay();
mPrepared = true;
}
-
-
+
+
/**
* Called when the file is finished playing.
- *
+ * <p/>
* Finishes the activity.
- *
- * @param mp {@link MediaPlayer} instance performing the playback.
+ *
+ * @param mp {@link MediaPlayer} instance performing the playback.
*/
@Override
- public void onCompletion(MediaPlayer mp) {
+ public void onCompletion(MediaPlayer mp) {
Log_OC.e(TAG, "completed");
if (mp != null) {
mVideoPreview.seekTo(0);
// next lines are necessary to work around undesired video loops
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD) {
- mVideoPreview.pause();
-
- } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD_MR1) {
- // mVideePreview.pause() is not enough
-
- mMediaController.setEnabled(false);
- mVideoPreview.stopPlayback();
- mAutoplay = false;
- mSavedPlaybackPosition = 0;
- mVideoPreview.setVideoPath(getFile().getStoragePath());
+ mVideoPreview.pause();
+
+ }
+ else {
+ if (Build.VERSION.SDK_INT == Build.VERSION_CODES.GINGERBREAD_MR1) {
+ // mVideePreview.pause() is not enough
+
+ mMediaController.setEnabled(false);
+ mVideoPreview.stopPlayback();
+ mAutoplay = false;
+ mSavedPlaybackPosition = 0;
+ mVideoPreview.setVideoPath(getFile().getStoragePath());
+ }
}
} // else : called from onError()
mMediaController.updatePausePlay();
}
-
-
+
+
/**
* Called when an error in playback occurs.
- *
- * @param mp {@link MediaPlayer} instance performing the playback.
- * @param what Type of error
- * @param extra Extra code specific to the error
+ *
+ * @param mp {@link MediaPlayer} instance performing the playback.
+ * @param what Type of error
+ * @param extra Extra code specific to the error
*/
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
}
return true;
}
-
+
}
-
+
@Override
public void onPause() {
Log_OC.e(TAG, "onPause");
super.onPause();
}
-
+
@Override
public void onResume() {
super.onResume();
Log_OC.e(TAG, "onResume");
}
-
+
@Override
public void onDestroy() {
Log_OC.e(TAG, "onDestroy");
super.onDestroy();
}
-
+
@Override
public void onStop() {
Log_OC.e(TAG, "onStop");
mMediaServiceConnection = null;
mMediaServiceBinder = null;
}
-
+
super.onStop();
}
-
+
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN && v == mVideoPreview) {
return false;
}
-
+
private void startFullScreenVideo() {
Intent i = new Intent(getActivity(), PreviewVideoActivity.class);
i.putExtra(FileActivity.EXTRA_ACCOUNT, mAccount);
}
@Override
- public void onConfigurationChanged (Configuration newConfig) {
+ public void onConfigurationChanged(Configuration newConfig) {
Log_OC.e(TAG, "onConfigurationChanged " + this);
}
-
+
@Override
- public void onActivityResult (int requestCode, int resultCode, Intent data) {
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log_OC.e(TAG, "onActivityResult " + this);
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
mSavedPlaybackPosition = data.getExtras().getInt(
PreviewVideoActivity.EXTRA_START_POSITION);
- mAutoplay = data.getExtras().getBoolean(PreviewVideoActivity.EXTRA_AUTOPLAY);
+ mAutoplay = data.getExtras().getBoolean(PreviewVideoActivity.EXTRA_AUTOPLAY);
}
}
-
+
private void playAudio() {
OCFile file = getFile();
if (!mMediaServiceBinder.isPlaying(file)) {
Log_OC.d(TAG, "starting playback of " + file.getStoragePath());
mMediaServiceBinder.start(mAccount, file, mAutoplay, mSavedPlaybackPosition);
-
- } else {
+
+ }
+ else {
if (!mMediaServiceBinder.isPlaying() && mAutoplay) {
mMediaServiceBinder.start();
mMediaController.updatePausePlay();
Log_OC.d(TAG, "Successfully bound to MediaService, MediaController ready");
- } else {
+ }
+ else {
Log_OC.e(TAG, "Unexpected response from MediaService while binding");
}
}
Log_OC.e(TAG, "Media service suddenly disconnected");
if (mMediaController != null) {
mMediaController.setMediaPlayer(null);
- } else {
+ }
+ else {
Toast.makeText(
getActivity(),
"No media controller to release when disconnected from media service",
mMediaServiceConnection = null;
}
}
- }
+ }
-
/**
* Opens the previewed file with an external application.
mContainerActivity.getFileOperationsHelper().openFile(getFile());
finish();
}
-
+
/**
* 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.
+ * to be previewed.
+ *
+ * @param file File to test if can be previewed.
+ * @return 'True' if the file can be handled by the fragment.
*/
public static boolean canBePreviewed(OCFile file) {
return (file != null && (file.isAudio() || file.isVideo()));
}
-
+
public void stopPreview(boolean stopAudio) {
OCFile file = getFile();
if (file.isAudio() && stopAudio) {
mMediaServiceBinder.pause();
-
- } else if (file.isVideo()) {
- mVideoPreview.stopPlayback();
+
+ }
+ else {
+ if (file.isVideo()) {
+ mVideoPreview.stopPlayback();
+ }
}
}
-
/**
* Finishes the preview
*/
Log_OC.e(TAG, "getting position: " + mSavedPlaybackPosition);
return mSavedPlaybackPosition;
}
-
+
public boolean isPlaying() {
if (mPrepared) {
mAutoplay = mVideoPreview.isPlaying();
}
return mAutoplay;
}
-
+
}
}
} else if (operation instanceof MoveFileOperation) {
- if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
+ if(isNetworkError(result.getCode())){
+ message = getErrorMessage(result, res);
+ } else if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
message = res.getString(R.string.move_file_not_found);
-
} else if (result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT) {
message = res.getString(R.string.move_file_invalid_into_descendent);
}
}
} else if (operation instanceof CopyFileOperation) {
-
- if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
+ if(isNetworkError(result.getCode())){
+ message = getErrorMessage(result, res);
+ } else if (result.getCode() == ResultCode.FILE_NOT_FOUND) {
message = res.getString(R.string.copy_file_not_found);
-
- } else if (result.getCode() == ResultCode.INVALID_MOVE_INTO_DESCENDANT) {
+ } else if (result.getCode() == ResultCode.INVALID_COPY_INTO_DESCENDANT) {
message = res.getString(R.string.copy_file_invalid_into_descendent);
} else if (result.getCode() == ResultCode.INVALID_OVERWRITE) {